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

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