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

191 lines
10 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using Quartz;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 产成品入库
  11. /// </summary>
  12. public class ICSManufactureReceive : 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 conStr = ICSHelper.GetConnectString();
  37. string Namespace = this.GetType().Namespace;
  38. //string Class = this.GetType().Name;
  39. DataTable dt = ICSHelper.GetERPDB(conStr);
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  43. string WorkPoint = dr["WorkPointCode"].ToString();
  44. string Class = this.GetType().Name + WorkPoint;
  45. erpName = string.Format(erpName, WorkPoint);
  46. #region SQL
  47. string sql = @" SELECT CAST(a.Autoid AS NVARCHAR(50)) AS ERPAutoid,
  48. b.cCode AS RCVCode,
  49. CAST(a.irowno AS NVARCHAR(50)) AS Sequence,
  50. b.cMPoCode as SourceCode,
  51. CAST(e.SortSeq AS NVARCHAR(50)) as SourceSequence,
  52. a.cInvCode AS InvCode,
  53. a.iQuantity AS Quantity,
  54. isnull(a.iNum,0) as Amount,
  55. 0 as RCVQuantity,
  56. b.cWhCode AS WhCode,
  57. CASE WHEN a.iQuantity>=0 THEN '1' ELSE '2' END AS Type,
  58. CASE WHEN a.iQuantity>=0 THEN '1' ELSE '2' END AS Status,
  59. b.cMaker as CreatePerson,
  60. b.dnmaketime as CreateDateTime,
  61. a.ID as RCVID,
  62. a.AutoID as RCVDetailID,
  63. ISNULL(b.dnmodifytime, b.dnmaketime) AS MTIME,
  64. isnull(a.cItemCode,'') ProjectCode,isnull(a.cbatch,'') cBatch,'' version ,'' brand,
  65. (case WHEN inv.bFree1=1 THEN a.cFree1 ELSE '' END) as cFree1,
  66. (case WHEN inv.bFree2=1 THEN a.cFree2 ELSE '' END) as cFree2,
  67. (case WHEN inv.bFree3=1 THEN a.cFree3 ELSE '' END) as cFree3,
  68. (case WHEN inv.bFree4=1 THEN a.cFree4 ELSE '' END) as cFree4,
  69. (case WHEN inv.bFree5=1 THEN a.cFree5 ELSE '' END) as cFree5,
  70. (case WHEN inv.bFree6=1 THEN a.cFree6 ELSE '' END) as cFree6,
  71. (case WHEN inv.bFree7=1 THEN a.cFree7 ELSE '' END) as cFree7,
  72. (case WHEN inv.bFree8=1 THEN a.cFree8 ELSE '' END) as cFree8,
  73. (case WHEN inv.bFree9=1 THEN a.cFree9 ELSE '' END) as cFree9,
  74. (case WHEN inv.bFree10=1 THEN a.cFree10 ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
  75. ,'{0}' as WorkPoint
  76. INTO #TempMFR
  77. FROM {1}.dbo.rdrecords10 a
  78. INNER JOIN {1}.dbo.rdrecord10 b ON a.ID = b.ID
  79. left join {1}.dbo.mom_orderdetail e on a.iMPoIds =e.MoDId
  80. LEFT JOIN {1}.dbo.Department c ON b.cDepCode = c.cDepCode
  81. LEFT JOIN {1}.dbo.Vendor d ON b.cVenCode = d.cVenCode
  82. LEFT JOIN {1}.dbo.Inventory inv ON a.cInvCode = inv.cInvCode
  83. WHERE ISNULL(b.dnmodifytime, b.dnmaketime)>=@LastTime AND ISNULL(b.cHandler, '')=''
  84. update #TempMFR set Colspan=isNULL(ProjectCode,'')+'~'+isNULL(cBatch,'')+'~'+isNULL(Version,'')+'~'+isNULL(Brand,'')+'~'+isNULL(cFree1,'')+'~'+isnull(cFree2,'')+'~'+isnull(cFree3,'')+'~'+isnull(cFree4,'')+'~'+isnull(cFree5,'')+'~'+isnull(cFree6,'')+'~'+isnull(cFree7,'')+'~'+isnull(cFree8,'')+'~'+isnull(cFree9,'')+'~'+isnull(cFree10,'')
  85. select distinct
  86. Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
  87. INTO #TempExtension
  88. from #TempMFR
  89. IF NOT EXISTS(SELECT * FROM #TempMFR)
  90. RETURN";
  91. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempMFR");
  92. Dictionary<string, string> value = new Dictionary<string, string>();
  93. value.Add("ID", "NEWID()");
  94. value.Add("BatchCode", "a.cBatch");
  95. value.Add("version", "a.version");
  96. value.Add("brand", "a.brand");
  97. value.Add("ProjectCode", "a.ProjectCode");
  98. value.Add("cFree1", "a.cFree1");
  99. value.Add("cFree2", "a.cFree2");
  100. value.Add("cFree3", "a.cFree3");
  101. value.Add("cFree4", "a.cFree4");
  102. value.Add("cFree5", "a.cFree5");
  103. value.Add("cFree6", "a.cFree6");
  104. value.Add("cFree7", "a.cFree7");
  105. value.Add("cFree8", "a.cFree8");
  106. value.Add("cFree9", "a.cFree9");
  107. value.Add("cFree10", "a.cFree10");
  108. value.Add("Colspan", "a.Colspan");
  109. value.Add("MTIME", "GETDATE()");
  110. value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  111. value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  112. value.Add("WorkPoint", "'" + WorkPoint + "'");
  113. //插入新增数据->ICSExtension表
  114. sql += ICSHelper.InsertSQL("ICSExtension", value)
  115. + @"#TempExtension a
  116. LEFT JOIN ICSExtension b ON a.ProjectCode+'~'+a.cBatch+'~'+a.Version+'~'+a.Brand+'~'+a.cFree1+'~'+a.cFree2+'~'+a.cFree3+'~'+a.cFree4+'~'+a.cFree5+'~'+a.cFree6+'~'+a.cFree7+'~'+a.cFree8+'~'+a.cFree9+'~'+a.cFree10=b.Colspan and a.WorkPoint=b.WorkPoint
  117. WHERE b.Colspan IS NULL";
  118. sql += "\r\n";
  119. sql += @"--删除数据
  120. --DELETE ICSManufactureReceive WHERE RCVDetailID NOT IN (SELECT Autoid FROM {1}.dbo.rdrecords10) AND LEN(RCVDetailID)>0
  121. SELECT a.RCVDetailID INTO #tableICSManufactureReceive
  122. FROM ICSManufactureReceive a With(NoLock)
  123. LEFT JOIN {1}.dbo.[rdrecords10] b With(NoLock) ON a.RCVDetailID=b.AutoID
  124. WHERE a.WorkPoint='{0}' and b.AutoID IS NULL AND LEN(RCVDetailID)>0
  125. DELETE ICSManufactureReceive
  126. WHERE WorkPoint='{0}' and RCVDetailID IN ( SELECT RCVDetailID from #tableICSManufactureReceive)
  127. ";
  128. Dictionary<string, string> values = new Dictionary<string, string>();
  129. values.Add("RCVCode", "a.RCVCode");//入库单号
  130. values.Add("Sequence", "a.Sequence");//入库单行号
  131. values.Add("SourceCode", "a.SourceCode");//来源单号
  132. values.Add("SourceSequence", "a.SourceSequence");//来源单号行号
  133. values.Add("InvCode", "a.InvCode");//物料编码
  134. values.Add("Quantity", "ABS(a.Quantity)");//入库数量
  135. values.Add("Amount", "a.Amount");//辅助数量
  136. values.Add("WHCode", "a.WHCode");//仓库代码
  137. values.Add("RCVDetailID", "a.RCVDetailID");
  138. values.Add("RCVID", "a.RCVID");
  139. values.Add("CreateDateTime", "a.CreateDateTime");
  140. values.Add("CreatePerson", "a.CreatePerson");
  141. values.Add("Status", "a.Status");//状态
  142. values.Add("ExtensionID", "c.ID");
  143. values.Add("MTIME", "a.MTIME");
  144. values.Add("Type", "a.Type");//类型
  145. //更新存在数据
  146. sql += ICSHelper.UpdateSQL("b", values)
  147. + @" #TempMFR a
  148. INNER JOIN ICSManufactureReceive b ON a.RCVDetailID=b.RCVDetailID and a.WorkPoint=b.WorkPoint
  149. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  150. WHERE a.WorkPoint='" + WorkPoint + "' ";
  151. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  152. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  153. values.Add("WorkPoint", "'" + WorkPoint + "'");
  154. values.Add("ID", "NewID()");
  155. sql += "\r\n";
  156. //插入新增数据
  157. sql += ICSHelper.InsertSQL("ICSManufactureReceive", values)
  158. + @" #TempMFR a
  159. LEFT JOIN ICSManufactureReceive b ON a.RCVDetailID=b.RCVDetailID and a.WorkPoint=b.WorkPoint
  160. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  161. WHERE b.RCVID IS NULL and a.WorkPoint='" + WorkPoint + "' ";
  162. sql += " DROP TABLE #TempMFR ";
  163. sql += " DROP TABLE #TempExtension " +
  164. " DROP TABLE #tableICSManufactureReceive";
  165. sql = string.Format(sql, WorkPoint, erpName);
  166. ICSHelper.ExecuteDate(conStr, sql);
  167. #endregion
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. log.Error(ex.ToString());
  173. }
  174. }
  175. }
  176. }