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

658 lines
33 KiB

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