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

557 lines
29 KiB

  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 SalesDeliveryNotice
  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["SaleDNCRDNAME"];
  23. string bustype = string.Empty;
  24. /// <summary>
  25. /// 获取销售发货
  26. /// </summary>
  27. /// <param name="infos"></param>
  28. /// <returns></returns>
  29. public string Get(List<ICSSalesDeliveryNotice> infos)
  30. {
  31. List<ICSSalesDeliveryNotice> szJson = new List<ICSSalesDeliveryNotice>();
  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. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  45. foreach (string WorkPoint in result)
  46. {
  47. try
  48. {
  49. connS = string.Format(connString, WorkPoint);
  50. conn = new System.Data.SqlClient.SqlConnection(connS);
  51. conn.Open();
  52. SqlTransaction sqlTran = conn.BeginTransaction();
  53. cmd = new SqlCommand();
  54. cmd.Transaction = sqlTran;
  55. cmd.Connection = conn;
  56. foreach (ICSSalesDeliveryNotice info in infos)
  57. {
  58. if (WorkPoint != info.WorkPoint)
  59. continue;
  60. ICSUserInfo userInfo = new ICSUserInfo();
  61. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  62. if (info.MTime < new DateTime(2000, 01, 01))
  63. throw new Exception("请输入正确的操作时间:" + info.MTime);
  64. sql = @" select a.DLID ,a.cDLCode ,a.cCusCode,c.cCusName,a.cDepCode ,
  65. d.cDepName,b.cordercode ,a.cMaker ,a.dcreatesystime ,
  66. b.AutoID ,b.irowno,b.cInvCode ,b.iQuantity ,b.iNum ,b.iSOsID
  67. FROM dbo.DispatchList a
  68. INNER JOIN dbo.DispatchLists b ON a.DLID = b.DLID
  69. LEFT JOIN dbo.Customer c ON a.cCusCode = c.cCusCode
  70. left join Department d on a.cDepCode=d.cDepCode ";
  71. if (!string.IsNullOrWhiteSpace(info.SDNCode))
  72. {
  73. sql += " and a.cDLCode='{0}'";
  74. }
  75. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  76. {
  77. sql += " and ISNULL(a.dnmodifytime ,ISNULL(a.dverifydate , ISNULL(a.dnmodifytime , a.dcreatesystime )))>='{1}'";
  78. }
  79. if (!string.IsNullOrWhiteSpace(info.User))
  80. {
  81. sql += "and a.CMAKER='{2}'";
  82. }
  83. sql = string.Format(sql, info.SOCode, info.MTime, userInfo.UserName);
  84. dt = DBHelper.SQlReturnData(sql, cmd);
  85. if (dt.Rows.Count <= 0 || dt == null)
  86. throw new Exception("销售发货单号:" + info.SOCode + ",无信息!");
  87. if (dtNew == null)
  88. dtNew = dt;
  89. else
  90. dtNew.Merge(dt);
  91. }
  92. cmd.Transaction.Commit();
  93. }
  94. catch (Exception ex)
  95. {
  96. cmd.Transaction.Rollback();
  97. log.Error(ex.Message);
  98. throw new Exception(ex.Message);
  99. }
  100. finally
  101. {
  102. if (conn.State == ConnectionState.Open)
  103. {
  104. conn.Close();
  105. }
  106. conn.Dispose();
  107. }
  108. }
  109. json = JsonConvert.SerializeObject(dtNew);
  110. return json;
  111. }
  112. /// <summary>
  113. /// 创建销售发货
  114. /// </summary>
  115. /// <param name="Bills"></param>
  116. /// <returns></returns>
  117. public string CerateSalesDeliveryNotice(List<ICSSalesDeliveryNotice> Bills)
  118. {
  119. string msg = "";
  120. DataTable dt = null;
  121. DataTable dtNew = null;
  122. string connS = "";
  123. //bool ResultFlag = false;
  124. SqlConnection conn = new SqlConnection();
  125. SqlCommand cmd = new SqlCommand();
  126. VouchKey key = new VouchKey();
  127. if (Bills.Count <= 0)
  128. {
  129. throw new Exception("传送数据为空!");
  130. }
  131. LogInfo(Bills);
  132. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  133. foreach (string WorkPoint in result)
  134. {
  135. try
  136. {
  137. connS = string.Format(connString, WorkPoint);
  138. conn = new System.Data.SqlClient.SqlConnection(connS);
  139. conn.Open();
  140. SqlTransaction sqlTran = conn.BeginTransaction();
  141. cmd = new SqlCommand();
  142. cmd.Transaction = sqlTran;
  143. cmd.Connection = conn;
  144. foreach (ICSSalesDeliveryNotice head in Bills)
  145. {
  146. string sql = "";
  147. if (WorkPoint != head.WorkPoint)
  148. continue;
  149. ICSUserInfo userInfo = new ICSUserInfo();
  150. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  151. string[] ss = head.WorkPoint.Split('_');
  152. ERPDB = ss[1];
  153. #region 销售发货单表头
  154. int num = 0;
  155. num = head.details.Count();
  156. string[] dd = CRNALL.Split('~');
  157. string crdname = dd[0];
  158. string carname = dd[1];
  159. string surface = dd[2];
  160. string SO_SOMain_VT_ID = DBHelper.GetDefaultTemplate("05", cmd);//目标账套销售订单VT_ID模板
  161. DateTime time = DateTime.Now;
  162. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", "DelNote", "" + num + "", head.WorkPoint);
  163. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  164. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  165. DateTime date = DateTime.Now;
  166. string iBaseCodeLen = DBHelper.GetAllRDCode("05", "" + time + "", "admin", "", head.WorkPoint);
  167. sql = string.Format(@"INSERT INTO dbo.DispatchList
  168. (@DLID , @cDLCode , @cVouchType , cSTCode ,CONVERT(NVARCHAR(50),GETDATE(),23)
  169. , @cDepCode ,SBVID , @cSOCode , @cCusCode , cPayCode
  170. , cSCCode, cCusOAddress , cexch_name , iExchRate , iTaxRate , 0 , bReturnFlag
  171. , bFirst , cMemo , cVerifier , cMaker , iSale, (select cCusName from {0}.dbo.Customer where cCusCode='@cCusCode')
  172. , iVTid , ufts , cBusType , cCloser , cAccounter , cCreChpName
  173. , bIAFirst , ioutgolden , cgatheringplan , dCreditStart , dGatheringDate , icreditdays , bCredit
  174. , caddcode , iverifystate , ireturncount , iswfcontrolled , icreditstate , bARFirst
  175. , cmodifier , dmoddate , dverifydate , ccusperson , dcreatesystime , dverifysystime , dmodifysystime
  176. , csvouchtype , iflowid , bsigncreate , bcashsale , cgathingcode , cChanger , cChangeMemo
  177. , outid , bmustbook , cBookDepcode , cBookType , bSaUsed , bneedbill , baccswitchflag
  178. , iPrintCount , ccuspersoncode , cSourceCode , bsaleoutcreatebill , cSysBarCode , cCurrentAuditor
  179. , csscode , cinvoicecompany , fEBweight , cEBweightUnit , cEBExpressCode , iEBExpressCoID
  180. , SeparateID , bNotToGoldTax , cEBTrnumber , cEBBuyer , cEBBuyerNote , ccontactname , cEBprovince
  181. , cEBcity , cEBdistrict , cmobilephone , cInvoiceCusName , cweighter , dweighttime , cPickVouchCode
  182. , cGCRouteCode)
  183. SELECT
  184. @DLID , @cDLCode , @cVouchType , cSTCode ,CONVERT(NVARCHAR(50),GETDATE(),23)
  185. , @cDepCode , 0 , @cSOCode , @cCusCode , cPayCode
  186. , cSCCode, cCusOAddress , cexch_name , iExchRate , iTaxRate , 0 , bReturnFlag
  187. , 0 , cMemo , cVerifier , @cMaker , 0 , (select cCusName from dbo.Customer where cCusCode='@cCusCode')
  188. , @iVTid , ufts , cBusType , cCloser , NULL , NULL
  189. , 0 , null , cgatheringplan , CONVERT(NVARCHAR(50),GETDATE(),23) ,NULL , NULL , 0
  190. , caddcode , iverifystate , ireturncount , iswfcontrolled , icreditstate , 0
  191. , NULL , NULL , NULL , ccusperson , CONVERT(NVARCHAR(50),GETDATE(),23) , dverifysystime , dmodifysystime
  192. , csvouchtype , iflowid , 0 , 0 , cgathingcode , NULL , NULL
  193. , outid , bmustbook , NULL , NULL , NULL , 0 , 0
  194. , 0 , ccuspersoncode , NULL , 0 , cSysBarCode , cCurrentAuditor
  195. , csscode , cinvoicecompany , NULL , NULL , NULL , NULL
  196. , NULL , 0 , NULL , NULL , NULL , NULL , NULL
  197. , NULL , NULL , NULL , NULL , NULL , NULL , NULL
  198. , NULL FROM SO_SOMain a
  199. where a.cSOCode ='" + head.SOCode + "'");
  200. cmd.Parameters.Clear();
  201. cmd.Parameters.Add(new SqlParameter("@DLID", iFatherId));
  202. cmd.Parameters.Add(new SqlParameter("@cDLCode", iBaseCodeLen));
  203. cmd.Parameters.Add(new SqlParameter("@cVouchType", "05"));
  204. cmd.Parameters.Add(new SqlParameter("@cDepCode", head.DepCode));
  205. cmd.Parameters.Add(new SqlParameter("@cMaker", userInfo.UserName));
  206. cmd.Parameters.Add(new SqlParameter("@cSOCode", head.SOCode));
  207. cmd.Parameters.Add(new SqlParameter("@cCusCode", head.CusCode));
  208. cmd.Parameters.Add(new SqlParameter("@iVTid", SO_SOMain_VT_ID));
  209. //cmd.Parameters.Add(new SqlParameter("@dDate", data.dMate));
  210. cmd.CommandText = sql;
  211. try
  212. {
  213. int count = cmd.ExecuteNonQuery();
  214. if (count <= 0)
  215. {
  216. log.Error("生成销售出库单表头失败,受影响行数<=0;");
  217. throw new Exception("生成销售出库单表头失败,受影响行数<=0;");
  218. }
  219. }
  220. catch (Exception ex)
  221. {
  222. log.Error("生成销售出库单表头失败!销售订单号:" + head.SDNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  223. throw new Exception("生成销售出库单表头失败!销售订单号:" + head.SDNCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  224. }
  225. #endregion
  226. #region 销售出库单表体
  227. foreach (ICSSalesDeliveryNotices body in head.details)
  228. {
  229. #region 销售顶订单表体
  230. sql = string.Format(@"INSERT INTO dbo.DispatchLists
  231. (AutoID , DLID , iCorID , cWhCode , cInvCode , iQuantity , iNum
  232. , iQuotedPrice , iUnitPrice , iTaxUnitPrice , iMoney , iTax , iSum , iDisCount , iNatUnitPrice
  233. , iNatMoney , iNatTax , iNatSum , iNatDisCount , iSettleNum , iSettleQuantity , iBatch , cBatch
  234. , bSettleAll , cMemo , iTB , dvDate , TBQuantity , TBNum , iSOsID , iDLsID
  235. , KL , KL2 , cInvName , iTaxRate
  236. , fOutQuantity , fOutNum , cItemCode , cItem_class , fSaleCost , fSalePrice , cVenAbbName
  237. , cItemName , cItem_CName
  238. , bIsSTQc , iInvExchRate , cUnitID , cCode , iRetQuantity , fEnSettleQuan , fEnSettleSum , iSettlePrice , dMDate , bGsp
  239. , cGspState , cSoCode , cCorCode , iPPartSeqID , iPPartID , iPPartQty , cContractID , cContractTagCode , cContractRowGuid
  240. , iMassDate , cMassUnit , bQANeedCheck , bQAUrgency , bQAChecking , bQAChecked , iQAQuantity , iQANum
  241. , cCusInvCode , cCusInvName , fsumsignquantity , fsumsignnum , cbaccounter , bcosting , cordercode
  242. , iorderrowno , fcusminprice , icostquantity , icostsum , ispecialtype , cvmivencode , iexchsum
  243. , imoneysum , irowno , frettbquantity , fretsum , iExpiratDateCalcu , dblPreExchMomey , dblPreMomey , idemandtype
  244. , cdemandcode , cdemandmemo , cdemandid , idemandseq , cvencode , cReasonCode , cInvSN , iInvSNCount , bneedsign
  245. , bsignover , bneedloss , flossrate , frlossqty , fulossqty , isettletype , crelacuscode , cLossMaker
  246. , dLossDate , dLossTime , icoridlsid , fretoutqty , body_outid , fVeriBillQty
  247. , fVeriBillSum , fVeriRetQty , fVeriRetSum , fLastSettleQty
  248. , fLastSettleSum , cBookWhcode , cInVouchType , cPosition , fretqtywkp , fretqtyykp , frettbqtyykp
  249. , fretsumykp , dkeepdate , cSCloser , isaleoutid , bsaleprice , bgift , bmpforderclosed
  250. , cbSysBarCode , fxjquantity , fxjnum
  251. , bIAcreatebill , cParentCode , cChildCode , fchildqty , fchildrate , iCalcType , fappretwkpqty , fappretwkpsum
  252. , fappretykpqty , fappretykpsum , fappretwkptbqty , fappretykptbqty , irtnappid , crtnappcode , fretailrealamount
  253. , fretailsettleamount , cFactoryCode , GCSourceId , GCSourceIds , cConfirmer , dConfirmDate )
  254. SELECT
  255. @AutoID , @DLID , @cWhCode , @cInvCode , @iQuantity , @iNum
  256. , iQuotedPrice , iUnitPrice , iTaxUnitPrice , iMoney , iTax , iSum , iDisCount , iNatUnitPrice
  257. , iNatMoney , iNatTax , iNatSum , iNatDisCount , NULL , NULL
  258. , 0 , cMemo , 0 , NULL , 0 , NULL , iSOsID , NULL
  259. , KL , KL2 , cInvName , iTaxRate
  260. , fOutQuantity , fOutNum , cItemCode , cItem_class , fSaleCost , fSalePrice ,NUll
  261. , cItemName , cItem_CName
  262. , 0 , iInvExchRate , cUnitID , NULL , 0 , 0 , 0 , 0 , NULL , 0
  263. , NULL , @cSoCode , NULL , iPPartSeqID , iPPartID , iPPartQty , cContractID , cContractTagCode , cContractRowGuid
  264. , NULL , NULL , 0 , 0 , 0 , 0 , 0 , 0
  265. , cCusInvCode , cCusInvName , 0 , 0 , NULL , 0 , @cordercode
  266. , NULL , fcusminprice , icostquantity , icostsum , NULL , NULL , iexchsum
  267. , imoneysum , @irowno , 0 , 0 , NULL , 0 , 0 , NULL
  268. , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL
  269. , NULL , NULL , NULL , 0 , 0 , NULL , NULL , NULL
  270. , NULL , NULL , NULL , NULL , NULL , NULL
  271. , NULL , NULL , NULL , NULL
  272. , NULL , NULL , NULL , NULL , NULL , NULL , NULL
  273. , NULL , NULL , NULL , isaleoutid , 1 , 0 , 0
  274. , cbSysBarCode , NULL , NULL
  275. , 1 , NULL , NULL , NULL , NULL , NULL , NULL , NULL
  276. , NULL , NULL , NULL , NULL , NULL , NULL , NULL
  277. , NULL , NULL , NULL , NULL , NULL , NULL FROM SO_SODetails a
  278. where a.AutoID ='" + body.SODetailID + "'");
  279. cmd.Parameters.Clear();
  280. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  281. cmd.Parameters.Add(new SqlParameter("@DLID", iFatherId));
  282. cmd.Parameters.Add(new SqlParameter("@cInvCode", body.InvCode));
  283. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  284. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount.ToString("0.00")));
  285. cmd.Parameters.Add(new SqlParameter("@cSoCode", head.SOCode));
  286. cmd.Parameters.Add(new SqlParameter("@cordercode", head.SOCode));
  287. cmd.Parameters.Add(new SqlParameter("@irowno", body.Sequence));
  288. //cmd.Parameters.Add(new SqlParameter("@dDate", data.dMate));
  289. cmd.CommandText = sql;
  290. try
  291. {
  292. int count = cmd.ExecuteNonQuery();
  293. if (count <= 0)
  294. {
  295. log.Error("生成销售出库单表体失败,受影响行数<=0;");
  296. throw new Exception("生成销售出库单表体失败,受影响行数<=0;");
  297. }
  298. }
  299. catch (Exception ex)
  300. {
  301. log.Error("生成销售出库单表体失败!销售订单号:" + head.SOCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  302. throw new Exception("生成销售出库单表体失败!销售订单号:" + head.SOCode + ";异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  303. }
  304. #endregion
  305. sql = @"UPDATE a SET a.foutquantity=ISNULL(a.foutquantity,0)+" + body.Quantity + @"
  306. FROM dbo.SO_SODetails a LEFT JOIN dbo.DispatchLists b ON a.iSOsID=b.iSOsID
  307. WHERE b.AutoID='" + body.SODetailID + "'";
  308. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写销售订单累计发货数量失败!");
  309. sql = @"select isnull(fOutQuantity,0)fOutQuantity,isnull(iQuantity,0)iQuantity,ISNULL(iNum, 0)iNum,ISNULL(NiNum, 0)NiNum,ISNULL(iNum, 0)-ISNULL(NiNum, 0) SiNum from SO_SODetails a
  310. LEFT JOIN (select sum(iNum) NiNum,iSOsID from DispatchLists GROUP BY iSOsID) b on a.iSOsID=b.iSOsID
  311. where a.AutoID='" + body.SODetailID + "'";
  312. DataTable dtDisCheck = DBHelper.SQlReturnData(sql, cmd);
  313. if (dtDisCheck != null && dtDisCheck.Rows.Count > 0)
  314. {
  315. foreach (DataRow item in dtDisCheck.Rows)
  316. {
  317. if (Convert.ToDecimal(item["fOutQuantity"].ToString()) == Convert.ToDecimal(item["iQuantity"].ToString()))
  318. {
  319. if (Convert.ToDecimal(item["iNum"].ToString()) != 0)
  320. {
  321. if (Convert.ToDecimal(item["SiNum"].ToString()) != 0)
  322. {
  323. sql = @"Update DispatchLists set iNum=isnull(iNum,0)+(" + item["SiNum"].ToString() + ") where autoid='" + iChildId + "' ";
  324. DBHelper.CmdExecuteNonQuery(sql, cmd, "辅计量余数处理失败!");
  325. }
  326. }
  327. }
  328. }
  329. }
  330. iChildId--;
  331. }
  332. #endregion
  333. sql = @"
  334. select a.DLID ,a.cDLCode ,a.cCusCode,c.cCusName,a.cDepCode ,
  335. d.cDepName,b.cordercode ,a.cMaker ,a.dcreatesystime ,
  336. b.AutoID ,b.irowno,b.cInvCode ,b.iQuantity ,b.iNum ,b.iSOsID
  337. FROM dbo.DispatchList a
  338. INNER JOIN dbo.DispatchLists b ON a.DLID = b.DLID
  339. LEFT JOIN dbo.Customer c ON a.cCusCode = c.cCusCode
  340. left join Department d on a.cDepCode=d.cDepCode WHERE a.DLID = '{0}' ";
  341. sql = string.Format(sql, iFatherId);
  342. dt = DBHelper.SQlReturnData(sql, cmd);
  343. if (dtNew == null)
  344. dtNew = dt;
  345. else
  346. dtNew.Merge(dt);
  347. }
  348. cmd.Transaction.Commit();
  349. }
  350. catch (Exception ex)
  351. {
  352. cmd.Transaction.Rollback();
  353. log.Error(ex.Message);
  354. throw new Exception(ex.Message);
  355. }
  356. finally
  357. {
  358. if (conn.State == ConnectionState.Open)
  359. {
  360. conn.Close();
  361. }
  362. conn.Dispose();
  363. }
  364. }
  365. msg = JsonConvert.SerializeObject(dtNew);
  366. cmd.Transaction.Commit();
  367. return msg;
  368. }
  369. /// <summary>
  370. /// 审核销售发货
  371. /// </summary>
  372. /// <param name="infos"></param>
  373. /// <returns></returns>
  374. public string Approve(List<ICSSalesDeliveryNotice> infos)
  375. {
  376. List<ICSSalesDeliveryNotice> szJson = new List<ICSSalesDeliveryNotice>();
  377. string connS = "";
  378. string json = "";
  379. if (infos.Count <= 0)
  380. {
  381. throw new Exception("传送数据为空!");
  382. }
  383. string res = string.Empty;
  384. SqlConnection conn = new SqlConnection();
  385. SqlCommand cmd = new SqlCommand();
  386. string sql = string.Empty;
  387. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  388. foreach (string WorkPoint in result)
  389. {
  390. try
  391. {
  392. connS = string.Format(connString, WorkPoint);
  393. conn = new System.Data.SqlClient.SqlConnection(connS);
  394. conn.Open();
  395. SqlTransaction sqlTran = conn.BeginTransaction();
  396. cmd = new SqlCommand();
  397. cmd.Transaction = sqlTran;
  398. cmd.Connection = conn;
  399. foreach (ICSSalesDeliveryNotice info in infos)
  400. {
  401. if (WorkPoint != info.WorkPoint)
  402. continue;
  403. ICSUserInfo userInfo = new ICSUserInfo();
  404. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  405. if (info.MTime < new DateTime(2000, 01, 01))
  406. throw new Exception("请输入正确的操作时间:" + info.MTime);
  407. sql = @"UPDATE DispatchList SET cMaker ='" + userInfo.UserName + @"' ,
  408. dverifysystime =CONVERT(VARCHAR(50),GETDATE(),112),dverifydate =GETDATE() WHERE DLID='{0}'";
  409. sql = string.Format(sql, info.ID);
  410. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  411. }
  412. cmd.Transaction.Commit();
  413. }
  414. catch (Exception ex)
  415. {
  416. cmd.Transaction.Rollback();
  417. log.Error(ex.Message);
  418. throw new Exception(ex.Message);
  419. }
  420. finally
  421. {
  422. if (conn.State == ConnectionState.Open)
  423. {
  424. conn.Close();
  425. }
  426. conn.Dispose();
  427. }
  428. }
  429. return json;
  430. }
  431. /// <summary>
  432. /// 删除销售发货
  433. /// </summary>
  434. /// <param name="infos"></param>
  435. /// <returns></returns>
  436. public string Delete(List<ICSSalesDeliveryNotice> infos)
  437. {
  438. List<ICSSalesDeliveryNotice> szJson = new List<ICSSalesDeliveryNotice>();
  439. if (infos.Count <= 0)
  440. {
  441. throw new Exception("传送数据为空!");
  442. }
  443. string res = string.Empty;
  444. string connS = "";
  445. SqlConnection conn = new SqlConnection();
  446. SqlCommand cmd = new SqlCommand();
  447. string sql = string.Empty;
  448. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  449. foreach (string WorkPoint in result)
  450. {
  451. try
  452. {
  453. connS = string.Format(connString, WorkPoint);
  454. conn = new System.Data.SqlClient.SqlConnection(connS);
  455. conn.Open();
  456. SqlTransaction sqlTran = conn.BeginTransaction();
  457. cmd = new SqlCommand();
  458. cmd.Transaction = sqlTran;
  459. cmd.Connection = conn;
  460. foreach (ICSSalesDeliveryNotice info in infos)
  461. {
  462. if (WorkPoint != info.WorkPoint)
  463. continue;
  464. if (info.MTime < new DateTime(2000, 01, 01))
  465. throw new Exception("请输入正确的操作时间:" + info.MTime);
  466. sql = @" DELETE DispatchList WHERE DLID={0}";
  467. sql = string.Format(sql, info.ID);
  468. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  469. }
  470. cmd.Transaction.Commit();
  471. }
  472. catch (Exception ex)
  473. {
  474. cmd.Transaction.Rollback();
  475. log.Error(ex.Message);
  476. throw new Exception(ex.Message);
  477. }
  478. finally
  479. {
  480. if (conn.State == ConnectionState.Open)
  481. {
  482. conn.Close();
  483. }
  484. conn.Dispose();
  485. }
  486. }
  487. return res;
  488. }
  489. /// <summary>
  490. ///
  491. /// 记录日志
  492. /// </summary>
  493. /// <param name="Bills"></param>
  494. private void LogInfo(List<ICSSalesDeliveryNotice> Bills)
  495. {
  496. string HeadList = string.Empty;
  497. string BodyList = string.Empty;
  498. foreach (ICSSalesDeliveryNotice head in Bills)
  499. {
  500. HeadList += "\r\n 表头主键ID:" + head.ID + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  501. foreach (ICSSalesDeliveryNotices body in head.details)
  502. {
  503. BodyList += "\r\n 表体主键ID:数量:" + body.Quantity;
  504. }
  505. }
  506. log.Info(HeadList);
  507. log.Info(BodyList);
  508. }
  509. }
  510. }