F_PC_0602.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /*******************************************************************************
  2. * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_0602.cs
  5. * 2.功能描述:新增/编辑员工关联
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 袁新成 2015/04/17 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.Client.Controls;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. namespace Dongke.IBOSS.PRD.Client.PCModule
  20. {
  21. /// <summary>
  22. /// 新增/编辑员工关联
  23. /// </summary>
  24. public partial class F_PC_0602 : DKFormBase
  25. {
  26. #region 成员变量
  27. // 打开选择窗体的标识
  28. private bool _showFromFlag = true;
  29. // 选中的员工编码
  30. private string _staffCode;
  31. // 选中的工号ID
  32. private int? _userId;
  33. // 选中的工号编码
  34. private string _userCode;
  35. // 页面数据源
  36. private DataTable _dtSourse = new DataTable();
  37. // 当前工号的工种集合
  38. private DataTable _userJobsTable = new DataTable();
  39. #endregion
  40. #region 构造函数
  41. public F_PC_0602(int? UserId, string UserCode)
  42. {
  43. InitializeComponent();
  44. if (UserId == null)
  45. {
  46. this.Text = FormTitles.F_PC_0602_ADD;
  47. }
  48. else
  49. {
  50. this.Text = FormTitles.F_PC_0602_EDIT;
  51. }
  52. this.btnSave.Text = ButtonText.BTN_SAVE;
  53. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  54. this._userId = UserId;
  55. this._userCode = UserCode;
  56. this.btnSave.Enabled = false;
  57. }
  58. #endregion
  59. #region 事件
  60. /// <summary>
  61. /// 单元格值改变事件
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  66. {
  67. try
  68. {
  69. if (e.RowIndex != -Constant.INT_IS_ONE)
  70. {
  71. if (!_showFromFlag)
  72. {
  73. return;
  74. }
  75. btnSave.Enabled = true;
  76. DataGridViewRow rowItem = this.dgvDataJobs.Rows[e.RowIndex];
  77. DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
  78. // 用编号获取员工信息
  79. if (columnItem.Name == "StaffCode"
  80. && !string.IsNullOrEmpty(this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""))
  81. {
  82. _showFromFlag = false;
  83. FormUtility.BindStaffRowDataSource(this.dgvDataJobs,
  84. e.RowIndex, columnItem.Name, this._staffCode, this.dkUser.UserID.Value, true);
  85. _showFromFlag = true;
  86. for (int i = 0; i < this.dgvDataJobs.Rows.Count; i++)
  87. {
  88. if (i != e.RowIndex)
  89. {
  90. if (this.dgvDataJobs.Rows[i].IsNewRow == true)
  91. {
  92. return;
  93. }
  94. String NowStaffID = this.dgvDataJobs.Rows[e.RowIndex].Cells["StaffID"].Value.ToString();
  95. if (NowStaffID == "")
  96. {
  97. this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
  98. return;
  99. }
  100. String ForStaffID = "";
  101. if (this.dgvDataJobs.Rows[i].Cells["StaffID"].Value != null)
  102. {
  103. ForStaffID = this.dgvDataJobs.Rows[i].Cells["StaffID"].Value.ToString();
  104. }
  105. if (NowStaffID == ForStaffID)
  106. {
  107. this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
  108. //仅限当前页面,工号间的待修改
  109. MessageBox.Show("员工信息不可重复配置!", this.Text,
  110. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  111. return;
  112. }
  113. }
  114. }
  115. }
  116. else if (columnItem.Name == "UserJobsCode")
  117. {
  118. string JobsCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  119. if (JobsCode != string.Empty && JobsCode != null)
  120. {
  121. DataTable TableCopy = _userJobsTable.Copy();
  122. TableCopy.DefaultView.RowFilter = "UserJobsId='" + JobsCode + "'";
  123. DataTable EndTable = TableCopy.DefaultView.ToTable();
  124. if (EndTable.Rows.Count != 0)
  125. {
  126. this.dgvDataJobs.Rows[e.RowIndex].Cells["UserJobsName"].Value = EndTable.Rows[0]["UserJobsName"].ToString();
  127. this.dgvDataJobs.Rows[e.RowIndex].Cells["UserJobsID"].Value = EndTable.Rows[0]["UserJobsID"].ToString();
  128. }
  129. else
  130. {
  131. ((DataTable)this.dgvDataJobs.DataSource).Rows[e.RowIndex].Delete();
  132. }
  133. }
  134. }
  135. if ((rowItem.Cells["StaffCode"].Value == null || rowItem.Cells["StaffCode"].Value == DBNull.Value)
  136. && (rowItem.Cells["UserJobsCode"].Value == null || rowItem.Cells["UserJobsCode"].Value == DBNull.Value))
  137. {
  138. this.dgvDataJobs.Rows.Remove(rowItem);
  139. }
  140. }
  141. }
  142. catch (Exception ex)
  143. {
  144. this._showFromFlag = true;
  145. // 对异常进行共通处理
  146. ExceptionManager.HandleEventException(this.ToString(),
  147. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  148. }
  149. }
  150. /// <summary>
  151. /// 单元格开始编辑事件
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void dgvDataJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  156. {
  157. try
  158. {
  159. if (e.RowIndex != -Constant.INT_IS_ONE)
  160. {
  161. DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
  162. if ("StaffCode".Equals(columnItem.Name))
  163. {
  164. this._staffCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  165. }
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. // 对异常进行共通处理
  171. ExceptionManager.HandleEventException(this.ToString(),
  172. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  173. }
  174. }
  175. /// <summary>
  176. /// 窗体加载事件
  177. /// </summary>
  178. /// <param name="sender"></param>
  179. /// <param name="e"></param>
  180. private void F_PC_0602_Load(object sender, EventArgs e)
  181. {
  182. try
  183. {
  184. this.dgvDataJobs.AutoGenerateColumns = false;
  185. if (this._userId != null)
  186. {
  187. this.dkUser.UserID = this._userId;
  188. this.dkUser.UserCode = this._userCode;
  189. this.dkUser.Text = this._userCode;
  190. }
  191. this.dgvDataJobs.IsSetInputColumnsColor = true;
  192. }
  193. catch (Exception ex)
  194. {
  195. throw ex;
  196. }
  197. }
  198. /// <summary>
  199. /// 工号值改变事件
  200. /// </summary>
  201. /// <param name="sender"></param>
  202. /// <param name="e"></param>
  203. private void dkUser_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e)
  204. {
  205. try
  206. {
  207. BindUserJobs();
  208. this.dkUser.Enabled = false;
  209. this.dgvDataJobs.Enabled = true;
  210. this.dgvDataJobs.IsSetInputColumnsColor = true;
  211. }
  212. catch (Exception ex)
  213. {
  214. // 对异常进行共通处理
  215. ExceptionManager.HandleEventException(this.ToString(),
  216. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  217. }
  218. }
  219. /// <summary>
  220. /// 保存按钮事件
  221. /// </summary>
  222. /// <param name="sender"></param>
  223. /// <param name="e"></param>
  224. private void btnSave_Click(object sender, EventArgs e)
  225. {
  226. try
  227. {
  228. if (this.dgvDataJobs.Rows.Count == Constant.INT_IS_ZERO || this.dkUser.UserID == null)
  229. {
  230. return;
  231. }
  232. //信息必填
  233. foreach (DataGridViewRow gvrFor in this.dgvDataJobs.Rows)
  234. {
  235. if (gvrFor.IsNewRow != true)
  236. {
  237. if (gvrFor.Cells["UserJobsID"].Value == null || gvrFor.Cells["UserJobsID"].Value == DBNull.Value)
  238. {
  239. MessageBox.Show("请为所有员工配置工种!",
  240. this.Text,
  241. MessageBoxButtons.OK,
  242. MessageBoxIcon.Information,
  243. MessageBoxDefaultButton.Button1);
  244. return;
  245. }
  246. if (gvrFor.Cells["StaffID"].Value == null || gvrFor.Cells["StaffID"].Value == DBNull.Value)
  247. {
  248. MessageBox.Show("请为已选择工种配置员工!",
  249. this.Text,
  250. MessageBoxButtons.OK,
  251. MessageBoxIcon.Information,
  252. MessageBoxDefaultButton.Button1);
  253. return;
  254. }
  255. }
  256. }
  257. // 获取成型线类型数据并绑定到控件上
  258. ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
  259. {
  260. return PCModuleProxyNew.Service.SetFPC0602Data(Convert.ToInt32(this.dkUser.UserID), this.DataSource);
  261. }
  262. );
  263. if (sre.Status == Constant.ServiceResultStatus.Other)
  264. {
  265. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
  266. this.DialogResult = DialogResult.Cancel;
  267. this.Close();
  268. return;
  269. }
  270. if (sre.Status != Constant.ServiceResultStatus.Success)
  271. {
  272. return;
  273. }
  274. if (sre.Status == Constant.ServiceResultStatus.Success)
  275. {
  276. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工关联", "保存"),
  277. this.Text,
  278. MessageBoxButtons.OK,
  279. MessageBoxIcon.Information,
  280. MessageBoxDefaultButton.Button1);
  281. this.DialogResult = DialogResult.OK;
  282. }
  283. /*
  284. int ReturnRows = SystemModuleProxy.Service.AddUserStaff(Convert.ToInt32(this.dkUser.UserID), (DataTable)this.dgvDataJobs.DataSource);
  285. if (ReturnRows > Constant.INT_IS_ZERO)
  286. {
  287. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工关联", "保存"),
  288. this.Text,
  289. MessageBoxButtons.OK,
  290. MessageBoxIcon.Information,
  291. MessageBoxDefaultButton.Button1);
  292. this.DialogResult = DialogResult.OK;
  293. }
  294. else
  295. {
  296. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工关联", "保存"),
  297. this.Text,
  298. MessageBoxButtons.OK,
  299. MessageBoxIcon.Information,
  300. MessageBoxDefaultButton.Button1);
  301. }
  302. */
  303. }
  304. catch (Exception ex)
  305. {
  306. throw ex;
  307. }
  308. }
  309. /// <summary>
  310. /// 取消按钮事件
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void btnCancel_Click(object sender, EventArgs e)
  315. {
  316. this.Close();
  317. }
  318. /// <summary>
  319. /// 添加行事件
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void dgvDataJobs_UserAddedRow(object sender, DataGridViewRowEventArgs e)
  324. {
  325. this.dgvDataJobs.IsSetInputColumnsColor = true;
  326. }
  327. #endregion
  328. #region 私有方法
  329. /*
  330. /// <summary>
  331. /// 根据工号ID获取该工号的工种关联
  332. /// </summary>
  333. /// <returns></returns>
  334. private DataSet GetUserRowData()
  335. {
  336. try
  337. {
  338. return SystemModuleProxy.Service.GetJobByUserId(Convert.ToInt32(this.dkUser.UserID));
  339. }
  340. catch (Exception ex)
  341. {
  342. throw ex;
  343. }
  344. }
  345. */
  346. /// <summary>
  347. /// 绑定工种
  348. /// </summary>
  349. private void BindUserJobs()
  350. {
  351. try
  352. {
  353. //获取可选择的工种数据源
  354. DataSet userJobsData=new DataSet();
  355. // 调用服务器端获取数据集
  356. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  357. {
  358. return PCModuleProxyNew.Service.GetJobByUserId(Convert.ToInt32(this.dkUser.UserID));
  359. }
  360. );
  361. if (sre.Status == Constant.ServiceResultStatus.Success)
  362. {
  363. userJobsData = sre.Data;
  364. }
  365. this.UserJobsCode.DisplayMember = "UserJobsCodeName";
  366. this.UserJobsCode.ValueMember = "UserJobsId";
  367. this.UserJobsCode.DataSource = userJobsData.Tables[0];
  368. this._userJobsTable = userJobsData.Tables[0];
  369. //获取用户当前关联的员工关系数据源
  370. this.GetUserStaffData();
  371. }
  372. catch (Exception ex)
  373. {
  374. throw ex;
  375. }
  376. }
  377. /// <summary>
  378. /// 获取工号下的员工
  379. /// </summary>
  380. /// <returns></returns>
  381. private void GetUserStaffData()
  382. {
  383. int id = Convert.ToInt32(this.dkUser.UserID);
  384. this.dgvDataJobs.DataSource = null;
  385. // 调用服务器端获取数据集
  386. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  387. {
  388. return PCModuleProxyNew.Service.GetFPC0601SNData(id);
  389. }
  390. );
  391. if (sre.Status == Constant.ServiceResultStatus.Success)
  392. {
  393. this.DataSource = sre.Data;
  394. this.dgvDataJobs.DataSource = this.DataSource.Tables[0];// sre.Data.Tables[0];
  395. }
  396. }
  397. #endregion
  398. private void dgvDataJobs_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
  399. {
  400. btnSave.Enabled = true;
  401. }
  402. }
  403. }