爱思开
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.

565 lines
29 KiB

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