F_PM_1201.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. // 加载权限
  98. FormPermissionManager.FormPermissionControl(this.Name, this,
  99. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  100. this.tsbtnAdd.Visible = true;
  101. // 设置表格不自动创建列
  102. this.dgvProduction.AutoGenerateColumns = false;
  103. // 初始化时间控件为当前日期
  104. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  105. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  106. // 设置ToolStripButton状态
  107. this.SetToolStripButtonEnable();
  108. #region 设置下拉列表框的数据源
  109. this.cobKilnName.DataSource = GetMSTKilnInfo();
  110. this.cobKilnName.DisplayMember = "KilnName";
  111. this.cobKilnName.ValueMember = "KilnCode";
  112. this.cobKilnCarPosition.DataSource = GetMSTKilnCarPositionInfo();
  113. this.cobKilnCarPosition.DisplayMember = "DictionaryValue";
  114. this.cobKilnCarPosition.ValueMember = "DictionaryID";
  115. #endregion
  116. }
  117. catch (Exception ex)
  118. {
  119. // 对异常进行共通处理
  120. ExceptionManager.HandleEventException(this.ToString(),
  121. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  122. }
  123. }
  124. /// <summary>
  125. /// 窗体关闭事件
  126. /// </summary>
  127. /// <param name="sender"></param>
  128. /// <param name="e"></param>
  129. private void F_PM_1201_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
  130. {
  131. _dicInstance = null;
  132. }
  133. /// <summary>
  134. /// 自动适应列宽
  135. /// </summary>
  136. /// <param name="sender"></param>
  137. /// <param name="e"></param>
  138. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  139. {
  140. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  141. this.dgvDefect.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  142. }
  143. /// <summary>
  144. /// 清空条件按钮事件
  145. /// </summary>
  146. /// <param name="sender"></param>
  147. /// <param name="e"></param>
  148. private void btnClearCondition_Click(object sender, EventArgs e)
  149. {
  150. this.txtBarCode.Text = string.Empty;
  151. this.txtGoodsCode.Text = string.Empty;
  152. this.txtGoodsName.Text = string.Empty;
  153. this.txtUserCode.Text = string.Empty;
  154. this.scbOrganization.ClearValue();
  155. //this.txtRemarks.Text = string.Empty;
  156. this.scbGoodsType.ClearValue();
  157. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  158. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  159. this.cobKilnName.SelectedIndex = Constant.INT_IS_ZERO;
  160. this.txtKilnCarName.Text = string.Empty;
  161. this.cobKilnCarPosition.SelectedIndex = Constant.INT_IS_ZERO;
  162. }
  163. /// <summary>
  164. /// 查询按钮事件
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void btnSearch_Click(object sender, EventArgs e)
  169. {
  170. try
  171. {
  172. // 记录当前选中行
  173. int selectRowIndex = this._selecedRow;
  174. // 异步处理
  175. this.btnSearch.Enabled = false;
  176. this.btnClearCondition.Enabled = false;
  177. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  178. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  179. {
  180. return PMModuleProxy.Service.GetProductionData(requestEntity);
  181. }));
  182. DataSet dsProductionData = new DataSet();
  183. dsProductionData.Tables.Add(dtProductionData);
  184. this.btnSearch.Enabled = true;
  185. this.btnClearCondition.Enabled = true;
  186. if (dsProductionData != null)
  187. {
  188. base.DataSource = dsProductionData;
  189. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  190. {
  191. tsbtnEdit.Enabled = true;
  192. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  193. selectRowIndex = 0;
  194. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  195. {
  196. tsbtnEdit.Enabled = false;
  197. this.dgvDefect.DataSource = null;
  198. // 提示未查找到数据
  199. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  200. MessageBoxButtons.OK, MessageBoxIcon.Information);
  201. }
  202. else
  203. {
  204. if (selectRowIndex >= Constant.INT_IS_ZERO)
  205. {
  206. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  207. {
  208. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  209. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  210. }
  211. else
  212. {
  213. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  214. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. catch (Exception ex)
  222. {
  223. this.btnSearch.Enabled = true;
  224. this.btnClearCondition.Enabled = true;
  225. // 对异常进行共通处理
  226. ExceptionManager.HandleEventException(this.ToString(),
  227. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  228. }
  229. }
  230. /// <summary>
  231. /// 关闭按钮事件
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. private void tsbtnClose_Click(object sender, EventArgs e)
  236. {
  237. this.Close();
  238. }
  239. /// <summary>
  240. /// 新建按钮事件
  241. /// </summary>
  242. /// <param name="sender"></param>
  243. /// <param name="e"></param>
  244. private void tsbtnAdd_Click(object sender, EventArgs e)
  245. {
  246. try
  247. {
  248. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle);
  249. DialogResult dialogResult = frmPM1202.ShowDialog();
  250. // 重新加载GridView
  251. if (dialogResult == DialogResult.OK)
  252. {
  253. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  254. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  255. {
  256. return PMModuleProxy.Service.GetProductionData(requestEntity);
  257. }));
  258. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  259. {
  260. this.dgvProduction.DataSource = null;
  261. this.dgvProduction.DataSource = dtProductionData;
  262. // 设置ToolStripButton按钮状态
  263. this.SetToolStripButtonEnable();
  264. this.dgvProduction.ReadOnly = true;
  265. }
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. // 对异常进行共通处理
  271. ExceptionManager.HandleEventException(this.ToString(),
  272. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  273. }
  274. }
  275. /// <summary>
  276. /// 数据表格选定项改变事件
  277. /// </summary>
  278. /// <param name="sender"></param>
  279. /// <param name="e"></param>
  280. private void dgvProduction_SelectionChanged(object sender, EventArgs e)
  281. {
  282. try
  283. {
  284. if (this.dgvProduction.CurrentCell != null)
  285. {
  286. if (!this.txtBarCode.ReadOnly)
  287. {
  288. this._selecedRow = this.dgvProduction.CurrentCell.RowIndex;
  289. this.dgvDefect.DataSource = null;
  290. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  291. if (flag != null && flag != "")
  292. {
  293. int ProductionDataID = Convert.ToInt32(this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString());
  294. DataSet dsProductionDefect = (DataSet)DoAsync(new AsyncMethod(() =>
  295. {
  296. return PMModuleProxy.Service.GetProductionDefectByProductionDataID(ProductionDataID);
  297. }));
  298. if (dsProductionDefect != null && dsProductionDefect.Tables.Count > Constant.INT_IS_ZERO
  299. && dsProductionDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  300. {
  301. this.dgvDefect.DataSource = dsProductionDefect.Tables[0];
  302. }
  303. }
  304. }
  305. }
  306. }
  307. catch (Exception ex)
  308. {
  309. // 对异常进行共通处理
  310. ExceptionManager.HandleEventException(this.ToString(),
  311. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  312. }
  313. }
  314. /// <summary>
  315. /// 编辑按钮事件
  316. /// </summary>
  317. /// <param name="sender"></param>
  318. /// <param name="e"></param>
  319. private void tsbtnEdit_Click(object sender, EventArgs e)
  320. {
  321. try
  322. {
  323. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  324. if (this.dgvProduction.CurrentRow != null && (flag != null && flag != ""))
  325. {
  326. int ProductionDataID = Convert.ToInt32(this.dgvProduction.CurrentRow.Cells["ProductionDataID"].Value);
  327. string BarCode = this.dgvProduction.CurrentRow.Cells["BarCode"].Value.ToString();
  328. int CompleteProcedureID = (int)DoAsync(new AsyncMethod(() =>
  329. {
  330. return PMModuleProxy.Service.GetCompleteProcedureID(BarCode);
  331. }));
  332. bool isView = true;
  333. if (CompleteProcedureID != -Constant.INT_IS_ONE && CompleteProcedureID == this._currentProcedureID)
  334. {
  335. // 尽管等于当前工序,但是如果该条码又插入了一条生产数据,在编辑此数据时,也应该为只读,即重烧后添加的生产数据,编辑上一次生产数据ID
  336. int CompleteProductionDataID = (int)DoAsync(new AsyncMethod(() =>
  337. {
  338. return PMModuleProxy.Service.GetCompleteProductionDataID(BarCode);
  339. }));
  340. if (ProductionDataID == CompleteProductionDataID)
  341. {
  342. int auditstatus = (int)DoAsync(new AsyncMethod(() =>
  343. {
  344. return PMModuleProxy.Service.CheckScrapProduct(BarCode);
  345. }));
  346. if (auditstatus != -100)
  347. {
  348. isView = true;
  349. }
  350. else
  351. {
  352. isView = false;
  353. }
  354. // }
  355. }
  356. }
  357. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle, ProductionDataID, isView);
  358. DialogResult dialogResult = frmPM1202.ShowDialog();
  359. // 重新加载GridView
  360. if (dialogResult == DialogResult.OK)
  361. {
  362. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  363. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  364. {
  365. return PMModuleProxy.Service.GetProductionData(requestEntity);
  366. }));
  367. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  368. {
  369. this.dgvProduction.DataSource = null;
  370. this.dgvProduction.DataSource = dtProductionData;
  371. // 设置ToolStripButton按钮状态
  372. this.SetToolStripButtonEnable();
  373. this.dgvProduction.ReadOnly = true;
  374. }
  375. }
  376. }
  377. else
  378. {
  379. MessageBox.Show("无法编辑小计合计数据 请重新选择", this.Text,
  380. MessageBoxButtons.OK, MessageBoxIcon.Information);
  381. }
  382. }
  383. catch (Exception ex)
  384. {
  385. // 对异常进行共通处理
  386. ExceptionManager.HandleEventException(this.ToString(),
  387. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  388. }
  389. }
  390. #endregion
  391. #region 私有方法
  392. /// <summary>
  393. /// 设置工具按钮的可用状态
  394. /// </summary>
  395. private void SetToolStripButtonEnable()
  396. {
  397. if (this.dgvProduction.CurrentCell != null)
  398. {
  399. this.tsbtnEdit.Enabled = true;
  400. }
  401. else
  402. {
  403. this.tsbtnEdit.Enabled = false;
  404. }
  405. }
  406. /// <summary>
  407. /// 搜索条件
  408. /// </summary>
  409. /// <returns></returns>
  410. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  411. {
  412. SearchProductionDataEntity result = new SearchProductionDataEntity();
  413. result.BarCode = this.txtBarCode.Text.Trim();
  414. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  415. result.GoodsName = this.txtGoodsName.Text.Trim();
  416. result.UserCode = this.txtUserCode.Text.Trim();
  417. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  418. result.Remarks = "";
  419. // this.txtRemarks.Text.Trim();
  420. //object[] objRework = this.statusIsReworked.SelectedValues;
  421. //string Rework = "";
  422. //for (int i = 0; i < objRework.Length; i++)
  423. //{
  424. // Rework += objRework[i] + ",";
  425. //}
  426. //Rework = Rework.TrimEnd(',');
  427. //result.IsRework = Rework;
  428. result.BeginDate = this.dtpStartTime.Value;
  429. result.EndDate = this.dtpEndTime.Value;
  430. result.ProcedureID = _currentProcedureID;
  431. if (this.cobKilnName.SelectedValue != null
  432. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnName.SelectedValue.ToString()))
  433. {
  434. result.KilnCode = this.cobKilnName.SelectedValue.ToString();
  435. }
  436. result.KilnCarCode = this.txtKilnCarName.Text.Trim();
  437. if (this.cobKilnCarPosition.SelectedValue != null
  438. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnCarPosition.SelectedValue.ToString()))
  439. {
  440. result.KilnCarPosition = Convert.ToInt32(this.cobKilnCarPosition.SelectedValue);
  441. }
  442. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  443. return result;
  444. }
  445. /// <summary>
  446. /// 获取窑炉字典信息
  447. /// </summary>
  448. /// <returns></returns>
  449. private DataTable GetMSTKilnInfo()
  450. {
  451. DataSet dsKilnInfo = (DataSet)DoAsync(new AsyncMethod(() =>
  452. {
  453. byte byFlage = Convert.ToByte(Constant.ValueFlag.Invalid);
  454. return SystemModuleProxy.Service.GetKilnData(byFlage);
  455. }));
  456. DataTable dtKilnInfo = dsKilnInfo.Tables[Constant.INT_IS_ZERO];
  457. DataRow newRowDic = dtKilnInfo.NewRow();
  458. newRowDic["KilnID"] = Constant.CBO_SELECT_ALL_VALUE;
  459. newRowDic["KilnCode"] = Constant.CBO_SELECT_ALL_VALUE;
  460. newRowDic["KilnName"] = Constant.CBO_SELECT_ALL_NAME;
  461. dtKilnInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  462. return dtKilnInfo;
  463. }
  464. /// <summary>
  465. /// 获取窑车位置字典表数据
  466. /// </summary>
  467. /// <returns></returns>
  468. public DataTable GetMSTKilnCarPositionInfo()
  469. {
  470. DataTable dtDicInfo = (DataTable)DoAsync(new AsyncMethod(() =>
  471. {
  472. return CommonModuleProxy.Service.GetDataDictionaryByType(Constant.TPC_TPC003);
  473. }));
  474. DataRow newRowDic = dtDicInfo.NewRow();
  475. newRowDic["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE;
  476. newRowDic["DictionaryValue"] = Constant.CBO_SELECT_ALL_NAME;
  477. dtDicInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  478. return dtDicInfo;
  479. }
  480. #endregion
  481. }
  482. }