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

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