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

594 lines
32 KiB

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
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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 MOIssueDocNegatives
  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["MoICRDNAME"];
  23. public string Get(List<ICSMOIssueDocNegative> infos)
  24. {
  25. List<ICSMOIssueDocNegative> szJson = new List<ICSMOIssueDocNegative>();
  26. DataTable dt = null;
  27. DataTable dtNew = null;
  28. string connS = "";
  29. string json = "";
  30. if (infos.Count <= 0)
  31. {
  32. throw new Exception("传送数据为空!");
  33. }
  34. string res = string.Empty;
  35. SqlConnection conn = new SqlConnection();
  36. SqlCommand cmd = new SqlCommand();
  37. string sql = string.Empty;
  38. foreach (ICSMOIssueDocNegative info in infos)
  39. {
  40. try
  41. {
  42. connS = string.Format(connString, info.WorkPoint);
  43. conn = new System.Data.SqlClient.SqlConnection(connS);
  44. conn.Open();
  45. SqlTransaction sqlTran = conn.BeginTransaction();
  46. cmd = new SqlCommand();
  47. cmd.Transaction = sqlTran;
  48. cmd.Connection = conn;
  49. if (info.MTime < new DateTime(2000, 01, 01))
  50. throw new Exception("请输入正确的操作时间:" + info.MTime);
  51. sql = @" select a.ID,iMPoIds,iordercode,cCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName,cSource,cMaker,dnmaketime,cHandler,dnverifytime,cSourceCodeLs,b.AutoID ,irowno,b.cInvCode,iQuantity,f.MoDId,iNum,g.MoCode from rdrecord11 a
  52. left join rdrecords11 b on a.ID=b.ID
  53. left join Department c on a.cDepCode=c.cDepCode
  54. left join Warehouse d on a.cWhCode=d.cWhCode
  55. left join mom_moallocate e on b.iMPoIds=e.AllocateId
  56. INNER JOIN dbo.mom_orderdetail f ON e.MoDId=f.MoDId
  57. INNER JOIN dbo.mom_order g ON f.MoId=g.MoId where b.iQuantity<0";
  58. if (!string.IsNullOrWhiteSpace(info.IssueNEGCode))
  59. {
  60. sql += " and a.cCode='{0}'";
  61. }
  62. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  63. {
  64. sql += " and ISNULL(a.dnmodifytime,ISNULL(a.dnverifytime, ISNULL(a.dnmodifytime, a.dnmaketime)))>='{1}'";
  65. }
  66. if (!string.IsNullOrWhiteSpace(info.User))
  67. {
  68. sql += "and a.CMAKER='{2}'";
  69. }
  70. sql = string.Format(sql, info.IssueNEGCode, info.MTime, info.User);
  71. dt = DBHelper.SQlReturnData(sql, cmd);
  72. if (dt.Rows.Count <= 0 || dt == null)
  73. throw new Exception("材料出库单:" + info.IssueNEGCode + ",无信息!");
  74. if (dtNew == null)
  75. dtNew = dt;
  76. else
  77. dtNew.Merge(dt);
  78. cmd.Transaction.Commit();
  79. }
  80. catch (Exception ex)
  81. {
  82. cmd.Transaction.Rollback();
  83. log.Error(ex.Message);
  84. throw new Exception(ex.Message);
  85. }
  86. finally
  87. {
  88. if (conn.State == ConnectionState.Open)
  89. {
  90. conn.Close();
  91. }
  92. conn.Dispose();
  93. }
  94. }
  95. json = JsonConvert.SerializeObject(dtNew);
  96. return json;
  97. }
  98. public string CreateRd11(List<ICSMOIssueDocNegative> Bills)
  99. {
  100. string msg = "";
  101. DataTable dtNew1 = null;
  102. DataTable dtNew2 = null;
  103. string connS = "";
  104. string sql = string.Empty;
  105. string iFatherIdTwo = string.Empty;
  106. VouchKey key = new VouchKey();
  107. int num = 0;
  108. SqlConnection conn = new SqlConnection();
  109. SqlCommand cmd = new SqlCommand();
  110. if (Bills.Count <= 0)
  111. {
  112. throw new Exception("传送数据为空!");
  113. }
  114. LogInfo(Bills);
  115. //MergeObject(Bills, cmd);
  116. foreach (ICSMOIssueDocNegative head in Bills)
  117. {
  118. try
  119. {
  120. num = head.details.Count();
  121. connS = string.Format(connString, head.WorkPoint);
  122. conn = new System.Data.SqlClient.SqlConnection(connS);
  123. conn.Open();
  124. SqlTransaction sqlTran = conn.BeginTransaction();
  125. cmd = new SqlCommand();
  126. cmd.Transaction = sqlTran;
  127. cmd.Connection = conn;
  128. cmd.CommandTimeout = 300;
  129. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  130. {
  131. }
  132. else
  133. {
  134. throw new Exception("U8正在整理现存量,请稍后再试");
  135. }
  136. string[] ss = head.WorkPoint.Split('_');
  137. ERPDB = ss[1];
  138. string[] dd = CRNALL.Split('~');
  139. string crdname = dd[0];
  140. string carname = dd[1];
  141. string surface = dd[2];
  142. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  143. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  144. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  145. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  146. DateTime date = DateTime.Now;
  147. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  148. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  149. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  150. // #region 判断工单是否已关闭
  151. // sql = @"SELECT isnull(CloseUser,'') as CloseUser from mom_orderdetail a
  152. // inner join mom_order b on a.MoId=b.MoId where b.MoId='" + head.DetailID + "' ";
  153. // DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  154. // if (dtClose != null && dtClose.Rows.Count > 0)
  155. // {
  156. // if (!string.IsNullOrEmpty(dtClose.Rows[0][0].ToString()))
  157. // {
  158. // throw new Exception("该工单行已关闭,无法领料!");
  159. // }
  160. // }
  161. // #endregion
  162. #region 材料出库单表头
  163. if (head.SourceType != "领料申请单")
  164. {
  165. sql = @"INSERT INTO dbo.rdrecord11
  166. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cWhCode ,dDate ,
  167. cCode ,cRdCode ,cDepCode,cHandler ,bTransFlag ,cMaker ,
  168. dVeriDate ,bpufirst ,biafirst ,VT_ID ,bIsSTQc
  169. ,cPsPcode ,cMPoCode ,iproorderid ,bFromPreYear ,
  170. bIsLsQuery ,bIsComplement ,iDiscountTaxType ,ireturncount ,iverifystate ,
  171. iswfcontrolled ,dnmaketime ,dnverifytime ,bredvouch ,iPrintCount,
  172. iMQuantity)
  173. SELECT distinct @ID,0,'11','','',@cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),
  174. @cCode,@cRdCode,a.MDeptCode,@cHandler,0,@cMaker,
  175. CONVERT(NVARCHAR(15),GETDATE(),23),0,0,@VT_ID,0,
  176. null,b.MoCode,a.MoId,0,
  177. 0,0,0,0,0,
  178. 0,GETDATE(),GETDATE(),1,1,
  179. null
  180. FROM dbo.mom_orderdetail a
  181. left JOIN dbo.mom_order b ON a.MoId=b.MoId
  182. left join mom_morder c on a.modid=c.modid
  183. WHERE b.MoCode='" + head.SourceCode + "'";
  184. cmd.Parameters.Clear();
  185. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  186. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  187. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  188. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  189. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  190. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  191. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  192. //cmd.Parameters.Add(new SqlParameter("@bredvouch",0));
  193. cmd.CommandText = sql;
  194. }
  195. else
  196. {
  197. sql = @"INSERT INTO dbo.rdrecord11
  198. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cBusCode ,cWhCode ,
  199. dDate ,cCode ,cRdCode ,cDepCode ,cPersonCode ,cHandler ,cMemo ,
  200. bTransFlag ,cMaker ,cDefine1 ,cDefine2 ,cDefine3 ,cDefine4 ,
  201. cDefine5 ,cDefine6 ,cDefine7 ,cDefine8 ,cDefine9 ,cDefine10 ,
  202. dVeriDate ,bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cDefine11 ,
  203. cDefine12 ,cDefine13 ,cDefine14 ,cDefine15 ,cDefine16 ,
  204. bOMFirst ,bFromPreYear ,bIsComplement ,iDiscountTaxType ,
  205. ireturncount ,iverifystate ,iswfcontrolled ,cModifyPerson ,
  206. dnmaketime ,dnverifytime ,bredvouch ,bmotran ,bHYVouch ,iPrintCount
  207. )
  208. SELECT distinct @ID,0,'11','','',a.cCode,@cWhCode,
  209. CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,a.cDepCode,a.cPersonCode,@cHandler,a.cMemo,
  210. 0,@cMaker,a.cDefine1,cdefine2,a.cDefine3,a.cDefine4,
  211. a.cDefine5,a.cDefine6,a.cDefine7,a.cDefine8,a.cDefine9,a.cDefine10,
  212. CONVERT(NVARCHAR(15),GETDATE(),23),0,0,@VT_ID,0,a.cDefine11,
  213. a.cDefine12,a.cDefine13,a.cDefine14,a.cDefine15,a.cDefine16,
  214. 0,0,0,0,
  215. 0,0,0,'',
  216. GETDATE(),GETDATE(),0,0,0,0
  217. FROM dbo.MaterialAppVouch a WHERE a.cCode='" + head.SourceCode + "'";
  218. cmd.Parameters.Clear();
  219. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  220. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  221. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  222. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  223. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  224. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  225. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  226. //DBHelper.CmdExecuteNonQuery(sql, cmd, "生成材料出库单表头失败!");
  227. cmd.CommandText = sql;
  228. }
  229. try
  230. {
  231. int count = cmd.ExecuteNonQuery();
  232. if (count <= 0)
  233. {
  234. log.Error("生成材料出库单表头失败,受影响行数<=0;");
  235. throw new Exception("生成材料出库单表头失败,受影响行数<=0;");
  236. }
  237. }
  238. catch (Exception ex)
  239. {
  240. log.Error("生成材料出库单表头失败" + sql, ex);
  241. throw new Exception("生成材料出库单表头失败" + sql, ex);
  242. }
  243. #endregion
  244. #region 材料出库单表体
  245. int irowno = 0;
  246. foreach (ICSMOIssueDocNegatives body in head.details)
  247. {
  248. irowno++;
  249. if (head.SourceType != "领料申请单")
  250. {
  251. sql = @"INSERT INTO dbo.rdrecords11
  252. ( AutoID ,ID ,cInvCode ,iQuantity ,cBatch ,iFlag ,iNum,
  253. cItemCode ,cName ,iNQuantity ,iMPoIds ,bLPUseFree ,
  254. iOriTrackID ,bCosting ,bVMIUsed ,cmocode ,invcode ,imoseq ,
  255. iopseq ,iExpiratDateCalcu ,iorderdid ,iordertype ,isotype ,
  256. ipesodid ,ipesotype ,cpesocode ,ipesoseq ,irowno ,
  257. bcanreplace ,iposflag,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  258. SELECT @AutoID,@ID,a.InvCode,@iQuantity,@cBatch,0,@iNum,
  259. null,null,a.Qty,a.AllocateId,0,
  260. 0,1,0,c.MoCode,b.InvCode,b.SortSeq,
  261. '0000',0,0,0,0,
  262. a.AllocateId,'7',c.MoCode,b.SortSeq,@irowno,
  263. 0,null,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  264. FROM dbo.mom_moallocate a
  265. INNER JOIN dbo.mom_orderdetail b ON a.MoDId=b.MoDId
  266. INNER JOIN dbo.mom_order c ON b.MoId=c.MoId
  267. WHERE a.AllocateId='" + body.SourceDetailID + "'";
  268. cmd.Parameters.Clear();
  269. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  270. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  271. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  272. cmd.Parameters.Add(new SqlParameter("@iNum", -body.Amount));
  273. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  274. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  275. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  276. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  277. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  278. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  279. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  280. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  281. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  282. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  283. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  284. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  285. cmd.CommandText = sql;
  286. }
  287. else
  288. {
  289. sql = @"INSERT INTO dbo.rdrecords11
  290. ( AutoID ,ID ,cInvCode ,iQuantity ,iFlag ,cDefine22 ,iMPoIds,cmocode,iNum,
  291. cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  292. cItem_class ,cItemCode ,cName ,cItemCName ,iNQuantity ,
  293. cDefine28 ,cDefine29 ,cDefine30 ,cDefine31 ,cDefine32 ,
  294. cDefine33 ,cDefine34 ,cDefine35 ,cDefine36 ,cDefine37 ,
  295. bLPUseFree ,iOriTrackID ,bCosting ,bVMIUsed ,iMaIDs ,
  296. iExpiratDateCalcu ,iordertype ,isotype ,ipesotype ,irowno,
  297. cBatch,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  298. SELECT @AutoID,@ID,a.cInvCode,@iQuantity,0,a.cDefine22,a.iMPoIds,a.cmocode,@iNum,
  299. a.cDefine23,a.cDefine24,a.cDefine25,a.cDefine26,a.cDefine27,
  300. a.cItem_class,a.cItemCode,a.cName,a.cItemCName,@iQuantity,
  301. a.cDefine28,a.cDefine29,a.cDefine30,a.cDefine31,a.cDefine32,
  302. a.cDefine33,a.cDefine34,a.cDefine35,a.cDefine36,a.cDefine37,
  303. 0,0,1,0,a.AutoID,
  304. 0,0,0,0,@irowno,
  305. @cBatch,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  306. FROM dbo.MaterialAppVouchs a WHERE a.AutoID='" + body.SourceDetailID + "'";
  307. cmd.Parameters.Clear();
  308. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  309. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  310. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  311. cmd.Parameters.Add(new SqlParameter("@iNum", -body.Amount));
  312. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  313. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  314. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  315. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  316. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  317. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  318. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  319. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  320. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  321. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  322. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  323. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  324. //DBHelper.CmdExecuteNonQuery(sql, cmd, "生成材料出库单表头失败!");
  325. cmd.CommandText = sql;
  326. }
  327. try
  328. {
  329. int count = cmd.ExecuteNonQuery();
  330. if (count <= 0)
  331. {
  332. log.Error("生成材料出库单表体失败,受影响行数<=0;");
  333. throw new Exception("生成材料出库单表体失败,受影响行数<=0;");
  334. }
  335. }
  336. catch (Exception ex)
  337. {
  338. log.Error("生成材料出库单表体失败" + sql, ex);
  339. throw new Exception("生成材料出库单表体失败 " + sql, ex);
  340. }
  341. if (head.UpdateStock)
  342. {
  343. //更新现存量
  344. key.cBustypeUN = "领料";
  345. key.cVouchTypeUN = "11";
  346. key.TableName = "IA_ST_UnAccountVouch11";
  347. 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);
  348. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  349. }
  350. if (head.SourceType != "领料申请单")
  351. {
  352. #region 回写工单子件已领数量
  353. sql = "update mom_moallocate set IssQty=isnull(IssQty,0)+" + body.Quantity + ",RequisitionIssQty=isnull(RequisitionIssQty,0)+(" + body.Quantity + ") where AllocateId='" + body.SourceDetailID + "' ";
  354. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写工单子件已领数量失败!");
  355. #endregion
  356. }
  357. else
  358. {
  359. #region 回写工单子件已领数量
  360. sql = "update mom_moallocate set IssQty=isnull(IssQty,0)+" + body.Quantity + ",RequisitionIssQty=isnull(RequisitionIssQty,0)+" + body.Quantity + " where AllocateId=(select iMPoIds from MaterialAppVouchs where AutoID='" + body.SourceDetailID + @"')
  361. update MaterialAppVouchs set fOutQuantity=isnull(fOutQuantity,0)+" + body.Quantity + @" where AutoID='" + body.SourceDetailID + @"'
  362. ";
  363. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写工单子件已领数量失败!");
  364. #endregion
  365. }
  366. iFatherIdTwo += "'" + iFatherId + "',";
  367. iChildId--;
  368. }
  369. #endregion
  370. #region 查询
  371. sql = @"
  372. select DISTINCT a.ID as ID,a.ID as IDs,cMPoCode as SourceCode ,
  373. cCode as IssueNEGCode,a.cDepCode,c.cDepName,a.cWhCode,d.cWhName,
  374. cSource as SourceType,cMaker as CreateUser,dnmaketime as CreateDateTime,
  375. cHandler as Checker,dnverifytime as CheckDateTime
  376. from rdrecord11 a
  377. left join Department c on a.cDepCode=c.cDepCode
  378. left join Warehouse d on a.cWhCode=d.cWhCode
  379. WHERE a.ID in ({0})
  380. select DISTINCT a.ID as IDs,b.AutoID as DetailID,b.irowno as Sequence,b.cInvCode as InvCode
  381. ,b.iQuantity as Quantity,(case when isnull(l.AutoID,'')='' then e.AllocateId else l.AutoID end) as SourceDetailID,b.iNum as Amount
  382. from rdrecord11 a
  383. left join rdrecords11 b on a.ID=b.ID
  384. left join MaterialAppVouchs l on b.iMaIDs=l.autoid
  385. left join Department c on a.cDepCode=c.cDepCode
  386. left join Warehouse d on a.cWhCode=d.cWhCode
  387. left join mom_moallocate e on b.iMPoIds=e.AllocateId
  388. INNER JOIN dbo.mom_orderdetail f ON e.MoDId=f.MoDId
  389. INNER JOIN dbo.mom_order g ON f.MoId=g.MoId WHERE a.ID in ({0})";
  390. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  391. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  392. if (dtNew1 == null)
  393. dtNew1 = ds.Tables[0];
  394. else
  395. dtNew1 = ds.Tables[0];
  396. if (dtNew2 == null)
  397. dtNew2 = ds.Tables[1];
  398. else
  399. dtNew2 = ds.Tables[1];
  400. #endregion
  401. cmd.Transaction.Commit();
  402. }
  403. catch (Exception ex)
  404. {
  405. cmd.Transaction.Rollback();
  406. log.Error(ex.Message);
  407. throw new Exception(ex.Message);
  408. }
  409. finally
  410. {
  411. if (conn.State == ConnectionState.Open)
  412. {
  413. conn.Close();
  414. }
  415. conn.Dispose();
  416. }
  417. }
  418. string RelationName = "details";
  419. DataSet dz = new DataSet();
  420. dtNew1.TableName = "Table0";
  421. dtNew2.TableName = "Table1";
  422. dz.Tables.Add(dtNew1.Copy());
  423. dz.Tables.Add(dtNew2.Copy());
  424. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  425. dz.Relations.Add(dh);
  426. msg = DBHelper.DataSetToJson(dz, RelationName);
  427. return msg;
  428. }
  429. public string Approve(List<ICSMOIssueDocNegative> infos)
  430. {
  431. List<ICSMOIssueDocNegative> szJson = new List<ICSMOIssueDocNegative>();
  432. string connS = "";
  433. string json = "";
  434. if (infos.Count <= 0)
  435. {
  436. throw new Exception("传送数据为空!");
  437. }
  438. string res = string.Empty;
  439. SqlConnection conn = new SqlConnection();
  440. SqlCommand cmd = new SqlCommand();
  441. string sql = string.Empty;
  442. foreach (ICSMOIssueDocNegative info in infos)
  443. {
  444. try
  445. {
  446. connS = string.Format(connString, info.WorkPoint);
  447. conn = new System.Data.SqlClient.SqlConnection(connS);
  448. conn.Open();
  449. SqlTransaction sqlTran = conn.BeginTransaction();
  450. cmd = new SqlCommand();
  451. cmd.Transaction = sqlTran;
  452. cmd.Connection = conn;
  453. if (info.MTime < new DateTime(2000, 01, 01))
  454. throw new Exception("请输入正确的操作时间:" + info.MTime);
  455. sql = @"UPDATE dbo.rdrecord11 SET cHandler ='" + info.User + @"' ,
  456. dnmodifytime =CONVERT(VARCHAR(50),GETDATE(),112),dModifyDate =GETDATE() WHERE ID='{0}'";
  457. sql = string.Format(sql, info.ID);
  458. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核生产退料单失败!");
  459. cmd.Transaction.Commit();
  460. }
  461. catch (Exception ex)
  462. {
  463. cmd.Transaction.Rollback();
  464. log.Error(ex.Message);
  465. throw new Exception(ex.Message);
  466. }
  467. finally
  468. {
  469. if (conn.State == ConnectionState.Open)
  470. {
  471. conn.Close();
  472. }
  473. conn.Dispose();
  474. }
  475. }
  476. return json;
  477. }
  478. /// <summary>
  479. /// 删除请购单
  480. /// </summary>
  481. /// <param name="infos"></param>
  482. /// <returns></returns>
  483. public string Delete(List<ICSMOIssueDocNegative> infos)
  484. {
  485. List<ICSMOIssueDocNegative> szJson = new List<ICSMOIssueDocNegative>();
  486. if (infos.Count <= 0)
  487. {
  488. throw new Exception("传送数据为空!");
  489. }
  490. string res = string.Empty;
  491. string connS = "";
  492. SqlConnection conn = new SqlConnection();
  493. SqlCommand cmd = new SqlCommand();
  494. string sql = string.Empty;
  495. foreach (ICSMOIssueDocNegative info in infos)
  496. {
  497. try
  498. {
  499. connS = string.Format(connString, info.WorkPoint);
  500. conn = new System.Data.SqlClient.SqlConnection(connS);
  501. conn.Open();
  502. SqlTransaction sqlTran = conn.BeginTransaction();
  503. cmd = new SqlCommand();
  504. cmd.Transaction = sqlTran;
  505. cmd.Connection = conn;
  506. if (info.MTime < new DateTime(2000, 01, 01))
  507. throw new Exception("请输入正确的操作时间:" + info.MTime);
  508. sql = @"delete rdrecord11 where rdrecord11.ID='" + info.ID + "'";
  509. sql += @"delete rdrecords11 where rdrecords11.ID='" + info.ID + "'";
  510. //UPDATE dbo.rdrecord11 a SET cHandler='" + info.User + @"' ,
  511. // dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE()
  512. // WHERE a.ID='" + info.ID + "'";
  513. DBHelper.CmdExecuteNonQuery(sql, cmd, "删除材料出库单失败!");
  514. cmd.Transaction.Commit();
  515. }
  516. catch (Exception ex)
  517. {
  518. cmd.Transaction.Rollback();
  519. log.Error(ex.Message);
  520. throw new Exception(ex.Message);
  521. }
  522. finally
  523. {
  524. if (conn.State == ConnectionState.Open)
  525. {
  526. conn.Close();
  527. }
  528. conn.Dispose();
  529. }
  530. }
  531. return res;
  532. }
  533. private void LogInfo(List<ICSMOIssueDocNegative> Bills)
  534. {
  535. string HeadList = string.Empty;
  536. string BodyList = string.Empty;
  537. foreach (ICSMOIssueDocNegative head in Bills)
  538. {
  539. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  540. foreach (ICSMOIssueDocNegatives body in head.details)
  541. {
  542. BodyList += "\r\n 表体主键ID: " + body.SourceDetailID + ",数量:" + body.Quantity;
  543. }
  544. }
  545. log.Info(HeadList);
  546. log.Info(BodyList);
  547. }
  548. /// <summary>
  549. /// 表体合并
  550. /// </summary>
  551. /// <param name="Bills"></param>
  552. private void MergeObject(List<ICSMOIssueDocNegative> Bills, SqlCommand cmd)
  553. {
  554. foreach (ICSMOIssueDocNegative head in Bills)
  555. {
  556. DataTable dt = DBHelper.ToDataTable(head.details.ToList());
  557. DataTable dtNew = dt.Clone();
  558. dtNew = DBHelper.MergeDataTable(dt, "AllocateId", "cBatch", "iQuantity", "InvCode", cmd);
  559. List<ICSMOIssueDocNegatives> list = DBHelper.ConvertTo<ICSMOIssueDocNegatives>(dtNew).ToList();
  560. head.details = list;
  561. }
  562. }
  563. }
  564. }