F_PM_2402.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0302.cs
  5. * 2.功能描述:新建标准、坯库计件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/09/23 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.BaseControls;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
  18. using Dongke.IBOSS.PRD.WCF.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  21. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  22. using Dongke.IBOSS.PRD.Client.DataModels;
  23. namespace Dongke.IBOSS.PRD.Client.PMModule
  24. {
  25. public partial class F_PM_2402 : FormBase
  26. {
  27. #region 成员变量
  28. // 数据源Table
  29. private DataTable _dataSourceTable = null;
  30. // 是否有商标
  31. private int? _isLogo = null;
  32. // 是否有商标编码
  33. private string _isLogoCode = "";
  34. // 是否有商标名称
  35. private string _isLogoName = "";
  36. // 1.产成品交接是否限制同商标
  37. private string _isEnable_S_PM_011 = "0";
  38. // 2.产成品交接是否限制同型号
  39. private string _isEnable_S_PM_012 = "0";
  40. // 3.产成品交接是否限制每板装板数量(必须先启用限制同型号);
  41. private string _isEnable_S_PM_013 = "0";
  42. // 最大限制数量
  43. private int _maxPlateLimitNum = 0;
  44. // 产品型号
  45. private string _goodsModel = string.Empty;
  46. // 商标ID
  47. private int? _logoID = null;
  48. // 商标ID
  49. private string _logoName = string.Empty;
  50. #endregion
  51. #region 属性
  52. /// <summary>
  53. /// 绑定GridView数据源
  54. /// </summary>
  55. public DataTable DataSourceTable
  56. {
  57. set
  58. {
  59. _dataSourceTable = value;
  60. }
  61. get
  62. {
  63. if (_dataSourceTable == null)
  64. {
  65. _dataSourceTable = new DataTable("dataSourceTable");
  66. _dataSourceTable.Columns.Add("BarCode");
  67. _dataSourceTable.Columns.Add("FinishedBarCode");
  68. _dataSourceTable.Columns.Add("logoid");
  69. _dataSourceTable.Columns.Add("logocode");
  70. _dataSourceTable.Columns.Add("logoname");
  71. _dataSourceTable.Columns.Add("goodscode");
  72. _dataSourceTable.Columns.Add("UserID");
  73. _dataSourceTable.Columns.Add("GroutingUserCode");
  74. _dataSourceTable.Columns.Add("MouldCode");
  75. _dataSourceTable.Columns.Add("GroutingDate", typeof(DateTime));
  76. _dataSourceTable.Columns.Add("DeliverTime", typeof(DateTime));
  77. _dataSourceTable.Columns.Add("GoodsModel");
  78. _dataSourceTable.Columns.Add("PlateLimitNum");
  79. _dataSourceTable.Columns.Add("OrderNo");
  80. _dataSourceTable.Columns.Add("FHTime", typeof(DateTime));
  81. _dataSourceTable.Columns.Add("FHUserCode");
  82. return _dataSourceTable;
  83. }
  84. else
  85. {
  86. return _dataSourceTable;
  87. }
  88. }
  89. }
  90. #endregion
  91. #region 构造函数
  92. public F_PM_2402()
  93. {
  94. InitializeComponent();
  95. }
  96. #endregion
  97. #region 事件
  98. /// <summary>
  99. /// 窗体关闭事件
  100. /// </summary>
  101. /// <param name="sender"></param>
  102. /// <param name="e"></param>
  103. private void btnClose_Click(object sender, EventArgs e)
  104. {
  105. this.Close();
  106. }
  107. /// <summary>
  108. /// 窗体关闭事件
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void tsbtnClose_Click(object sender, EventArgs e)
  113. {
  114. this.Close();
  115. }
  116. /// <summary>
  117. /// 条形码按键事件
  118. /// </summary>
  119. /// <param name="sender"></param>
  120. /// <param name="e"></param>
  121. private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e)
  122. {
  123. try
  124. {
  125. if (this.txtBarcode.ReadOnly)
  126. {
  127. return;
  128. }
  129. if ((int)e.KeyChar == 13) // 按了回车键
  130. {
  131. if (this.txtBarcode.Text.Trim() == string.Empty)
  132. {
  133. this.txtBarcode.Focus();
  134. return;
  135. }
  136. DataRow[] drRows = this.DataSourceTable.Select("BarCode='" + this.txtBarcode.Text.Trim() + "' or FinishedBarCode='" + this.txtBarcode.Text.Trim() + "'");
  137. if (drRows.Length == Constant.INT_IS_ZERO)
  138. {
  139. // 包装装板,产成品交接不限制
  140. //if (this._maxPlateLimitNum > 0 && this.DataSourceTable.Rows.Count >= this._maxPlateLimitNum)
  141. //{
  142. // MessageBox.Show("超过最大装板数量【" + this._maxPlateLimitNum + "】",
  143. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  144. // this.txtBarcode.Focus();
  145. // this.txtBarcode.SelectAll();
  146. // return;
  147. //}
  148. ServiceResultEntity resultEntity = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  149. {
  150. return PMModuleProxy.Service.FinishedHandoverBarcode(this.txtBarcode.Text.Trim());
  151. }));
  152. if (Convert.ToInt32(resultEntity.Result) > 0)
  153. {
  154. /* 包装装板,产成品交接不限制
  155. if (this.DataSourceTable.Rows.Count == 0)
  156. {
  157. // 设置装板数量
  158. if (this._isEnable_S_PM_013 == "1" && this._isEnable_S_PM_012 == "1")
  159. {
  160. this._maxPlateLimitNum = Convert.ToInt32(resultEntity.Data.Tables[0].Rows[0]["PlateLimitNum"]);
  161. }
  162. this._goodsModel = resultEntity.Data.Tables[0].Rows[0]["GoodsModel"].ToString();
  163. this._logoID = Convert.ToInt32(resultEntity.Data.Tables[0].Rows[0]["logoid"]);
  164. this._logoName = resultEntity.Data.Tables[0].Rows[0]["logoName"].ToString();
  165. }
  166. else
  167. {
  168. #region 启用限制同商标
  169. if (this._isEnable_S_PM_011 == "1")
  170. {
  171. if (Convert.ToInt32(resultEntity.Data.Tables[0].Rows[0]["logoid"]) != this._logoID)
  172. {
  173. MessageBox.Show("此产品【" + resultEntity.Data.Tables[0].Rows[0]["BarCode"] + "】的商标【"
  174. + resultEntity.Data.Tables[0].Rows[0]["logoname"] + "】与此批次商标【" + this._logoName + "】不同,不能进行该操作。 ",
  175. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  176. this.txtBarcode.Focus();
  177. this.txtBarcode.SelectAll();
  178. return;
  179. }
  180. }
  181. #endregion
  182. #region 启用限制同型号
  183. if (this._isEnable_S_PM_012 == "1")
  184. {
  185. if (resultEntity.Data.Tables[0].Rows[0]["GoodsModel"].ToString() != this._goodsModel)
  186. {
  187. MessageBox.Show("此产品【" + resultEntity.Data.Tables[0].Rows[0]["BarCode"] + "】的型号【"
  188. + resultEntity.Data.Tables[0].Rows[0]["GoodsModel"] + "】与此批次型号【" + this._goodsModel + "】不同,不能进行该操作。 ",
  189. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  190. this.txtBarcode.Focus();
  191. this.txtBarcode.SelectAll();
  192. return;
  193. }
  194. }
  195. #endregion
  196. }
  197. */
  198. foreach (DataRow item in resultEntity.Data.Tables[0].Rows)
  199. {
  200. // 添加产到列表
  201. DataRow dr = this.DataSourceTable.NewRow();
  202. dr["BarCode"] = item["BarCode"].ToString();
  203. dr["FinishedBarCode"] = item["FinishedBarCode"].ToString();
  204. dr["goodscode"] = item["goodscode"].ToString();
  205. dr["logoid"] = item["logoid"].ToString();
  206. dr["logoname"] = item["logoname"].ToString();
  207. dr["GroutingUserCode"] = item["GroutingUserCode"].ToString();
  208. dr["MouldCode"] = item["MouldCode"].ToString();
  209. dr["GroutingDate"] = item["GroutingDate"].ToString();
  210. if (!string.IsNullOrEmpty(item["DeliverTime"].ToString()))
  211. {
  212. dr["DeliverTime"] = item["DeliverTime"].ToString();
  213. }
  214. dr["OrderNo"] = this.cmbLogo.Text;
  215. dr["FHTime"] = DateTime.Now;
  216. dr["FHUserCode"] = LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode;
  217. this.DataSourceTable.Rows.Add(dr);
  218. }
  219. this.dgvProduction.CurrentCell = null;
  220. this.dgvProduction.Rows[dgvProduction.RowCount - 1].Selected = true;
  221. this.dgvProduction.CurrentCell = this.dgvProduction.Rows[dgvProduction.RowCount - 1].Cells[0];
  222. this.txtBarcode.Focus();
  223. this.txtBarcode.SelectAll();
  224. this.txtBarcode.Text = "";
  225. this.btnSave.Visible = true;
  226. this.btnSave.Enabled = true;
  227. }
  228. else
  229. {
  230. if (resultEntity.OtherStatus >0)
  231. {
  232. S_CMN_020 frmscmn020 = new S_CMN_020(resultEntity.OtherStatus, resultEntity.Message);
  233. frmscmn020.ShowDialog();
  234. }
  235. else
  236. {
  237. // 表示有错误
  238. MessageBox.Show(string.Format(resultEntity.Message, this.txtBarcode.Text.Trim(), "产品条码"),
  239. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  240. }
  241. this.txtBarcode.Focus();
  242. this.txtBarcode.SelectAll();
  243. return;
  244. }
  245. }
  246. else
  247. {
  248. this.txtBarcode.Text = "";
  249. }
  250. }
  251. }
  252. catch (Exception ex)
  253. {
  254. // 对异常进行共通处理
  255. ExceptionManager.HandleEventException(this.ToString(),
  256. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  257. }
  258. }
  259. /// <summary>
  260. /// 窗体加载事件
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void F_PM_2402_Load(object sender, EventArgs e)
  265. {
  266. try
  267. {
  268. this.dgvProduction.AutoGenerateColumns = false;
  269. this.dgvProduction.DataSource = DataSourceTable;
  270. // 加载权限
  271. FormPermissionManager.FormPermissionControl(this.Name, this,
  272. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  273. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  274. // 加载订单数据源
  275. DataSet dsResultLogo = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  276. {
  277. return PMModuleProxy.Service.GetOrderList(new OrderEntity());
  278. }));
  279. if (dsResultLogo != null && dsResultLogo.Tables[0].Rows.Count > 0)
  280. {
  281. DataView dv = dsResultLogo.Tables[0].DefaultView;
  282. dv.RowFilter = "ValueFlag=1";
  283. DataTable dtNew = dv.ToTable();
  284. DataRow dr = dtNew.NewRow();
  285. dr["OrderID"] = -1;
  286. dr["OrderNo"] = string.Empty;
  287. dtNew.Rows.InsertAt(dr, 0);
  288. this.cmbLogo.DataSource = dtNew;
  289. this.cmbLogo.ValueMember = "OrderID";
  290. this.cmbLogo.DisplayMember = "OrderNo";
  291. }
  292. // 包装装板,产成品交接不限制
  293. //DataSet dsSystemData = (DataSet)DoAsync(new BaseAsyncMethod(GetSystemData));
  294. //if (dsSystemData != null && dsSystemData.Tables[0].Rows.Count > 0)
  295. //{
  296. // this._isEnable_S_PM_011 = dsSystemData.Tables[0].Select("SettingCode='S_PM_011'")[0]["SettingValue"].ToString();
  297. // this._isEnable_S_PM_012 = dsSystemData.Tables[0].Select("SettingCode='S_PM_012'")[0]["SettingValue"].ToString();
  298. // this._isEnable_S_PM_013 = dsSystemData.Tables[0].Select("SettingCode='S_PM_013'")[0]["SettingValue"].ToString();
  299. //}
  300. this.btnSave.Enabled = false;
  301. }
  302. catch (Exception ex)
  303. {
  304. // 对异常进行共通处理
  305. ExceptionManager.HandleEventException(this.ToString(),
  306. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  307. }
  308. }
  309. /// <summary>
  310. /// 删除按钮事件
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void tsbtnDelete_Click(object sender, EventArgs e)
  315. {
  316. if (this.dgvProduction.CurrentCell != null)
  317. {
  318. this.DataSourceTable.Rows[this.dgvProduction.CurrentCell.RowIndex].Delete();
  319. if (this.DataSourceTable.Rows.Count == 0)
  320. {
  321. // 最大限制数量
  322. this._maxPlateLimitNum = 0;
  323. // 产品型号
  324. this._goodsModel = string.Empty;
  325. // 商标ID
  326. this._logoID = null;
  327. // 商标ID
  328. this._logoName = string.Empty;
  329. this.btnSave.Visible = false;
  330. this.btnSave.Enabled = false;
  331. }
  332. }
  333. }
  334. /// <summary>
  335. /// 保存按钮事件
  336. /// </summary>
  337. /// <param name="sender"></param>
  338. /// <param name="e"></param>
  339. private void btnSave_Click(object sender, EventArgs e)
  340. {
  341. try
  342. {
  343. this.DataSourceTable.AcceptChanges();
  344. //if (this.cmbLogo.SelectedValue.ToString() == "-1")
  345. //{
  346. // MessageBox.Show("请选择生产订单",
  347. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  348. // this.cmbLogo.Focus();
  349. // return;
  350. //}
  351. // 包装装板,产成品交接不限制
  352. //if (this._maxPlateLimitNum > 0 && this._maxPlateLimitNum != this.DataSourceTable.Rows.Count)
  353. //{
  354. // MessageBox.Show("未达到装板数量【" + this._maxPlateLimitNum + "】",
  355. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  356. // this.cmbLogo.Focus();
  357. // return;
  358. //}
  359. int orderid = Convert.ToInt32(this.cmbLogo.SelectedValue);
  360. ServiceResultEntity entity = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  361. {
  362. return PMModuleProxy.Service.SaveFinishedHandover(orderid, this.DataSourceTable);
  363. }));
  364. if (Convert.ToInt32(entity.Result) < 0)
  365. {
  366. MessageBox.Show(entity.Message,
  367. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  368. return;
  369. }
  370. else
  371. {
  372. // 提示信息
  373. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新增" + this.Text, "保存"),
  374. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  375. this.txtBarcode.Text = string.Empty;
  376. this.DataSourceTable.Rows.Clear();
  377. this.cmbLogo.SelectedValue = -1;
  378. this.txtOrderNo.Text = string.Empty;
  379. this.btnSave.Visible = false;
  380. this.btnSave.Enabled = false;
  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. /// <summary>
  391. /// 自动适应列宽
  392. /// </summary>
  393. /// <param name="sender"></param>
  394. /// <param name="e"></param>
  395. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  396. {
  397. this.dgvProduction.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  398. }
  399. /// <summary>
  400. /// 窗体关闭时事件
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void F_PM_0302_FormClosing(object sender, FormClosingEventArgs e)
  405. {
  406. if (this.btnSave.Visible)
  407. {
  408. try
  409. {
  410. this.DataSourceTable.AcceptChanges();
  411. if (this.DataSourceTable.Rows.Count > Constant.INT_IS_ZERO)
  412. {
  413. DialogResult result = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  414. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  415. if (result == DialogResult.Yes)
  416. {
  417. // 保存数据
  418. btnSave_Click(sender, e);
  419. }
  420. else if (result == DialogResult.Cancel)
  421. {
  422. e.Cancel = true;
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. // 对异常进行共通处理
  429. ExceptionManager.HandleEventException(this.ToString(),
  430. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  431. }
  432. }
  433. }
  434. /// <summary>
  435. /// 生产订单号回车事件
  436. /// </summary>
  437. /// <param name="sender"></param>
  438. /// <param name="e"></param>
  439. private void txtUserCode_KeyPress(object sender, KeyPressEventArgs e)
  440. {
  441. try
  442. {
  443. if (this.txtOrderNo.ReadOnly)
  444. {
  445. return;
  446. }
  447. if ((int)e.KeyChar == 13) // 按了回车键
  448. {
  449. DataTable dt = this.cmbLogo.DataSource as DataTable;
  450. if (dt != null && dt.Rows.Count > 0)
  451. {
  452. DataRow[] dr = dt.Select("OrderNo='" + this.txtOrderNo.Text.Trim() + "'");
  453. if (dr.Length > 0)
  454. {
  455. this.cmbLogo.SelectedValue = Convert.ToInt32(dr[0]["OrderID"]);
  456. }
  457. else
  458. {
  459. this.cmbLogo.SelectedIndex = 0;
  460. }
  461. this.txtOrderNo.Text = string.Empty;
  462. }
  463. }
  464. }
  465. catch (Exception ex)
  466. {
  467. // 对异常进行共通处理
  468. ExceptionManager.HandleEventException(this.ToString(),
  469. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  470. }
  471. }
  472. #endregion
  473. #region 私有方法
  474. /// <summary>
  475. /// 获取系统参数
  476. /// </summary>
  477. /// <returns></returns>
  478. private object GetSystemData()
  479. {
  480. try
  481. {
  482. return SystemModuleProxy.Service.GetSystemData();
  483. }
  484. catch (Exception ex)
  485. {
  486. throw ex;
  487. }
  488. }
  489. #endregion
  490. }
  491. }