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

662 lines
34 KiB

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