F_PM_1301.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_1301.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_1301 : DockPanelBase
  27. {
  28. #region 成员变量
  29. // 窗体的单例模式
  30. private static Dictionary<int, F_PM_1301> _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_1301()
  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_1301 Instance(int procedureID, string fromTitle)
  65. {
  66. F_PM_1301 fInstance = null;
  67. if (_dicInstance == null)
  68. {
  69. _dicInstance = new Dictionary<int, F_PM_1301>();
  70. fInstance = new F_PM_1301();
  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_1301();
  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_1301_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_1301_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. this.dgvProduction.DataSource = this.DataSource.Tables[0];
  193. selectRowIndex = 0;
  194. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  195. {
  196. this.dgvDefect.DataSource = null;
  197. this.tsbtnEdit.Enabled = false;
  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_1302 frmPM1302 = new F_PM_1302(_currentProcedureID, _fromTitle);
  249. DialogResult dialogResult = frmPM1302.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. int ProductionDataID = Convert.ToInt32(this.dgvProduction.Rows[_selecedRow].Cells["ProductionDataID"].Value.ToString());
  291. DataSet dsProductionDefect = (DataSet)DoAsync(new AsyncMethod(() =>
  292. {
  293. return PMModuleProxy.Service.GetProductionDefectByProductionDataID(ProductionDataID);
  294. }));
  295. if (dsProductionDefect != null && dsProductionDefect.Tables.Count > Constant.INT_IS_ZERO
  296. && dsProductionDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  297. {
  298. this.tsbtnEdit.Enabled = true;
  299. this.dgvDefect.DataSource = dsProductionDefect.Tables[0];
  300. }
  301. }
  302. }
  303. }
  304. catch (Exception ex)
  305. {
  306. // 对异常进行共通处理
  307. ExceptionManager.HandleEventException(this.ToString(),
  308. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  309. }
  310. }
  311. /// <summary>
  312. /// 编辑按钮事件
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. private void tsbtnEdit_Click(object sender, EventArgs e)
  317. {
  318. try
  319. {
  320. if (this.dgvProduction.CurrentRow != null)
  321. {
  322. string BarCode = this.dgvProduction.CurrentRow.Cells["BarCode"].Value.ToString();
  323. // 判断条码是否成为废品,只能废品进行编辑
  324. int auditstatus = (int)DoAsync(new AsyncMethod(() =>
  325. {
  326. return PMModuleProxy.Service.CheckWasteScrapProduct(BarCode);
  327. }));
  328. if (auditstatus != -100)
  329. {
  330. //可以编辑,获取生产数据ID
  331. int ProductionDataID = Convert.ToInt32(this.dgvProduction.CurrentRow.Cells["ProductionDataID"].Value);
  332. F_PM_1302 frmPM1302 = new F_PM_1302(_currentProcedureID, _fromTitle, ProductionDataID);
  333. DialogResult dialogResult = frmPM1302.ShowDialog();
  334. // 重新加载GridView
  335. if (dialogResult == DialogResult.OK)
  336. {
  337. SearchProductionDataEntity requestEntity = CreatesearchProductionDataRequestEntity();
  338. DataTable dtProductionData = (DataTable)DoAsync(new AsyncMethod(() =>
  339. {
  340. return PMModuleProxy.Service.GetProductionData(requestEntity);
  341. }));
  342. if (dtProductionData != null && dtProductionData.Rows.Count > Constant.INT_IS_ZERO)
  343. {
  344. this.dgvProduction.DataSource = null;
  345. this.dgvProduction.DataSource = dtProductionData;
  346. // 设置ToolStripButton按钮状态
  347. this.SetToolStripButtonEnable();
  348. this.dgvProduction.ReadOnly = true;
  349. }
  350. }
  351. }
  352. else
  353. {
  354. //不可以编辑,进行错误提示
  355. MessageBox.Show("条码[" + BarCode + "]不是废品,不能进行编辑",
  356. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  357. return;
  358. }
  359. }
  360. }
  361. catch (Exception ex)
  362. {
  363. // 对异常进行共通处理
  364. ExceptionManager.HandleEventException(this.ToString(),
  365. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  366. }
  367. }
  368. #endregion
  369. #region 私有方法
  370. /// <summary>
  371. /// 设置工具按钮的可用状态
  372. /// </summary>
  373. private void SetToolStripButtonEnable()
  374. {
  375. if (this.dgvProduction.CurrentCell != null)
  376. {
  377. this.tsbtnEdit.Enabled = true;
  378. }
  379. else
  380. {
  381. this.tsbtnEdit.Enabled = false;
  382. }
  383. }
  384. /// <summary>
  385. /// 搜索条件
  386. /// </summary>
  387. /// <returns></returns>
  388. private SearchProductionDataEntity CreatesearchProductionDataRequestEntity()
  389. {
  390. SearchProductionDataEntity result = new SearchProductionDataEntity();
  391. result.BarCode = this.txtBarCode.Text.Trim();
  392. result.GoodsCode = this.txtGoodsCode.Text.Trim();
  393. result.GoodsName = this.txtGoodsName.Text.Trim();
  394. result.UserCode = this.txtUserCode.Text.Trim();
  395. result.OrganizationID = this.scbOrganization.SearchedPKMember;
  396. result.Remarks = "";
  397. // this.txtRemarks.Text.Trim();
  398. //object[] objRework = this.statusIsReworked.SelectedValues;
  399. //string Rework = "";
  400. //for (int i = 0; i < objRework.Length; i++)
  401. //{
  402. // Rework += objRework[i] + ",";
  403. //}
  404. //Rework = Rework.TrimEnd(',');
  405. //result.IsRework = Rework;
  406. result.BeginDate = this.dtpStartTime.Value;
  407. result.EndDate = this.dtpEndTime.Value;
  408. result.ProcedureID = _currentProcedureID;
  409. if (this.cobKilnName.SelectedValue != null
  410. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnName.SelectedValue.ToString()))
  411. {
  412. result.KilnCode = this.cobKilnName.SelectedValue.ToString();
  413. }
  414. result.KilnCarCode = this.txtKilnCarName.Text.Trim();
  415. if (this.cobKilnCarPosition.SelectedValue != null
  416. && !Constant.CBO_SELECT_ALL_VALUE.ToString().Equals(this.cobKilnCarPosition.SelectedValue.ToString()))
  417. {
  418. result.KilnCarPosition = Convert.ToInt32(this.cobKilnCarPosition.SelectedValue);
  419. }
  420. result.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  421. return result;
  422. }
  423. /// <summary>
  424. /// 获取窑炉字典信息
  425. /// </summary>
  426. /// <returns></returns>
  427. private DataTable GetMSTKilnInfo()
  428. {
  429. DataSet dsKilnInfo = (DataSet)DoAsync(new AsyncMethod(() =>
  430. {
  431. byte byFlage = Convert.ToByte(Constant.ValueFlag.Invalid);
  432. return SystemModuleProxy.Service.GetKilnData(byFlage);
  433. }));
  434. DataTable dtKilnInfo = dsKilnInfo.Tables[Constant.INT_IS_ZERO];
  435. DataRow newRowDic = dtKilnInfo.NewRow();
  436. newRowDic["KilnID"] = Constant.CBO_SELECT_ALL_VALUE;
  437. newRowDic["KilnCode"] = Constant.CBO_SELECT_ALL_VALUE;
  438. newRowDic["KilnName"] = Constant.CBO_SELECT_ALL_NAME;
  439. dtKilnInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  440. return dtKilnInfo;
  441. }
  442. /// <summary>
  443. /// 获取窑车位置字典表数据
  444. /// </summary>
  445. /// <returns></returns>
  446. public DataTable GetMSTKilnCarPositionInfo()
  447. {
  448. DataTable dtDicInfo = (DataTable)DoAsync(new AsyncMethod(() =>
  449. {
  450. return CommonModuleProxy.Service.GetDataDictionaryByType(Constant.TPC_TPC003);
  451. }));
  452. DataRow newRowDic = dtDicInfo.NewRow();
  453. newRowDic["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE;
  454. newRowDic["DictionaryValue"] = Constant.CBO_SELECT_ALL_NAME;
  455. dtDicInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO);
  456. return dtDicInfo;
  457. }
  458. #endregion
  459. }
  460. }