F_PM_2901.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_2901.cs
  5. * 2.功能描述:开模报损
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 周兴 2018/04/02 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. using Dongke.IBOSS.PRD.Basics.BaseControls;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. using Dongke.IBOSS.PRD.Client.Controls;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.Proxys;
  22. namespace Dongke.IBOSS.PRD.Client.PMModule
  23. {
  24. /// <summary>
  25. /// 注浆明细条码绑定
  26. /// </summary>
  27. public partial class F_PM_2901 : DKFormBase
  28. {
  29. #region 成员变量
  30. // 注浆日报ID
  31. private int _dailyId;
  32. // 注浆日期
  33. private DateTime _groutingDate = DateTime.Now.Date;
  34. #endregion
  35. #region 构造函数
  36. /// <summary>
  37. /// 构造函数
  38. /// </summary>
  39. public F_PM_2901()
  40. : this(0)
  41. {
  42. }
  43. /// <summary>
  44. /// 构造函数
  45. /// </summary>
  46. /// <param name="dailyID">注浆日报ID</param>
  47. public F_PM_2901(int dailyID)
  48. {
  49. this.InitializeComponent();
  50. this._dailyId = dailyID;
  51. this.InitializeControls();
  52. }
  53. #endregion
  54. #region 属性
  55. /// <summary>
  56. /// 注浆登记ID
  57. /// </summary>
  58. public List<int> GroutingDailyIDs
  59. {
  60. get;
  61. private set;
  62. }
  63. #endregion
  64. #region 事件
  65. /// <summary>
  66. /// 窗体加载
  67. /// </summary>
  68. private void F_PM_2901_Load(object sender, EventArgs e)
  69. {
  70. try
  71. {
  72. this.lblGroutingDateValue.Text = string.Empty;
  73. // 设置列表
  74. this.InitializeData();
  75. }
  76. catch (Exception ex)
  77. {
  78. // 对异常进行共通处理
  79. ExceptionManager.HandleEventException(this.ToString(),
  80. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  81. }
  82. }
  83. /// <summary>
  84. /// 全线注浆按钮按下,生成该成型班长的所有注浆信息
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void tsbtnGrouting_Click(object sender, EventArgs e)
  89. {
  90. try
  91. {
  92. F_PM_0105 frmPM0105 = new F_PM_0105();
  93. frmPM0105.IsBarCodeScrapReasonUseFlag = true;
  94. DialogResult dialogResult = frmPM0105.ShowDialog();
  95. if (dialogResult != DialogResult.OK)
  96. {
  97. return;
  98. }
  99. this._dailyId = frmPM0105.GroutingDailyID;
  100. this.InitializeData();
  101. }
  102. catch (Exception ex)
  103. {
  104. // 对异常进行共通处理
  105. ExceptionManager.HandleEventException(this.ToString(),
  106. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  107. }
  108. }
  109. /// <summary>
  110. /// 提交选择列内容的修改
  111. /// </summary>
  112. /// <param name="sender"></param>
  113. /// <param name="e"></param>
  114. private void dgvDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  115. {
  116. try
  117. {
  118. if (this.dgvDetail.CurrentRow != null && this.dgvDetail.IsCurrentCellDirty)
  119. {
  120. if ("ScrapFlag".Equals(this.dgvDetail.Columns
  121. [this.dgvDetail.CurrentCell.ColumnIndex].Name))
  122. {
  123. this.dgvDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
  124. }
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. // 对异常进行共通处理
  130. ExceptionManager.HandleEventException(this.ToString(),
  131. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  132. }
  133. }
  134. /// <summary>
  135. /// 损坯时,不能绑定条码
  136. /// </summary>
  137. private void dgvDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  138. {
  139. if (e.RowIndex < 0)
  140. {
  141. return;
  142. }
  143. try
  144. {
  145. DataGridViewRow dataGridViewRow = this.dgvDetail.Rows[e.RowIndex];
  146. if ("ScrapFlag".Equals(this.dgvDetail.Columns[e.ColumnIndex].Name))
  147. {
  148. // 未绑定时,如果是改变了损坯标识,则对绑定条码进行控制输入
  149. if (string.IsNullOrWhiteSpace(dataGridViewRow.Cells["colOBarCode"].Value + ""))
  150. {
  151. if (Convert.ToBoolean(dataGridViewRow.Cells["ScrapFlag"].EditedFormattedValue))
  152. {
  153. dataGridViewRow.Cells["SReasonID"].ReadOnly = false;
  154. }
  155. else
  156. {
  157. dataGridViewRow.Cells["SReasonID"].ReadOnly = true;
  158. dataGridViewRow.Cells["SReasonID"].Value = DBNull.Value;
  159. }
  160. this.dgvDetail.IsSetInputColumnsColor = true;
  161. }
  162. }
  163. }
  164. catch (Exception ex)
  165. {
  166. // 对异常进行共通处理
  167. ExceptionManager.HandleEventException(this.ToString(),
  168. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  169. }
  170. }
  171. /// <summary>
  172. /// 排序后设置Grid状态
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void dgvDetail_Sorted(object sender, EventArgs e)
  177. {
  178. this.SetEditGrid();
  179. }
  180. /// <summary>
  181. /// 自动列宽
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  186. {
  187. this.dgvDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  188. }
  189. /// <summary>
  190. /// 页面关闭
  191. /// </summary>
  192. /// <param name="sender"></param>
  193. /// <param name="e"></param>
  194. private void tsbtnClose_Click(object sender, EventArgs e)
  195. {
  196. this.DialogResult = DialogResult.Cancel;
  197. this.Close();
  198. }
  199. /// <summary>
  200. /// 绑定条码
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e"></param>
  204. private void txtBarCodeStart_KeyPress(object sender, KeyPressEventArgs e)
  205. {
  206. if (e.KeyChar == Constant.SYSTEM_KEYBOARD_ENTER_VALUE)
  207. {
  208. this.btnBindBarCode_Click(sender, e);
  209. }
  210. }
  211. /// <summary>
  212. /// 绑定报损原因
  213. /// </summary>
  214. /// <param name="sender"></param>
  215. /// <param name="e"></param>
  216. private void btnBindBarCode_Click(object sender, EventArgs e)
  217. {
  218. try
  219. {
  220. if (!string.IsNullOrWhiteSpace(this.cboSReason.SelectedValue + ""))
  221. {
  222. int sReasonID = Convert.ToInt32(this.cboSReason.SelectedValue);
  223. for (int i = 0; i < this.dgvDetail.Rows.Count; i++)
  224. {
  225. if (Convert.ToBoolean(this.dgvDetail.Rows[i].Cells["ScrapFlag"].EditedFormattedValue))
  226. {
  227. this.dgvDetail.Rows[i].Cells["SReasonID"].Value = sReasonID;
  228. }
  229. }
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. // 对异常进行共通处理
  235. ExceptionManager.HandleEventException(this.ToString(),
  236. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  237. }
  238. }
  239. /// <summary>
  240. /// 清空条码
  241. /// </summary>
  242. /// <param name="sender"></param>
  243. /// <param name="e"></param>
  244. private void btnClearBarCode_Click(object sender, EventArgs e)
  245. {
  246. try
  247. {
  248. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  249. {
  250. row.Cells["SReasonID"].Value = DBNull.Value;
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. // 对异常进行共通处理
  256. ExceptionManager.HandleEventException(this.ToString(),
  257. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  258. }
  259. }
  260. /// <summary>
  261. /// 保存数据
  262. /// </summary>
  263. private void btnSave_Click(object sender, EventArgs e)
  264. {
  265. // 没有注浆数据
  266. if (this.DataSource == null || this._dailyId <= 0)
  267. {
  268. return;
  269. }
  270. try
  271. {
  272. // 校验数据
  273. if (!IsValidData())
  274. {
  275. return;
  276. }
  277. ClientRequestEntity cre = new ClientRequestEntity();
  278. cre.NameSpace = "GroutingScrapProduct";
  279. cre.Name = "SaveScrapKm";
  280. cre.Data = this.DataSource;
  281. ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
  282. {
  283. return PMModuleProxyNew.Service.HandleRequest(cre);
  284. }
  285. );
  286. if (sre.Status == Constant.ServiceResultStatus.Success)
  287. {
  288. if (string.IsNullOrWhiteSpace(sre.Message))
  289. {
  290. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "开模报损", "保存"),
  291. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  292. }
  293. else
  294. {
  295. MessageBox.Show("开模报损保存成功,但有部分商品未成功;具体信息如下【" + sre.Message + "】。",
  296. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  297. }
  298. if (this.GroutingDailyIDs == null)
  299. {
  300. this.GroutingDailyIDs = new List<int>();
  301. }
  302. this.GroutingDailyIDs.Add(this._dailyId);
  303. //this.DialogResult = DialogResult.OK;
  304. //this.Close();
  305. this._dailyId = 0;
  306. this.lblGroutingDateValue.Text = string.Empty;
  307. this.txtGrouting.Clear();
  308. this.dgvDetail.DataSource = null;
  309. this.btnSave.Enabled = false;
  310. return;
  311. }
  312. else if (sre.Status == Constant.ServiceResultStatus.Other)
  313. {
  314. int resultRow = (int)sre.Result;
  315. if (resultRow == -99)
  316. {
  317. MessageBox.Show(string.Format(Messages.W_CMN_C_006, "未查询到该产品信息,请确认该产品是否已经进行注浆"),
  318. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  319. }
  320. else
  321. {
  322. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
  323. }
  324. }
  325. this.SetEditGrid();
  326. }
  327. catch (Exception ex)
  328. {
  329. this.SetEditGrid();
  330. // 对异常进行共通处理
  331. ExceptionManager.HandleEventException(this.ToString(),
  332. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  333. }
  334. }
  335. /// <summary>
  336. /// 关闭窗体
  337. /// </summary>
  338. private void btnCancel_Click(object sender, EventArgs e)
  339. {
  340. this.DialogResult = DialogResult.Cancel;
  341. this.Close();
  342. }
  343. #endregion
  344. #region 私有方法
  345. /// <summary>
  346. /// 初始化控件
  347. /// </summary>
  348. private void InitializeControls()
  349. {
  350. this.Text = FormTitles.F_PM_2901;
  351. // 功能按钮文本赋值
  352. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  353. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  354. this.btnSave.Text = ButtonText.BTN_SAVE;
  355. this.btnClose.Text = ButtonText.BTN_CLOSE;
  356. this.dgvDetail.AutoGenerateColumns = false;
  357. this.lblGroutingDateValue.Text = string.Empty;
  358. this.btnBindBarCode.Text = ButtonText.BTN_BINDSCRAPREASON;
  359. this.btnClearBarCode.Text = ButtonText.BTN_CLEARSCRAPREASON;
  360. this.btnBindBarCode.Enabled = false;
  361. this.btnClearBarCode.Enabled = false;
  362. }
  363. /// <summary>
  364. /// 取得注浆日报信息
  365. /// </summary>
  366. private void InitializeData()
  367. {
  368. try
  369. {
  370. if (this._dailyId > 0)
  371. {
  372. this.DataSource = null;
  373. this.dgvDetail.DataSource = null;
  374. this.txtGrouting.Clear();
  375. // 获取成型线类型数据并绑定到控件上
  376. ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
  377. {
  378. return PMModuleProxyNew.Service.GetFPM0103Data(this._dailyId);
  379. }
  380. );
  381. if (sre.Status == Constant.ServiceResultStatus.Other)
  382. {
  383. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
  384. return;
  385. }
  386. if (sre.Status != Constant.ServiceResultStatus.Success)
  387. {
  388. return;
  389. }
  390. this.DataSource = sre.Data;
  391. DataRow lineDataRow = sre.Data.Tables[0].Rows[0];
  392. this._groutingDate = Convert.ToDateTime(lineDataRow["GroutingDate"]);
  393. this.lblGroutingDateValue.Text = this._groutingDate.ToString(Constant.S_DATE_YYYY_MM_DD);
  394. this.txtGrouting.Text = string.Format("{0}({1})", lineDataRow["GroutingLineCode"], lineDataRow["MouldQuantity"]);
  395. this.dgvDetail.DataSource = sre.Data.Tables[1];
  396. // 获取成型报损原因
  397. if (sre.Data.Tables.Count > 2)
  398. {
  399. SReasonID.DisplayMember = "ScrapReason";
  400. SReasonID.ValueMember = "ScrapReasonID";
  401. SReasonID.DataSource = sre.Data.Tables[2];
  402. this.cboSReason.DisplayMember = "ScrapReason";
  403. this.cboSReason.ValueMember = "ScrapReasonID";
  404. this.cboSReason.DataSource = sre.Data.Tables[2];
  405. }
  406. this.SetEditGrid();
  407. this.btnBindBarCode.Enabled = true;
  408. this.btnClearBarCode.Enabled = true;
  409. this.btnSave.Enabled = true;
  410. }
  411. }
  412. catch (Exception ex)
  413. {
  414. throw ex;
  415. }
  416. }
  417. /// <summary>
  418. /// 编辑模式下设置Grid编辑状态
  419. /// </summary>
  420. private void SetEditGrid()
  421. {
  422. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  423. {
  424. // 报损标识勾上才可以编辑报损原因
  425. if (!Convert.ToBoolean(row.Cells["ScrapFlag"].EditedFormattedValue))
  426. {
  427. row.Cells["SReasonID"].ReadOnly = true;
  428. }
  429. //// 交坯后,不能编辑
  430. //object deliverFlag = row.Cells["DeliverFlag"].Value;
  431. //if (deliverFlag != null && "1" == deliverFlag.ToString())
  432. //{
  433. // row.Cells["BarCode"].ReadOnly = true;
  434. // row.Cells["ScrapFlag"].ReadOnly = true;
  435. // row.Cells["Remarks"].ReadOnly = true;
  436. // row.Cells["colLogo"].ReadOnly = true;
  437. // continue;
  438. //}
  439. //// 绑定条码后,不能编辑条码
  440. //object obarCode = row.Cells["colOBarCode"].Value;
  441. //if (obarCode != null && !string.IsNullOrWhiteSpace(obarCode.ToString()))
  442. //{
  443. // row.Cells["BarCode"].ReadOnly = true;
  444. // continue;
  445. //}
  446. //// 损坯后,不能编辑
  447. //if (((int)Constant.GroutingScrapFlag.No).ToString() == row.Cells["ScrapFlag"].Value.ToString())
  448. //{
  449. // row.Cells["BarCode"].ReadOnly = false;
  450. //}
  451. //else
  452. //{
  453. // row.Cells["BarCode"].Value = DBNull.Value;
  454. // row.Cells["BarCode"].ReadOnly = true;
  455. //}
  456. }
  457. this.dgvDetail.IsSetInputColumnsColor = true;
  458. }
  459. /// <summary>
  460. /// 校验数据
  461. /// </summary>
  462. /// <returns></returns>
  463. private bool IsValidData()
  464. {
  465. try
  466. {
  467. for (int j = 0; j < this.dgvDetail.Rows.Count; j++)
  468. {
  469. // 判断如果勾选上报损标识,那么报损原因必须输入
  470. if (Convert.ToBoolean(this.dgvDetail.Rows[j].Cells["ScrapFlag"].EditedFormattedValue)
  471. && string.IsNullOrWhiteSpace(this.dgvDetail.Rows[j].Cells["SReasonID"].EditedFormattedValue + ""))
  472. {
  473. dgvDetail.CurrentCell = dgvDetail.Rows[j].Cells["ScrapFlag"];
  474. // 增加单元格的错误消息
  475. dgvDetail.Rows[j].ErrorText = string.Format(Messages.W_CMN_S_004, "报损原因为空");
  476. return false;
  477. }
  478. }
  479. return true;
  480. }
  481. catch (Exception ex)
  482. {
  483. throw ex;
  484. }
  485. }
  486. #endregion
  487. }
  488. }