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

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