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

552 lines
28 KiB

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