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

548 lines
28 KiB

  1. using ICSSoft.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Newtonsoft.Json;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Common;
  11. namespace ICSSoft.DataProject
  12. {
  13. /// <summary>
  14. /// 委外到货单
  15. /// </summary>
  16. public class DeliveryNotice
  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. //参数示例
  23. //[{
  24. // "ASNNO": "DN510852000001",
  25. // "WHCode": "11",
  26. // "User": "CC001",
  27. // "MTime": "2021-08-26 17:20:13",
  28. // "details": [
  29. // {
  30. // "LOTNO": "PO200219004100005",
  31. // "ReceiveQty": "2"
  32. // },{
  33. // "LOTNO": "PO200219004100001",
  34. // "ReceiveQty": "1"
  35. // }
  36. // ]
  37. //}]
  38. //返回参数
  39. //{
  40. //"Success": true,
  41. //"Message": "接口调用成功!",
  42. //"Data": null
  43. //}
  44. public string Get(List<ICSDeliveryNotice> infos)
  45. {
  46. List<ICSDeliveryNotice> szJson = new List<ICSDeliveryNotice>();
  47. DataTable dt = null;
  48. DataTable dtNew = null;
  49. string connS = "";
  50. string json = "";
  51. if (infos.Count <= 0)
  52. {
  53. throw new Exception("传送数据为空!");
  54. }
  55. string res = string.Empty;
  56. SqlConnection conn = new SqlConnection();
  57. SqlCommand cmd = new SqlCommand();
  58. string sql = string.Empty;
  59. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  60. foreach (string WorkPoint in result)
  61. {
  62. try
  63. {
  64. connS = string.Format(connString, WorkPoint);
  65. conn = new System.Data.SqlClient.SqlConnection(connS);
  66. conn.Open();
  67. SqlTransaction sqlTran = conn.BeginTransaction();
  68. cmd = new SqlCommand();
  69. cmd.Transaction = sqlTran;
  70. cmd.Connection = conn;
  71. foreach (ICSDeliveryNotice info in infos)
  72. {
  73. if (WorkPoint != info.WorkPoint)
  74. {
  75. continue;
  76. }
  77. ICSUserInfo userInfo = new ICSUserInfo();
  78. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  79. if (info.MTime < new DateTime(2000, 01, 01))
  80. throw new Exception("请输入正确的操作时间:" + info.MTime);
  81. sql = @" SELECT A.ID,A.cCode,A.cVenCode,D.cVenName,C.CDEPNAME,A.cDepCode,C.cDepName,A.cpocode,A.cMaker,A.cMakeTime,A.cverifier,A.caudittime,
  82. B.Autoid,B.irowno ,B.cInvCode ,B.INUM,B.iQuantity,B.fValidInQuan,B.iPOsID
  83. FROM PU_ArrivalVouch A
  84. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  85. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  86. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and A.cBusType=''";
  87. if (!string.IsNullOrWhiteSpace(info.ODNCode))
  88. {
  89. sql += " and a.cCode='{0}'";
  90. }
  91. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  92. {
  93. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{1}'";
  94. }
  95. if (!string.IsNullOrWhiteSpace(info.User))
  96. {
  97. sql += "and a.CMAKER='{2}'";
  98. }
  99. sql = string.Format(sql, info.ODNCode, info.MTime, userInfo.UserName);
  100. dt = DBHelper.SQlReturnData(sql, cmd);
  101. if (dtNew == null)
  102. dtNew = dt;
  103. else
  104. dtNew.Merge(dt);
  105. }
  106. cmd.Transaction.Commit();
  107. }
  108. catch (Exception ex)
  109. {
  110. cmd.Transaction.Rollback();
  111. log.Error(ex.Message);
  112. throw new Exception(ex.Message);
  113. }
  114. finally
  115. {
  116. if (conn.State == ConnectionState.Open)
  117. {
  118. conn.Close();
  119. }
  120. conn.Dispose();
  121. }
  122. }
  123. json = JsonConvert.SerializeObject(dtNew);
  124. return json;
  125. }
  126. /// <summary>
  127. /// 回写U8到货单,
  128. /// </summary>
  129. /// <param name="cmd"></param>
  130. /// <param name="Lotnos"></param>
  131. /// <param name="info"></param>
  132. public string CreatePUArrive(List<ICSDeliveryNotice> Bills)
  133. {
  134. string res = string.Empty;
  135. DataSet ds = null;
  136. string str = "";
  137. string connS = "";
  138. int num = 0;
  139. SqlConnection conn = new SqlConnection();
  140. SqlCommand cmd = new SqlCommand();
  141. string iFatherIdTwo = "";
  142. List<ICSDeliveryNotice> datas = new List<ICSDeliveryNotice>();
  143. string sql = "";
  144. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  145. foreach (string WorkPoint in result)
  146. {
  147. try
  148. {
  149. connS = string.Format(connString, WorkPoint);
  150. conn = new System.Data.SqlClient.SqlConnection(connS);
  151. conn.Open();
  152. SqlTransaction sqlTran = conn.BeginTransaction();
  153. cmd = new SqlCommand();
  154. cmd.Transaction = sqlTran;
  155. cmd.Connection = conn;
  156. foreach (ICSDeliveryNotice head in Bills)
  157. {
  158. iFatherIdTwo = "";
  159. if (WorkPoint != head.WorkPoint)
  160. {
  161. continue;
  162. }
  163. ICSUserInfo userInfo = new ICSUserInfo();
  164. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  165. num = head.details.Count();
  166. string[] ss = head.WorkPoint.Split('_');
  167. ERPDB = ss[1];
  168. if (!DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  169. throw new Exception("U8正在整理现存量,请稍后再试");
  170. DateTime time = DateTime.Now;
  171. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", "PuArrival", "" + num + "", head.WorkPoint);
  172. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  173. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  174. DateTime date = DateTime.Now;
  175. string iBaseCodeLen = DBHelper.GetAllRDCode("26", "" + time + "", "admin", "", head.WorkPoint);
  176. string DEF_ID = DBHelper.GetDefaultTemplate(Type, cmd);
  177. #region 主表
  178. sql = @"INSERT INTO PU_ArrivalVouch
  179. (iVTid, ID, cCode, cPTCode, dDate,
  180. cVenCode, cDepCode, cPersonCode, cPayCode,
  181. cexch_name, iExchRate, iTaxRate, cMemo,
  182. cBusType, cMaker, bNegative, iBillType,
  183. cMakeTime, cAuditDate, caudittime, cverifier,
  184. iverifystateex, IsWfControlled, iflowid, iPrintCount,
  185. cpocode)
  186. SELECT
  187. @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23),
  188. cVenCode, cDepCode, cPersonCode, cPayCode,
  189. cexch_name, nflat, iTaxRate, cMemo,
  190. '', @User, 0, 0,
  191. GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User,
  192. 2, 0, 0, iPrintCount,
  193. cCode
  194. FROM OM_MOMain WHERE 1=1 AND cCode = @POID ";
  195. cmd.Parameters.Clear();
  196. cmd.Parameters.Add(new SqlParameter("@iVTid", DEF_ID));
  197. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  198. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  199. cmd.Parameters.Add(new SqlParameter("@User", userInfo.UserName));
  200. cmd.Parameters.Add(new SqlParameter("@POID", head.OOCode));
  201. //cmd.Parameters.Add(new SqlParameter("@dDate", data.dMate));
  202. cmd.CommandText = sql;
  203. try
  204. {
  205. int count = cmd.ExecuteNonQuery();
  206. if (count <= 0)
  207. {
  208. log.Error("生成委外到货单表头失败,受影响行数<=0;");
  209. throw new Exception("生成委外到货单表头失败,受影响行数<=0;");
  210. }
  211. }
  212. catch (Exception ex)
  213. {
  214. log.Error("生成委外到货单表头失败!委外订单号:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  215. throw new Exception("生成委外到货单表头失败!委外订单号:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  216. }
  217. #endregion
  218. foreach (ICSDeliveryNotices body in head.details)
  219. {
  220. int iMassDate = 0;
  221. int cMassUnit = 0;
  222. sql = @"SELECT cInvCode, ISNULL(iMassDate, 0) iMassDate, ISNULL(cMassUnit, 0) cMassUnit FROM Inventory WHERE cInvCode = '{0}' ";
  223. sql = string.Format(sql, body.InvCode);
  224. DataTable dts = DBHelper.SQlReturnData(sql, cmd);
  225. if (dts.Rows.Count == 0)
  226. {
  227. log.Error("存货档案不存在");
  228. throw new Exception("存货档案不存在");
  229. }
  230. else
  231. {
  232. iMassDate = Convert.ToInt16(dts.Rows[0]["iMassDate"].ToString());
  233. cMassUnit = Convert.ToInt16(dts.Rows[0]["cMassUnit"].ToString());
  234. }
  235. sql = @"
  236. INSERT INTO PU_ArrivalVouchs
  237. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  238. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  239. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  240. dPDate, dVDate, imassdate, cmassunit, cExpirationdate, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cItemCode,
  241. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,iNum)
  242. SELECT @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  243. round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),round(pd.iTaxPrice*@iQuantity,2),round((pd.iTaxPrice/(1+pd.iPerTaxRate/100)*b.nflat),2),
  244. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  245. round((round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2))*b.nflat,2),round(round(pd.iTaxPrice*@iQuantity,2)*b.nflat,2),pd.iPerTaxRate,
  246. pd.MODetailsID , 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  247. 0, null, 0, @cordercode, 0, 0, 0, @ivouchrowno, 0,
  248. @dPDate, @dVDate, @imassdate, @cmassunit, null, @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8,@cFree9, @cFree10,@cItemCode,
  249. @Batch, @cDefine37, null, null, null, null, null,@iNum FROM OM_MODetails pd
  250. left join OM_MOMain b on pd.MOID =b.MOID
  251. WHERE pd.MODetailsID = @MODetailsID
  252. EXEC PROC_Update_OM_PUArrivalVouchs @ID= @ID1";
  253. cmd.Parameters.Clear();
  254. cmd.Parameters.Add(new SqlParameter("@MODetailsID", body.OODetailID));
  255. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  256. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  257. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  258. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  259. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount.ToString("0.00")));
  260. cmd.Parameters.Add(new SqlParameter("@cordercode", head.OOCode));
  261. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  262. cmd.Parameters.Add(new SqlParameter("@dPDate", head.MTime));
  263. if (cMassUnit == 1)
  264. {
  265. cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddYears(iMassDate).Date));
  266. }
  267. if (cMassUnit == 2)
  268. {
  269. cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddMonths(iMassDate).Date));
  270. }
  271. if (cMassUnit == 3)
  272. {
  273. cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddDays(iMassDate).Date));
  274. }
  275. cmd.Parameters.Add(new SqlParameter("@dVDate", ""));
  276. cmd.Parameters.Add(new SqlParameter("@imassdate", iMassDate));
  277. cmd.Parameters.Add(new SqlParameter("@cmassunit", cMassUnit));
  278. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  279. cmd.Parameters.Add(new SqlParameter("@cItemCode", body.ProjectCode));
  280. cmd.Parameters.Add(new SqlParameter("@cDefine37", head.MTime.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  281. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  282. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  283. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  284. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  285. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  286. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  287. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  288. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  289. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  290. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  291. cmd.CommandText = sql;
  292. try
  293. {
  294. int count = cmd.ExecuteNonQuery();
  295. if (count <= 0)
  296. {
  297. log.Error("生成委外到货单表体失败,受影响行数<=0;");
  298. throw new Exception("生成委外到货单表体失败,受影响行数<=0;");
  299. }
  300. }
  301. catch (Exception ex)
  302. {
  303. log.Error("生成委外到货单表体失败!委外订单号:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  304. throw new Exception("生成委外到货单表体失败!委外订单号:" + head.ODNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  305. }
  306. sql = string.Format(@"UPDATE B SET B.iArrMoney = ISNULL(B.iArrMoney, 0) + A.iOriSum, B.iNatArrMoney = ISNULL(B.iNatArrMoney, 0) + A.iSum,
  307. B.iArrQTY=isnull(B.iArrQTY,0)+A.iQuantity
  308. FROM dbo.PU_ArrivalVouchs A LEFT JOIN dbo.OM_MODetails B ON A.iPOsID = B.MODetailsID
  309. WHERE A.Autoid = '{0}'", iChildId);
  310. cmd.CommandText = sql;
  311. cmd.ExecuteNonQuery();
  312. sql = @"select isnull(iArrQTY,0)fOutQuantity,isnull(iQuantity,0)iQuantity,ISNULL(iNum, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(iNum, 0)-ISNULL(NiNum, 0) SiNum from OM_MODetails a
  313. LEFT JOIN (select sum(iNum) NiNum,iPOsID from PU_ArrivalVouchs GROUP BY iPOsID) b on a.MODetailsID=b.iPOsID
  314. where a.MODetailsID='" + body.OODetailID + "'";
  315. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  316. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  317. {
  318. foreach (DataRow item in dtDisCheck.Rows)
  319. {
  320. if (Convert.ToDecimal(item["fOutQuantity"].ToString()) == Convert.ToDecimal(item["iQuantity"].ToString()))
  321. {
  322. if (Convert.ToDecimal(item["iNum"].ToString()) != 0)
  323. {
  324. if (Convert.ToDecimal(item["SiNum"].ToString()) != 0)
  325. {
  326. sql = @"Update PU_ArrivalVouchs set iNum=isnull(iNum,0)+(" + item["SiNum"].ToString() + ") where autoid='" + iChildId + "' ";
  327. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  328. }
  329. }
  330. }
  331. }
  332. }
  333. iFatherIdTwo = "'" + iFatherId + "',";
  334. iChildId--;
  335. }
  336. sql = @" SELECT DISTINCT A.ID as ID, A.ID as IDs,A.cCode as ODNCode,A.cVenCode,D.cVenName,
  337. A.cDepCode,C.cDepName,A.cpocode as OOCode,A.cMaker,A.cMakeTime,A.cverifier,A.caudittime
  338. FROM PU_ArrivalVouch A
  339. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  340. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE
  341. WHERE 1=1 and A.cBusType='' AND A.ID in ({0})
  342. SELECT DISTINCT A.ID as IDs, B.Autoid as DetailID ,B.ivouchrowno as Sequence,B.cInvCode,B.INUM,B.iQuantity,
  343. B.fValidInQuan,B.iPOsID as OODetailID
  344. ,isnull(b.cItemCode,'') ProjectCode,
  345. isnull(b.cbatch,'') cBatch,
  346. '' version ,'' brand,
  347. isnull(b.cFree1,'') as cFree1,
  348. isnull(b.cFree2,'') as cFree2,
  349. isnull(b.cFree3,'') as cFree3,
  350. isnull(b.cFree4,'') as cFree4,
  351. isnull(b.cFree5,'') as cFree5,
  352. isnull(b.cFree6,'') as cFree6,
  353. isnull(b.cFree7,'') as cFree7,
  354. isnull(b.cFree8,'') as cFree8,
  355. isnull(b.cFree9,'') as cFree9,
  356. isnull(b.cFree10,'') as cFree10
  357. FROM PU_ArrivalVouch A
  358. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  359. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  360. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and A.cBusType='' AND A.ID in ({0}) ";
  361. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  362. if (ds != null)
  363. ds.Merge(DBHelper.SQlReturnDataSet(sql, cmd));
  364. else
  365. ds = DBHelper.SQlReturnDataSet(sql, cmd);
  366. }
  367. cmd.Transaction.Commit();
  368. }
  369. catch (Exception ex)
  370. {
  371. cmd.Transaction.Rollback();
  372. log.Error(ex.Message);
  373. throw new Exception(ex.Message);
  374. }
  375. finally
  376. {
  377. if (conn.State == ConnectionState.Open)
  378. {
  379. conn.Close();
  380. }
  381. conn.Dispose();
  382. }
  383. }
  384. str = JSON.DataSetToJson(ds, "details", "IDs");
  385. return str;
  386. }
  387. public string Approve(List<ICSDeliveryNotice> infos)
  388. {
  389. List<ICSDeliveryNotice> szJson = new List<ICSDeliveryNotice>();
  390. string json = "";
  391. string connS = "";
  392. if (infos.Count <= 0)
  393. {
  394. throw new Exception("传送数据为空!");
  395. }
  396. string res = string.Empty;
  397. SqlConnection conn = new SqlConnection();
  398. SqlCommand cmd = new SqlCommand();
  399. string sql = string.Empty;
  400. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  401. foreach (string WorkPoint in result)
  402. {
  403. try
  404. {
  405. connS = string.Format(connString, WorkPoint);
  406. conn = new System.Data.SqlClient.SqlConnection(connS);
  407. conn.Open();
  408. SqlTransaction sqlTran = conn.BeginTransaction();
  409. cmd = new SqlCommand();
  410. cmd.Transaction = sqlTran;
  411. cmd.Connection = conn;
  412. foreach (ICSDeliveryNotice info in infos)
  413. {
  414. if (WorkPoint != info.WorkPoint)
  415. {
  416. continue;
  417. }
  418. ICSUserInfo userInfo = new ICSUserInfo();
  419. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  420. if (info.MTime < new DateTime(2000, 01, 01))
  421. throw new Exception("请输入正确的操作时间:" + info.MTime);
  422. sql = @"UPDATE dbo.PU_ArrivalVouch SET cVerifier ='" + userInfo.UserName + @"' ,
  423. cAuditTime=CONVERT(VARCHAR(50),GETDATE(),112),cAuditDate=GETDATE() WHERE ID='{0}'";
  424. sql = string.Format(sql, info.ID);
  425. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  426. }
  427. cmd.Transaction.Commit();
  428. }
  429. catch (Exception ex)
  430. {
  431. cmd.Transaction.Rollback();
  432. log.Error(ex.Message);
  433. throw new Exception(ex.Message);
  434. }
  435. finally
  436. {
  437. if (conn.State == ConnectionState.Open)
  438. {
  439. conn.Close();
  440. }
  441. conn.Dispose();
  442. }
  443. }
  444. return json;
  445. }
  446. /// <summary>
  447. /// 删除请购单
  448. /// </summary>
  449. /// <param name="infos"></param>
  450. /// <returns></returns>
  451. public string Delete(List<ICSDeliveryNotice> infos)
  452. {
  453. List<ICSDeliveryNotice> szJson = new List<ICSDeliveryNotice>();
  454. if (infos.Count <= 0)
  455. {
  456. throw new Exception("传送数据为空!");
  457. }
  458. string res = string.Empty;
  459. string connS = "";
  460. SqlConnection conn = new SqlConnection();
  461. SqlCommand cmd = new SqlCommand();
  462. string sql = string.Empty;
  463. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  464. foreach (string WorkPoint in result)
  465. {
  466. try
  467. {
  468. connS = string.Format(connString, WorkPoint);
  469. conn = new System.Data.SqlClient.SqlConnection(connS);
  470. conn.Open();
  471. SqlTransaction sqlTran = conn.BeginTransaction();
  472. cmd = new SqlCommand();
  473. cmd.Transaction = sqlTran;
  474. cmd.Connection = conn;
  475. foreach (ICSDeliveryNotice info in infos)
  476. {
  477. if (WorkPoint != info.WorkPoint)
  478. {
  479. continue;
  480. }
  481. if (info.MTime < new DateTime(2000, 01, 01))
  482. throw new Exception("请输入正确的操作时间:" + info.MTime);
  483. sql = @" DELETE dbo.PU_ArrivalVouch WHERE ID='{0}'";
  484. sql = string.Format(sql, info.ID);
  485. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  486. }
  487. cmd.Transaction.Commit();
  488. }
  489. catch (Exception ex)
  490. {
  491. cmd.Transaction.Rollback();
  492. log.Error(ex.Message);
  493. throw new Exception(ex.Message);
  494. }
  495. finally
  496. {
  497. if (conn.State == ConnectionState.Open)
  498. {
  499. conn.Close();
  500. }
  501. conn.Dispose();
  502. }
  503. }
  504. return res;
  505. }
  506. }
  507. }