F_PM_2402.cs 22 KB

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