/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_TAT_0802.cs * 2.功能描述:新建/编辑/复制出勤考核信息 * 编辑履历: * 作者 日期 版本 修改内容 * 任海 2014/12/15 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; 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.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_0802 : FormBase { #region 成员变量 // 窗体模式ID private Constant.FormMode _formType; // 操作实体ID private int? _entityId; // 操作实体名称 //private string _entityname; // 窗体加载完毕标识 private bool _pageLoadOK = false; // 选择窗体弹出标识 private bool _showFlag = true; // 数据源 private DataSet _dsSourse; // 操作实体信息 private AttendanceEntity _dfEntity = new AttendanceEntity(); #endregion #region 构造函数 /// /// 窗体构造 /// /// 窗体打开模式 /// 操作实体ID public F_TAT_0802(Constant.FormMode formType, int entityId) { InitializeComponent(); _formType = formType; _entityId = entityId; this.btnSubmit.Text = ButtonText.BTN_SAVE; this.btnClose.Text = ButtonText.BTN_CANCEL; } #endregion #region 事件处理 /// /// 窗体加载 /// /// /// private void F_TAT_0802_Load(object sender, EventArgs e) { try { if (this._formType == Constant.FormMode.Add) { this.Text = FormTitles.F_TAT_0802_ADD; } else if (this._formType == Constant.FormMode.Edit) { this.Text = FormTitles.F_TAT_0802_EDIT; } else if (this._formType == Constant.FormMode.CopyAndAdd) { this.Text = FormTitles.F_TAT_0802_COPY; } else if (this._formType == Constant.FormMode.Display) { this.Text = FormTitles.F_TAT_0802_AUDIT; } //无论如何先绑定工种,即使没有信息,也需要Table的结构 this.dgvJobs.AutoGenerateColumns = false; this.BindJobs(); //如果是编辑或审核模式,还要绑定主体信息 if (this._formType == Constant.FormMode.Edit || this._formType == Constant.FormMode.Display) { if (this._formType == Constant.FormMode.Display) { this.btnSubmit.Visible = false; } this.BindPage(); this.dgvJobs.IsSetInputColumnsColor = true; this.tsbtnOther.Visible = true; this.tsbtnOther.Enabled = false; } else { //新建模式下是不可以进入明细的 if (this._formType == Constant.FormMode.Add) { this.tsbtnOther.Visible = false; } else //复制模式不可编辑明细 { this.dgvJobs.ReadOnly = true; this.dgvJobs.IsSetInputColumnsColor = false; this.dgvJobs.AllowUserToAddRows = false; } } //页面加载完毕 this._pageLoadOK = true; //如果是审核及观看模式 if (this._formType == Constant.FormMode.Display) { this.btnPass.Visible = true; this.btnReturn.Visible = true; //列表设置为只读 this.dgvJobs.ReadOnly = true; this.dgvJobs.IsSetInputColumnsColor = false; this.dgvJobs.AllowUserToAddRows = false; //控件除关闭外全部不可用 this.txtBasicSalaryName.Enabled = false; this.txtRemarks.Enabled = false; this.dtpStartTime.Enabled = false; } } 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.ValidationInput() == false) { return; } //为实体绑定属性 this.BindEntity(); //进行添加操作 ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() => { return EntityToServer(); }); //服务实体共通处理 ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text); if (srEntity.Status == Constant.ServiceResultStatus.Success) { this.DialogResult = DialogResult.OK; } } else//审批操作的话,只打开明细的查看模式就可以了 { //模式化开启明细窗体 //F_TAT_0803 frmTAT0803 // = new F_TAT_0803(this._formType, Convert.ToInt32(this._entityId), JobsId); //DialogResult dialogResult = frmTAT0803.ShowDialog(); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 审批通过 /// /// /// private void btnPass_Click(object sender, EventArgs e) { //进行审核操作 this._dfEntity.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._dfEntity.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; } } /// /// 编辑工种对应明细 /// /// /// private void tsbtnOther_Click(object sender, EventArgs e) { try { //获取当前行,如果不为空以及非新建行的话,就可以进入明细页面 DataGridViewRow gvrNow = this.dgvJobs.CurrentRow; if (gvrNow != null && !gvrNow.IsNewRow) { //获取需要添加明细的信息ID int JobsId = Convert.ToInt32(gvrNow.Cells["JobsId"].Value); //以编辑模式打开信息窗体 F_TAT_0803 frmTAT0803 = new F_TAT_0803(this._formType, Convert.ToInt32(this._entityId), JobsId); DialogResult dialogResult = frmTAT0803.ShowDialog(); } else { //不可为空或选择新建行 } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 编辑工种编码弹出工种窗体 /// /// /// private void dgvJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { //变更后重新加载 this._pageLoadOK = false; if (this.dgvJobs.Rows.Count <= 1 || !this._showFlag) { return; } DataGridViewRow rowItem = this.dgvJobs.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex]; if (columnItem.Name == "JobsCode") { //打开多选页面进行值绑定 this._showFlag = false; FormUtility.BindJobsRowDataSource(this.dgvJobs, e.RowIndex, columnItem.Name, string.Empty); this._showFlag = true; } //加载OK this._pageLoadOK = true; // 设置可输入单元格的颜色 this.dgvJobs.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 自适应列宽 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvJobs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 窗体关闭 /// /// /// private void btnClose_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; } #endregion #region 私有方法/函数 /// /// 绑定需要操作的实体信息 /// private void BindPage() { if (this._entityId != 0 && this._entityId != null) { this._dfEntity.AttendanceID = this._entityId; ServiceResultEntity srEntity = TATModuleProxy.Service.GetAttendance(this._dfEntity); if (srEntity.Data != null && srEntity.Data.Tables.Count != 0 && srEntity.Data.Tables[0].Rows.Count != 0) { DataSet dsEntityData = (DataSet)srEntity.Data; DataRow drEntityRow = dsEntityData.Tables[0].Rows[0]; this.txtBasicSalaryName.Text = drEntityRow["AttendanceName"].ToString(); this.txtRemarks.Text = drEntityRow["Remarks"].ToString(); this.dtpStartTime.Text = drEntityRow["BeginAccountMonth"].ToString(); this._dfEntity.BeginAccountMonth = Convert.ToDateTime(drEntityRow["BeginAccountMonth"].ToString()); //将时间戳给到要修改的实体中 this._dfEntity.OPTimeStamp = Convert.ToDateTime(drEntityRow["OPTimeStamp"]); } } } /// /// 验证必填项 /// /// 是否通过 private bool ValidationInput() { if (string.IsNullOrWhiteSpace(this.txtBasicSalaryName.Text)) { this.txtBasicSalaryName.Focus(); return false; } return true; } /// /// 为实体绑定页面属性 /// private void BindEntity() { this._dfEntity.AttendanceName = this.txtBasicSalaryName.Text.Trim(); this._dfEntity.BeginAccountMonth = this.dtpStartTime.Value.Date; this._dfEntity.Remarks = this.txtRemarks.Text; this._dfEntity.AuditStatus = 0; } /// /// 与服务交互操作 /// /// private ServiceResultEntity EntityToServer() { if (this._formType == Constant.FormMode.Add) { return TATModuleProxy.Service.AddAttendance(this._dfEntity, _dsSourse); } else if (this._formType == Constant.FormMode.Edit) { return TATModuleProxy.Service.UpdateAttendance(this._dfEntity, _dsSourse); } else if (_formType == Constant.FormMode.CopyAndAdd) { this._dfEntity.CopyId = Convert.ToInt32(this._entityId); return TATModuleProxy.Service.AddAttendance(this._dfEntity, _dsSourse); } else if (_formType == Constant.FormMode.Display) { return TATModuleProxy.Service.AuditAttendance(this._dfEntity); } return null; } /// /// 绑定对应工种 /// private void BindJobs() { try { try { //获取对应工种明细 ServiceResultEntity srEntityDetail = TATModuleProxy.Service.GetAttendanceEntityById(Convert.ToInt32(this._entityId)); if (srEntityDetail.Data != null && srEntityDetail.Data.Tables.Count != 0) { this._dsSourse = srEntityDetail.Data; this.dgvJobs.DataSource = srEntityDetail.Data.Tables[0]; this.dgvJobs.IsSetInputColumnsColor = true; } } catch (Exception ex) { throw ex; } } catch (Exception ex) { throw ex; } } /// /// 清空页面 /// private void ClaerInput() { this.txtBasicSalaryName.Text = string.Empty; this.txtRemarks.Text = string.Empty; } #endregion /// /// 选择信息后,工具条按钮的变化 /// /// /// private void dgvJobs_SelectionChanged(object sender, EventArgs e) { try { //DataGridViewRow gvrNow = this.dgvJobs.CurrentRow; //if (gvrNow != null && gvrNow.Cells["isHave"].Value != null) //{ // if (gvrNow.Cells["isHave"].Value.ToString() == "1") // { // this.tsbtnOther.Enabled = true; // } // else // { // this.tsbtnOther.Enabled = false; // } //} //else //{ // this.tsbtnOther.Enabled = false; //} if (this.dgvJobs.SelectedRows.Count != 0) { DataGridViewRow gvrNow = this.dgvJobs.SelectedRows[0]; if (gvrNow.Cells["isHave"].Value != null && gvrNow.Cells["isHave"].Value != DBNull.Value && gvrNow.IsNewRow == false) { this.tsbtnOther.Enabled = true; } else { this.tsbtnOther.Enabled = false; } } else { this.tsbtnOther.Enabled = false; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }