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

561 lines
29 KiB

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