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

579 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
2 years ago
3 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
2 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 OutsourcingIssueDoc
  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["OutIssCRDNAME"];
  23. public string Get(List<ICSOutsourcingIssueDoc> infos)
  24. {
  25. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  26. DataTable dt = null;
  27. string json = "";
  28. DataTable dtNew = null;
  29. string connS = "";
  30. if (infos.Count <= 0)
  31. {
  32. throw new Exception("传送数据为空!");
  33. }
  34. string res = string.Empty;
  35. SqlConnection conn = new SqlConnection();
  36. SqlCommand cmd = new SqlCommand();
  37. string sql = string.Empty;
  38. foreach (ICSOutsourcingIssueDoc info in infos)
  39. {
  40. try
  41. {
  42. connS = string.Format(connString, info.WorkPoint);
  43. conn = new System.Data.SqlClient.SqlConnection(connS);
  44. conn.Open();
  45. SqlTransaction sqlTran = conn.BeginTransaction();
  46. cmd = new SqlCommand();
  47. cmd.Transaction = sqlTran;
  48. cmd.Connection = conn;
  49. if (info.MTime < new DateTime(2000, 01, 01))
  50. throw new Exception("请输入正确的操作时间:" + info.MTime);
  51. sql = @"select a.ID as ID,a.ID as IDs,a.cCode as IssueCode,a.cDepCode,c.cDepName,a.cWhCode,
  52. d.cWhName,a.cSource,cMPoCode,a.cMaker,dnmaketime,cHandler,dnverifytime
  53. from rdrecord11 a
  54. left join Department c on a.cDepCode=c.cDepCode
  55. left join Warehouse d on a.cWhCode=d.cWhCode
  56. where a.cBusType=''
  57. select a.ID as IDs,iMPoIds as SourceDetailID ,b.irowno as Sequence,iordercode,b.cInvCode,b.iQuantity,b.iNum,b.AutoID as DetailID
  58. from rdrecord11 a
  59. left join rdrecords11 b on a.ID=b.ID
  60. left join Department c on a.cDepCode=c.cDepCode
  61. left join Warehouse d on a.cWhCode=d.cWhCode
  62. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  63. where a.cBusType=''";
  64. if (!string.IsNullOrWhiteSpace(info.IssueCode))
  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.IssueCode, info.MTime, info.User);
  77. dt = DBHelper.SQlReturnData(sql, cmd);
  78. if (dt.Rows.Count <= 0 || dt == null)
  79. throw new Exception("委外发料单:" + info.IssueCode + ",无信息!");
  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. public string CreateOutsourcingIssueDoc(List<ICSOutsourcingIssueDoc> Bills)
  105. {
  106. string msg = "";
  107. string sql = string.Empty;
  108. DataTable dtNew1 = null;
  109. DataTable dtNew2 = null;
  110. string connS = "";
  111. int num = 0;
  112. //取得out库单的默认显示模版
  113. //取得采购入库单单据 表头ID,表体DID
  114. VouchKey key = new VouchKey();
  115. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  116. SqlCommand cmd = new SqlCommand();
  117. if (Bills.Count <= 0)
  118. {
  119. throw new Exception("传送数据为空!");
  120. }
  121. LogInfo(Bills);
  122. foreach (ICSOutsourcingIssueDoc head in Bills)
  123. {
  124. try
  125. {
  126. string iFatherIdTwo = "";
  127. connS = string.Format(connString, head.WorkPoint);
  128. conn = new System.Data.SqlClient.SqlConnection(connS);
  129. conn.Open();
  130. SqlTransaction sqlTran = conn.BeginTransaction();
  131. cmd = new SqlCommand();
  132. cmd.Transaction = sqlTran;
  133. cmd.Connection = conn;
  134. string[] ss = head.WorkPoint.Split('_');
  135. ERPDB = ss[1];
  136. if (DBHelper.IsInventoryConsolidation(cmd, head.WorkPoint))
  137. {
  138. }
  139. else
  140. {
  141. throw new Exception("U8正在整理现存量,请稍后再试");
  142. }
  143. num = head.details.Count();
  144. string[] dd = CRNALL.Split('~');
  145. string crdname = dd[0];
  146. string carname = dd[1];
  147. string surface = dd[2];
  148. string cardnewcode = DBHelper.GetCardNumber(carname, cmd);
  149. string cRDcode = DBHelper.GetRDCode(crdname, cmd);
  150. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", surface, "" + num + "", head.WorkPoint);
  151. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  152. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  153. DateTime date = DateTime.Now;
  154. string iBaseCodeLen = DBHelper.GetAllRDCode(cardnewcode, "" + date + "", "admin", head.WorkPoint);
  155. string DEF_ID = DBHelper.GetDefaultTemplate(cardnewcode, cmd);
  156. if (head.details.Count <= 0)
  157. {
  158. throw new Exception("表体信息不存在!");
  159. }
  160. #region 判断委外订单是否已关闭
  161. sql = @"SELECT distinct isnull(b.cbCloser,'') as CloseUser
  162. from dbo.OM_MOMaterials a
  163. INNER JOIN OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  164. where a.MOMaterialsID='" + head.details[0].SourceDetailID + "'";
  165. DataTable dtClose = DBHelper.SQlReturnData(sql, cmd);
  166. if (dtClose != null && dtClose.Rows.Count > 0)
  167. {
  168. if (!string.IsNullOrEmpty(dtClose.Rows[0][0].ToString()))
  169. {
  170. throw new Exception("该委外订单行已关闭,无法领料!");
  171. }
  172. }
  173. #endregion
  174. #region 判断物料是否超额领取
  175. foreach (ICSOutsourcingIssueDocs body in head.details)
  176. {
  177. sql = @"SELECT isnull(b.fOutExcess,0) as fOutExcess,isnull(a.iSendQTY,0) as IssQty,a.iQuantity
  178. FROM dbo.OM_MOMaterials a
  179. LEFT JOIN dbo.Inventory b ON a.cInvCode=b.cInvCode
  180. WHERE a.MOMaterialsID='" + body.SourceDetailID + "'";
  181. DataTable dtQty = DBHelper.SQlReturnData(sql, cmd);
  182. // if (dtQty != null && dtQty.Rows.Count > 0)
  183. // {
  184. // //可超领比率
  185. // decimal fOutExcess = Convert.ToDecimal(dtQty.Rows[0]["fOutExcess"]);
  186. // //已领数量
  187. // decimal IssQty = Convert.ToDecimal(dtQty.Rows[0]["IssQty"]);
  188. // //应领数量
  189. // decimal Qty = Convert.ToDecimal(dtQty.Rows[0]["iQuantity"]);
  190. // //当前可总领数量
  191. // decimal TotalQty = Qty + fOutExcess * Qty;
  192. // if (head.IsReturn != "1")
  193. // {
  194. // if (IssQty + body.Quantity > TotalQty)
  195. // {
  196. // throw new Exception("物料领取超过当前可领用最大数,AllocateId:" + body.SourceDetailID);
  197. // }
  198. // }
  199. // else
  200. // {
  201. // if (IssQty < body.Quantity)
  202. // {
  203. // throw new Exception("物料退料超过当前已领用最大数,AllocateId:" + body.SourceDetailID);
  204. // }
  205. // }
  206. // }
  207. // else
  208. // {
  209. // throw new Exception("委外订单行子件不存在!AllocateId:" + body.SourceDetailID);
  210. // }
  211. //}
  212. }
  213. #endregion
  214. #region 委外材料出库单表头
  215. sql = @"
  216. INSERT INTO dbo.rdrecord11
  217. ( ID ,bRdFlag ,cVouchType ,cBusType ,cSource ,
  218. cWhCode ,dDate ,cCode ,cRdCode ,cDepCode,
  219. cPersonCode,cHandler ,bTransFlag ,cMaker ,dVeriDate ,
  220. bpufirst ,biafirst ,VT_ID ,bIsSTQc ,cPsPcode ,
  221. cMPoCode ,iproorderid ,bFromPreYear ,bIsLsQuery ,bIsComplement ,
  222. iDiscountTaxType ,ireturncount ,iverifystate ,iswfcontrolled ,dnmaketime ,
  223. dnverifytime ,bredvouch ,iPrintCount,cVenCode,iMQuantity)
  224. SELECT distinct @ID,0,'11','','',
  225. @cWhCode,CONVERT(NVARCHAR(15),GETDATE(),23),@cCode,@cRDcode,c.cDepCode,
  226. c.cPersonCode,@cHandler,0,@cMaker,CONVERT(NVARCHAR(15),GETDATE(),23),
  227. 0,0,@VT_ID,0,b.cInvCode,
  228. c.cCode,a.MoId,0,0,0,
  229. 0,0,0,0,GETDATE(),
  230. GETDATE(),0,0,c.cVenCode,b.iQuantity
  231. from dbo.OM_MOMaterials a
  232. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID = b.MoDetailsID
  233. LEFT JOIN dbo.OM_MOMain c ON b.MOID = c.MOID
  234. WHERE a.MOMaterialsID='" + head.details[0].SourceDetailID + "'";
  235. cmd.Parameters.Clear();
  236. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  237. cmd.Parameters.Add(new SqlParameter("@cWhCode", head.WHCode));
  238. cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  239. cmd.Parameters.Add(new SqlParameter("@cHandler", head.User));
  240. cmd.Parameters.Add(new SqlParameter("@cMaker", head.User));
  241. cmd.Parameters.Add(new SqlParameter("@VT_ID", DEF_ID));
  242. cmd.Parameters.Add(new SqlParameter("@cRDcode", cRDcode));
  243. cmd.CommandText = sql;
  244. try
  245. {
  246. int count = cmd.ExecuteNonQuery();
  247. if (count <= 0)
  248. {
  249. log.Error("生成委外发料单表头失败,受影响行数<=0;");
  250. throw new Exception("生成委外发料单表头失败,受影响行数<=0;");
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. log.Error("生成委外发料单表头失败!SQL:\r\n" + sql, ex);
  256. throw new Exception("生成委外发料单表头失败!SQL:\r\n" + sql, ex);
  257. }
  258. #endregion
  259. #region 委外材料出库单表体
  260. string iNQuantity = "";
  261. int irowno = 0;
  262. foreach (ICSOutsourcingIssueDocs body in head.details)
  263. {
  264. irowno++;
  265. //if (head.IsReturn == "1")
  266. //{
  267. // body.iQuantity = -body.iQuantity;
  268. // iNQuantity = "-a.iQuantity";
  269. //}
  270. //else
  271. //{
  272. iNQuantity = "a.iQuantity";
  273. //}
  274. //if (head.IsReturn == "0")
  275. //{
  276. // //判断物料批号与现存量表批号是否一致、数量不能超过现存量物料数量
  277. // sql = @"SELECT cBatch,iQuantity from CurrentStock WHERE cInvCode='" + body.cInvCode + "'AND cBatch='" + body.cBatch + "'and cWhCode='" + head.cWhCode + "'";
  278. // DataTable dtItem = U8Helper.SQlReturnData(sql, cmd);
  279. // if (dtItem != null && dtItem.Rows.Count > 0)
  280. // {
  281. // if (!dtItem.Rows[0]["cBatch"].ToString().Equals(body.cBatch))
  282. // {
  283. // throw new Exception("物料条码的批号与U8现存量物料批号不一致,物料:" + body.cInvCode);
  284. // }
  285. // if (Convert.ToDecimal(dtItem.Rows[0]["iQuantity"].ToString()) < body.iQuantity)
  286. // {
  287. // throw new Exception("物料条码的数量大于U8现存量物料数量,物料:" + body.cInvCode);
  288. // }
  289. // }
  290. // else
  291. // {
  292. // throw new Exception("物料:" + body.cInvCode + "在现存量表中不存在!");
  293. // }
  294. //}
  295. sql = @"INSERT INTO dbo.rdrecords11
  296. ( AutoID,ID ,cInvCode,iQuantity ,cBatch ,iNum,
  297. iFlag ,cItemCode ,cName ,iNQuantity ,iMPoIds ,
  298. bLPUseFree ,iOriTrackID ,bCosting ,bVMIUsed ,cmocode ,
  299. invcode ,imoseq ,iopseq ,iExpiratDateCalcu ,iorderdid ,
  300. iordertype ,isotype ,ipesodid ,ipesotype ,cpesocode ,
  301. ipesoseq ,irowno ,bcanreplace ,iposflag,iOMoDID,
  302. iOMoMID,comcode)
  303. SELECT distinct
  304. @AutoID,@ID,@InvCode,@iQuantity,@cBatch,@iNum,
  305. 0,null,null,@iQuantity,NULL,
  306. 0,0,1,0,NULL,
  307. b.cInvCode,NULL,NULL,0,0,
  308. 0,0,a.MOMaterialsID,'6',c.cCode,
  309. NULL, @irowno,0,NULL,b.MODetailsID,
  310. a.MOMaterialsID,c.cCode
  311. FROM dbo.OM_MOMaterials a
  312. INNER JOIN dbo.OM_MODetails b ON a.MoDetailsID=b.MODetailsID
  313. INNER JOIN dbo.OM_MOMain c ON b.MOID=c.MOID
  314. WHERE a.MOMaterialsID='" + body.SourceDetailID + "'";
  315. cmd.Parameters.Clear();
  316. cmd.Parameters.Add(new SqlParameter("@AutoID", iChildId));
  317. cmd.Parameters.Add(new SqlParameter("@ID", iFatherId));
  318. cmd.Parameters.Add(new SqlParameter("@iQuantity", body.Quantity));
  319. cmd.Parameters.Add(new SqlParameter("@iNum", body.Amount));
  320. //cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen));
  321. cmd.Parameters.Add(new SqlParameter("@InvCode", body.InvCode));
  322. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  323. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  324. cmd.Parameters.Add(new SqlParameter("@iNQuantity", iNQuantity));
  325. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  326. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  327. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  328. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  329. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  330. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  331. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  332. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  333. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  334. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  335. cmd.CommandText = sql;
  336. try
  337. {
  338. int count = cmd.ExecuteNonQuery();
  339. if (count <= 0)
  340. {
  341. log.Error("生成委外发料单表体失败,受影响行数<=0;");
  342. throw new Exception("生成委外发料单表体失败,受影响行数<=0;");
  343. }
  344. }
  345. catch (Exception ex)
  346. {
  347. log.Error("生成委外发料单表体失败" + sql, ex);
  348. throw new Exception("生成委外发料单表体失败 " + sql, ex);
  349. }
  350. if (head.UpdateStock)
  351. {
  352. //更新现存量
  353. key.cBustypeUN = "委外发料";
  354. key.cVouchTypeUN = "11";
  355. key.TableName = "IA_ST_UnAccountVouch11";
  356. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", -body.Quantity, key);
  357. 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);
  358. }
  359. #region 回写工单子件已领数量
  360. sql = "update OM_MOMaterials set iSendQTY=isnull(iSendQTY,0)+" + body.Quantity + ",fsendapplyqty=isnull(fsendapplyqty,0)+" + body.Quantity + @" where MOMaterialsID='" + body.SourceDetailID + "' ";
  361. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写委外订单子件已领数量失败!");
  362. #endregion
  363. iFatherIdTwo += "'" + iFatherId + "',";
  364. iChildId--;
  365. }
  366. #endregion
  367. #region 查询
  368. sql = @"select a.ID as ID,a.ID as IDs,a.cCode as IssueCode,a.cDepCode,c.cDepName,a.cWhCode,
  369. d.cWhName,a.cSource,cMPoCode,a.cMaker,dnmaketime,cHandler,dnverifytime
  370. from rdrecord11 a
  371. left join Department c on a.cDepCode=c.cDepCode
  372. left join Warehouse d on a.cWhCode=d.cWhCode
  373. where a.cBusType=''and a.ID in ({0})
  374. select a.ID as IDs,iOMoMID as SourceDetailID ,b.irowno as Sequence,iordercode,b.cInvCode,b.iQuantity,b.iNum,b.AutoID as DetailID
  375. from rdrecord11 a
  376. left join rdrecords11 b on a.ID=b.ID
  377. left join Department c on a.cDepCode=c.cDepCode
  378. left join Warehouse d on a.cWhCode=d.cWhCode
  379. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  380. where a.cBusType=''and a.ID in ({0})";
  381. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  382. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  383. if (dtNew1 == null)
  384. dtNew1 = ds.Tables[0];
  385. else
  386. dtNew1.Merge(ds.Tables[0]);
  387. if (dtNew2 == null)
  388. dtNew2 = ds.Tables[1];
  389. else
  390. dtNew2.Merge(ds.Tables[1]);
  391. #endregion
  392. cmd.Transaction.Commit();
  393. }
  394. catch (Exception ex)
  395. {
  396. cmd.Transaction.Rollback();
  397. log.Error(ex.Message);
  398. throw new Exception(ex.Message);
  399. }
  400. finally
  401. {
  402. if (conn.State == ConnectionState.Open)
  403. {
  404. conn.Close();
  405. }
  406. conn.Dispose();
  407. }
  408. }
  409. string RelationName = "details";
  410. DataSet dz = new DataSet();
  411. dtNew1.TableName = "Table0";
  412. dtNew2.TableName = "Table1";
  413. dz.Tables.Add(dtNew1.Copy());
  414. dz.Tables.Add(dtNew2.Copy());
  415. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  416. dz.Relations.Add(dh);
  417. msg = DBHelper.DataSetToJson(dz, RelationName);
  418. return msg;
  419. }
  420. public string Approve(List<ICSOutsourcingIssueDoc> infos)
  421. {
  422. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  423. string connS = "";
  424. string json = "";
  425. if (infos.Count <= 0)
  426. {
  427. throw new Exception("传送数据为空!");
  428. }
  429. string res = string.Empty;
  430. SqlConnection conn = new SqlConnection();
  431. SqlCommand cmd = new SqlCommand();
  432. string sql = string.Empty;
  433. foreach (ICSOutsourcingIssueDoc info in infos)
  434. {
  435. try
  436. {
  437. connS = string.Format(connString, info.WorkPoint);
  438. conn = new System.Data.SqlClient.SqlConnection(connS);
  439. conn.Open();
  440. SqlTransaction sqlTran = conn.BeginTransaction();
  441. cmd = new SqlCommand();
  442. cmd.Transaction = sqlTran;
  443. cmd.Connection = conn;
  444. if (info.MTime < new DateTime(2000, 01, 01))
  445. throw new Exception("请输入正确的操作时间:" + info.MTime);
  446. sql = @"UPDATE dbo.rdrecord11 SET cHandler ='" + info.User + @"' ,
  447. dnmodifytime =CONVERT(VARCHAR(50),GETDATE(),112),dModifyDate =GETDATE() WHERE ID='{0}'";
  448. sql = string.Format(sql, info.ID);
  449. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  450. cmd.Transaction.Commit();
  451. }
  452. catch (Exception ex)
  453. {
  454. cmd.Transaction.Rollback();
  455. log.Error(ex.Message);
  456. throw new Exception(ex.Message);
  457. }
  458. finally
  459. {
  460. if (conn.State == ConnectionState.Open)
  461. {
  462. conn.Close();
  463. }
  464. conn.Dispose();
  465. }
  466. }
  467. return json;
  468. }
  469. /// <summary>
  470. /// 删除请购单
  471. /// </summary>
  472. /// <param name="infos"></param>
  473. /// <returns></returns>
  474. public string Delete(List<ICSOutsourcingIssueDoc> infos)
  475. {
  476. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  477. if (infos.Count <= 0)
  478. {
  479. throw new Exception("传送数据为空!");
  480. }
  481. string res = string.Empty;
  482. string connS = "";
  483. SqlConnection conn = new SqlConnection();
  484. SqlCommand cmd = new SqlCommand();
  485. string sql = string.Empty;
  486. foreach (ICSOutsourcingIssueDoc info in infos)
  487. {
  488. try
  489. {
  490. connS = string.Format(connString, info.WorkPoint);
  491. conn = new System.Data.SqlClient.SqlConnection(connS);
  492. conn.Open();
  493. SqlTransaction sqlTran = conn.BeginTransaction();
  494. cmd = new SqlCommand();
  495. cmd.Transaction = sqlTran;
  496. cmd.Connection = conn;
  497. if (info.MTime < new DateTime(2000, 01, 01))
  498. throw new Exception("请输入正确的操作时间:" + info.MTime);
  499. sql = @" DELETE dbo.rdrecord11 WHERE ID='{0}'";
  500. sql = string.Format(sql, info.ID);
  501. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  502. cmd.Transaction.Commit();
  503. }
  504. catch (Exception ex)
  505. {
  506. cmd.Transaction.Rollback();
  507. log.Error(ex.Message);
  508. throw new Exception(ex.Message);
  509. }
  510. finally
  511. {
  512. if (conn.State == ConnectionState.Open)
  513. {
  514. conn.Close();
  515. }
  516. conn.Dispose();
  517. }
  518. }
  519. return res;
  520. }
  521. /// <summary>
  522. ///
  523. /// 记录日志
  524. /// </summary>
  525. /// <param name="Bills"></param>
  526. private void LogInfo(List<ICSOutsourcingIssueDoc> Bills)
  527. {
  528. string HeadList = string.Empty;
  529. string BodyList = string.Empty;
  530. foreach (ICSOutsourcingIssueDoc head in Bills)
  531. {
  532. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  533. foreach (ICSOutsourcingIssueDocs body in head.details)
  534. {
  535. BodyList += "\r\n 表体主键ID: " + body.SourceDetailID + ",数量:" + body.Quantity;
  536. }
  537. }
  538. log.Info(HeadList);
  539. log.Info(BodyList);
  540. }
  541. }
  542. }