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

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