| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- /*******************************************************************************
- * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_PC_0602.cs
- * 2.功能描述:新增/编辑员工关联
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 袁新成 2015/04/17 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.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.PCModule
- {
- /// <summary>
- /// 新增/编辑员工关联
- /// </summary>
- public partial class F_PC_0602 : DKFormBase
- {
- #region 成员变量
- // 打开选择窗体的标识
- private bool _showFromFlag = true;
- // 选中的员工编码
- private string _staffCode;
- // 选中的工号ID
- private int? _userId;
- // 选中的工号编码
- private string _userCode;
- // 页面数据源
- private DataTable _dtSourse = new DataTable();
- // 当前工号的工种集合
- private DataTable _userJobsTable = new DataTable();
- #endregion
- #region 构造函数
- public F_PC_0602(int? UserId, string UserCode)
- {
- InitializeComponent();
- if (UserId == null)
- {
- this.Text = FormTitles.F_PC_0602_ADD;
- }
- else
- {
- this.Text = FormTitles.F_PC_0602_EDIT;
- }
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- this._userId = UserId;
- this._userCode = UserCode;
- this.btnSave.Enabled = false;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 单元格值改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- if (e.RowIndex != -Constant.INT_IS_ONE)
- {
- if (!_showFromFlag)
- {
- return;
- }
- btnSave.Enabled = true;
- DataGridViewRow rowItem = this.dgvDataJobs.Rows[e.RowIndex];
- DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
- // 用编号获取员工信息
- if (columnItem.Name == "StaffCode"
- && !string.IsNullOrEmpty(this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""))
- {
- _showFromFlag = false;
- FormUtility.BindStaffRowDataSource(this.dgvDataJobs,
- e.RowIndex, columnItem.Name, this._staffCode, this.dkUser.UserID.Value, true);
- _showFromFlag = true;
- for (int i = 0; i < this.dgvDataJobs.Rows.Count; i++)
- {
- if (i != e.RowIndex)
- {
- if (this.dgvDataJobs.Rows[i].IsNewRow == true)
- {
- return;
- }
- String NowStaffID = this.dgvDataJobs.Rows[e.RowIndex].Cells["StaffID"].Value.ToString();
- if (NowStaffID == "")
- {
- this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
- return;
- }
- String ForStaffID = "";
- if (this.dgvDataJobs.Rows[i].Cells["StaffID"].Value != null)
- {
- ForStaffID = this.dgvDataJobs.Rows[i].Cells["StaffID"].Value.ToString();
- }
- if (NowStaffID == ForStaffID)
- {
- this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
- //仅限当前页面,工号间的待修改
- MessageBox.Show("员工信息不可重复配置!", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- }
- }
- else if (columnItem.Name == "UserJobsCode")
- {
- string JobsCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
- if (JobsCode != string.Empty && JobsCode != null)
- {
- DataTable TableCopy = _userJobsTable.Copy();
- TableCopy.DefaultView.RowFilter = "UserJobsId='" + JobsCode + "'";
- DataTable EndTable = TableCopy.DefaultView.ToTable();
- if (EndTable.Rows.Count != 0)
- {
- this.dgvDataJobs.Rows[e.RowIndex].Cells["UserJobsName"].Value = EndTable.Rows[0]["UserJobsName"].ToString();
- this.dgvDataJobs.Rows[e.RowIndex].Cells["UserJobsID"].Value = EndTable.Rows[0]["UserJobsID"].ToString();
- }
- else
- {
- ((DataTable)this.dgvDataJobs.DataSource).Rows[e.RowIndex].Delete();
- }
- }
- }
- if ((rowItem.Cells["StaffCode"].Value == null || rowItem.Cells["StaffCode"].Value == DBNull.Value)
- && (rowItem.Cells["UserJobsCode"].Value == null || rowItem.Cells["UserJobsCode"].Value == DBNull.Value))
- {
- this.dgvDataJobs.Rows.Remove(rowItem);
- }
- }
- }
- 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 dgvDataJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- if (e.RowIndex != -Constant.INT_IS_ONE)
- {
- DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
- if ("StaffCode".Equals(columnItem.Name))
- {
- this._staffCode = this.dgvDataJobs.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 F_PC_0602_Load(object sender, EventArgs e)
- {
- try
- {
- this.dgvDataJobs.AutoGenerateColumns = false;
- if (this._userId != null)
- {
- this.dkUser.UserID = this._userId;
- this.dkUser.UserCode = this._userCode;
- this.dkUser.Text = this._userCode;
- }
- this.dgvDataJobs.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 工号值改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dkUser_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e)
- {
- try
- {
- BindUserJobs();
- this.dkUser.Enabled = false;
- this.dgvDataJobs.Enabled = true;
- this.dgvDataJobs.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 btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvDataJobs.Rows.Count == Constant.INT_IS_ZERO || this.dkUser.UserID == null)
- {
- return;
- }
- //信息必填
- foreach (DataGridViewRow gvrFor in this.dgvDataJobs.Rows)
- {
- if (gvrFor.IsNewRow != true)
- {
- if (gvrFor.Cells["UserJobsID"].Value == null || gvrFor.Cells["UserJobsID"].Value == DBNull.Value)
- {
- MessageBox.Show("请为所有员工配置工种!",
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- return;
- }
- if (gvrFor.Cells["StaffID"].Value == null || gvrFor.Cells["StaffID"].Value == DBNull.Value)
- {
- MessageBox.Show("请为已选择工种配置员工!",
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- return;
- }
- }
- }
- // 获取成型线类型数据并绑定到控件上
- ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
- {
- return PCModuleProxyNew.Service.SetFPC0602Data(Convert.ToInt32(this.dkUser.UserID), this.DataSource);
- }
- );
- if (sre.Status == Constant.ServiceResultStatus.Other)
- {
- DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- return;
- }
- if (sre.Status != Constant.ServiceResultStatus.Success)
- {
- return;
- }
- if (sre.Status == Constant.ServiceResultStatus.Success)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工关联", "保存"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- this.DialogResult = DialogResult.OK;
- }
- /*
- int ReturnRows = SystemModuleProxy.Service.AddUserStaff(Convert.ToInt32(this.dkUser.UserID), (DataTable)this.dgvDataJobs.DataSource);
- if (ReturnRows > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工关联", "保存"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- this.DialogResult = DialogResult.OK;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工关联", "保存"),
- this.Text,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information,
- MessageBoxDefaultButton.Button1);
- }
- */
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 取消按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 添加行事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataJobs_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- this.dgvDataJobs.IsSetInputColumnsColor = true;
- }
- #endregion
- #region 私有方法
- /*
- /// <summary>
- /// 根据工号ID获取该工号的工种关联
- /// </summary>
- /// <returns></returns>
- private DataSet GetUserRowData()
- {
- try
- {
- return SystemModuleProxy.Service.GetJobByUserId(Convert.ToInt32(this.dkUser.UserID));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- */
- /// <summary>
- /// 绑定工种
- /// </summary>
- private void BindUserJobs()
- {
- try
- {
- //获取可选择的工种数据源
- DataSet userJobsData=new DataSet();
- // 调用服务器端获取数据集
- ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
- {
- return PCModuleProxyNew.Service.GetJobByUserId(Convert.ToInt32(this.dkUser.UserID));
- }
- );
- if (sre.Status == Constant.ServiceResultStatus.Success)
- {
- userJobsData = sre.Data;
- }
- this.UserJobsCode.DisplayMember = "UserJobsCodeName";
- this.UserJobsCode.ValueMember = "UserJobsId";
- this.UserJobsCode.DataSource = userJobsData.Tables[0];
- this._userJobsTable = userJobsData.Tables[0];
- //获取用户当前关联的员工关系数据源
- this.GetUserStaffData();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取工号下的员工
- /// </summary>
- /// <returns></returns>
- private void GetUserStaffData()
- {
- int id = Convert.ToInt32(this.dkUser.UserID);
- this.dgvDataJobs.DataSource = null;
- // 调用服务器端获取数据集
- ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
- {
- return PCModuleProxyNew.Service.GetFPC0601SNData(id);
- }
- );
- if (sre.Status == Constant.ServiceResultStatus.Success)
- {
- this.DataSource = sre.Data;
- this.dgvDataJobs.DataSource = this.DataSource.Tables[0];// sre.Data.Tables[0];
- }
- }
- #endregion
- private void dgvDataJobs_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
- {
- btnSave.Enabled = true;
- }
- }
- }
|