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

1009 lines
59 KiB

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 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
3 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
3 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 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 OutsourcingIssueDoNegative
  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["OutIssCRDNAME"];
  23. public string Get(List<ICSOutsourcingIssueDoc> infos)
  24. {
  25. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  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. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  39. foreach (string WorkPoint in result)
  40. {
  41. try
  42. {
  43. connS = string.Format(connString, WorkPoint);
  44. conn = new System.Data.SqlClient.SqlConnection(connS);
  45. conn.Open();
  46. SqlTransaction sqlTran = conn.BeginTransaction();
  47. cmd = new SqlCommand();
  48. cmd.Transaction = sqlTran;
  49. cmd.Connection = conn;
  50. foreach (ICSOutsourcingIssueDoc info in infos)
  51. {
  52. if (WorkPoint != info.WorkPoint)
  53. continue;
  54. ICSUserInfo userInfo = new ICSUserInfo();
  55. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  56. if (info.MTime < new DateTime(2000, 01, 01))
  57. throw new Exception("请输入正确的操作时间:" + info.MTime);
  58. sql = @" select a.ID,iMPoIds,iordercode,a.cCode,a.cDepCode,c.cDepName,a.cWhCode,
  59. d.cWhName,a.cSource,a.cMaker,dnmaketime,cHandler,dnverifytime,cSourceCodeLs,
  60. b.AutoID ,b.irowno,b.cInvCode,b.iQuantity,e.MoDetailsID,b.iNum,e.csocode
  61. from rdrecord11 a
  62. left join rdrecords11 b on a.ID=b.ID
  63. left join Department c on a.cDepCode=c.cDepCode
  64. left join Warehouse d on a.cWhCode=d.cWhCode
  65. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  66. where a.cBusType=''and b.iQuantity<0";
  67. if (!string.IsNullOrWhiteSpace(info.IssueCode))
  68. {
  69. sql += " and a.cCode='{0}'";
  70. }
  71. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  72. {
  73. sql += " and ISNULL(a.dnmodifytime,ISNULL(a.dnverifytime, ISNULL(a.dnmodifytime, a.dnmaketime)))>='{1}'";
  74. }
  75. if (!string.IsNullOrWhiteSpace(info.User))
  76. {
  77. sql += "and a.CMAKER='{2}'";
  78. }
  79. sql = string.Format(sql, info.IssueCode, info.MTime, userInfo.UserName);
  80. dt = DBHelper.SQlReturnData(sql, cmd);
  81. if (dt.Rows.Count <= 0 || dt == null)
  82. throw new Exception("委外发料单:" + info.IssueCode + ",无信息!");
  83. if (dtNew == null)
  84. dtNew = dt;
  85. else
  86. dtNew.Merge(dt);
  87. }
  88. cmd.Transaction.Commit();
  89. }
  90. catch (Exception ex)
  91. {
  92. cmd.Transaction.Rollback();
  93. log.Error(ex.Message);
  94. throw new Exception(ex.Message);
  95. }
  96. finally
  97. {
  98. if (conn.State == ConnectionState.Open)
  99. {
  100. conn.Close();
  101. }
  102. conn.Dispose();
  103. }
  104. }
  105. json = JsonConvert.SerializeObject(dtNew);
  106. return json;
  107. }
  108. public string CreateOutsourcingIssueDoNegative(List<ICSOutsourcingIssueDoc> Bills)
  109. {
  110. string msg = "";
  111. string mocodeall = "";
  112. string sql = string.Empty;
  113. DataTable dt = null;
  114. DataSet ds = null;
  115. int isif = 0;
  116. string connS = "";
  117. int num = 0;
  118. //取得out库单的默认显示模版
  119. //取得采购入库单单据 表头ID,表体DID
  120. VouchKey key = new VouchKey();
  121. SqlConnection conn = new SqlConnection();
  122. SqlCommand cmd = new SqlCommand();
  123. if (Bills.Count <= 0)
  124. {
  125. throw new Exception("传送数据为空!");
  126. }
  127. LogInfo(Bills);
  128. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  129. foreach (string WorkPoint in result)
  130. {
  131. try
  132. {
  133. connS = string.Format(connString, WorkPoint);
  134. conn = new System.Data.SqlClient.SqlConnection(connS);
  135. conn.Open();
  136. SqlTransaction sqlTran = conn.BeginTransaction();
  137. cmd = new SqlCommand();
  138. cmd.Transaction = sqlTran;
  139. cmd.Connection = conn;
  140. foreach (ICSOutsourcingIssueDoc head in Bills)
  141. {
  142. string mocode = "";
  143. string seq = "";
  144. string iFatherIdTwo = "";
  145. if (WorkPoint != head.WorkPoint)
  146. continue;
  147. string[] ss = head.WorkPoint.Split('_');
  148. ERPDB = ss[1];
  149. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  150. throw new Exception("U8正在整理现存量,请稍后再试");
  151. ICSUserInfo userInfo = new ICSUserInfo();
  152. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  153. if (head.details.Count <= 0)
  154. {
  155. throw new Exception("表体信息不存在!");
  156. }
  157. if (head.SourceType == "委外领料申请单")
  158. {
  159. #region 判断物料是否超额领取
  160. foreach (ICSOutsourcingIssueDocs body in head.details)
  161. {
  162. sql = @"SELECT isnull(fOutQuantity,0) as fOutQuantity,iQuantity FROM dbo.MaterialAppVouchs WHERE AutoID='" + body.SourceDetailID + "'";
  163. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  164. if (dtQty != null && dtQty.Rows.Count > 0)
  165. {
  166. //已领数量
  167. decimal IssQty = Convert.ToDecimal(dtQty.Rows[0]["fOutQuantity"]);
  168. //应领数量
  169. decimal Qty = Convert.ToDecimal(dtQty.Rows[0]["iQuantity"]);
  170. if (IssQty - body.Quantity < 0)
  171. {
  172. throw new Exception("物料领取小于当前可领用最大数,单据号:" + head.SourceCode + ",行号:" + body.Sequence + "");
  173. }
  174. }
  175. else
  176. {
  177. throw new Exception("领料申请单不存在!单据号:" + head.SourceCode);
  178. }
  179. }
  180. #endregion
  181. #region 现存量是否够领
  182. // //if (head.IsReturn != "1")
  183. // //{
  184. // foreach (rdrecords11 body in head.rdcords)
  185. // {
  186. // sql = string.Format(@"SELECT iQuantity FROM dbo.CurrentStock
  187. // WHERE cInvCode='{0}' AND cWhCode='{1}'", body.cInvCode, head.cWhCode);
  188. // if (!string.IsNullOrWhiteSpace(body.cBatch))
  189. // sql += " and cBatch='" + body.cBatch + "'";
  190. // DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  191. // decimal qtyCurrent = 0;
  192. // if (dt != null && dt.Rows.Count > 0)
  193. // {
  194. // qtyCurrent = Convert.ToDecimal(dt.Rows[0][0]);
  195. // if (qtyCurrent < body.Quantity)
  196. // {
  197. // throw new Exception("物料编号:" + body.cInvCode + ",现存量不足!");
  198. // }
  199. // }
  200. // else
  201. // {
  202. // throw new Exception("该物料:" + body.cInvCode + "在U8中仓库:" + head.cWhCode + "中不存在!");
  203. // }
  204. // }
  205. // //}
  206. #endregion
  207. }
  208. else
  209. {
  210. #region 判断委外订单是否已关闭
  211. sql = @"SELECT distinct isnull(b.cbCloser,'') as CloseUser
  212. from dbo.OM_MOMaterials a
  213. INNER JOIN OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  214. where a.MOMaterialsID='" + head.details[0].SourceDetailID + "'";
  215. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  216. if (dtClose != null && dtClose.Rows.Count > 0)
  217. {
  218. if (!string.IsNullOrEmpty(dtClose.Rows[0][0].ToString()))
  219. {
  220. throw new Exception("该委外订单行已关闭,无法领料!");
  221. }
  222. }
  223. #endregion
  224. #region 判断物料是否超额领取
  225. foreach (ICSOutsourcingIssueDocs body in head.details)
  226. {
  227. sql = @"SELECT isnull(b.fOutExcess,0) as fOutExcess,isnull(a.iSendQTY,0) as IssQty,a.iQuantity
  228. FROM dbo.OM_MOMaterials a
  229. LEFT JOIN dbo.Inventory b ON a.cInvCode=b.cInvCode
  230. WHERE a.MOMaterialsID='" + body.SourceDetailID + "'";
  231. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  232. if (dtQty != null && dtQty.Rows.Count > 0)
  233. {
  234. //可超领比率
  235. decimal fOutExcess = Convert.ToDecimal(dtQty.Rows[0]["fOutExcess"]);
  236. //已领数量
  237. decimal IssQty = Convert.ToDecimal(dtQty.Rows[0]["IssQty"]);
  238. //应领数量
  239. decimal Qty = Convert.ToDecimal(dtQty.Rows[0]["iQuantity"]);
  240. //当前可总领数量
  241. decimal TotalQty = Qty + fOutExcess * Qty;
  242. //if (head.IsReturn != "1")
  243. //{
  244. if (IssQty - body.Quantity < 0)
  245. {
  246. throw new Exception("物料退料数量超过当前已领用数量,AllocateId:" + body.SourceDetailID);
  247. }
  248. //}
  249. //else
  250. //{
  251. //if (IssQty - body.Quantity < 0)
  252. //{
  253. // throw new Exception("物料退料超过当前已领用最大数,AllocateId:" + body.SourceDetailID);
  254. //}
  255. //}
  256. }
  257. else
  258. {
  259. throw new Exception("委外订单行子件不存在!AllocateId:" + body.SourceDetailID);
  260. }
  261. }
  262. #endregion
  263. }
  264. #region 委外退料表头
  265. num = head.details.Count();
  266. string[] dd = CRNALL.Split('~');
  267. string crdname = dd[0];
  268. string carname = dd[1];
  269. string surface = dd[2];
  270. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  271. //取得out库单的默认显示模版
  272. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  273. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  274. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  275. DateTime date = DateTime.Now;
  276. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  277. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", cRDcode, head.WorkPoint);
  278. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  279. if (head.SourceType != "委外领料申请单")
  280. {
  281. mocodeall = head.SourceCode;
  282. sql = @"
  283. INSERT INTO dbo.rdrecord11
  284. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,
  285. cWhCode ,dDate ,cCode ,cRdCode ,cDepCode,
  286. cPersonCode,cHandler ,bTransFlag ,cMaker ,dVeriDate ,
  287. bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cPsPcode ,
  288. cMPoCode ,iproorderid ,bFromPreYear ,bIsLsQuery ,bIsComplement ,
  289. iDiscountTaxType ,ireturncount ,iverifystate ,iswfcontrolled ,dnmaketime ,
  290. dnverifytime ,bredvouch ,iPrintCount,cVenCode,iMQuantity)
  291. SELECT distinct @ID,0,'11','','',
  292. @cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,c.cDepCode,
  293. c.cPersonCode,@cHandler,0,@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),
  294. 0,0,@VT_ID,0,null,
  295. c.cCode,a.MoId,0,0,0,
  296. 0,0,0,0,GETDATE(),
  297. GETDATE(),@bredvouch,0,c.cVenCode,null
  298. from dbo.OM_MOMaterials a
  299. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  300. LEFT JOIN dbo.OM_MOMain c ON b.MOID = c.MOID
  301. WHERE c.cCode='" + head.SourceCode + "'";
  302. cmd.Parameters.Clear();
  303. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  304. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  305. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  306. cmd.Parameters.Add(new SqlParameter("@cHandler", userInfo.UserName));
  307. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  308. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  309. cmd.Parameters.Add(new SqlParameter("@bredvouch", "0"));
  310. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  311. cmd.CommandText = sql;
  312. }
  313. else
  314. {
  315. sql = @"select DISTINCT comcode from MaterialAppVouch a
  316. left join MaterialAppVouchs b on a.ID=b.ID where csource is not null
  317. and ccode='" + head.SourceCode + "'";
  318. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  319. if (dtQty != null && dtQty.Rows.Count > 0)
  320. {
  321. foreach (DataRow item in dtQty.Rows)
  322. {
  323. mocodeall = item["comcode"].ToString();
  324. }
  325. }
  326. sql = @"INSERT INTO dbo.rdrecord11
  327. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cBusCode ,cWhCode ,cMPoCode,
  328. dDate ,cCode ,cRdCode ,cDepCode ,cPersonCode ,cHandler ,cMemo ,
  329. bTransFlag ,cMaker ,cDefine1 ,cDefine2 ,cDefine3 ,cDefine4 ,
  330. cDefine5 ,cDefine6 ,cDefine7 ,cDefine8 ,cDefine9 ,cDefine10 ,
  331. dVeriDate ,bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cDefine11 ,
  332. cDefine12 ,cDefine13 ,cDefine14 ,cDefine15 ,cDefine16 ,
  333. bOMFirst ,bFromPreYear ,bIsComplement ,iDiscountTaxType ,
  334. ireturncount ,iverifystate ,iswfcontrolled ,cModifyPerson ,
  335. dnmaketime ,dnverifytime ,bredvouch ,bmotran ,bHYVouch ,iPrintCount
  336. )
  337. SELECT distinct @ID,0,'11','','',a.cCode,@cWhCode,comcode,
  338. CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRdCode,a.cDepCode,a.cPersonCode,@cHandler,a.cMemo,
  339. 0,@cMaker,a.cDefine1,cdefine2,a.cDefine3,a.cDefine4,
  340. a.cDefine5,a.cDefine6,a.cDefine7,a.cDefine8,a.cDefine9,a.cDefine10,
  341. CONVERT(NVARCHAR(15),GETDATE(),23),0,0,@VT_ID,0,a.cDefine11,
  342. a.cDefine12,a.cDefine13,a.cDefine14,a.cDefine15,a.cDefine16,
  343. 0,0,0,0,
  344. 0,0,0,'',
  345. GETDATE(),GETDATE(),0,0,0,0
  346. FROM dbo.MaterialAppVouch a
  347. LEFT JOIN dbo.MaterialAppVouchs B ON A.ID=B.ID
  348. WHERE a.cCode='" + head.SourceCode + "'";
  349. cmd.Parameters.Clear();
  350. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  351. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  352. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  353. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  354. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  355. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  356. cmd.Parameters.Add(new SqlParameter("@cRdCode", cRDcode));
  357. //DBHelper.CmdExecuteNonQuery(sql, cmd, "生成材料出库单表头失败!");
  358. cmd.CommandText = sql;
  359. }
  360. try
  361. {
  362. int count = cmd.ExecuteNonQuery();
  363. if (count <= 0)
  364. {
  365. log.Error("生成材料出库单表头失败,受影响行数<=0;");
  366. throw new Exception("生成材料出库单表头失败,受影响行数<=0;");
  367. }
  368. }
  369. catch (Exception ex)
  370. {
  371. log.Error("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  372. throw new Exception("生成材料出库单表头失败!SQL:\r\n" + sql, ex);
  373. }
  374. #endregion
  375. #region 委外退料表体
  376. string iNQuantity = "";
  377. int irowno = 0;
  378. foreach (ICSOutsourcingIssueDocs body in head.details)
  379. {
  380. sql = @"SELECT b.cCode,a.iVouchRowNo FROM dbo.OM_MODetails a INNER JOIN
  381. dbo.OM_MOMain b ON b.MoId = a.MoId WHERE a.MODetailsID =(select a.MODetailsID from OM_MODetails a left join
  382. OM_MOMaterials b on a.MoDetailsID=b.MODetailsID where b.MOMaterialsID='" + body.SourceDetailID + @"'
  383. )";
  384. DataTable dtCheck = DBHelper.SQlReturnData(sql, cmd);
  385. if (dtCheck != null && dtCheck.Rows.Count > 0)
  386. {
  387. mocode = dtCheck.Rows[0]["cCode"].ToString();
  388. seq = dtCheck.Rows[0]["iVouchRowNo"].ToString();
  389. sql = @" select
  390. count(c.MOMaterialsID) num,d.number
  391. from DBO.OM_MOMain a
  392. left join DBO.OM_MODetails b on a.moid = b.moid
  393. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  394. left join(select MODetailsID,COUNT(MOMaterialsID) number from DBO.OM_MOMaterials where iWIPtype=1 GROUP BY MODetailsID
  395. ) d on b.MODetailsID = d.MODetailsID
  396. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  397. GROUP BY d.number ";
  398. sql = string.Format(sql, mocode, seq);
  399. dtCheck = DBHelper.SQlReturnData(sql, cmd);
  400. if (dtCheck != null && dtCheck.Rows.Count > 0)
  401. {
  402. if (dtCheck.Rows[0]["num"].ToString() != dtCheck.Rows[0]["number"].ToString())
  403. {
  404. isif = 1;
  405. }
  406. else
  407. {
  408. isif = 0;
  409. }
  410. }
  411. }
  412. irowno++;
  413. body.Quantity = -body.Quantity;
  414. iNQuantity = "-a.iQuantity";
  415. if (head.SourceType != "委外领料申请单")
  416. {
  417. sql = @"INSERT INTO dbo.rdrecords11
  418. ( AutoID,ID ,cInvCode,iQuantity ,cBatch ,iNum,
  419. iFlag ,cItemCode ,cName ,iNQuantity ,iMPoIds ,
  420. bLPUseFree ,iOriTrackID ,bCosting ,bVMIUsed ,cmocode ,
  421. invcode ,imoseq ,iopseq ,iExpiratDateCalcu ,iorderdid ,
  422. iordertype ,isotype ,ipesodid ,ipesotype ,cpesocode ,
  423. ipesoseq ,irowno ,bcanreplace ,iposflag,iOMoDID,
  424. iOMoMID,comcode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  425. SELECT distinct
  426. @AutoID,@ID,a.cInvCode,@iQuantity,@cBatch,@iNum,
  427. 0,null,null,@iQuantity,NULL,
  428. 0,0,1,0,NULL,
  429. b.cInvCode,NULL,NULL,0,0,
  430. 0,0,a.MOMaterialsID,'6',c.cCode,
  431. NULL, @irowno,0,NULL,b.MODetailsID,
  432. a.MOMaterialsID,c.cCode,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  433. FROM dbo.OM_MOMaterials a
  434. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID=b.MODetailsID
  435. INNER JOIN dbo.OM_MOMain c ON b.MOID=c.MOID
  436. WHERE a.MOMaterialsID='" + body.SourceDetailID + "'";
  437. cmd.Parameters.Clear();
  438. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  439. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  440. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  441. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount.ToString("0.00")));
  442. //cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  443. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  444. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  445. cmd.Parameters.Add(new SqlParameter("@iNQuantity", iNQuantity));
  446. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  447. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  448. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  449. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  450. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  451. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  452. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  453. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  454. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  455. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  456. cmd.CommandText = sql;
  457. }
  458. else
  459. {
  460. sql = @"SELECT isnull(fOutQuantity,0) as fOutQuantity,iQuantity from MaterialAppVouchs a where a.AutoID='" + body.SourceDetailID + "' ";
  461. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  462. if (dtClose != null && dtClose.Rows.Count > 0)
  463. {
  464. if (Convert.ToDecimal(dtClose.Rows[0][0].ToString()) + body.Quantity > Convert.ToDecimal(dtClose.Rows[0][1].ToString()))
  465. {
  466. throw new Exception("退料数量不能大于领料单的已出数量!");
  467. }
  468. }
  469. sql = @"INSERT INTO dbo.rdrecords11
  470. ( AutoID ,ID ,cInvCode ,iQuantity ,iFlag ,cDefine22 ,iOMoDID,iOMoMID,iNum,
  471. cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,cDefine27 ,
  472. cItem_class ,cItemCode ,cName ,cItemCName ,iNQuantity ,
  473. cDefine28 ,cDefine29 ,cDefine30 ,cDefine31 ,cDefine32 ,
  474. cDefine33 ,cDefine34 ,cDefine35 ,cDefine36 ,cDefine37 ,
  475. bLPUseFree ,iOriTrackID ,bCosting ,bVMIUsed ,iMaIDs ,
  476. iExpiratDateCalcu ,iordertype ,isotype ,ipesotype ,irowno,
  477. cBatch,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  478. SELECT @AutoID,@ID,a.cInvCode,@iQuantity,0,a.cDefine22,a.iOMoDID,a.iOMoMID,@iNum,
  479. a.cDefine23,a.cDefine24,a.cDefine25,a.cDefine26,a.cDefine27,
  480. a.cItem_class,@cItemCode,a.cName,a.cItemCName,@iQuantity,
  481. a.cDefine28,a.cDefine29,a.cDefine30,a.cDefine31,a.cDefine32,
  482. a.cDefine33,a.cDefine34,a.cDefine35,a.cDefine36,a.cDefine37,
  483. 0,0,1,0,a.AutoID,
  484. 0,0,0,0,@irowno,
  485. @cBatch,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  486. FROM dbo.MaterialAppVouchs a WHERE a.AutoID='" + body.SourceDetailID + "'";
  487. cmd.Parameters.Clear();
  488. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  489. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  490. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  491. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount.ToString("0.00")));
  492. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  493. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  494. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  495. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  496. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  497. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  498. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  499. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  500. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  501. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  502. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  503. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  504. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  505. //DBHelper.CmdExecuteNonQuery(sql, cmd, "生成材料出库单表头失败!");
  506. cmd.CommandText = sql;
  507. }
  508. try
  509. {
  510. int count = cmd.ExecuteNonQuery();
  511. if (count <= 0)
  512. {
  513. log.Error("生产退料单表体失败,受影响行数<=0;");
  514. throw new Exception("生产退料单表体失败,受影响行数<=0;");
  515. }
  516. }
  517. catch (Exception ex)
  518. {
  519. log.Error("生产退料单表体失败" + sql, ex);
  520. throw new Exception("生产退料单表体失败 " + sql, ex);
  521. }
  522. if (isif == 1)
  523. {
  524. if (head.CompleteVerification)
  525. {
  526. #region 齐套检验
  527. sql = @" select cValue from AccInformation where cName=N'iMOProInCtrlBySet' ";
  528. DataTable qt = DBHelper.SQlReturnData(sql, cmd);
  529. if (qt != null && qt.Rows.Count > 0)
  530. {
  531. if (qt.Rows[0]["cValue"].ToString() == "1")
  532. {
  533. sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
  534. (
  535. select
  536. a.cCode,b.iVouchRowNo,
  537. c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty
  538. from DBO.OM_MOMain a
  539. left join DBO.OM_MODetails b on a.moid = b.moid
  540. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  541. left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode
  542. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  543. and c.iQuantity<>0 and c.iWIPtype<>1
  544. group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity
  545. ) tt
  546. group by cCode,iVouchRowNo";
  547. sql = string.Format(sql, mocodeall, seq);
  548. qt = DBHelper.SQlReturnData(sql, cmd);
  549. if (qt == null || qt.Rows.Count == 0)
  550. {
  551. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  552. }
  553. else
  554. {
  555. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  556. {
  557. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料<=0!");
  558. }
  559. }
  560. }
  561. else if (qt.Rows[0]["cValue"].ToString() == "2")
  562. {
  563. sql = @"select cValue from AccInformation where cName=N'bControlKeyMaterial'";
  564. qt = DBHelper.SQlReturnData(sql, cmd);
  565. if (qt != null && qt.Rows.Count > 0)
  566. {
  567. if (qt.Rows[0]["cValue"].ToString() == "true")
  568. {
  569. sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
  570. (
  571. select
  572. a.cCode,b.iVouchRowNo,
  573. c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty
  574. from DBO.OM_MOMain a
  575. left join DBO.OM_MODetails b on a.moid = b.moid
  576. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  577. left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode
  578. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  579. and c.iQuantity<>0 and c.iWIPtype<>1
  580. group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity
  581. ) tt
  582. group by cCode,iVouchRowNo";
  583. sql = string.Format(sql, mocodeall, seq);
  584. qt = DBHelper.SQlReturnData(sql, cmd);
  585. if (qt == null || qt.Rows.Count == 0)
  586. {
  587. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  588. }
  589. else
  590. {
  591. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  592. {
  593. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  594. }
  595. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  596. {
  597. throw new Exception("该物料:" + body.InvCode + @"入库数量大于关键物料领料套数!");
  598. }
  599. }
  600. }
  601. else
  602. {
  603. sql = @"select cCode,iVouchRowNo,MIN(lotqty) min_lotqty from
  604. (
  605. select
  606. a.cCode,b.iVouchRowNo,
  607. c.MOMaterialsID as AllocateId,sum(c.iQuantity) as Qty,SUM(c.iSendQTY) IssQty,SUM(c.iSendQTY)/(SUM(c.iQuantity)/b.iQuantity) lotqty
  608. from DBO.OM_MOMain a
  609. left join DBO.OM_MODetails b on a.moid = b.moid
  610. left join DBO.OM_MOMaterials c on b.MODetailsID = c.MODetailsID
  611. left join DBO.Inventory_Sub f on c.cInvCode=f.cInvSubCode
  612. where a.cCode='{0}' and b.iVouchRowNo='{1}'
  613. and c.iQuantity<>0 and c.iWIPtype<>1
  614. group by a.cCode,b.iVouchRowNo,c.MOMaterialsID,b.iQuantity
  615. ) tt
  616. group by cCode,iVouchRowNo";
  617. sql = string.Format(sql, mocodeall, seq);
  618. qt = DBHelper.SQlReturnData(sql, cmd);
  619. if (qt == null || qt.Rows.Count == 0)
  620. {
  621. throw new Exception("该物料:" + body.InvCode + @"在订单内未有可用领料!");
  622. }
  623. else
  624. {
  625. if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) <= 0)
  626. {
  627. throw new Exception("该物料:" + body.InvCode + @"在订单内未领料!");
  628. }
  629. else if (Convert.ToDecimal(qt.Rows[0]["min_lotqty"]) - body.Quantity <= 0)
  630. {
  631. throw new Exception("该物料:" + body.InvCode + @"入库数量大于领料套数!");
  632. }
  633. }
  634. }
  635. }
  636. }
  637. }
  638. #endregion
  639. }
  640. }
  641. if (head.SourceType != "委外领料申请单")
  642. {
  643. #region 回写工单子件已领数量
  644. sql = "update OM_MOMaterials set iSendQTY=isnull(iSendQTY,0)+" + body.Quantity + ",fsendapplyqty=isnull(fsendapplyqty,0)+" + body.Quantity + @" where MOMaterialsID='" + body.SourceDetailID + "' ";
  645. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写委外订单子件已领数量失败!");
  646. #endregion
  647. }
  648. else
  649. {
  650. #region 回写工单子件已领数量
  651. sql = "update OM_MOMaterials set iSendQTY=isnull(iSendQTY,0)+" + body.Quantity + @",fsendapplyqty=isnull(fsendapplyqty,0)+" + body.Quantity + @" where MOMaterialsID=(select iOMoMID from MaterialAppVouchs where AutoID='" + body.SourceDetailID + @"')
  652. update MaterialAppVouchs set fOutQuantity=isnull(fOutQuantity,0)+" + body.Quantity + @" where AutoID='" + body.SourceDetailID + @"'
  653. ";
  654. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写委外订单子件已领数量失败!");
  655. #endregion
  656. }
  657. if (head.SourceType != "委外领料申请单")
  658. {
  659. sql = @"select isnull(iSendQTY,0)fOutQuantity,isnull(iQuantity,0)iQuantity,ISNULL(iNum, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(iNum, 0)-ISNULL(NiNum, 0) SiNum from OM_MOMaterials a
  660. LEFT JOIN (select sum(iNum) NiNum,iOMoMID from rdrecords11 GROUP BY iOMoMID) b on a.MOMaterialsID=b.iOMoMID
  661. where a.MOMaterialsID='" + body.SourceDetailID + "'";
  662. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  663. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  664. {
  665. foreach (DataRow item in dtDisCheck.Rows)
  666. {
  667. if (Convert.ToDecimal(item["fOutQuantity"].ToString()) == Convert.ToDecimal(item["iQuantity"].ToString()))
  668. {
  669. if (Convert.ToDecimal(item["iNum"].ToString()) != 0)
  670. {
  671. if (Convert.ToDecimal(item["SiNum"].ToString()) != 0)
  672. {
  673. sql = @"Update rdrecords11 set iNum=isnull(iNum,0)+(" + item["SiNum"].ToString() + ") where autoid='" + iChildId + "' ";
  674. body.Amount = (Convert.ToDecimal(body.Amount.ToString("0.00"))) + (Convert.ToDecimal(item["SiNum"].ToString()));
  675. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  676. }
  677. }
  678. }
  679. }
  680. }
  681. }
  682. else
  683. {
  684. sql = @"select isnull(fOutQuantity,0)fOutQuantity,isnull(iQuantity,0)iQuantity,ISNULL(iNum, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(iNum, 0)-ISNULL(NiNum, 0) SiNum from MaterialAppVouchs a
  685. LEFT JOIN (select sum(iNum) NiNum,iMaIDs from rdrecords11 GROUP BY iMaIDs) b on a.AutoID=b.iMaIDs
  686. where a.AutoID='" + body.SourceDetailID + "'";
  687. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  688. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  689. {
  690. foreach (DataRow item in dtDisCheck.Rows)
  691. {
  692. if (Convert.ToDecimal(item["fOutQuantity"].ToString()) == Convert.ToDecimal(item["iQuantity"].ToString()))
  693. {
  694. if (Convert.ToDecimal(item["iNum"].ToString()) != 0)
  695. {
  696. if (Convert.ToDecimal(item["SiNum"].ToString()) != 0)
  697. {
  698. sql = @"Update rdrecords11 set iNum=isnull(iNum,0)+(" + item["SiNum"].ToString() + ") where autoid='" + iChildId + "' ";
  699. body.Amount = (Convert.ToDecimal(body.Amount.ToString("0.00"))) + (Convert.ToDecimal(item["SiNum"].ToString()));
  700. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  701. }
  702. }
  703. }
  704. }
  705. }
  706. }
  707. //更新现存量
  708. key.cBustypeUN = "委外发料";
  709. key.cVouchTypeUN = "11";
  710. key.TableName = "IA_ST_UnAccountVouch11";
  711. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", -body.Quantity, key);
  712. //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);
  713. DBHelper.UpdateCurrentStockCCGC(cmd, body.InvCode, head.WHCode, body.BatchCode, -body.Quantity, -body.Amount, body.cFree1,
  714. body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10,
  715. "", key, "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, iFatherId, iChildId);
  716. iFatherIdTwo = "'" + iFatherId + "',";
  717. iChildId--;
  718. }
  719. #endregion
  720. #region 查询
  721. sql = @"select DISTINCT a.ID as ID,a.ID as IDs,a.cCode as IssueNEGCode,a.cDepCode,c.cDepName,a.cWhCode,
  722. d.cWhName,a.cSource,cMPoCode,a.cMaker,dnmaketime,cHandler,dnverifytime
  723. from rdrecord11 a
  724. left join Department c on a.cDepCode=c.cDepCode
  725. left join Warehouse d on a.cWhCode=d.cWhCode
  726. where a.cBusType='' and a.ID in ({0})
  727. select DISTINCT a.ID as IDs,(case when isnull(f.AutoID,'')='' then h.MOMaterialsID else f.AutoID end) as SourceDetailID,b.irowno as Sequence ,b.iordercode,b.cInvCode,b.iQuantity,b.iNum,b.AutoID as DetailID
  728. ,isnull(b.cItemCode,'') ProjectCode,isnull(b.cbatch,'') cBatch,'' version ,'' brand,
  729. isnull(b.cFree1,'') as cFree1,
  730. isnull(b.cFree2,'') as cFree2,
  731. isnull(b.cFree3,'') as cFree3,
  732. isnull(b.cFree4,'') as cFree4,
  733. isnull(b.cFree5,'') as cFree5,
  734. isnull(b.cFree6,'') as cFree6,
  735. isnull(b.cFree7,'') as cFree7,
  736. isnull(b.cFree8,'') as cFree8,
  737. isnull(b.cFree9,'') as cFree9,
  738. isnull(b.cFree10,'') as cFree10
  739. from rdrecord11 a
  740. left join rdrecords11 b on a.ID=b.ID
  741. left join Department c on a.cDepCode=c.cDepCode
  742. left join Warehouse d on a.cWhCode=d.cWhCode
  743. left join OM_MOMaterials h on b.iOMoMID=h.MOMaterialsID
  744. left join MaterialAppVouchs f on b.iMaIDs=f.autoid
  745. where a.cBusType='' and a.ID in ({0})";
  746. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  747. if (ds != null)
  748. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  749. else
  750. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  751. // sql = @" select a.ID as ID,iMPoIds,iordercode,a.cCode,a.cDepCode,c.cDepName,a.cWhCode,
  752. // d.cWhName,a.cSource,a.cMaker,dnmaketime,cHandler,dnverifytime,cSourceCodeLs,
  753. // b.AutoID ,b.irowno,b.cInvCode,b.iQuantity,e.MoDetailsID,b.iNum,e.csocode
  754. // from rdrecord11 a
  755. // left join rdrecords11 b on a.ID=b.ID
  756. // left join Department c on a.cDepCode=c.cDepCode
  757. // left join Warehouse d on a.cWhCode=d.cWhCode
  758. // left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  759. // where a.cBusType='委外发料'and b.iQuantity<0 and a.ID in ({0})";
  760. // sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  761. // dt = DBHelper.SQlReturnData(sql, cmd);
  762. #endregion
  763. }
  764. cmd.Transaction.Commit();
  765. }
  766. catch (Exception ex)
  767. {
  768. cmd.Transaction.Rollback();
  769. log.Error(ex.Message);
  770. throw new Exception(ex.Message);
  771. }
  772. finally
  773. {
  774. if (conn.State == ConnectionState.Open)
  775. {
  776. conn.Close();
  777. }
  778. conn.Dispose();
  779. }
  780. }
  781. msg = JSON.DataSetToJson(ds, "details", "IDs");
  782. return msg;
  783. }
  784. public string Approve(List<ICSOutsourcingIssueDoc> infos)
  785. {
  786. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  787. string connS = "";
  788. string json = "";
  789. if (infos.Count <= 0)
  790. {
  791. throw new Exception("传送数据为空!");
  792. }
  793. string res = string.Empty;
  794. SqlConnection conn = new SqlConnection();
  795. SqlCommand cmd = new SqlCommand();
  796. string sql = string.Empty;
  797. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  798. foreach (string WorkPoint in result)
  799. {
  800. try
  801. {
  802. connS = string.Format(connString, WorkPoint);
  803. conn = new System.Data.SqlClient.SqlConnection(connS);
  804. conn.Open();
  805. SqlTransaction sqlTran = conn.BeginTransaction();
  806. cmd = new SqlCommand();
  807. cmd.Transaction = sqlTran;
  808. cmd.Connection = conn;
  809. foreach (ICSOutsourcingIssueDoc info in infos)
  810. {
  811. if (WorkPoint != info.WorkPoint)
  812. continue;
  813. ICSUserInfo userInfo = new ICSUserInfo();
  814. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  815. if (info.MTime < new DateTime(2000, 01, 01))
  816. throw new Exception("请输入正确的操作时间:" + info.MTime);
  817. sql = @"UPDATE dbo.rdrecord11 SET cHandler ='" + userInfo.UserName + @"' ,
  818. dnmodifytime =CONVERT(VARCHAR(50),GETDATE(),112),dModifyDate =GETDATE() WHERE ID='{0}'";
  819. sql = string.Format(sql, info.ID);
  820. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  821. }
  822. cmd.Transaction.Commit();
  823. }
  824. catch (Exception ex)
  825. {
  826. cmd.Transaction.Rollback();
  827. log.Error(ex.Message);
  828. throw new Exception(ex.Message);
  829. }
  830. finally
  831. {
  832. if (conn.State == ConnectionState.Open)
  833. {
  834. conn.Close();
  835. }
  836. conn.Dispose();
  837. }
  838. }
  839. return json;
  840. }
  841. /// <summary>
  842. /// 删除请购单
  843. /// </summary>
  844. /// <param name="infos"></param>
  845. /// <returns></returns>
  846. public string Delete(List<ICSOutsourcingIssueDoc> infos)
  847. {
  848. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  849. if (infos.Count <= 0)
  850. {
  851. throw new Exception("传送数据为空!");
  852. }
  853. DataTable dtNew = null;
  854. string connS = "";
  855. string res = string.Empty;
  856. SqlConnection conn = new SqlConnection();
  857. SqlCommand cmd = new SqlCommand();
  858. string sql = string.Empty;
  859. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  860. foreach (string WorkPoint in result)
  861. {
  862. try
  863. {
  864. connS = string.Format(connString, WorkPoint);
  865. conn = new System.Data.SqlClient.SqlConnection(connS);
  866. conn.Open();
  867. SqlTransaction sqlTran = conn.BeginTransaction();
  868. cmd = new SqlCommand();
  869. cmd.Transaction = sqlTran;
  870. cmd.Connection = conn;
  871. foreach (ICSOutsourcingIssueDoc info in infos)
  872. {
  873. if (WorkPoint != info.WorkPoint)
  874. continue;
  875. if (info.MTime < new DateTime(2000, 01, 01))
  876. throw new Exception("请输入正确的操作时间:" + info.MTime);
  877. sql = @" DELETE dbo.rdrecord11 WHERE ID='{0}'";
  878. sql = string.Format(sql, info.ID);
  879. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  880. }
  881. cmd.Transaction.Commit();
  882. }
  883. catch (Exception ex)
  884. {
  885. cmd.Transaction.Rollback();
  886. log.Error(ex.Message);
  887. throw new Exception(ex.Message);
  888. }
  889. finally
  890. {
  891. if (conn.State == ConnectionState.Open)
  892. {
  893. conn.Close();
  894. }
  895. conn.Dispose();
  896. }
  897. }
  898. return res;
  899. }
  900. /// <summary>
  901. ///
  902. /// 记录日志
  903. /// </summary>
  904. /// <param name="Bills"></param>
  905. private void LogInfo(List<ICSOutsourcingIssueDoc> Bills)
  906. {
  907. string HeadList = string.Empty;
  908. string BodyList = string.Empty;
  909. foreach (ICSOutsourcingIssueDoc head in Bills)
  910. {
  911. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  912. foreach (ICSOutsourcingIssueDocs body in head.details)
  913. {
  914. BodyList += "\r\n 表体主键ID: " + body.SourceDetailID + ",数量:" + body.Quantity;
  915. }
  916. }
  917. log.Info(HeadList);
  918. log.Info(BodyList);
  919. }
  920. }
  921. }