F_PM_1201.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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 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.PMModule;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. /// <summary>
  24. /// 成品检验一览
  25. /// </summary>
  26. public partial class F_PM_1201 : DockPanelBase
  27. {
  28. #region 成员变量
  29. // 窗体的单例模式
  30. private static Dictionary<int, F_PM_1201> _dicInstance;
  31. // 当前工序ID
  32. private int _currentProcedureID = 0;
  33. // 最后选择行
  34. private int _selecedRow;
  35. // 窗体显示的Title
  36. private string _fromTitle;
  37. #endregion
  38. #region 构造函数
  39. public F_PM_1201()
  40. {
  41. InitializeComponent();
  42. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  43. //编辑
  44. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  45. //自动适应列宽
  46. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  47. //关闭
  48. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  49. //查询
  50. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  51. //清空条件
  52. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  53. //查询条件
  54. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  55. this.Text = _fromTitle;
  56. }
  57. #endregion
  58. #region 单例模式
  59. /// <summary>
  60. /// 一个工序ID有一个单例,防止重复创建窗体
  61. /// </summary>
  62. /// <param name="procedureID">工序ID</param>
  63. /// <returns></returns>
  64. public static F_PM_1201 Instance(int procedureID, string fromTitle)
  65. {
  66. F_PM_1201 fInstance = null;
  67. if (_dicInstance == null)
  68. {
  69. _dicInstance = new Dictionary<int, F_PM_1201>();
  70. fInstance = new F_PM_1201();
  71. _dicInstance.Add(procedureID, fInstance);
  72. }
  73. else if (_dicInstance.ContainsKey(procedureID))
  74. {
  75. fInstance = _dicInstance[procedureID];
  76. }
  77. else
  78. {
  79. fInstance = new F_PM_1201();
  80. _dicInstance.Add(procedureID, fInstance);
  81. }
  82. fInstance._currentProcedureID = procedureID;
  83. fInstance._fromTitle = fromTitle;
  84. fInstance.Text = fromTitle;
  85. return fInstance;
  86. }
  87. #endregion
  88. #region 事件
  89. /// <summary>
  90. /// 窗体加载事件
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. private void F_PM_1201_Load(object sender, System.EventArgs e)
  95. {
  96. try
  97. {
  98. // 加载权限
  99. FormPermissionManager.FormPermissionControl(this.Name, this,
  100. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  101. this.tsbtnAdd.Visible = true;
  102. // 设置表格不自动创建列
  103. this.dgvProduction.AutoGenerateColumns = false;
  104. // 初始化时间控件为当前日期
  105. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  106. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  107. // 设置ToolStripButton状态
  108. this.SetToolStripButtonEnable();
  109. #region 设置下拉列表框的数据源
  110. this.cobKilnName.DataSource = GetMSTKilnInfo();
  111. this.cobKilnName.DisplayMember = "KilnName";
  112. this.cobKilnName.ValueMember = "KilnCode";
  113. this.cobKilnCarPosition.DataSource = GetMSTKilnCarPositionInfo();
  114. this.cobKilnCarPosition.DisplayMember = "DictionaryValue";
  115. this.cobKilnCarPosition.ValueMember = "DictionaryID";
  116. #endregion
  117. }
  118. catch (Exception ex)
  119. {
  120. // 对异常进行共通处理
  121. ExceptionManager.HandleEventException(this.ToString(),
  122. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  123. }
  124. }
  125. /// <summary>
  126. /// 窗体关闭事件
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void F_PM_1201_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
  131. {
  132. _dicInstance = null;
  133. }
  134. /// <summary>
  135. /// 自动适应列宽
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  140. {
  141. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  142. this.dgvDefect.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  143. }
  144. /// <summary>
  145. /// 清空条件按钮事件
  146. /// </summary>
  147. /// <param name="sender"></param>
  148. /// <param name="e"></param>
  149. private void btnClearCondition_Click(object sender, EventArgs e)
  150. {
  151. this.txtBarCode.Text = string.Empty;
  152. this.txtGoodsCode.Text = string.Empty;
  153. this.txtGoodsName.Text = string.Empty;
  154. this.txtUserCode.Text = string.Empty;
  155. this.scbOrganization.ClearValue();
  156. //this.txtRemarks.Text = string.Empty;
  157. this.scbGoodsType.ClearValue();
  158. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  159. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  160. this.cobKilnName.SelectedIndex = Constant.INT_IS_ZERO;
  161. this.txtKilnCarName.Text = string.Empty;
  162. this.cobKilnCarPosition.SelectedIndex = Constant.INT_IS_ZERO;
  163. }
  164. /// <summary>
  165. /// 查询按钮事件
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void btnSearch_Click(object sender, EventArgs e)
  170. {
  171. try
  172. {
  173. // 记录当前选中行
  174. int selectRowIndex = this._selecedRow;
  175. // 异步处理
  176. this.btnSearch.Enabled = false;
  177. this.btnClearCondition.Enabled = false;
  178. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  179. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  180. {
  181. return PMModuleProxy.Service.GetProductionData(requestEntity);
  182. }));
  183. DataSet dsProductionData = new DataSet();
  184. dsProductionData.Tables.Add(dtProductionData);
  185. this.btnSearch.Enabled = true;
  186. this.btnClearCondition.Enabled = true;
  187. if (dsProductionData != null)
  188. {
  189. base.DataSource = dsProductionData;
  190. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  191. {
  192. tsbtnEdit.Enabled = true;
  193. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  194. selectRowIndex = 0;
  195. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  196. {
  197. tsbtnEdit.Enabled = false;
  198. this.dgvDefect.DataSource = null;
  199. // 提示未查找到数据
  200. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  201. MessageBoxButtons.OK, MessageBoxIcon.Information);
  202. }
  203. else
  204. {
  205. if (selectRowIndex >= Constant.INT_IS_ZERO)
  206. {
  207. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  208. {
  209. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  210. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  211. }
  212. else
  213. {
  214. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  215. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. this.btnSearch.Enabled = true;
  225. this.btnClearCondition.Enabled = true;
  226. // 对异常进行共通处理
  227. ExceptionManager.HandleEventException(this.ToString(),
  228. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  229. }
  230. }
  231. /// <summary>
  232. /// 关闭按钮事件
  233. /// </summary>
  234. /// <param name="sender"></param>
  235. /// <param name="e"></param>
  236. private void tsbtnClose_Click(object sender, EventArgs e)
  237. {
  238. this.Close();
  239. }
  240. /// <summary>
  241. /// 新建按钮事件
  242. /// </summary>
  243. /// <param name="sender"></param>
  244. /// <param name="e"></param>
  245. private void tsbtnAdd_Click(object sender, EventArgs e)
  246. {
  247. try
  248. {
  249. F_PM_1202 frmPM1202 = new F_PM_1202(_currentProcedureID, _fromTitle);
  250. DialogResult dialogResult = frmPM1202.ShowDialog();
  251. // 重新加载GridView
  252. if (dialogResult == DialogResult.OK)
  253. {
  254. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  255. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  256. {
  257. return PMModuleProxy.Service.GetProductionData(requestEntity);
  258. }));
  259. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  260. {
  261. this.dgvProduction.DataSource = null;
  262. this.dgvProduction.DataSource = dtProductionData;
  263. // 设置ToolStripButton按钮状态
  264. this.SetToolStripButtonEnable();
  265. this.dgvProduction.ReadOnly = true;
  266. }
  267. }
  268. }
  269. catch (Exception ex)
  270. {
  271. // 对异常进行共通处理
  272. ExceptionManager.HandleEventException(this.ToString(),
  273. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  274. }
  275. }
  276. /// <summary>
  277. /// 数据表格选定项改变事件
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void dgvProduction_SelectionChanged(object sender, EventArgs e)
  282. {
  283. try
  284. {
  285. if (this.dgvProduction.CurrentCell != null)
  286. {
  287. if (!this.txtBarCode.ReadOnly)
  288. {
  289. this._selecedRow = this.dgvProduction.CurrentCell.RowIndex;
  290. this.dgvDefect.DataSource = null;
  291. string flag = this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString();
  292. if (flag != null && flag != "") {
  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. MessageBox.Show("无法编辑小计合计数据 请重新选择", this.Text,
  379. MessageBoxButtons.OK, MessageBoxIcon.Information);
  380. }
  381. }
  382. catch (Exception ex)
  383. {
  384. // 对异常进行共通处理
  385. ExceptionManager.HandleEventException(this.ToString(),
  386. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  387. }
  388. }
  389. #endregion
  390. #region 私有方法
  391. /// <summary>
  392. /// 设置工具按钮的可用状态
  393. /// </summary>
  394. private void SetToolStripButtonEnable()
  395. {
  396. if (this.dgvProduction.CurrentCell != null)
  397. {
  398. this.tsbtnEdit.Enabled = true;
  399. }
  400. else
  401. {
  402. this.tsbtnEdit.Enabled = false;
  403. }
  404. }
  405. /// <summary>
  406. /// 搜索条件
  407. /// </summary>
  408. /// <returns></returns>
  409. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  410. {
  411. SearchProductionDataEntity result = new SearchProductionDataEntity();
  412. result.BarCode = this.txtBarCode.Text.Trim();
  413. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  414. result.GoodsName = this.txtGoodsName.Text.Trim();
  415. result.UserCode = this.txtUserCode.Text.Trim();
  416. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  417. result.Remarks = "";
  418. // this.txtRemarks.Text.Trim();
  419. //object[] objRework = this.statusIsReworked.SelectedValues;
  420. //string Rework = "";
  421. //for (int i = 0; i < objRework.Length; i++)
  422. //{
  423. // Rework += objRework[i] + ",";
  424. //}
  425. //Rework = Rework.TrimEnd(',');
  426. //result.IsRework = Rework;
  427. result.BeginDate = this.dtpStartTime.Value;
  428. result.EndDate = this.dtpEndTime.Value;
  429. result.ProcedureID = _currentProcedureID;
  430. if (this.cobKilnName.SelectedValue != null
  431. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnName.SelectedValue.ToString()))
  432. {
  433. result.KilnCode = this.cobKilnName.SelectedValue.ToString();
  434. }
  435. result.KilnCarCode = this.txtKilnCarName.Text.Trim();
  436. if (this.cobKilnCarPosition.SelectedValue != null
  437. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnCarPosition.SelectedValue.ToString()))
  438. {
  439. result.KilnCarPosition = Convert.ToInt32(this.cobKilnCarPosition.SelectedValue);
  440. }
  441. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  442. return result;
  443. }
  444. /// <summary>
  445. /// 获取窑炉字典信息
  446. /// </summary>
  447. /// <returns></returns>
  448. private DataTable GetMSTKilnInfo()
  449. {
  450. DataSet dsKilnInfo = (DataSet)DoAsync(new AsyncMethod(() =>
  451. {
  452. byte byFlage = Convert.ToByte(Constant.ValueFlag.Invalid);
  453. return SystemModuleProxy.Service.GetKilnData(byFlage);
  454. }));
  455. DataTable dtKilnInfo = dsKilnInfo.Tables[Constant.INT_IS_ZERO];
  456. DataRow newRowDic = dtKilnInfo.NewRow();
  457. newRowDic["KilnID"] = Constant.CBO_SELECT_ALL_VALUE;
  458. newRowDic["KilnCode"] = Constant.CBO_SELECT_ALL_VALUE;
  459. newRowDic["KilnName"] = Constant.CBO_SELECT_ALL_NAME;
  460. dtKilnInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  461. return dtKilnInfo;
  462. }
  463. /// <summary>
  464. /// 获取窑车位置字典表数据
  465. /// </summary>
  466. /// <returns></returns>
  467. public DataTable GetMSTKilnCarPositionInfo()
  468. {
  469. DataTable dtDicInfo = (DataTable)DoAsync(new AsyncMethod(() =>
  470. {
  471. return CommonModuleProxy.Service.GetDataDictionaryByType(Constant.TPC_TPC003);
  472. }));
  473. DataRow newRowDic = dtDicInfo.NewRow();
  474. newRowDic["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE;
  475. newRowDic["DictionaryValue"] = Constant.CBO_SELECT_ALL_NAME;
  476. dtDicInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  477. return dtDicInfo;
  478. }
  479. #endregion
  480. }
  481. }