ExcCreateDeliveryM.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using com.hnshituo.pur.vo;
  11. using Core.Mes.Client.Comm.Control;
  12. using CoreFS.CA06;using Pur.Entity;
  13. using Infragistics.Win.UltraWinGrid;
  14. using Pur.Entity.ck;
  15. using Pur.Entity.require_planEntiy;
  16. using Core.Mes.Client.Comm.Tool;
  17. using Core.Mes.Client.Comm.Server;
  18. using Pur.order;
  19. namespace Pur.ck
  20. {
  21. public partial class ExcCreateDeliveryM : FrmPmsBase
  22. {
  23. private int tips;
  24. private string noticeId="";
  25. ExcDeliveryNoticeM tempEsm;
  26. public int Tips
  27. {
  28. get { return tips; }
  29. set { tips = value; }
  30. }
  31. public ExcCreateDeliveryM(OpeBase ob, string strNoticeId)
  32. {
  33. this.ob = ob;
  34. this.noticeId = strNoticeId;
  35. InitializeComponent();
  36. }
  37. private void ExcCreateDeliveryM_Load(object sender, EventArgs e)
  38. {
  39. getDropDown();
  40. this.tips = 0;
  41. GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new String[] { "CHK","createQty", "carNum", "batchNo" });
  42. init();
  43. }
  44. #region tooolbar工具区
  45. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  46. {
  47. switch (e.Tool.Key)
  48. {
  49. case "doRefresh": // 提交
  50. doRefresh();
  51. break;
  52. case "doChange": // 提交
  53. doCreate();
  54. break;
  55. case "Close": // 关闭当前页
  56. this.Close();
  57. break;
  58. case "doSpit": // 拆分装车
  59. doSpit();
  60. break;
  61. }
  62. }
  63. //拆分装车
  64. private void doSpit()
  65. {
  66. ultraGrid3.UpdateData();
  67. UltraGridRow uge = ultraGrid3.ActiveRow;
  68. if (uge == null)
  69. {
  70. MessageUtil.ShowTips("请选择通知单行进行操作");
  71. return;
  72. }
  73. frmPopNoticeItemSpit frm = new frmPopNoticeItemSpit(this.ob);
  74. frm.ShowDialog();
  75. if (frm.tips == "1" && frm.num>=2)
  76. {
  77. int qtySpit=0;
  78. for(int i=0;i<frm.num-1;i++)
  79. {
  80. if (dataTable2.Select("noticeLineSqe = '" + ultraGrid3.ActiveRow.Cells["noticeLineSqe"].Text.Trim() + "'").Length > 0)
  81. {
  82. DataRow row = dataTable2.Select("noticeLineSqe = '" + ultraGrid3.ActiveRow.Cells["noticeLineSqe"].Text.Trim() + "'")[0];
  83. if (i == 0)
  84. {
  85. try
  86. {
  87. double dbCanUseQty = Convert.ToDouble(row["canUseQty"]);
  88. double dbcreateQty = Convert.ToDouble(row["createQty"]);
  89. if (dbCanUseQty == dbcreateQty)
  90. {
  91. qtySpit = (int)(Convert.ToDouble(row["canUseQty"]) / frm.num);
  92. }
  93. else
  94. {
  95. qtySpit = 0;
  96. }
  97. }
  98. catch (Exception)
  99. {
  100. qtySpit=0;
  101. }
  102. }
  103. row["createQty"] = qtySpit;
  104. dataTable2.ImportRow(row);
  105. }
  106. }
  107. dataTable2.DefaultView.Sort = "noticeLineSqe desc";
  108. GridHelper.CopyDataToDatatable(dataTable2.DefaultView.ToTable(),dataTable2,true);
  109. //ultraGrid3.DataSource = dataTable2.DefaultView.ToTable();
  110. }
  111. }
  112. //刷新数据
  113. private void doRefresh()
  114. {
  115. init();
  116. }
  117. //提交数据
  118. private void doCreate()
  119. {
  120. ultraGrid3.UpdateData();
  121. //校验数据
  122. int i=0;
  123. foreach (UltraGridRow row in ultraGrid3.Rows)
  124. {
  125. if (Convert.ToBoolean(row.Cells["CHK"].Value) == true)
  126. {
  127. i = i + 1;
  128. double dbcanUseQty = Convert.ToDouble(row.Cells["canUseQty"].Value);
  129. double dbCreateQty = Convert.ToDouble(row.Cells["createQty"].Value);
  130. if (dbcanUseQty <dbCreateQty || dbCreateQty<=0)
  131. {
  132. MessageBox.Show("物料[" + row.Cells["itemCode"].Value.ToString() + "]的编制量不能大于可编制量且需大于0", "提示");
  133. return;
  134. }
  135. }
  136. }
  137. if (i <= 0)
  138. {
  139. MessageUtil.ShowTips("未编制物料!");
  140. return;
  141. }
  142. //准备数据写入
  143. ExcDeliverySubM sm = new ExcDeliverySubM();
  144. sm.NoticeId=tempEsm.NoticeId;
  145. sm.Status="1";
  146. sm.OrderId = tempEsm.OrderId;
  147. sm.DeliveryLocationCode = tempEsm.DeliveryLocationCode;
  148. sm.DeliveryLocation = tempEsm.DeliveryLocation;
  149. sm.SuppCode=tempEsm.SuppCode;
  150. sm.SuppName=tempEsm.SuppName;
  151. sm.PlanedDeliveryDate=tempEsm.PlanedDeliveryDate;
  152. sm.Validflag="1";
  153. sm.CreateName = UserInfo.GetUserName();
  154. sm.CreateUserid = UserInfo.GetUserID();
  155. sm.CreateTime=DateTime.Now;
  156. sm.DeliveryCondition=tempEsm.DeliveryCondition;
  157. sm.BuyerDeptCode = UserInfo.GetDeptid();
  158. if (txt_deliveryType.SelectedIndex == -1)
  159. {
  160. MessageUtil.ShowTips("请选择运输方式");
  161. txt_deliveryType.Focus();
  162. return;
  163. }
  164. if (txt_receive_type.SelectedIndex == -1)
  165. {
  166. MessageUtil.ShowTips("请选择接收方式");
  167. txt_receive_type.Focus();
  168. return;
  169. }
  170. sm.DeliveryType = txt_deliveryType.Value.ToString();
  171. sm.ReceiveType = txt_receive_type.Value.ToString();
  172. List<ExcDeliverySubC> list = new List<ExcDeliverySubC>();
  173. foreach (UltraGridRow row in ultraGrid3.Rows)
  174. {
  175. if (Convert.ToBoolean(row.Cells["CHK"].Value) == true)
  176. {
  177. double dbCreateQty = Convert.ToDouble(row.Cells["createQty"].Value);
  178. String strNoticeLineSqe=row.GetCellValue("noticeLineSqe").ToString().Trim();
  179. if(String.IsNullOrEmpty(strNoticeLineSqe))
  180. {
  181. MessageUtil.ShowTips("送货单行编辑区第"+row.Index+"条数据通知单行号为空");
  182. return;
  183. }
  184. ExcDeliveryNoticeC tempEsc = this.execute<ExcDeliveryNoticeC>("com.hnshituo.pur.ck.service.ExcDeliveryNoticeCService", "findById", new object[] {strNoticeLineSqe});
  185. ExcDeliverySubC sc = new ExcDeliverySubC();
  186. sc.NoticeId = tempEsm.NoticeId;
  187. sc.OrderId = tempEsc.OrderId;
  188. sc.OrderLineSqe = tempEsc.OrderLineSqe;
  189. sc.NoticeLineSqe = tempEsc.NoticeLineSqe;
  190. sc.ItemCode = tempEsc.ItemCode;
  191. sc.ItemDesc=tempEsc.ItemDesc;
  192. sc.ItemDescE=tempEsc.ItemDescE;
  193. sc.ItemName=tempEsc.ItemName;
  194. sc.ItemUom=tempEsc.ItemUom;
  195. sc.WeightUnit=tempEsc.WeightUnit;
  196. sc.ItemUomConefficient=tempEsc.ItemUomConefficient;
  197. sc.ItemUseUom=tempEsc.ItemUseUom;
  198. sc.ItemAttr=tempEsc.ItemAttr;//物料属性
  199. sc.ItemAttrId=tempEsc.ItemAttrId;//属性编码
  200. sc.ItemStandardsCode=tempEsc.ItemStandardsCode;
  201. sc.ItemStandardsId=tempEsc.ItemStandardsId;
  202. sc.ItemUnique=tempEsc.ItemUnique;
  203. sc.ItemUomId = tempEsc.ItemUomId;
  204. sc.Qty=dbCreateQty;//送货数量
  205. String strBatchNo = row.GetCellValue("batchNo")==null?"":row.GetCellValue("batchNo").ToString().Trim();
  206. if (tempEsc.BatchFlag == "1")//批次控制
  207. {
  208. if (String.IsNullOrEmpty(strBatchNo))
  209. {
  210. MessageUtil.ShowTips("物料:" + tempEsc.ItemName + "为批次控制物料,请输入生产批次号!");
  211. return;
  212. }
  213. }
  214. sc.BatchNo = strBatchNo;
  215. String strCarNumC = row.GetCellValue("carNum") == null ? "" : row.GetCellValue("carNum").ToString().Trim();
  216. if (String.IsNullOrEmpty(strCarNumC))
  217. {
  218. //MessageUtil.ShowTips("请输入物料:" + tempEsc.ItemName + "的运输车号!");
  219. //return;
  220. }
  221. sc.CarNum = strCarNumC;
  222. if (sm.ReceiveType != tempEsc.ReceiveType)
  223. {
  224. if (MessageUtil.ShowYesNoAndQuestion("通知单行:" + tempEsc.NoticeLineSqe + " 接收方式和本次编制的接收方式不一致,确定是否继续?") != DialogResult.Yes)
  225. {
  226. return;
  227. }
  228. }
  229. sc.ReceiveType = sm.ReceiveType;
  230. sc.BuyerName=tempEsc.BuyerName;
  231. sc.MeteringFlag=tempEsc.MeteringFlag;
  232. sc.BatchFlag=tempEsc.BatchFlag;
  233. sc.PcFlag=tempEsc.PcFlag;
  234. sc.Ismeter = "0";
  235. sc.CreateName = UserInfo.GetUserName();
  236. sc.CreateUserid = UserInfo.GetUserID();
  237. sc.CreateTime = DateTime.Now;
  238. sc.Validflag="1";
  239. sc.Status="1";//待收货
  240. sc.ShippedQty = 0;
  241. sc.ShipQty=0;
  242. sc.ReceivedQty=0;
  243. sc.PackageType=tempEsc.PackageType;
  244. list.Add(sc);
  245. }
  246. }
  247. if (MessageUtil.ShowYesNoAndQuestion("确定生成【" + tempEsm.SuppName + "】的新送货单?")!=DialogResult.Yes)
  248. { return; }
  249. CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.ck.service.ExcDeliverySubMService", "insert_PC", new object[] { sm, list });
  250. if (re.Resultcode == 0)
  251. {
  252. MessageUtil.ShowTips("新增成功,已生成送货单:" + re.Resultmsg);
  253. tips = 1;
  254. this.Close();
  255. }
  256. else
  257. {
  258. MessageUtil.ShowTips("操作失败:" + re.Resultmsg);
  259. tips = 0;
  260. }
  261. }
  262. #endregion
  263. #region 初始化区域
  264. private void init()
  265. {
  266. try
  267. {
  268. this.Cursor = Cursors.WaitCursor;
  269. dataSet1.Clear();
  270. //加载通知单头
  271. if (String.IsNullOrEmpty(noticeId))
  272. {
  273. MessageUtil.ShowTips("通知单号为空,无法获取通知单信息");
  274. return;
  275. }
  276. tempEsm = this.execute<ExcDeliveryNoticeM>("com.hnshituo.pur.ck.service.ExcDeliveryNoticeMService", "findById", new object[] { noticeId });
  277. if (tempEsm == null)
  278. {
  279. MessageUtil.ShowTips("未发现通知单:" + noticeId + "信息记录,无法获取通知单信息");
  280. return;
  281. }
  282. //加载头编辑区
  283. txt_supp.Text = tempEsm.SuppName + "(" + tempEsm.SuppCode + ")";
  284. txt_deliveryLocation.Text = tempEsm.DeliveryLocation + "(" + tempEsm.DeliveryLocationCode + ")";
  285. txt_deliveryTime.Value = tempEsm.PlanedDeliveryDate;
  286. txt_orderId.Text = tempEsm.OrderId;
  287. txt_deliveryCondition.Value = tempEsm.DeliveryCondition;
  288. txt_deliveryType.Value = tempEsm.DeliveryType;
  289. //加载通知单行信息
  290. getNoticeC();
  291. }
  292. catch (Exception ex)
  293. {
  294. MessageBox.Show("初始化失败" + ex, "提示");
  295. }
  296. finally
  297. {
  298. this.Cursor = Cursors.Default;
  299. }
  300. }
  301. /// <summary>
  302. /// 加载行信息
  303. /// </summary>
  304. private void getNoticeC()
  305. {
  306. ExcDeliveryNoticeC EdnC = new ExcDeliveryNoticeC();
  307. EdnC.NoticeId = noticeId;
  308. EdnC.Validflag = "1";
  309. EdnC.DeleteUserid = "0";
  310. if (txt_receive_type.SelectedIndex == -1)
  311. {
  312. MessageUtil.ShowTips("请选择接收方式");
  313. txt_receive_type.Focus();
  314. return;
  315. }
  316. EdnC.ReceiveType = txt_receive_type.Value.ToString().Trim();
  317. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.ck.service.ExcDeliveryNoticeCService", "find_EdnC", new object[] { EdnC });
  318. if (dt == null)
  319. {
  320. return;
  321. }
  322. //String strNoticeLineSqe = dt.Rows[0]["noticeLineSqe"].ToString().Trim();
  323. //String strReceiveType = "";
  324. //ExcDeliveryNoticeC nc = this.execute<ExcDeliveryNoticeC>("com.hnshituo.pur.ck.service.ExcDeliveryNoticeCService", "findById", new object[] { strNoticeLineSqe });
  325. //if (nc != null)
  326. //{
  327. // strReceiveType = nc.ReceiveType;
  328. // txt_receive_type.Value = nc.ReceiveType;
  329. //}
  330. //汇编物料数量
  331. dt.Columns.Add("canUseQty", Type.GetType("System.String"));
  332. //dt.Columns.Add("createQty", Type.GetType("System.String"));
  333. foreach (DataRow row in dt.Rows)
  334. {
  335. double dbcreateQty = Convert.ToDouble(row["createdQty"].ToString().Trim());
  336. double dbQty = Convert.ToDouble(row["qty"].ToString().Trim());
  337. row["createQty"] = dbQty - dbcreateQty;
  338. row["canUseQty"] = dbQty - dbcreateQty;
  339. }
  340. dt.DefaultView.Sort = "noticeLineSqe desc";
  341. GridHelper.CopyDataToDatatable(dt.DefaultView.ToTable(), dataTable2, true);
  342. foreach (UltraGridRow roww in ultraGrid3.Rows)
  343. {
  344. roww.Cells["CHK"].Value = true;
  345. }
  346. ultraGrid3.UpdateData();
  347. GridHelper.RefreshAndAutoSize(ultraGrid3);
  348. }
  349. #endregion
  350. #region 初始化
  351. private void getDropDown()
  352. {
  353. //加载运输条件
  354. DataTable dt6 = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQuery", new Object[] { "1105" }, this.ob);
  355. comm.FilComboboxAdd(txt_deliveryCondition, dt6, "baseCode", "baseName", "validflag NOT in ('0')", true, "/", "");
  356. txt_deliveryCondition.SelectedIndex = 0;
  357. //加载运输方式
  358. DataTable dt7 = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQuery", new Object[] { "1102" }, this.ob);
  359. comm.FilComboboxAdd(txt_deliveryType, dt7, "baseCode", "baseName", "validflag NOT in ('0')", true, "/", "");
  360. txt_deliveryType.SelectedIndex = 0;
  361. //加载接收方式
  362. DataTable dt5 = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQueryByNoticeId", new Object[] { "1101", noticeId }, this.ob);
  363. comm.FilComboboxAdd(txt_receive_type, dt5, "baseCode", "baseName", "validflag NOT in ('0')", false, "/", "");
  364. txt_receive_type.SelectedIndex = 0;
  365. }
  366. #endregion
  367. private void txt_receive_type_SelectionChanged(object sender, EventArgs e)
  368. {
  369. getNoticeC();
  370. }
  371. //private void txt_deliveryType_ValueChanged(object sender, EventArgs e)
  372. //{
  373. // if (txt_deliveryType.SelectedIndex != -1)
  374. // {
  375. // if (txt_deliveryType.Value.ToString().Trim() == "110203")
  376. // {
  377. // txt_carNum.Clear();
  378. // txt_carNum.ReadOnly = true;
  379. // ultraGrid3.DisplayLayout.Bands[0].Columns["carNum"].Hidden = false;
  380. // }
  381. // else
  382. // {
  383. // txt_carNum.ReadOnly = false;
  384. // ultraGrid3.DisplayLayout.Bands[0].Columns["carNum"].Hidden = true;
  385. // }
  386. // }
  387. // else
  388. // {
  389. // txt_carNum.ReadOnly = false;
  390. // ultraGrid3.DisplayLayout.Bands[0].Columns["carNum"].Hidden = true;
  391. // }
  392. //}
  393. }
  394. }