F_PM_0901.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0901.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_0901 : DockPanelBase
  27. {
  28. #region 成员变量
  29. // 窗体的单例模式
  30. private static Dictionary<int, F_PM_0901> _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_0901()
  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_0901 Instance(int procedureID, string fromTitle)
  65. {
  66. F_PM_0901 fInstance = null;
  67. if (_dicInstance == null)
  68. {
  69. _dicInstance = new Dictionary<int, F_PM_0901>();
  70. fInstance = new F_PM_0901();
  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_0901();
  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_0901_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. }
  110. catch (Exception ex)
  111. {
  112. // 对异常进行共通处理
  113. ExceptionManager.HandleEventException(this.ToString(),
  114. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  115. }
  116. }
  117. /// <summary>
  118. /// 窗体关闭事件
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void F_PM_0901_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
  123. {
  124. _dicInstance = null;
  125. }
  126. /// <summary>
  127. /// 自动适应列宽
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  132. {
  133. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  134. this.dgvDefect.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  135. }
  136. /// <summary>
  137. /// 清空条件按钮事件
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void btnClearCondition_Click(object sender, EventArgs e)
  142. {
  143. this.txtBarCode.Text = string.Empty;
  144. this.txtGoodsCode.Text = string.Empty;
  145. this.txtGoodsName.Text = string.Empty;
  146. this.txtUserCode.Text = string.Empty;
  147. this.scbOrganization.ClearValue();
  148. //this.txtRemarks.Text = string.Empty;
  149. //this.statusIsReworked.ClearItemCheck();
  150. this.scbGoodsType.ClearValue();
  151. this.dtpStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
  152. this.dtpEndTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1).AddMinutes(-1);
  153. }
  154. /// <summary>
  155. /// 查询按钮事件
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void btnSearch_Click(object sender, EventArgs e)
  160. {
  161. try
  162. {
  163. // 记录当前选中行
  164. int selectRowIndex = this._selecedRow;
  165. // 异步处理
  166. this.btnSearch.Enabled = false;
  167. this.btnClearCondition.Enabled = false;
  168. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  169. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  170. {
  171. return PMModuleProxy.Service.GetProductionData(requestEntity);
  172. }));
  173. DataSet dsProductionData = new DataSet();
  174. dsProductionData.Tables.Add(dtProductionData);
  175. this.btnSearch.Enabled = true;
  176. this.btnClearCondition.Enabled = true;
  177. if (dsProductionData != null)
  178. {
  179. base.DataSource = dsProductionData;
  180. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  181. {
  182. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  183. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  184. {
  185. // 提示未查找到数据
  186. this.tsbtnEdit.Enabled = false;
  187. this.dgvDefect.DataSource = null;
  188. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  189. MessageBoxButtons.OK, MessageBoxIcon.Information);
  190. }
  191. else
  192. {
  193. if (selectRowIndex >= Constant.INT_IS_ZERO)
  194. {
  195. if (selectRowIndex >= dsProductionData.Tables[0].Rows.Count)
  196. {
  197. this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Selected = true;
  198. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[this.dgvProduction.Rows.Count - 1].Cells["GoodsCode"];
  199. }
  200. else
  201. {
  202. this.dgvProduction.Rows[selectRowIndex].Selected = true;
  203. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[selectRowIndex].Cells["GoodsCode"];
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. catch (Exception ex)
  211. {
  212. this.btnSearch.Enabled = true;
  213. this.btnClearCondition.Enabled = true;
  214. // 对异常进行共通处理
  215. ExceptionManager.HandleEventException(this.ToString(),
  216. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  217. }
  218. }
  219. /// <summary>
  220. /// 关闭按钮事件
  221. /// </summary>
  222. /// <param name="sender"></param>
  223. /// <param name="e"></param>
  224. private void tsbtnClose_Click(object sender, EventArgs e)
  225. {
  226. this.Close();
  227. }
  228. /// <summary>
  229. /// 新建按钮事件
  230. /// </summary>
  231. /// <param name="sender"></param>
  232. /// <param name="e"></param>
  233. private void tsbtnAdd_Click(object sender, EventArgs e)
  234. {
  235. try
  236. {
  237. F_PM_0903 frmPM0903 = new F_PM_0903(_currentProcedureID, _fromTitle);
  238. DialogResult dialogResult = frmPM0903.ShowDialog();
  239. // 重新加载GridView
  240. if (dialogResult == DialogResult.OK)
  241. {
  242. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  243. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  244. {
  245. return PMModuleProxy.Service.GetProductionData(requestEntity);
  246. }));
  247. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  248. {
  249. this.dgvProduction.DataSource = null;
  250. this.dgvProduction.DataSource = dtProductionData;
  251. // 设置ToolStripButton按钮状态
  252. this.SetToolStripButtonEnable();
  253. this.dgvProduction.ReadOnly = true;
  254. }
  255. }
  256. }
  257. catch (Exception ex)
  258. {
  259. // 对异常进行共通处理
  260. ExceptionManager.HandleEventException(this.ToString(),
  261. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  262. }
  263. }
  264. /// <summary>
  265. /// 数据表格选定项改变事件
  266. /// </summary>
  267. /// <param name="sender"></param>
  268. /// <param name="e"></param>
  269. private void dgvProduction_SelectionChanged(object sender, EventArgs e)
  270. {
  271. try
  272. {
  273. if (this.dgvProduction.CurrentCell != null)
  274. {
  275. this._selecedRow = this.dgvProduction.CurrentCell.RowIndex;
  276. this.dgvDefect.DataSource = null;
  277. int ProductionDataID = Convert.ToInt32(this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString());
  278. DataSet dsProductionDefect = (DataSet)DoAsync(new AsyncMethod(() =>
  279. {
  280. return PMModuleProxy.Service.GetProductionDefectByProductionDataID(ProductionDataID);
  281. }));
  282. if (dsProductionDefect != null && dsProductionDefect.Tables.Count > Constant.INT_IS_ZERO
  283. && dsProductionDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  284. {
  285. this.tsbtnEdit.Enabled = true;
  286. this.dgvDefect.DataSource = dsProductionDefect.Tables[0];
  287. }
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. // 对异常进行共通处理
  293. ExceptionManager.HandleEventException(this.ToString(),
  294. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  295. }
  296. }
  297. /// <summary>
  298. /// 编辑按钮事件
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void tsbtnEdit_Click(object sender, EventArgs e)
  303. {
  304. try
  305. {
  306. if (this.dgvProduction.CurrentRow != null)
  307. {
  308. string BarCode = this.dgvProduction.CurrentRow.Cells["BarCode"].Value.ToString();
  309. // 判断条码是否成为废品,只能废品进行编辑
  310. int auditstatus = (int)DoAsync(new AsyncMethod(() =>
  311. {
  312. return PMModuleProxy.Service.CheckWasteScrapProduct(BarCode);
  313. }));
  314. if (auditstatus != -100)
  315. {
  316. //可以编辑,获取生产数据ID
  317. int ProductionDataID = Convert.ToInt32(this.dgvProduction.CurrentRow.Cells["ProductionDataID"].Value);
  318. F_PM_0903 frmPM1302 = new F_PM_0903(_currentProcedureID, _fromTitle, ProductionDataID);
  319. DialogResult dialogResult = frmPM1302.ShowDialog();
  320. // 重新加载GridView
  321. if (dialogResult == DialogResult.OK)
  322. {
  323. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  324. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  325. {
  326. return PMModuleProxy.Service.GetProductionData(requestEntity);
  327. }));
  328. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  329. {
  330. this.dgvProduction.DataSource = null;
  331. this.dgvProduction.DataSource = dtProductionData;
  332. // 设置ToolStripButton按钮状态
  333. this.SetToolStripButtonEnable();
  334. this.dgvProduction.ReadOnly = true;
  335. }
  336. }
  337. }
  338. else
  339. {
  340. //不可以编辑,进行错误提示
  341. MessageBox.Show("条码[" + BarCode + "]不是废品,不能进行编辑",
  342. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  343. return;
  344. }
  345. }
  346. }
  347. catch (Exception ex)
  348. {
  349. // 对异常进行共通处理
  350. ExceptionManager.HandleEventException(this.ToString(),
  351. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  352. }
  353. }
  354. #endregion
  355. #region 私有方法
  356. /// <summary>
  357. /// 设置工具按钮的可用状态
  358. /// </summary>
  359. private void SetToolStripButtonEnable()
  360. {
  361. if (this.dgvProduction.CurrentCell != null)
  362. {
  363. this.tsbtnEdit.Enabled = true;
  364. }
  365. else
  366. {
  367. this.tsbtnEdit.Enabled = false;
  368. }
  369. }
  370. /// <summary>
  371. /// 搜索条件
  372. /// </summary>
  373. /// <returns></returns>
  374. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  375. {
  376. SearchProductionDataEntity result = new SearchProductionDataEntity();
  377. result.BarCode = this.txtBarCode.Text.Trim();
  378. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  379. result.GoodsName = this.txtGoodsName.Text.Trim();
  380. result.UserCode = this.txtUserCode.Text.Trim();
  381. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  382. result.Remarks = "";// this.txtRemarks.Text.Trim();
  383. // object[] objRework = this.statusIsReworked.SelectedValues;
  384. string Rework = "";
  385. //for (int i = 0; i < objRework.Length; i++)
  386. //{
  387. // Rework += objRework[i] + ",";
  388. //}
  389. Rework = "";// Rework.TrimEnd(',');
  390. result.IsRework = Rework;
  391. result.BeginDate = this.dtpStartTime.Value;
  392. result.EndDate = this.dtpEndTime.Value;
  393. result.ProcedureID = _currentProcedureID;
  394. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  395. return result;
  396. }
  397. #endregion
  398. }
  399. }