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

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