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

602 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
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
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 ,
  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,
  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("@cBatch", body.BatchCode));
  332. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  333. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  334. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  335. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  336. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  337. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  338. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  339. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  340. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  341. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  342. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  343. cmd.CommandText = sql;
  344. try
  345. {
  346. int count = cmd.ExecuteNonQuery();
  347. if (count <= 0)
  348. {
  349. log.Error("生成销售出库单表体失败,受影响行数<=0;");
  350. throw new Exception("生成销售出库单表体失败,受影响行数<=0;");
  351. }
  352. }
  353. catch (Exception ex)
  354. {
  355. log.Error("生成销售出库单表体失败!销售出库单号:" + head.SSDCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  356. throw new Exception("生成销售出库单表体失败!销售出库单号:" + head.SSDCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  357. }
  358. if (head.UpdateStock)
  359. {
  360. #region 更新现存量 现存量表待出库数量扣减
  361. key.cBustypeUN = bustype;
  362. key.cVouchTypeUN = "32";
  363. key.TableName = "IA_ST_UnAccountVouch32";
  364. 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);
  365. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", -body.Quantity, key);
  366. #endregion
  367. }
  368. log.Debug(sql);
  369. #region 回写销售订单累计发货数量,回写销售发货单累计出库数量
  370. sql = @"UPDATE a SET a.foutquantity=ISNULL(a.foutquantity,0)+" + body.Quantity + @"
  371. FROM dbo.SO_SODetails a LEFT JOIN dbo.DispatchLists b ON a.iSOsID=b.iSOsID
  372. WHERE b.AutoID='" + body.SDNDetailID + "'";
  373. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写销售订单累计发货数量失败!");
  374. sql = @"Update DispatchList set cSaleOut='" + status + "' where DLID=(select DLID from DispatchLists where AutoID='" + body.SDNDetailID + @"')
  375. Update DispatchLists set fOutQuantity=isnull(fOutQuantity,0)+" + body.Quantity + " where AutoID='" + body.SDNDetailID + "' ";
  376. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写销售发货单累计出库数量失败!");
  377. iFatherIdTwo += "'" + iFatherId + "',";
  378. iChildId--;
  379. #endregion
  380. }
  381. #endregion
  382. #region 查询
  383. sql = @"
  384. select distinct a.ID as ID, a.ID as IDs,a.cCode as SSDCode,a.cCusCode as CusCode,
  385. c.cCusName as CusName,a.cWhCode as WHCode,d.cWhName as WHName,e.cordercode ,
  386. a.cMaker as CreateUser ,a.dnmaketime as CreateDateTime ,a.cHandler as Checker ,
  387. a.dnverifytime as CheckDateTime
  388. from rdrecord32 a
  389. left join DispatchLists e on a.cDLCode=e.DLID
  390. left join Customer c on a.cCusCode=c.cCusCode
  391. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1 and a.ID in({0})
  392. select distinct a.ID as IDs,b.AutoID as DetailID,b.irowno as Sequence,b.cInvCode as InvCode ,b.iQuantity as Quantity ,
  393. b.iNum as Amount,e.autoid as SDNDetailID
  394. from rdrecord32 a
  395. inner join rdrecords32 b on a.ID=b.ID
  396. left join DispatchLists e on b.iDLsID=e.iDLsID
  397. left join Customer c on a.cCusCode=c.cCusCode
  398. left join Warehouse d on a.cWhCode=d.cWhCode WHERE 1=1 and a.ID in({0})";
  399. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  400. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  401. if (dtNew1 == null)
  402. dtNew1 = ds.Tables[0];
  403. else
  404. dtNew1.Merge(ds.Tables[0]);
  405. if (dtNew2 == null)
  406. dtNew2 = ds.Tables[1];
  407. else
  408. dtNew2.Merge(ds.Tables[1]);
  409. #endregion
  410. cmd.Transaction.Commit();
  411. }
  412. catch (Exception ex)
  413. {
  414. cmd.Transaction.Rollback();
  415. log.Error(ex.Message);
  416. throw new Exception(ex.Message);
  417. }
  418. finally
  419. {
  420. if (conn.State == ConnectionState.Open)
  421. {
  422. conn.Close();
  423. }
  424. conn.Dispose();
  425. }
  426. }
  427. string RelationName = "details";
  428. DataSet dz = new DataSet();
  429. dtNew1.TableName = "Table0";
  430. dtNew2.TableName = "Table1";
  431. dz.Tables.Add(dtNew1.Copy());
  432. dz.Tables.Add(dtNew2.Copy());
  433. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  434. dz.Relations.Add(dh);
  435. msg = DBHelper.DataSetToJson(dz, RelationName);
  436. return msg;
  437. }
  438. /// <summary>
  439. /// 审核销售出库单
  440. /// </summary>
  441. /// <param name="infos"></param>
  442. /// <returns></returns>
  443. public string Approve(List<ICSSalesShipmentDoc> infos)
  444. {
  445. List<ICSSalesShipmentDoc> szJson = new List<ICSSalesShipmentDoc>();
  446. string connS = "";
  447. string json = "";
  448. if (infos.Count <= 0)
  449. {
  450. throw new Exception("传送数据为空!");
  451. }
  452. string res = string.Empty;
  453. SqlConnection conn = new SqlConnection();
  454. SqlCommand cmd = new SqlCommand();
  455. string sql = string.Empty;
  456. foreach (ICSSalesShipmentDoc info in infos)
  457. {
  458. try
  459. {
  460. connS = string.Format(connString, info.WorkPoint);
  461. conn = new System.Data.SqlClient.SqlConnection(connS);
  462. conn.Open();
  463. SqlTransaction sqlTran = conn.BeginTransaction();
  464. cmd = new SqlCommand();
  465. cmd.Transaction = sqlTran;
  466. cmd.Connection = conn;
  467. if (info.MTime < new DateTime(2000, 01, 01))
  468. throw new Exception("请输入正确的操作时间:" + info.MTime);
  469. sql = @"UPDATE rdrecord32 SET cHandler ='" + info.User + @"' ,
  470. dnverifytime=CONVERT(VARCHAR(50),GETDATE(),112),dVeriDate=GETDATE() WHERE ID='{0}'";
  471. sql = string.Format(sql, info.ID);
  472. DBHelper.CmdExecuteNonQuery(sql, cmd, "审核销售出单失败!");
  473. cmd.Transaction.Commit();
  474. }
  475. catch (Exception ex)
  476. {
  477. cmd.Transaction.Rollback();
  478. log.Error(ex.Message);
  479. throw new Exception(ex.Message);
  480. }
  481. finally
  482. {
  483. if (conn.State == ConnectionState.Open)
  484. {
  485. conn.Close();
  486. }
  487. conn.Dispose();
  488. }
  489. }
  490. return json;
  491. }
  492. /// <summary>
  493. /// 删除销售出库单
  494. /// </summary>
  495. /// <param name="infos"></param>
  496. /// <returns></returns>
  497. public string Delete(List<ICSSalesShipmentDoc> infos)
  498. {
  499. List<ICSSalesShipmentDoc> szJson = new List<ICSSalesShipmentDoc>();
  500. if (infos.Count <= 0)
  501. {
  502. throw new Exception("传送数据为空!");
  503. }
  504. string res = string.Empty;
  505. string connS = "";
  506. SqlConnection conn = new SqlConnection();
  507. SqlCommand cmd = new SqlCommand();
  508. string sql = string.Empty;
  509. foreach (ICSSalesShipmentDoc 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 = @"delete rdrecord11 where rdrecord32.ID='" + info.ID + "'";
  523. sql += @"delete rdrecords11 where rdrecords32.ID='" + info.ID + "'";
  524. //UPDATE dbo.rdrecord11 a SET cHandler='" + info.User + @"' ,
  525. // dVeriDate=CONVERT(VARCHAR(50),GETDATE(),112),dnverifytime=GETDATE()
  526. // WHERE a.ID='" + info.ID + "'";
  527. DBHelper.CmdExecuteNonQuery(sql, cmd, "删除销售出单失败!");
  528. cmd.Transaction.Commit();
  529. }
  530. catch (Exception ex)
  531. {
  532. cmd.Transaction.Rollback();
  533. log.Error(ex.Message);
  534. throw new Exception(ex.Message);
  535. }
  536. finally
  537. {
  538. if (conn.State == ConnectionState.Open)
  539. {
  540. conn.Close();
  541. }
  542. conn.Dispose();
  543. }
  544. }
  545. return res;
  546. }
  547. /// <summary>
  548. ///
  549. /// 记录日志
  550. /// </summary>
  551. /// <param name="Bills"></param>
  552. private void LogInfo(List<ICSSalesShipmentDoc> Bills)
  553. {
  554. string HeadList = string.Empty;
  555. string BodyList = string.Empty;
  556. foreach (ICSSalesShipmentDoc head in Bills)
  557. {
  558. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  559. foreach (ICSSalesShipmentDocs body in head.details)
  560. {
  561. BodyList += "\r\n 表体主键ID: " + body.SDNDetailID + ",数量:" + body.Quantity;
  562. }
  563. }
  564. log.Info(HeadList);
  565. log.Info(BodyList);
  566. }
  567. }
  568. }