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

556 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
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
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
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 ManufactureOrder
  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. /// <summary>
  23. /// 查找生产订单
  24. /// </summary>
  25. /// <param name="infos"></param>
  26. /// <returns></returns>
  27. public string GET(List<ICSManufactureOrder> infos)
  28. {
  29. DataTable dt = null;
  30. DataTable dtNew = null;
  31. string connS = "";
  32. string json = "";
  33. if (infos.Count <= 0)
  34. {
  35. throw new Exception("传送数据为空!");
  36. }
  37. string res = string.Empty;
  38. SqlConnection conn = new SqlConnection();
  39. SqlCommand cmd = new SqlCommand();
  40. string sql = string.Empty;
  41. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  42. foreach (string WorkPoint in result)
  43. {
  44. try
  45. {
  46. connS = string.Format(connString, WorkPoint);
  47. conn = new System.Data.SqlClient.SqlConnection(connS);
  48. conn.Open();
  49. SqlTransaction sqlTran = conn.BeginTransaction();
  50. cmd = new SqlCommand();
  51. cmd.Transaction = sqlTran;
  52. cmd.Connection = conn;
  53. foreach (ICSManufactureOrder info in infos)
  54. {
  55. if (WorkPoint != info.WorkPoint)
  56. {
  57. continue;
  58. }
  59. ICSUserInfo userInfo = new ICSUserInfo();
  60. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  61. if (info.MTime < new DateTime(2000, 01, 01))
  62. throw new Exception("请输入正确的操作时间:" + info.MTime);
  63. sql = @" select a.MoId ,a.MoCode ,a.CreateUser ,a.CreateTime ,b.RelsUser ,b.RelsTime ,b.MoDId ,b.SortSeq,b.InvCode,b.Qty,b.AuxQty,b.QualifiedInQty,b.MDeptCode,
  64. e.CDEPNAME, b.WhCode cWhCode,f.cWhName,c.StartDate,c.DueDate FROM dbo.mom_order a
  65. INNER JOIN dbo.mom_orderdetail b ON a.MoId = b.MoId
  66. INNER JOIN dbo.mom_morder c ON b.MoDId = c.MoDId
  67. LEFT JOIN dbo.mom_orderdetail_extradefine d ON b.MoDId = d.MoDId
  68. INNER JOIN DEPARTMENT e ON b.MDeptCode=e.CDEPCODE
  69. INNER JOIN Warehouse f ON b.WhCode=f.cWhCode WHERE 1=1";
  70. if (!string.IsNullOrWhiteSpace(info.MOCode))
  71. {
  72. sql += " and a.MoCode='{0}'";
  73. }
  74. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  75. {
  76. sql += " and ISNULL(b.cbCloseTime,ISNULL(a.cChangAuditTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime))))>='{1}'";
  77. }
  78. if (!string.IsNullOrWhiteSpace(info.User))
  79. {
  80. sql += "and a.CMAKER='{2}'";
  81. }
  82. sql = string.Format(sql, info.MOCode, info.MTime, userInfo.UserName);
  83. dt = DBHelper.SQlReturnData(sql, cmd);
  84. if (dt.Rows.Count <= 0 || dt == null)
  85. throw new Exception("生产订单:" + info.MOCode + ",无信息!");
  86. if (dtNew == null)
  87. dtNew = dt;
  88. else
  89. dtNew.Merge(dt);
  90. }
  91. cmd.Transaction.Commit();
  92. }
  93. catch (Exception ex)
  94. {
  95. cmd.Transaction.Rollback();
  96. log.Error(ex.Message);
  97. throw new Exception(ex.Message);
  98. }
  99. finally
  100. {
  101. if (conn.State == ConnectionState.Open)
  102. {
  103. conn.Close();
  104. }
  105. conn.Dispose();
  106. }
  107. }
  108. json = JsonConvert.SerializeObject(dtNew);
  109. return json;
  110. }
  111. /// <summary>
  112. /// 创建生产订单
  113. /// </summary>
  114. /// <param name="infos"></param>
  115. /// <returns></returns>
  116. public string CreateManufactureOrder(List<ICSManufactureOrder> Bills)
  117. {
  118. string msg = "";
  119. List<ICSManufactureOrder> szJson = new List<ICSManufactureOrder>();
  120. string connS = "";
  121. DateTime time = DateTime.Now;
  122. int num = 0;
  123. VouchKey key = new VouchKey();
  124. //int iBaseCodeLen = Convert.ToInt32(dic["iBaseCodeLen"].ToString());
  125. //int cVouchCodeBase = Convert.ToInt32(dic["cVouchCodeBase"].ToString());
  126. List<ICSPOArrive> datas = new List<ICSPOArrive>();
  127. if (Bills.Count <= 0)
  128. {
  129. throw new Exception("传送数据为空!");
  130. }
  131. string res = string.Empty;
  132. SqlConnection conn = new SqlConnection();
  133. SqlCommand cmd = new SqlCommand();
  134. List<string> result = Bills.Select(t => t.WorkPoint).Distinct().ToList();
  135. foreach (string WorkPoint in result)
  136. {
  137. try
  138. {
  139. connS = string.Format(connString, WorkPoint);
  140. conn = new System.Data.SqlClient.SqlConnection(connS);
  141. conn.Open();
  142. SqlTransaction sqlTran = conn.BeginTransaction();
  143. cmd = new SqlCommand();
  144. cmd.Transaction = sqlTran;
  145. cmd.Connection = conn;
  146. foreach (ICSManufactureOrder head in Bills)
  147. {
  148. if (WorkPoint != head.WorkPoint)
  149. {
  150. continue;
  151. }
  152. ICSUserInfo userInfo = new ICSUserInfo();
  153. userInfo = DBHelper.GetPersonInfo(head.User, cmd);
  154. num = head.details.Count();
  155. string[] ss = head.WorkPoint.Split('_');
  156. ERPDB = ss[1];
  157. Dictionary<string, int> dic = DBHelper.GetAllCode("" + ERPDB + "", "mom_order", "" + num + "", head.WorkPoint);
  158. int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString());
  159. int iChildId = Convert.ToInt32(dic["iChildId"].ToString());
  160. DateTime date = DateTime.Now;
  161. string iBaseCodeLen = DBHelper.GetAllRDCode("MO21", "" + time + "", "admin", "", head.WorkPoint);
  162. if (head.MTime < new DateTime(2000, 01, 01))
  163. throw new Exception("请输入正确的操作时间:" + head.MTime);
  164. string sql = "";
  165. #region 生产订单
  166. sql = @"INSERT INTO mom_order(MoId, MoCode,cSysBarCode, CreateDate, CreateTime,
  167. CreateUser, ModifyDate, ModifyTime, ModifyUser, UpdCount ,
  168. VTid,RelsVTid)
  169. values (@MoId,@MoCode,NULL, CONVERT(VARCHAR(10),GETDATE(),23), GETDATE(),
  170. '@CreateUser', NULL, NULL, NULL, 0 ,
  171. @VTID,0)" + Environment.NewLine;
  172. cmd.Parameters.Clear();
  173. cmd.Parameters.Add(new SqlParameter("@MoId", iFatherId));
  174. cmd.Parameters.Add(new SqlParameter("@MoCode", iBaseCodeLen));
  175. cmd.Parameters.Add(new SqlParameter("@CreateUser", userInfo.UserName));
  176. cmd.Parameters.Add(new SqlParameter("@VTID", iChildId));
  177. cmd.CommandText = sql;
  178. try
  179. {
  180. int count = cmd.ExecuteNonQuery();
  181. if (count <= 0)
  182. {
  183. log.Error("生成生产顶订单表头失败,受影响行数<=0;");
  184. throw new Exception("生成生产顶订单表头失败,受影响行数<=0;");
  185. }
  186. }
  187. catch (Exception ex)
  188. {
  189. log.Error("生成生产顶订单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  190. throw new Exception("生成生产顶订单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  191. }
  192. #endregion
  193. #region 采购入库单表体
  194. foreach (ICSManufactureOrders body in head.details)
  195. {
  196. sql += @"INSERT INTO mom_orderdetail(MoDId, MoId, SortSeq, MoClass, MoTypeId,
  197. Qty, MrpQty, AuxUnitCode, AuxQty, ChangeRate,
  198. MoLotCode, WhCode, MDeptCode, OrderType, OrderDId,
  199. OrderCode, OrderSeq, CustCode, DeclaredQty, QualifiedInQty,
  200. Status, OrgStatus, BomId, RoutingId, CustBomId,
  201. DemandId, PlanCode, PartId, InvCode,cbSysBarCode ,
  202. Free1, Free2, Free3, Free4, Free5, Free6, Free7, Free8, Free9, Free10 ,
  203. SfcFlag, CrpFlag, QcFlag,LeadTime,WIPType,
  204. SupplyWhCode,OpScheduleType,ReasonCode,Remark ,SourceQCId,
  205. SourceQCDId,SourceMoId,SourceMoDId,SourceQCVouchType,SourceSvcVouchType,
  206. PAllocateId ,RelsTime,AuditStatus,Iswfcontrolled,iVerifyState,
  207. iReturnCount ,CollectiveFlag,SoType,ReformFlag, RelsUser,
  208. RelsDate, FmFlag,BomType,RoutingType,OrdFlag,
  209. RunCardFlag,RequisitionFlag,AlloVTid,RelsAlloVTid)
  210. SELECT @MoDId, @MoId, @SortSeq, '1', NULL,
  211. @Qty, 0, NULL, @AuxQty, NULL,
  212. NULL, NULL, @MDeptCode, '0', '0',
  213. NULL, NULL,NULL, '0', '0',
  214. '3', '2', a.BomId, '0', '0',
  215. '0', NULL, c.PartId, @InvCode,'' ,
  216. '', '', '', '', '', '', '', '', '', '' ,
  217. '0', '0', '0', '0','',
  218. NULL,'3',NULL,'','0',
  219. '0','0','0','0','0',
  220. '0',GETDATE(),'1','0','0',
  221. '0' ,'0','0','0',@RelsUser,
  222. NULL, '0' ,a.BomType,'0','0',
  223. '0','0',NULL,NULL
  224. FROM dbo.bom_bom a
  225. INNER JOIN dbo.bom_parent b ON a.BomId = b.BomId
  226. INNER JOIN dbo.bas_part c ON b.ParentId = c.PartId
  227. WHERE c.InvCode=@InvCode
  228. " + Environment.NewLine;
  229. cmd.Parameters.Clear();
  230. cmd.Parameters.Add(new SqlParameter("@MoDId", iChildId));
  231. cmd.Parameters.Add(new SqlParameter("@SortSeq", body.Sequence));
  232. cmd.Parameters.Add(new SqlParameter("@MDeptCode", body.DepCode));
  233. cmd.Parameters.Add(new SqlParameter("@Qty", body.Quantity));
  234. cmd.Parameters.Add(new SqlParameter("@AuxQty", body.Amount.ToString("0.00")));
  235. cmd.Parameters.Add(new SqlParameter("@InvCode", body.InvCode));
  236. cmd.Parameters.Add(new SqlParameter("@RelsUser", head.User));
  237. cmd.Parameters.Add(new SqlParameter("@MoId", iFatherId));
  238. //cmd.Parameters.Add(new SqlParameter("@RelsDate", body.Quantity));
  239. cmd.CommandText = sql;
  240. try
  241. {
  242. int count = cmd.ExecuteNonQuery();
  243. if (count <= 0)
  244. {
  245. log.Error("生成生产顶订单表头失败,受影响行数<=0;");
  246. throw new Exception("生成生产顶订单表头失败,受影响行数<=0;");
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. log.Error("生成生产顶订单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  252. throw new Exception("生成生产顶订单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  253. }
  254. #region 生产订单资料
  255. sql += @"INSERT INTO mom_morder(MoDId, MoId, StartDate, DueDate)
  256. values (" + iChildId + ", " + iFatherId + ", '" + body.StartDate + "', '" + body.DueDate + "') " + Environment.NewLine;
  257. cmd.CommandText = sql;
  258. try
  259. {
  260. int count = cmd.ExecuteNonQuery();
  261. if (count <= 0)
  262. {
  263. log.Error("生产订单资料表失败,受影响行数<=0;");
  264. throw new Exception("生产订单资料表失败,受影响行数<=0;");
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. log.Error("生产订单资料表失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  270. throw new Exception("生产订单资料表失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  271. }
  272. #endregion
  273. #region 考虑虚拟件,如果包含虚拟件,取虚拟件的下一级,如果虚拟件的下级bom未维护,不做处理
  274. sql += @"SELECT c.InvCode AS PInvCode,0 AS [Level], CAST(1 AS nvarchar(MAX)) AS SEQ,CAST(1 AS nvarchar(MAX)) AS Sort,
  275. d.MoDId,a.SortSeq,a.OpSeq,a.ComponentId,
  276. a.FVFlag,a.BaseQtyN,a.BaseQtyD,'0' AS ParentScrap,a.CompScrap,
  277. CAST(d.Qty AS DECIMAL(28,6)) AS Qty,'0' AS IssQty,'0' AS DeclaredQty, '@StartDate' AS StartDemDate, '@DueDate' AS EndDemDate,
  278. NULL AS WhCode,NULL AS LotNo,e.WIPType,a.ByproductFlag,'0' AS QcFlag,
  279. '0' AS Offset,a.Free1,a.Free2,a.Free3,
  280. a.Free4,a.Free5,a.Free6,a.Free7,a.Free8,
  281. a.Free9,a.Free10,a.OpComponentId,a.Define22,a.Define23,
  282. a.Define24,a.Define25,a.Define26,a.Define27,a.Define28,
  283. a.Define29,a.Define30,a.Define31,a.Define32,a.Define33,
  284. a.Define34,a.Define35,a.Define36,a.Define37,'0' AS ReplenishQty,
  285. a.Remark,'0' AS TransQty,a.ProductType,'0' AS SoType,NULL AS SoDId,
  286. NULL AS SoCode,NULL AS SoSeq,NULL AS DemandCode,'0' AS QmFlag,'0' AS OrgQty,
  287. '0' AS OrgAuxQty,NULL AS CostItemCode,NULL AS CostItemName,'0' AS RequisitionFlag,'0' AS RequisitionQty,
  288. '0' AS RequisitionIssQty,'0' AS CostWIPRel,NULL AS MoallocateSubId,NULL AS cSubSysBarCode,'0' AS PickingQty,
  289. '0' AS PickingAuxQty,'0' AS UpperMoQty,'0' AS InvAlloeFlag,NULL AS FactoryCode
  290. INTO #TempBOMP" + iFatherId + @"
  291. FROM bas_part c
  292. INNER JOIN mom_orderdetail d ON c.PartId=d.PartId
  293. LEFT JOIN bom_parent b ON 1<>1 --b.ParentId=c.PartId
  294. LEFT JOIN bom_opcomponent a ON a.BomId=b.BomId
  295. LEFT JOIN bom_opcomponentopt e ON a.OptionsId=e.OptionsId
  296. WHERE d.MoDId=" + iChildId + @"
  297. ORDER BY d.MoDId
  298. ;
  299. SELECT row_number() OVER (partition by c.InvCode ORDER BY c.InvCode,d.SortSeq) AS SEQ,c.InvCode AS PInvCode,f.InvCode AS InvCode,
  300. d.SortSeq,d.OpSeq,d.ComponentId,
  301. d.FVFlag,d.BaseQtyN,d.BaseQtyD,'0' AS ParentScrap,d.CompScrap,
  302. CAST(d.BaseQtyN/d.BaseQtyD AS DECIMAL(28,6)) AS Qty,'0' AS IssQty,'0' AS DeclaredQty, '@StartDate' AS StartDemDate, '@DueDate' AS EndDemDate,
  303. NULL AS WhCode,NULL AS LotNo,e.WIPType,d.ByproductFlag,'0' AS QcFlag,
  304. '0' AS Offset,d.Free1,d.Free2,d.Free3,
  305. d.Free4,d.Free5,d.Free6,d.Free7,d.Free8,
  306. d.Free9,d.Free10,d.OpComponentId,d.Define22,d.Define23,
  307. d.Define24,d.Define25,d.Define26,d.Define27,d.Define28,
  308. d.Define29,d.Define30,d.Define31,d.Define32,d.Define33,
  309. d.Define34,d.Define35,d.Define36,d.Define37,'0' AS ReplenishQty,
  310. d.Remark,'0' AS TransQty,d.ProductType,'0' AS SoType,NULL AS SoDId,
  311. NULL AS SoCode,NULL AS SoSeq,NULL AS DemandCode,'0' AS QmFlag,'0' AS OrgQty,
  312. '0' AS OrgAuxQty,NULL AS CostItemCode,NULL AS CostItemName,'0' AS RequisitionFlag,'0' AS RequisitionQty,
  313. '0' AS RequisitionIssQty,'0' AS CostWIPRel,NULL AS MoallocateSubId,NULL AS cSubSysBarCode,'0' AS PickingQty,
  314. '0' AS PickingAuxQty,'0' AS UpperMoQty,'0' AS InvAlloeFlag,NULL AS FactoryCode
  315. INTO #TempBOM" + iFatherId + @"
  316. FROM dbo.bom_bom a
  317. INNER JOIN dbo.bom_parent b on a.BomId = b.BomId
  318. INNER JOIN dbo.bas_part c on b.ParentId = c.PartId
  319. INNER JOIN dbo.bom_opcomponent d on a.BomId=d.BomId
  320. INNER JOIN dbo.bom_opcomponentopt e ON d.OptionsId=e.OptionsId
  321. INNER JOIN dbo.bas_part f on d.ComponentId = f.PartId
  322. WHERE a.VersionEndDate>=CONVERT(VARCHAR(10),GETDATE(),23)
  323. ORDER BY c.InvCode,d.SortSeq
  324. ;
  325. WITH ICSBomALL AS
  326. (
  327. SELECT
  328. PInvCode AS TInvCode,
  329. PInvCode AS PInvCode,
  330. PInvCode AS InvCode,
  331. --CAST('1' AS tinyint) AS WIPType,
  332. [Level],
  333. SEQ,
  334. CAST(REPLICATE('0',5-len(Sort))+Sort AS nvarchar(MAX)) AS Sort,
  335. MoDId,SortSeq,OpSeq,ComponentId,
  336. FVFlag,BaseQtyN,BaseQtyD,ParentScrap,CompScrap,
  337. CAST(Qty AS DECIMAL(28,6)) AS Qty,IssQty,DeclaredQty, StartDemDate, EndDemDate,
  338. WhCode,LotNo,WIPType,ByproductFlag,QcFlag,
  339. Offset,Free1,Free2,Free3,
  340. Free4,Free5,Free6,Free7,Free8,
  341. Free9,Free10,OpComponentId,Define22,Define23,
  342. Define24,Define25,Define26,Define27,Define28,
  343. Define29,Define30,Define31,Define32,Define33,
  344. Define34,Define35,Define36,Define37,ReplenishQty,
  345. Remark,TransQty,ProductType,SoType,SoDId,
  346. SoCode,SoSeq,DemandCode,QmFlag,OrgQty,
  347. OrgAuxQty,CostItemCode,CostItemName,RequisitionFlag,RequisitionQty,
  348. RequisitionIssQty,CostWIPRel,MoallocateSubId,cSubSysBarCode,PickingQty,
  349. PickingAuxQty,UpperMoQty,InvAlloeFlag,FactoryCode
  350. FROM
  351. #TempBOMP" + iFatherId + @"
  352. UNION ALL
  353. SELECT
  354. b.TInvCode,
  355. a.PInvCode,
  356. a.InvCode,
  357. --a.WIPType,
  358. b.[Level]+1 AS [Level],
  359. CAST(b.SEQ AS nvarchar(MAX))+'.'+CAST(a.SEQ AS nvarchar(MAX)) AS SEQ,
  360. CAST(b.Sort+'.'+REPLICATE('0',5-len(a.SEQ))+CAST(a.SEQ AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort,
  361. b.MoDId,a.SortSeq,a.OpSeq,a.ComponentId,
  362. a.FVFlag,a.BaseQtyN,a.BaseQtyD,a.ParentScrap,a.CompScrap,
  363. CAST(a.Qty*b.Qty AS DECIMAL(28,6)) AS Qty,a.IssQty,a.DeclaredQty, a.StartDemDate, a.EndDemDate,
  364. a.WhCode,a.LotNo,a.WIPType,a.ByproductFlag,a.QcFlag,
  365. a.Offset,a.Free1,a.Free2,a.Free3,
  366. a.Free4,a.Free5,a.Free6,a.Free7,a.Free8,
  367. a.Free9,a.Free10,a.OpComponentId,a.Define22,a.Define23,
  368. a.Define24,a.Define25,a.Define26,a.Define27,a.Define28,
  369. a.Define29,a.Define30,a.Define31,a.Define32,a.Define33,
  370. a.Define34,a.Define35,a.Define36,a.Define37,a.ReplenishQty,
  371. a.Remark,a.TransQty,a.ProductType,a.SoType,a.SoDId,
  372. a.SoCode,a.SoSeq,a.DemandCode,a.QmFlag,a.OrgQty,
  373. a.OrgAuxQty,a.CostItemCode,a.CostItemName,a.RequisitionFlag,a.RequisitionQty,
  374. a.RequisitionIssQty,a.CostWIPRel,a.MoallocateSubId,a.cSubSysBarCode,a.PickingQty,
  375. a.PickingAuxQty,a.UpperMoQty,a.InvAlloeFlag,a.FactoryCode
  376. FROM
  377. #TempBOM" + iFatherId + @" a
  378. INNER JOIN ICSBomALL b ON a.PInvCode=b.InvCode
  379. --
  380. WHERE b.[Level]='0' OR b.WIPType='4'
  381. )
  382. SELECT row_number() OVER (ORDER BY Sort) AS RowIndex,* INTO #TempMOAll" + iFatherId + @" FROM ICSBomALL WHERE [Level]<>'0' AND WIPType<>'4' ORDER BY Sort";
  383. //更新临时表的ID
  384. // sql += @" DECLARE @CurrentRow" + iFatherId + @" INT,@TotalRow" + iFatherId + @" INT
  385. // SET @TotalRow" + iFatherId + @"=@@rowcount
  386. // SET @CurrentRow" + iFatherId + @"=1
  387. // WHILE @CurrentRow" + iFatherId + @"<=@TotalRow" + iFatherId + @"
  388. // BEGIN
  389. // " + ICSHelper.GetIDSql(cCompanyCode, "mom_moallocate", appmokey, GetID.ALL) + @"
  390. // UPDATE #TempMOAll" + appskey + @" SET RowIndex=" + baseInt + "+@DID" + appmokey + @" WHERE RowIndex=@CurrentRow" + appskey + @"
  391. // SET @CurrentRow" + appskey + @"+=1
  392. // END
  393. // " + Environment.NewLine;
  394. sql += @" INSERT INTO mom_moallocate (AllocateId,MoDId,SortSeq,OpSeq,ComponentId,
  395. FVFlag,BaseQtyN,BaseQtyD,ParentScrap,CompScrap,
  396. Qty,IssQty,DeclaredQty,StartDemDate,EndDemDate,
  397. WhCode,LotNo,WIPType,ByproductFlag,QcFlag,
  398. Offset,InvCode,Free1,Free2,Free3,
  399. Free4,Free5,Free6,Free7,Free8,
  400. Free9,Free10,OpComponentId,Define22,Define23,
  401. Define24,Define25,Define26,Define27,Define28,
  402. Define29,Define30,Define31,Define32,Define33,
  403. Define34,Define35,Define36,Define37,ReplenishQty,
  404. Remark,TransQty,ProductType,SoType,SoDId,
  405. SoCode,SoSeq,DemandCode,QmFlag,OrgQty,
  406. OrgAuxQty,CostItemCode,CostItemName,RequisitionFlag,RequisitionQty,
  407. RequisitionIssQty,CostWIPRel,cSubSysBarCode,PickingQty,
  408. PickingAuxQty,UpperMoQty,InvAlloeFlag,FactoryCode)
  409. SELECT RowIndex,MoDId,SortSeq,OpSeq,ComponentId,
  410. FVFlag,BaseQtyN,BaseQtyD,ParentScrap,CompScrap,
  411. Qty,IssQty,DeclaredQty,StartDemDate,EndDemDate,
  412. WhCode,LotNo,WIPType,ByproductFlag,QcFlag,
  413. Offset,InvCode,Free1,Free2,Free3,
  414. Free4,Free5,Free6,Free7,Free8,
  415. Free9,Free10,OpComponentId,Define22,Define23,
  416. Define24,Define25,Define26,Define27,Define28,
  417. Define29,Define30,Define31,Define32,Define33,
  418. Define34,Define35,Define36,Define37,ReplenishQty,
  419. Remark,TransQty,ProductType,SoType,SoDId,
  420. SoCode,SoSeq,DemandCode,QmFlag,OrgQty,
  421. OrgAuxQty,CostItemCode,CostItemName,RequisitionFlag,RequisitionQty,
  422. RequisitionIssQty,CostWIPRel,cSubSysBarCode,PickingQty,
  423. PickingAuxQty,UpperMoQty,InvAlloeFlag,FactoryCode
  424. FROM #TempMOAll" + iFatherId + Environment.NewLine;
  425. sql += @" DROP TABLE #TempMOAll" + iFatherId + Environment.NewLine;
  426. sql += @" DROP TABLE #TempBOMP" + iFatherId + Environment.NewLine;
  427. sql += @" DROP TABLE #TempBOM" + iFatherId + Environment.NewLine;
  428. cmd.CommandText = sql;
  429. try
  430. {
  431. int count = cmd.ExecuteNonQuery();
  432. if (count <= 0)
  433. {
  434. log.Error("生成生产顶订单表头失败,受影响行数<=0;");
  435. throw new Exception("生成生产顶订单表头失败,受影响行数<=0;");
  436. }
  437. }
  438. catch (Exception ex)
  439. {
  440. log.Error("生成生产顶订单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  441. throw new Exception("生成生产顶订单表头失败!异常:" + ex.Message + ";SQL:\r\n" + sql, ex);
  442. }
  443. #endregion
  444. }
  445. #endregion
  446. ////更新主键ID,DID
  447. //DBHelper.UpdateIDandDID("rd", head.list.Count(), cmd);
  448. }
  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 msg;
  467. }
  468. /// <summary>
  469. /// 删除生产订单
  470. /// </summary>
  471. /// <param name="infos"></param>
  472. /// <returns></returns>
  473. public string Delete(List<ICSManufactureOrder> infos)
  474. {
  475. List<ICSManufactureOrder> szJson = new List<ICSManufactureOrder>();
  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. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  486. foreach (string WorkPoint in result)
  487. {
  488. try
  489. {
  490. connS = string.Format(connString, 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. foreach (ICSManufactureOrder info in infos)
  498. {
  499. if (WorkPoint != info.WorkPoint)
  500. {
  501. continue;
  502. }
  503. if (info.MTime < new DateTime(2000, 01, 01))
  504. throw new Exception("请输入正确的操作时间:" + info.MTime);
  505. sql = @" DELETE [{1}].dbo.mom_order WHERE ID={0}";
  506. sql = string.Format(sql, info.ID, ERPDB);
  507. DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!");
  508. }
  509. cmd.Transaction.Commit();
  510. }
  511. catch (Exception ex)
  512. {
  513. cmd.Transaction.Rollback();
  514. log.Error(ex.Message);
  515. throw new Exception(ex.Message);
  516. }
  517. finally
  518. {
  519. if (conn.State == ConnectionState.Open)
  520. {
  521. conn.Close();
  522. }
  523. conn.Dispose();
  524. }
  525. }
  526. return res;
  527. }
  528. }
  529. }