FrmPurOutBill.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;using Pur.Entity;
  10. using Infragistics.Win.UltraWinGrid;
  11. using System.Collections;
  12. using Pur.Entity.require_planEntiy;
  13. using Core.Mes.Client.Comm.Control;
  14. using Pur.Entity.ck;
  15. using com.hnshituo.pur.vo;
  16. using Core.Mes.Client.Comm.Tool;
  17. namespace Pur.ck
  18. {
  19. public partial class FrmPurOutBill : FrmPmsBase
  20. {
  21. private ArrayList checkList;
  22. public ArrayList CheckList
  23. {
  24. get { return checkList; }
  25. set { checkList = value; }
  26. }
  27. public FrmPurOutBill()
  28. {
  29. InitializeComponent();
  30. }
  31. public FrmPurOutBill(OpeBase ob)
  32. {
  33. this.ob = ob;
  34. InitializeComponent();
  35. }
  36. private void FrmPurOutBill_Load(object sender, EventArgs e)
  37. {
  38. Init();
  39. }
  40. #region toolbar
  41. private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  42. {
  43. switch (e.Tool.Key)
  44. {
  45. case "createBill": // ButtonTool
  46. createBill();
  47. break;
  48. case "clear": // ButtonTool
  49. clear();
  50. break;
  51. case "关闭": // ButtonTool
  52. this.Close();
  53. break;
  54. }
  55. }
  56. #endregion
  57. #region toolbar事件
  58. private void clear()
  59. {
  60. String strItemCode = ultraGrid1.ActiveRow.Cells["itemCode"].Value.ToString().Trim();
  61. String strItemAttrCode = ultraGrid1.ActiveRow.Cells["itemAttrId"].Value.ToString().Trim();
  62. if (String.IsNullOrEmpty(strItemCode))
  63. {
  64. MessageBox.Show("查询库存信息失败:没有获取到物料编码", "提示");
  65. return;
  66. }
  67. foreach (UltraGridRow row in ultraGrid2.Rows)
  68. {
  69. if (row.Cells["itemCode"].Value.ToString().Trim().Equals(strItemCode) && row.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode))
  70. {
  71. row.Cells["isSelect"].Value = false;
  72. row.Cells["createQty"].Value = 0;
  73. }
  74. }
  75. }
  76. private void createBill()
  77. {
  78. try
  79. {
  80. ultraGrid1.UpdateData();
  81. ultraGrid2.UpdateData();
  82. foreach (UltraGridRow rowm in ultraGrid1.Rows)
  83. {
  84. String stritemcode=rowm.Cells["itemCode"].Value.ToString().Trim();
  85. String strItemAttrCode = ultraGrid1.ActiveRow.Cells["itemAttrId"].Value.ToString().Trim();
  86. int j = 0;
  87. foreach (UltraGridRow row in ultraGrid2.Rows)
  88. {
  89. if (row.Cells["itemCode"].Value.ToString().Trim().Equals(stritemcode) && row.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode) && Convert.ToBoolean(row.Cells["isSelect"].Value) == true)
  90. {
  91. j = j + 1;
  92. if (Convert.ToDouble(row.Cells["createQty"].Value) <= 0)
  93. {
  94. String strinvno = row.Cells["invId"].Value.ToString().Trim();
  95. MessageBox.Show(strinvno+"未编制有效数量","提示");
  96. return;
  97. }
  98. Double inStock;//在库
  99. if(row.Cells["invQty"].Value==null)
  100. {
  101. inStock=0;
  102. }
  103. else
  104. {
  105. inStock=Convert.ToDouble(row.Cells["invOrigQty"].Value);
  106. }
  107. Double onTrip;//在途
  108. if(row.Cells["invQty"].Value==null)
  109. {
  110. onTrip=0;
  111. }
  112. else{
  113. onTrip=Convert.ToDouble(row.Cells["invQty"].Value);
  114. }
  115. Double orQty;//已预约
  116. if(row.Cells["invOrQty"].Value==null)
  117. {
  118. orQty=0;
  119. }
  120. else
  121. {
  122. orQty=Convert.ToDouble(row.Cells["invOrQty"].Value);
  123. }
  124. //校验输入量:不能大于原始量+在途量-已经预约的量
  125. Double canUsed = inStock + onTrip - orQty;
  126. if(Convert.ToDouble(row.Cells["createQty"].Value)>canUsed)
  127. {
  128. String strinvno = row.Cells["invId"].Value.ToString().Trim();
  129. MessageBox.Show("库存行【"+ strinvno + "】的编制数量不能大于可编制的最大量:" + canUsed + "(即在库库存+在途库存-已预约量)", "提示");
  130. return;
  131. }
  132. }
  133. }
  134. if (j == 0)
  135. {
  136. MessageBox.Show("物料【"+stritemcode+"】的领用计划未编制库存数据", "提示");
  137. return;
  138. }
  139. }
  140. ultraGrid1.UpdateData();
  141. if (MessageUtil.ShowYesNoAndQuestion("确定进行出库操作?") != DialogResult.Yes)
  142. {
  143. return;
  144. }
  145. foreach (UltraGridRow rowm in ultraGrid1.Rows)
  146. {
  147. String stritemcode = rowm.Cells["itemCode"].Value.ToString().Trim();
  148. String strItemAttrCode = rowm.Cells["itemAttrId"].Value.ToString().Trim();
  149. //获取领用明细的信息,用于生成送货单主记录
  150. String strMrLineId = rowm.Cells["mrLineId"].Value.ToString().Trim();
  151. String strMrId = rowm.Cells["mrId"].Value.ToString().Trim();
  152. UsePlanD Upd = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
  153. UsePlanM UpM = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
  154. //获取库存记录信息用于生成出库单详细信息
  155. //CkOutBill cb = EntityHelper.CopyEntity<CkOutBill>(Upd);
  156. CkOutBill cb = new CkOutBill();
  157. cb.OutstockType="1";
  158. cb.Status="1";
  159. cb.MrLineId = Upd.MrLineId;
  160. cb.ItemCode = Upd.ItemCode;
  161. cb.ItemDesc = Upd.ItemDesc;
  162. cb.ItemDescE = Upd.ItemDescE;
  163. cb.ItemModel = Upd.ItemModel;
  164. cb.ItemName = Upd.ItemName;
  165. cb.ItemSpec = Upd.ItemSpec;
  166. cb.ItemUom = Upd.ItemUom;
  167. cb.ItemUomConefficient = Upd.ItemUomConefficient;
  168. cb.ItemUseUom = Upd.ItemUseUom;
  169. cb.WeightUnit = Upd.WeightUnit;
  170. cb.ItemAttr = Upd.ItemAttr;//物料属性
  171. cb.ItemAttrId = Upd.ItemAttrId;//物料属性Id
  172. cb.CostCenter = Upd.CostCenter;
  173. cb.ExpenseType = Upd.ExpenseType;
  174. cb.ApplyDate = UpM.ApplyTime;
  175. cb.ApplyUserid = UpM.ApplyReqOrgId;
  176. cb.ApplyUsername = UpM.ApplyReqOrgName;
  177. cb.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  178. cb.CreateTime = DateTime.Now;
  179. cb.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  180. //System.Guid outStockNo = System.Guid.NewGuid().ToString();
  181. // String outStockNo = System.Guid.NewGuid().ToString();
  182. CoreResult reid = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "createId", new object[] { });
  183. if (reid.Resultcode == 0)
  184. {
  185. cb.OutStockNo = reid.Resultmsg;
  186. }
  187. else
  188. {
  189. MessageBox.Show("操作失败:生成主表ID失败," + reid.Resultmsg, "提示");
  190. return;
  191. }
  192. cb.Validflag = "1";
  193. //生成出库单号
  194. //插入出库表 和 更新领用计划主表
  195. CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "doInsert_Update", new object[] { cb });
  196. if (re.Resultcode != 0)
  197. {
  198. MessageBox.Show("操作失败:"+re.Resultmsg, "提示");
  199. return;
  200. }
  201. //循环库存明细,生成出库库位明细从表
  202. ultraGrid2.UpdateData();
  203. int i = 0;
  204. foreach (UltraGridRow row in ultraGrid2.Rows)
  205. {
  206. if (row.Cells["itemCode"].Value.ToString().Trim().Equals(stritemcode) && row.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode) && Convert.ToBoolean(row.Cells["isSelect"].Value) == true && Convert.ToDouble(row.Cells["createQty"].Value) > 0)
  207. {
  208. i = i + 1;
  209. //收集数据进行插入
  210. CkOutbillPosition cp = new CkOutbillPosition();
  211. cp.OutStockNo = cb.OutStockNo;
  212. cp.SeqId = i + "";
  213. //cp.Id = Guid.NewGuid().ToString();
  214. CoreResult reid1 = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutbillPositionService", "createId", new object[] { cb.OutStockNo });
  215. if (reid1.Resultcode == 0)
  216. {
  217. cp.Id = reid1.Resultmsg;
  218. }
  219. else
  220. {
  221. MessageBox.Show("操作失败:生成明细ID失败," + reid1.Resultmsg, "提示");
  222. return;
  223. }
  224. cp.InvId = row.Cells["invid"].Value.ToString().Trim();
  225. cp.OutNum = Convert.ToDouble(row.Cells["createQty"].Value);
  226. cp.Validflag = "1";
  227. cp.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  228. cp.CreateTime = DateTime.Now;
  229. cp.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  230. cp.OrderId = row.Cells["orderId"].Value.ToString().Trim();
  231. cp.OrderLineSqe = row.Cells["orderLineSqe"].Value.ToString().Trim();
  232. cp.SuppCode = row.Cells["suppCode"].Value.ToString().Trim();
  233. cp.SuppName = row.Cells["suppName"].Value.ToString().Trim();
  234. cp.InvLogic = row.Cells["invLogic"].Value.ToString().Trim();
  235. cp.InvPhysic = row.Cells["invPhysic"].Value.ToString().Trim();
  236. cp.InvPos = row.Cells["invBin"].Value.ToString().Trim();
  237. //cp.BatchNo = row.Cells["batchno"].Value.ToString().Trim();
  238. cp.BatchNo = "";
  239. cp.WeightUnit = row.Cells["weightUnit"].Value.ToString().Trim();
  240. CoreResult re1 = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutbillPositionService", "doInsert_Update", new object[] { cp });
  241. if (re1.Resultcode == 1)
  242. {
  243. MessageBox.Show("操作失败:" + re1.Resultmsg, "");
  244. return;
  245. }
  246. //更新库存记录+领用计划表详细表
  247. }
  248. }
  249. ////删除已生成的记录
  250. ////DataRow roww= dataTable2.Select("mrLineId=strMrLineId");
  251. // //DataTable.Rows.Remove(roww);
  252. //for (int k = dataTable2.Rows.Count - 1; k >= 0; k--)
  253. //{
  254. // if (dataTable2.Rows[k]["mrLineId"].ToString().Equals(strMrLineId))
  255. // dataTable2.Rows.RemoveAt(k);
  256. //}
  257. //if (dataTable2.Rows.Count == 0)
  258. //{
  259. // MessageBox.Show("已经编制完成,请确定","提示");
  260. // this.Close();
  261. //}
  262. }
  263. MessageBox.Show("已经编制完成,请确定", "提示");
  264. this.Close();
  265. }
  266. catch(Exception ex)
  267. {
  268. MessageBox.Show("生成失败:"+ex.Message,"提示");
  269. }
  270. }
  271. #endregion
  272. #region 界面事件
  273. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  274. {
  275. String strItemCode = ultraGrid1.ActiveRow.Cells["itemCode"].Value.ToString().Trim();
  276. String strItemAttrCode = ultraGrid1.ActiveRow.Cells["itemAttrId"].Value.ToString().Trim();
  277. if (String.IsNullOrEmpty(strItemCode))
  278. {
  279. MessageBox.Show("查询库存信息失败:没有获取到物料编码","提示");
  280. return;
  281. }
  282. //ultraGrid2.UpdateData();
  283. foreach (UltraGridRow rowd in ultraGrid2.Rows)
  284. {
  285. if (rowd.Cells["itemCode"].Value.ToString().Trim().Equals(strItemCode) && rowd.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode))
  286. {
  287. rowd.Hidden = false;
  288. }
  289. else
  290. {
  291. rowd.Hidden=true;
  292. }
  293. }
  294. }
  295. #endregion
  296. #region 初始化
  297. private void Init()
  298. {
  299. try
  300. {
  301. dataTable2.Clear();
  302. dataTable1.Clear();
  303. foreach (object o in checkList)
  304. {
  305. //加载领用计划明细
  306. UsePlanD Upd = new UsePlanD();
  307. Upd.Validflag = "1";
  308. Upd.MrLineId = o.ToString().Trim();
  309. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanDService", "find_UsePlanD", new object[] { Upd });
  310. dataTable2.ImportRow(dt.Rows[0]);
  311. //加载库存信息
  312. String strItemCode = dt.Rows[0]["itemCode"].ToString().Trim();
  313. String strItemAttrCode = dt.Rows[0]["itemAttrId"].ToString().Trim();
  314. if (String.IsNullOrEmpty(strItemCode))
  315. {
  316. MessageBox.Show("查询库存信息失败:没有获取到物料编码", "提示");
  317. return;
  318. }
  319. CkStorage CkSto = new CkStorage();
  320. CkSto.ItemCode = strItemCode;
  321. CkSto.ItemAttrId = strItemAttrCode;
  322. DataTable dt1 = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkStorageService", "find_Storage", new object[] { CkSto });
  323. //dataTable1.ImportRow(dt1.Rows[0]);
  324. foreach (DataRow rowf in dt1.Rows)
  325. {
  326. dataTable1.ImportRow(rowf);
  327. }
  328. }
  329. //GridHelper.CopyDataToDatatable(dtall, dataTable1, true);
  330. ultraGrid1.UpdateData();
  331. ultraGrid2.UpdateData();
  332. foreach (UltraGridRow rowd in ultraGrid2.Rows)
  333. {
  334. rowd.Hidden = true;
  335. }
  336. }
  337. catch (Exception ex)
  338. {
  339. MessageBox.Show("界面初始化加载数据失败:" + ex.Message, "提示");
  340. }
  341. }
  342. #endregion
  343. }
  344. }