IcsFromERPJob
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.

100 lines
4.2 KiB

4 months ago
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 装配工单(工单途程)
  11. /// </summary>
  12. public class IcsAutoSyncMoRoute : IJob
  13. {
  14. private static object key = new object();
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. public void Execute(IJobExecutionContext context)
  17. {
  18. try
  19. {
  20. lock (key)
  21. {
  22. log.Info("开始……………………………………………………………………");
  23. Execute();
  24. log.Info("结束……………………………………………………………………");
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. log.Error(ex.ToString());
  30. }
  31. }
  32. public void Execute()
  33. {
  34. try
  35. {
  36. //string conERPStr = ICSHelper.GetERPConnectString();
  37. string conStr = ICSHelper.GetConnectString();
  38. string Namespace = this.GetType().Namespace;
  39. //string Class = this.GetType().Name;
  40. // List<string> itemCodeList = new List<string>() { "A2001", "A2002", "KA10", "A2003" };
  41. DataTable dt = ICSHelper.GetERPDB(conStr);
  42. Dictionary<string, string> dis = new Dictionary<string, string>() {
  43. { "A2001", "ZP01_Route" },
  44. { "A2002", "ZP02_Route" },
  45. { "KA10", "ZP03_Route" },
  46. { "A2003", "ZP04_Route" },
  47. };
  48. foreach (DataRow dr in dt.Rows)
  49. {
  50. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  51. string TenantId = dr["TenantId"].ToString();
  52. string TenantCode = dr["TenantCode"].ToString();
  53. foreach (var item in dis)
  54. {
  55. string sql1 = @" select a.MoCode,a.MoSeq, a.Id from IcsMo a with(nolock)
  56. where a.ItemCode like '" + item.Key+ "%' and not exists (select MoCode from IcsMo2Route with(nolock) where MoCode=a.MoCode) and TenantId='" + TenantId + "' ";
  57. var itemDt = ICSHelper.ExecuteTable(conStr, sql1);
  58. if (itemDt != null && itemDt.Rows.Count > 0)
  59. {
  60. string sql2 = "";
  61. foreach (DataRow dr2 in itemDt.Rows)
  62. {
  63. //工艺路线表头
  64. sql2 += @"
  65. insert into IcsMo2Route (MoId,RouteId,MoCode,MoSeq, RouteCode,IsMRoute, TenantId,CreationTime,CreatorUserId,CreatorUserName)
  66. select top 1 " + dr2["Id"].ToInt64() + ",Id,'"+ dr2["MoCode"].ToString() + "',"+ dr2["MoSeq"].ToInt64() + ",RouteCode,'Y','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsRoute where RouteCode='" + item.Value + "' and TenantId='" + TenantId + "' ";
  67. //工艺路线明细
  68. sql2 += @"
  69. insert into IcsMoRoute2Op (MoId,RouteId,OpId,MoCode,MoSeq, RouteCode,OpCode,OpSeq,OpControl ,OpLevel ,OpControlSeq,ParallelOp
  70. ,TenantId,CreationTime,CreatorUserId,CreatorUserName)
  71. select " + dr2["Id"].ToInt64() + ",RouteId,OpId,'" + dr2["MoCode"].ToString() + "'," + dr2["MoSeq"].ToInt64() + ",RouteCode,OpCode,OpSeq,OPControl,'A',OpControlSeq,'N','" + TenantId + "',GETDATE(),'c65321b94c804dc26eb93a0ba67c8a2a','xusc' from IcsRoute2Op where RouteCode='" + item.Value + "' and TenantId='" + TenantId + "' ";
  72. sql2 += @" update icsmo set MoRoute='" + item.Value + "' where Id=" + dr2["Id"].ToInt64() + " and TenantId='" + TenantId + "' ";
  73. }
  74. ICSHelper.ExecuteDate(conStr, sql2);
  75. }
  76. }
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. log.Error(ex.ToString());
  82. }
  83. }
  84. }
  85. }