纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1840 lines
107 KiB

3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace ICSSoft.DataProject
  12. {
  13. /// <summary>
  14. /// 成品入库单
  15. /// </summary>
  16. public class ManufactureReceiveDoc
  17. {
  18. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  19. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  20. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  21. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  22. private static string CRNALL = System.Configuration.ConfigurationManager.AppSettings["ManuFaCRDNAME"];
  23. private static string CRNA = System.Configuration.ConfigurationManager.AppSettings["MoICRDNAME"];
  24. /// <summary>
  25. /// 获取成品入库单
  26. /// </summary>
  27. /// <param name="infos"></param>
  28. /// <returns></returns>
  29. public string Get(List<ICSManufactureReceiveDoc> infos)
  30. {
  31. List<ICSManufactureReceiveDoc> szJson = new List<ICSManufactureReceiveDoc>();
  32. DataTable dt = null;
  33. DataTable dtNew = null;
  34. string connS = "";
  35. string json = "";
  36. if (infos.Count <= 0)
  37. {
  38. throw new Exception("传送数据为空!");
  39. }
  40. string res = string.Empty;
  41. SqlConnection conn = new SqlConnection();
  42. SqlCommand cmd = new SqlCommand();
  43. string sql = string.Empty;
  44. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  45. foreach (string WorkPoint in result)
  46. {
  47. try
  48. {
  49. connS = string.Format(connString, WorkPoint);
  50. conn = new System.Data.SqlClient.SqlConnection(connS);
  51. conn.Open();
  52. SqlTransaction sqlTran = conn.BeginTransaction();
  53. cmd = new SqlCommand();
  54. cmd.Transaction = sqlTran;
  55. cmd.Connection = conn;
  56. foreach (ICSManufactureReceiveDoc info in infos)
  57. {
  58. if (WorkPoint != info.WorkPoint)
  59. continue;
  60. ICSUserInfo userInfo = new ICSUserInfo();
  61. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  62. if (info.MTime < new DateTime(2000, 01, 01))
  63. throw new Exception("请输入正确的操作时间:" + info.MTime);
  64. sql = @" select a.ID,a.cCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName,a.cMPoCode ,a.cMaker ,a.dnmaketime ,a.cHandler ,a.dnverifytime ,
  65. b.AutoID,b.iRSRowNO ,b.cInvCode ,b.iQuantity ,b.iNum ,b.iMPoIds from rdrecord10 a
  66. left join rdrecords10 b on a.ID=b.ID
  67. left join Department c on a.cDepCode=c.cDepCode
  68. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1";
  69. if (!string.IsNullOrWhiteSpace(info.MRCVCode))
  70. {
  71. sql += " and a.cCode='{0}'";
  72. }
  73. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  74. {
  75. sql += " and ISNULL(a.dnmodifytime,ISNULL(a.dnverifytime, ISNULL(a.dnmodifytime, a.dnmaketime)))>='{1}'";
  76. }
  77. if (!string.IsNullOrWhiteSpace(info.User))
  78. {
  79. sql += "and a.CMAKER='{2}'";
  80. }
  81. sql = string.Format(sql, info.MRCVCode, info.MTime, userInfo.UserName);
  82. dt = DBHelper.SQlReturnData(sql, cmd);
  83. if (dt.Rows.Count <= 0 || dt == null)
  84. throw new Exception("成品入库单:" + info.MRCVCode + ",无信息!");
  85. if (dtNew == null)
  86. dtNew = dt;
  87. else
  88. dtNew.Merge(dt);
  89. }
  90. cmd.Transaction.Commit();
  91. }
  92. catch (Exception ex)
  93. {
  94. if (cmd.Transaction != null)
  95. cmd.Transaction.Rollback();
  96. log.Error(ex.Message);
  97. throw new Exception(ex.Message);
  98. }
  99. finally
  100. {
  101. if (conn.State == ConnectionState.Open)
  102. {
  103. conn.Close();
  104. }
  105. conn.Dispose();
  106. }
  107. }
  108. json = JsonConvert.SerializeObject(dtNew);
  109. return json;
  110. }
  111. /// <summary>
  112. /// 创建成品入库单
  113. /// </summary>
  114. /// <param name="Bills"></param>
  115. /// <returns></returns>
  116. public string CreateManufactureReceiveDoc(List<ICSManufactureReceiveDoc> Bills)
  117. {
  118. int moidinbatch = 0;
  119. string msg = "";
  120. DataSet ds=null;
  121. string iFatherIdTwo = "";
  122. string iFatherIdTree = "";
  123. int isif = 0;
  124. string connS = "";
  125. string MoClass = "";
  126. int num = 0;
  127. int news = 0;
  128. int out11 = 0;
  129. int iseq = 0;
  130. int irownnew = 0;
  131. string sql = string.Empty;
  132. string mocode = "";
  133. string seq = "";
  134. //取得out库单的默认显示模版
  135. //取得采购入库单单据 表头ID,表体DID
  136. VouchKey key = new VouchKey();
  137. SqlConnection conn = new SqlConnection();
  138. SqlCommand cmd = new SqlCommand();
  139. if (Bills.Count <= 0)
  140. {
  141. throw new Exception("传送数据为空!");
  142. }
  143. LogInfo(Bills);
  144. foreach (ICSManufactureReceiveDoc head in Bills)
  145. {
  146. foreach (ICSManufactureReceiveDocs load in head.details)
  147. {
  148. foreach (ICSManufactureReceiveDocss loads in load.detailss)
  149. {
  150. news++;
  151. }
  152. }
  153. }
  154. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  155. foreach (string WorkPoint in result)
  156. {
  157. try
  158. {
  159. connS = string.Format(connString, WorkPoint);
  160. conn = new System.Data.SqlClient.SqlConnection(connS);
  161. conn.Open();
  162. SqlTransaction sqlTran = conn.BeginTransaction();
  163. cmd = new SqlCommand();
  164. cmd.Transaction = sqlTran;
  165. cmd.Connection = conn;
  166. foreach (ICSManufactureReceiveDoc head in Bills)
  167. {
  168. moidinbatch=0;
  169. iFatherIdTwo = "";
  170. iFatherIdTree = "";
  171. if (WorkPoint != head.WorkPoint)
  172. continue;
  173. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  174. throw new Exception("U8正在整理现存量,请稍后再试");
  175. ICSUserInfo userInfo = new ICSUserInfo();
  176. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  177. string[] ss = head.WorkPoint.Split('_');
  178. ERPDB = ss[1];
  179. string[] dd = CRNALL.Split('~');
  180. string crdname = dd[0];
  181. string carname = dd[1];
  182. string surface = dd[2];
  183. string[] d = CRNA.Split('~');
  184. string crdname1 = d[0];
  185. string carname1 = d[1];
  186. string surface1 = d[2];
  187. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  188. string cardnewcode1 = DBHelper.GetCardNumber(carname1, cmd);
  189. num = head.details.Count();
  190. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint, cmd);
  191. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  192. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  193. DateTime date = DateTime.Now;
  194. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  195. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  196. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", cRDcode, head.WorkPoint, cmd);
  197. string cRDcode1 = DBHelper.GetRDCode(crdname1, cmd);
  198. string DEF_ID1 = DBHelper.GetDefaultTemplate(cardnewcode1, cmd);
  199. //Person personEntity = new Person();
  200. //personEntity = U8Helper.GetDepCodeByUserCode(head.UserCode, cmd);
  201. DateTime dvDate = DateTime.Now.Date;
  202. #region 产成品入库单表头
  203. sql = @"INSERT INTO dbo.rdrecord10
  204. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,dDate ,
  205. cCode ,cRdCode ,cDepCode ,cHandler ,bTransFlag ,cMaker ,
  206. cDefine1 ,cDefine2 ,cDefine3 ,cDefine4 ,cDefine5 ,cDefine6 ,
  207. cDefine7 ,cDefine8 ,cDefine9 ,cDefine10 ,dVeriDate ,bpufirst ,
  208. biafirst ,VT_ID ,bIsSTQc ,cDefine11 ,cDefine12 ,cDefine13 ,
  209. cDefine14 ,cDefine15 ,cDefine16 ,cMPoCode ,iproorderid ,
  210. bFromPreYear ,bIsComplement ,iDiscountTaxType ,ireturncount ,
  211. iverifystate ,iswfcontrolled ,cModifyPerson ,dnmaketime ,
  212. dnverifytime ,bredvouch ,iPrintCount )
  213. SELECT @ID,1,'10','','',@cWhCode,convert(datetime,convert(varchar(10),getdate(),120)),
  214. @cCode,@RdCode,@DepCode,@cHandler,0,@cMaker,
  215. a.Define1,a.Define2,a.Define3,a.Define4,a.Define5,a.Define6,
  216. a.Define7,a.Define8,a.Define9,a.Define10,@dDate,0,
  217. 0,@VT_ID,0,a.Define11,a.Define12,a.Define13,
  218. a.Define14,a.Define15,a.Define16,a.MoCode,a.MoId,
  219. 0,0,0,0,
  220. 0,0,'',@dDate,
  221. @dDate,0,0
  222. FROM dbo.mom_order a
  223. WHERE a.MoCode='" + head.MOCode + "'";
  224. cmd.Parameters.Clear();
  225. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  226. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  227. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  228. cmd.Parameters.Add(new SqlParameter("@cDepCode", head.DepCode));
  229. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  230. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  231. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  232. cmd.Parameters.Add(new SqlParameter("@DepCode", head.DepCode));
  233. cmd.Parameters.Add(new SqlParameter("@dDate", dvDate));
  234. cmd.Parameters.Add(new SqlParameter("@RdCode", cRDcode));
  235. cmd.CommandText = sql;
  236. try
  237. {
  238. int count = cmd.ExecuteNonQuery();
  239. if (count <= 0)
  240. {
  241. log.Error("生成成品入库单表头失败,受影响行数<=0;");
  242. throw new Exception("生成成品入库单表头失败,受影响行数<=0;");
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. log.Error("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  248. throw new Exception("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  249. }
  250. List<WH> LWH = new List<WH>();
  251. #endregion
  252. if (news != 0)
  253. {
  254. foreach (ICSManufactureReceiveDocs load in head.details)
  255. {
  256. foreach (ICSManufactureReceiveDocss loads in load.detailss)
  257. {
  258. WH wh = new WH();
  259. wh.WHCODE = loads.WHCode;
  260. wh.seq = 0;
  261. if (LWH.Count != 0)
  262. {
  263. int whnumber = 0;
  264. foreach (WH item in LWH)
  265. {
  266. if (item.WHCODE == wh.WHCODE)
  267. whnumber++;
  268. }
  269. if (whnumber == 0)
  270. LWH.Add(wh);
  271. }
  272. else
  273. LWH.Add(wh);
  274. }
  275. }
  276. foreach (WH item in LWH)
  277. {
  278. Dictionary<string, int> dic1 = DBHelper.GetAllCode("" + ERPDB + "", surface1, "1", head.WorkPoint, cmd);
  279. int iFatherId1 = Convert.ToInt32(dic1["iFatherId"].ToString());
  280. int iChildId1 = Convert.ToInt32(dic1["iChildId"].ToString());
  281. DateTime date1 = DateTime.Now;
  282. string iBaseCodeLen1 = DBHelper.GetAllRDCode(cardnewcode1, "" + date1 + "", "admin", cRDcode1, head.WorkPoint, cmd);
  283. #region 材料出库单表头
  284. sql = @"INSERT INTO dbo.rdrecord11
  285. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,dDate ,cBusCode,
  286. cCode ,cRdCode ,cDepCode,cHandler ,bTransFlag ,cMaker ,
  287. dVeriDate ,bpufirst ,biafirst ,VT_ID ,bIsSTQc
  288. ,cPsPcode ,cMPoCode ,iproorderid ,bFromPreYear ,
  289. bIsLsQuery ,bIsComplement ,iDiscountTaxType ,ireturncount ,iverifystate ,
  290. iswfcontrolled ,dnmaketime ,dnverifytime ,bredvouch ,iPrintCount,
  291. iMQuantity)
  292. SELECT TOP 1 @ID,0,'11','','',@cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cBusCode,
  293. @cCode,@cRdCode,a.MDeptCode,@cHandler,0,@cMaker,
  294. CONVERT(NVARCHAR(15),GETDATE(),23),0,0,@VT_ID,0,
  295. null,b.MoCode,a.MoId,0,
  296. 0,0,0,0,0,
  297. 0,GETDATE(),GETDATE(),1,1,
  298. null
  299. FROM dbo.mom_orderdetail a
  300. left JOIN dbo.mom_order b ON a.MoId=b.MoId
  301. left join mom_morder c on a.modid=c.modid
  302. WHERE b.MoCode='" + head.MOCode + "'";
  303. cmd.Parameters.Clear();
  304. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId1));
  305. cmd.Parameters.Add(new SqlParameter("@cBusCode", iBaseCodeLen));
  306. cmd.Parameters.Add(new SqlParameter("@cWhCode", item.WHCODE));
  307. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen1));
  308. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  309. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  310. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID1));
  311. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode1));
  312. //cmd.Parameters.Add(new SqlParameter("@bredvouch",0));
  313. cmd.CommandText = sql;
  314. try
  315. {
  316. int count = cmd.ExecuteNonQuery();
  317. if (count <= 0)
  318. {
  319. log.Error("生成成品入库单表头失败,受影响行数<=0;");
  320. throw new Exception("生成成品入库单表头失败,受影响行数<=0;");
  321. }
  322. }
  323. catch (Exception ex)
  324. {
  325. log.Error("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  326. throw new Exception("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  327. }
  328. item.ID = iFatherId1;
  329. #endregion
  330. }
  331. }
  332. #region 产成品入库单表体
  333. int irow = 0;
  334. foreach (ICSManufactureReceiveDocs body in head.details)
  335. {
  336. if (DBHelper.bInvBatch(body.InvCode, cmd) == true)
  337. {
  338. if (body.BatchCode == "")
  339. {
  340. log.Error("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  341. throw new Exception("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  342. }
  343. }
  344. else
  345. {
  346. if (body.BatchCode != "")
  347. {
  348. log.Error("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  349. throw new Exception("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  350. }
  351. }
  352. irow++;
  353. #region 判断工单行是否关闭,关闭不能入库
  354. sql = @"SELECT ISNULL(a.CloseUser,'') as CloseUser,b.MoCode,a.SortSeq FROM dbo.mom_orderdetail a INNER JOIN
  355. dbo.mom_order b ON b.MoId = a.MoId WHERE a.MoDId = '" + body.MODetailID + "'";
  356. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  357. if (dtCheck != null && dtCheck.Rows.Count > 0)
  358. {
  359. mocode = dtCheck.Rows[0]["MoCode"].ToString();
  360. seq = dtCheck.Rows[0]["SortSeq"].ToString();
  361. if (!string.IsNullOrEmpty(dtCheck.Rows[0]["CloseUser"].ToString()))
  362. {
  363. throw new Exception("工单号:" + dtCheck.Rows[0]["MoCode"].ToString() + ",行号:" + dtCheck.Rows[0]["SortSeq"].ToString() + ",已关闭,无法入库!");
  364. }
  365. sql = @" select
  366. count(c.AllocateID) num,d.number
  367. from DBO.mom_order a
  368. left join DBO.mom_orderdetail b on a.moid = b.moid
  369. left join DBO.mom_moallocate c on b.modid = c.modid
  370. left join(select modid,COUNT(AllocateID) number from DBO.mom_moallocate where WIPType=1 GROUP BY modid
  371. ) d on b.modid = d.modid
  372. where a.MoCode='{0}' and b.SortSeq='{1}'
  373. GROUP BY d.number ";
  374. sql = string.Format(sql, mocode, seq);
  375. dtCheck = DBHelper.SQlReturnData(sql, cmd);
  376. if (dtCheck != null && dtCheck.Rows.Count > 0)
  377. {
  378. if (dtCheck.Rows[0]["num"].ToString() != dtCheck.Rows[0]["number"].ToString())
  379. {
  380. isif = 1;
  381. }
  382. else
  383. {
  384. isif = 0;
  385. }
  386. }
  387. }
  388. #endregion
  389. #region 判断是否为非标
  390. sql = @"select MoClass from dbo.mom_orderdetail where MoDId='" + body.MODetailID + "'";
  391. dtCheck = DBHelper.SQlReturnData(sql, cmd);
  392. if (dtCheck != null && dtCheck.Rows.Count > 0)
  393. {
  394. MoClass = dtCheck.Rows[0]["MoClass"].ToString();
  395. }
  396. #endregion
  397. #region 生成产成品入库单表体
  398. //if (head.IsReturn == "1")
  399. //{
  400. // body.iQuantity = -body.iQuantity;
  401. //}
  402. moidinbatch = iChildId;
  403. sql = @"INSERT INTO dbo.rdrecords10
  404. ( AutoID ,ID ,cInvCode ,iQuantity ,cBatch ,iFlag ,iNum,
  405. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  406. cItemCode ,cName ,iNQuantity ,cDefine28 ,
  407. cDefine29 ,cDefine30 ,cDefine31 ,cDefine32 ,cDefine33 ,cDefine34 ,
  408. cDefine35 ,cDefine36 ,cDefine37 ,iMPoIds ,bRelated ,bLPUseFree ,
  409. iRSRowNO ,iOriTrackID ,bCosting ,cmocode ,imoseq ,iExpiratDateCalcu ,
  410. iorderdid ,iordertype,iordercode,iorderseq,isodid,isotype,csocode,isoseq,irowno ,iposflag ,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  411. SELECT @AutoID,@ID,@cInvCode,@iQuantity,@cBatch,0,@iNum,
  412. a.Define22,a.Define23,a.Define24,a.Define25,a.Define26,a.Define27,
  413. @cItemCode,null,a.Qty-isnull(a.QualifiedInQty,0),a.Define28,
  414. a.Define29,a.Define30,a.Define31,a.Define32,a.Define33,a.Define34,
  415. a.Define35,a.Define36,a.Define37,a.MoDId,0,0,
  416. 0,0,1,b.MoCode,a.SortSeq,0,
  417. a.OrderDid,a.OrderType,a.OrderCode,a.OrderSeq,a.SoDId,a.SoType,a.SoCode,a.SoSeq,@irowno,0,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  418. FROM dbo.mom_orderdetail a
  419. INNER JOIN dbo.mom_order b ON a.MoId=b.MoId WHERE a.MoDId='" + body.MODetailID + "'";
  420. cmd.Parameters.Clear();
  421. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  422. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  423. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  424. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount.ToString("0.00")));
  425. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  426. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  427. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  428. cmd.Parameters.Add(new SqlParameter("@irowno", irow));
  429. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  430. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  431. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  432. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  433. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  434. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  435. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  436. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  437. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  438. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  439. cmd.CommandText = sql;
  440. try
  441. {
  442. int count = cmd.ExecuteNonQuery();
  443. if (count <= 0)
  444. {
  445. log.Error("生成材料出库单表头失败,受影响行数<=0;");
  446. throw new Exception("生成材料出库单表头失败,受影响行数<=0;");
  447. }
  448. }
  449. catch (Exception ex)
  450. {
  451. log.Error("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  452. throw new Exception("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  453. }
  454. #endregion
  455. if (isif == 1)
  456. {
  457. if (head.CompleteVerification)
  458. {
  459. #region 齐套检验
  460. sql = @" select cValue from AccInformation where cName=N'iMOProInCtrlBySet' ";
  461. DataTable qt = DBHelper.SQlReturnData(sql, cmd);
  462. if (qt != null && qt.Rows.Count > 0)
  463. {
  464. if (qt.Rows[0]["cValue"].ToString() == "1")
  465. {
  466. sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
  467. (
  468. select
  469. a.MoCode,b.SortSeq,
  470. case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId
  471. end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty
  472. from DBO.mom_order a
  473. left join DBO.mom_orderdetail b on a.moid = b.moid
  474. left join DBO.mom_moallocate c on b.modid = c.modid
  475. left join
  476. (select d.AllocateId,e.InvCode,d.MoallocateSubId from
  477. DBO.mom_moallocatesub d
  478. left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId
  479. left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode
  480. where a.MoCode='{0}' and b.SortSeq='{1}'
  481. and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1
  482. group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty
  483. ) tt
  484. group by MoCode,SortSeq";
  485. sql = string.Format(sql, mocode, seq);
  486. qt = DBHelper.SQlReturnData(sql, cmd);
  487. if (qt == null || qt.Rows.Count == 0)
  488. {
  489. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  490. }
  491. else
  492. {
  493. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  494. {
  495. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料<=0!");
  496. }
  497. }
  498. }
  499. else if (qt.Rows[0]["cValue"].ToString() == "2")
  500. {
  501. sql = @"select cValue from AccInformation where cName=N'bControlKeyMaterial'";
  502. qt = DBHelper.SQlReturnData(sql, cmd);
  503. if (qt != null && qt.Rows.Count > 0)
  504. {
  505. if (qt.Rows[0]["cValue"].ToString() == "true")
  506. {
  507. sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
  508. (
  509. select
  510. a.MoCode,b.SortSeq,
  511. case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId
  512. end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty
  513. from DBO.mom_order a
  514. left join DBO.mom_orderdetail b on a.moid = b.moid
  515. left join DBO.mom_moallocate c on b.modid = c.modid
  516. left join
  517. (select d.AllocateId,e.InvCode,d.MoallocateSubId from
  518. DBO.mom_moallocatesub d
  519. left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId
  520. left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode
  521. where a.MoCode='{0}' and b.SortSeq='{1}'
  522. and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1 and f.bInvKeyPart=1
  523. group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty
  524. ) tt
  525. group by MoCode,SortSeq";
  526. sql = string.Format(sql, mocode, seq);
  527. qt = DBHelper.SQlReturnData(sql, cmd);
  528. if (qt == null || qt.Rows.Count == 0)
  529. {
  530. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  531. }
  532. else
  533. {
  534. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  535. {
  536. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  537. }
  538. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  539. {
  540. throw new Exception("该物料:" + body.InvCode + @"入库数量大于关键物料领料套数!");
  541. }
  542. }
  543. }
  544. else
  545. {
  546. sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
  547. (
  548. select
  549. a.MoCode,b.SortSeq,
  550. case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId
  551. end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty
  552. from DBO.mom_order a
  553. left join DBO.mom_orderdetail b on a.moid = b.moid
  554. left join DBO.mom_moallocate c on b.modid = c.modid
  555. left join
  556. (select d.AllocateId,e.InvCode,d.MoallocateSubId from
  557. DBO.mom_moallocatesub d
  558. left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId
  559. left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode
  560. where a.MoCode='{0}' and b.SortSeq='{1}'
  561. and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1
  562. group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty
  563. ) tt
  564. group by MoCode,SortSeq";
  565. sql = string.Format(sql, mocode, seq);
  566. qt = DBHelper.SQlReturnData(sql, cmd);
  567. if (qt == null || qt.Rows.Count == 0)
  568. {
  569. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  570. }
  571. else
  572. {
  573. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  574. {
  575. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  576. }
  577. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  578. {
  579. throw new Exception("该物料:" + body.InvCode + @"入库数量大于领料套数!");
  580. }
  581. }
  582. }
  583. }
  584. }
  585. }
  586. #endregion
  587. }
  588. }
  589. sql = @"select isnull(QualifiedInQty,0)fOutQuantity,isnull(Qty,0)iQuantity,ISNULL(AuxQty, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(AuxQty, 0)-ISNULL(NiNum, 0) SiNum from mom_orderdetail a
  590. LEFT JOIN (select sum(iNum) NiNum,iMPoIds from rdrecords10 GROUP BY iMPoIds) b on a.MoDId=b.iMPoIds
  591. where a.MoDId='" + body.MODetailID + "'";
  592. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  593. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  594. {
  595. foreach (DataRow item in dtDisCheck.Rows)
  596. {
  597. if (Convert.ToDecimal(item["fOutQuantity"].ToString()) == Convert.ToDecimal(item["iQuantity"].ToString()))
  598. {
  599. if (Convert.ToDecimal(item["iNum"].ToString()) != 0)
  600. {
  601. if (Convert.ToDecimal(item["SiNum"].ToString()) != 0)
  602. {
  603. sql = @"Update rdrecords10 set iNum=isnull(iNum,0)+(" + item["SiNum"].ToString() + ") where autoid='" + iChildId + "' ";
  604. body.Amount = (Convert.ToDecimal(body.Amount.ToString("0.00"))) + (Convert.ToDecimal(item["SiNum"].ToString()));
  605. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  606. }
  607. }
  608. }
  609. }
  610. }
  611. #region 回写生产订单入库数量
  612. sql = @"UPDATE dbo.mom_orderdetail SET QualifiedInQty=ISNULL(QualifiedInQty,0)+" + body.Quantity + " where MoDId='" + body.MODetailID + "'";
  613. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写生产订单入库数量失败!");
  614. #endregion
  615. #region 更新现存量
  616. key.cBustypeUN = "成品入库";
  617. key.cVouchTypeUN = "10";
  618. key.TableName = "IA_ST_UnAccountVouch10";
  619. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  620. //DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key);
  621. DBHelper.UpdateCurrentStockCCGC(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.Amount, body.cFree1,
  622. body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10,
  623. "", key, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, iFatherId, iChildId);
  624. #endregion
  625. if (Convert.ToInt32(MoClass) == 1)
  626. {
  627. #region 判断工单行是否全部入库
  628. sql = "select Qty from mom_moallocate WHERE MoDId='" + body.MODetailID + @"' and IssQty-qty<0 and ProductType=1
  629. union all
  630. select Qty from mom_orderdetail where MoDId='" + body.MODetailID + @"' and QualifiedInQty-Qty<0";
  631. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  632. if (dtClose.Rows.Count == 0)
  633. {
  634. sql = @"
  635. update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId='" + body.MODetailID + "'";
  636. DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  637. }
  638. //foreach (DataRow dr in dtClose.Rows)
  639. //{
  640. // if (Convert.ToDecimal(dr["qty"]) >= 0)
  641. // {
  642. // sql = "update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId='" + body.MODetailID + "'";
  643. // DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  644. // }
  645. //}
  646. #endregion
  647. }
  648. else
  649. {
  650. #region 判断工单行是否全部入库
  651. sql = "select Qty from mom_moallocate WHERE MoDId='" + body.MODetailID + @"' and IssQty-qty<0
  652. union all
  653. select Qty from mom_orderdetail where MoDId='" + body.MODetailID + @"' and QualifiedInQty-Qty<0
  654. ";
  655. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  656. if (dtClose.Rows.Count == 0)
  657. {
  658. sql = @"
  659. update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId='" + body.MODetailID + "'";
  660. DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  661. }
  662. //foreach (DataRow dr in dtClose.Rows)
  663. //{
  664. // if (Convert.ToDecimal(dr["qty"]) >= 0)
  665. // {
  666. // sql = "update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId='" + body.MODetailID + "'";
  667. // DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  668. // }
  669. //}
  670. #endregion
  671. }
  672. num = body.detailss.Count();
  673. Dictionary<string, int> dic2 = DBHelper.GetAllCode("" + ERPDB + "", surface1, "" + num + "", head.WorkPoint, cmd);
  674. int iFatherId2 = Convert.ToInt32(dic2["iFatherId"].ToString());
  675. int iChildId2 = Convert.ToInt32(dic2["iChildId"].ToString());
  676. foreach (ICSManufactureReceiveDocss item in body.detailss)
  677. {
  678. if (item.PickID != null && item.PickID != "")
  679. {
  680. foreach (WH wh in LWH)
  681. {
  682. if (wh.WHCODE == item.WHCode)
  683. {
  684. out11 = wh.ID;
  685. iseq = wh.seq + 1;
  686. wh.seq += 1;
  687. }
  688. }
  689. sql = @"INSERT INTO dbo.rdrecords11
  690. ( AutoID ,ID ,cInvCode ,iQuantity ,cBatch ,iFlag ,iNum,
  691. cItemCode ,cName ,iNQuantity ,iMPoIds ,bLPUseFree ,
  692. iOriTrackID ,bCosting ,bVMIUsed ,cmocode ,invcode ,imoseq ,
  693. iopseq ,iExpiratDateCalcu ,iorderdid ,iordertype ,isotype ,
  694. ipesodid ,ipesotype ,cpesocode ,ipesoseq ,irowno ,
  695. bcanreplace ,iposflag,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  696. SELECT @AutoID,@ID,a.InvCode,@iQuantity,@cBatch,0,@iNum,
  697. @cItemCode,null,a.Qty,a.AllocateId,0,
  698. 0,1,0,c.MoCode,b.InvCode,b.SortSeq,
  699. '0000',0,0,0,0,
  700. a.AllocateId,'7',c.MoCode,b.SortSeq,@irowno,
  701. 0,null,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  702. FROM dbo.mom_moallocate a
  703. INNER JOIN dbo.mom_orderdetail b ON a.MoDId=b.MoDId
  704. INNER JOIN dbo.mom_order c ON b.MoId=c.MoId
  705. WHERE a.AllocateId='" + item.PickID + "'";
  706. cmd.Parameters.Clear();
  707. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId2));
  708. cmd.Parameters.Add(new SqlParameter("@ID", out11));
  709. cmd.Parameters.Add(new SqlParameter("@iQuantity", item.Quantity));
  710. cmd.Parameters.Add(new SqlParameter("@iNum", item.Amount));
  711. cmd.Parameters.Add(new SqlParameter("@cBatch", item.BatchCode));
  712. cmd.Parameters.Add(new SqlParameter("@cItemCode", item.ProjectCode));
  713. cmd.Parameters.Add(new SqlParameter("@irowno", iseq));
  714. cmd.Parameters.Add(new SqlParameter("@cFree1", item.cFree1));
  715. cmd.Parameters.Add(new SqlParameter("@cFree2", item.cFree2));
  716. cmd.Parameters.Add(new SqlParameter("@cFree3", item.cFree3));
  717. cmd.Parameters.Add(new SqlParameter("@cFree4", item.cFree4));
  718. cmd.Parameters.Add(new SqlParameter("@cFree5", item.cFree5));
  719. cmd.Parameters.Add(new SqlParameter("@cFree6", item.cFree6));
  720. cmd.Parameters.Add(new SqlParameter("@cFree7", item.cFree7));
  721. cmd.Parameters.Add(new SqlParameter("@cFree8", item.cFree8));
  722. cmd.Parameters.Add(new SqlParameter("@cFree9", item.cFree9));
  723. cmd.Parameters.Add(new SqlParameter("@cFree10", item.cFree10));
  724. cmd.CommandText = sql;
  725. try
  726. {
  727. int count = cmd.ExecuteNonQuery();
  728. if (count <= 0)
  729. {
  730. log.Error("生成材料出库单表体失败,受影响行数<=0;");
  731. throw new Exception("生成材料出库单表体失败,受影响行数<=0;");
  732. }
  733. }
  734. catch (Exception ex)
  735. {
  736. log.Error("生成材料出库单表体失败" + sql, ex);
  737. throw new Exception("生成材料出库单表体失败 " + sql, ex);
  738. }
  739. #region 回写工单子件已领数量
  740. sql = "update mom_moallocate set IssQty=isnull(IssQty,0)+" + item.Quantity + ",RequisitionIssQty=isnull(RequisitionIssQty,0)+(" + item.Quantity + ") where AllocateId='" + item.PickID + "' ";
  741. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写工单子件已领数量失败!");
  742. #endregion
  743. sql = @"select isnull(Issqty,0)fOutQuantity,isnull(qty,0)iQuantity,ISNULL(AuxQty, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(AuxQty, 0)-ISNULL(NiNum, 0) SiNum from mom_moallocate a
  744. LEFT JOIN (select sum(iNum) NiNum,ipesodid from rdrecords11 GROUP BY ipesodid) b on a.AllocateId=b.ipesodid
  745. where a.AllocateId='" + item.PickID + "'";
  746. dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  747. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  748. {
  749. foreach (DataRow item1 in dtDisCheck.Rows)
  750. {
  751. if (Convert.ToDecimal(item1["fOutQuantity"].ToString()) == Convert.ToDecimal(item1["iQuantity"].ToString()))
  752. {
  753. if (Convert.ToDecimal(item1["iNum"].ToString()) != 0)
  754. {
  755. if (Convert.ToDecimal(item1["SiNum"].ToString()) != 0)
  756. {
  757. sql = @"Update rdrecords11 set iNum=isnull(iNum,0)+(" + item1["SiNum"].ToString() + ") where autoid='" + iChildId2 + "' ";
  758. body.Amount = (Convert.ToDecimal(body.Amount.ToString("0.00"))) + (Convert.ToDecimal(item1["SiNum"].ToString()));
  759. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  760. }
  761. }
  762. }
  763. }
  764. }
  765. //更新现存量
  766. key.cBustypeUN = "领料";
  767. key.cVouchTypeUN = "11";
  768. key.TableName = "IA_ST_UnAccountVouch11";
  769. //DBHelper.UpdateCurrentStockNEW(cmd, item.InvCode, head.WHCode, item.BatchCode, -item.Quantity, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, key);
  770. DBHelper.UpdateCurrentStockCCGC(cmd, body.InvCode, head.WHCode, body.BatchCode, -body.Quantity, -body.Amount, body.cFree1,
  771. body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10,
  772. "", key, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, out11, iChildId2);
  773. iFatherIdTree += "'" + out11 + "',";
  774. iChildId2--;
  775. }
  776. }
  777. iFatherIdTwo = "'" + iFatherId + "',";
  778. iChildId--;
  779. }
  780. #endregion
  781. #region 查询
  782. if (news == 0)
  783. {
  784. sql = @" select DISTINCT a.ID as ID,a.ID as IDs,a.cCode as MRCVCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName
  785. ,a.cMPoCode as MOCode ,a.cMaker as CreateUser ,a.dnmaketime as CreateDateTime
  786. ,a.cHandler as Checker ,a.dnverifytime as CheckDateTime
  787. from rdrecord10 a
  788. left join Department c on a.cDepCode=c.cDepCode
  789. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0})
  790. select DISTINCT a.ID as IDs, b.AutoID as DetailID,CAST(b.AutoID as char) as IDSS ,b.irowno as Sequence ,b.cInvCode as InvCode ,
  791. b.iQuantity as Quantity ,b.iNum as Amount,b.iMPoIds as MODetailID,
  792. isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  793. isnull(b.cFree1,'') as cFree1,
  794. isnull(b.cFree2,'') as cFree2,
  795. isnull(b.cFree3,'') as cFree3,
  796. isnull(b.cFree4,'') as cFree4,
  797. isnull(b.cFree5,'') as cFree5,
  798. isnull(b.cFree6,'') as cFree6,
  799. isnull(b.cFree7,'') as cFree7,
  800. isnull(b.cFree8,'') as cFree8,
  801. isnull(b.cFree9,'') as cFree9,
  802. isnull(b.cFree10,'') as cFree10
  803. from rdrecord10 a
  804. left join rdrecords10 b on a.ID=b.ID
  805. left join Department c on a.cDepCode=c.cDepCode
  806. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0})
  807. select DISTINCT a.ID as IDs,b.AutoID as DetailID,CAST('{2}' as char) as IDSS,a.cCode as MRCVCode,irowno as Sequence,b.cInvCode as InvCode
  808. ,iQuantity as Quantity,e.AllocateId as SourceDetailID,iNum as Amount,
  809. isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  810. isnull(b.cFree1,'') as cFree1,
  811. isnull(b.cFree2,'') as cFree2,
  812. isnull(b.cFree3,'') as cFree3,
  813. isnull(b.cFree4,'') as cFree4,
  814. isnull(b.cFree5,'') as cFree5,
  815. isnull(b.cFree6,'') as cFree6,
  816. isnull(b.cFree7,'') as cFree7,
  817. isnull(b.cFree8,'') as cFree8,
  818. isnull(b.cFree9,'') as cFree9,
  819. isnull(b.cFree10,'') as cFree10
  820. from rdrecord11 a
  821. left join rdrecords11 b on a.ID=b.ID
  822. left join Department c on a.cDepCode=c.cDepCode
  823. left join Warehouse d on a.cWhCode=d.cWhCode
  824. left join mom_moallocate e on b.iMPoIds=e.AllocateId
  825. INNER JOIN dbo.mom_orderdetail f ON e.MoDId=f.MoDId
  826. INNER JOIN dbo.mom_order g ON f.MoId=g.MoId WHERE a.ID in ({1})
  827. ";
  828. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','), "''", moidinbatch);
  829. }
  830. else
  831. {
  832. sql = @" select DISTINCT a.ID as ID,a.ID as IDs,a.cCode as MRCVCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName
  833. ,a.cMPoCode as MOCode ,a.cMaker as CreateUser ,a.dnmaketime as CreateDateTime
  834. ,a.cHandler as Checker ,a.dnverifytime as CheckDateTime
  835. from rdrecord10 a
  836. left join Department c on a.cDepCode=c.cDepCode
  837. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0})
  838. select DISTINCT a.ID as IDs, b.AutoID as DetailID,CAST(b.AutoID as char) as IDSS ,b.irowno as Sequence ,b.cInvCode as InvCode ,
  839. b.iQuantity as Quantity ,b.iNum as Amount,b.iMPoIds as MODetailID ,
  840. isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  841. isnull(b.cFree1,'') as cFree1,
  842. isnull(b.cFree2,'') as cFree2,
  843. isnull(b.cFree3,'') as cFree3,
  844. isnull(b.cFree4,'') as cFree4,
  845. isnull(b.cFree5,'') as cFree5,
  846. isnull(b.cFree6,'') as cFree6,
  847. isnull(b.cFree7,'') as cFree7,
  848. isnull(b.cFree8,'') as cFree8,
  849. isnull(b.cFree9,'') as cFree9,
  850. isnull(b.cFree10,'') as cFree10
  851. from rdrecord10 a
  852. left join rdrecords10 b on a.ID=b.ID
  853. left join Department c on a.cDepCode=c.cDepCode
  854. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0})
  855. select DISTINCT a.ID as IDs,b.AutoID as DetailID,CAST('{2}' as char) as IDSS,a.cCode as MRCVCode,irowno as Sequence,b.cInvCode as InvCode
  856. ,iQuantity as Quantity,e.AllocateId as SourceDetailID,iNum as Amount,a.ID ERPID,b.AutoID as ERPDetailID,
  857. isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  858. isnull(b.cFree1,'') as cFree1,
  859. isnull(b.cFree2,'') as cFree2,
  860. isnull(b.cFree3,'') as cFree3,
  861. isnull(b.cFree4,'') as cFree4,
  862. isnull(b.cFree5,'') as cFree5,
  863. isnull(b.cFree6,'') as cFree6,
  864. isnull(b.cFree7,'') as cFree7,
  865. isnull(b.cFree8,'') as cFree8,
  866. isnull(b.cFree9,'') as cFree9,
  867. isnull(b.cFree10,'') as cFree10
  868. from rdrecord11 a
  869. left join rdrecords11 b on a.ID=b.ID
  870. left join Department c on a.cDepCode=c.cDepCode
  871. left join Warehouse d on a.cWhCode=d.cWhCode
  872. left join mom_moallocate e on b.iMPoIds=e.AllocateId
  873. INNER JOIN dbo.mom_orderdetail f ON e.MoDId=f.MoDId
  874. INNER JOIN dbo.mom_order g ON f.MoId=g.MoId WHERE a.ID in ({1})
  875. ";
  876. if (iFatherIdTree.TrimEnd(',')=="")
  877. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','), "''", moidinbatch);
  878. else
  879. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','), iFatherIdTree.TrimEnd(','), moidinbatch);
  880. }
  881. if (ds != null)
  882. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  883. else
  884. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  885. #endregion
  886. }
  887. cmd.Transaction.Commit();
  888. }
  889. catch (Exception ex)
  890. {
  891. if (cmd.Transaction != null)
  892. cmd.Transaction.Rollback();
  893. log.Error(ex.Message);
  894. throw new Exception(ex.Message);
  895. }
  896. finally
  897. {
  898. if (conn.State == ConnectionState.Open)
  899. {
  900. conn.Close();
  901. }
  902. conn.Dispose();
  903. }
  904. }
  905. if (news != 0)
  906. {
  907. msg = JSON.DataSetToJson(ds, "details", "IDs", "detailss", "IDSS");
  908. }
  909. else
  910. {
  911. msg = JSON.DataSetToJson(ds, "details", "IDs");
  912. }
  913. return msg;
  914. }
  915. /// <summary>
  916. /// 创建联副产品
  917. /// </summary>
  918. /// <param name="Bills"></param>
  919. /// <returns></returns>
  920. public string CreateManufactureReceiveDoc1(List<ICSManufactureReceiveDoc> Bills)
  921. {
  922. string msg = "";
  923. int isif = 0;
  924. DataSet ds = null;
  925. string connS = "";
  926. int num = 0;
  927. string sql = string.Empty;
  928. string mocode = "";
  929. string seq = "";
  930. //取得out库单的默认显示模版
  931. string iFatherIdTwo = "";
  932. //取得采购入库单单据 表头ID,表体DID
  933. VouchKey key = new VouchKey();
  934. SqlConnection conn = new SqlConnection();
  935. SqlCommand cmd = new SqlCommand();
  936. if (Bills.Count <= 0)
  937. {
  938. throw new Exception("传送数据为空!");
  939. }
  940. LogInfo(Bills);
  941. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  942. foreach (string WorkPoint in result)
  943. {
  944. try
  945. {
  946. connS = string.Format(connString, WorkPoint);
  947. conn = new System.Data.SqlClient.SqlConnection(connS);
  948. conn.Open();
  949. SqlTransaction sqlTran = conn.BeginTransaction();
  950. cmd = new SqlCommand();
  951. cmd.Transaction = sqlTran;
  952. cmd.Connection = conn;
  953. foreach (ICSManufactureReceiveDoc head in Bills)
  954. {
  955. iFatherIdTwo = "";
  956. if (WorkPoint != head.WorkPoint)
  957. continue;
  958. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  959. throw new Exception("U8正在整理现存量,请稍后再试");
  960. string[] ss = head.WorkPoint.Split('_');
  961. ERPDB = ss[1];
  962. string[] dd = CRNALL.Split('~');
  963. string crdname = dd[0];
  964. string carname = dd[1];
  965. string surface = dd[2];
  966. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  967. ICSUserInfo userInfo = new ICSUserInfo();
  968. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  969. num = head.details.Count();
  970. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint, cmd);
  971. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  972. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  973. DateTime date = DateTime.Now;
  974. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  975. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  976. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", cRDcode, head.WorkPoint, cmd);
  977. //Person personEntity = new Person();
  978. //personEntity = U8Helper.GetDepCodeByUserCode(head.UserCode, cmd);
  979. DateTime dvDate = DateTime.Now.Date;
  980. #region 产成品入库单表头
  981. sql = @"INSERT INTO dbo.rdrecord10
  982. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,dDate ,
  983. cCode ,cRdCode ,cDepCode ,cHandler ,bTransFlag ,cMaker ,
  984. cDefine1 ,cDefine2 ,cDefine3 ,cDefine4 ,cDefine5 ,cDefine6 ,
  985. cDefine7 ,cDefine8 ,cDefine9 ,cDefine10 ,dVeriDate ,bpufirst ,
  986. biafirst ,VT_ID ,bIsSTQc ,cDefine11 ,cDefine12 ,cDefine13 ,
  987. cDefine14 ,cDefine15 ,cDefine16 ,cMPoCode ,iproorderid ,
  988. bFromPreYear ,bIsComplement ,iDiscountTaxType ,ireturncount ,
  989. iverifystate ,iswfcontrolled ,cModifyPerson ,dnmaketime ,
  990. dnverifytime ,bredvouch ,iPrintCount )
  991. SELECT @ID,1,'10','','',@cWhCode,convert(datetime,convert(varchar(10),getdate(),120)),
  992. @cCode,@RdCode,@DepCode,@cHandler,0,@cMaker,
  993. a.Define1,a.Define2,a.Define3,a.Define4,a.Define5,a.Define6,
  994. a.Define7,a.Define8,a.Define9,a.Define10,@dDate,0,
  995. 0,@VT_ID,0,a.Define11,a.Define12,a.Define13,
  996. a.Define14,a.Define15,a.Define16,a.MoCode,a.MoId,
  997. 0,0,0,0,
  998. 0,0,'',@dDate,
  999. @dDate,0,0
  1000. FROM dbo.mom_order a
  1001. WHERE a.MoCode='" + head.MOCode + "'";
  1002. cmd.Parameters.Clear();
  1003. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  1004. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  1005. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  1006. cmd.Parameters.Add(new SqlParameter("@cDepCode", head.DepCode));
  1007. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  1008. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  1009. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  1010. cmd.Parameters.Add(new SqlParameter("@DepCode", head.DepCode));
  1011. cmd.Parameters.Add(new SqlParameter("@dDate", dvDate));
  1012. cmd.Parameters.Add(new SqlParameter("@RdCode", cRDcode));
  1013. cmd.CommandText = sql;
  1014. try
  1015. {
  1016. int count = cmd.ExecuteNonQuery();
  1017. if (count <= 0)
  1018. {
  1019. log.Error("生成成品入库单表头失败,受影响行数<=0;");
  1020. throw new Exception("生成成品入库单表头失败,受影响行数<=0;");
  1021. }
  1022. }
  1023. catch (Exception ex)
  1024. {
  1025. log.Error("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  1026. throw new Exception("生成成品入库单表头失败!SQL:\r\n" + sql, ex);
  1027. }
  1028. #endregion
  1029. #region 产成品入库单表体
  1030. int irowno = 0;
  1031. foreach (ICSManufactureReceiveDocs body in head.details)
  1032. {
  1033. if (DBHelper.bInvBatch(body.InvCode, cmd) == true)
  1034. {
  1035. if (body.BatchCode == "")
  1036. {
  1037. log.Error("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  1038. throw new Exception("该物料:" + body.InvCode + "已启用批次,请重新填写!");
  1039. }
  1040. }
  1041. else
  1042. {
  1043. if (body.BatchCode != "")
  1044. {
  1045. log.Error("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  1046. throw new Exception("该物料:" + body.InvCode + "未启用批次,请重新填写!");
  1047. }
  1048. }
  1049. irowno++;
  1050. #region 判断工单行是否关闭,关闭不能入库
  1051. sql = @"SELECT ISNULL(a.CloseUser,'') as CloseUser,b.MoCode,a.SortSeq FROM dbo.mom_orderdetail a INNER JOIN
  1052. dbo.mom_order b ON b.MoId = a.MoId WHERE a.MoDId =(select MoDId from dbo.mom_moallocate where AllocateId='" + body.MODetailID + "')";
  1053. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  1054. if (dtCheck != null && dtCheck.Rows.Count > 0)
  1055. {
  1056. mocode = dtCheck.Rows[0]["MoCode"].ToString();
  1057. seq = dtCheck.Rows[0]["SortSeq"].ToString();
  1058. if (!string.IsNullOrEmpty(dtCheck.Rows[0]["CloseUser"].ToString()))
  1059. {
  1060. throw new Exception("工单号:" + dtCheck.Rows[0]["MoCode"].ToString() + ",行号:" + dtCheck.Rows[0]["SortSeq"].ToString() + ",已关闭,无法入库!");
  1061. }
  1062. sql = @" select
  1063. count(c.AllocateID) num,d.number
  1064. from DBO.mom_order a
  1065. left join DBO.mom_orderdetail b on a.moid = b.moid
  1066. left join DBO.mom_moallocate c on b.modid = c.modid
  1067. left join(select modid,COUNT(AllocateID) number from DBO.mom_moallocate where WIPType=1 GROUP BY modid
  1068. ) d on b.modid = d.modid
  1069. where a.MoCode='{0}' and b.SortSeq='{1}'
  1070. GROUP BY d.number ";
  1071. sql = string.Format(sql, mocode, seq);
  1072. dtCheck = DBHelper.SQlReturnData(sql, cmd);
  1073. if (dtCheck != null && dtCheck.Rows.Count > 0)
  1074. {
  1075. if (dtCheck.Rows[0]["num"].ToString() != dtCheck.Rows[0]["number"].ToString())
  1076. {
  1077. isif = 1;
  1078. }
  1079. else
  1080. {
  1081. isif = 0;
  1082. }
  1083. }
  1084. }
  1085. #endregion
  1086. #region 判断是否都是联.副产品
  1087. sql = @"select ProductType from dbo.mom_moallocate where AllocateId='" + body.MODetailID + "'";
  1088. dtCheck = DBHelper.SQlReturnData(sql, cmd);
  1089. if (dtCheck != null && dtCheck.Rows.Count > 0)
  1090. {
  1091. string ProductType = dtCheck.Rows[0]["ProductType"].ToString();
  1092. if (Convert.ToInt32(ProductType) == 1)
  1093. {
  1094. throw new Exception("该返工工单存在非联、副产品子件,无法入库!");
  1095. }
  1096. }
  1097. #endregion
  1098. #region 生成产成品入库单表体
  1099. //if (head.IsReturn == "1")
  1100. //{
  1101. // body.iQuantity = -body.iQuantity;
  1102. //}
  1103. sql = @"INSERT INTO dbo.rdrecords10
  1104. ( AutoID ,ID ,cInvCode ,iQuantity ,cBatch ,iFlag ,iNum,
  1105. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  1106. cItemCode ,cName ,iNQuantity ,cDefine28 ,
  1107. cDefine29 ,cDefine30 ,cDefine31 ,cDefine32 ,cDefine33 ,cDefine34 ,
  1108. cDefine35 ,cDefine36 ,cDefine37 ,iMPoIds ,bRelated ,bLPUseFree ,
  1109. iRSRowNO ,iOriTrackID ,bCosting ,cmocode ,imoseq ,iExpiratDateCalcu ,
  1110. iorderdid ,iordertype,iordercode,iorderseq,isodid,isotype,csocode,isoseq,irowno ,iposflag ,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1111. SELECT @AutoID,@ID,@cInvCode,@iQuantity,@cBatch,0,@iNum,
  1112. a.Define22,a.Define23,a.Define24,a.Define25,a.Define26,a.Define27,
  1113. @cItemCode,null,c.Qty-isnull(c.QualifiedInQty,0),c.Define28,
  1114. c.Define29,c.Define30,c.Define31,c.Define32,c.Define33,c.Define34,
  1115. c.Define35,c.Define36,c.Define37,c.MoDId,0,0,
  1116. 0,0,1,b.MoCode,a.SortSeq,0,
  1117. a.AllocateId,c.OrderType,c.OrderCode,c.OrderSeq,c.SoDId,c.SoType,c.SoCode,c.SoSeq,@irowno,0,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  1118. FROM dbo.mom_moallocate a
  1119. INNER join dbo.mom_orderdetail c on a.MoDId=c.MoDId
  1120. INNER JOIN dbo.mom_order b ON c.MoId=b.MoId
  1121. WHERE a.AllocateId='" + body.MODetailID + "' and a.SortSeq='" + body.Sequence + "' ";
  1122. cmd.Parameters.Clear();
  1123. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  1124. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  1125. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  1126. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  1127. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount.ToString("0.00")));
  1128. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  1129. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  1130. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  1131. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  1132. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  1133. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  1134. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  1135. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  1136. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  1137. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  1138. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  1139. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  1140. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  1141. cmd.CommandText = sql;
  1142. try
  1143. {
  1144. int count = cmd.ExecuteNonQuery();
  1145. if (count <= 0)
  1146. {
  1147. log.Error("生成材料出库单表头失败,受影响行数<=0;");
  1148. throw new Exception("生成材料出库单表头失败,受影响行数<=0;");
  1149. }
  1150. }
  1151. catch (Exception ex)
  1152. {
  1153. log.Error("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  1154. throw new Exception("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  1155. }
  1156. #endregion
  1157. if (isif == 1)
  1158. {
  1159. if (head.CompleteVerification)
  1160. {
  1161. #region 齐套检验
  1162. sql = @" select cValue from AccInformation where cName=N'iMOProInCtrlBySet' ";
  1163. DataTable qt = DBHelper.SQlReturnData(sql, cmd);
  1164. if (qt != null && qt.Rows.Count > 0)
  1165. {
  1166. if (qt.Rows[0]["cValue"].ToString() == "1")
  1167. {
  1168. sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
  1169. (
  1170. select
  1171. a.MoCode,b.SortSeq,
  1172. case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId
  1173. end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty
  1174. from DBO.mom_order a
  1175. left join DBO.mom_orderdetail b on a.moid = b.moid
  1176. left join DBO.mom_moallocate c on b.modid = c.modid
  1177. left join
  1178. (select d.AllocateId,e.InvCode,d.MoallocateSubId from
  1179. DBO.mom_moallocatesub d
  1180. left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId
  1181. left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode
  1182. where a.MoCode='{0}' and b.SortSeq='{1}'
  1183. and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1
  1184. group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty
  1185. ) tt
  1186. group by MoCode,SortSeq";
  1187. sql = string.Format(sql, mocode, seq);
  1188. qt = DBHelper.SQlReturnData(sql, cmd);
  1189. if (qt == null || qt.Rows.Count == 0)
  1190. {
  1191. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  1192. }
  1193. else
  1194. {
  1195. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  1196. {
  1197. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料<=0!");
  1198. }
  1199. }
  1200. }
  1201. else if (qt.Rows[0]["cValue"].ToString() == "2")
  1202. {
  1203. sql = @"select cValue from AccInformation where cName=N'bControlKeyMaterial'";
  1204. qt = DBHelper.SQlReturnData(sql, cmd);
  1205. if (qt != null && qt.Rows.Count > 0)
  1206. {
  1207. if (qt.Rows[0]["cValue"].ToString() == "true")
  1208. {
  1209. sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
  1210. (
  1211. select
  1212. a.MoCode,b.SortSeq,
  1213. case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId
  1214. end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty
  1215. from DBO.mom_order a
  1216. left join DBO.mom_orderdetail b on a.moid = b.moid
  1217. left join DBO.mom_moallocate c on b.modid = c.modid
  1218. left join
  1219. (select d.AllocateId,e.InvCode,d.MoallocateSubId from
  1220. DBO.mom_moallocatesub d
  1221. left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId
  1222. left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode
  1223. where a.MoCode='{0}' and b.SortSeq='{1}'
  1224. and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1 and f.bInvKeyPart=1
  1225. group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty
  1226. ) tt
  1227. group by MoCode,SortSeq";
  1228. sql = string.Format(sql, mocode, seq);
  1229. qt = DBHelper.SQlReturnData(sql, cmd);
  1230. if (qt == null || qt.Rows.Count == 0)
  1231. {
  1232. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  1233. }
  1234. else
  1235. {
  1236. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  1237. {
  1238. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  1239. }
  1240. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  1241. {
  1242. throw new Exception("该物料:" + body.InvCode + @"入库数量大于关键物料领料套数!");
  1243. }
  1244. }
  1245. }
  1246. else
  1247. {
  1248. sql = @"select MoCode,SortSeq,MIN(lotqty) min_lotqty from
  1249. (
  1250. select
  1251. a.MoCode,b.SortSeq,
  1252. case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId
  1253. end as AllocateId,sum(c.Qty) as Qty,SUM(c.IssQty) IssQty,SUM(c.IssQty)/(SUM(c.Qty)/b.Qty) lotqty
  1254. from DBO.mom_order a
  1255. left join DBO.mom_orderdetail b on a.moid = b.moid
  1256. left join DBO.mom_moallocate c on b.modid = c.modid
  1257. left join
  1258. (select d.AllocateId,e.InvCode,d.MoallocateSubId from
  1259. DBO.mom_moallocatesub d
  1260. left join DBO.bas_part e ON d.partid = e.PartId ) aa on c.MoallocateSubId=aa.MoallocateSubId
  1261. left join DBO.Inventory_Sub f on c.InvCode=f.cInvSubCode
  1262. where a.MoCode='{0}' and b.SortSeq='{1}'
  1263. and c.WIPType<>1 and c.Qty<>0 and c.ByproductFlag<>1
  1264. group by a.MoCode,b.SortSeq,case when aa.AllocateId IS null then c.AllocateId else aa.AllocateId end ,b.Qty
  1265. ) tt
  1266. group by MoCode,SortSeq";
  1267. sql = string.Format(sql, mocode, seq);
  1268. qt = DBHelper.SQlReturnData(sql, cmd);
  1269. if (qt == null || qt.Rows.Count == 0)
  1270. {
  1271. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  1272. }
  1273. else
  1274. {
  1275. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  1276. {
  1277. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  1278. }
  1279. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  1280. {
  1281. throw new Exception("该物料:" + body.InvCode + @"入库数量大于领料套数!");
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. #endregion
  1289. }
  1290. }
  1291. #region 回写生产子件已领数量
  1292. sql = @"
  1293. UPDATE a SET a.IssQty=ISNULL(a.IssQty,0)+" + body.Quantity + @" from dbo.mom_moallocate a
  1294. inner join dbo.mom_orderdetail b on a.MoDId=b.MoDId
  1295. where a.AllocateId='" + body.MODetailID + "' and a.SortSeq='" + body.Sequence + @"'
  1296. ";
  1297. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写生产订单入库数量失败!");
  1298. #endregion
  1299. sql = @"select isnull(IssQty,0)fOutQuantity,isnull(Qty,0)iQuantity,ISNULL(AuxQty, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(AuxQty, 0)-ISNULL(NiNum, 0) SiNum from mom_moallocate a
  1300. LEFT JOIN (select sum(iNum) NiNum,iorderdid from rdrecords10 GROUP BY iorderdid) b on a.AllocateId=b.iorderdid
  1301. where a.AllocateId='" + body.MODetailID + "'";
  1302. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  1303. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  1304. {
  1305. foreach (DataRow item in dtDisCheck.Rows)
  1306. {
  1307. if (Convert.ToDecimal(item["fOutQuantity"].ToString()) == Convert.ToDecimal(item["iQuantity"].ToString()))
  1308. {
  1309. if (Convert.ToDecimal(item["iNum"].ToString()) != 0)
  1310. {
  1311. if (Convert.ToDecimal(item["SiNum"].ToString()) != 0)
  1312. {
  1313. sql = @"Update rdrecords10 set iNum=isnull(iNum,0)+(" + item["SiNum"].ToString() + ") where autoid='" + iChildId + "' ";
  1314. body.Amount = (Convert.ToDecimal(body.Amount.ToString("0.00"))) + (Convert.ToDecimal(item["SiNum"].ToString()));
  1315. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. #region 更新现存量
  1322. key.cBustypeUN = "成品入库";
  1323. key.cVouchTypeUN = "10";
  1324. key.TableName = "IA_ST_UnAccountVouch10";
  1325. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  1326. //DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key);
  1327. DBHelper.UpdateCurrentStockCCGC(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.Amount, body.cFree1,
  1328. body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10,
  1329. "", key, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, iFatherId, iChildId);
  1330. #endregion
  1331. #region 判断工单行是否全部入库
  1332. sql = "select Qty from mom_moallocate WHERE MoDId=(select MoDId from dbo.mom_moallocate where AllocateId='" + body.MODetailID + @"') and IssQty-qty<0
  1333. union all
  1334. select Qty from mom_orderdetail where MoDId=(select MoDId from dbo.mom_moallocate where AllocateId='" + body.MODetailID + @"') and QualifiedInQty-Qty<0
  1335. ";
  1336. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  1337. if (dtClose.Rows.Count == 0)
  1338. {
  1339. sql = @"
  1340. update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId=(select MoDId from dbo.mom_moallocate where AllocateId='" + body.MODetailID + @"')";
  1341. DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  1342. }
  1343. //foreach (DataRow dr in dtClose.Rows)
  1344. //{
  1345. // if (Convert.ToDecimal(dr["qty"]) >= 0)
  1346. // {
  1347. // sql = "update mom_orderdetail set CloseTime = GETDATE(),CloseDate= CONVERT(NVARCHAR(15),GETDATE(),23), CloseUser ='" + head.User + "',Status=4 where MODId='" + body.MODetailID + "'";
  1348. // DBHelper.CmdExecuteNonQuery(sql, cmd, "生产订单行关闭失败!");
  1349. // }
  1350. //}
  1351. #endregion
  1352. iFatherIdTwo = "'" + iFatherId + "',";
  1353. iChildId--;
  1354. }
  1355. #endregion
  1356. #region 查询
  1357. sql = @" select DISTINCT a.ID as ID,a.ID as IDs,a.cCode as MRCVCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName
  1358. ,a.cMPoCode as MOCode ,a.cMaker as CreateUser ,a.dnmaketime as CreateDateTime
  1359. ,a.cHandler as Checker ,a.dnverifytime as CheckDateTime
  1360. from rdrecord10 a
  1361. left join Department c on a.cDepCode=c.cDepCode
  1362. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0})
  1363. select DISTINCT a.ID as IDs, b.iorderdid as DetailID,b.irowno as Sequence ,b.cInvCode as InvCode ,
  1364. b.iQuantity as Quantity ,b.iNum as Amount,b.iMPoIds as MODetailID ,
  1365. isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  1366. isnull(b.cFree1,'') as cFree1,
  1367. isnull(b.cFree2,'') as cFree2,
  1368. isnull(b.cFree3,'') as cFree3,
  1369. isnull(b.cFree4,'') as cFree4,
  1370. isnull(b.cFree5,'') as cFree5,
  1371. isnull(b.cFree6,'') as cFree6,
  1372. isnull(b.cFree7,'') as cFree7,
  1373. isnull(b.cFree8,'') as cFree8,
  1374. isnull(b.cFree9,'') as cFree9,
  1375. isnull(b.cFree10,'') as cFree10
  1376. from rdrecord10 a
  1377. left join rdrecords10 b on a.ID=b.ID
  1378. left join Department c on a.cDepCode=c.cDepCode
  1379. left join Warehouse d on a.cWhCode=d.cWhCode WHERE A.cHandler IS NOT NULL AND A.ID in({0}) ";
  1380. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  1381. if (ds != null)
  1382. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  1383. else
  1384. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1385. #endregion
  1386. }
  1387. cmd.Transaction.Commit();
  1388. }
  1389. catch (Exception ex)
  1390. {
  1391. if (cmd.Transaction != null)
  1392. cmd.Transaction.Rollback();
  1393. log.Error(ex.Message);
  1394. throw new Exception(ex.Message);
  1395. }
  1396. finally
  1397. {
  1398. if (conn.State == ConnectionState.Open)
  1399. {
  1400. conn.Close();
  1401. }
  1402. conn.Dispose();
  1403. }
  1404. }
  1405. //string RelationName = "details";
  1406. //DataSet dz = new DataSet();
  1407. //dtNew1.TableName = "Table0";
  1408. //dtNew2.TableName = "Table1";
  1409. //dz.Tables.Add(dtNew1.Copy());
  1410. //dz.Tables.Add(dtNew2.Copy());
  1411. //DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  1412. //dz.Relations.Add(dh);
  1413. msg = JSON.DataSetToJson(ds, "details", "IDs");
  1414. return msg;
  1415. }
  1416. /// <summary>
  1417. /// 审核成品入库单
  1418. /// </summary>
  1419. /// <param name="infos"></param>
  1420. /// <returns></returns>
  1421. public bool Approve(List<ICSManufactureReceiveDoc> infos)
  1422. {
  1423. bool ResultFlag = false;
  1424. List<ICSManufactureReceiveDoc> szJson = new List<ICSManufactureReceiveDoc>();
  1425. string connS = "";
  1426. if (infos.Count <= 0)
  1427. {
  1428. throw new Exception("传送数据为空!");
  1429. }
  1430. LogInfo(infos);
  1431. string res = string.Empty;
  1432. SqlConnection conn = new SqlConnection();
  1433. SqlCommand cmd = new SqlCommand();
  1434. string sql = string.Empty;
  1435. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  1436. foreach (string WorkPoint in result)
  1437. {
  1438. try
  1439. {
  1440. connS = string.Format(connString, WorkPoint);
  1441. conn = new System.Data.SqlClient.SqlConnection(connS);
  1442. conn.Open();
  1443. SqlTransaction sqlTran = conn.BeginTransaction();
  1444. cmd = new SqlCommand();
  1445. cmd.Transaction = sqlTran;
  1446. cmd.Connection = conn;
  1447. foreach (ICSManufactureReceiveDoc head in infos)
  1448. {
  1449. if (WorkPoint != head.WorkPoint)
  1450. continue;
  1451. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  1452. throw new Exception("U8正在整理现存量,请稍后再试");
  1453. ICSUserInfo userInfo = new ICSUserInfo();
  1454. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  1455. #region 检验单号是否存在
  1456. sql = "select * from rdrecord10 where ID='" + head.ID + "'";
  1457. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1458. if (dt != null && dt.Rows.Count > 0)
  1459. {
  1460. string cHandler = dt.Rows[0]["cHandler"].ToString();
  1461. if (!string.IsNullOrEmpty(cHandler))
  1462. {
  1463. throw new Exception("单据ID:" + head.ID + "不是开立状态!");
  1464. }
  1465. }
  1466. else
  1467. {
  1468. throw new Exception("单据ID:" + head.ID + "在U8中不存在!");
  1469. }
  1470. #endregion
  1471. #region 审核其他出库单
  1472. sql = @"UPDATE dbo.rdrecord10 SET cHandler='" + userInfo.UserName + @"' ,
  1473. dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE() WHERE ID='" + head.ID + "'";
  1474. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核其他出库单失败!");
  1475. #endregion
  1476. sql = "select * from dbo.rdrecords10 a inner join rdrecord10 b on a.ID=b.ID where b.ID='" + head.ID + "';";
  1477. DataTable dtChecks = DBHelper.SQlReturnData(sql, cmd);
  1478. if (head.UpdateStock)
  1479. {
  1480. #region 更新现存量
  1481. for (int i = 0; i < dtChecks.Rows.Count; i++)
  1482. {
  1483. //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  1484. sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "'AND cBatch='" + dtChecks.Rows[i]["cBatch"].ToString() + @"'AND cFree1='" + dtChecks.Rows[i]["cFree1"].ToString() + @"' AND cFree2='" + dtChecks.Rows[i]["cFree2"].ToString() + @"' AND cFree3='" + dtChecks.Rows[i]["cFree3"].ToString() + @"' AND cFree4='" + dtChecks.Rows[i]["cFree4"].ToString() + @"' AND cFree5='" + dtChecks.Rows[i]["cFree5"].ToString() + @"' AND cFree6='" + dtChecks.Rows[i]["cFree6"].ToString() + @"' AND cFree7='" + dtChecks.Rows[i]["cFree7"].ToString() + @"' AND cFree8='" + dtChecks.Rows[i]["cFree8"].ToString() + @"' AND cFree9='" + dtChecks.Rows[i]["cFree9"].ToString() + @"' AND cFree10='" + dtChecks.Rows[i]["cFree10"].ToString() + @"' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "'";
  1485. DataTable dtItem = DBHelper.SQlReturnData(sql, cmd);
  1486. if (dtItem != null && dtItem.Rows.Count > 0)
  1487. {
  1488. //if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
  1489. //{
  1490. // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  1491. //}
  1492. if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()))
  1493. {
  1494. throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + dtChecks.Rows[i]["cInvCode"].ToString());
  1495. }
  1496. }
  1497. else
  1498. {
  1499. throw new Exception("物料:" + dtChecks.Rows[i]["cInvCode"].ToString() + "在现存量表中不存在!");
  1500. }
  1501. VouchKey key = new VouchKey();
  1502. key.cBustypeUN = "成品入库";
  1503. key.cVouchTypeUN = "10";
  1504. key.TableName = "IA_ST_UnAccountVouch10";
  1505. //DBHelper.UpdateCurrentStock(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), "", Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), key);
  1506. //DBHelper.UpdateCurrentStockNEW(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(), dtChecks.Rows[i]["cBatch"].ToString(), Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()), dtChecks.Rows[i]["cFree1"].ToString(), dtChecks.Rows[i]["cFree2"].ToString(), dtChecks.Rows[i]["cFree3"].ToString(), dtChecks.Rows[i]["cFree4"].ToString(), dtChecks.Rows[i]["cFree5"].ToString(), dtChecks.Rows[i]["cFree6"].ToString(), dtChecks.Rows[i]["cFree7"].ToString(), dtChecks.Rows[i]["cFree8"].ToString(), dtChecks.Rows[i]["cFree9"].ToString(), dtChecks.Rows[i]["cFree10"].ToString(), key);
  1507. string inum = dtChecks.Rows[i]["iAVNum"].ToString();
  1508. if (inum == "")
  1509. {
  1510. inum = "0";
  1511. }
  1512. DBHelper.UpdateCurrentStockCCGC(cmd, dtChecks.Rows[i]["cInvCode"].ToString(), dtChecks.Rows[i]["cWhCode"].ToString(),
  1513. dtChecks.Rows[i]["cBatch"].ToString(), Convert.ToDecimal(dtChecks.Rows[i]["iAVQuantity"].ToString()),
  1514. Convert.ToDecimal(inum), dtChecks.Rows[i]["cFree1"].ToString(),
  1515. dtChecks.Rows[i]["cFree2"].ToString(), dtChecks.Rows[i]["cFree3"].ToString(), dtChecks.Rows[i]["cFree4"].ToString(), dtChecks.Rows[i]["cFree5"].ToString(), dtChecks.Rows[i]["cFree6"].ToString(), dtChecks.Rows[i]["cFree7"].ToString(), dtChecks.Rows[i]["cFree8"].ToString(), dtChecks.Rows[i]["cFree9"].ToString(), dtChecks.Rows[i]["cFree10"].ToString(),
  1516. "", key, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, Convert.ToInt32(dtChecks.Rows[i]["ID"].ToString()), Convert.ToInt32(dtChecks.Rows[i]["AutoID"].ToString()));
  1517. //回写fOutQuantityy
  1518. // sql = @"Update CurrentStock set fOutQuantity=isnull(fOutQuantity,0)-" + Convert.ToDecimal(dtChecks.Rows[i]["iQuantity"].ToString()) + @"
  1519. // where cInvCode='" + dtChecks.Rows[i]["cInvCode"].ToString() + "' and cWhCode='" + dtChecks.Rows[i]["cWhCode"].ToString() + "' ";
  1520. //if (body.cBatch != null)
  1521. //{
  1522. // sql += "and cBatch='" + body.cBatch + "'";
  1523. //}
  1524. //else
  1525. //{
  1526. // sql += "and cBatch=''";
  1527. //}
  1528. //DBHelper.CmdExecuteNonQuery(sql, cmd, "回写fOutQuantity失败!");
  1529. //if (head.UpdateTodoQuantity == true)
  1530. //{
  1531. }
  1532. #endregion
  1533. }
  1534. }
  1535. cmd.Transaction.Commit();
  1536. }
  1537. catch (Exception ex)
  1538. {
  1539. if (cmd.Transaction != null)
  1540. cmd.Transaction.Rollback();
  1541. log.Error(ex.Message);
  1542. throw new Exception(ex.Message);
  1543. }
  1544. finally
  1545. {
  1546. if (conn.State == ConnectionState.Open)
  1547. {
  1548. conn.Close();
  1549. }
  1550. conn.Dispose();
  1551. }
  1552. ResultFlag = true;
  1553. }
  1554. return ResultFlag;
  1555. }
  1556. /// <summary>
  1557. /// 删除成品入库单
  1558. /// </summary>
  1559. /// <param name="infos"></param>
  1560. /// <returns></returns>
  1561. public string Delete(List<ICSManufactureReceiveDoc> infos)
  1562. {
  1563. List<ICSManufactureReceiveDoc> szJson = new List<ICSManufactureReceiveDoc>();
  1564. if (infos.Count <= 0)
  1565. {
  1566. throw new Exception("传送数据为空!");
  1567. }
  1568. string connS = "";
  1569. string res = string.Empty;
  1570. SqlConnection conn = new SqlConnection();
  1571. SqlCommand cmd = new SqlCommand();
  1572. string sql = string.Empty;
  1573. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  1574. foreach (string WorkPoint in result)
  1575. {
  1576. try
  1577. {
  1578. connS = string.Format(connString, WorkPoint);
  1579. conn = new System.Data.SqlClient.SqlConnection(connS);
  1580. conn.Open();
  1581. SqlTransaction sqlTran = conn.BeginTransaction();
  1582. cmd = new SqlCommand();
  1583. cmd.Transaction = sqlTran;
  1584. cmd.Connection = conn;
  1585. foreach (ICSManufactureReceiveDoc info in infos)
  1586. {
  1587. if (WorkPoint != info.WorkPoint)
  1588. continue;
  1589. if (info.MTime < new DateTime(2000, 01, 01))
  1590. throw new Exception("请输入正确的操作时间:" + info.MTime);
  1591. sql = @" DELETE rdrecord10 WHERE ID={0}";
  1592. sql = string.Format(sql, info.ID);
  1593. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  1594. }
  1595. cmd.Transaction.Commit();
  1596. }
  1597. catch (Exception ex)
  1598. {
  1599. if (cmd.Transaction != null)
  1600. cmd.Transaction.Rollback();
  1601. log.Error(ex.Message);
  1602. throw new Exception(ex.Message);
  1603. }
  1604. finally
  1605. {
  1606. if (conn.State == ConnectionState.Open)
  1607. {
  1608. conn.Close();
  1609. }
  1610. conn.Dispose();
  1611. }
  1612. }
  1613. return res;
  1614. }
  1615. /// <summary>
  1616. ///
  1617. /// 记录日志
  1618. /// </summary>
  1619. /// <param name="Bills"></param>
  1620. private void LogInfo(List<ICSManufactureReceiveDoc> Bills)
  1621. {
  1622. string HeadList = string.Empty;
  1623. string BodyList = string.Empty;
  1624. foreach (ICSManufactureReceiveDoc head in Bills)
  1625. {
  1626. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  1627. foreach (ICSManufactureReceiveDocs body in head.details)
  1628. {
  1629. BodyList += "\r\n 表体主键ID: " + body.MODetailID + ",数量:" + body.Quantity;
  1630. }
  1631. }
  1632. log.Info(HeadList);
  1633. log.Info(BodyList);
  1634. }
  1635. }
  1636. }