F_PM_1201.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. }
  170. /// <summary>
  171. /// 查询按钮事件
  172. /// </summary>
  173. /// <param name="sender"></param>
  174. /// <param name="e"></param>
  175. private void btnSearch_Click(object sender, EventArgs e)
  176. {
  177. try
  178. {
  179. // 记录当前选中行
  180. int selectRowIndex = this._selecedRow;
  181. // 异步处理
  182. this.btnSearch.Enabled = false;
  183. this.btnClearCondition.Enabled = false;
  184. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  185. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  186. {
  187. return PMModuleProxy.Service.GetProductionData(requestEntity);
  188. }));
  189. DataSet dsProductionData = new DataSet();
  190. dsProductionData.Tables.Add(dtProductionData);
  191. this.btnSearch.Enabled = true;
  192. this.btnClearCondition.Enabled = true;
  193. if (dsProductionData != null)
  194. {
  195. base.DataSource = dsProductionData;
  196. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  197. {
  198. tsbtnEdit.Enabled = true;
  199. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  200. selectRowIndex = 0;
  201. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  202. {
  203. tsbtnEdit.Enabled = false;
  204. this.dgvDefect.DataSource = null;
  205. // 提示未查找到数据
  206. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  207. MessageBoxButtons.OK, MessageBoxIcon.Information);
  208. }
  209. else
  210. {
  211. if (selectRowIndex >= Constant.INT_IS_ZERO)
  212. {
  213. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  214. {
  215. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  216. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  217. }
  218. else
  219. {
  220. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  221. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. catch (Exception ex)
  229. {
  230. this.btnSearch.Enabled = true;
  231. this.btnClearCondition.Enabled = true;
  232. // 对异常进行共通处理
  233. ExceptionManager.HandleEventException(this.ToString(),
  234. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  235. }
  236. }
  237. /// <summary>
  238. /// 关闭按钮事件
  239. /// </summary>
  240. /// <param name="sender"></param>
  241. /// <param name="e"></param>
  242. private void tsbtnClose_Click(object sender, EventArgs e)
  243. {
  244. this.Close();
  245. }
  246. /// <summary>
  247. /// 新建按钮事件
  248. /// </summary>
  249. /// <param name="sender"></param>
  250. /// <param name="e"></param>
  251. private void tsbtnAdd_Click(object sender, EventArgs e)
  252. {
  253. try
  254. {
  255. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle);
  256. DialogResult dialogResult = frmPM1202.ShowDialog();
  257. // 重新加载GridView
  258. if (dialogResult == DialogResult.OK)
  259. {
  260. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  261. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  262. {
  263. return PMModuleProxy.Service.GetProductionData(requestEntity);
  264. }));
  265. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  266. {
  267. this.dgvProduction.DataSource = null;
  268. this.dgvProduction.DataSource = dtProductionData;
  269. // 设置ToolStripButton按钮状态
  270. this.SetToolStripButtonEnable();
  271. this.dgvProduction.ReadOnly = true;
  272. }
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. // 对异常进行共通处理
  278. ExceptionManager.HandleEventException(this.ToString(),
  279. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  280. }
  281. }
  282. /// <summary>
  283. /// 数据表格选定项改变事件
  284. /// </summary>
  285. /// <param name="sender"></param>
  286. /// <param name="e"></param>
  287. private void dgvProduction_SelectionChanged(object sender, EventArgs e)
  288. {
  289. try
  290. {
  291. if (this.dgvProduction.CurrentCell != null)
  292. {
  293. if (!this.txtBarCode.ReadOnly)
  294. {
  295. this._selecedRow = this.dgvProduction.CurrentCell.RowIndex;
  296. this.dgvDefect.DataSource = null;
  297. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  298. if (flag != null && flag != "")
  299. {
  300. int ProductionDataID = Convert.ToInt32(this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString());
  301. DataSet dsProductionDefect = (DataSet)DoAsync(new AsyncMethod(() =>
  302. {
  303. return PMModuleProxy.Service.GetProductionDefectByProductionDataID(ProductionDataID);
  304. }));
  305. if (dsProductionDefect != null && dsProductionDefect.Tables.Count > Constant.INT_IS_ZERO
  306. && dsProductionDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  307. {
  308. this.dgvDefect.DataSource = dsProductionDefect.Tables[0];
  309. }
  310. }
  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 tsbtnEdit_Click(object sender, EventArgs e)
  327. {
  328. try
  329. {
  330. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  331. if (this.dgvProduction.CurrentRow != null && (flag != null && flag != ""))
  332. {
  333. int ProductionDataID = Convert.ToInt32(this.dgvProduction.CurrentRow.Cells["ProductionDataID"].Value);
  334. string BarCode = this.dgvProduction.CurrentRow.Cells["BarCode"].Value.ToString();
  335. int CompleteProcedureID = (int)DoAsync(new AsyncMethod(() =>
  336. {
  337. return PMModuleProxy.Service.GetCompleteProcedureID(BarCode);
  338. }));
  339. bool isView = true;
  340. if (CompleteProcedureID != -Constant.INT_IS_ONE && CompleteProcedureID == this._currentProcedureID)
  341. {
  342. // 尽管等于当前工序,但是如果该条码又插入了一条生产数据,在编辑此数据时,也应该为只读,即重烧后添加的生产数据,编辑上一次生产数据ID
  343. int CompleteProductionDataID = (int)DoAsync(new AsyncMethod(() =>
  344. {
  345. return PMModuleProxy.Service.GetCompleteProductionDataID(BarCode);
  346. }));
  347. if (ProductionDataID == CompleteProductionDataID)
  348. {
  349. int auditstatus = (int)DoAsync(new AsyncMethod(() =>
  350. {
  351. return PMModuleProxy.Service.CheckScrapProduct(BarCode);
  352. }));
  353. if (auditstatus != -100)
  354. {
  355. isView = true;
  356. }
  357. else
  358. {
  359. isView = false;
  360. }
  361. // }
  362. }
  363. }
  364. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle, ProductionDataID, isView);
  365. DialogResult dialogResult = frmPM1202.ShowDialog();
  366. // 重新加载GridView
  367. if (dialogResult == DialogResult.OK)
  368. {
  369. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  370. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  371. {
  372. return PMModuleProxy.Service.GetProductionData(requestEntity);
  373. }));
  374. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  375. {
  376. this.dgvProduction.DataSource = null;
  377. this.dgvProduction.DataSource = dtProductionData;
  378. // 设置ToolStripButton按钮状态
  379. this.SetToolStripButtonEnable();
  380. this.dgvProduction.ReadOnly = true;
  381. }
  382. }
  383. }
  384. else
  385. {
  386. MessageBox.Show("无法编辑小计合计数据 请重新选择", this.Text,
  387. MessageBoxButtons.OK, MessageBoxIcon.Information);
  388. }
  389. }
  390. catch (Exception ex)
  391. {
  392. // 对异常进行共通处理
  393. ExceptionManager.HandleEventException(this.ToString(),
  394. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  395. }
  396. }
  397. #endregion
  398. #region 私有方法
  399. /// <summary>
  400. /// 设置工具按钮的可用状态
  401. /// </summary>
  402. private void SetToolStripButtonEnable()
  403. {
  404. if (this.dgvProduction.CurrentCell != null)
  405. {
  406. this.tsbtnEdit.Enabled = true;
  407. }
  408. else
  409. {
  410. this.tsbtnEdit.Enabled = false;
  411. }
  412. }
  413. /// <summary>
  414. /// 搜索条件
  415. /// </summary>
  416. /// <returns></returns>
  417. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  418. {
  419. SearchProductionDataEntity result = new SearchProductionDataEntity();
  420. result.BarCode = this.txtBarCode.Text.Trim();
  421. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  422. result.GoodsName = this.txtGoodsName.Text.Trim();
  423. result.UserCode = this.txtUserCode.Text.Trim();
  424. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  425. result.Remarks = cobworkshop.Text;//暂传车间(成检部分)
  426. // this.txtRemarks.Text.Trim();
  427. //object[] objRework = this.statusIsReworked.SelectedValues;
  428. //string Rework = "";
  429. //for (int i = 0; i < objRework.Length; i++)
  430. //{
  431. // Rework += objRework[i] + ",";
  432. //}
  433. //Rework = Rework.TrimEnd(',');
  434. //result.IsRework = Rework;
  435. result.BeginDate = this.dtpStartTime.Value;
  436. result.EndDate = this.dtpEndTime.Value;
  437. result.ProcedureID = _currentProcedureID;
  438. if (this.cobKilnName.SelectedValue != null
  439. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnName.SelectedValue.ToString()))
  440. {
  441. result.KilnCode = this.cobKilnName.SelectedValue.ToString();
  442. }
  443. result.KilnCarCode = this.txtKilnCarName.Text.Trim();
  444. result.GroutingUserCode = this.txtGroutingUserCode.Text.Trim();
  445. if (this.cobKilnCarPosition.SelectedValue != null
  446. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnCarPosition.SelectedValue.ToString()))
  447. {
  448. result.KilnCarPosition = Convert.ToInt32(this.cobKilnCarPosition.SelectedValue);
  449. }
  450. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  451. return result;
  452. }
  453. /// <summary>
  454. /// 获取窑炉字典信息
  455. /// </summary>
  456. /// <returns></returns>
  457. private DataTable GetMSTKilnInfo()
  458. {
  459. DataSet dsKilnInfo = (DataSet)DoAsync(new AsyncMethod(() =>
  460. {
  461. byte byFlage = Convert.ToByte(Constant.ValueFlag.Invalid);
  462. return SystemModuleProxy.Service.GetKilnData(byFlage);
  463. }));
  464. DataTable dtKilnInfo = dsKilnInfo.Tables[Constant.INT_IS_ZERO];
  465. DataRow newRowDic = dtKilnInfo.NewRow();
  466. newRowDic["KilnID"] = Constant.CBO_SELECT_ALL_VALUE;
  467. newRowDic["KilnCode"] = Constant.CBO_SELECT_ALL_VALUE;
  468. newRowDic["KilnName"] = Constant.CBO_SELECT_ALL_NAME;
  469. dtKilnInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  470. return dtKilnInfo;
  471. }
  472. /// <summary>
  473. /// 获取窑车位置字典表数据
  474. /// </summary>
  475. /// <returns></returns>
  476. public DataTable GetMSTKilnCarPositionInfo()
  477. {
  478. DataTable dtDicInfo = (DataTable)DoAsync(new AsyncMethod(() =>
  479. {
  480. return CommonModuleProxy.Service.GetDataDictionaryByType(Constant.TPC_TPC003);
  481. }));
  482. DataRow newRowDic = dtDicInfo.NewRow();
  483. newRowDic["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE;
  484. newRowDic["DictionaryValue"] = Constant.CBO_SELECT_ALL_NAME;
  485. dtDicInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  486. return dtDicInfo;
  487. }
  488. #endregion
  489. }
  490. }