F_PC_1101.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_1101.cs
  5. * 2.功能描述:模具盘点一览
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/05/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.DockPanel;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels.PMModule;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  22. namespace Dongke.IBOSS.PRD.Client.PMModule
  23. {
  24. /// <summary>
  25. /// 模具盘点一览
  26. /// </summary>
  27. public partial class F_PC_1101 : DockPanelBase
  28. {
  29. #region 成员变量
  30. // 窗体的单例模式
  31. private static F_PC_1101 _instance;
  32. #endregion
  33. #region 构造函数
  34. public F_PC_1101()
  35. {
  36. InitializeComponent();
  37. this.Text = "模具盘点";//FormTitles.F_PM_2101;
  38. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  39. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  40. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  41. //this.tsbtnClearData.Text = ButtonText.TSBTN_CLEARDATAINCHECKED;
  42. this.tsbtnAll.Text = ButtonText.TSBTN_ALL;
  43. this.tsbtnUnAll.Text = ButtonText.TSBTN_UNALL;
  44. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  45. }
  46. /// <summary>
  47. /// 单例模式,防止重复创建窗体
  48. /// </summary>
  49. public static F_PC_1101 Instance
  50. {
  51. get
  52. {
  53. if (_instance == null)
  54. {
  55. _instance = new F_PC_1101();
  56. }
  57. return _instance;
  58. }
  59. }
  60. #endregion
  61. #region 事件
  62. /// <summary>
  63. /// 新建按钮事件
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. private void tsbtnAdd_Click(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. F_PC_1102 frmPM2102 = new F_PC_1102();
  72. DialogResult dialogResult = frmPM2102.ShowDialog();
  73. // 重新加载GridView
  74. if (dialogResult == DialogResult.OK)
  75. {
  76. }
  77. }
  78. catch (Exception ex)
  79. {
  80. // 对异常进行共通处理
  81. ExceptionManager.HandleEventException(this.ToString(),
  82. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  83. }
  84. }
  85. /// <summary>
  86. /// 盘点按钮事件
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void tsbtnInChecked_Click(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. if (this.dgvInChecked.CurrentCell != null)
  95. {
  96. int checkedID = Convert.ToInt32(
  97. this.dgvInChecked.CurrentRow.Cells["CheckedID"].Value);
  98. string checkedNO =
  99. this.dgvInChecked.CurrentRow.Cells["CheckedNo"].Value.ToString();
  100. F_PC_1103 frmPM2603 = new F_PC_1103(checkedID, checkedNO);
  101. DialogResult dialogResult = frmPM2603.ShowDialog();
  102. // 重新加载GridView
  103. if (dialogResult == DialogResult.OK)
  104. {
  105. //btnSearch_Click(sender, e);
  106. dgvInChecked_SelectionChanged(null, null);
  107. }
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. // 对异常进行共通处理
  113. ExceptionManager.HandleEventException(this.ToString(),
  114. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  115. }
  116. }
  117. /// <summary>
  118. /// 停用按钮事件
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void tsbtnDisable_Click(object sender, EventArgs e)
  123. {
  124. try
  125. {
  126. if (this.dgvInChecked.CurrentCell != null)
  127. {
  128. DialogResult dialogResult
  129. = MessageBox.Show(string.Format(Messages.MSG_CMN_Q002, "盘点单", "停用"),
  130. this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  131. if (dialogResult != DialogResult.OK)
  132. {
  133. return;
  134. }
  135. int checkedID = Convert.ToInt32(
  136. this.dgvInChecked.CurrentRow.Cells["CheckedID"].Value);
  137. // 停用
  138. ServiceResultEntity result = (ServiceResultEntity)DoAsync(() =>
  139. {
  140. ClientRequestEntity cre = new ClientRequestEntity();
  141. cre.NameSpace = "FPC1101";
  142. cre.Name = "DisableMouldChecked";
  143. cre.Properties["CheckedID"] = checkedID;
  144. return PCModuleProxyNew.Service.HandleRequest(cre);
  145. });
  146. if (result.Status == Constant.ServiceResultStatus.Success)
  147. {
  148. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "盘点单", "停用"),
  149. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  150. // 刷新窗口数据
  151. this.btnSearch_Click(sender, e);
  152. }
  153. else
  154. {
  155. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "盘点单", "停用"),
  156. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  157. return;
  158. }
  159. }
  160. }
  161. catch (Exception ex)
  162. {
  163. // 对异常进行共通处理
  164. ExceptionManager.HandleEventException(this.ToString(),
  165. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  166. }
  167. }
  168. /// <summary>
  169. /// 窗体加载事件
  170. /// </summary>
  171. /// <param name="sender"></param>
  172. /// <param name="e"></param>
  173. private void F_PM_2101_Load(object sender, EventArgs e)
  174. {
  175. try
  176. {
  177. // 绑定权限
  178. FormPermissionManager.FormPermissionControl(this.Name, this,
  179. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  180. LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  181. this.dgvInChecked.AutoGenerateColumns = false;
  182. this.dgvInCheckedNoDetail.AutoGenerateColumns = false;
  183. this.dgvInCheckededDetail.AutoGenerateColumns = false;
  184. this.dgvInCheckedWinDetail.AutoGenerateColumns = false;
  185. this.dgvLossDetail.AutoGenerateColumns = false;
  186. this.dgvInCheckedNoDetail.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  187. // 初始化时间控件为当前日期
  188. this.dtpStartTime.Value = DateTime.Now.Date;
  189. this.dtpEndTime.Value = DateTime.Now.Date;
  190. }
  191. catch (Exception ex)
  192. {
  193. // 对异常进行共通处理
  194. ExceptionManager.HandleEventException(this.ToString(),
  195. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  196. }
  197. }
  198. /// <summary>
  199. /// 窗体关闭事件
  200. /// </summary>
  201. /// <param name="sender"></param>
  202. /// <param name="e"></param>
  203. private void F_PM_2101_FormClosed(object sender, FormClosedEventArgs e)
  204. {
  205. _instance = null;
  206. }
  207. /// <summary>
  208. /// 清空按钮事件
  209. /// </summary>
  210. /// <param name="sender"></param>
  211. /// <param name="e"></param>
  212. private void btnClearCondition_Click(object sender, EventArgs e)
  213. {
  214. this.txtInCheckedNo.Clear();
  215. this.txtCheckedName.Clear();
  216. // 初始化时间控件为当前日期
  217. this.dtpStartTime.Value = DateTime.Now.Date;
  218. this.dtpEndTime.Value = DateTime.Now.Date;
  219. }
  220. /// <summary>
  221. /// 选定项改变事件
  222. /// </summary>
  223. /// <param name="sender"></param>
  224. /// <param name="e"></param>
  225. private void dgvInChecked_SelectionChanged(object sender, EventArgs e)
  226. {
  227. // 在绑定总表时 不查询明细
  228. if (!Convert.ToBoolean(this.Tag)
  229. || this.dgvInChecked.CurrentCell == null)
  230. {
  231. return;
  232. }
  233. try
  234. {
  235. // 选中行时查询明细
  236. if (this.txtInCheckedNo.ReadOnly)
  237. {
  238. return;
  239. }
  240. this.dgvInChecked.Enabled = false;
  241. this.dgvInCheckedNoDetail.DataSource = null;
  242. this.dgvInCheckededDetail.DataSource = null;
  243. this.dgvInCheckedWinDetail.DataSource = null;
  244. this.dgvLossDetail.DataSource = null;
  245. this.dgvFunctionUsers.DataSource = null;
  246. int checkedID = Convert.ToInt32(this.dgvInChecked.CurrentRow.Cells["CheckedID"].Value.ToString());
  247. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new AsyncMethod(() =>
  248. {
  249. ClientRequestEntity cre = new ClientRequestEntity();
  250. cre.NameSpace = "FPC1101";
  251. cre.Name = "GetAllMouldCheckDetail";
  252. cre.Properties["CheckedID"] = checkedID;
  253. return PCModuleProxyNew.Service.HandleRequest(cre);
  254. }));
  255. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  256. {
  257. this.dgvFunctionUsers.DataSource = sre.Data.Tables[0];
  258. this.dgvInCheckedNoDetail.DataSource = sre.Data.Tables[1];
  259. this.dgvInCheckededDetail.DataSource = sre.Data.Tables[2];
  260. this.dgvInCheckedWinDetail.DataSource = sre.Data.Tables[3];
  261. this.dgvLossDetail.DataSource = sre.Data.Tables[4];
  262. dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
  263. }
  264. }
  265. catch (Exception ex)
  266. {
  267. // 对异常进行共通处理
  268. ExceptionManager.HandleEventException(this.ToString(),
  269. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  270. }
  271. finally
  272. {
  273. this.dgvInChecked.Enabled = true;
  274. this.dgvInChecked.Focus();
  275. }
  276. }
  277. /// <summary>
  278. /// 搜索按钮事件
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void btnSearch_Click(object sender, EventArgs e)
  283. {
  284. try
  285. {
  286. // 控制明细不查询
  287. this.Tag = false;
  288. // 异步处理
  289. this.btnSearch.Enabled = false;
  290. this.btnClearCondition.Enabled = false;
  291. this.dgvInChecked.DataSource = null;
  292. this.dgvFunctionUsers.DataSource = null;
  293. this.dgvInCheckededDetail.DataSource = null;
  294. this.dgvInCheckedNoDetail.DataSource = null;
  295. this.dgvInCheckedWinDetail.DataSource = null;
  296. this.dgvLossDetail.DataSource = null;
  297. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new AsyncMethod(() =>
  298. {
  299. ClientRequestEntity cre = new ClientRequestEntity();
  300. cre.NameSpace = "FPC1101";
  301. cre.Name = "GetAllMouldCheckList";
  302. cre.Properties["datebegin"] = this.dtpStartTime.Value;
  303. cre.Properties["dateend"] = this.dtpEndTime.Value.AddDays(1).AddSeconds(-1);
  304. cre.Properties["checkedno"] = this.txtInCheckedNo.Text.Trim();
  305. cre.Properties["checkname"] = this.txtCheckedName.Text.Trim();
  306. return PCModuleProxyNew.Service.HandleRequest(cre);
  307. }));
  308. this.btnSearch.Enabled = true;
  309. this.btnClearCondition.Enabled = true;
  310. if (sre != null && sre.Status == Constant.ServiceResultStatus.Success)
  311. {
  312. base.DataSource = sre.Data;
  313. if (this.DataSource != null && this.DataSource.Tables.Count > 0)
  314. {
  315. tsbtnInChecked.Enabled = true;
  316. tsbtnDisable.Enabled = true;
  317. this.dgvInChecked.DataSource = this.DataSource.Tables[0];
  318. if (this.DataSource.Tables[0].Rows.Count == 0)
  319. {
  320. tsbtnInChecked.Enabled = false;
  321. tsbtnDisable.Enabled = false;
  322. this.dgvInCheckedNoDetail.DataSource = null;
  323. // 提示未查找到数据
  324. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  325. MessageBoxButtons.OK, MessageBoxIcon.Information);
  326. }
  327. else
  328. {
  329. this.Tag = true;
  330. dgvInChecked_SelectionChanged(null, null);
  331. }
  332. }
  333. }
  334. }
  335. catch (Exception ex)
  336. {
  337. // 对异常进行共通处理
  338. ExceptionManager.HandleEventException(this.ToString(),
  339. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  340. }
  341. finally
  342. {
  343. this.tsrOperate.Enabled = true;
  344. this.btnSearch.Enabled = true;
  345. this.btnClearCondition.Enabled = true;
  346. // 控制明细不查询
  347. this.Tag = true;
  348. }
  349. }
  350. /// <summary>
  351. /// 关闭按钮事件
  352. /// </summary>
  353. /// <param name="sender"></param>
  354. /// <param name="e"></param>
  355. private void tsbtnClose_Click(object sender, EventArgs e)
  356. {
  357. this.Close();
  358. }
  359. /// <summary>
  360. /// 自动适应列宽
  361. /// </summary>
  362. /// <param name="sender"></param>
  363. /// <param name="e"></param>
  364. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  365. {
  366. this.dgvInChecked.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  367. this.dgvInCheckedNoDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  368. this.dgvInCheckededDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  369. this.dgvInCheckedWinDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  370. this.dgvLossDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  371. this.dgvFunctionUsers.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  372. }
  373. #endregion
  374. #region 私有方法
  375. #endregion
  376. /// <summary>
  377. /// 清除未盘点数据按钮事件
  378. /// </summary>
  379. /// <param name="sender"></param>
  380. /// <param name="e"></param>
  381. private void tsbtnClearData_Click(object sender, EventArgs e)
  382. {
  383. bool hasSearch = false;
  384. try
  385. {
  386. DataTable dt = this.dgvInCheckedNoDetail.DataSource as DataTable;
  387. if (dt == null)
  388. {
  389. MessageBox.Show("没有未盘点的数据",
  390. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  391. return;
  392. }
  393. dt.AcceptChanges();
  394. DataRow[] dr = dt.Select("Sel=1");
  395. if (dr.Length == 0)
  396. {
  397. MessageBox.Show("没有选择任何未盘点的模具",
  398. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  399. return;
  400. }
  401. DialogResult dialogResult
  402. = MessageBox.Show("是否报损选择的未盘点模具?",
  403. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  404. if (dialogResult != DialogResult.Yes)
  405. {
  406. return;
  407. }
  408. int checkID = Convert.ToInt32(dr[0]["CheckedID"]);
  409. string barcodes = "";
  410. foreach (DataRow r in dr)
  411. {
  412. barcodes += r["mouldbarcode"].ToString() + ",";
  413. }
  414. barcodes = barcodes.TrimEnd(',');
  415. // 清除
  416. ServiceResultEntity result = (ServiceResultEntity)DoAsync(() =>
  417. {
  418. ClientRequestEntity cre = new ClientRequestEntity();
  419. cre.NameSpace = "FPC1101";
  420. cre.Name = "SaveClearMouldChecked";
  421. cre.Properties["CheckedID"] = checkID;
  422. cre.Properties["Barcodes"] = barcodes;
  423. cre.Properties["BarcodeCount"] = dr.Length;
  424. return PCModuleProxyNew.Service.HandleRequest(cre);
  425. });
  426. if (result != null)
  427. {
  428. if (result.Status == Constant.ServiceResultStatus.Success)
  429. {
  430. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "未盘点模具", "报损"),
  431. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  432. this.btnSearch_Click(sender, e);
  433. }
  434. else if (!string.IsNullOrEmpty(result.Message))
  435. {
  436. MessageBox.Show(result.Message,
  437. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  438. this.btnSearch_Click(sender, e);
  439. }
  440. }
  441. hasSearch = true;
  442. }
  443. catch (Exception ex)
  444. {
  445. // 对异常进行共通处理
  446. ExceptionManager.HandleEventException(this.ToString(),
  447. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  448. }
  449. finally
  450. {
  451. if (!hasSearch)
  452. {
  453. this.dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
  454. }
  455. }
  456. }
  457. private void dgvInCheckedNoDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  458. {
  459. try
  460. {
  461. if (this.dgvInCheckedNoDetail.CurrentRow != null && this.dgvInCheckedNoDetail.IsCurrentCellDirty)
  462. {
  463. if ("Sel".Equals(this.dgvInCheckedNoDetail.Columns
  464. [this.dgvInCheckedNoDetail.CurrentCell.ColumnIndex].Name))
  465. {
  466. this.dgvInCheckedNoDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
  467. }
  468. }
  469. }
  470. catch (Exception ex)
  471. {
  472. // 对异常进行共通处理
  473. ExceptionManager.HandleEventException(this.ToString(),
  474. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  475. }
  476. }
  477. private void tsbtnAll_Click(object sender, EventArgs e)
  478. {
  479. DataTable returnData = (DataTable)this.dgvInCheckedNoDetail.DataSource;
  480. if (returnData != null)
  481. {
  482. //for (int i = 0; i < returnData.Rows.Count; i++)
  483. //{
  484. // returnData.Rows[i]["Sel"] = 1;
  485. //}
  486. for (int i = 0; i < returnData.DefaultView.Count; i++)
  487. {
  488. returnData.DefaultView[i]["Sel"] = 1;
  489. returnData.DefaultView[i].EndEdit();
  490. }
  491. }
  492. }
  493. private void tsbtnUnAll_Click(object sender, EventArgs e)
  494. {
  495. DataTable returnData = (DataTable)this.dgvInCheckedNoDetail.DataSource;
  496. if (returnData != null)
  497. {
  498. for (int i = 0; i < returnData.Rows.Count; i++)
  499. {
  500. returnData.Rows[i]["Sel"] = 0;
  501. returnData.Rows[i].EndEdit();
  502. }
  503. }
  504. }
  505. private void tsbtnEdit_Click(object sender, EventArgs e)
  506. {
  507. try
  508. {
  509. DataGridViewRow currentRow = this.dgvInChecked.CurrentRow;
  510. if (currentRow != null)
  511. {
  512. int checkedID = Convert.ToInt32(currentRow.Cells["CheckedID"].Value);
  513. F_PC_1102 frm2602 = new F_PC_1102(checkedID);
  514. DialogResult dialogresult = frm2602.ShowDialog();
  515. if (dialogresult.Equals(DialogResult.OK))
  516. {
  517. btnSearch_Click(sender, e);
  518. }
  519. }
  520. }
  521. catch (Exception ex)
  522. {
  523. // 对异常进行共通处理
  524. ExceptionManager.HandleEventException(this.ToString(),
  525. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  526. }
  527. }
  528. private void dgvInChecked_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  529. {
  530. if (-1 < e.RowIndex && -1 < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
  531. {
  532. this.tsbtnEdit_Click(sender, e);
  533. }
  534. }
  535. private void dgvInCheckedNoDetail_Sorted(object sender, EventArgs e)
  536. {
  537. dgvInCheckedNoDetail.IsSetInputColumnsColor = true;
  538. }
  539. }
  540. }