| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- /*******************************************************************************
- * 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
- {
- /// <summary>
- /// 班次配置新建\编辑窗体
- /// </summary>
- 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 属性
- /// <summary>
- /// 备注
- /// </summary>
- public string Remark
- {
- get { return _remark; }
- set { _remark = value; }
- }
- /// <summary>
- /// 工号名称
- /// </summary>
- public string UserName1
- {
- get { return _userName; }
- set { _userName = value; }
- }
- /// <summary>
- /// 班次配置ID
- /// </summary>
- public int ClassesSettingID
- {
- get { return _classesSettingID; }
- set { _classesSettingID = value; }
- }
- /// <summary>
- /// 工号ID
- /// </summary>
- public int UserId
- {
- get { return _userId; }
- set { _userId = value; }
- }
- /// <summary>
- /// 工号编号
- /// </summary>
- public string UserCode
- {
- get { return _userCode; }
- set { _userCode = value; }
- }
- public DateTime AccountDate
- {
- get { return _accountdate; }
- set { _accountdate = value; }
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="editStatus">新建/编辑</param>
- /// <param name="pUserId">要编辑的员工编号</param>
- 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 事件
- /// <summary>
- /// 页面加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 自动适应列宽
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvClassesDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- /// <summary>
- /// 关闭按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 工号ValueChanged事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<ServiceResultEntity>(() =>
- {
- 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);
- }
- }
- /// <summary>
- /// 员工编号值改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 单元格编辑时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 保存按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<ServiceResultEntity>(() =>
- {
- 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<ServiceResultEntity>(() =>
- {
- 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);
- }
- }
- /// <summary>
- /// 取消按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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 私有方法
- /// <summary>
- /// 验证输入格式是否正确
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 清空输入项
- /// </summary>
- 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;
- }
- /// <summary>
- /// 绑定用户工种
- /// </summary>
- private void BindUserJobs()
- {
- try
- {
- //获取可选择的工种数据源
- this.txtRemarks.Text = "";
- DataSet userJobsData = new DataSet();
- // 调用服务器端获取数据集
- ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
- {
- 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<ServiceResultEntity>(() =>
- {
- 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;
- }
- }
- /// <summary>
- /// 获取工号下的员工
- /// </summary>
- /// <returns></returns>
- private void GetClassDetailData()
- {
- int id = Convert.ToInt32(this.dkUserInfo.UserID);
- this.dgvClassesDetail.DataSource = null;
- // 调用服务器端获取数据集
- ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
- {
- 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;
- }
- }
- /// <summary>
- /// 是否空表
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- }
|