F_PM_3502.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*******************************************************************************
  2. * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_RPT_010201_1.cs
  5. * 2.功能描述:发货单编辑
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 冯林勇 2023/1/11 1.00 新建
  9. *******************************************************************************/
  10. using Dongke.IBOSS.PRD.Basics.BaseResources;
  11. using Dongke.IBOSS.PRD.Client.CommonModule;
  12. using Dongke.IBOSS.PRD.Client.Controls;
  13. using Dongke.IBOSS.PRD.WCF.DataModels;
  14. using Dongke.IBOSS.PRD.WCF.Proxys;
  15. using System;
  16. using System.Data;
  17. using System.Windows.Forms;
  18. namespace Dongke.IBOSS.PRD.Client.PMModule
  19. {
  20. public partial class F_PM_3502 : DKDockPanelBase
  21. {
  22. #region 成员变量
  23. // 窗体的单例模式
  24. private static F_PM_3502 _instance;
  25. // 存储窗口的编辑状态
  26. private Constant.FormMode _editStatus;
  27. private int _sendoutGoodsLogID;
  28. private int _warehouseID;
  29. private DataTable _sapInvertory;
  30. #endregion
  31. #region 构造函数
  32. public F_PM_3502()
  33. {
  34. InitializeComponent();
  35. }
  36. public F_PM_3502(Constant.FormMode editStatus, int sendoutGoodsLogID)
  37. {
  38. InitializeComponent();
  39. this._editStatus = editStatus;
  40. // 根据新建、编辑状态为标题赋值
  41. if (editStatus == Constant.FormMode.Edit)
  42. {
  43. this.Text = "编辑发货单";
  44. this._sendoutGoodsLogID = sendoutGoodsLogID;
  45. }
  46. // 按钮文本
  47. this.btnSave.Text = ButtonText.BTN_SAVE;
  48. }
  49. #endregion
  50. #region 单例模式
  51. /// <summary>
  52. /// 单例模式,防止重复创建窗体
  53. /// </summary>
  54. public static F_PM_3502 Instance
  55. {
  56. get
  57. {
  58. if (_instance == null || _instance.IsDisposed)
  59. {
  60. _instance = new F_PM_3502();
  61. }
  62. return _instance;
  63. }
  64. }
  65. #endregion
  66. #region 事件处理
  67. /// <summary>
  68. /// 窗体加载事件
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. private void F_PM_3502_Load(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. #region 页面数据源
  77. #region 发出/接收仓库
  78. //发出仓库
  79. ServiceResultEntity sreType = DoAsync<ServiceResultEntity>(() =>
  80. {
  81. return ReportModuleProxy.Service.GetRptDictionaryData(0, "TPC027");
  82. }
  83. );
  84. if (sreType.Data == null)
  85. {
  86. return;
  87. }
  88. if (sreType.Data != null && sreType.Data.Tables[0].Rows.Count > 0)
  89. {
  90. // 设置空选项
  91. DataRow dataRow = sreType.Data.Tables[0].NewRow();
  92. dataRow["DictionaryID"] = DBNull.Value;
  93. dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME;
  94. dataRow["DisplayNo"] = 0;
  95. sreType.Data.Tables[0].Rows.InsertAt(dataRow, 0);
  96. this.cmbWAREHOUSINGCODE.DisplayMember = "DictionaryValue";
  97. this.cmbWAREHOUSINGCODE.ValueMember = "DictionaryID";
  98. this.cmbWAREHOUSINGCODE.DataSource = sreType.Data.Tables[0];
  99. }
  100. //接收仓库
  101. sreType = DoAsync<ServiceResultEntity>(() =>
  102. {
  103. return ReportModuleProxy.Service.GetRptDictionaryData(0, "TPC028");
  104. }
  105. );
  106. if (sreType.Data == null)
  107. {
  108. return;
  109. }
  110. if (sreType.Data != null && sreType.Data.Tables[0].Rows.Count > 0)
  111. {
  112. // 设置空选项
  113. DataRow dataRow = sreType.Data.Tables[0].NewRow();
  114. dataRow["DictionaryID"] = DBNull.Value;
  115. dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME;
  116. dataRow["DisplayNo"] = 0;
  117. sreType.Data.Tables[0].Rows.InsertAt(dataRow, 0);
  118. this.cmbRECEIVECODE.DisplayMember = "DictionaryValue";
  119. this.cmbRECEIVECODE.ValueMember = "DictionaryID";
  120. this.cmbRECEIVECODE.DataSource = sreType.Data.Tables[0];
  121. }
  122. #endregion
  123. #region 车牌号
  124. //接收仓库
  125. sreType = DoAsync<ServiceResultEntity>(() =>
  126. {
  127. return ReportModuleProxy.Service.GetRptDictionaryData(0, "TPC029");
  128. }
  129. );
  130. if (sreType.Data == null)
  131. {
  132. return;
  133. }
  134. if (sreType.Data != null && sreType.Data.Tables[0].Rows.Count > 0)
  135. {
  136. // 设置空选项
  137. DataRow dataRow = sreType.Data.Tables[0].NewRow();
  138. dataRow["DictionaryID"] = DBNull.Value;
  139. dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME;
  140. dataRow["DisplayNo"] = 0;
  141. sreType.Data.Tables[0].Rows.InsertAt(dataRow, 0);
  142. this.cmbCARPLATENAME.DisplayMember = "DictionaryValue";
  143. this.cmbCARPLATENAME.ValueMember = "DictionaryID";
  144. this.cmbCARPLATENAME.DataSource = sreType.Data.Tables[0];
  145. }
  146. #endregion
  147. #endregion
  148. //编辑查询数据
  149. if (this._sendoutGoodsLogID > 0)
  150. {
  151. ClientRequestEntity cre = new ClientRequestEntity();
  152. cre.NameSpace = "F_PM_3502";
  153. cre.Name = "GetSendInfo";
  154. cre.Properties["SENDOUTGOODSLOGID"] = this._sendoutGoodsLogID;
  155. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  156. {
  157. return PMModuleProxyNew.Service.HandleRequest(cre);
  158. });
  159. if (sre.Status == Constant.ServiceResultStatus.Success)
  160. {
  161. if (sre != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  162. {
  163. DataTable dtable = sre.Data.Tables[0];
  164. this.txtSENDOUTCODE.Text = dtable.Rows[0]["SENDOUTCODE"].ToString();
  165. this.cmbWAREHOUSINGCODE.SelectedValue = Convert.ToInt32(dtable.Rows[0]["WAREHOUSINGID"]);
  166. this.cmbRECEIVECODE.SelectedValue = Convert.ToInt32(dtable.Rows[0]["RECEIVEID"]);
  167. this.cmbCARPLATENAME.SelectedValue = Convert.ToInt32(dtable.Rows[0]["CARPLATEID"]);
  168. this.dtpAccountDateStart.Value = (DateTime)dtable.Rows[0]["AccountDate"];
  169. this.c_DateTimePicker1.Value = (DateTime)dtable.Rows[0]["DELIVERDATE"];
  170. //cre.Properties["AccountDateStart"] = this.dtpAccountDateStart.Value;
  171. //cre.Properties["DELIVERDATE"] = this.c_DateTimePicker1.Value;
  172. if (sre.Data.Tables[1].Rows.Count > 0)
  173. {
  174. DataTable dtable2 = sre.Data.Tables[1];
  175. this.dgvSendDetail.DataSource = dtable2;
  176. }
  177. }
  178. }
  179. _warehouseID = Convert.ToInt32(this.cmbWAREHOUSINGCODE.SelectedValue);
  180. //调用sap库存查询接口
  181. cre = new ClientRequestEntity();
  182. cre.NameSpace = "F_PM_3502";
  183. cre.Name = "GetSendOutGoodsLogs";
  184. cre.Properties["LGORT"] = this.cmbWAREHOUSINGCODE.SelectedValue;
  185. sre = DoAsync<ServiceResultEntity>(() =>
  186. {
  187. return PMModuleProxyNew.Service.HandleRequest(cre);
  188. });
  189. if (sre.Status == Constant.ServiceResultStatus.Success)
  190. {
  191. if (sre != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  192. {
  193. _sapInvertory = sre.Data.Tables[0];
  194. }
  195. }
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. // 对异常进行共通处理
  201. ExceptionManager.HandleEventException(this.ToString(),
  202. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  203. }
  204. }
  205. /// <summary>
  206. /// 窗体关闭事件
  207. /// </summary>
  208. /// <param name="sender"></param>
  209. /// <param name="e"></param>
  210. private void F_PM_3502_FormClosed(object sender, FormClosedEventArgs e)
  211. {
  212. _instance = null;
  213. }
  214. /// <summary>
  215. /// 保存
  216. /// </summary>
  217. /// <param name="sender"></param>
  218. /// <param name="e"></param>
  219. private void btnSave_Click(object sender, EventArgs e)
  220. {
  221. try
  222. {
  223. ((DataTable)this.dgvSendDetail.DataSource).AcceptChanges();
  224. ClientRequestEntity cre = new ClientRequestEntity();
  225. cre.NameSpace = "F_PM_3502";
  226. cre.Name = "SaveSendInfo";
  227. cre.Properties["SENDOUTGOODSLOGID"] = this._sendoutGoodsLogID;
  228. cre.Properties["OUTLABELCODE"] = this.txtOUTLABELCODE.Text;
  229. cre.Properties["SENDOUTCODE"] = this.txtSENDOUTCODE.Text;
  230. cre.Properties["WAREHOUSINGCODE"] = this.cmbWAREHOUSINGCODE.SelectedValue;
  231. cre.Properties["RECEIVECODE"] = this.cmbRECEIVECODE.SelectedValue;
  232. cre.Properties["CARPLATECODE"] = this.cmbCARPLATENAME.SelectedValue;
  233. cre.Properties["WAREHOUSINGENAME"] = this.cmbWAREHOUSINGCODE.Text;
  234. cre.Properties["RECEIVEENAME"] = this.cmbRECEIVECODE.Text;
  235. cre.Properties["CARPLATENAME"] = this.cmbCARPLATENAME.Text;
  236. cre.Properties["AccountDateStart"] = this.dtpAccountDateStart.Value;
  237. cre.Properties["DELIVERDATE"] = this.c_DateTimePicker1.Value;
  238. if (dgvSendDetail.DataSource != null)
  239. {
  240. DataTable detail = (DataTable)(dgvSendDetail.DataSource);
  241. cre.Data = new DataSet();
  242. cre.Data.Tables.Add(detail.Copy());
  243. }
  244. else
  245. {
  246. MessageBox.Show(string.Format("发货单信息不能为空"),
  247. this.Text,
  248. MessageBoxButtons.OK,
  249. MessageBoxIcon.Warning);
  250. return;
  251. }
  252. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  253. {
  254. return PMModuleProxyNew.Service.HandleRequest(cre);
  255. });
  256. if (sre.OtherStatus < 0 )
  257. {
  258. //失败
  259. MessageBox.Show(sre.Message,
  260. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  261. return;
  262. }
  263. else
  264. {
  265. //成功
  266. MessageBox.Show("保存成功",
  267. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  268. return;
  269. }
  270. }
  271. catch (Exception ex)
  272. {
  273. this.btnSave.Enabled = true;
  274. // 对异常进行共通处理
  275. ExceptionManager.HandleEventException(this.ToString(),
  276. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  277. }
  278. }
  279. /// <summary>
  280. ///编辑时输入外箱码事件
  281. /// </summary>
  282. /// <param name="sender"></param>
  283. /// <param name="e"></param>
  284. private void txtOUTLABELCODE_KeyDown(object sender, KeyEventArgs e)
  285. {
  286. if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(this.txtOUTLABELCODE.Text.Trim()))
  287. {
  288. //调用查询
  289. string code = this.txtOUTLABELCODE.Text.Trim();
  290. ClientRequestEntity cre = new ClientRequestEntity();
  291. cre.NameSpace = "F_PM_3502";
  292. cre.Name = "CheckSendInfo";
  293. cre.Properties["code"] = code;
  294. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  295. {
  296. return PMModuleProxyNew.Service.HandleRequest(cre);
  297. });
  298. if (string.IsNullOrEmpty(sre.Message))
  299. {
  300. if (sre.Data.Tables != null && sre.Data.Tables[0].Rows.Count > 0)
  301. {
  302. //先校验物料的库存
  303. DataRow data = sre.Data.Tables[0].Rows[0];
  304. string materialCode = data["MATERIALCODE"].ToString();
  305. decimal counts = Convert.ToDecimal(data["COUNT"]);
  306. DataRow[] row = _sapInvertory.Select(" MATNR = '" + materialCode + "'");
  307. decimal count = 0;
  308. for (int i = 0; i < row.Length; i++)
  309. {
  310. count += Convert.ToDecimal(row[i]["LABST"]);
  311. }
  312. if (counts > count)
  313. {
  314. MessageBox.Show("库存不足",
  315. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  316. return;
  317. }
  318. else
  319. {
  320. var dt = (DataTable)this.dgvSendDetail.DataSource;
  321. if (dt == null)
  322. {
  323. dt = new DataTable();
  324. }
  325. DataRow dr = dt.NewRow();
  326. dr["BANMA"] = data["BANMA"];
  327. dr["GOODSCODE"] = data["GOODSCODE"];
  328. dr["MATERIALCODE"] = data["MATERIALCODE"];
  329. dr["MATERIALREMARK"] = data["MATERIALREMARK"];
  330. dr["BINDINGCOUNT"] = data["COUNT"];
  331. dr["FINISHEDLOADBATCHNO"] = data["FINISHEDLOADBATCHNO"];
  332. dt.Rows.Add(dr);
  333. this.dgvSendDetail.DataSource = dt;
  334. }
  335. }
  336. }
  337. else
  338. {
  339. MessageBox.Show(sre.Message,
  340. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  341. return;
  342. }
  343. }
  344. }
  345. /// <summary>
  346. /// 发货仓库值变化
  347. /// </summary>
  348. /// <param name="sender"></param>
  349. /// <param name="e"></param>
  350. private void cmbWAREHOUSINGCODE_SelectedIndexChanged(object sender, EventArgs e)
  351. {
  352. try
  353. {
  354. if (_warehouseID > 0 && _warehouseID != Convert.ToInt32(this.cmbWAREHOUSINGCODE.SelectedValue))
  355. {
  356. //当仓库值变化时,提示如果变化发出仓,明细数据将清空
  357. DialogResult dialogResult
  358. = MessageBox.Show(string.Format(Messages.MSG_CMN_Q002, "发出仓", "变更"),
  359. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  360. if (dialogResult.Equals(DialogResult.No))
  361. {
  362. this.cmbWAREHOUSINGCODE.SelectedValue = _warehouseID;
  363. return;
  364. }
  365. //清除表格数据
  366. if (dgvSendDetail.DataSource is DataTable dataTable)
  367. {
  368. // 清除所有行,但保留列结构
  369. dataTable.Rows.Clear();
  370. }
  371. _warehouseID = Convert.ToInt32(this.cmbWAREHOUSINGCODE.SelectedValue);
  372. //调用sap库存查询接口
  373. ClientRequestEntity cre = new ClientRequestEntity();
  374. cre.NameSpace = "F_PM_3502";
  375. cre.Name = "GetSendOutGoodsLogs";
  376. cre.Properties["LGORT"] = this.cmbWAREHOUSINGCODE.SelectedValue;
  377. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  378. {
  379. return PMModuleProxyNew.Service.HandleRequest(cre);
  380. });
  381. if (sre.Status == Constant.ServiceResultStatus.Success)
  382. {
  383. if (sre != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  384. {
  385. _sapInvertory = sre.Data.Tables[0];
  386. }
  387. }
  388. }
  389. }
  390. catch (Exception ex)
  391. {
  392. this.btnSave.Enabled = true;
  393. // 对异常进行共通处理
  394. ExceptionManager.HandleEventException(this.ToString(),
  395. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  396. }
  397. }
  398. #endregion
  399. }
  400. }