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

644 lines
31 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
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 CreatePuArrivalVouch
  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 ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  19. private static string CRNALL = System.Configuration.ConfigurationManager.AppSettings["PUARRIVALRCRDNAME"];
  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<ICSPUArrivalVouch> infos)
  43. {
  44. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  45. DataTable dt = null;
  46. DataTable dtNew = null;
  47. string connS = "";
  48. string json = "";
  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 (ICSPUArrivalVouch 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,A.cDepCode,C.CDEPNAME, A.CMAKER,A.CMAKETIME,A.CVERIFIER,A.CAUDITTIME,
  71. B.Autoid ,B.irowno ,B.IQUANTITY ,B.INUM,B.cInvCode ,B.iCost ,B.irejectautoid
  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=2 and b.IQUANTITY<0 ";
  76. if (!string.IsNullOrWhiteSpace(info.RJTCode))
  77. {
  78. sql += " and a.cCode='{0}'";
  79. }
  80. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  81. {
  82. sql += " and ISNULL(A.dclosedate,ISNULL(A.caudittime ,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.RJTCode, info.MTime, info.User);
  89. dt = DBHelper.SQlReturnData(sql, cmd);
  90. if (dt.Rows.Count <= 0 || dt == null)
  91. throw new Exception("拒收单单:" + info.RJTCode + ",无信息!");
  92. if (dtNew == null)
  93. dtNew = dt;
  94. else
  95. dtNew.Merge(dt);
  96. cmd.Transaction.Commit();
  97. }
  98. catch (Exception ex)
  99. {
  100. cmd.Transaction.Rollback();
  101. log.Error(ex.Message);
  102. throw new Exception(ex.Message);
  103. }
  104. finally
  105. {
  106. if (conn.State == ConnectionState.Open)
  107. {
  108. conn.Close();
  109. }
  110. conn.Dispose();
  111. }
  112. }
  113. json = JsonConvert.SerializeObject(dtNew);
  114. return json;
  115. }
  116. /// <summary>
  117. /// 回写U8到货单,
  118. /// </summary>
  119. /// <param name="cmd"></param>
  120. /// <param name="Lotnos"></param>
  121. /// <param name="info"></param>
  122. public string CreatePUArrive(List<ICSPUArrivalVouch> Bills)
  123. {
  124. string msg = "";
  125. bool ResultFlag = false;
  126. int num = 0;
  127. foreach (ICSPUArrivalVouch head in Bills)
  128. {
  129. num = head.Vouchs.Count();
  130. }
  131. DataTable dtNew = null;
  132. string connS = "";
  133. SqlConnection conn = new SqlConnection();
  134. SqlCommand cmd = new SqlCommand();
  135. if (Bills.Count <= 0)
  136. {
  137. throw new Exception("传送数据为空!");
  138. }
  139. bool isNG = false;
  140. LogInfo(Bills);
  141. DateTime dVDate = new DateTime();
  142. DateTime dPDate = new DateTime();
  143. foreach (ICSPUArrivalVouch head in Bills)
  144. {
  145. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  146. {
  147. if (body.Quantity > 0)
  148. {
  149. isNG = true;
  150. }
  151. }
  152. }
  153. if (isNG)
  154. {
  155. int sum = 0;
  156. foreach (ICSPUArrivalVouch head in Bills)
  157. {
  158. try
  159. {
  160. connS = string.Format(connString, head.WorkPoint);
  161. conn = new System.Data.SqlClient.SqlConnection(connS);
  162. conn.Open();
  163. SqlTransaction sqlTran = conn.BeginTransaction();
  164. cmd = new SqlCommand();
  165. cmd.Transaction = sqlTran;
  166. cmd.Connection = conn;
  167. string[] ss = head.WorkPoint.Split('_');
  168. ERPDB = ss[1];
  169. string sql = "";
  170. VouchKey key = new VouchKey();
  171. //取得out库单的默认显示模版
  172. string[] dd = CRNALL.Split('~');
  173. string crdname = dd[0];
  174. string carname = dd[1];
  175. string surface = dd[2];
  176. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  177. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  178. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  179. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  180. DateTime date = DateTime.Now;
  181. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  182. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  183. #region 主表
  184. sql = @"INSERT INTO PU_ArrivalVouch
  185. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  186. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  187. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, '', @User, 1,
  188. iDiscountTaxType, 2, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, null
  189. FROM PU_ArrivalVouch WHERE 1=1 AND cCode = @headID ";
  190. cmd.Parameters.Clear();
  191. cmd.Parameters.Add(new SqlParameter("@iVTid", iChildId));
  192. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  193. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  194. cmd.Parameters.Add(new SqlParameter("@User", head.User));
  195. cmd.Parameters.Add(new SqlParameter("@headID", head.DNCode));
  196. cmd.CommandText = sql;
  197. try
  198. {
  199. int count = cmd.ExecuteNonQuery();
  200. if (count <= 0)
  201. {
  202. log.Error("生成采购拒收单表头失败,受影响行数<=0;");
  203. throw new Exception("生成采购拒收单表头失败,受影响行数<=0;");
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. log.Error("生成采购拒收单表头失败!到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  209. throw new Exception("生成采购拒收单表头失败!到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  210. }
  211. #endregion
  212. #region 表体
  213. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  214. {
  215. sql = @"INSERT INTO PU_ArrivalVouchs
  216. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  217. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  218. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  219. cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,
  220. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,inum,iCorId,carrivalcode )
  221. SELECT @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  222. 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),
  223. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  224. round((round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2))*b.nflat,2),round(round(pd.iTaxPrice*3402,2)*b.nflat,2),pd.iPerTaxRate,
  225. pd.ID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  226. 0, null, 0, b.cPOID, 0, 0, 0, @ivouchrowno, 0,
  227. @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,
  228. @Batch, @cDefine37, null, null, null, null, null,0,a.Autoid,c.cCode
  229. FROM dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  230. INNER JOIN dbo.PO_Pomain b ON pd.POID=b.POID
  231. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + @"'
  232. EXEC PROC_Update_PO_PUArrivalVouchs @ID= @ID1";
  233. cmd.Parameters.Clear();
  234. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  235. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  236. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  237. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  238. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  239. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  240. cmd.Parameters.Add(new SqlParameter("@cDefine37", DateTime.Now.Date.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  241. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  242. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  243. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  244. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  245. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  246. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  247. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  248. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  249. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  250. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  251. cmd.CommandText = sql;
  252. try
  253. {
  254. int count = cmd.ExecuteNonQuery();
  255. if (count <= 0)
  256. {
  257. log.Error("生成采购拒收单表体失败,受影响行数<=0;");
  258. throw new Exception("生成采购拒收单表体失败,受影响行数<=0;");
  259. }
  260. }
  261. catch (Exception ex)
  262. {
  263. log.Error("生成采购拒收单表体失败!采购到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  264. throw new Exception("生成采购拒收单表体失败!采购到货单ID:" + head.ID + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  265. }
  266. sql = string.Format(@"update pd set pd.fPoRefuseQuantity = isnull(pd.fPoRefuseQuantity,0)+{0}
  267. from dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  268. INNER JOIN dbo.PO_Pomain b ON pd.POID=b.POID
  269. INNER JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + "' ", body.Quantity);
  270. cmd.CommandText = sql;
  271. cmd.ExecuteNonQuery();
  272. iChildId -= 1;
  273. }
  274. #endregion
  275. cmd.Transaction.Commit();
  276. }
  277. catch (Exception ex)
  278. {
  279. cmd.Transaction.Rollback();
  280. log.Error(ex.Message);
  281. throw new Exception(ex.Message);
  282. }
  283. finally
  284. {
  285. if (conn.State == ConnectionState.Open)
  286. {
  287. conn.Close();
  288. }
  289. conn.Dispose();
  290. }
  291. }
  292. }
  293. ResultFlag = true;
  294. return msg;
  295. }
  296. /// <summary>
  297. /// 回写委外拒收单
  298. /// </summary>
  299. /// <param name="cmd"></param>
  300. /// <param name="Lotnos"></param>
  301. /// <param name="info"></param>
  302. public string CreateWPUArrive(List<ICSPUArrivalVouch> Bills)
  303. {
  304. string msg = "";
  305. bool ResultFlag = false;
  306. int num = 0;
  307. foreach (ICSPUArrivalVouch head in Bills)
  308. {
  309. num = head.Vouchs.Count();
  310. }
  311. DataTable dtNew = null;
  312. string connS = "";
  313. SqlConnection conn = new SqlConnection();
  314. SqlCommand cmd = new SqlCommand();
  315. if (Bills.Count <= 0)
  316. {
  317. throw new Exception("传送数据为空!");
  318. }
  319. bool isNG = false;
  320. LogInfo(Bills);
  321. DateTime dVDate = new DateTime();
  322. DateTime dPDate = new DateTime();
  323. foreach (ICSPUArrivalVouch head in Bills)
  324. {
  325. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  326. {
  327. if (body.Quantity > 0)
  328. {
  329. isNG = true;
  330. }
  331. }
  332. }
  333. if (isNG)
  334. {
  335. int sum = 0;
  336. foreach (ICSPUArrivalVouch head in Bills)
  337. {
  338. try
  339. {
  340. connS = string.Format(connString, head.WorkPoint);
  341. conn = new System.Data.SqlClient.SqlConnection(connS);
  342. conn.Open();
  343. SqlTransaction sqlTran = conn.BeginTransaction();
  344. cmd = new SqlCommand();
  345. cmd.Transaction = sqlTran;
  346. cmd.Connection = conn;
  347. string[] ss = head.WorkPoint.Split('_');
  348. ERPDB = ss[1];
  349. string sql = "";
  350. VouchKey key = new VouchKey();
  351. //取得out库单的默认显示模版
  352. string[] dd = CRNALL.Split('~');
  353. string crdname = dd[0];
  354. string carname = dd[1];
  355. string surface = dd[2];
  356. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  357. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  358. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  359. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  360. DateTime date = DateTime.Now;
  361. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  362. #region 主表
  363. sql = @"INSERT INTO PU_ArrivalVouch
  364. (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative,
  365. iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode)
  366. SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, '', @User, 1,
  367. iDiscountTaxType, 2, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, null
  368. FROM PU_ArrivalVouch WHERE 1=1 AND cCode = @headID ";
  369. cmd.Parameters.Clear();
  370. cmd.Parameters.Add(new SqlParameter("@iVTid", iChildId));
  371. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  372. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  373. cmd.Parameters.Add(new SqlParameter("@User", head.User));
  374. cmd.Parameters.Add(new SqlParameter("@headID", head.DNCode));
  375. cmd.CommandText = sql;
  376. try
  377. {
  378. int count = cmd.ExecuteNonQuery();
  379. if (count <= 0)
  380. {
  381. log.Error("生成采购拒收单表头失败,受影响行数<=0;");
  382. throw new Exception("生成采购拒收单表头失败,受影响行数<=0;");
  383. }
  384. }
  385. catch (Exception ex)
  386. {
  387. log.Error("生成采购拒收单表头失败!到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  388. throw new Exception("生成采购拒收单表头失败!到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  389. }
  390. #endregion
  391. #region 表体
  392. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  393. {
  394. iChildId -= 1;
  395. sql = @"INSERT INTO PU_ArrivalVouchs
  396. (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate,
  397. iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost,
  398. SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift,
  399. cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,
  400. cBatch, cDefine37, fKPQuantity, finValidQuantity, fRefuseQuantity, iProductType,bexigency,inum,iCorId,carrivalcode )
  401. SELECT top 1 @Autoid, @ID1, @cInvCode, @iQuantity,pd.iUnitPrice,pd.iTaxPrice,round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2),
  402. 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),
  403. round(round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2)*b.nflat,2),
  404. round((round(pd.iTaxPrice*@iQuantity,2)-round((pd.iTaxPrice*@iQuantity)/(1+pd.iPerTaxRate/100),2))*b.nflat,2),round(round(pd.iTaxPrice*3402,2)*b.nflat,2),pd.iPerTaxRate,
  405. pd.MODetailsID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1,
  406. 0, null, 0, b.ccode, 0, 0, 0, @ivouchrowno, 0,
  407. @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,
  408. @Batch, @cDefine37, null, null, null, null, null,0,a.Autoid,c.cCode
  409. from dbo.PU_ArrivalVouchs a
  410. LEFT JOIN dbo.OM_MODetails pd ON a.iPOsID = pd.MODetailsID
  411. left JOIN dbo.OM_MOMain b ON pd.MOID = b.MOID
  412. left JOIN dbo.PU_ArrivalVouch c ON a.ID=c.ID where a.Autoid='" + body.DNDetailID + @"'
  413. EXEC PROC_Update_OM_PUArrivalVouchs @ID= @ID1
  414. ";
  415. cmd.Parameters.Clear();
  416. cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId));
  417. cmd.Parameters.Add(new SqlParameter("@ID1", iFatherId));
  418. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  419. cmd.Parameters.Add(new SqlParameter("@iQuantity", -body.Quantity));
  420. cmd.Parameters.Add(new SqlParameter("@ivouchrowno", body.Sequence));
  421. cmd.Parameters.Add(new SqlParameter("@Batch", body.BatchCode));
  422. cmd.Parameters.Add(new SqlParameter("@cDefine37", DateTime.Now.Date.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddSeconds(-1)));
  423. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  424. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  425. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  426. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  427. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  428. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  429. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  430. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  431. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  432. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  433. cmd.CommandText = sql;
  434. try
  435. {
  436. int count = cmd.ExecuteNonQuery();
  437. if (count <= 0)
  438. {
  439. log.Error("生成采购拒收单表体失败,受影响行数<=0;");
  440. throw new Exception("生成采购拒收单表体失败,受影响行数<=0;");
  441. }
  442. }
  443. catch (Exception ex)
  444. {
  445. log.Error("生成委外拒收单表体失败!委外到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  446. throw new Exception("生成委外拒收单表体失败!委外到货单:" + head.DNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  447. }
  448. sql = string.Format(@"update pd set pd.fPoRefuseQuantity = isnull(pd.fPoRefuseQuantity,0)+{0}
  449. from dbo.PU_ArrivalVouchs a LEFT JOIN dbo.PO_Podetails pd ON a.iPOsID= pd.ID
  450. where a.Autoid='" + body.DNDetailID + "' ", body.Quantity);
  451. cmd.CommandText = sql;
  452. cmd.ExecuteNonQuery();
  453. }
  454. #endregion
  455. cmd.Transaction.Commit();
  456. }
  457. catch (Exception ex)
  458. {
  459. cmd.Transaction.Rollback();
  460. log.Error(ex.Message);
  461. throw new Exception(ex.Message);
  462. }
  463. finally
  464. {
  465. if (conn.State == ConnectionState.Open)
  466. {
  467. conn.Close();
  468. }
  469. conn.Dispose();
  470. }
  471. }
  472. }
  473. ResultFlag = true;
  474. return msg;
  475. }
  476. public string Approve(List<ICSPUArrivalVouch> infos)
  477. {
  478. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  479. DataTable dt = null;
  480. DataTable dtNew = null;
  481. string connS = "";
  482. string json = "";
  483. if (infos.Count <= 0)
  484. {
  485. throw new Exception("传送数据为空!");
  486. }
  487. string res = string.Empty;
  488. SqlConnection conn = new SqlConnection();
  489. SqlCommand cmd = new SqlCommand();
  490. string sql = string.Empty;
  491. foreach (ICSPUArrivalVouch info in infos)
  492. {
  493. try
  494. {
  495. connS = string.Format(connString, info.WorkPoint);
  496. conn = new System.Data.SqlClient.SqlConnection(connS);
  497. conn.Open();
  498. SqlTransaction sqlTran = conn.BeginTransaction();
  499. cmd = new SqlCommand();
  500. cmd.Transaction = sqlTran;
  501. cmd.Connection = conn;
  502. if (info.MTime < new DateTime(2000, 01, 01))
  503. throw new Exception("请输入正确的操作时间:" + info.MTime);
  504. sql = @"UPDATE PU_ArrivalVouch SET cVerifier ='" + info.User + @"' ,
  505. cAuditTime=CONVERT(VARCHAR(50),GETDATE(),112),cAuditDate=GETDATE() WHERE ID='{0}'";
  506. sql = string.Format(sql, info.ID);
  507. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  508. cmd.Transaction.Commit();
  509. }
  510. catch (Exception ex)
  511. {
  512. cmd.Transaction.Rollback();
  513. log.Error(ex.Message);
  514. throw new Exception(ex.Message);
  515. }
  516. finally
  517. {
  518. if (conn.State == ConnectionState.Open)
  519. {
  520. conn.Close();
  521. }
  522. conn.Dispose();
  523. }
  524. }
  525. return json;
  526. }
  527. /// <summary>
  528. /// 删除请购单
  529. /// </summary>
  530. /// <param name="infos"></param>
  531. /// <returns></returns>
  532. public string Delete(List<ICSPUArrivalVouch> infos)
  533. {
  534. List<ICSPUArrivalVouch> szJson = new List<ICSPUArrivalVouch>();
  535. if (infos.Count <= 0)
  536. {
  537. throw new Exception("传送数据为空!");
  538. }
  539. string res = string.Empty;
  540. DataTable dtNew = null;
  541. string connS = "";
  542. SqlConnection conn = new SqlConnection();
  543. SqlCommand cmd = new SqlCommand();
  544. string sql = string.Empty;
  545. foreach (ICSPUArrivalVouch info in infos)
  546. {
  547. try
  548. {
  549. connS = string.Format(connString, info.WorkPoint);
  550. conn = new System.Data.SqlClient.SqlConnection(connS);
  551. conn.Open();
  552. SqlTransaction sqlTran = conn.BeginTransaction();
  553. cmd = new SqlCommand();
  554. cmd.Transaction = sqlTran;
  555. cmd.Connection = conn;
  556. if (info.MTime < new DateTime(2000, 01, 01))
  557. throw new Exception("请输入正确的操作时间:" + info.MTime);
  558. sql = @" DELETE PU_AppVouch WHERE ID={0}";
  559. sql = string.Format(sql, info.ID);
  560. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  561. cmd.Transaction.Commit();
  562. }
  563. catch (Exception ex)
  564. {
  565. cmd.Transaction.Rollback();
  566. log.Error(ex.Message);
  567. throw new Exception(ex.Message);
  568. }
  569. finally
  570. {
  571. if (conn.State == ConnectionState.Open)
  572. {
  573. conn.Close();
  574. }
  575. conn.Dispose();
  576. }
  577. }
  578. return res;
  579. }
  580. /// <summary>
  581. ///
  582. /// 记录日志
  583. /// </summary>
  584. /// <param name="Bills"></param>
  585. private void LogInfo(List<ICSPUArrivalVouch> Bills)
  586. {
  587. string HeadList = string.Empty;
  588. string BodyList = string.Empty;
  589. foreach (ICSPUArrivalVouch head in Bills)
  590. {
  591. HeadList += "\r\n 表头主键ID:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  592. foreach (ICSPUArrivalVouchs body in head.Vouchs)
  593. {
  594. BodyList += "\r\n 表体主键ID: " + body.DNDetailID + ",数量:" + body.Quantity;
  595. }
  596. }
  597. log.Info(HeadList);
  598. log.Info(BodyList);
  599. }
  600. }
  601. }