| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0102.cs
- * 2.功能描述:组织机构新建/编辑界面
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2014/09/12 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- /// <summary>
- /// 组织机构新建/编辑界面
- /// </summary>
- public partial class F_MST_0102 : FormBase
- {
- #region 成员变量
- // 存储窗口的编辑状态
- private Constant.FormMode _editStatus;
- // 修改组织机构时存储上个窗口传过来的ID
- private int _organizationID;
- // 组织机构ID列表
- private List<int> _organizationIDList = new List<int>();
- // 组织机构编码
- private string _organizationCode;
- // 封装组织机构实体
- private OrganizationEntity _organization = new OrganizationEntity();
- // 上个窗口传过来的上级部门ID
- private int _parentOrganizationID;
- // 上个窗口传过来的上级部门编码
- private string _parentOrganizationCode;
- // 上个窗口传过来的上级部门名称
- private string _parentOrganizationName;
- // 过来的上级部门编码
- private string _parentOrganizationCodeTemp;
- #endregion
- #region 属性
- /// <summary>
- /// 父窗体组织机构编码
- /// </summary>
- public string ParentOrganizationCodeTemp
- {
- get
- {
- return _parentOrganizationCodeTemp;
- }
- set
- {
- _parentOrganizationCodeTemp = value;
- }
- }
- /// <summary>
- /// 组织机构ID列表
- /// </summary>
- public List<int> OrganizationIDList
- {
- get
- {
- return _organizationIDList;
- }
- set
- {
- _organizationIDList = value;
- }
- }
- /// <summary>
- /// 组织机构编码
- /// </summary>
- public string OrganizationCode
- {
- get
- {
- return _organizationCode;
- }
- set
- {
- _organizationCode = value;
- }
- }
- /// <summary>
- /// 上个窗口传过来的上级部门
- /// </summary>
- public int ParentOrganizationID
- {
- get
- {
- return _parentOrganizationID;
- }
- set
- {
- _parentOrganizationID = value;
- }
- }
- /// <summary>
- /// 上个窗口传过来的上级部门编码
- /// </summary>
- public string ParentOrganizationCode
- {
- get
- {
- return _parentOrganizationCode;
- }
- set
- {
- _parentOrganizationCode = value;
- }
- }
- /// <summary>
- /// 上个窗口传过来的上级部门名称
- /// </summary>
- public string ParentOrganizationName
- {
- get
- {
- return _parentOrganizationName;
- }
- set
- {
- _parentOrganizationName = value;
- }
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0102()
- : this(Constant.FormMode.Add)
- {
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0102(Constant.FormMode editStatus)
- : this(editStatus, 0)
- {
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0102(Constant.FormMode editStatus, int organizationID)
- {
- InitializeComponent();
- this._editStatus = editStatus;
- // 根据新建、编辑状态为标题赋值
- if (editStatus == Constant.FormMode.Add)
- {
- this.Text = FormTitles.F_MST_0102_ADD;
- }
- else
- {
- this.Text = FormTitles.F_MST_0102_EDIT;
- // 存储上个窗口传过来的组织机构ID
- this._organizationID = organizationID;
- }
- // 按钮文本
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
-
- }
- #endregion
- #region 事件
- /// <summary>
- /// 关闭按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 保存按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- // 验证信息是否完整
- bool validResult = IsValidData();
- if (validResult)
- {
- string OrgCode = (string)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetOrganizationCode(this.ParentOrganizationCode);
- }));
- this.ParentOrganizationCodeTemp = OrgCode;
- this._organization = this.GetOrganization();//获取组织机构实体类
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- int result = (int)DoAsync(new BaseAsyncMethod(this.SaveOrganization));//保存按钮方法
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- if ((int)result > Constant.INT_IS_ZERO)//保存成功
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "组织机构", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this._organizationIDList.Add(Convert.ToInt32(result));
- this.DialogResult = DialogResult.OK;
- }
- else if (result == Constant.RETURN_IS_EXIST)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "系统中存在有效的运营中心"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else if (result == Constant.RETURN_IS_HAVEVALIDCHILD)//
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "该组织机构存在有效的下级组织机构"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else if (result == Constant.RETURN_IS_ENABLETOOPERATE)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "该组织机构存在员工"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else if (result == Constant.RETURN_IS_DATAISNOTVALID)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "该组织机构存在用户"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else //保存机构有错误
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "组织机构", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (this._editStatus == Constant.FormMode.Edit)
- {
- this.Close();
- }
- else
- {
- // 重置窗口数据
- this.ResetFormData();
- }
- }
- }
- catch (Exception ex)
- {
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 获取组织机构结果集
- /// </summary>
- /// <returns></returns>
- private DataSet GetOrganizationDataSource()
- {
- try
- {
- OrganizationEntity organization = new OrganizationEntity();
- // 票号开头字母
- organization.LetterMarket = this.LetterMarket.Text.Trim();
- // 联系电话
- organization.Telephone = this.txtTelephone.Text.Trim();
- // 地址
- organization.Address = this.txtAddress.Text;
- // 备注
- organization.Remarks = this.txtRemarks.Text;
- // 正常标识
- organization.ValueFlags = null;
- organization.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
- organization.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
- this._organization = organization;
- return SystemModuleProxy.Service.SelectOrganizationData(organization);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 票头字母的限制输入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtLetterMarket_KeyPress(object sender, KeyPressEventArgs e)
- {
- if ((e.KeyChar >= 'A' && e.KeyChar <= 'Z'))
- {
- e.Handled = false;
- }
- else
- {
- if ((int)e.KeyChar != Constant.INT_IS_EIGHT)
- {
- e.Handled = true;
- }
- }
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0102_Load(object sender, EventArgs e)
- {
- try
- {
- // 若状态是添加,则有效标志为可用并且不显示
- if (this._editStatus == Constant.FormMode.Add)
- {
- this.chkValueFlag.Checked = true;
- this.chkValueFlag.Visible = false;
- this.txtOrganization.Text = ParentOrganizationName;
- }
- // 若状态是修改,则为窗口各控件赋值
- else
- {
- this.SetOrganizationData();
- }
- this.txtOrganizationName.Focus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 为窗体各个控赋值
- /// </summary>
- private void SetOrganizationData()
- {
- try
- {
- // 获取组织机构信息
- this._organization = new OrganizationEntity();
- this._organization.OrganizationID = this._organizationID;
- DataSet result = (DataSet)DoAsync(new BaseAsyncMethod(this.GetOrganizationRowData));
- if (result != null && result.Tables.Count > Constant.INT_IS_ZERO && result.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow organizationRow = result.Tables[0].Rows[0];
- // 编码
- this.txtOrganizationCode.Text = organizationRow["OrganizationCode"].ToString();
- // 名称
- this.txtOrganizationName.Text = organizationRow["OrganizationName"].ToString();
- // 全称
- this.txtOrganizationFullName.Text = organizationRow["OrganizationFullName"].ToString();
- // 负责人
- this.txtLeader.Text = organizationRow["Leader"].ToString();
- // 票头字母
- this.LetterMarket.Text = organizationRow["LetterMarket"].ToString();
- // 联系电话
- this.txtTelephone.Text = organizationRow["Telephone"].ToString();
- // 地址
- this.txtAddress.Text = organizationRow["Address"].ToString();
- // 备注
- this.txtRemarks.Text = organizationRow["Remarks"].ToString();
- // 正常标识
- this.chkValueFlag.Checked = Convert.ToBoolean(Convert.ToInt32(organizationRow["ValueFlag"]));
- this._organization.AccountID = Convert.ToInt32(organizationRow["AccountID"].ToString());
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取组织机构数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetOrganizationRowData()
- {
- try
- {
- return SystemModuleProxy.Service.GetOrganizationRowData(this._organizationID);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 验证输入是否完整
- /// </summary>
- /// <returns></returns>
- private bool IsValidData()
- {
- try
- {
- // 名称不能为空
- if (string.IsNullOrEmpty(this.txtOrganizationName.Text.Trim()))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtOrganizationName.Focus();
- return false;
- }
- // 名称不能包含“→”
- else
- {
- if (this.txtOrganizationName.Text.Trim().Contains("→"))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "名称不能包含“→”"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtOrganizationName.Focus();
- return false;
- }
- }
- // 票头字母必须是两位字母
- if (!string.IsNullOrEmpty(this.LetterMarket.Text)
- && this.LetterMarket.Text.Trim().Length != Constant.INT_IS_TWO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "票头字母必须是两位字母"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.LetterMarket.Focus();
- return false;
- }
- return true;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存组织机构
- /// </summary>
- /// <returns>影响的行数</returns>
- private object SaveOrganization()
- {
- try
- {
- OrganizationEntity organization = GetOrganization();
- return SystemModuleProxy.Service.SaveOrganization(organization);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 给组织机构实体类传值
- /// </summary>
- /// <returns></returns>
- private OrganizationEntity GetOrganization()
- {
- OrganizationEntity organization = new OrganizationEntity();
- // 组织机构ID
- organization.OrganizationID = this._organizationID;
- // 编码
- organization.OrganizationCode = this.txtOrganizationCode.Text.Trim();
- // 名称
- organization.OrganizationName = this.txtOrganizationName.Text.Trim();
- // 全称 →
- organization.OrganizationFullName = this.txtOrganizationFullName.Text.Trim();
- // 负责人
- organization.Leader = this.txtLeader.Text.Trim();
- organization.ParentOrganizationID = this.ParentOrganizationID;
- organization.ParentOrganizationCode = this.ParentOrganizationCode;
- // 票头字母
- organization.LetterMarket = this.LetterMarket.Text.Trim();
- // 联系电话
- organization.Telephone = this.txtTelephone.Text.Trim();
- // 地址
- organization.Address = this.txtAddress.Text;
- // 备注
- organization.Remarks = this.txtRemarks.Text;
- // 正常标识
- organization.ValueFlag = Convert.ToByte(this.chkValueFlag.Checked);
- organization.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
- organization.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
- return organization;
- }
- /// <summary>
- /// 重置窗口数据
- /// </summary>
- private void ResetFormData()
- {
- // 组织机构ID
- this._organizationID = Constant.INT_IS_ZERO;
- // 编码
- this.txtOrganizationCode.Clear();
- // 名称
- this.txtOrganizationName.Clear();
- // 全称
- this.txtOrganizationFullName.Clear();
- // 负责人
- this.txtLeader.Clear();
- // 票头字母
- this.LetterMarket.Clear();
- // 联系电话
- this.txtTelephone.Clear();
- // 地址
- this.txtAddress.Clear();
- // 备注
- this.txtRemarks.Clear();
- // 正常标识
- this.chkValueFlag.Checked = true;
- }
- #endregion
- }
- }
|