F_TAT_0102.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_TAT_0102.cs
  5. * 2.功能描述:缺陷扣罚策略明细
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/11/18 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. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.TATModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.TATModule
  22. {
  23. /// <summary>
  24. /// 缺陷扣罚策略明细
  25. /// </summary>
  26. public partial class F_TAT_0102 : FormBase
  27. {
  28. #region 成员变量
  29. // 窗体模式ID
  30. private Constant.FormMode _formType;
  31. // 操作实体ID
  32. private int? _entityId;
  33. // 选择窗体弹出标识
  34. private bool _showFlag = true;
  35. // 数据源
  36. private DataSet _dsSourse;
  37. // 产品数据源
  38. private DataTable _dtGoodsSourse;
  39. // 窗体加载完毕标识
  40. private bool _pageLoadOK = false;
  41. #endregion
  42. #region 构造函数
  43. /// <summary>
  44. /// 窗体构造
  45. /// </summary>
  46. /// <param name="formType">窗体开启模式</param>
  47. /// <param name="entityId">操作实体ID</param>
  48. public F_TAT_0102(Constant.FormMode formType, int entityId)
  49. {
  50. InitializeComponent();
  51. this._formType = formType;
  52. this._entityId = entityId;
  53. this.Text = FormTitles.F_TAT_0102;
  54. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  55. this.tsbtnCreateJobs.Text = ButtonText.TSBTN_CREATEJOBS;
  56. this.tsbtnCreateGoods.Text = ButtonText.TSBTN_CREATEGOODS;
  57. this.btnEdit.Text = ButtonText.BTN_EDIT;
  58. }
  59. #endregion
  60. #region 事件
  61. /// <summary>
  62. /// 窗体加载
  63. /// </summary>
  64. /// <param name="sender"></param>
  65. /// <param name="e"></param>
  66. private void F_TAT_0102_Load(object sender, EventArgs e)
  67. {
  68. try
  69. {
  70. //绑定产品信息
  71. this.GetGoods();
  72. //绑定数据源与列表
  73. this.BindData();
  74. this.dgvJobs.AutoGenerateColumns = false;
  75. this.dgvGoods.AutoGenerateColumns = false;
  76. //页面加载完毕
  77. this._pageLoadOK = true;
  78. //如果是审核及观看模式
  79. if (this._formType == Constant.FormMode.Display)
  80. {
  81. //列表设置为只读
  82. this.dgvGoods.ReadOnly = true;
  83. this.dgvJobs.ReadOnly = true;
  84. this.dgvGoods.AllowUserToDeleteRows = false;
  85. this.dgvJobs.AllowUserToDeleteRows = false;
  86. //控件除关闭外全部不可用
  87. this.tsbtnCreateGoods.Enabled = false;
  88. this.tsbtnCreateJobs.Enabled = false;
  89. this.btnEdit.Enabled = false;
  90. this.txtMoney.Enabled = false;
  91. this.btnSave.Enabled = false;
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. // 对异常进行共通处理
  97. ExceptionManager.HandleEventException(this.ToString(),
  98. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  99. }
  100. }
  101. /// <summary>
  102. /// 工种列表值变更
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. private void dgvJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  107. {
  108. try
  109. {
  110. //变更后重新加载
  111. this._pageLoadOK = false;
  112. if (this.dgvJobs.Rows.Count <= Constant.INT_IS_ONE || !this._showFlag)
  113. {
  114. return;
  115. }
  116. DataGridViewRow rowItem = this.dgvJobs.Rows[e.RowIndex];
  117. DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex];
  118. //打开多选页面进行值绑定
  119. this._showFlag = false;
  120. FormUtility.BindJobsRowDataSource(this.dgvJobs,
  121. e.RowIndex, columnItem.Name, string.Empty);
  122. this._showFlag = true;
  123. //根据工种信息绑定明细信息
  124. this.BindDetail();
  125. //加载OK
  126. this._pageLoadOK = true;
  127. // 设置可输入单元格的颜色
  128. this.dgvJobs.IsSetInputColumnsColor = true;
  129. this.dgvGoods.IsSetInputColumnsColor = true;
  130. }
  131. catch (Exception ex)
  132. {
  133. // 对异常进行共通处理
  134. ExceptionManager.HandleEventException(this.ToString(),
  135. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  136. }
  137. }
  138. /// <summary>
  139. /// 关闭窗体
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void btnCancel_Click(object sender, EventArgs e)
  144. {
  145. this.Close();
  146. }
  147. /// <summary>
  148. /// 保存操作
  149. /// </summary>
  150. /// <param name="sender"></param>
  151. /// <param name="e"></param>
  152. private void btnSave_Click(object sender, EventArgs e)
  153. {
  154. try
  155. {
  156. //提交操作
  157. ServiceResultEntity srEntity =
  158. (ServiceResultEntity)DoAsync(() =>
  159. {
  160. return TATModuleProxy.Service.EditDefectFineDetail(Convert.ToInt32(this._entityId), this._dsSourse);
  161. });
  162. ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
  163. if (srEntity.Status == Constant.ServiceResultStatus.Success)
  164. {
  165. this.DialogResult = DialogResult.OK;
  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 tsbtnCreateJobs_Click(object sender, EventArgs e)
  181. {
  182. try
  183. {
  184. //需重新加载
  185. this._pageLoadOK = false;
  186. //这句话,因为新建的时候,莫名其妙会多出一个数据源不存在的空行,这样设定就不会出现了。
  187. this.dgvJobs.AllowUserToAddRows = false;
  188. //获取全部工种
  189. DataSet dsJobs = (DataSet)DoAsync(() =>
  190. {
  191. return SystemModuleProxy.Service.GetJobsData(1);
  192. });
  193. //如果获取到了工种
  194. if (dsJobs != null && dsJobs.Tables.Count != Constant.INT_IS_ZERO)
  195. {
  196. //循环生成工种信息并加入到数据源中
  197. foreach (DataRow drFor in dsJobs.Tables[0].Rows)
  198. {
  199. //首先查看该工种在现有数据源中是否存在
  200. int JobIsHave = 0;
  201. foreach (DataRow drSourse in this._dsSourse.Tables[0].Rows)
  202. {
  203. if (drSourse.RowState == DataRowState.Deleted)
  204. {
  205. continue;
  206. }
  207. int drForJobsId = Convert.ToInt32(drFor["JobsId"]);
  208. int drSourseJobsId = Convert.ToInt32(drSourse["JobsId"]);
  209. if (drForJobsId == drSourseJobsId)
  210. {
  211. JobIsHave++;
  212. break;
  213. }
  214. }
  215. //如果不存在才重新生成
  216. if (JobIsHave == 0 && drFor["JobsId"] != DBNull.Value)
  217. {
  218. DataRow drJobs = _dsSourse.Tables[0].NewRow();
  219. drJobs["JobsId"] = drFor["JobsId"];
  220. drJobs["JobsCode"] = drFor["JobsCode"];
  221. drJobs["JobsName"] = drFor["JobsName"];
  222. this._dsSourse.Tables[0].Rows.Add(drJobs);
  223. }
  224. }
  225. //绑定
  226. this.dgvJobs.AutoGenerateColumns = false;
  227. this.dgvJobs.DataSource = this._dsSourse.Tables[0];
  228. //并根据工种生成明细
  229. this.BindDetail();
  230. this.dgvGoods.IsSetInputColumnsColor = true;
  231. }
  232. //加载完毕
  233. this._pageLoadOK = true;
  234. this.dgvJobs.AllowUserToAddRows = true;
  235. this.dgvJobs.IsSetInputColumnsColor = true;
  236. }
  237. catch (Exception ex)
  238. {
  239. // 对异常进行共通处理
  240. ExceptionManager.HandleEventException(this.ToString(),
  241. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  242. }
  243. }
  244. /// <summary>
  245. /// 为某工种添加明细信息
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void tsbtnCreateGoods_Click(object sender, EventArgs e)
  250. {
  251. try
  252. {
  253. //如果选择了一个有效工种
  254. if (this.dgvJobs.SelectedRows.Count != Constant.INT_IS_ZERO && this.dgvJobs.SelectedRows[0].IsNewRow == false)
  255. {
  256. //获取工种ID
  257. DataGridViewRow gvrSelected = this.dgvJobs.SelectedRows[0];
  258. int JobsId = Convert.ToInt32(gvrSelected.Cells["JobsId"].Value);
  259. //遍历产品明细添加该工种的所有明细信息
  260. foreach (DataRow drFor in this._dtGoodsSourse.Rows)
  261. {
  262. //首先查看该产品是否已存在
  263. int GoodsIsHave = 0;
  264. foreach (DataGridViewRow gvrFor in this.dgvGoods.Rows)
  265. {
  266. if (Convert.ToInt32(gvrFor.Cells["GoodsID"].Value)
  267. == Convert.ToInt32(drFor["GoodsID"]))
  268. {
  269. GoodsIsHave++;
  270. break;
  271. }
  272. }
  273. //如果不存在才进行添加
  274. if (GoodsIsHave == 0)
  275. {
  276. //向最终数据源添加扣罚明细信息
  277. DataRow drDetail = this._dsSourse.Tables[1].NewRow();
  278. drDetail["JobsId"] = gvrSelected.Cells["JobsId"].Value;
  279. drDetail["GoodsID"] = drFor["GoodsId"];
  280. drDetail["GoodsCode"] = drFor["GoodsCode"];
  281. drDetail["GoodsName"] = drFor["GoodsName"];
  282. drDetail["FineAmount"] = 0;
  283. this._dsSourse.Tables[1].Rows.Add(drDetail);
  284. }
  285. }
  286. this.dgvGoods.IsSetInputColumnsColor = true;
  287. }
  288. else
  289. {
  290. //提示用户先选中一行工种信息
  291. MessageBox.Show(Messages.MSG_TAT_W001, this.Text,
  292. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  293. }
  294. }
  295. catch (Exception ex)
  296. {
  297. // 对异常进行共通处理
  298. ExceptionManager.HandleEventException(this.ToString(),
  299. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  300. }
  301. }
  302. /// <summary>
  303. /// 工种删除
  304. /// </summary>
  305. /// <param name="sender"></param>
  306. /// <param name="e"></param>
  307. private void dgvJobs_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  308. {
  309. try
  310. {
  311. //获取删除的工种ID
  312. int JobsId = Convert.ToInt32(e.Row.Cells["JobsId"].Value);
  313. //将该工种对应的明细信息全部删除
  314. this.DeleteGoods(JobsId);
  315. }
  316. catch (Exception ex)
  317. {
  318. // 对异常进行共通处理
  319. ExceptionManager.HandleEventException(this.ToString(),
  320. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  321. }
  322. }
  323. /// <summary>
  324. /// 批量更新扣罚金额
  325. /// </summary>
  326. /// <param name="sender"></param>
  327. /// <param name="e"></param>
  328. private void btnEdit_Click(object sender, EventArgs e)
  329. {
  330. try
  331. {
  332. if (!string.IsNullOrWhiteSpace(this.txtMoney.Text))
  333. {
  334. //批量更新现工种对应的明细信息
  335. foreach (DataGridViewRow gvrFor in this.dgvGoods.Rows)
  336. {
  337. gvrFor.Cells["FineAmount"].Value = this.txtMoney.Text;
  338. }
  339. this.dgvGoods.Focus();
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. // 对异常进行共通处理
  345. ExceptionManager.HandleEventException(this.ToString(),
  346. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  347. }
  348. }
  349. /// <summary>
  350. /// 产品编号变更
  351. /// </summary>
  352. /// <param name="sender"></param>
  353. /// <param name="e"></param>
  354. private void dgvGoods_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  355. {
  356. try
  357. {
  358. if (this.dgvGoods.Rows.Count <= Constant.INT_IS_ONE)
  359. {
  360. return;
  361. }
  362. DataGridViewRow rowItem = this.dgvGoods.Rows[e.RowIndex];
  363. DataGridViewColumn columnItem = this.dgvGoods.Columns[e.ColumnIndex];
  364. // 用编号获取产品信息
  365. if ("GoodsCode".Equals(columnItem.Name))
  366. {
  367. FormUtility.BindGoodsRowDataSource(this.dgvGoods,
  368. e.RowIndex, columnItem.Name, string.Empty);
  369. // 设置可输入单元格的颜色
  370. this.dgvGoods.IsSetInputColumnsColor = true;
  371. }
  372. }
  373. catch (Exception ex)
  374. {
  375. // 对异常进行共通处理
  376. ExceptionManager.HandleEventException(this.ToString(),
  377. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  378. }
  379. }
  380. /// <summary>
  381. /// 工种选择变更
  382. /// </summary>
  383. /// <param name="sender"></param>
  384. /// <param name="e"></param>
  385. private void dgvJobs_SelectionChanged(object sender, EventArgs e)
  386. {
  387. try
  388. {
  389. this.dgvGoods.AutoGenerateColumns = false;
  390. //根据选择的工种绑定对应的明细信息
  391. if (this.dgvJobs.SelectedRows.Count != Constant.INT_IS_ZERO)
  392. {
  393. DataGridViewRow gvrNow = this.dgvJobs.SelectedRows[0];
  394. if (gvrNow.Cells["JobsId"].Value != DBNull.Value && gvrNow.Cells["JobsId"].Value != null)
  395. {
  396. DataTable dtDetail = this._dsSourse.Tables[1];
  397. dtDetail.DefaultView.RowFilter = "JobsId=" + gvrNow.Cells["JobsId"].Value.ToString();
  398. this.dgvGoods.DataSource = dtDetail;
  399. if (this._formType != Constant.FormMode.Display)
  400. {
  401. this.dgvGoods.IsSetInputColumnsColor = true;
  402. }
  403. }
  404. else
  405. {
  406. this.dgvGoods.DataSource = null;
  407. }
  408. }
  409. }
  410. catch (Exception ex)
  411. {
  412. // 对异常进行共通处理
  413. ExceptionManager.HandleEventException(this.ToString(),
  414. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  415. }
  416. }
  417. /// <summary>
  418. /// 窗体自适应
  419. /// </summary>
  420. /// <param name="sender"></param>
  421. /// <param name="e"></param>
  422. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  423. {
  424. this.dgvJobs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  425. this.dgvGoods.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  426. }
  427. #endregion
  428. #region 私有方法
  429. /// <summary>
  430. /// 绑定数据源
  431. /// </summary>
  432. private void BindData()
  433. {
  434. try
  435. {
  436. if (this._entityId != 0 && this._entityId != null)
  437. {
  438. ServiceResultEntity srEntity = TATModuleProxy.Service.GetDefectFineDetailById(Convert.ToInt32(this._entityId));
  439. if (srEntity.Data != null)
  440. {
  441. this._dsSourse = (DataSet)srEntity.Data;
  442. if (this._dsSourse.Tables.Count != Constant.INT_IS_TWO)
  443. {
  444. this.DialogResult = DialogResult.Cancel;
  445. }
  446. this.dgvJobs.DataSource = this._dsSourse.Tables[0];
  447. if (this._formType != Constant.FormMode.Display)
  448. {
  449. this.dgvJobs.IsSetInputColumnsColor = true;
  450. }
  451. }
  452. }
  453. }
  454. catch (Exception ex)
  455. {
  456. throw ex;
  457. }
  458. }
  459. /// <summary>
  460. /// 批量生成明细信息并绑定
  461. /// </summary>
  462. private void BindDetail()
  463. {
  464. try
  465. {
  466. //首先遍历选中的工种
  467. foreach (DataGridViewRow gvrFor in this.dgvJobs.Rows)
  468. {
  469. //新行不进行该操作
  470. if (gvrFor.IsNewRow)
  471. {
  472. return;
  473. }
  474. //已存在的工种不进行该操作
  475. if (gvrFor.Cells["isHave"].Value != DBNull.Value)
  476. {
  477. continue;
  478. }
  479. //向符合条件的工种添加全部产品信息
  480. foreach (DataRow drFor in this._dtGoodsSourse.Rows)
  481. {
  482. //向最终数据源添加扣罚明细信息
  483. if (gvrFor.Cells["JobsId"].Value != DBNull.Value)
  484. {
  485. DataRow drDetail = this._dsSourse.Tables[1].NewRow();
  486. drDetail["JobsId"] = gvrFor.Cells["JobsId"].Value;
  487. drDetail["GoodsID"] = drFor["GoodsId"];
  488. drDetail["GoodsCode"] = drFor["GoodsCode"];
  489. drDetail["GoodsName"] = drFor["GoodsName"];
  490. drDetail["FineAmount"] = 0;
  491. this._dsSourse.Tables[1].Rows.Add(drDetail);
  492. }
  493. }
  494. gvrFor.Cells["isHave"].Value = 1;
  495. }
  496. }
  497. catch (Exception ex)
  498. {
  499. throw ex;
  500. }
  501. }
  502. /// <summary>
  503. /// 获取全部产品信息
  504. /// </summary>
  505. private void GetGoods()
  506. {
  507. try
  508. {
  509. GoodsEntity goods = new GoodsEntity();
  510. goods.ValueFlag = 1;
  511. DataSet dsGoods = SystemModuleProxy.Service.SerachGoods(goods);
  512. if (dsGoods != null && dsGoods.Tables.Count != Constant.INT_IS_ZERO)
  513. {
  514. this._dtGoodsSourse = dsGoods.Tables[0];
  515. }
  516. }
  517. catch (Exception ex)
  518. {
  519. throw ex;
  520. }
  521. }
  522. /// <summary>
  523. /// 根据工种ID删除明细信息
  524. /// </summary>
  525. /// <param name="JobsId"></param>
  526. private void DeleteGoods(int JobsId)
  527. {
  528. try
  529. {
  530. //遍历全部明细信息
  531. for (int i = 0; i < this._dsSourse.Tables[1].Rows.Count; i++)
  532. {
  533. DataRow drFor = this._dsSourse.Tables[1].Rows[i];
  534. //如果是已存在的才需要删除,新建的会直接消失
  535. if (drFor.RowState != DataRowState.Deleted)
  536. {
  537. //如果是要删除的明细信息,进行移除并修改迭代变量
  538. int drJobsId = Convert.ToInt32(drFor["JobsId"]);
  539. if (drJobsId == JobsId)
  540. {
  541. this._dsSourse.Tables[1].Rows.Remove(drFor);
  542. i--;
  543. }
  544. }
  545. }
  546. }
  547. catch (Exception ex)
  548. {
  549. throw ex;
  550. }
  551. }
  552. #endregion
  553. }
  554. }