/******************************************************************************* * Copyright(c) 2015 dongke All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PC_0402_1.cs * 2.功能描述:班次配置新建\编辑 * 编辑履历: * 作者 日期 版本 修改内容 * 袁新成 2015/04/22 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; 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; namespace Dongke.IBOSS.PRD.Client.PCModule { /// /// 班次配置新建\编辑窗体 /// public partial class F_PC_0402_1 : DKFormBase { #region 成员变量 // 班次配置ID private int _classesSettingID; // 窗体状态的枚举 新建/编辑 private Constant.FormMode _editStatus; // 选中的员工编码 private string _staffCode; // 工号ID private int _userId; // 工号名称 private string _userName; // 工号编号 private string _userCode; // 备注 private string _remark; //配置日期 private DateTime _accountdate; //保存影响行 private int _returnRow = Constant.INT_IS_ZERO; // 打开选择窗体的标识 private bool _showFromFlag = true; // 当前工号的工种集合 private DataTable _userJobsTable = new DataTable(); //工号集合体 private FPC0402_SE frmse = new FPC0402_SE(); //保存操作类型0--新增,1--更新 private int saveStatus=0; #endregion #region 属性 /// /// 备注 /// public string Remark { get { return _remark; } set { _remark = value; } } /// /// 工号名称 /// public string UserName1 { get { return _userName; } set { _userName = value; } } /// /// 班次配置ID /// public int ClassesSettingID { get { return _classesSettingID; } set { _classesSettingID = value; } } /// /// 工号ID /// public int UserId { get { return _userId; } set { _userId = value; } } /// /// 工号编号 /// public string UserCode { get { return _userCode; } set { _userCode = value; } } public DateTime AccountDate { get { return _accountdate; } set { _accountdate = value; } } #endregion #region 构造函数 /// /// 构造函数 /// /// 新建/编辑 /// 要编辑的员工编号 public F_PC_0402_1(Constant.FormMode editStatus) { InitializeComponent(); this._editStatus = editStatus; this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CANCEL; this.btnSave.Enabled = false; if (this._editStatus == Constant.FormMode.Add) { this.Text = FormTitles.F_PC_0402_ADD; } else { this.Text = FormTitles.F_PC_0402_EDIT; } } #endregion #region 事件 /// /// 页面加载事件 /// /// /// private void F_PC_0402_Load(object sender, EventArgs e) { try { if (this._editStatus == Constant.FormMode.Edit) { frmse.ClassSettingID = this._classesSettingID; frmse.AccountDate = this.AccountDate; saveStatus = 1; //更新 this.txtRemarks.Text = this.Remark; this.dkUserInfo.UserID = this._userId; this.dkUserInfo.UserName = this._userName; this.dkUserInfo.UserCode = this._userCode; this.dkUserInfo.Enabled = false; this.dtpAccountDate.Enabled = false; this.dgvClassesDetail.AllowUserToAddRows = true; this.dgvClassesDetail.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.dgvClassesDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 关闭按钮事件 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 工号ValueChanged事件 /// /// /// private void dkUserInfo_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e) { try { this.btnSave.Enabled = false; int userId = this.dkUserInfo.UserID.Value; if(!string.IsNullOrEmpty(this.dkUserInfo.Text.Trim())) { // 调用服务器端获取数据集 ServiceResultEntity sreuser = DoAsync(() => { return PCModuleProxyNew.Service.GetUserInfo(userId); } ); if (sreuser.Status == Constant.ServiceResultStatus.Success) { frmse.UserID = userId; frmse.UserCode = this.dkUserInfo.UserCode; frmse.UserOrganizationID = int.Parse(sreuser.Data.Tables[0].Rows[0]["organizationid"].ToString()); } BindUserJobs(); this.dgvClassesDetail.AllowUserToAddRows = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 员工编号值改变事件 /// /// /// private void dgvClassesDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (this.dgvClassesDetail.Rows.Count <= Constant.INT_IS_ONE || !_showFromFlag) { return; } DataGridViewRow rowItem = this.dgvClassesDetail.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvClassesDetail.Columns[e.ColumnIndex]; // 用编号获取员工信息 if ("StaffCode".Equals(columnItem.Name) && !string.IsNullOrEmpty(this.dgvClassesDetail.Rows[e.RowIndex].Cells[columnItem.Name].Value + "")) { this._showFromFlag = false; FormUtility.BindClassStaffRowDataSource(this.dgvClassesDetail, e.RowIndex, columnItem.Name, this._staffCode, this.dkUserInfo.UserID.Value, true); this._showFromFlag = true; // 设置可输入单元格的颜色 this.dgvClassesDetail.IsSetInputColumnsColor = true; // 不可出现重复的人员 for (int i = 0; i < this.dgvClassesDetail.Rows.Count; i++) { if (i != e.RowIndex) { if (this.dgvClassesDetail.Rows[i].IsNewRow == true) { return; } String NowStaffID = this.dgvClassesDetail.Rows[e.RowIndex].Cells["StaffID"].Value.ToString(); if (NowStaffID == string.Empty) { this.dgvClassesDetail.Rows.RemoveAt(e.RowIndex); return; } String ForStaffID = ""; if (this.dgvClassesDetail.Rows[i].Cells["StaffID"].Value != null) { ForStaffID = this.dgvClassesDetail.Rows[i].Cells["StaffID"].Value.ToString(); } if (NowStaffID == ForStaffID) { ((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex].Delete(); //仅限当前页面,工号间的待修改 MessageBox.Show("员工信息不可重复配置!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.btnSave.Enabled = true; } } } if (columnItem.Name == "UJobsId") { string JobsId = this.dgvClassesDetail.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (JobsId == string.Empty) { if (((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex]["UJobsId", DataRowVersion.Original] != null) { string OValue = ((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex]["UJobsId", DataRowVersion.Original].ToString(); ((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex]["UJobsId"] = OValue; } else { ((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex].Delete(); } } } } catch (Exception ex) { this._showFromFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 单元格编辑时 /// /// /// private void dgvClassesDetail_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { try { if (this.dgvClassesDetail.Rows.Count <= Constant.INT_IS_ONE) { return; } DataGridViewColumn columnItem = this.dgvClassesDetail.Columns[e.ColumnIndex]; if ("StaffCode".Equals(columnItem.Name)) { this._staffCode = this.dgvClassesDetail.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""; } } 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 (isWhiteTable() == true) { MessageBox.Show("至少要有一条班次配置明细信息!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } // 不可更改帐务日期之前的班次配置 DateTime accountDate = CommonModuleProxy.Service.GetAccountDate(); if (Convert.ToDateTime(this.dtpAccountDate.Text) < accountDate) { FPC0401_SE se = new FPC0401_SE(); se.DateBegin = DateTime.Parse(dtpAccountDate.Value.ToString("yyyy-MM-dd") + " 0:0:0"); se.DateEnd = DateTime.Parse(dtpAccountDate.Value.ToString("yyyy-MM-dd") + " 23:59:59"); se.UserCode = dkUserInfo.UserCode; // 调用服务器端获取数据集 ServiceResultEntity sreclass = DoAsync(() => { return PCModuleProxyNew.Service.GetFPC0401SData(se); } ); if (sreclass.Status == Constant.ServiceResultStatus.Success) { if (sreclass.Data != null && sreclass.Data.Tables[0].Rows.Count >0) { MessageBox.Show("选择日期已存在班次配置,不可再次补录!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } } } // 验证界面必录项的录入; if (this.CheckInputValidity()) { // 保存 DataTable dTable = (DataTable)this.dgvClassesDetail.DataSource; // 修改table中的工号为当前配置的工号 foreach (DataRow row in dTable.Rows) { if (row.RowState == DataRowState.Deleted) { continue; } row["UserID"] = this.dkUserInfo.UserID.Value; row["UserCode"] = this.dkUserInfo.UserCode; if (row["UJobsId"].ToString() == string.Empty && row["StaffCode"].ToString() == string.Empty) { continue; } if (row["UJobsId"].ToString() == string.Empty) { MessageBox.Show("请为所有员工配置工种!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } if (row["StaffCode"].ToString() == "") { MessageBox.Show("请为已选择工种配置员工!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } } frmse.AccountDate = Convert.ToDateTime(this.dtpAccountDate.Text); frmse.ClassRemarks = this.txtRemarks.Text.Trim(); // 调用服务器端获取数据集 ServiceResultEntity sreclass = DoAsync(() => { return PCModuleProxyNew.Service.SetFPC0402SData(frmse,saveStatus, (DataTable)dgvClassesDetail.DataSource); } ); if (sreclass.Status == Constant.ServiceResultStatus.Success) { //this.DataSource = sreclass.Data; // 保存成功提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "班次配置", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.InitializationForm(); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 取消按钮 /// /// /// private void btnCancel_Click(object sender, EventArgs e) { if (this._returnRow > Constant.INT_IS_ZERO) { this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { this.DialogResult = System.Windows.Forms.DialogResult.Cancel; } } #endregion #region 私有方法 /// /// 验证输入格式是否正确 /// /// private bool CheckInputValidity() { // 验证员工信息是否录入; if (string.IsNullOrEmpty(this.dkUserInfo.Text.Trim())) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工号"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.dkUserInfo.Focus(); return false; } if (this.dgvClassesDetail.RowCount <= Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "员工信息"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.dgvClassesDetail.Focus(); return false; } return true; } /// /// 清空输入项 /// private void InitializationForm() { if (this._editStatus == Constant.FormMode.Add) { this.dkUserInfo.Text = ""; this.txtRemarks.Clear(); this.dgvClassesDetail.DataSource = null; } else { this.DialogResult = System.Windows.Forms.DialogResult.OK; } this.btnSave.Enabled = false; } /// /// 绑定用户工种 /// private void BindUserJobs() { try { //获取可选择的工种数据源 this.txtRemarks.Text = ""; DataSet userJobsData = new DataSet(); // 调用服务器端获取数据集 ServiceResultEntity sre = DoAsync(() => { return PCModuleProxyNew.Service.GetJobByUserId(Convert.ToInt32(this.dkUserInfo.UserID)); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { userJobsData = sre.Data; } this.UJobsId.DisplayMember = "UserJobsCodeName"; this.UJobsId.ValueMember = "UserJobsId"; this.UJobsId.DataSource = userJobsData.Tables[0]; this._userJobsTable = userJobsData.Tables[0]; //获取用户班次配置信息 FPC0401_SE se = new FPC0401_SE(); se.DateBegin =DateTime.Parse( dtpAccountDate.Value.ToString("yyyy-MM-dd") + " 0:0:0"); se.DateEnd =DateTime.Parse( dtpAccountDate.Value.ToString("yyyy-MM-dd") + " 23:59:59"); se.UserCode = dkUserInfo.UserCode; // 调用服务器端获取数据集 ServiceResultEntity sreclass = DoAsync(() => { return PCModuleProxyNew.Service.GetFPC0401SData(se); } ); if (sreclass.Status == Constant.ServiceResultStatus.Success) { this.DataSource = sreclass.Data; if (sreclass.Data == null) { //获取用户当前关联的员工关系数据源 saveStatus = 0; this.GetClassDetailData(); } } if (this.DataSource != null && this.DataSource.Tables.Count == 2) { this.txtRemarks.Text = this.DataSource.Tables[0].Rows[0]["remarks"].ToString(); frmse.ClassSettingID = this._classesSettingID; frmse.AccountDate = this.AccountDate; saveStatus = 1; //更新 this.btnSave.Enabled = false; if (this.DataSource.Tables[1] != null && this.DataSource.Tables[1].Rows.Count > 0) { dgvClassesDetail.DataSource = this.DataSource.Tables[1]; } else { //获取用户当前关联的员工关系数据源 this.GetClassDetailData(); } } } catch (Exception ex) { throw ex; } } /// /// 获取工号下的员工 /// /// private void GetClassDetailData() { int id = Convert.ToInt32(this.dkUserInfo.UserID); this.dgvClassesDetail.DataSource = null; // 调用服务器端获取数据集 ServiceResultEntity sre = DoAsync(() => { return PCModuleProxyNew.Service.GetFPC0402SData(id); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { this.dgvClassesDetail.DataSource = sre.Data.Tables[0];//this.DataSource.Tables[0]; this.btnSave.Enabled = true; } } /// /// 是否空表 /// /// private bool isWhiteTable() { foreach (DataGridViewRow gvrFor in this.dgvClassesDetail.Rows) { if ((gvrFor.Cells["UJobsId"].Value != null && gvrFor.Cells["UJobsId"].Value.ToString() != "") || (gvrFor.Cells["StaffCode"].Value != null && gvrFor.Cells["StaffCode"].Value.ToString() != "")) { return false; } } return true; } #endregion private void dtpAccountDate_ValueChanged(object sender, EventArgs e) { try { if(!string.IsNullOrEmpty(dkUserInfo.Text.Trim())) { this.btnSave.Enabled = false; int userId = this.dkUserInfo.UserID.Value; BindUserJobs(); this.dgvClassesDetail.AllowUserToAddRows = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void dgvClassesDetail_UserDeletedRow(object sender, DataGridViewRowEventArgs e) { this.btnSave.Enabled = true; } private void txtRemarks_TextChanged(object sender, EventArgs e) { this.btnSave.Enabled = true; } } }