/*******************************************************************************
* 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
{
///
/// 组织机构新建/编辑界面
///
public partial class F_MST_0102 : FormBase
{
#region 成员变量
// 存储窗口的编辑状态
private Constant.FormMode _editStatus;
// 修改组织机构时存储上个窗口传过来的ID
private int _organizationID;
// 组织机构ID列表
private List _organizationIDList = new List();
// 组织机构编码
private string _organizationCode;
// 封装组织机构实体
private OrganizationEntity _organization = new OrganizationEntity();
// 上个窗口传过来的上级部门ID
private int _parentOrganizationID;
// 上个窗口传过来的上级部门编码
private string _parentOrganizationCode;
// 上个窗口传过来的上级部门名称
private string _parentOrganizationName;
// 过来的上级部门编码
private string _parentOrganizationCodeTemp;
#endregion
#region 属性
///
/// 父窗体组织机构编码
///
public string ParentOrganizationCodeTemp
{
get
{
return _parentOrganizationCodeTemp;
}
set
{
_parentOrganizationCodeTemp = value;
}
}
///
/// 组织机构ID列表
///
public List OrganizationIDList
{
get
{
return _organizationIDList;
}
set
{
_organizationIDList = value;
}
}
///
/// 组织机构编码
///
public string OrganizationCode
{
get
{
return _organizationCode;
}
set
{
_organizationCode = value;
}
}
///
/// 上个窗口传过来的上级部门
///
public int ParentOrganizationID
{
get
{
return _parentOrganizationID;
}
set
{
_parentOrganizationID = value;
}
}
///
/// 上个窗口传过来的上级部门编码
///
public string ParentOrganizationCode
{
get
{
return _parentOrganizationCode;
}
set
{
_parentOrganizationCode = value;
}
}
///
/// 上个窗口传过来的上级部门名称
///
public string ParentOrganizationName
{
get
{
return _parentOrganizationName;
}
set
{
_parentOrganizationName = value;
}
}
#endregion
#region 构造函数
///
/// 构造函数
///
public F_MST_0102()
: this(Constant.FormMode.Add)
{
}
///
/// 构造函数
///
public F_MST_0102(Constant.FormMode editStatus)
: this(editStatus, 0)
{
}
///
/// 构造函数
///
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 事件
///
/// 关闭按钮事件
///
///
///
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 保存按钮事件
///
///
///
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);
}
}
///
/// 获取组织机构结果集
///
///
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;
}
}
///
/// 票头字母的限制输入
///
///
///
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;
}
}
}
///
/// 窗体加载事件
///
///
///
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 私有方法
///
/// 为窗体各个控赋值
///
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;
}
}
///
/// 获取组织机构数据
///
///
private DataSet GetOrganizationRowData()
{
try
{
return SystemModuleProxy.Service.GetOrganizationRowData(this._organizationID);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 验证输入是否完整
///
///
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;
}
}
///
/// 保存组织机构
///
/// 影响的行数
private object SaveOrganization()
{
try
{
OrganizationEntity organization = GetOrganization();
return SystemModuleProxy.Service.SaveOrganization(organization);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 给组织机构实体类传值
///
///
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;
}
///
/// 重置窗口数据
///
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
}
}