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

578 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
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 ,
  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,
  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("@cCode", iBaseCodeLen));
  320. cmd.Parameters.Add(new SqlParameter("@InvCode", body.InvCode));
  321. cmd.Parameters.Add(new SqlParameter("@cBatch", body.BatchCode));
  322. cmd.Parameters.Add(new SqlParameter("@irowno", irowno));
  323. cmd.Parameters.Add(new SqlParameter("@iNQuantity", iNQuantity));
  324. cmd.Parameters.Add(new SqlParameter("@cFree1", body.cFree1));
  325. cmd.Parameters.Add(new SqlParameter("@cFree2", body.cFree2));
  326. cmd.Parameters.Add(new SqlParameter("@cFree3", body.cFree3));
  327. cmd.Parameters.Add(new SqlParameter("@cFree4", body.cFree4));
  328. cmd.Parameters.Add(new SqlParameter("@cFree5", body.cFree5));
  329. cmd.Parameters.Add(new SqlParameter("@cFree6", body.cFree6));
  330. cmd.Parameters.Add(new SqlParameter("@cFree7", body.cFree7));
  331. cmd.Parameters.Add(new SqlParameter("@cFree8", body.cFree8));
  332. cmd.Parameters.Add(new SqlParameter("@cFree9", body.cFree9));
  333. cmd.Parameters.Add(new SqlParameter("@cFree10", body.cFree10));
  334. cmd.CommandText = sql;
  335. try
  336. {
  337. int count = cmd.ExecuteNonQuery();
  338. if (count <= 0)
  339. {
  340. log.Error("生成委外发料单表体失败,受影响行数<=0;");
  341. throw new Exception("生成委外发料单表体失败,受影响行数<=0;");
  342. }
  343. }
  344. catch (Exception ex)
  345. {
  346. log.Error("生成委外发料单表体失败" + sql, ex);
  347. throw new Exception("生成委外发料单表体失败 " + sql, ex);
  348. }
  349. if (head.UpdateStock)
  350. {
  351. //更新现存量
  352. key.cBustypeUN = "委外发料";
  353. key.cVouchTypeUN = "11";
  354. key.TableName = "IA_ST_UnAccountVouch11";
  355. //DBHelper.UpdateCurrentStock(cmd, body.InvCode, head.WHCode, "", -body.Quantity, key);
  356. 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);
  357. }
  358. #region 回写工单子件已领数量
  359. sql = "update OM_MOMaterials set iSendQTY=isnull(iSendQTY,0)+" + body.Quantity + ",fsendapplyqty=isnull(fsendapplyqty,0)+" + body.Quantity + @" where MOMaterialsID='" + body.SourceDetailID + "' ";
  360. DBHelper.CmdExecuteNonQuery(sql, cmd, "回写委外订单子件已领数量失败!");
  361. #endregion
  362. iFatherIdTwo += "'" + iFatherId + "',";
  363. iChildId--;
  364. }
  365. #endregion
  366. #region 查询
  367. sql = @"select a.ID as ID,a.ID as IDs,a.cCode as IssueCode,a.cDepCode,c.cDepName,a.cWhCode,
  368. d.cWhName,a.cSource,cMPoCode,a.cMaker,dnmaketime,cHandler,dnverifytime
  369. from rdrecord11 a
  370. left join Department c on a.cDepCode=c.cDepCode
  371. left join Warehouse d on a.cWhCode=d.cWhCode
  372. where a.cBusType=''and a.ID in ({0})
  373. select a.ID as IDs,iOMoMID as SourceDetailID ,b.irowno as Sequence,iordercode,b.cInvCode,b.iQuantity,b.iNum,b.AutoID as DetailID
  374. from rdrecord11 a
  375. left join rdrecords11 b on a.ID=b.ID
  376. left join Department c on a.cDepCode=c.cDepCode
  377. left join Warehouse d on a.cWhCode=d.cWhCode
  378. left join OM_MODetails e on b.iOMoDID=e.MoDetailsID
  379. where a.cBusType=''and a.ID in ({0})";
  380. sql = string.Format(sql, iFatherIdTwo.TrimEnd(','));
  381. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  382. if (dtNew1 == null)
  383. dtNew1 = ds.Tables[0];
  384. else
  385. dtNew1.Merge(ds.Tables[0]);
  386. if (dtNew2 == null)
  387. dtNew2 = ds.Tables[1];
  388. else
  389. dtNew2.Merge(ds.Tables[1]);
  390. #endregion
  391. cmd.Transaction.Commit();
  392. }
  393. catch (Exception ex)
  394. {
  395. cmd.Transaction.Rollback();
  396. log.Error(ex.Message);
  397. throw new Exception(ex.Message);
  398. }
  399. finally
  400. {
  401. if (conn.State == ConnectionState.Open)
  402. {
  403. conn.Close();
  404. }
  405. conn.Dispose();
  406. }
  407. }
  408. string RelationName = "details";
  409. DataSet dz = new DataSet();
  410. dtNew1.TableName = "Table0";
  411. dtNew2.TableName = "Table1";
  412. dz.Tables.Add(dtNew1.Copy());
  413. dz.Tables.Add(dtNew2.Copy());
  414. DataRelation dh = new DataRelation(RelationName, dz.Tables[0].Columns["IDs"], dz.Tables[1].Columns["IDs"]);
  415. dz.Relations.Add(dh);
  416. msg = DBHelper.DataSetToJson(dz, RelationName);
  417. return msg;
  418. }
  419. public string Approve(List<ICSOutsourcingIssueDoc> infos)
  420. {
  421. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  422. string connS = "";
  423. string json = "";
  424. if (infos.Count <= 0)
  425. {
  426. throw new Exception("传送数据为空!");
  427. }
  428. string res = string.Empty;
  429. SqlConnection conn = new SqlConnection();
  430. SqlCommand cmd = new SqlCommand();
  431. string sql = string.Empty;
  432. foreach (ICSOutsourcingIssueDoc info in infos)
  433. {
  434. try
  435. {
  436. connS = string.Format(connString, info.WorkPoint);
  437. conn = new System.Data.SqlClient.SqlConnection(connS);
  438. conn.Open();
  439. SqlTransaction sqlTran = conn.BeginTransaction();
  440. cmd = new SqlCommand();
  441. cmd.Transaction = sqlTran;
  442. cmd.Connection = conn;
  443. if (info.MTime < new DateTime(2000, 01, 01))
  444. throw new Exception("请输入正确的操作时间:" + info.MTime);
  445. sql = @"UPDATE dbo.rdrecord11 SET cHandler ='" + info.User + @"' ,
  446. dnmodifytime =CONVERT(VARCHAR(50),GETDATE(),112),dModifyDate =GETDATE() WHERE ID='{0}'";
  447. sql = string.Format(sql, info.ID);
  448. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  449. cmd.Transaction.Commit();
  450. }
  451. catch (Exception ex)
  452. {
  453. cmd.Transaction.Rollback();
  454. log.Error(ex.Message);
  455. throw new Exception(ex.Message);
  456. }
  457. finally
  458. {
  459. if (conn.State == ConnectionState.Open)
  460. {
  461. conn.Close();
  462. }
  463. conn.Dispose();
  464. }
  465. }
  466. return json;
  467. }
  468. /// <summary>
  469. /// 删除请购单
  470. /// </summary>
  471. /// <param name="infos"></param>
  472. /// <returns></returns>
  473. public string Delete(List<ICSOutsourcingIssueDoc> infos)
  474. {
  475. List<ICSOutsourcingIssueDoc> szJson = new List<ICSOutsourcingIssueDoc>();
  476. if (infos.Count <= 0)
  477. {
  478. throw new Exception("传送数据为空!");
  479. }
  480. string res = string.Empty;
  481. string connS = "";
  482. SqlConnection conn = new SqlConnection();
  483. SqlCommand cmd = new SqlCommand();
  484. string sql = string.Empty;
  485. foreach (ICSOutsourcingIssueDoc info in infos)
  486. {
  487. try
  488. {
  489. connS = string.Format(connString, info.WorkPoint);
  490. conn = new System.Data.SqlClient.SqlConnection(connS);
  491. conn.Open();
  492. SqlTransaction sqlTran = conn.BeginTransaction();
  493. cmd = new SqlCommand();
  494. cmd.Transaction = sqlTran;
  495. cmd.Connection = conn;
  496. if (info.MTime < new DateTime(2000, 01, 01))
  497. throw new Exception("请输入正确的操作时间:" + info.MTime);
  498. sql = @" DELETE dbo.rdrecord11 WHERE ID='{0}'";
  499. sql = string.Format(sql, info.ID);
  500. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  501. cmd.Transaction.Commit();
  502. }
  503. catch (Exception ex)
  504. {
  505. cmd.Transaction.Rollback();
  506. log.Error(ex.Message);
  507. throw new Exception(ex.Message);
  508. }
  509. finally
  510. {
  511. if (conn.State == ConnectionState.Open)
  512. {
  513. conn.Close();
  514. }
  515. conn.Dispose();
  516. }
  517. }
  518. return res;
  519. }
  520. /// <summary>
  521. ///
  522. /// 记录日志
  523. /// </summary>
  524. /// <param name="Bills"></param>
  525. private void LogInfo(List<ICSOutsourcingIssueDoc> Bills)
  526. {
  527. string HeadList = string.Empty;
  528. string BodyList = string.Empty;
  529. foreach (ICSOutsourcingIssueDoc head in Bills)
  530. {
  531. HeadList += "\r\n 表头主键ID:" + head.ID + ",仓库:" + head.WHCode + ",用户:" + head.User + ",站点:" + head.WorkPoint;
  532. foreach (ICSOutsourcingIssueDocs body in head.details)
  533. {
  534. BodyList += "\r\n 表体主键ID: " + body.SourceDetailID + ",数量:" + body.Quantity;
  535. }
  536. }
  537. log.Info(HeadList);
  538. log.Info(BodyList);
  539. }
  540. }
  541. }