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

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