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

582 lines
30 KiB

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