/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_TAT_0602.cs
* 2.功能描述:新建/编辑/复制缺陷扣罚信息
* 编辑履历:
* 作者 日期 版本 修改内容
* 宋扬 2014/12/11 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.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.TATModuleService;
namespace Dongke.IBOSS.PRD.Client.TATModule
{
public partial class F_TAT_0602 : FormBase
{
#region 成员变量
// 窗体模式ID
private Constant.FormMode _formType;
// 操作实体ID
private int? _entityId;
// 操作实体信息
private AdministrationEntity _administrationEntity = new AdministrationEntity();
#endregion
#region 构造函数
///
/// 窗体构造
///
/// 窗体打开模式
/// 操作实体ID
public F_TAT_0602(Constant.FormMode formType, int entityId)
{
InitializeComponent();
_formType = formType;
_entityId = entityId;
// 窗体显示的Title
if (this._formType == Constant.FormMode.Add)
{
this.Text = FormTitles.F_TAT_0602_ADD;
}
else if (this._formType == Constant.FormMode.Edit)
{
this.Text = FormTitles.F_TAT_0602_EDIT;
}
else if (this._formType == Constant.FormMode.CopyAndAdd)
{
this.Text = FormTitles.F_TAT_0602_COPY;
}
else if (this._formType == Constant.FormMode.Display)
{
this.Text = FormTitles.F_TAT_0602_AUDIT;
}
}
#endregion
#region 事件处理
///
/// 窗体加载
///
///
///
private void F_TAT_0602_Load(object sender, EventArgs e)
{
try
{
//绑定类别信息
BindSelectData();
//如果是修改,要绑定选中的信息
if (this._formType == Constant.FormMode.Edit)
{
BindPage();
}
//如果是新建,选项默认值设定
else if (this._formType == Constant.FormMode.Add || this._formType == Constant.FormMode.CopyAndAdd)
{
this.cbCeremonial.Checked = true;
}
//如果是审核,绑定值后,所有控件不可用,保存按钮变为明细按钮,并且审批通过与不通过按钮变为可见
else
{
BindPage();
//绑定页面实体成员变量
this.txtAdministrationName.Enabled = false;
this.txtRemarks.Enabled = false;
this.dtpStartTime.Enabled = false;
this.cbCeremonial.Enabled = false;
this.cbTrial.Enabled = false;
this.lbxAdministrationType.Enabled = false;
this.btnSubmit.Text = Constant.BUTTON_TEXT_DETAIL;
this.btnPass.Visible = true;
this.btnReturn.Visible = true;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 提交操作按钮事件
///
///
///
private void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (this._formType != Constant.FormMode.Display)
{
//为实体绑定属性
if (this.BindEntity())
{
return;
}
//进行添加操作
ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
{
return EntityToServer();
});
//服务实体共通处理
ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
if (srEntity.Status == Constant.ServiceResultStatus.Success)
{
this.DialogResult = DialogResult.OK;
}
}
else
{
//模式化开启明细窗体
F_TAT_0403 frmTAT0403 = new F_TAT_0403(Constant.FormMode.Display, Convert.ToInt32(this._entityId));
DialogResult dialogResult = frmTAT0403.ShowDialog();
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 窗体关闭
///
///
///
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 窗体释放
///
///
///
private void F_TAT_0602_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
}
///
/// 审批通过
///
///
///
private void btnPass_Click(object sender, EventArgs e)
{
//进行审核操作
this._administrationEntity.AuditStatus = Convert.ToInt32(Constant.AuditStatus.Agree);
ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
{
return EntityToServer();
});
//服务实体共通处理
ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
if (srEntity.Status == Constant.ServiceResultStatus.Success)
{
this.DialogResult = DialogResult.OK;
}
}
///
/// 审批驳回
///
///
///
private void btnReturn_Click(object sender, EventArgs e)
{
//进行审核操作
this._administrationEntity.AuditStatus = Convert.ToInt32(Constant.AuditStatus.Disagree);
ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
{
return EntityToServer();
});
//服务实体共通处理
ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
if (srEntity.Status == Constant.ServiceResultStatus.Success)
{
this.DialogResult = DialogResult.OK;
}
}
#endregion
#region 私有方法/函数
///
/// 绑定需要操作的实体信息
///
private void BindPage()
{
if (this._entityId != Constant.INT_IS_ZERO && this._entityId != null)
{
this._administrationEntity.AdministrationID = this._entityId;
ServiceResultEntity srQuality = (ServiceResultEntity)DoAsync(() =>
{
return TATModuleProxy.Service.GetAdministration(_administrationEntity);
});
if (srQuality.Data != null && srQuality.Data.Tables.Count != Constant.INT_IS_ZERO
&& srQuality.Data.Tables[Constant.INT_IS_ZERO].Rows.Count != Constant.INT_IS_ZERO)
{
DataRow drEntityRow = srQuality.Data.Tables[Constant.INT_IS_ZERO].Rows[Constant.INT_IS_ZERO];
this.txtAdministrationName.Text = drEntityRow["AdministrationName"].ToString();
this.txtRemarks.Text = drEntityRow["Remarks"].ToString();
int SalaryType = Convert.ToInt32(drEntityRow["SalaryType"]);
if (SalaryType == Constant.INT_IS_ONE)
{
this.cbCeremonial.Checked = true;
}
else
{
this.cbTrial.Checked = true;
}
this._administrationEntity.SalaryType = SalaryType;
this.dtpStartTime.Text = drEntityRow["BeginAccountMonth"].ToString();
this.lbxAdministrationType.SelectedValue = Convert.ToInt32(drEntityRow["AdministrationType"]);
this._administrationEntity.AdministrationType = Convert.ToInt32(this.lbxAdministrationType.SelectedValue);
this._administrationEntity.BeginAccountMonthStart = Convert.ToDateTime(this.dtpStartTime.Text);
//将时间戳给到要修改的实体中
this._administrationEntity.OPTimeStamp = Convert.ToDateTime(drEntityRow["OPTimeStamp"]);
}
}
}
///
/// 为实体绑定页面属性
///
private bool BindEntity()
{
if (string.IsNullOrEmpty(this.txtAdministrationName.Text.Trim())
|| string.IsNullOrEmpty(this.lbxAdministrationType.Text.Trim()))
{
return true;
}
this._administrationEntity.AdministrationName = this.txtAdministrationName.Text.Trim();
this._administrationEntity.Remarks = this.txtRemarks.Text.Trim();
this._administrationEntity.BeginAccountMonthStart = Convert.ToDateTime(this.dtpStartTime.Value.ToString("yyyy-MM")); ;
if (this.cbCeremonial.Checked)
{
this._administrationEntity.SalaryType = Constant.INT_IS_ONE;
}
else
{
this._administrationEntity.SalaryType = Constant.INT_IS_ZERO;
}
this._administrationEntity.AuditStatus = Constant.INT_IS_ZERO;
if (this.lbxAdministrationType.SelectedValue != null)
{
this._administrationEntity.AdministrationType = Convert.ToInt32(this.lbxAdministrationType.SelectedValue);
}
return false;
}
///
/// 与服务交互操作
///
///
private ServiceResultEntity EntityToServer()
{
if (this._formType == Constant.FormMode.Add)
{
return TATModuleProxy.Service.AddAdministration(this._administrationEntity);
}
else if (this._formType == Constant.FormMode.Edit)
{
return TATModuleProxy.Service.UpdateAdministration(this._administrationEntity);
}
else if (_formType == Constant.FormMode.CopyAndAdd)
{
this._administrationEntity.CopyId = Convert.ToInt32(this._entityId);
return TATModuleProxy.Service.AddAdministration(this._administrationEntity);
}
else if (_formType == Constant.FormMode.Display)
{
return TATModuleProxy.Service.AuditAdministration(this._administrationEntity);
}
return null;
}
///
/// 绑定下拉列数据
///
private void BindSelectData()
{
//获取行政信息
DataSet dsAdministrationType = (DataSet)DoAsync(() =>
{
return SystemModuleProxy.Service.GetDictionaryData(0, "ASE001");
});
this.lbxAdministrationType.DataSource = dsAdministrationType.Tables[Constant.INT_IS_ZERO];
this.lbxAdministrationType.ValueMember = "Dictionaryid";
this.lbxAdministrationType.DisplayMember = "Dictionaryvalue";
this.lbxAdministrationType.Text = string.Empty;
}
#endregion
}
}