纽威
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.

1438 lines
81 KiB

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