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

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