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

201 lines
11 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 ICSTransfer : 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 = @"
  48. SELECT A1.DocNo AS TransferNO,
  49. CAST(A2.DocLineNo AS NVARCHAR(50)) AS Sequence,
  50. A6.Code AS FromWarehouseCode,
  51. --d.LocationCode as FromLocationCode,
  52. A3.Code AS ToWarehouseCode,
  53. '1' AS Status,
  54. A2.ItemInfo_ItemCode AS InvCode,
  55. A2.StoreUOMQty AS Quantity,
  56. 0 as Amount,
  57. '1' AS Type,
  58. A1.Memo as Memo,
  59. A1.CreatedBy as CreatePerson,
  60. A1.CreatedOn as CreateDateTime,
  61. A1.ID as TransferID,
  62. CAST(A2.ID AS NVARCHAR(50)) AS TransferDetailID,
  63. ISNULL(A2.ModifiedOn ,A2.CreatedOn) AS MTIME,
  64. isnull(A12.Code,'') ProjectCode,isnull(A5.LotInfo_LotCode,'') cBatch,'' version ,'' brand,
  65. '' as cFree1,
  66. '' as cFree2,
  67. '' as cFree3,
  68. '' as cFree4,
  69. '' as cFree5,
  70. '' as cFree6,
  71. '' as cFree7,
  72. '' as cFree8,
  73. '' as cFree9,
  74. '' as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
  75. ,A13.Code as WorkPoint
  76. INTO #TempTrans
  77. FROM {1}.dbo.InvDoc_TransferIn A1
  78. LEFT JOIN {1}.dbo.InvDoc_TransINLine A2 ON A2.TransferIn=A1.ID
  79. LEFT JOIN {1}.dbo.CBO_Wh A3 ON A2.TransInWh=A3.ID
  80. LEFT JOIN {1}.dbo.CBO_Wh_Trl A4 ON A4.ID = A3.ID AND A4.SysMLFlag='zh-CN'
  81. LEFT JOIN {1}.dbo.InvDoc_TransINSubLine A5 ON A2.ID=A5.TransINLine
  82. LEFT JOIN {1}.dbo.CBO_Wh A6 ON A5.TransOutWh=A6.ID
  83. LEFT JOIN {1}.dbo.CBO_Wh_Trl A7 ON A7.ID = A6.ID AND A7.SysMLFlag='zh-CN'
  84. LEFT JOIN {1}.dbo.Base_Organization A8 ON A1.Org=A8.ID
  85. LEFT JOIN {1}.dbo.[CBO_Project] as A11 on (A2.[Project] = A11.[ID])
  86. LEFT JOIN {1}.dbo.[CBO_Project] as A12 on (A5.[Project] = A12.[ID])
  87. LEFT JOIN {1}.dbo.Base_Organization A13 ON A1.Org=A13.ID
  88. where ISNULL(A2.ModifiedOn ,A2.CreatedOn)>=@LastTime and A1.Status=1
  89. update #TempTrans 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,'')
  90. select distinct
  91. Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
  92. INTO #TempExtension
  93. from #TempTrans
  94. IF NOT EXISTS(SELECT * FROM #TempTrans)
  95. RETURN";
  96. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempTrans");
  97. Dictionary<string, string> value = new Dictionary<string, string>();
  98. value.Add("ID", "NEWID()");
  99. value.Add("BatchCode", "a.cBatch");
  100. value.Add("version", "a.version");
  101. value.Add("brand", "a.brand");
  102. value.Add("ProjectCode", "a.ProjectCode");
  103. value.Add("cFree1", "a.cFree1");
  104. value.Add("cFree2", "a.cFree2");
  105. value.Add("cFree3", "a.cFree3");
  106. value.Add("cFree4", "a.cFree4");
  107. value.Add("cFree5", "a.cFree5");
  108. value.Add("cFree6", "a.cFree6");
  109. value.Add("cFree7", "a.cFree7");
  110. value.Add("cFree8", "a.cFree8");
  111. value.Add("cFree9", "a.cFree9");
  112. value.Add("cFree10", "a.cFree10");
  113. value.Add("Colspan", "a.Colspan");
  114. value.Add("MTIME", "GETDATE()");
  115. value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  116. value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  117. value.Add("WorkPoint", "'" + WorkPoint + "'");
  118. //插入新增数据->ICSExtension表
  119. sql += ICSHelper.InsertSQL("ICSExtension", value)
  120. + @"#TempExtension a
  121. 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
  122. WHERE b.Colspan IS NULL";
  123. sql += @"--删除数据
  124. -- DELETE ICSTransfer where ISNULL(TransferDetailID,'') NOT IN ( SELECT autoID FROM {1}.dbo.TransVouchs )
  125. SELECT ISNULL(a.TransferDetailID,'') TransferDetailID INTO #tableICSTransfer
  126. FROM ICSTransfer a With(NoLock)
  127. LEFT JOIN {1}.dbo.[InvDoc_TransINLine] b With(NoLock) ON ISNULL(a.TransferDetailID,'')=b.ID
  128. WHERE a.WorkPoint='{0}' and b.ID IS NULL
  129. DELETE ICSTransfer
  130. WHERE WorkPoint='{0}' and ISNULL(TransferDetailID,'') IN ( SELECT TransferDetailID from #tableICSTransfer)
  131. ";
  132. sql += "\r\n";
  133. Dictionary<string, string> values = new Dictionary<string, string>();
  134. values.Add("TransferNO", "a.TransferNO");
  135. values.Add("Sequence", "a.Sequence");
  136. values.Add("FromWarehouseCode", "a.FromWarehouseCode");
  137. //values.Add("FromLocationCode", "a.FromLocationCode");
  138. values.Add("ToWarehouseCode", "a.ToWarehouseCode");
  139. values.Add("Status", "a.Status");
  140. values.Add("InvCode", "a.InvCode");
  141. values.Add("Quantity", "a.Quantity");
  142. values.Add("Amount", "a.Amount");
  143. values.Add("Type", "a.Type");
  144. values.Add("Memo", "a.Memo");
  145. values.Add("CreateDateTime", "a.CreateDateTime");
  146. values.Add("CreatePerson", "a.CreatePerson");
  147. values.Add("TransferID", "a.TransferID");
  148. values.Add("TransferDetailID", "a.TransferDetailID");
  149. values.Add("ExtensionID", "c.ID");
  150. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  151. values.Add("MUSERNAME", "'" + ConstWorkPoint.Musername + "'");
  152. values.Add("WorkPoint", "'" + WorkPoint + "'");
  153. values.Add("MTIME", "a.MTIME");
  154. //更新存在数据
  155. sql += "\r\n";
  156. sql += ICSHelper.UpdateSQL("b", values)
  157. + @" #TempTrans a
  158. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID and a.WorkPoint=b.WorkPoint
  159. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  160. WHERE a.WorkPoint='" + WorkPoint + "' ";
  161. values.Add("ID", "newid()");
  162. values.Add("TransferQuantity", "0");
  163. //values.Add("EATTRIBUTE3", "a.EATTRIBUTE3");
  164. //插入新增数据
  165. sql += "\r\n";
  166. sql += ICSHelper.InsertSQL("ICSTransfer", values)
  167. + @" #TempTrans a
  168. LEFT JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID and a.WorkPoint=b.WorkPoint
  169. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  170. WHERE b.TransferDetailID IS NULL and a.WorkPoint='" + WorkPoint + @"' ";
  171. sql += "DROP TABLE #TempTrans";
  172. sql += " DROP TABLE #TempExtension " +
  173. " DROP TABLE #tableICSTransfer";
  174. sql = string.Format(sql, WorkPoint, erpName);
  175. ICSHelper.ExecuteDate(conStr, sql);
  176. #endregion
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. log.Error(ex.ToString());
  182. }
  183. }
  184. }
  185. }