F_PM_3502.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. if (sre.Data.Tables[1].Rows.Count > 0)
  169. {
  170. DataTable dtable2 = sre.Data.Tables[1];
  171. this.dgvSendDetail.DataSource = dtable2;
  172. }
  173. }
  174. }
  175. _warehouseID = Convert.ToInt32(this.cmbWAREHOUSINGCODE.SelectedValue);
  176. //调用sap库存查询接口
  177. cre = new ClientRequestEntity();
  178. cre.NameSpace = "F_PM_3502";
  179. cre.Name = "GetSendOutGoodsLogs";
  180. cre.Properties["LGORT"] = this.cmbWAREHOUSINGCODE.SelectedValue;
  181. sre = DoAsync<ServiceResultEntity>(() =>
  182. {
  183. return PMModuleProxyNew.Service.HandleRequest(cre);
  184. });
  185. if (sre.Status == Constant.ServiceResultStatus.Success)
  186. {
  187. if (sre != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  188. {
  189. _sapInvertory = sre.Data.Tables[0];
  190. }
  191. }
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. // 对异常进行共通处理
  197. ExceptionManager.HandleEventException(this.ToString(),
  198. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  199. }
  200. }
  201. /// <summary>
  202. /// 窗体关闭事件
  203. /// </summary>
  204. /// <param name="sender"></param>
  205. /// <param name="e"></param>
  206. private void F_PM_3502_FormClosed(object sender, FormClosedEventArgs e)
  207. {
  208. _instance = null;
  209. }
  210. /// <summary>
  211. /// 保存
  212. /// </summary>
  213. /// <param name="sender"></param>
  214. /// <param name="e"></param>
  215. private void btnSave_Click(object sender, EventArgs e)
  216. {
  217. try
  218. {
  219. ((DataTable)this.dgvSendDetail.DataSource).AcceptChanges();
  220. ClientRequestEntity cre = new ClientRequestEntity();
  221. cre.NameSpace = "F_PM_3502";
  222. cre.Name = "SaveSendInfo";
  223. cre.Properties["SENDOUTGOODSLOGID"] = this._sendoutGoodsLogID;
  224. cre.Properties["OUTLABELCODE"] = this.txtOUTLABELCODE.Text;
  225. cre.Properties["SENDOUTCODE"] = this.txtSENDOUTCODE.Text;
  226. cre.Properties["WAREHOUSINGCODE"] = this.cmbWAREHOUSINGCODE.SelectedValue;
  227. cre.Properties["RECEIVECODE"] = this.cmbRECEIVECODE.SelectedValue;
  228. cre.Properties["CARPLATECODE"] = this.cmbCARPLATENAME.SelectedValue;
  229. cre.Properties["WAREHOUSINGENAME"] = this.cmbWAREHOUSINGCODE.Text;
  230. cre.Properties["RECEIVEENAME"] = this.cmbRECEIVECODE.Text;
  231. cre.Properties["CARPLATENAME"] = this.cmbCARPLATENAME.Text;
  232. cre.Properties["AccountDateStart"] = this.dtpAccountDateStart.Value;
  233. cre.Properties["DELIVERDATE"] = this.c_DateTimePicker1.Value;
  234. if (dgvSendDetail.DataSource != null)
  235. {
  236. DataTable detail = (DataTable)(dgvSendDetail.DataSource);
  237. cre.Data = new DataSet();
  238. cre.Data.Tables.Add(detail.Copy());
  239. }
  240. else
  241. {
  242. MessageBox.Show(string.Format("发货单信息不能为空"),
  243. this.Text,
  244. MessageBoxButtons.OK,
  245. MessageBoxIcon.Warning);
  246. return;
  247. }
  248. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  249. {
  250. return PMModuleProxyNew.Service.HandleRequest(cre);
  251. });
  252. if (sre.OtherStatus < 0 )
  253. {
  254. //失败
  255. MessageBox.Show(sre.Message,
  256. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  257. return;
  258. }
  259. else
  260. {
  261. //成功
  262. MessageBox.Show("保存成功",
  263. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  264. return;
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. this.btnSave.Enabled = true;
  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 txtOUTLABELCODE_KeyDown(object sender, KeyEventArgs e)
  281. {
  282. if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(this.txtOUTLABELCODE.Text.Trim()))
  283. {
  284. //调用查询
  285. string code = this.txtOUTLABELCODE.Text.Trim();
  286. ClientRequestEntity cre = new ClientRequestEntity();
  287. cre.NameSpace = "F_PM_3502";
  288. cre.Name = "CheckSendInfo";
  289. cre.Properties["code"] = code;
  290. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  291. {
  292. return PMModuleProxyNew.Service.HandleRequest(cre);
  293. });
  294. if (string.IsNullOrEmpty(sre.Message))
  295. {
  296. if (sre.Data.Tables != null && sre.Data.Tables[0].Rows.Count > 0)
  297. {
  298. //先校验物料的库存
  299. DataRow data = sre.Data.Tables[0].Rows[0];
  300. string materialCode = data["MATERIALCODE"].ToString();
  301. decimal counts = Convert.ToDecimal(data["COUNT"]);
  302. DataRow[] row = _sapInvertory.Select(" MATNR = '" + materialCode + "'");
  303. decimal count = 0;
  304. for (int i = 0; i < row.Length; i++)
  305. {
  306. count += Convert.ToDecimal(row[i]["LABST"]);
  307. }
  308. if (counts > count)
  309. {
  310. MessageBox.Show("库存不足",
  311. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  312. return;
  313. }
  314. else
  315. {
  316. var dt = (DataTable)this.dgvSendDetail.DataSource;
  317. if (dt == null)
  318. {
  319. dt = new DataTable();
  320. }
  321. DataRow dr = dt.NewRow();
  322. dr["BANMA"] = data["BANMA"];
  323. dr["GOODSCODE"] = data["GOODSCODE"];
  324. dr["MATERIALCODE"] = data["MATERIALCODE"];
  325. dr["MATERIALREMARK"] = data["MATERIALREMARK"];
  326. dr["BINDINGCOUNT"] = data["COUNT"];
  327. dr["FINISHEDLOADBATCHNO"] = data["FINISHEDLOADBATCHNO"];
  328. dt.Rows.Add(dr);
  329. this.dgvSendDetail.DataSource = dt;
  330. }
  331. }
  332. }
  333. else
  334. {
  335. MessageBox.Show(sre.Message,
  336. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  337. return;
  338. }
  339. }
  340. }
  341. /// <summary>
  342. /// 发货仓库值变化
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. private void cmbWAREHOUSINGCODE_SelectedIndexChanged(object sender, EventArgs e)
  347. {
  348. try
  349. {
  350. if (_warehouseID > 0 && _warehouseID != Convert.ToInt32(this.cmbWAREHOUSINGCODE.SelectedValue))
  351. {
  352. //当仓库值变化时,提示如果变化发出仓,明细数据将清空
  353. DialogResult dialogResult
  354. = MessageBox.Show(string.Format(Messages.MSG_CMN_Q002, "发出仓", "变更"),
  355. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  356. if (dialogResult.Equals(DialogResult.No))
  357. {
  358. this.cmbWAREHOUSINGCODE.SelectedValue = _warehouseID;
  359. return;
  360. }
  361. //清除表格数据
  362. if (dgvSendDetail.DataSource is DataTable dataTable)
  363. {
  364. // 清除所有行,但保留列结构
  365. dataTable.Rows.Clear();
  366. }
  367. _warehouseID = Convert.ToInt32(this.cmbWAREHOUSINGCODE.SelectedValue);
  368. //调用sap库存查询接口
  369. ClientRequestEntity cre = new ClientRequestEntity();
  370. cre.NameSpace = "F_PM_3502";
  371. cre.Name = "GetSendOutGoodsLogs";
  372. cre.Properties["LGORT"] = this.cmbWAREHOUSINGCODE.SelectedValue;
  373. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  374. {
  375. return PMModuleProxyNew.Service.HandleRequest(cre);
  376. });
  377. if (sre.Status == Constant.ServiceResultStatus.Success)
  378. {
  379. if (sre != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  380. {
  381. _sapInvertory = sre.Data.Tables[0];
  382. }
  383. }
  384. }
  385. }
  386. catch (Exception ex)
  387. {
  388. this.btnSave.Enabled = true;
  389. // 对异常进行共通处理
  390. ExceptionManager.HandleEventException(this.ToString(),
  391. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  392. }
  393. }
  394. #endregion
  395. }
  396. }