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

481 lines
29 KiB

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