F_PM_1201.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_1201.cs
  5. * 2.功能描述:成品检验一览
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/10/18 1.00 新建
  9. *******************************************************************************/
  10. using Dongke.IBOSS.PRD.Basics.BaseResources;
  11. using Dongke.IBOSS.PRD.Basics.DockPanel;
  12. using Dongke.IBOSS.PRD.Client.CommonModule;
  13. using Dongke.IBOSS.PRD.Client.DataModels;
  14. using Dongke.IBOSS.PRD.WCF.DataModels.PMModule;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Data;
  19. using System.Windows.Forms;
  20. namespace Dongke.IBOSS.PRD.Client.PMModule
  21. {
  22. /// <summary>
  23. /// 成品检验一览
  24. /// </summary>
  25. public partial class F_PM_1201 : DockPanelBase
  26. {
  27. #region 成员变量
  28. // 窗体的单例模式
  29. private static Dictionary<int, F_PM_1201> _dicInstance;
  30. // 当前工序ID
  31. private int _currentProcedureID = 0;
  32. // 最后选择行
  33. private int _selecedRow;
  34. // 窗体显示的Title
  35. private string _fromTitle;
  36. #endregion
  37. #region 构造函数
  38. public F_PM_1201()
  39. {
  40. InitializeComponent();
  41. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  42. //编辑
  43. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  44. //自动适应列宽
  45. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  46. //关闭
  47. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  48. //查询
  49. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  50. //清空条件
  51. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  52. //查询条件
  53. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  54. this.Text = _fromTitle;
  55. }
  56. #endregion
  57. #region 单例模式
  58. /// <summary>
  59. /// 一个工序ID有一个单例,防止重复创建窗体
  60. /// </summary>
  61. /// <param name="procedureID">工序ID</param>
  62. /// <returns></returns>
  63. public static F_PM_1201 Instance(int procedureID, string fromTitle)
  64. {
  65. F_PM_1201 fInstance = null;
  66. if (_dicInstance == null)
  67. {
  68. _dicInstance = new Dictionary<int, F_PM_1201>();
  69. fInstance = new F_PM_1201();
  70. _dicInstance.Add(procedureID, fInstance);
  71. }
  72. else if (_dicInstance.ContainsKey(procedureID))
  73. {
  74. fInstance = _dicInstance[procedureID];
  75. }
  76. else
  77. {
  78. fInstance = new F_PM_1201();
  79. _dicInstance.Add(procedureID, fInstance);
  80. }
  81. fInstance._currentProcedureID = procedureID;
  82. fInstance._fromTitle = fromTitle;
  83. fInstance.Text = fromTitle;
  84. return fInstance;
  85. }
  86. #endregion
  87. #region 事件
  88. /// <summary>
  89. /// 窗体加载事件
  90. /// </summary>
  91. /// <param name="sender"></param>
  92. /// <param name="e"></param>
  93. private void F_PM_1201_Load(object sender, System.EventArgs e)
  94. {
  95. try
  96. {
  97. if (_currentProcedureID == 16 || _currentProcedureID == 28)
  98. {
  99. this.dgvProduction.Columns["CheckTime"].Visible = false;
  100. }
  101. else {
  102. this.dgvProduction.Columns["CheckTime"].Visible = true;
  103. }
  104. // 加载权限
  105. FormPermissionManager.FormPermissionControl(this.Name, this,
  106. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  107. this.tsbtnAdd.Visible = true;
  108. // 设置表格不自动创建列
  109. this.dgvProduction.AutoGenerateColumns = false;
  110. // 初始化时间控件为当前日期
  111. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  112. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  113. // 设置ToolStripButton状态
  114. this.SetToolStripButtonEnable();
  115. #region 设置下拉列表框的数据源
  116. this.cobKilnName.DataSource = GetMSTKilnInfo();
  117. this.cobKilnName.DisplayMember = "KilnName";
  118. this.cobKilnName.ValueMember = "KilnCode";
  119. this.cobKilnCarPosition.DataSource = GetMSTKilnCarPositionInfo();
  120. this.cobKilnCarPosition.DisplayMember = "DictionaryValue";
  121. this.cobKilnCarPosition.ValueMember = "DictionaryID";
  122. #endregion
  123. }
  124. catch (Exception ex)
  125. {
  126. // 对异常进行共通处理
  127. ExceptionManager.HandleEventException(this.ToString(),
  128. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  129. }
  130. }
  131. /// <summary>
  132. /// 窗体关闭事件
  133. /// </summary>
  134. /// <param name="sender"></param>
  135. /// <param name="e"></param>
  136. private void F_PM_1201_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
  137. {
  138. _dicInstance = null;
  139. }
  140. /// <summary>
  141. /// 自动适应列宽
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  146. {
  147. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  148. this.dgvDefect.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  149. }
  150. /// <summary>
  151. /// 清空条件按钮事件
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void btnClearCondition_Click(object sender, EventArgs e)
  156. {
  157. this.txtBarCode.Text = string.Empty;
  158. this.txtGoodsCode.Text = string.Empty;
  159. this.txtGoodsName.Text = string.Empty;
  160. this.txtUserCode.Text = string.Empty;
  161. this.scbOrganization.ClearValue();
  162. //this.txtRemarks.Text = string.Empty;
  163. this.scbGoodsType.ClearValue();
  164. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  165. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  166. this.cobKilnName.SelectedIndex = Constant.INT_IS_ZERO;
  167. this.txtKilnCarName.Text = string.Empty;
  168. this.cobKilnCarPosition.SelectedIndex = Constant.INT_IS_ZERO;
  169. this.cobworkshop.SelectedIndex = Constant.INT_IS_NEGATIE_ONE;
  170. this.txtGroutingUserCode.Text = string.Empty;
  171. }
  172. /// <summary>
  173. /// 查询按钮事件
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. private void btnSearch_Click(object sender, EventArgs e)
  178. {
  179. try
  180. {
  181. // 记录当前选中行
  182. int selectRowIndex = this._selecedRow;
  183. // 异步处理
  184. this.btnSearch.Enabled = false;
  185. this.btnClearCondition.Enabled = false;
  186. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  187. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  188. {
  189. return PMModuleProxy.Service.GetProductionData(requestEntity);
  190. }));
  191. DataSet dsProductionData = new DataSet();
  192. dsProductionData.Tables.Add(dtProductionData);
  193. this.btnSearch.Enabled = true;
  194. this.btnClearCondition.Enabled = true;
  195. if (dsProductionData != null)
  196. {
  197. base.DataSource = dsProductionData;
  198. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  199. {
  200. tsbtnEdit.Enabled = true;
  201. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  202. selectRowIndex = 0;
  203. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  204. {
  205. tsbtnEdit.Enabled = false;
  206. this.dgvDefect.DataSource = null;
  207. // 提示未查找到数据
  208. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  209. MessageBoxButtons.OK, MessageBoxIcon.Information);
  210. }
  211. else
  212. {
  213. if (selectRowIndex >= Constant.INT_IS_ZERO)
  214. {
  215. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  216. {
  217. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  218. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  219. }
  220. else
  221. {
  222. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  223. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. this.btnSearch.Enabled = true;
  233. this.btnClearCondition.Enabled = true;
  234. // 对异常进行共通处理
  235. ExceptionManager.HandleEventException(this.ToString(),
  236. System.Reflection.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 tsbtnClose_Click(object sender, EventArgs e)
  245. {
  246. this.Close();
  247. }
  248. /// <summary>
  249. /// 新建按钮事件
  250. /// </summary>
  251. /// <param name="sender"></param>
  252. /// <param name="e"></param>
  253. private void tsbtnAdd_Click(object sender, EventArgs e)
  254. {
  255. try
  256. {
  257. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle);
  258. DialogResult dialogResult = frmPM1202.ShowDialog();
  259. // 重新加载GridView
  260. if (dialogResult == DialogResult.OK)
  261. {
  262. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  263. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  264. {
  265. return PMModuleProxy.Service.GetProductionData(requestEntity);
  266. }));
  267. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  268. {
  269. this.dgvProduction.DataSource = null;
  270. this.dgvProduction.DataSource = dtProductionData;
  271. // 设置ToolStripButton按钮状态
  272. this.SetToolStripButtonEnable();
  273. this.dgvProduction.ReadOnly = true;
  274. }
  275. }
  276. }
  277. catch (Exception ex)
  278. {
  279. // 对异常进行共通处理
  280. ExceptionManager.HandleEventException(this.ToString(),
  281. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  282. }
  283. }
  284. /// <summary>
  285. /// 数据表格选定项改变事件
  286. /// </summary>
  287. /// <param name="sender"></param>
  288. /// <param name="e"></param>
  289. private void dgvProduction_SelectionChanged(object sender, EventArgs e)
  290. {
  291. try
  292. {
  293. if (this.dgvProduction.CurrentCell != null)
  294. {
  295. if (!this.txtBarCode.ReadOnly)
  296. {
  297. this._selecedRow = this.dgvProduction.CurrentCell.RowIndex;
  298. this.dgvDefect.DataSource = null;
  299. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  300. if (flag != null && flag != "")
  301. {
  302. int ProductionDataID = Convert.ToInt32(this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString());
  303. DataSet dsProductionDefect = (DataSet)DoAsync(new AsyncMethod(() =>
  304. {
  305. return PMModuleProxy.Service.GetProductionDefectByProductionDataID(ProductionDataID);
  306. }));
  307. if (dsProductionDefect != null && dsProductionDefect.Tables.Count > Constant.INT_IS_ZERO
  308. && dsProductionDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  309. {
  310. this.dgvDefect.DataSource = dsProductionDefect.Tables[0];
  311. }
  312. }
  313. }
  314. }
  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 tsbtnEdit_Click(object sender, EventArgs e)
  329. {
  330. try
  331. {
  332. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  333. if (this.dgvProduction.CurrentRow != null && (flag != null && flag != ""))
  334. {
  335. int ProductionDataID = Convert.ToInt32(this.dgvProduction.CurrentRow.Cells["ProductionDataID"].Value);
  336. string BarCode = this.dgvProduction.CurrentRow.Cells["BarCode"].Value.ToString();
  337. int CompleteProcedureID = (int)DoAsync(new AsyncMethod(() =>
  338. {
  339. return PMModuleProxy.Service.GetCompleteProcedureID(BarCode);
  340. }));
  341. bool isView = true;
  342. if (CompleteProcedureID != -Constant.INT_IS_ONE && CompleteProcedureID == this._currentProcedureID)
  343. {
  344. // 尽管等于当前工序,但是如果该条码又插入了一条生产数据,在编辑此数据时,也应该为只读,即重烧后添加的生产数据,编辑上一次生产数据ID
  345. int CompleteProductionDataID = (int)DoAsync(new AsyncMethod(() =>
  346. {
  347. return PMModuleProxy.Service.GetCompleteProductionDataID(BarCode);
  348. }));
  349. if (ProductionDataID == CompleteProductionDataID)
  350. {
  351. int auditstatus = (int)DoAsync(new AsyncMethod(() =>
  352. {
  353. return PMModuleProxy.Service.CheckScrapProduct(BarCode);
  354. }));
  355. if (auditstatus != -100)
  356. {
  357. isView = true;
  358. }
  359. else
  360. {
  361. isView = false;
  362. }
  363. // }
  364. }
  365. }
  366. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle, ProductionDataID, isView);
  367. DialogResult dialogResult = frmPM1202.ShowDialog();
  368. // 重新加载GridView
  369. if (dialogResult == DialogResult.OK)
  370. {
  371. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  372. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  373. {
  374. return PMModuleProxy.Service.GetProductionData(requestEntity);
  375. }));
  376. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  377. {
  378. this.dgvProduction.DataSource = null;
  379. this.dgvProduction.DataSource = dtProductionData;
  380. // 设置ToolStripButton按钮状态
  381. this.SetToolStripButtonEnable();
  382. this.dgvProduction.ReadOnly = true;
  383. }
  384. }
  385. }
  386. else
  387. {
  388. MessageBox.Show("无法编辑小计合计数据 请重新选择", this.Text,
  389. MessageBoxButtons.OK, MessageBoxIcon.Information);
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. // 对异常进行共通处理
  395. ExceptionManager.HandleEventException(this.ToString(),
  396. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  397. }
  398. }
  399. #endregion
  400. #region 私有方法
  401. /// <summary>
  402. /// 设置工具按钮的可用状态
  403. /// </summary>
  404. private void SetToolStripButtonEnable()
  405. {
  406. if (this.dgvProduction.CurrentCell != null)
  407. {
  408. this.tsbtnEdit.Enabled = true;
  409. }
  410. else
  411. {
  412. this.tsbtnEdit.Enabled = false;
  413. }
  414. }
  415. /// <summary>
  416. /// 搜索条件
  417. /// </summary>
  418. /// <returns></returns>
  419. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  420. {
  421. SearchProductionDataEntity result = new SearchProductionDataEntity();
  422. result.BarCode = this.txtBarCode.Text.Trim();
  423. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  424. result.GoodsName = this.txtGoodsName.Text.Trim();
  425. result.UserCode = this.txtUserCode.Text.Trim();
  426. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  427. result.Remarks = cobworkshop.Text;//暂传车间(成检部分)
  428. // this.txtRemarks.Text.Trim();
  429. //object[] objRework = this.statusIsReworked.SelectedValues;
  430. //string Rework = "";
  431. //for (int i = 0; i < objRework.Length; i++)
  432. //{
  433. // Rework += objRework[i] + ",";
  434. //}
  435. //Rework = Rework.TrimEnd(',');
  436. //result.IsRework = Rework;
  437. result.BeginDate = this.dtpStartTime.Value;
  438. result.EndDate = this.dtpEndTime.Value;
  439. result.ProcedureID = _currentProcedureID;
  440. if (this.cobKilnName.SelectedValue != null
  441. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnName.SelectedValue.ToString()))
  442. {
  443. result.KilnCode = this.cobKilnName.SelectedValue.ToString();
  444. }
  445. result.KilnCarCode = this.txtKilnCarName.Text.Trim();
  446. result.GroutingUserCode = this.txtGroutingUserCode.Text.Trim();
  447. if (this.cobKilnCarPosition.SelectedValue != null
  448. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnCarPosition.SelectedValue.ToString()))
  449. {
  450. result.KilnCarPosition = Convert.ToInt32(this.cobKilnCarPosition.SelectedValue);
  451. }
  452. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  453. return result;
  454. }
  455. /// <summary>
  456. /// 获取窑炉字典信息
  457. /// </summary>
  458. /// <returns></returns>
  459. private DataTable GetMSTKilnInfo()
  460. {
  461. DataSet dsKilnInfo = (DataSet)DoAsync(new AsyncMethod(() =>
  462. {
  463. byte byFlage = Convert.ToByte(Constant.ValueFlag.Invalid);
  464. return SystemModuleProxy.Service.GetKilnData(byFlage);
  465. }));
  466. DataTable dtKilnInfo = dsKilnInfo.Tables[Constant.INT_IS_ZERO];
  467. DataRow newRowDic = dtKilnInfo.NewRow();
  468. newRowDic["KilnID"] = Constant.CBO_SELECT_ALL_VALUE;
  469. newRowDic["KilnCode"] = Constant.CBO_SELECT_ALL_VALUE;
  470. newRowDic["KilnName"] = Constant.CBO_SELECT_ALL_NAME;
  471. dtKilnInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  472. return dtKilnInfo;
  473. }
  474. /// <summary>
  475. /// 获取窑车位置字典表数据
  476. /// </summary>
  477. /// <returns></returns>
  478. public DataTable GetMSTKilnCarPositionInfo()
  479. {
  480. DataTable dtDicInfo = (DataTable)DoAsync(new AsyncMethod(() =>
  481. {
  482. return CommonModuleProxy.Service.GetDataDictionaryByType(Constant.TPC_TPC003);
  483. }));
  484. DataRow newRowDic = dtDicInfo.NewRow();
  485. newRowDic["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE;
  486. newRowDic["DictionaryValue"] = Constant.CBO_SELECT_ALL_NAME;
  487. dtDicInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  488. return dtDicInfo;
  489. }
  490. #endregion
  491. }
  492. }