纽威
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
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.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace ICSSoft.DataProject
  12. {
  13. /// <summary>
  14. /// 销售出库红字
  15. /// </summary>
  16. public class SalesShipmentDocNegative
  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. string bustype = string.Empty;
  23. /// <summary>
  24. ///获取销售出库单红字
  25. /// </summary>
  26. /// <param name="infos"></param>
  27. /// <returns></returns>
  28. public string Get(List<ICSSalesShipmentDocNegative> infos)
  29. {
  30. List<ICSSalesShipmentDocNegative> szJson = new List<ICSSalesShipmentDocNegative>();
  31. DataTable dt = null;
  32. DataTable dtNew = null;
  33. string connS = "";
  34. string json = "";
  35. if (infos.Count <= 0)
  36. {
  37. throw new Exception("传送数据为空!");
  38. }
  39. string res = string.Empty;
  40. SqlConnection conn = new SqlConnection();
  41. SqlCommand cmd = new SqlCommand();
  42. string sql = string.Empty;
  43. foreach (ICSSalesShipmentDocNegative info in infos)
  44. {
  45. try
  46. {
  47. connS = string.Format(connString, info.WorkPoint);
  48. conn = new System.Data.SqlClient.SqlConnection(connS);
  49. conn.Open();
  50. SqlTransaction sqlTran = conn.BeginTransaction();
  51. cmd = new SqlCommand();
  52. cmd.Transaction = sqlTran;
  53. cmd.Connection = conn;
  54. if (info.MTime < new DateTime(2000, 01, 01))
  55. throw new Exception("请输入正确的操作时间:" + info.MTime);
  56. sql = @"select a.ID,a.cCode,a.cCusCode,c.cCusName,a.cWhCode,d.cWhName,e.cordercode ,a.cMaker ,a.dnmaketime ,a.cHandler ,a.dnverifytime ,
  57. b.AutoID,b.iRSRowNO ,b.cInvCode ,b.iQuantity ,b.iNum,e.AutoID
  58. from rdrecord32 a
  59. inner join rdrecords32 b on a.ID=b.ID
  60. left join DispatchLists e on a.cDLCode=e.DLID
  61. left join Customer c on a.cCusCode=c.cCusCode
  62. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1 and b.iquantity<0 ";
  63. if (!string.IsNullOrWhiteSpace(info.SDNNEGCode))
  64. {
  65. sql += " and a.cCode='{0}'";
  66. }
  67. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  68. {
  69. sql += " and ISNULL(a.dnmodifytime ,ISNULL(a.dnverifytime , ISNULL(a.dnmodifytime , a.dnmaketime )))>='{1}'";
  70. }
  71. if (!string.IsNullOrWhiteSpace(info.User))
  72. {
  73. sql += "and a.CMAKER='{2}'";
  74. }
  75. sql = string.Format(sql, info.SDNNEGCode, info.MTime, info.User);
  76. dt = DBHelper.SQlReturnData(sql, cmd);
  77. if (dt.Rows.Count <= 0 || dt == null)
  78. throw new Exception("红字销售出库单号:" + info.SDNNEGCode + ",无信息!");
  79. dtNew.Merge(dt);
  80. cmd.Transaction.Commit();
  81. }
  82. catch (Exception ex)
  83. {
  84. cmd.Transaction.Rollback();
  85. log.Error(ex.Message);
  86. throw new Exception(ex.Message);
  87. }
  88. finally
  89. {
  90. if (conn.State == ConnectionState.Open)
  91. {
  92. conn.Close();
  93. }
  94. conn.Dispose();
  95. }
  96. }
  97. json = JsonConvert.SerializeObject(dtNew);
  98. return json;
  99. }
  100. /// <summary>
  101. /// 创建销售出库单红字
  102. /// </summary>
  103. /// <param name="Bills"></param>
  104. /// <returns></returns>
  105. public string CreateSalesShipmentDocNegative(List<ICSSalesShipmentDocNegative> Bills)
  106. {
  107. string sql = "";
  108. string msg = "";
  109. DataTable dtNew1 = null;
  110. DataTable dtNew2 = null;
  111. string connS = "";
  112. int iFatherId = 0;
  113. int iChildId = 0;
  114. string iFatherIdTwo = "";
  115. int num = 0;
  116. //bool ResultFlag = false;
  117. SqlConnection conn = new SqlConnection();
  118. SqlCommand cmd = new SqlCommand();
  119. VouchKey key = new VouchKey();
  120. if (Bills.Count <= 0)
  121. {
  122. throw new Exception("传送数据为空!");
  123. }
  124. LogInfo(Bills);
  125. foreach (ICSSalesShipmentDocNegative head in Bills)
  126. {
  127. try
  128. {
  129. connS = string.Format(connString, head.WorkPoint);
  130. conn = new System.Data.SqlClient.SqlConnection(connS);
  131. conn.Open();
  132. SqlTransaction sqlTran = conn.BeginTransaction();
  133. cmd = new SqlCommand();
  134. cmd.Transaction = sqlTran;
  135. cmd.Connection = conn;
  136. string[] ss = head.WorkPoint.Split('_');
  137. ERPDB = ss[1];
  138. #region 检查 发货单状态
  139. sql = @"SELECT a.DLID,a.cBusType,c.cRdCode,a.cSTCode,b.AutoID,b.irowno,a.cPersonCode,a.cCusCode,b.iDLsID,
  140. a.cMemo,a.cShipAddress,a.cDepCode,cCusInvName,b.cBatch,a.caddcode,a.cCloser,a.cVerifier FROM dbo.DispatchList a INNER JOIN
  141. dbo.DispatchLists b ON a.DLID=b.DLID
  142. LEFT JOIN dbo.SaleType c ON c.cSTCode=a.cSTCode
  143. WHERE a.cDLCode ='" + head.SDNRTCode + "'";
  144. cmd.CommandText = sql;
  145. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  146. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  147. {
  148. foreach (DataRow item in dtDisCheck.Rows)
  149. {
  150. if (!string.IsNullOrEmpty(item["cCloser"].ToString()))
  151. {
  152. log.Info("DLID:" + head.ID);
  153. throw new Exception("ERP发货单已关闭,无法发货!发货单号:" + head.SDNNEGCode);
  154. }
  155. }
  156. bustype = dtDisCheck.Rows[0]["cBusType"].ToString();
  157. }
  158. else
  159. {
  160. throw new Exception("销售发货单单号:" + head.ID + "在ERP内不存在!");
  161. }
  162. #endregion
  163. #region 检验发货单数量
  164. foreach (ICSSalesShipmentDocNegatives body in head.details)
  165. {
  166. sql = "SELECT isnull(fOutQuantity,0) as fOutQuantity,ABS(iQuantity) as iQuantity FROM dbo.DispatchLists WHERE AutoID='" + body.SDNRTDetailID + "'";
  167. DataTable dtfOutQty = DBHelper.SQlReturnData(sql, cmd);
  168. if (dtfOutQty != null && dtfOutQty.Rows.Count > 0)
  169. {
  170. decimal fOutQty = Convert.ToDecimal(dtfOutQty.Rows[0]["fOutQuantity"]);
  171. decimal iQuantity = Convert.ToDecimal(dtfOutQty.Rows[0]["iQuantity"]);
  172. if (fOutQty + body.Quantity > iQuantity)
  173. {
  174. throw new Exception("可出库数量超过发货单表体出库数量!");
  175. }
  176. }
  177. else
  178. {
  179. throw new Exception("发货单表体不存在!");
  180. }
  181. }
  182. #endregion
  183. #region 红字销售出库单表头
  184. num = head.details.Count();
  185. DateTime time = DateTime.Now;
  186. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", "ShipmentDoc", "" + num + "");
  187. iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  188. iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  189. DateTime date = DateTime.Now;
  190. string iBaseCodeLen = DBHelper.GetAllRDCode("0303", "" + time + "", "admin");
  191. sql = @"INSERT INTO dbo.rdrecord32
  192. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,cBusCode ,cWhCode ,
  193. dDate ,cCode ,cRdCode ,cDepCode ,cPersonCode ,cSTCode ,cCusCode ,
  194. cDLCode ,cHandler ,cMemo ,bTransFlag ,cMaker ,cDefine1 ,cDefine2 ,
  195. cDefine3 ,cDefine4 ,cDefine5 ,cDefine6 ,cDefine7 ,cDefine8 ,cDefine9 ,
  196. cDefine10 ,dVeriDate ,bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cDefine11 ,
  197. cDefine12 ,cDefine13 ,cDefine14 ,cDefine15 ,cDefine16 ,cShipAddress ,
  198. caddcode ,bOMFirst ,bFromPreYear ,bIsComplement ,iDiscountTaxType ,
  199. ireturncount ,iverifystate ,iswfcontrolled ,dnmaketime ,dnverifytime ,
  200. iPrintCount ,cinvoicecompany)
  201. SELECT @ID,0,32,a.cBusType,'',a.cDLCode,@cWhCode,
  202. CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,'21',a.cDepCode,a.cPersonCode,a.cSTCode,a.cCusCode,
  203. a.DLID,@cHandler,a.cMemo,0,@cMaker,a.cDefine1,a.cDefine2,
  204. a.cDefine3,a.cDefine4,a.cDefine5,a.cDefine6,a.cDefine7,a.cDefine8,a.cDefine9,
  205. a.cDefine10,CONVERT(NVARCHAR(15),GETDATE(),23),0,0,@VT_ID,0,a.cDefine11,
  206. a.cDefine12,a.cDefine13,a.cDefine14,a.cDefine15,a.cDefine16,a.cShipAddress,
  207. a.caddcode,null,0,0,0,
  208. 0,0,0,GETDATE(),GETDATE(),
  209. 0,a.cinvoicecompany
  210. FROM dbo.DispatchList a WHERE a.cDLCode ='" + head.SDNRTCode + "'";
  211. cmd.Parameters.Clear();
  212. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  213. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  214. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  215. cmd.Parameters.Add(new SqlParameter("@cDepCode", ""));
  216. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  217. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  218. cmd.Parameters.Add(new SqlParameter("@VT_ID", iChildId));
  219. //cmd.Parameters.Add(new SqlParameter("@dDate", data.dMate));
  220. cmd.CommandText = sql;
  221. try
  222. {
  223. int count = cmd.ExecuteNonQuery();
  224. if (count <= 0)
  225. {
  226. log.Error("生成红字销售出库单表头失败,受影响行数<=0;");
  227. throw new Exception("生成红字销售出库单表头失败,受影响行数<=0;");
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. log.Error("生成红字销售出库单表头失败!销售出库单号:" + head.SDNNEGCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  233. throw new Exception("生成红字销售出库单表头失败!销售出库单号:" + head.SDNNEGCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  234. }
  235. #endregion
  236. #region 红字销售出库单表体
  237. foreach (ICSSalesShipmentDocNegatives body in head.details)
  238. {
  239. //iChildId -= 1;
  240. ////if (head.IsReturn == "1")
  241. ////{
  242. //body.Quantity = -body.Quantity;
  243. //}
  244. //else
  245. //{
  246. //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  247. //sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.InvCode + "'AND cBatch='" + "" + "'and cWhCode='" + head.WHCode + "'";
  248. //DataTable dtItem = DBHelper.SQlReturnData(sql, cmd);
  249. //if (dtItem != null && dtItem.Rows.Count > 0)
  250. //{
  251. // //if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
  252. // //{
  253. // // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  254. // //}
  255. // if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.Quantity)
  256. // {
  257. // throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.InvCode);
  258. // }
  259. //}
  260. //else
  261. //{
  262. // throw new Exception("物料:" + body.InvCode + "在现存量表中不存在!");
  263. //}
  264. //}
  265. sql = @"INSERT INTO dbo.rdrecords32
  266. ( AutoID ,ID ,cInvCode ,iQuantity ,cBatch ,iFlag ,
  267. cDefine22 ,cDefine23 ,cDefine24 ,cDefine25 ,cDefine26 ,
  268. cDefine27 ,cItem_class ,cItemCode ,iDLsID ,iNQuantity ,
  269. cDefine28 ,cDefine29 ,cDefine30 ,cDefine31 ,cDefine32 ,
  270. cDefine33 ,cDefine34 ,cDefine35 ,cDefine36 ,cDefine37 ,
  271. bLPUseFree ,iRSRowNO ,iOriTrackID ,ccusinvcode,ccusinvname,bCosting ,bVMIUsed ,
  272. cbdlcode ,iExpiratDateCalcu ,iorderdid ,iordertype ,
  273. iordercode ,iorderseq ,ipesodid ,ipesotype ,cpesocode ,
  274. ipesoseq ,isodid ,isotype ,csocode ,isoseq ,irowno ,
  275. bIAcreatebill ,bsaleoutcreatebill ,isaleoutid ,bneedbill,iposflag,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 )
  276. SELECT @AutoID,@ID,@cInvCode,@iQuantity,@cBatch,0,
  277. a.cDefine22,a.cDefine23,a.cDefine24,a.cDefine25,a.cDefine26,
  278. a.cDefine27,a.cItem_class,a.cItemCode,a.AutoID,a.iQuantity,
  279. a.cDefine28,a.cDefine29,a.cDefine30,a.cDefine31,a.cDefine32,
  280. a.cDefine33,a.cDefine34,a.cDefine35,a.cDefine36,a.cDefine37,
  281. 0,0,0,a.cCusInvCode,a.cCusInvName,1,0,
  282. b.cDLCode,0,a.iSOsID,1,
  283. d.cSOCode,c.iRowNo,a.iSOsID,1,d.cSOCode,
  284. 1,a.iSOsID,1,d.cSOCode,c.iRowNo,@irowno,
  285. 1,1,@AutoID,1,null,@cFree1,@cFree2,@cFree3,@cFree4,@cFree5,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10
  286. FROM dbo.DispatchLists a
  287. INNER JOIN dbo.DispatchList b ON a.DLID=b.DLID
  288. LEFT JOIN dbo.SO_SODetails c ON a.iSOsID=c.iSOsID
  289. LEFT JOIN dbo.SO_SOMain d ON c.ID=d.ID WHERE a.AutoID='" + body.SDNRTDetailID + "'";
  290. cmd.Parameters.Clear();
  291. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  292. cmd.Parameters.Add(new SqlParameter("@ID", 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("@cBatch", body.BatchCode));
  296. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  297. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  298. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  299. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  300. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  301. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  302. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  303. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  304. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  305. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  306. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  307. cmd.CommandText = sql;
  308. try
  309. {
  310. int count = cmd.ExecuteNonQuery();
  311. if (count <= 0)
  312. {
  313. log.Error("生成红字销售出库单表体失败,受影响行数<=0;");
  314. throw new Exception("生成红字销售出库单表体失败,受影响行数<=0;");
  315. }
  316. }
  317. catch (Exception ex)
  318. {
  319. log.Error("生成红字销售出库单表体失败!销售出库单号:" + head.SDNNEGCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  320. throw new Exception("生成红字销售出库单表体失败!销售出库单号:" + head.SDNNEGCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  321. }
  322. if (head.UpdateStock)
  323. {
  324. #region 更新现存量 现存量表待出库数量增加
  325. key.cBustypeUN = bustype;
  326. key.cVouchTypeUN = "32";
  327. key.TableName = "IA_ST_UnAccountVouch32";
  328. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", body.Quantity, key);
  329. DBHelper.UpdateCurrentStockNEW(cmd, body.InvCode, head.WHCode, body.BatchCode, body.Quantity, body.cFree1, body.cFree2, body.cFree3, body.cFree4, body.cFree5, body.cFree6, body.cFree7, body.cFree8, body.cFree9, body.cFree10, key);
  330. #endregion
  331. }
  332. log.Debug(sql);
  333. #region 回写销售订单累计发货数量,回写销售发货单累计出库数量
  334. sql = @"UPDATE a SET a.foutquantity=ISNULL(a.foutquantity,0)+" + -body.Quantity + @"
  335. FROM dbo.SO_SODetails a LEFT JOIN dbo.DispatchLists b ON a.iSOsID=b.iSOsID
  336. WHERE b.AutoID='" + body.SDNRTDetailID + "'";
  337. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写销售订单累计发货数量失败!");
  338. sql = "Update DispatchLists set fOutQuantity=isnull(fOutQuantity,0)+" + -body.Quantity + " where AutoID='" + body.SDNRTDetailID + "' ";
  339. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写销售发货单累计出库数量失败!");
  340. iFatherIdTwo += "'" + iFatherId + "',";
  341. iChildId--;
  342. #endregion
  343. }
  344. #endregion
  345. #region 查询
  346. sql = @"
  347. select distinct a.ID as ID, a.ID as IDs,a.cCode as SDNNEGCode,a.cCusCode as CusCode,
  348. c.cCusName as CusName,a.cWhCode as WHCode,d.cWhName as WHName,e.cordercode ,
  349. a.cMaker as CreateUser ,a.dnmaketime as CreateDateTime ,a.cHandler as Checker ,
  350. a.dnverifytime as CheckDateTime
  351. from rdrecord32 a
  352. left join DispatchLists e on a.cDLCode=e.DLID
  353. left join Customer c on a.cCusCode=c.cCusCode
  354. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1 and a.ID in({0})
  355. select distinct a.ID as IDs,b.AutoID as DetailID,b.irowno as Sequence,b.cInvCode as InvCode ,b.iQuantity as Quantity ,
  356. b.iNum as Amount,b.iDLsID as SDNRTDetailID
  357. from rdrecord32 a
  358. inner join rdrecords32 b on a.ID=b.ID
  359. left join Customer c on a.cCusCode=c.cCusCode
  360. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1 and a.ID in({0})";
  361. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  362. log.Debug(sql);
  363. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  364. dtNew1.Merge(ds.Tables[0]);
  365. dtNew2.Merge(ds.Tables[1]);
  366. #endregion
  367. cmd.Transaction.Commit();
  368. }
  369. catch (Exception ex)
  370. {
  371. cmd.Transaction.Rollback();
  372. log.Error(ex.Message);
  373. throw new Exception(ex.Message);
  374. }
  375. finally
  376. {
  377. if (conn.State == ConnectionState.Open)
  378. {
  379. conn.Close();
  380. }
  381. conn.Dispose();
  382. }
  383. }
  384. string RelationName = "details";
  385. DataRelation dh = new DataRelation(RelationName, dtNew1.Columns["IDs"], dtNew2.Columns["IDs"]);
  386. DataSet dz = new DataSet();
  387. dz.Relations.Add(dh);
  388. msg = DBHelper.DataSetToJson(dz, RelationName);
  389. return msg;
  390. }
  391. /// <summary>
  392. /// 删除销售出库单红字
  393. /// </summary>
  394. /// <param name="infos"></param>
  395. /// <returns></returns>
  396. public string Delete(List<ICSSalesShipmentDocNegative> infos)
  397. {
  398. List<ICSSalesShipmentDocNegative> szJson = new List<ICSSalesShipmentDocNegative>();
  399. if (infos.Count <= 0)
  400. {
  401. throw new Exception("传送数据为空!");
  402. }
  403. string res = string.Empty;
  404. string connS = "";
  405. SqlConnection conn = new SqlConnection();
  406. SqlCommand cmd = new SqlCommand();
  407. string sql = string.Empty;
  408. foreach (ICSSalesShipmentDocNegative info in infos)
  409. {
  410. try
  411. {
  412. connS = string.Format(connString, info.WorkPoint);
  413. conn = new System.Data.SqlClient.SqlConnection(connS);
  414. conn.Open();
  415. SqlTransaction sqlTran = conn.BeginTransaction();
  416. cmd = new SqlCommand();
  417. cmd.Transaction = sqlTran;
  418. cmd.Connection = conn;
  419. if (info.MTime < new DateTime(2000, 01, 01))
  420. throw new Exception("请输入正确的操作时间:" + info.MTime);
  421. sql = @"delete rdrecord11 where rdrecord32.ID='" + info.ID + "'";
  422. sql += @"delete rdrecords11 where rdrecords32.ID='" + info.ID + "'";
  423. //UPDATE dbo.rdrecord11 a SET cHandler='" + info.User + @"' ,
  424. // dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE()
  425. // WHERE a.ID='" + info.ID + "'";
  426. DBHelper.CmdExecuteNonQuery(sql, cmd, "删除红字销售出单失败!");
  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. return res;
  445. }
  446. /// <summary>
  447. /// 审核销售出库单
  448. /// </summary>
  449. /// <param name="infos"></param>
  450. /// <returns></returns>
  451. public string Approve(List<ICSSalesShipmentDocNegative> infos)
  452. {
  453. List<ICSSalesShipmentDocNegative> szJson = new List<ICSSalesShipmentDocNegative>();
  454. string connS = "";
  455. string json = "";
  456. if (infos.Count <= 0)
  457. {
  458. throw new Exception("传送数据为空!");
  459. }
  460. string res = string.Empty;
  461. SqlConnection conn = new SqlConnection();
  462. SqlCommand cmd = new SqlCommand();
  463. string sql = string.Empty;
  464. foreach (ICSSalesShipmentDocNegative info in infos)
  465. {
  466. try
  467. {
  468. connS = string.Format(connString, info.WorkPoint);
  469. conn = new System.Data.SqlClient.SqlConnection(connS);
  470. conn.Open();
  471. SqlTransaction sqlTran = conn.BeginTransaction();
  472. cmd = new SqlCommand();
  473. cmd.Transaction = sqlTran;
  474. cmd.Connection = conn;
  475. if (info.MTime < new DateTime(2000, 01, 01))
  476. throw new Exception("请输入正确的操作时间:" + info.MTime);
  477. sql = @"UPDATE rdrecord32 SET cHandler ='" + info.User + @"' ,
  478. dnverifytime=CONVERT(VARCHAR(50),GETDATE(),112),dVeriDate=GETDATE() WHERE ID='{0}'";
  479. sql = string.Format(sql, info.ID);
  480. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核红字销售出单失败!");
  481. cmd.Transaction.Commit();
  482. }
  483. catch (Exception ex)
  484. {
  485. cmd.Transaction.Rollback();
  486. log.Error(ex.Message);
  487. throw new Exception(ex.Message);
  488. }
  489. finally
  490. {
  491. if (conn.State == ConnectionState.Open)
  492. {
  493. conn.Close();
  494. }
  495. conn.Dispose();
  496. }
  497. }
  498. return json;
  499. }
  500. /// <summary>
  501. ///
  502. /// 记录日志
  503. /// </summary>
  504. /// <param name="Bills"></param>
  505. private void LogInfo(List<ICSSalesShipmentDocNegative> Bills)
  506. {
  507. string HeadList = string.Empty;
  508. string BodyList = string.Empty;
  509. foreach (ICSSalesShipmentDocNegative head in Bills)
  510. {
  511. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  512. foreach (ICSSalesShipmentDocNegatives body in head.details)
  513. {
  514. BodyList += "\r\n 表体主键ID: " + body.SDNRTDetailID + ",数量:" + body.Quantity;
  515. }
  516. }
  517. log.Info(HeadList);
  518. log.Info(BodyList);
  519. }
  520. }
  521. }