F_PM_2112.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*******************************************************************************
  2. * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_2112.cs
  5. * 2.功能描述:查询在产临时表数据
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/08/11 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Text;
  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.Controls;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. public partial class F_PM_2112 : DKDockPanelBase
  24. {
  25. #region 成员变量
  26. // 窗体的单例模式
  27. private static F_PM_2112 _instance;
  28. //默认清空工序,重置回用户当前权限工序
  29. private string _currentUserPurview = null;
  30. //默认清空生产线,重置回用户当前权限生产线
  31. private string _currentUserLinePuview = null;
  32. #endregion
  33. #region 构造函数
  34. public F_PM_2112()
  35. {
  36. InitializeComponent();
  37. //自动适应列宽
  38. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  39. //关闭
  40. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  41. //查询
  42. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  43. // 清除选择
  44. this.tsbtnClearSelected.Text = ButtonText.TSBTN_CLEARSELECTED;
  45. //批量清除
  46. this.tsbtnAllClear.Text = ButtonText.TSBTN_CLEARALL;
  47. //清空条件
  48. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  49. //查询条件
  50. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  51. // 窗体显示的Title
  52. this.Text = FormTitles.F_PM_2112;
  53. //恢复数据
  54. this.tsbtnResetData.Text = ButtonText.TSBTN_RESETDATA;
  55. this.tsbtnResetSelected.Text = ButtonText.TSBTN_RESETSELECTEDDATA;
  56. }
  57. #endregion
  58. #region 单例模式
  59. /// <summary>
  60. /// 单例模式,防止重复创建窗体
  61. /// </summary>
  62. public static F_PM_2112 Instance
  63. {
  64. get
  65. {
  66. if (_instance == null || _instance.IsDisposed)
  67. {
  68. _instance = new F_PM_2112();
  69. }
  70. return _instance;
  71. }
  72. }
  73. #endregion
  74. #region 事件
  75. /// <summary>
  76. /// 窗体加载事件
  77. /// </summary>
  78. /// <param name="sender"></param>
  79. /// <param name="e"></param>
  80. private void F_PM_2112_Load(object sender, EventArgs e)
  81. {
  82. try
  83. {
  84. // 加载权限
  85. FormPermissionManager.FormPermissionControl(this.Name, this,
  86. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  87. LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  88. this.tsbtnClearSelected.Visible = false;
  89. this.tsbtnAllClear.Visible = false;
  90. // 设置表格不自动创建列
  91. this.dgvInProduction.AutoGenerateColumns = false;
  92. // 初始化时间控件为当前日期
  93. this.dtpUpdateTimeStart.Value = DateTime.Now.Date;
  94. this.dtpUpdateTimeEnd.Value = DateTime.Now.Date;
  95. this.dtpScrapDate.Value = DateTime.Now.Date;
  96. this.dtpScrapDateEnd.Value = DateTime.Now.Date;
  97. this.dtpDeletedDateStart.Value = DateTime.Now.Date;
  98. this.dtpDeletedDateEnd.Value = DateTime.Now.Date;
  99. this.dtpScrapDate.Enabled = false;
  100. this.dtpScrapDateEnd.Enabled = false;
  101. this.dtpDeletedDateStart.Enabled = false;
  102. this.dtpDeletedDateEnd.Enabled = false;
  103. this.dtpUpdateTimeStart.Enabled = false;
  104. this.dtpUpdateTimeEnd.Enabled = false;
  105. this.dtpDeletedDateStart.Enabled = false;
  106. this.dtpDeletedDateEnd.Enabled = false;
  107. //绑定产品分级
  108. BindGoodsType();
  109. //绑定数据来源
  110. BindComDataSource();
  111. }
  112. catch (Exception ex)
  113. {
  114. // 对异常进行共通处理
  115. ExceptionManager.HandleEventException(this.ToString(),
  116. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  117. }
  118. }
  119. /// <summary>
  120. /// 窗体关闭事件
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void F_PM_2112_FormClosed(object sender, FormClosedEventArgs e)
  125. {
  126. _instance = null;
  127. }
  128. /// <summary>
  129. /// 关闭按钮事件
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void tsbtnClose_Click(object sender, EventArgs e)
  134. {
  135. this.Close();
  136. }
  137. /// <summary>
  138. /// 查询按钮事件
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void btnSearch_Click(object sender, EventArgs e)
  143. {
  144. try
  145. {
  146. this.dgvInProduction.DataSource = null;
  147. this.dgvInProduction.DataSource = this.GetSearchData();
  148. }
  149. catch (Exception ex)
  150. {
  151. this.btnSearch.Enabled = true;
  152. this.btnClearCondition.Enabled = true;
  153. // 对异常进行共通处理
  154. ExceptionManager.HandleEventException(this.ToString(),
  155. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  156. }
  157. }
  158. /// <summary>
  159. /// 自动适应列宽
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  164. {
  165. this.dgvInProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  166. }
  167. /// <summary>
  168. /// 清空条件按钮事件
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void btnClearCondition_Click(object sender, EventArgs e)
  173. {
  174. //清空更多条件内容
  175. this.dkProcedureSearchBox.ClearControl();
  176. this.dkproductionLineSearchBox.ClearControl();
  177. this.dtpUpdateTimeStart.Value = DateTime.Now.Date;
  178. this.dtpUpdateTimeEnd.Value = DateTime.Now.Date;
  179. this.dtpScrapDate.Value = DateTime.Now.Date;
  180. this.dtpScrapDateEnd.Value = DateTime.Now.Date;
  181. this.dtpDeletedDateStart.Value = DateTime.Now.Date;
  182. this.dtpDeletedDateEnd.Value = DateTime.Now.Date;
  183. this.comGoodsType.SelectedValue = -100;
  184. this.dkProcedureSearchBox.ProcedureIDS = this._currentUserPurview;
  185. this.dkproductionLineSearchBox.ProductionLineIDS = this._currentUserLinePuview;
  186. this.cmbDataSource.SelectedValue = 0;
  187. this.chkDateTime.Checked = false;
  188. this.chkScrapDate.Checked = false;
  189. this.chkDeletedate.Checked = false;
  190. this.txtBarcode.Text = "";
  191. }
  192. /// <summary>
  193. /// 清除选择按钮事件
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. /// <param name="e"></param>
  197. private void tsbtnClearSelected_Click(object sender, EventArgs e)
  198. {
  199. try
  200. {
  201. DataTable dt = this.dgvInProduction.DataSource as DataTable;
  202. if (dt == null)
  203. {
  204. return;
  205. }
  206. dt.AcceptChanges();
  207. DataRow[] dr = dt.Select("Sel=1");
  208. if (dr.Length == 0)
  209. {
  210. MessageBox.Show("请选择清除在产临时数据",
  211. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  212. return;
  213. }
  214. DialogResult dialogResult
  215. = MessageBox.Show("确认是否清除选中的在产临时数据?",
  216. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  217. if (dialogResult.Equals(DialogResult.No))
  218. {
  219. return;
  220. }
  221. string barcodes = "";
  222. foreach (DataRow r in dr)
  223. {
  224. barcodes += r["barcode"].ToString() + ",";
  225. }
  226. barcodes = barcodes.TrimEnd(',');
  227. // 清除
  228. int result = (int)DoAsync(() =>
  229. {
  230. return PMModuleProxy.Service.SaveClearInproductionTmp(barcodes);
  231. });
  232. if (result > Constant.INT_IS_ZERO)
  233. {
  234. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "在产临时表", "清除数据"),
  235. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  236. // 刷新窗口数据
  237. this.btnSearch_Click(sender, e);
  238. }
  239. else
  240. {
  241. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "在产临时表", "清除数据"),
  242. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  243. return;
  244. }
  245. }
  246. catch (Exception ex)
  247. {
  248. // 对异常进行共通处理
  249. ExceptionManager.HandleEventException(this.ToString(),
  250. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  251. }
  252. }
  253. /// <summary>
  254. /// 批量清除按钮事件
  255. /// </summary>
  256. /// <param name="sender"></param>
  257. /// <param name="e"></param>
  258. private void tsbtnAllClear_Click(object sender, EventArgs e)
  259. {
  260. try
  261. {
  262. F_PM_2113 frmPM2113 = new F_PM_2113();
  263. DialogResult dialogResult = frmPM2113.ShowDialog();
  264. // 重新加载GridView
  265. if (dialogResult == DialogResult.OK)
  266. {
  267. btnSearch_Click(sender, e);
  268. }
  269. }
  270. catch (Exception ex)
  271. {
  272. // 对异常进行共通处理
  273. ExceptionManager.HandleEventException(this.ToString(),
  274. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  275. }
  276. }
  277. /// <summary>
  278. /// 恢复数据按钮事件
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void tsbtnResetData_Click(object sender, EventArgs e)
  283. {
  284. try
  285. {
  286. F_PM_2114 frmPM2114 = new F_PM_2114();
  287. DialogResult dialogResult = frmPM2114.ShowDialog();
  288. // 重新加载GridView
  289. if (dialogResult == DialogResult.OK)
  290. {
  291. btnSearch_Click(sender, e);
  292. }
  293. }
  294. catch (Exception ex)
  295. {
  296. // 对异常进行共通处理
  297. ExceptionManager.HandleEventException(this.ToString(),
  298. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  299. }
  300. }
  301. private void dgvInProduction_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  302. {
  303. try
  304. {
  305. if (this.dgvInProduction.CurrentRow != null && this.dgvInProduction.IsCurrentCellDirty)
  306. {
  307. if ("Sel".Equals(this.dgvInProduction.Columns
  308. [this.dgvInProduction.CurrentCell.ColumnIndex].Name))
  309. {
  310. this.dgvInProduction.CommitEdit(DataGridViewDataErrorContexts.Commit);
  311. }
  312. }
  313. }
  314. catch (Exception ex)
  315. {
  316. // 对异常进行共通处理
  317. ExceptionManager.HandleEventException(this.ToString(),
  318. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  319. }
  320. }
  321. /// <summary>
  322. /// 选定项改变事件
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void cmbDataSource_SelectedIndexChanged(object sender, EventArgs e)
  327. {
  328. if (cmbDataSource.SelectedIndex == 0)
  329. {
  330. this.dtpScrapDate.Enabled = false;
  331. this.dtpScrapDateEnd.Enabled = false;
  332. if (!this.chkDateTime.Checked)
  333. {
  334. this.dtpUpdateTimeStart.Enabled = false;
  335. this.dtpUpdateTimeEnd.Enabled = false;
  336. }
  337. this.chkScrapDate.Enabled = false;
  338. this.comGoodsType.SelectedValue = -100;
  339. this.comGoodsType.Enabled = false;
  340. this.chkScrapDate.Checked = false;
  341. }
  342. else
  343. {
  344. //this.dtpScrapDate.Enabled = true;
  345. //this.dtpScrapDateEnd.Enabled = true;
  346. //this.dtpUpdateTimeStart.Enabled = true;
  347. //this.dtpUpdateTimeEnd.Enabled = true;
  348. if (this.chkDateTime.Checked)
  349. {
  350. this.dtpUpdateTimeStart.Enabled = true;
  351. this.dtpUpdateTimeEnd.Enabled = true;
  352. }
  353. // this.chkDateTime.Checked = false;
  354. this.chkScrapDate.Enabled = true;
  355. this.comGoodsType.Enabled = true;
  356. }
  357. }
  358. /// <summary>
  359. /// 恢复选定数据按钮事件
  360. /// </summary>
  361. /// <param name="sender"></param>
  362. /// <param name="e"></param>
  363. private void tsbtnResetSelected_Click(object sender, EventArgs e)
  364. {
  365. try
  366. {
  367. DataTable dt = this.dgvInProduction.DataSource as DataTable;
  368. if (dt == null)
  369. {
  370. return;
  371. }
  372. dt.AcceptChanges();
  373. DataRow[] dr = dt.Select("Sel=1");
  374. if (dr.Length == 0)
  375. {
  376. MessageBox.Show("请选择恢复的数据",
  377. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Question);
  378. return;
  379. }
  380. DialogResult dialogResult
  381. = MessageBox.Show("确认是否恢复选中的在产临时数据?",
  382. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  383. if (dialogResult.Equals(DialogResult.No))
  384. {
  385. return;
  386. }
  387. string barcodes = "";
  388. foreach (DataRow r in dr)
  389. {
  390. barcodes += r["barcode"].ToString() + ",";
  391. }
  392. barcodes = barcodes.TrimEnd(',');
  393. // 恢复
  394. int returnValue = (int)DoAsync(new AsyncMethod(() =>
  395. {
  396. return PMModuleProxy.Service.ResetSelectedBarCode(barcodes);
  397. }));
  398. if (returnValue == -1)
  399. {
  400. MessageBox.Show("此条码没有清除,不能恢复", this.Text,
  401. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  402. return;
  403. }
  404. else if (returnValue == 0)
  405. {
  406. MessageBox.Show("没有可恢复的数据", this.Text,
  407. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  408. return;
  409. }
  410. else if (returnValue > 0)
  411. {
  412. MessageBox.Show("恢复数据成功", this.Text,
  413. MessageBoxButtons.OK, MessageBoxIcon.Information);
  414. // 刷新窗口数据
  415. this.btnSearch_Click(sender, e);
  416. }
  417. }
  418. catch (Exception ex)
  419. {
  420. // 对异常进行共通处理
  421. ExceptionManager.HandleEventException(this.ToString(),
  422. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  423. }
  424. }
  425. private void chkDateTime_CheckedChanged(object sender, EventArgs e)
  426. {
  427. dtpUpdateTimeStart.Enabled = chkDateTime.Checked;
  428. dtpUpdateTimeEnd.Enabled = chkDateTime.Checked;
  429. }
  430. private void chkScrapDate_CheckedChanged(object sender, EventArgs e)
  431. {
  432. dtpScrapDate.Enabled = chkScrapDate.Checked;
  433. dtpScrapDateEnd.Enabled = chkScrapDate.Checked;
  434. }
  435. private void chkDeletedate_CheckedChanged(object sender, EventArgs e)
  436. {
  437. dtpDeletedDateStart.Enabled = chkDeletedate.Checked;
  438. dtpDeletedDateEnd.Enabled = chkDeletedate.Checked;
  439. }
  440. #endregion
  441. #region 私有方法
  442. /// <summary>
  443. /// 根据界面查询条件获取数据集
  444. /// </summary>
  445. private DataTable GetSearchData()
  446. {
  447. try
  448. {
  449. FPM2112_SE se = new FPM2112_SE();
  450. se.ProductionLineIDS = dkproductionLineSearchBox.ProductionLineIDS;
  451. se.ProcedureIDS = dkProcedureSearchBox.ProcedureIDS;
  452. if (this.chkDateTime.Checked)
  453. {
  454. se.UpdateTimeStart = DateTime.Parse(this.dtpUpdateTimeStart.Value.ToString("yyyy-MM-dd") + " 0:0:0");
  455. se.UpdateTimeEnd = DateTime.Parse(this.dtpUpdateTimeEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59");
  456. }
  457. if (this.chkScrapDate.Checked)
  458. {
  459. //报废日期
  460. se.ScrapDataStart = DateTime.Parse(this.dtpScrapDate.Value.ToString("yyyy-MM-dd") + " 0:0:0");
  461. se.ScrapDataEnd = DateTime.Parse(this.dtpScrapDateEnd.Value.ToString("yyyy-MM-dd") + " 0:0:0");
  462. }
  463. if(this.chkDeletedate.Checked)
  464. {
  465. se.DeletedTimeStart = DateTime.Parse(this.dtpDeletedDateStart.Value.ToString("yyyy-MM-dd") + " 0:0:0");
  466. se.DeletedTimeEnd = DateTime.Parse(this.dtpDeletedDateEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59");
  467. }
  468. se.GooddLevelTypeID = Convert.ToInt32(comGoodsType.SelectedValue);
  469. se.TrashFlag = Convert.ToInt32(cmbDataSource.SelectedValue);
  470. se.Barcode = this.txtBarcode.Text.Trim();
  471. // 调用服务器端获取数据集
  472. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  473. {
  474. return PMModuleProxy.Service.GetPM2112Data(se);
  475. }
  476. );
  477. if (sre.Status == Constant.ServiceResultStatus.Success)
  478. {
  479. if (sre.Data.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  480. {
  481. // 提示未查找到数据
  482. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  483. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  484. //清空数据
  485. return null;
  486. }
  487. return sre.Data.Tables[0];
  488. }
  489. return null;
  490. }
  491. catch (Exception ex)
  492. {
  493. throw ex;
  494. }
  495. }
  496. /// <summary>
  497. /// 绑定产品分级
  498. /// </summary>
  499. private void BindGoodsType()
  500. {
  501. DataTable dt = new DataTable();
  502. dt.Columns.Add("GoodsLevelTypeID");
  503. dt.Columns.Add("GoodsLevelTypeName");
  504. DataRow dr = dt.NewRow();
  505. dr["GoodsLevelTypeID"] = -100;
  506. dr["GoodsLevelTypeName"] = "";
  507. dt.Rows.Add(dr);
  508. dr = dt.NewRow();
  509. dr["GoodsLevelTypeID"] = 8;
  510. dr["GoodsLevelTypeName"] = "损坯";
  511. dt.Rows.Add(dr);
  512. dr = dt.NewRow();
  513. dr["GoodsLevelTypeID"] = 7;
  514. dr["GoodsLevelTypeName"] = "次品";
  515. dt.Rows.Add(dr);
  516. dr = dt.NewRow();
  517. dr["GoodsLevelTypeID"] = 3;
  518. dr["GoodsLevelTypeName"] = "废品";
  519. dt.Rows.Add(dr);
  520. dr = dt.NewRow();
  521. dr["GoodsLevelTypeID"] = 13;
  522. dr["GoodsLevelTypeName"] = "不合格";
  523. dt.Rows.Add(dr);
  524. dr = dt.NewRow();
  525. dr["GoodsLevelTypeID"] = 14;
  526. dr["GoodsLevelTypeName"] = "不合格(返)";
  527. dt.Rows.Add(dr);
  528. this.comGoodsType.DataSource = dt;
  529. this.comGoodsType.DisplayMember = "GoodsLevelTypeName";
  530. this.comGoodsType.ValueMember = "GoodsLevelTypeID";
  531. }
  532. /// <summary>
  533. /// 绑定数据来源
  534. /// </summary>
  535. private void BindComDataSource()
  536. {
  537. DataTable dt = new DataTable();
  538. dt.Columns.Add("DataSourceID");
  539. dt.Columns.Add("DataSourceName");
  540. DataRow dr = dt.NewRow();
  541. dr["DataSourceID"] = 0;
  542. dr["DataSourceName"] = "在产";
  543. dt.Rows.Add(dr);
  544. dr = dt.NewRow();
  545. dr["DataSourceID"] = 1;
  546. dr["DataSourceName"] = "回收站";
  547. dt.Rows.Add(dr);
  548. this.cmbDataSource.DataSource = dt;
  549. this.cmbDataSource.DisplayMember = "DataSourceName";
  550. this.cmbDataSource.ValueMember = "DataSourceID";
  551. }
  552. #endregion
  553. }
  554. }