/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PAM_0502.cs
* 2.功能描述:行政奖惩新建/编辑
* 编辑履历:
* 作者 日期 版本 修改内容
* 张国印 2014/09/25 1.00 新建
*******************************************************************************/
using System;
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.Controls;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.HRModule
{
///
/// 行政奖惩新建/编辑
///
public partial class F_PAM_0502 : DKFormBase
{
#region 成员变量
// 窗体状态的枚举 新建/编辑
private Constant.FormMode _editStatus;
//行政奖惩编号
private int _adminEXAID;
// 编辑数据
private DataTable _data;
#endregion
#region 构造函数
///
/// 构造函数
///
///
///
public F_PAM_0502()
: this(Constant.FormMode.Add, 0)
{
}
///
/// 构造函数
///
///
///
public F_PAM_0502(Constant.FormMode editStatus, int adminEXAID)
{
InitializeComponent();
this._editStatus = editStatus;
this._adminEXAID = adminEXAID;
this.dkUserName.WhereCondition = "(StaffStatus = 1 Or StaffStatus = 2) AND ValueFlag = 1";
//this.txtRAPAmount.Text = "0";
this.SetFromTitleInfo();
}
#endregion
#region 属性
#endregion
#region 事件
///
/// 页面加载事件
///
///
///
private void F_HR_1102_Load(object sender, EventArgs e)
{
try
{
#region 绑定数据源
this.comAdministrationType.DataSource = DataDictionaryInfo();
this.comAdministrationType.DisplayMember = "DictionaryValue";
this.comAdministrationType.ValueMember = "DictionaryID";
#endregion
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
if (this._editStatus == Constant.FormMode.Edit)
{
// 获取用户信息数据集
ServiceResultEntity srData = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(this.GetDataInfo));
if (srData.Status == Constant.ServiceResultStatus.Success)
{
_data = srData.Data.Tables[0];
DataRow info = _data.Rows[0];
this.dkUserName.UserID = Convert.ToInt32(info["StaffID"]);
this.dkUserName.UserCode = info["StaffCode"].ToString().Trim();
this.dkUserName.UserName = info["StaffName"].ToString().Trim();
this.dtpRAPDate.Value = Convert.ToDateTime(info["CreateTime"]);
this.txtRAPAmount.DataValue = Convert.ToDecimal(info["Amount"]);
this.comAdministrationType.SelectedValue = Convert.ToInt32(info["AdminEXATypeID"]);
this.txtRemarks.Text = info["Remarks"].ToString();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存按钮
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (!IsInputValid())
{
return ;
}
if (_editStatus == Constant.FormMode.Add)
{
AdminEXAEntity se = SetStaffRecordEntity();
ServiceResultEntity sre = DoAsync(() =>
{
return PAMModuleProxy.Service.AddAdminEXA(se);
}
);
if (sre.Status == Constant.ServiceResultStatus.Success)
{
DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002);
}
}
else
{
DataRow info = _data.Rows[0];
info["StaffID"] = this.dkUserName.UserID;
info["Amount"] = this.txtRAPAmount.DataValue;
info["AdminEXATypeID"] = this.comAdministrationType.SelectedValue;
info["Remarks"] = this.txtRemarks.Text;
ServiceResultEntity sre = DoAsync(() =>
{
return PAMModuleProxy.Service.EditAdminEXA(_data);
}
);
if (sre.Status == Constant.ServiceResultStatus.Success)
{
DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002);
}
else
{
DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, "数据已被修改");
}
}
this.Close();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 设置窗体按钮的文本信息
///
private void SetFromTitleInfo()
{
if (this._editStatus == Constant.FormMode.Add)
{
this.Text = FormTitles.F_PAM_0502_ADD;
this.dkUserName.Enabled = true;
}
else if (this._editStatus == Constant.FormMode.Edit)
{
this.Text = FormTitles.F_PAM_0502_EDIT;
this.dkUserName.Enabled = false;
}
this.dtpRAPDate.Value = DateTime.Now;
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
///
/// 获取行政考核类别数据源
///
///
public DataTable DataDictionaryInfo()
{
DataTable dtDicInfo = (DataTable)DoAsync(new BaseAsyncMethod(() =>
{
return CommonModuleProxy.Service.GetDataDictionaryByType(Constant.ASE_ASE001);
}));
return dtDicInfo;
}
///
/// 根据查询条件获取要显示的数据
///
/// 返回查询的结果集
private ServiceResultEntity GetDataInfo()
{
return PAMModuleProxy.Service.GetAdminEXAByID(_adminEXAID);
}
///
/// 设置非待审核的履历控件禁用
///
private void SetControlEnable()
{
this.dkUserName.Enabled = false;
this.dtpRAPDate.Enabled = false;
this.txtRAPAmount.Enabled = false;
this.comAdministrationType.Enabled = false;
this.txtRemarks.Enabled = false;
this.btnSave.Enabled = false;
}
///
/// 检查页面的输入项目
///
///
///
///
private bool IsInputValid()
{
if (this.dkUserName.UserID == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "员工姓名"),
this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button1);
this.dkUserName.Focus();
return false;
}
else if (string.IsNullOrEmpty(this.txtRAPAmount.Text))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "考核金额"),
this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button1);
this.txtRAPAmount.Focus();
return false;
}
else if (this.comAdministrationType.SelectedValue == null)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "考核类别"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
this.comAdministrationType.Focus();
return false;
}
else
{
return true;
}
}
///
/// 根据页面输入值,对实体赋值
///
///
private AdminEXAEntity SetStaffRecordEntity()
{
AdminEXAEntity staffRecordEntity = new AdminEXAEntity();
staffRecordEntity.StaffID = this.dkUserName.UserID.Value;
staffRecordEntity.Amount = this.txtRAPAmount.DataValue.Value;
if (this.comAdministrationType.SelectedValue != null)
{
staffRecordEntity.AdminEXATypeID = Convert.ToInt32(this.comAdministrationType.SelectedValue);
}
staffRecordEntity.Remarks = this.txtRemarks.Text;
return staffRecordEntity;
}
///
/// 清空输入项
///
private void InitializationForm()
{
this.dkUserName.UserID = null;
this.dkUserName.UserCode = string.Empty;
this.dkUserName.UserName = string.Empty;
this.dkUserName.StaffEntity = null;
this.dtpRAPDate.Value = DateTime.Now;
this.txtRAPAmount.Text = "0";
if (this.comAdministrationType.SelectedValue != null)
{
this.comAdministrationType.SelectedIndex = 0;
}
this.txtRemarks.Text = string.Empty;
}
#endregion
}
}