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

576 lines
28 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
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
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
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 OutsourcingIssueDoc
  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. string json = "";
  28. DataTable dtNew = null;
  29. string connS = "";
  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 (ICSOutsourcingIssueDoc 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 as ID,a.ID as IDs,a.cCode as IssueCode,a.cDepCode,c.cDepName,a.cWhCode,
  52. d.cWhName,a.cSource,cMPoCode,a.cMaker,dnmaketime,cHandler,dnverifytime
  53. from rdrecord11 a
  54. left join Department c on a.cDepCode=c.cDepCode
  55. left join Warehouse d on a.cWhCode=d.cWhCode
  56. where a.cBusType=''
  57. select a.ID as IDs,iMPoIds as SourceDetailID ,b.irowno as Sequence,iordercode,b.cInvCode,b.iQuantity,b.iNum,b.AutoID as DetailID
  58. from rdrecord11 a
  59. left join rdrecords11 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
  62. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  63. where a.cBusType=''";
  64. if (!string.IsNullOrWhiteSpace(info.IssueCode))
  65. {
  66. sql += " and a.cCode='{0}'";
  67. }
  68. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  69. {
  70. sql += " and ISNULL(a.dnmodifytime,ISNULL(a.dnverifytime, ISNULL(a.dnmodifytime, a.dnmaketime)))>='{1}'";
  71. }
  72. if (!string.IsNullOrWhiteSpace(info.User))
  73. {
  74. sql += "and a.CMAKER='{2}'";
  75. }
  76. sql = string.Format(sql, info.IssueCode, info.MTime, info.User);
  77. dt = DBHelper.SQlReturnData(sql, cmd);
  78. if (dt.Rows.Count <= 0 || dt == null)
  79. throw new Exception("委外发料单:" + info.IssueCode + ",无信息!");
  80. if (dtNew == null)
  81. dtNew = dt;
  82. else
  83. dtNew.Merge(dt);
  84. cmd.Transaction.Commit();
  85. }
  86. catch (Exception ex)
  87. {
  88. cmd.Transaction.Rollback();
  89. log.Error(ex.Message);
  90. throw new Exception(ex.Message);
  91. }
  92. finally
  93. {
  94. if (conn.State == ConnectionState.Open)
  95. {
  96. conn.Close();
  97. }
  98. conn.Dispose();
  99. }
  100. }
  101. json = JsonConvert.SerializeObject(dtNew);
  102. return json;
  103. }
  104. public string CreateOutsourcingIssueDoc(List<ICSOutsourcingIssueDoc> Bills)
  105. {
  106. string msg = "";
  107. string sql = string.Empty;
  108. DataTable dtNew1 = null;
  109. DataTable dtNew2 = null;
  110. string connS = "";
  111. int num = 0;
  112. //取得out库单的默认显示模版
  113. //取得采购入库单单据 表头ID,表体DID
  114. VouchKey key = new VouchKey();
  115. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  116. SqlCommand cmd = new SqlCommand();
  117. if (Bills.Count <= 0)
  118. {
  119. throw new Exception("传送数据为空!");
  120. }
  121. LogInfo(Bills);
  122. foreach (ICSOutsourcingIssueDoc head in Bills)
  123. {
  124. try
  125. {
  126. string iFatherIdTwo = "";
  127. connS = string.Format(connString, head.WorkPoint);
  128. conn = new System.Data.SqlClient.SqlConnection(connS);
  129. conn.Open();
  130. SqlTransaction sqlTran = conn.BeginTransaction();
  131. cmd = new SqlCommand();
  132. cmd.Transaction = sqlTran;
  133. cmd.Connection = conn;
  134. string[] ss = head.WorkPoint.Split('_');
  135. ERPDB = ss[1];
  136. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  137. {
  138. }
  139. else
  140. {
  141. throw new Exception("U8正在整理现存量,请稍后再试");
  142. }
  143. num = head.details.Count();
  144. string[] dd = CRNALL.Split('~');
  145. string crdname = dd[0];
  146. string carname = dd[1];
  147. string surface = dd[2];
  148. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  149. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  150. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  151. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  152. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  153. DateTime date = DateTime.Now;
  154. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  155. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  156. if (head.details.Count <= 0)
  157. {
  158. throw new Exception("表体信息不存在!");
  159. }
  160. #region 判断委外订单是否已关闭
  161. sql = @"SELECT distinct isnull(b.cbCloser,'') as CloseUser
  162. from dbo.OM_MOMaterials a
  163. INNER JOIN OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  164. where a.MOMaterialsID='" + head.details[0].SourceDetailID + "'";
  165. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  166. if (dtClose != null && dtClose.Rows.Count > 0)
  167. {
  168. if (!string.IsNullOrEmpty(dtClose.Rows[0][0].ToString()))
  169. {
  170. throw new Exception("该委外订单行已关闭,无法领料!");
  171. }
  172. }
  173. #endregion
  174. #region 判断物料是否超额领取
  175. foreach (ICSOutsourcingIssueDocs body in head.details)
  176. {
  177. sql = @"SELECT isnull(b.fOutExcess,0) as fOutExcess,isnull(a.iSendQTY,0) as IssQty,a.iQuantity
  178. FROM dbo.OM_MOMaterials a
  179. LEFT JOIN dbo.Inventory b ON a.cInvCode=b.cInvCode
  180. WHERE a.MOMaterialsID='" + body.SourceDetailID + "'";
  181. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  182. // if (dtQty != null && dtQty.Rows.Count > 0)
  183. // {
  184. // //可超领比率
  185. // decimal fOutExcess = Convert.ToDecimal(dtQty.Rows[0]["fOutExcess"]);
  186. // //已领数量
  187. // decimal IssQty = Convert.ToDecimal(dtQty.Rows[0]["IssQty"]);
  188. // //应领数量
  189. // decimal Qty = Convert.ToDecimal(dtQty.Rows[0]["iQuantity"]);
  190. // //当前可总领数量
  191. // decimal TotalQty = Qty + fOutExcess * Qty;
  192. // if (head.IsReturn != "1")
  193. // {
  194. // if (IssQty + body.Quantity > TotalQty)
  195. // {
  196. // throw new Exception("物料领取超过当前可领用最大数,AllocateId:" + body.SourceDetailID);
  197. // }
  198. // }
  199. // else
  200. // {
  201. // if (IssQty < body.Quantity)
  202. // {
  203. // throw new Exception("物料退料超过当前已领用最大数,AllocateId:" + body.SourceDetailID);
  204. // }
  205. // }
  206. // }
  207. // else
  208. // {
  209. // throw new Exception("委外订单行子件不存在!AllocateId:" + body.SourceDetailID);
  210. // }
  211. //}
  212. }
  213. #endregion
  214. #region 委外材料出库单表头
  215. sql = @"
  216. INSERT INTO dbo.rdrecord11
  217. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,
  218. cWhCode ,dDate ,cCode ,cRdCode ,cDepCode,
  219. cPersonCode,cHandler ,bTransFlag ,cMaker ,dVeriDate ,
  220. bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cPsPcode ,
  221. cMPoCode ,iproorderid ,bFromPreYear ,bIsLsQuery ,bIsComplement ,
  222. iDiscountTaxType ,ireturncount ,iverifystate ,iswfcontrolled ,dnmaketime ,
  223. dnverifytime ,bredvouch ,iPrintCount,cVenCode,iMQuantity)
  224. SELECT distinct @ID,0,'11','','',
  225. @cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRDcode,c.cDepCode,
  226. c.cPersonCode,@cHandler,0,@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),
  227. 0,0,@VT_ID,0,b.cInvCode,
  228. c.cCode,a.MoId,0,0,0,
  229. 0,0,0,0,GETDATE(),
  230. GETDATE(),0,0,c.cVenCode,b.iQuantity
  231. from dbo.OM_MOMaterials a
  232. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  233. LEFT JOIN dbo.OM_MOMain c ON b.MOID = c.MOID
  234. WHERE a.MOMaterialsID='" + head.details[0].SourceDetailID + "'";
  235. cmd.Parameters.Clear();
  236. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  237. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  238. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  239. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  240. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  241. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  242. cmd.Parameters.Add(new SqlParameter("@cRDcode", cRDcode));
  243. cmd.CommandText = sql;
  244. try
  245. {
  246. int count = cmd.ExecuteNonQuery();
  247. if (count <= 0)
  248. {
  249. log.Error("生成委外发料单表头失败,受影响行数<=0;");
  250. throw new Exception("生成委外发料单表头失败,受影响行数<=0;");
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. log.Error("生成委外发料单表头失败!SQL:\r\n" + sql, ex);
  256. throw new Exception("生成委外发料单表头失败!SQL:\r\n" + sql, ex);
  257. }
  258. #endregion
  259. #region 委外材料出库单表体
  260. string iNQuantity = "";
  261. foreach (ICSOutsourcingIssueDocs body in head.details)
  262. {
  263. //if (head.IsReturn == "1")
  264. //{
  265. // body.iQuantity = -body.iQuantity;
  266. // iNQuantity = "-a.iQuantity";
  267. //}
  268. //else
  269. //{
  270. iNQuantity = "a.iQuantity";
  271. //}
  272. //if (head.IsReturn == "0")
  273. //{
  274. // //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  275. // sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.cInvCode + "'AND cBatch='" + body.cBatch + "'and cWhCode='" + head.cWhCode + "'";
  276. // DataTable dtItem = U8Helper.SQlReturnData(sql, cmd);
  277. // if (dtItem != null && dtItem.Rows.Count > 0)
  278. // {
  279. // if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
  280. // {
  281. // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  282. // }
  283. // if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.iQuantity)
  284. // {
  285. // throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.cInvCode);
  286. // }
  287. // }
  288. // else
  289. // {
  290. // throw new Exception("物料:" + body.cInvCode + "在现存量表中不存在!");
  291. // }
  292. //}
  293. sql = @"INSERT INTO dbo.rdrecords11
  294. ( AutoID,ID ,cInvCode,iQuantity ,cBatch ,
  295. iFlag ,cItemCode ,cName ,iNQuantity ,iMPoIds ,
  296. bLPUseFree ,iOriTrackID ,bCosting ,bVMIUsed ,cmocode ,
  297. invcode ,imoseq ,iopseq ,iExpiratDateCalcu ,iorderdid ,
  298. iordertype ,isotype ,ipesodid ,ipesotype ,cpesocode ,
  299. ipesoseq ,irowno ,bcanreplace ,iposflag,iOMoDID,
  300. iOMoMID,comcode)
  301. SELECT distinct
  302. @AutoID,@ID,@InvCode,@iQuantity,@cBatch,
  303. 0,null,null,@iQuantity,NULL,
  304. 0,0,1,0,NULL,
  305. b.cInvCode,NULL,NULL,0,0,
  306. 0,0,a.MOMaterialsID,'6',c.cCode,
  307. NULL, @irowno,0,NULL,b.MODetailsID,
  308. a.MOMaterialsID,c.cCode
  309. FROM dbo.OM_MOMaterials a
  310. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID=b.MODetailsID
  311. INNER JOIN dbo.OM_MOMain c ON b.MOID=c.MOID
  312. WHERE a.MOMaterialsID='" + body.SourceDetailID + "'";
  313. cmd.Parameters.Clear();
  314. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  315. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  316. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  317. //cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  318. cmd.Parameters.Add(new SqlParameter("@InvCode", body.InvCode));
  319. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  320. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  321. cmd.Parameters.Add(new SqlParameter("@iNQuantity", iNQuantity));
  322. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  323. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  324. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  325. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  326. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  327. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  328. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  329. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  330. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  331. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  332. cmd.CommandText = sql;
  333. try
  334. {
  335. int count = cmd.ExecuteNonQuery();
  336. if (count <= 0)
  337. {
  338. log.Error("生成委外发料单表体失败,受影响行数<=0;");
  339. throw new Exception("生成委外发料单表体失败,受影响行数<=0;");
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. log.Error("生成委外发料单表体失败" + sql, ex);
  345. throw new Exception("生成委外发料单表体失败 " + sql, ex);
  346. }
  347. if (head.UpdateStock)
  348. {
  349. //更新现存量
  350. key.cBustypeUN = "委外发料";
  351. key.cVouchTypeUN = "11";
  352. key.TableName = "IA_ST_UnAccountVouch11";
  353. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", -body.Quantity, key);
  354. 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);
  355. }
  356. #region 回写工单子件已领数量
  357. sql = "update OM_MOMaterials set iSendQTY=isnull(iSendQTY,0)+" + body.Quantity + ",fsendapplyqty=isnull(fsendapplyqty,0)+" + body.Quantity + @" where MOMaterialsID='" + body.SourceDetailID + "' ";
  358. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写委外订单子件已领数量失败!");
  359. #endregion
  360. iFatherIdTwo += "'" + iFatherId + "',";
  361. iChildId--;
  362. }
  363. #endregion
  364. #region 查询
  365. sql = @"select a.ID as ID,a.ID as IDs,a.cCode as IssueCode,a.cDepCode,c.cDepName,a.cWhCode,
  366. d.cWhName,a.cSource,cMPoCode,a.cMaker,dnmaketime,cHandler,dnverifytime
  367. from rdrecord11 a
  368. left join Department c on a.cDepCode=c.cDepCode
  369. left join Warehouse d on a.cWhCode=d.cWhCode
  370. where a.cBusType=''and a.ID in ({0})
  371. select a.ID as IDs,iOMoMID as SourceDetailID ,b.irowno as Sequence,iordercode,b.cInvCode,b.iQuantity,b.iNum,b.AutoID as DetailID
  372. from rdrecord11 a
  373. left join rdrecords11 b on a.ID=b.ID
  374. left join Department c on a.cDepCode=c.cDepCode
  375. left join Warehouse d on a.cWhCode=d.cWhCode
  376. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  377. where a.cBusType=''and a.ID in ({0})";
  378. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  379. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  380. if (dtNew1 == null)
  381. dtNew1 = ds.Tables[0];
  382. else
  383. dtNew1.Merge(ds.Tables[0]);
  384. if (dtNew2 == null)
  385. dtNew2 = ds.Tables[1];
  386. else
  387. dtNew2.Merge(ds.Tables[1]);
  388. #endregion
  389. cmd.Transaction.Commit();
  390. }
  391. catch (Exception ex)
  392. {
  393. cmd.Transaction.Rollback();
  394. log.Error(ex.Message);
  395. throw new Exception(ex.Message);
  396. }
  397. finally
  398. {
  399. if (conn.State == ConnectionState.Open)
  400. {
  401. conn.Close();
  402. }
  403. conn.Dispose();
  404. }
  405. }
  406. string RelationName = "details";
  407. DataSet dz = new DataSet();
  408. dtNew1.TableName = "Table0";
  409. dtNew2.TableName = "Table1";
  410. dz.Tables.Add(dtNew1.Copy());
  411. dz.Tables.Add(dtNew2.Copy());
  412. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  413. dz.Relations.Add(dh);
  414. msg = DBHelper.DataSetToJson(dz, RelationName);
  415. return msg;
  416. }
  417. public string Approve(List<ICSOutsourcingIssueDoc> infos)
  418. {
  419. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  420. string connS = "";
  421. string json = "";
  422. if (infos.Count <= 0)
  423. {
  424. throw new Exception("传送数据为空!");
  425. }
  426. string res = string.Empty;
  427. SqlConnection conn = new SqlConnection();
  428. SqlCommand cmd = new SqlCommand();
  429. string sql = string.Empty;
  430. foreach (ICSOutsourcingIssueDoc info in infos)
  431. {
  432. try
  433. {
  434. connS = string.Format(connString, info.WorkPoint);
  435. conn = new System.Data.SqlClient.SqlConnection(connS);
  436. conn.Open();
  437. SqlTransaction sqlTran = conn.BeginTransaction();
  438. cmd = new SqlCommand();
  439. cmd.Transaction = sqlTran;
  440. cmd.Connection = conn;
  441. if (info.MTime < new DateTime(2000, 01, 01))
  442. throw new Exception("请输入正确的操作时间:" + info.MTime);
  443. sql = @"UPDATE dbo.rdrecord11 SET cHandler ='" + info.User + @"' ,
  444. dnmodifytime =CONVERT(VARCHAR(50),GETDATE(),112),dModifyDate =GETDATE() WHERE ID='{0}'";
  445. sql = string.Format(sql, info.ID);
  446. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  447. cmd.Transaction.Commit();
  448. }
  449. catch (Exception ex)
  450. {
  451. cmd.Transaction.Rollback();
  452. log.Error(ex.Message);
  453. throw new Exception(ex.Message);
  454. }
  455. finally
  456. {
  457. if (conn.State == ConnectionState.Open)
  458. {
  459. conn.Close();
  460. }
  461. conn.Dispose();
  462. }
  463. }
  464. return json;
  465. }
  466. /// <summary>
  467. /// 删除请购单
  468. /// </summary>
  469. /// <param name="infos"></param>
  470. /// <returns></returns>
  471. public string Delete(List<ICSOutsourcingIssueDoc> infos)
  472. {
  473. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  474. if (infos.Count <= 0)
  475. {
  476. throw new Exception("传送数据为空!");
  477. }
  478. string res = string.Empty;
  479. string connS = "";
  480. SqlConnection conn = new SqlConnection();
  481. SqlCommand cmd = new SqlCommand();
  482. string sql = string.Empty;
  483. foreach (ICSOutsourcingIssueDoc info in infos)
  484. {
  485. try
  486. {
  487. connS = string.Format(connString, info.WorkPoint);
  488. conn = new System.Data.SqlClient.SqlConnection(connS);
  489. conn.Open();
  490. SqlTransaction sqlTran = conn.BeginTransaction();
  491. cmd = new SqlCommand();
  492. cmd.Transaction = sqlTran;
  493. cmd.Connection = conn;
  494. if (info.MTime < new DateTime(2000, 01, 01))
  495. throw new Exception("请输入正确的操作时间:" + info.MTime);
  496. sql = @" DELETE dbo.rdrecord11 WHERE ID='{0}'";
  497. sql = string.Format(sql, info.ID);
  498. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  499. cmd.Transaction.Commit();
  500. }
  501. catch (Exception ex)
  502. {
  503. cmd.Transaction.Rollback();
  504. log.Error(ex.Message);
  505. throw new Exception(ex.Message);
  506. }
  507. finally
  508. {
  509. if (conn.State == ConnectionState.Open)
  510. {
  511. conn.Close();
  512. }
  513. conn.Dispose();
  514. }
  515. }
  516. return res;
  517. }
  518. /// <summary>
  519. ///
  520. /// 记录日志
  521. /// </summary>
  522. /// <param name="Bills"></param>
  523. private void LogInfo(List<ICSOutsourcingIssueDoc> Bills)
  524. {
  525. string HeadList = string.Empty;
  526. string BodyList = string.Empty;
  527. foreach (ICSOutsourcingIssueDoc head in Bills)
  528. {
  529. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  530. foreach (ICSOutsourcingIssueDocs body in head.details)
  531. {
  532. BodyList += "\r\n 表体主键ID: " + body.SourceDetailID + ",数量:" + body.Quantity;
  533. }
  534. }
  535. log.Info(HeadList);
  536. log.Info(BodyList);
  537. }
  538. }
  539. }