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

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