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

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