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

3195 lines
168 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
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 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
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 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
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 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
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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using NFine.Domain._03_Entity.WMS;
  18. namespace NFine.Application.WMS
  19. {
  20. public class PickMaterialApp : RepositoryFactory<ICSVendor>
  21. {
  22. public static DataTable Invmes = new DataTable();
  23. //工单备料(工单子件)
  24. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  25. {
  26. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  27. DataTable dt = new DataTable();
  28. var queryParam = queryJson.ToJObject();
  29. List<DbParameter> parameter = new List<DbParameter>();
  30. StringBuilder sqlstring = new StringBuilder();
  31. #region [SQL]
  32. // sql = @"select a.ID,b.MOCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  33. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  34. //from ICSMOPick a
  35. //left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  36. //left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  37. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  38. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  39. // sql += " WHERE 1=1 and e.ID is null";
  40. sqlstring.Append($@"select a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  41. case when max(d.SourceID) is null then '' else '' end as IsNew,
  42. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,
  43. f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  44. from ICSMO a
  45. inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  46. left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
  47. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  48. where a.WorkPoint='{WorkPoint}' ");
  49. if (!string.IsNullOrWhiteSpace(queryJson))
  50. {
  51. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  52. {
  53. sqlstring.Append($" and a.MOCode like '%{queryParam["POCode"]}%' ");
  54. }
  55. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  56. {
  57. sqlstring.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  58. }
  59. }
  60. sqlstring.Append(@" group by a.MOCode, a.WorkPoint,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,
  61. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  62. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10");
  63. #endregion
  64. return Repository().FindTablePageBySql(sqlstring.ToString(), parameter.ToArray(), ref jqgridparam);
  65. }
  66. //工单备料(工单子件)子表查询
  67. public DataTable GetSubGridJson1(string Code)
  68. {
  69. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  70. DataTable dt = new DataTable();
  71. //var queryParam = queryJson.ToJObject();
  72. List<DbParameter> parameter = new List<DbParameter>();
  73. string sql = @" select a.ID,b.MOCode as Code,a.Sequence+'-'+b.Sequence AS Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  74. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  75. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  76. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  77. from ICSMOPick a
  78. left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  79. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  80. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  81. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  82. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  83. where b.MOCode='{0}' and a.WorkPoint='{1}'";
  84. sql = string.Format(sql, Code, WorkPoint);
  85. return Repository().FindTableBySql(sql.ToString());
  86. }
  87. //工单领料(发料申请)
  88. public DataTable GetGridJson2(string queryJson, ref Pagination jqgridparam)
  89. {
  90. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  91. DataTable dt = new DataTable();
  92. var queryParam = queryJson.ToJObject();
  93. List<DbParameter> parameter = new List<DbParameter>();
  94. StringBuilder sqlString = new StringBuilder();
  95. #region [SQL]
  96. // select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  97. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  98. // from ICSMOApply a
  99. // left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
  100. // left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  101. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  102. sqlString.Append($@"
  103. SELECT * from (select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
  104. a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.createperson as MUSER,a.WHCode,detail.LocationCode AS Area,
  105. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  106. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  107. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,
  108. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  109. case when (a.EATTRIBUTE='01' OR a.EATTRIBUTE='20') then(
  110. case when sum(a.Quantity)=sum(IssueQuantity) and a.MUSERName != 'JOB' then ''
  111. when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' then '' else '' end)
  112. else (case when sum(a.Quantity) =sum(IssueQuantity) then ''
  113. when sum(a.Quantity)!=sum(IssueQuantity) AND sum(IssueQuantity)>0 then '' else '' end) END as Status,
  114. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,
  115. f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.ID,
  116. case when a.MUSER!= 'JOB' then a.MUSER else '' end AS PickName
  117. from ICSMOApply a
  118. left JOIN ICSInventory b ON b.InvCode=a.InvCode
  119. LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  120. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  121. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  122. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  123. where a.WorkPoint='{WorkPoint}' and a.EATTRIBUTE!='17'");
  124. if (!string.IsNullOrWhiteSpace(queryJson))
  125. {
  126. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  127. {
  128. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  129. }
  130. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  131. {
  132. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  133. }
  134. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  135. {
  136. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  137. }
  138. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  139. {
  140. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  141. }
  142. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  143. {
  144. sqlString.Append($@" and a.OrderNumber like '%{queryParam["Order"]}%' ");
  145. }
  146. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  147. {
  148. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  149. WHERE
  150. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  151. }
  152. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  153. {
  154. sqlString.Append($@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ");
  155. }
  156. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  157. {
  158. sqlString.Append($@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ");
  159. }
  160. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  161. {
  162. if (queryParam["NeedDate"].ToString() == "3")
  163. {
  164. sqlString.Append($@" and sum(a.Quantity) = sum(IssueQuantity) and a.MUSERName != 'JOB ");
  165. }
  166. else if (queryParam["NeedDate"].ToString() == "2")
  167. {
  168. sqlString.Append($@" and sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' ");
  169. }
  170. else if (queryParam["NeedDate"].ToString() == "1")
  171. {
  172. sqlString.Append($@" and sum(a.Quantity) >= sum(IssueQuantity) ");
  173. }
  174. }
  175. }
  176. sqlString.Append(@" group by a.ApplyCode, a.WorkPoint,a.IssueQuantity,a.CreateDateTime,a.createperson,
  177. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  178. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.WHCode,detail.LocationCode,a.ID,a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  179. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,a.MUSERName,a.MUSER ) as t where t.row=1");
  180. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  181. {
  182. if (queryParam["Status"].ToString() == "3")
  183. {
  184. sqlString.Append($@" AND t.Status='已过账' ");
  185. }
  186. else if (queryParam["Status"].ToString() == "2")
  187. {
  188. sqlString.Append($@" AND t.Status='已配料' ");
  189. }
  190. else if (queryParam["Status"].ToString() == "1")
  191. {
  192. sqlString.Append($@" AND t.Status='未配料' ");
  193. }
  194. }
  195. #endregion
  196. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  197. }
  198. //工单领料(发料申请)子表查询
  199. public DataTable GetSubGridJson2(string queryJson, string Code)
  200. {
  201. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  202. DataTable dt = new DataTable();
  203. var queryParam = queryJson.ToJObject();
  204. List<DbParameter> parameter = new List<DbParameter>();
  205. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  206. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,a.OrderNumber,
  207. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  208. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  209. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,
  210. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  211. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  212. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  213. from ICSMOApply a
  214. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  215. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  216. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  217. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  218. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  219. where a.ApplyCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE!='17'";
  220. if (!string.IsNullOrWhiteSpace(queryJson))
  221. {
  222. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  223. {
  224. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  225. }
  226. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  227. {
  228. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  229. }
  230. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  231. {
  232. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  233. }
  234. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  235. {
  236. sql += $@" and a.OrderNumber like '%{queryParam["Order"]}%' ";
  237. }
  238. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  239. {
  240. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  241. WHERE
  242. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  243. }
  244. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  245. {
  246. sql += $@" and a.CreateDateTime like '%{queryParam["CreateDate"]}%' ";
  247. }
  248. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  249. {
  250. sql += $@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ";
  251. }
  252. }
  253. sql += " ) c WHERE c.row=1 ";
  254. sql = string.Format(sql, Code, WorkPoint);
  255. return Repository().FindTableBySql(sql.ToString());
  256. }
  257. //售后领料
  258. public DataTable GetGridJson12(string queryJson, ref Pagination jqgridparam)
  259. {
  260. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  261. DataTable dt = new DataTable();
  262. var queryParam = queryJson.ToJObject();
  263. List<DbParameter> parameter = new List<DbParameter>();
  264. StringBuilder sqlString = new StringBuilder();
  265. #region [SQL]
  266. // select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  267. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  268. // from ICSMOApply a
  269. // left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
  270. // left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  271. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  272. sqlString.Append($@"
  273. SELECT * from (select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
  274. a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME ,a.createperson MUSER,a.WHCode,detail.LocationCode AS Area,
  275. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  276. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  277. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,
  278. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  279. case when sum(a.Quantity) =sum(IssueQuantity) then ''
  280. when sum(a.Quantity)!=sum(IssueQuantity) AND sum(IssueQuantity)>0 then ''
  281. else '' end as Status,
  282. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,
  283. f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.ID
  284. from ICSMOApply a
  285. left JOIN ICSInventory b ON b.InvCode=a.InvCode
  286. LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  287. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  288. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  289. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  290. where a.WorkPoint='{WorkPoint}' and a.EATTRIBUTE='17' ");
  291. if (!string.IsNullOrWhiteSpace(queryJson))
  292. {
  293. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  294. {
  295. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  296. }
  297. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  298. {
  299. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  300. }
  301. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  302. {
  303. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  304. }
  305. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  306. {
  307. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  308. }
  309. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  310. {
  311. sqlString.Append($@" and a.OrderNumber like '%{queryParam["Order"]}%' ");
  312. }
  313. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  314. {
  315. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  316. WHERE
  317. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  318. }
  319. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  320. {
  321. sqlString.Append($@" and a.CreateDateTime >='{queryParam["CreateDate"].ToDate()}' and a.CreateDateTime <'{queryParam["CreateDate"].ToDate().AddDays(+1)}' ");
  322. }
  323. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  324. {
  325. sqlString.Append($@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ");
  326. }
  327. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  328. {
  329. if (queryParam["NeedDate"].ToString() == "3")
  330. {
  331. sqlString.Append($@" and sum(a.Quantity) = sum(IssueQuantity) and a.MUSERName != 'JOB ");
  332. }
  333. else if (queryParam["NeedDate"].ToString() == "2")
  334. {
  335. sqlString.Append($@" and sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' ");
  336. }
  337. else if (queryParam["NeedDate"].ToString() == "1")
  338. {
  339. sqlString.Append($@" and sum(a.Quantity) >= sum(IssueQuantity) ");
  340. }
  341. }
  342. }
  343. sqlString.Append(@" group by a.ApplyCode, a.WorkPoint,a.IssueQuantity,a.CreateDateTime,a.createperson,
  344. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  345. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.WHCode,detail.LocationCode,a.ID,a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  346. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,a.MUSERName) as t where t.row=1");
  347. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  348. {
  349. if (queryParam["Status"].ToString() == "3")
  350. {
  351. sqlString.Append($@" AND t.Status='已过帐' ");
  352. }
  353. else if (queryParam["Status"].ToString() == "2")
  354. {
  355. sqlString.Append($@" AND t.Status='已配料' ");
  356. }
  357. else if (queryParam["Status"].ToString() == "1")
  358. {
  359. sqlString.Append($@" AND t.Status='未配料' ");
  360. }
  361. }
  362. #endregion
  363. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  364. }
  365. //售后领料(子表查询)
  366. public DataTable GetSubGridJson12(string queryJson, string Code)
  367. {
  368. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  369. DataTable dt = new DataTable();
  370. var queryParam = queryJson.ToJObject();
  371. List<DbParameter> parameter = new List<DbParameter>();
  372. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  373. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,a.OrderNumber,
  374. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  375. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  376. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,
  377. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  378. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  379. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  380. from ICSMOApply a
  381. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  382. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  383. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  384. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  385. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  386. where a.ApplyCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE='17'";
  387. if (!string.IsNullOrWhiteSpace(queryJson))
  388. {
  389. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  390. {
  391. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  392. }
  393. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  394. {
  395. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  396. }
  397. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  398. {
  399. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  400. }
  401. if (!string.IsNullOrWhiteSpace(queryParam["Order"].ToString()))
  402. {
  403. sql += $@" and a.OrderNumber like '%{queryParam["Order"]}%' ";
  404. }
  405. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  406. {
  407. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  408. WHERE
  409. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  410. }
  411. if (!string.IsNullOrWhiteSpace(queryParam["CreateDate"].ToString()))
  412. {
  413. sql += $@" and a.CreateDateTime like '%{queryParam["CreateDate"]}%' ";
  414. }
  415. if (!string.IsNullOrWhiteSpace(queryParam["NeedDate"].ToString()))
  416. {
  417. sql += $@" and a.NeedDate like '%{queryParam["NeedDate"]}%' ";
  418. }
  419. }
  420. sql += " ) c WHERE c.row=1 ";
  421. sql = string.Format(sql, Code, WorkPoint);
  422. return Repository().FindTableBySql(sql.ToString());
  423. }
  424. //工单材料出库(材料出库)
  425. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  426. {
  427. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  428. DataTable dt = new DataTable();
  429. var queryParam = queryJson.ToJObject();
  430. List<DbParameter> parameter = new List<DbParameter>();
  431. StringBuilder sqlString = new StringBuilder();
  432. #region [SQL]
  433. // sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  434. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  435. // from ICSMOIssue a
  436. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  437. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  438. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  439. // sql += " WHERE 1=1 and e.ID is null";
  440. sqlString.Append($@"SELECT * FROM(SELECT row_number ( ) OVER ( partition BY a.IssueCode ORDER BY a.IssueCode ) AS row,
  441. a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  442. case when max(e.SourceID) is null then '' else ''
  443. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  444. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  445. from ICSMOIssue a
  446. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  447. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  448. where a.WorkPoint = '{WorkPoint}' ");
  449. if (!string.IsNullOrWhiteSpace(queryJson))
  450. {
  451. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  452. {
  453. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  454. }
  455. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  456. {
  457. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  458. }
  459. }
  460. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,f.BatchCode,
  461. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  462. f.cFree8, f.cFree9, f.cFree10 ) AS t WHERE t.row= 1 ");
  463. #endregion
  464. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  465. }
  466. //工单材料出库(材料出库)子表查询
  467. public DataTable GetSubGridJson3(string Code)
  468. {
  469. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  470. DataTable dt = new DataTable();
  471. //var queryParam = queryJson.ToJObject();
  472. List<DbParameter> parameter = new List<DbParameter>();
  473. string sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  474. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  475. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  476. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  477. from ICSMOIssue a
  478. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  479. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  480. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  481. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  482. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  483. sql = string.Format(sql, Code, WorkPoint);
  484. return Repository().FindTableBySql(sql.ToString());
  485. }
  486. //委外备料(委外备料)
  487. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  488. {
  489. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  490. DataTable dt = new DataTable();
  491. var queryParam = queryJson.ToJObject();
  492. List<DbParameter> parameter = new List<DbParameter>();
  493. StringBuilder sqlString = new StringBuilder();
  494. #region [SQL]
  495. sqlString.Append($@"select * from (select row_number() over(partition by b.OOCode order by b.OOCode) row, b.OOCode as Code,
  496. b.CreateDateTime as MTIME,
  497. b.CreatePerson as MUSER,
  498. case
  499. when max(e.SourceID) is null then ''
  500. else ''
  501. end as IsNew,
  502. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  503. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  504. from ICSOOPick a
  505. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.WorkPoint = b.WorkPoint
  506. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  507. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  508. WHERE b.WorkPoint = '{WorkPoint}' ");
  509. if (!string.IsNullOrWhiteSpace(queryJson))
  510. {
  511. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  512. {
  513. sqlString.Append($@" and a.OOCode like '%{queryParam["POCode"]}%' ");
  514. }
  515. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  516. {
  517. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  518. }
  519. }
  520. sqlString.Append(@" group by b.OOCode,b.CreateDateTime,b.CreatePerson,f.Colspan ,f.ProjectCode ,
  521. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  522. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10) t where t.row=1");
  523. #endregion
  524. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  525. }
  526. //委外备料(委外备料)子表查询
  527. public DataTable GetSubGridJson4(string Code)
  528. {
  529. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  530. DataTable dt = new DataTable();
  531. //var queryParam = queryJson.ToJObject();
  532. List<DbParameter> parameter = new List<DbParameter>();
  533. string sql = @"select a.ID,b.OOCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  534. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  535. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  536. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  537. from ICSOOPick a
  538. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  539. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  540. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  541. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  542. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  543. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  544. sql = string.Format(sql, Code, WorkPoint);
  545. return Repository().FindTableBySql(sql.ToString());
  546. }
  547. //委外领料(委外发料申请)
  548. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  549. {
  550. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  551. DataTable dt = new DataTable();
  552. var queryParam = queryJson.ToJObject();
  553. List<DbParameter> parameter = new List<DbParameter>();
  554. StringBuilder sqlString = new StringBuilder();
  555. #region [SQL]
  556. // sql = @"select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  557. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  558. // from ICSOApply a
  559. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  560. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  561. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  562. // sql += " WHERE 1=1 and e.ID is null";
  563. sqlString.Append($@"select * from (select row_number() over (partition by a.ApplyCode order by a.ApplyCode ) row, a.ApplyCode as Code,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.CreatePerson as MUSER,
  564. case when max(e.SourceID) is null then ''
  565. else ''
  566. end as IsNew,
  567. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  568. case when sum(a.Quantity) =sum(IssueQuantity) then ''
  569. when sum(a.Quantity)!=sum(IssueQuantity) AND sum(IssueQuantity)>0 then ''
  570. else '' end as Status,
  571. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  572. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID
  573. from ICSOApply a
  574. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  575. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  576. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  577. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  578. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  579. where a.WorkPoint = '{WorkPoint}'");
  580. if (!string.IsNullOrWhiteSpace(queryJson))
  581. {
  582. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  583. {
  584. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  585. }
  586. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  587. {
  588. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  589. }
  590. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  591. {
  592. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  593. }
  594. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  595. {
  596. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  597. }
  598. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  599. {
  600. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  601. WHERE
  602. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  603. }
  604. }
  605. sqlString.Append(@"group by a.ApplyCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  606. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  607. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID ) t where row=1");
  608. #endregion
  609. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  610. }
  611. //委外领料(委外发料申请)子表查询
  612. public DataTable GetSubGridJson5(string Code, string queryJson)
  613. {
  614. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  615. DataTable dt = new DataTable();
  616. var queryParam = queryJson.ToJObject();
  617. List<DbParameter> parameter = new List<DbParameter>();
  618. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  619. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode, a.SourceCode,a.SourceSequence,a.VenCode,a.VenName,
  620. b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  621. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity,detail.LocationCode AS Area,
  622. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  623. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  624. from ICSOApply a
  625. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  626. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  627. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  628. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  629. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  630. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  631. if (!string.IsNullOrWhiteSpace(queryJson))
  632. {
  633. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  634. {
  635. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  636. }
  637. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  638. {
  639. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  640. }
  641. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  642. {
  643. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  644. }
  645. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  646. {
  647. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  648. WHERE
  649. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  650. }
  651. }
  652. sql += " ) c WHERE c.row=1 ";
  653. sql = string.Format(sql, Code, WorkPoint);
  654. return Repository().FindTableBySql(sql.ToString());
  655. }
  656. //委外材料出库(委外发料申请)
  657. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  658. {
  659. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  660. DataTable dt = new DataTable();
  661. var queryParam = queryJson.ToJObject();
  662. List<DbParameter> parameter = new List<DbParameter>();
  663. StringBuilder sqlString = new StringBuilder();
  664. #region [SQL]
  665. // sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseCode,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  666. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  667. // from ICSOIssue a
  668. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  669. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  670. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  671. // sql += " WHERE 1=1 and e.ID is null";
  672. sqlString.Append($@"select * from(select row_number() over(partition by a.IssueCode order by a.IssueCode) row, a.IssueCode as Code,
  673. a.CreateDateTime as MTIME,
  674. a.CreatePerson as MUSER,
  675. case
  676. when max(e.SourceID) is null then ''
  677. else ''
  678. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  679. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  680. f.cFree8,f.cFree9,f.cFree10
  681. from ICSOIssue a
  682. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  683. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  684. where a.WorkPoint = '{WorkPoint}'");
  685. if (!string.IsNullOrWhiteSpace(queryJson))
  686. {
  687. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  688. {
  689. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  690. }
  691. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  692. {
  693. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  694. }
  695. }
  696. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  697. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  698. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10) t where t.row=1");
  699. #endregion
  700. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  701. }
  702. //委外材料出库(委外发料申请)子表查询
  703. public DataTable GetSubGridJson6(string Code)
  704. {
  705. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  706. DataTable dt = new DataTable();
  707. //var queryParam = queryJson.ToJObject();
  708. List<DbParameter> parameter = new List<DbParameter>();
  709. string sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseCode,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  710. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  711. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  712. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  713. from ICSOIssue a
  714. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  715. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  716. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  717. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  718. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  719. sql = string.Format(sql, Code, WorkPoint);
  720. return Repository().FindTableBySql(sql.ToString());
  721. }
  722. //销售发货(销售发货)
  723. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  724. {
  725. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  726. DataTable dt = new DataTable();
  727. var queryParam = queryJson.ToJObject();
  728. List<DbParameter> parameter = new List<DbParameter>();
  729. StringBuilder sqlString = new StringBuilder();
  730. #region [SQL]
  731. // sql = @"select a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  732. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  733. // from ICSSDN a
  734. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  735. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  736. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  737. // sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  738. sqlString.Append($@"SELECT * from (SELECT Row_Number() over(partition by a.SDNCode Order by a.SDNCode) as r, a.SDNCode AS Code,
  739. CONVERT(varchar(100),a.CreateDateTime,23) AS MTIME,
  740. a.CreatePerson AS MUSER,
  741. a.CusCode,a.CusName,
  742. (CASE WHEN max(e.SourceID) IS NULL THEN '' ELSE '' END) AS IsNew,
  743. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  744. case when sum(a.Quantity) =sum(SDNQuantity) then ''
  745. when sum(a.Quantity)!=sum(SDNQuantity) AND sum(SDNQuantity)>0 then ''
  746. else '' end as Status,
  747. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  748. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10,a.ID
  749. FROM ICSSDN a
  750. LEFT JOIN ICSMOPickMerge e ON a.ID = e.SourceID AND a.WorkPoint = e.WorkPoint
  751. LEFT JOIN ICSExtension f ON a.ExtensionID = f.ID AND a.WorkPoint = f.WorkPoint
  752. LEFT JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  753. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  754. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.SDNCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  755. WHERE a.WorkPoint = '{WorkPoint}' ");
  756. if (!string.IsNullOrWhiteSpace(queryJson))
  757. {
  758. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  759. {
  760. sqlString.Append($" and a.SDNCode like '%{queryParam["POCode"]}%' ");
  761. }
  762. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  763. {
  764. sqlString.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  765. }
  766. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  767. {
  768. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  769. }
  770. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  771. {
  772. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  773. }
  774. if (!string.IsNullOrWhiteSpace(queryParam["CusCode"].ToString()))
  775. {
  776. sqlString.Append($@" and a.CusCode like '%{queryParam["CusCode"]}%' ");
  777. }
  778. if (!string.IsNullOrWhiteSpace(queryParam["CusName"].ToString()))
  779. {
  780. sqlString.Append($@" and a.CusName like '%{queryParam["CusName"]}%' ");
  781. }
  782. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  783. {
  784. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  785. WHERE
  786. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  787. }
  788. }
  789. sqlString.Append(@"GROUP BY a.SDNCode, a.CreateDateTime, a.CreatePerson, f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  790. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10,a.ID,a.CusCode,a.CusName) t WHERE t.r=1");
  791. #endregion
  792. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  793. }
  794. //销售发货(销售发货)子表查询
  795. public DataTable GetSubGridJson7(string Code, string queryJson)
  796. {
  797. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  798. DataTable dt = new DataTable();
  799. var queryParam = queryJson.ToJObject();
  800. List<DbParameter> parameter = new List<DbParameter>();
  801. string sql = @"SELECT * FROM (select row_number() over(partition by a.SDNCode,a.InvCode,a.Sequence ORDER BY a.SDNCode) as row,
  802. a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode
  803. ,a.WorkPoint,a.Points,a.DeliveryType,a.DeliveryDescribe,a.InvDescribe,a.OtherDescribe,a.CusCode,a.CusName,
  804. a.SalesUnit,a.StockIndicator,a.IsSerialNumber,
  805. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  806. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity,detail.LocationCode AS Area
  807. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  808. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.SDNQuantity as IssueQuantity
  809. from ICSSDN a
  810. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  811. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  812. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  813. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  814. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  815. where a.SDNCode='{0}' and a.WorkPoint='{1}'";
  816. if (!string.IsNullOrWhiteSpace(queryJson))
  817. {
  818. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  819. {
  820. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  821. }
  822. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  823. {
  824. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  825. }
  826. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  827. {
  828. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  829. }
  830. if (!string.IsNullOrWhiteSpace(queryParam["CusCode"].ToString()))
  831. {
  832. sql += $@" and a.CusCode like '%{queryParam["CusCode"]}%' ";
  833. }
  834. if (!string.IsNullOrWhiteSpace(queryParam["CusName"].ToString()))
  835. {
  836. sql += $@" and a.CusName like '%{queryParam["CusName"]}%' ";
  837. }
  838. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  839. {
  840. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  841. WHERE
  842. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  843. }
  844. }
  845. sql += " ) c WHERE c.row=1 ";
  846. sql = string.Format(sql, Code, WorkPoint);
  847. return Repository().FindTableBySql(sql.ToString());
  848. }
  849. //其它出库(其它出库)
  850. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  851. {
  852. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  853. DataTable dt = new DataTable();
  854. var queryParam = queryJson.ToJObject();
  855. List<DbParameter> parameter = new List<DbParameter>();
  856. StringBuilder sqlString = new StringBuilder();
  857. #region [SQL]
  858. // sql = @"select a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  859. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  860. //from ICSOtherOut a
  861. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  862. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  863. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  864. // sql += " WHERE 1=1 and e.ID is null ";
  865. sqlString.Append($@"select * from(select row_number() over(partition by a.OutCode order by a.OutCode) row, a.OutCode as Code,
  866. CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,
  867. a.CreatePerson as MUSER,
  868. case
  869. when max(e.SourceID) is null then ''
  870. else ''
  871. end as IsNew,
  872. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  873. case when sum(a.Quantity)=sum(a.OutQuantity) then ''
  874. when sum(a.Quantity)!=sum(a.OutQuantity) and sum(a.OutQuantity)>0 then ''
  875. else '' END AS Status,
  876. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  877. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID
  878. from ICSOtherOut a
  879. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  880. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  881. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  882. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  883. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.OutCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  884. where a.WorkPoint = '{WorkPoint}'");
  885. #endregion
  886. if (!string.IsNullOrWhiteSpace(queryJson))
  887. {
  888. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  889. {
  890. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  891. }
  892. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  893. {
  894. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  895. }
  896. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  897. {
  898. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  899. }
  900. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  901. {
  902. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  903. }
  904. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  905. {
  906. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  907. WHERE
  908. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  909. }
  910. }
  911. sqlString.Append(@" group by a.OutCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,f.BatchCode,
  912. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,
  913. f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID) t where t.row=1");
  914. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  915. }
  916. //其它出库(其它出库)子表查询
  917. public DataTable GetSubGridJson8(string Code, string queryJson)
  918. {
  919. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  920. DataTable dt = new DataTable();
  921. var queryParam = queryJson.ToJObject();
  922. List<DbParameter> parameter = new List<DbParameter>();
  923. string sql = @"SELECT * FROM (select row_number() over(partition by a.OutCode,a.InvCode,a.Sequence ORDER BY a.OutCode) as row,
  924. a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.Quantity,
  925. a.InvCode,a.WorkPoint,a.OrderType, a.TypeDescribe,a.CostCenter,a.Remarks,a.PersonNumber,a.InvDescribe,
  926. a.Unit,a.StockIndicator,
  927. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  928. case when e.SourceID is null then '' else '' end as IsNew,detail.LocationCode AS Area
  929. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  930. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  931. from ICSOtherOut a
  932. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  933. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  934. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  935. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  936. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  937. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  938. if (!string.IsNullOrWhiteSpace(queryJson))
  939. {
  940. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  941. {
  942. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  943. }
  944. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  945. {
  946. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  947. }
  948. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  949. {
  950. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  951. }
  952. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  953. {
  954. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  955. WHERE
  956. F_Define3='HGAreaConfig' AND F_Define1=a.WHCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  957. }
  958. }
  959. sql += " ) c WHERE c.row=1 ";
  960. sql = string.Format(sql, Code, WorkPoint);
  961. return Repository().FindTableBySql(sql.ToString());
  962. }
  963. //借用(借用)
  964. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  965. {
  966. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  967. DataTable dt = new DataTable();
  968. var queryParam = queryJson.ToJObject();
  969. List<DbParameter> parameter = new List<DbParameter>();
  970. StringBuilder sqlString = new StringBuilder();
  971. #region [SQL]
  972. // sql = @"
  973. //select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  974. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  975. // from ICSBrrow a
  976. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  977. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  978. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  979. // sql += " WHERE 1=1 and e.ID is null ";
  980. sqlString.Append($@"select * from(select row_number() over(partition by a.BrrowCode order by a.BrrowCode) row, a.BrrowCode as Code,
  981. a.CreateDateTime as MTIME,
  982. a.CreatePerson as MUSER,
  983. case
  984. when max(e.SourceID) is null then ''
  985. else ''
  986. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  987. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  988. f.cFree8,f.cFree9,f.cFree10
  989. from ICSBrrow a
  990. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  991. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  992. where a.WorkPoint = '{WorkPoint}'");
  993. if (!string.IsNullOrWhiteSpace(queryJson))
  994. {
  995. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  996. {
  997. sqlString.Append($@" and a.BrrowCode like '%{queryParam["POCode"]}%' ");
  998. }
  999. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1000. {
  1001. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  1002. }
  1003. }
  1004. sqlString.Append(@"group by a.BrrowCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  1005. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  1006. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,
  1007. f.cFree10) t where t.row=1");
  1008. #endregion
  1009. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  1010. }
  1011. //借用(借用)子表查询
  1012. public DataTable GetSubGridJson9(string Code)
  1013. {
  1014. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1015. DataTable dt = new DataTable();
  1016. //var queryParam = queryJson.ToJObject();
  1017. List<DbParameter> parameter = new List<DbParameter>();
  1018. string sql = @"select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  1019. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  1020. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1021. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.BrrowQuantity as IssueQuantity
  1022. from ICSBrrow a
  1023. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1024. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1025. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  1026. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1027. where a.BrrowCode='{0}' and a.WorkPoint='{1}'";
  1028. sql = string.Format(sql, Code, WorkPoint);
  1029. return Repository().FindTableBySql(sql.ToString());
  1030. }
  1031. //物料调拨
  1032. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  1033. {
  1034. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1035. DataTable dt = new DataTable();
  1036. var queryParam = queryJson.ToJObject();
  1037. List<DbParameter> parameter = new List<DbParameter>();
  1038. StringBuilder sqlString = new StringBuilder();
  1039. #region [SQL]
  1040. // sql = @"
  1041. //select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  1042. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  1043. // from ICSBrrow a
  1044. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1045. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1046. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  1047. // sql += " WHERE 1=1 and e.ID is null ";
  1048. sqlString.Append($@"select * from (select row_number() over(partition by a.TransferNO order by a.TransferNO) row,
  1049. a.TransferNO as Code,a.ID,CONVERT(varchar(100),a.CreateDateTime,23) as MTIME,a.CreatePerson as MUSER,
  1050. case
  1051. when max(e.SourceID) is null then ''
  1052. else ''
  1053. end as IsNew,
  1054. case when max(k.TransCode) is null then '' else '' end as IsOccupy,
  1055. case when sum(a.Quantity)=sum(a.TransferQuantity) then ''
  1056. when sum(a.Quantity)!=sum(a.TransferQuantity) and a.TransferQuantity>0 then ''
  1057. else '' END AS Status,
  1058. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  1059. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  1060. from ICSTransfer a
  1061. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  1062. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  1063. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1064. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.ToWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  1065. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.TransferNO=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  1066. where a.WorkPoint = '{WorkPoint}' and a.Status = '2'");
  1067. if (!string.IsNullOrWhiteSpace(queryJson))
  1068. {
  1069. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1070. {
  1071. sqlString.Append($@" and a.TransferNO like '%{queryParam["POCode"]}%' ");
  1072. }
  1073. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1074. {
  1075. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  1076. }
  1077. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  1078. {
  1079. sqlString.Append($@" and a.ToWarehouseCode like '%{queryParam["WHCode"]}%' ");
  1080. }
  1081. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  1082. {
  1083. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  1084. }
  1085. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  1086. {
  1087. sqlString.Append($@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  1088. WHERE
  1089. F_Define3='HGAreaConfig' AND F_Define1=a.FromWarehouseCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ");
  1090. }
  1091. }
  1092. sqlString.Append(@"group by a.TransferNO,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  1093. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  1094. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID) t where t.row=1");
  1095. #endregion
  1096. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  1097. }
  1098. //物料调拨子表查询
  1099. public DataTable GetSubGridJson10(string Code, string queryJson)
  1100. {
  1101. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1102. DataTable dt = new DataTable();
  1103. var queryParam = queryJson.ToJObject();
  1104. List<DbParameter> parameter = new List<DbParameter>();
  1105. string sql = @"SELECT * from (select row_number() over(partition by a.TransferNO,a.InvCode,
  1106. a.Sequence ORDER BY a.TransferNO) as row, a.ID,a.TransferNO as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.FromWarehouseCode as WHCode,b.WarehouseName,detail.LocationCode AS Area,
  1107. a.InvCode,a.ToWarehouseCode,a.EATTRIBUTE1 AS ReceiveWork,a.WorkPoint,a.OrderType,
  1108. a.TypeDescribe,a.Remarks,a.PersonNumber,a.InvDescribe,
  1109. a.Unit,a.StockIndicator,a.ReceiveInvCode,a.ReceiveInvDescribe,
  1110. a.ReceiveStock,a.ReceiveSales,a.ReceiveSequence,a.Remark2,
  1111. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  1112. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  1113. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1114. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.TransferQuantity as IssueQuantity
  1115. from ICSTransfer a
  1116. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1117. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1118. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.ToWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  1119. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  1120. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1121. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  1122. if (!string.IsNullOrWhiteSpace(queryJson))
  1123. {
  1124. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  1125. {
  1126. sql += " and a.ToWarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  1127. }
  1128. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  1129. {
  1130. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  1131. }
  1132. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1133. {
  1134. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1135. }
  1136. if (!string.IsNullOrWhiteSpace(queryParam["Container"].ToString()) && queryParam["Container"].ToString() == "2")
  1137. {
  1138. sql += $@" and (detail.LocationCode not in (SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  1139. WHERE
  1140. F_Define3='HGAreaConfig' AND F_Define1=a.FromWarehouseCode AND F_Define4=a.WorkPoint) OR detail.LocationCode is null OR detail.LocationCode='') ";
  1141. }
  1142. }
  1143. sql += " ) as t where t.row=1";
  1144. sql = string.Format(sql, Code, WorkPoint);
  1145. return Repository().FindTableBySql(sql.ToString());
  1146. }
  1147. //两步调拨
  1148. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  1149. {
  1150. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1151. DataTable dt = new DataTable();
  1152. var queryParam = queryJson.ToJObject();
  1153. List<DbParameter> parameter = new List<DbParameter>();
  1154. StringBuilder sqlString = new StringBuilder();
  1155. #region [SQL]
  1156. // sql = @"
  1157. //select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  1158. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  1159. // from ICSBrrow a
  1160. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1161. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1162. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  1163. // sql += " WHERE 1=1 and e.ID is null ";
  1164. sqlString.Append($@"select * from (select row_number() over(partition by a.OutCode order by a.OutCode)row, a.OutCode as Code, a.CreateDateTime as MTIME, a.CreatePerson as MUSER,
  1165. case when max(e.SourceID) is null then '' else '' end as IsNew,a.EATTRIBUTE1 AS ReceiveWork,tra.ToWarehouseCode,
  1166. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  1167. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10
  1168. FROM ICSOtherOut a
  1169. INNER JOIN ICSTransfer tra ON a.TransferDetailID = tra.TransferDetailID AND a.WorkPoint = tra.WorkPoint
  1170. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  1171. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  1172. where a.WorkPoint = '{WorkPoint}'
  1173. and a.Status = '2' ");
  1174. if (!string.IsNullOrWhiteSpace(queryJson))
  1175. {
  1176. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1177. {
  1178. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  1179. }
  1180. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1181. {
  1182. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  1183. }
  1184. }
  1185. sqlString.Append(@" group by a.OutCode, a.CreateDateTime, a.CreatePerson,a.EATTRIBUTE1 ,tra.ToWarehouseCode, f.Colspan ,f.ProjectCode ,
  1186. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,
  1187. f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10) t where t.row=1");
  1188. #endregion
  1189. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  1190. }
  1191. //两步调拨子表查询
  1192. public DataTable GetSubGridJson11(string Code)
  1193. {
  1194. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1195. DataTable dt = new DataTable();
  1196. //var queryParam = queryJson.ToJObject();
  1197. List<DbParameter> parameter = new List<DbParameter>();
  1198. string sql = @" select a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  1199. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  1200. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1201. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  1202. FROM ICSOtherOut a
  1203. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1204. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  1205. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1206. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  1207. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1208. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  1209. sql = string.Format(sql, Code, WorkPoint);
  1210. return Repository().FindTableBySql(sql.ToString());
  1211. }
  1212. // public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  1213. // {
  1214. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1215. // ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1216. // #region sql
  1217. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1218. // c.Code,
  1219. // c.InvCode,
  1220. // c.InvName,
  1221. // c.InvStd,
  1222. // c.InvUnit,
  1223. // FLOOR(c.iQuantity) AS iQuantity,
  1224. // d.WarehouseCode,
  1225. // m.LotNO,
  1226. // (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
  1227. // (case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
  1228. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1229. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1230. // FROM
  1231. // ({0}) c
  1232. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1233. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1234. // LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  1235. //DECLARE @ItemCode VARCHAR(50),
  1236. // @QTY DECIMAL(18,3),
  1237. // @ItemCodeCurrent VARCHAR(50),
  1238. // @Lotno VARCHAR(50),
  1239. // @QTYCurrent DECIMAL(18,3),
  1240. // @iQuantityCurrent DECIMAL(18,3),
  1241. // @CanDelete BIT,
  1242. // @Row INT,
  1243. // @rowCurrent INT
  1244. //SET @Row = @@rowcount
  1245. //SET @rowCurrent=1
  1246. //SET @CanDelete=0
  1247. //SET @ItemCode=''
  1248. //SET @Lotno = ''
  1249. //WHILE @rowCurrent<=@Row
  1250. // BEGIN
  1251. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
  1252. //PRINT(@rowCurrent)
  1253. // IF @ItemCode<>@ItemCodeCurrent
  1254. // BEGIN
  1255. // SET @ItemCode=@ItemCodeCurrent
  1256. // SET @QTY=0
  1257. // SET @CanDelete=0
  1258. // END
  1259. // IF @CanDelete=1
  1260. // BEGIN
  1261. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  1262. // SET @rowCurrent += 1
  1263. // CONTINUE
  1264. // END
  1265. // SET @QTY += @QTYCurrent
  1266. // IF @LotNo is null or @QTY>=@iQuantityCurrent
  1267. // BEGIN
  1268. // SET @CanDelete=1
  1269. // END
  1270. // SET @rowCurrent += 1
  1271. // END
  1272. //SELECT * FROM #temp
  1273. //DROP TABLE #temp
  1274. //";
  1275. // #endregion
  1276. // string sqls = "";
  1277. // if (Type=="1")
  1278. // {
  1279. // #region 工单备料sql
  1280. // sqls = @" SELECT
  1281. // c.MOCode as Code,
  1282. // a.InvCode,
  1283. // b.InvName,
  1284. // b.InvStd,
  1285. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1286. // a.WhCode,
  1287. // b.InvUnit,
  1288. // a.ExtensionID
  1289. // FROM
  1290. // ICSMOPick a
  1291. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1292. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1293. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1294. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1295. // #endregion
  1296. // }
  1297. // if (Type == "2")
  1298. // {
  1299. // return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
  1300. // }
  1301. // if (Type=="3")
  1302. // {
  1303. // #region 工单材料出库SQL
  1304. // sqls = @" select
  1305. // a.IssueCode as Code,
  1306. // a.InvCode,
  1307. // b.InvName,
  1308. // b.InvStd,
  1309. // b.InvUnit,
  1310. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1311. // a.WhCode,
  1312. // a.ExtensionID
  1313. // FROM
  1314. // ICSMOIssue a
  1315. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1316. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1317. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1318. // #endregion
  1319. // }
  1320. // if (Type=="4")
  1321. // {
  1322. // #region 委外备料SQL
  1323. // sqls = @" select
  1324. // c.OOCode as Code,
  1325. // a.InvCode,
  1326. // b.InvName,
  1327. // b.InvStd,
  1328. // b.InvUnit,
  1329. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1330. // a.WhCode,
  1331. // a.ExtensionID
  1332. // FROM
  1333. // ICSOOPick a
  1334. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1335. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1336. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1337. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  1338. // #endregion
  1339. // }
  1340. // if (Type=="5")
  1341. // {
  1342. // #region 委外领料SQL
  1343. // sqls = @" select
  1344. // a.ApplyCode as Code,
  1345. // a.InvCode,
  1346. // b.InvName,
  1347. // b.InvStd,
  1348. //b.InvUnit,
  1349. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1350. // a.WhCode,
  1351. // a.ExtensionID
  1352. // FROM
  1353. // ICSOApply a
  1354. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1355. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1356. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1357. // #endregion
  1358. // }
  1359. // if (Type=="6")
  1360. // {
  1361. // #region 委外材料出库SQL
  1362. // sqls = @" select
  1363. // a.IssueCode as Code,
  1364. // a.InvCode,
  1365. // b.InvName,
  1366. // b.InvStd,
  1367. //b.InvUnit,
  1368. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1369. // a.WhCode,
  1370. //a.ExtensionID
  1371. // FROM
  1372. // ICSOIssue a
  1373. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1374. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1375. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1376. // #endregion
  1377. // }
  1378. // if (Type=="7")
  1379. // {
  1380. // #region 销售发货SQL
  1381. // sqls = @" select
  1382. // a.SDNCode as Code,
  1383. // a.InvCode,
  1384. // b.InvName,
  1385. // b.InvStd,
  1386. //b.InvUnit,
  1387. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1388. // a.WhCode,
  1389. //a.ExtensionID
  1390. // FROM
  1391. // ICSSDN a
  1392. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1393. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1394. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1395. // #endregion
  1396. // }
  1397. // if (Type=="8")
  1398. // {
  1399. // #region 其它出库SQL
  1400. // sqls = @" select
  1401. // a.OutCode as Code,
  1402. // a.InvCode,
  1403. // b.InvName,
  1404. // b.InvStd,
  1405. // b.InvUnit,
  1406. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1407. // a.WhCode,
  1408. // a.ExtensionID
  1409. // FROM
  1410. // ICSOtherOut a
  1411. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1412. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1413. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1414. // #endregion
  1415. // }
  1416. // if (Type == "9")
  1417. // {
  1418. // #region 借用SQL
  1419. // sqls = @"select
  1420. // a.BrrowCode as Code,
  1421. // a.InvCode,
  1422. // b.InvName,
  1423. // b.InvStd,
  1424. //b.InvUnit,
  1425. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1426. // a.WhCode,
  1427. //a.ExtensionID
  1428. // FROM
  1429. // ICSBrrow a
  1430. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1431. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1432. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1433. // #endregion
  1434. // }
  1435. // if (Type == "10")
  1436. // {
  1437. // #region 物料调拨
  1438. // sqls = @" select
  1439. // a.TransferNO as Code,
  1440. // a.InvCode,
  1441. // b.InvName,
  1442. // b.InvStd,
  1443. //b.InvUnit,
  1444. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1445. // a.FromWarehouseCode as WhCode,
  1446. //a.ExtensionID
  1447. // FROM
  1448. // ICSTransfer a
  1449. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1450. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1451. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1452. // #endregion
  1453. // }
  1454. // if (Type == "11")
  1455. // {
  1456. // #region 两步调出
  1457. // sqls = @"select
  1458. // a.OutCode as Code,
  1459. // a.InvCode,
  1460. // b.InvName,
  1461. // b.InvStd,
  1462. //b.InvUnit,
  1463. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1464. // a.WHCode ,
  1465. //a.ExtensionID
  1466. // from ICSOtherOut a
  1467. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1468. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1469. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1470. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1471. // #endregion
  1472. // }
  1473. // sqls = string.Format(sqls, ID,WorkPoint);
  1474. // sql = string.Format(sql, sqls, WorkPoint);
  1475. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1476. // DataTable dtCloned = table.Clone();
  1477. // foreach (DataColumn col in dtCloned.Columns)
  1478. // {
  1479. // col.DataType = typeof(string);
  1480. // }
  1481. // foreach (DataRow row in table.Rows)
  1482. // {
  1483. // DataRow newrow = dtCloned.NewRow();
  1484. // foreach (DataColumn column in dtCloned.Columns)
  1485. // {
  1486. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1487. // }
  1488. // dtCloned.Rows.Add(newrow);
  1489. // }
  1490. // if (Invmes.Rows.Count > 0)
  1491. // {
  1492. // dtCloned.Merge(Invmes, false);
  1493. // }
  1494. // return dtCloned;
  1495. // }
  1496. public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  1497. {
  1498. string postUrlStr = System.Configuration.ConfigurationManager.AppSettings["HGDocpostUrlStr"].ToString();
  1499. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1500. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1501. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1502. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1503. #region sql
  1504. #endregion
  1505. string sqls = "";
  1506. if (Type == "1")
  1507. {
  1508. #region 工单备料sql
  1509. sqls = @" SELECT
  1510. c.MOCode as Code,
  1511. c.Sequence+'~'+a.Sequence as Sequence,
  1512. a.InvCode,
  1513. b.InvName,
  1514. b.InvStd,
  1515. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1516. a.WhCode,
  1517. b.InvUnit,
  1518. a.ExtensionID
  1519. FROM
  1520. ICSMOPick a
  1521. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1522. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1523. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1524. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.Sequence+'~'+a.Sequence";
  1525. #endregion
  1526. }
  1527. if (Type == "2" || Type == "12")
  1528. {
  1529. sqls = @"select
  1530. a.ApplyCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1531. FROM
  1532. ICSMOApply a
  1533. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1534. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1535. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1536. }
  1537. if (Type == "3")
  1538. {
  1539. #region 工单材料出库SQL
  1540. sqls = @" select
  1541. a.IssueCode as Code,
  1542. a.Sequence,
  1543. a.InvCode,
  1544. b.InvName,
  1545. b.InvStd,
  1546. b.InvUnit,
  1547. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1548. a.WhCode,
  1549. a.ExtensionID
  1550. FROM
  1551. ICSMOIssue a
  1552. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1553. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1554. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1555. #endregion
  1556. }
  1557. if (Type == "4")
  1558. {
  1559. #region 委外备料SQL
  1560. sqls = @" select
  1561. c.OOCode as Code,
  1562. c.Sequence+'~'+a.Sequence as Sequence,
  1563. a.InvCode,
  1564. b.InvName,
  1565. b.InvStd,
  1566. b.InvUnit,
  1567. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1568. a.WhCode,
  1569. a.ExtensionID
  1570. FROM
  1571. ICSOOPick a
  1572. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1573. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1574. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1575. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID,c.Sequence+'~'+a.Sequence";
  1576. #endregion
  1577. }
  1578. if (Type == "5")
  1579. {
  1580. #region 委外领料SQL
  1581. sqls = @"select
  1582. a.ApplyCode as Code,
  1583. a.Sequence,
  1584. a.InvCode,
  1585. b.InvName,
  1586. b.InvStd,
  1587. b.InvUnit,
  1588. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1589. a.WhCode,a.ExtensionID
  1590. FROM
  1591. ICSOApply a
  1592. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1593. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1594. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1595. #endregion
  1596. }
  1597. if (Type == "6")
  1598. {
  1599. #region 委外材料出库SQL
  1600. sqls = @" select
  1601. a.IssueCode as Code,
  1602. a.Sequence,
  1603. a.InvCode,
  1604. b.InvName,
  1605. b.InvStd,
  1606. b.InvUnit,
  1607. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1608. a.WhCode,
  1609. a.ExtensionID
  1610. FROM
  1611. ICSOIssue a
  1612. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1613. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1614. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1615. #endregion
  1616. }
  1617. if (Type == "7")
  1618. {
  1619. #region 销售发货SQL
  1620. sqls = @" select
  1621. a.SDNCode as Code,
  1622. a.Sequence,
  1623. a.InvCode,
  1624. b.InvName,
  1625. b.InvStd,
  1626. b.InvUnit,
  1627. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1628. a.WhCode,
  1629. a.ExtensionID
  1630. FROM
  1631. ICSSDN a
  1632. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1633. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1634. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1635. #endregion
  1636. }
  1637. if (Type == "8")
  1638. {
  1639. #region 其它出库SQL
  1640. sqls = @" select
  1641. a.OutCode as Code,
  1642. a.Sequence,
  1643. a.InvCode,
  1644. b.InvName,
  1645. b.InvStd,
  1646. b.InvUnit,
  1647. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1648. a.WhCode,
  1649. a.ExtensionID
  1650. FROM
  1651. ICSOtherOut a
  1652. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1653. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1654. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1655. #endregion
  1656. }
  1657. if (Type == "9")
  1658. {
  1659. #region 借用SQL
  1660. sqls = @"select
  1661. a.BrrowCode as Code,
  1662. a.Sequence,
  1663. a.InvCode,
  1664. b.InvName,
  1665. b.InvStd,
  1666. b.InvUnit,
  1667. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1668. a.WhCode,
  1669. a.ExtensionID
  1670. FROM
  1671. ICSBrrow a
  1672. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1673. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1674. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence";
  1675. #endregion
  1676. }
  1677. if (Type == "10")
  1678. {
  1679. #region 物料调拨
  1680. sqls = @"select
  1681. a.TransferNO as Code,
  1682. a.Sequence,
  1683. a.InvCode,
  1684. b.InvName,
  1685. b.InvStd,
  1686. b.InvUnit,
  1687. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1688. a.FromWarehouseCode as WhCode,
  1689. a.ExtensionID
  1690. FROM
  1691. ICSTransfer a
  1692. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1693. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1694. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence";
  1695. #endregion
  1696. }
  1697. if (Type == "11")
  1698. {
  1699. #region 两步调出
  1700. sqls = @"select
  1701. a.OutCode as Code,
  1702. a.Sequence,
  1703. a.InvCode,
  1704. b.InvName,
  1705. b.InvStd,
  1706. b.InvUnit,
  1707. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1708. a.WHCode ,
  1709. a.ExtensionID
  1710. from ICSOtherOut a
  1711. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1712. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1713. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1714. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,a.Sequence";
  1715. #endregion
  1716. }
  1717. sqls = string.Format(sqls, ID, WorkPoint);
  1718. string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1719. c.Code,
  1720. c.Sequence,
  1721. c.InvCode,
  1722. c.InvName,
  1723. c.InvStd,
  1724. c.InvUnit,
  1725. FLOOR(c.iQuantity) AS iQuantity,
  1726. c.WHCode AS WarehouseCode,
  1727. d.LotNO,
  1728. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1729. FLOOR(ISNULL(d.Quantity, 0)) AS QTYLeft,
  1730. 0 AS SendQTY,
  1731. d.LocationCode AS LocationCode,
  1732. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1733. FLOOR(f.QTYTotal) QTYTotal,c.ExtensionID
  1734. FROM
  1735. ({sqls}) c
  1736. left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  1737. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1738. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1739. and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0
  1740. --AND SUBSTRING( SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)),0,CHARINDEX('-', SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)))) Not IN(SELECT F_Define2 FROM Sys_SRM_ItemsDetail
  1741. --WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)
  1742. ) d
  1743. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1744. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  1745. order by c.Code,c.Sequence,d.MTIME ";
  1746. var dataset = Repository().FindDataSetBySql(sql);
  1747. if (dataset.Tables.Count == 0)
  1748. return null;
  1749. DataTable table = dataset.Tables[0];
  1750. decimal qtyCount = 0;
  1751. bool remove = false;
  1752. List<int> removeList = new List<int>();
  1753. for (int i = 0; i < table.Rows.Count; i++)
  1754. {
  1755. if (i != 0
  1756. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  1757. || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
  1758. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  1759. || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  1760. )
  1761. {
  1762. qtyCount = 0;
  1763. remove = false;
  1764. }
  1765. if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
  1766. {
  1767. removeList.Add(i);
  1768. continue;
  1769. }
  1770. if (remove)
  1771. {
  1772. removeList.Add(i);
  1773. }
  1774. else
  1775. {
  1776. var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  1777. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1778. qtyCount += lotQty;
  1779. foreach (DataRow dr in table.Rows)
  1780. {
  1781. if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  1782. {
  1783. if (qtyCount > orderQty)
  1784. {
  1785. dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  1786. }
  1787. else
  1788. {
  1789. dr["QTYLeft"] = 0;
  1790. }
  1791. }
  1792. }
  1793. if (qtyCount >= orderQty)
  1794. {
  1795. table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  1796. remove = true;
  1797. }
  1798. else
  1799. {
  1800. table.Rows[i]["SendQTY"] = lotQty;
  1801. }
  1802. }
  1803. }
  1804. if (removeList.Count > 0)
  1805. {
  1806. removeList.Reverse();
  1807. foreach (var item in removeList)
  1808. {
  1809. table.Rows.RemoveAt(item);
  1810. }
  1811. }
  1812. try
  1813. {
  1814. if (table.Rows.Count != 0)
  1815. {
  1816. #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
  1817. string BusinessCode = string.Empty;
  1818. string TransType = "";
  1819. if (Type == "2") { BusinessCode = "13"; TransType = "生产发料-领料申请单"; }
  1820. if (Type == "12") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; }
  1821. if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; }
  1822. if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; }
  1823. if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; }
  1824. if (Type == "10") { BusinessCode = "47"; TransType = "调拨申请单"; }
  1825. string Identification = Guid.NewGuid().ToString();
  1826. var pikTbLogTime = DateTime.Now;
  1827. string pikTbLogsql = string.Empty;
  1828. List<string> DocNoList = new List<string>();
  1829. #region 货柜
  1830. string InspectJosn = "";
  1831. string InspectJosnHead = "";
  1832. string InspectJosnBody = "";
  1833. InspectJosn += "{";
  1834. InspectJosn += "\"IMP_ORDINI\":[";
  1835. InspectJosn += "货柜主表区域预留";
  1836. InspectJosn += "],";
  1837. InspectJosn += "\"IMP_ORDINI_RIGHE\":[";
  1838. InspectJosn += "货柜子表区域预留";
  1839. InspectJosn += "]";
  1840. InspectJosn += "}";
  1841. foreach (DataRow PickLog in table.Rows)
  1842. {
  1843. string hgsql = @"select A.InvCode,A.LocationCode,B.F_Define3,C.LocationCode AS Area
  1844. from ICSWareHouseLotInfo A
  1845. INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define2=A.LocationCode AND F_Define4=A.WorkPoint AND F_ItemName='HG_Location'
  1846. INNER JOIN ICSInventoryDetail C ON C.INVCode=A.InvCode AND C.WHCode=A.WarehouseCode AND C.WorkPoint=A.WorkPoint
  1847. where A.LotNo='{0}' AND A.WorkPoint='{1}'";
  1848. hgsql = string.Format(hgsql, PickLog["LotNO"].ToString(), WorkPoint);
  1849. var hgds = Repository().FindDataSetBySql(hgsql);
  1850. if (hgds.Tables.Count == 0)
  1851. return null;
  1852. DataTable hgtable = hgds.Tables[0];
  1853. if (hgtable.Rows.Count > 0)
  1854. {
  1855. if (!DocNoList.Contains(PickLog["Code"].ToString()))
  1856. {
  1857. DocNoList.Add(PickLog["Code"].ToString());
  1858. }
  1859. InspectJosnBody += "{";
  1860. InspectJosnBody += "\"RIG_ORDINE\":\"" + PickLog["Code"].ToString() + "\",";
  1861. InspectJosnBody += "\"RIG_ARTICOLO\": \"" + hgtable.Rows[0]["InvCode"].ToString() + "\",";
  1862. InspectJosnBody += "\"RIG_SUB1\": \"\",";
  1863. InspectJosnBody += "\"RIG_SUB2\": \"\",";
  1864. InspectJosnBody += "\"RIG_ELERUOLI_GEST\": \"" + hgtable.Rows[0]["Area"].ToString() + "\",";
  1865. InspectJosnBody += "\"RIG_ELEBAIE\": \"" + hgtable.Rows[0]["F_Define3"].ToString() + "\",";
  1866. InspectJosnBody += "\"RIG_QTAR\": " + PickLog["SendQTY"].ToString() + ",";
  1867. InspectJosnBody += "\"RIG_HOSTINF\": \"" + PickLog["Sequence"].ToString() + "\"";
  1868. InspectJosnBody += "},";
  1869. }
  1870. }
  1871. InspectJosnBody.TrimEnd(',');
  1872. foreach (string DocNo in DocNoList)
  1873. {
  1874. InspectJosnHead += "{";
  1875. InspectJosnHead += "\"ORD_ORDINE\":\"" + DocNo.TrimStart('\'').TrimEnd('\'') + "\",";
  1876. InspectJosnHead += "\"ORD_DES\":\"" + TransType + "\",";
  1877. InspectJosnHead += "\"ORD_TIPOOP\":\"P\",";
  1878. InspectJosnHead += "\"ORD_CLIENTE\":\"" + WorkPoint + "\"";
  1879. InspectJosnHead += "},";
  1880. }
  1881. InspectJosnHead.TrimEnd(',');
  1882. if (InspectJosnBody != "")
  1883. {
  1884. InspectJosn = InspectJosn.Replace("货柜主表区域预留", InspectJosnHead);
  1885. InspectJosn = InspectJosn.Replace("货柜子表区域预留", InspectJosnBody);
  1886. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  1887. {
  1888. string callresult = "";
  1889. #region 货柜接口调用前日志
  1890. object logID = Guid.NewGuid();
  1891. string logsql = @"insert into ICSWMS_HGLog
  1892. values
  1893. ('{0}',GETDATE(),'{1}','{2}','{3}','{4}','{5}')";
  1894. logsql = string.Format(logsql, logID, InspectJosn, "", WorkPoint, MUSER, MUSERNAME);
  1895. SqlHelper.CmdExecuteNonQueryLi(logsql);
  1896. #endregion
  1897. callresult = HTTPHelper.RestFulGet(InspectJosn, postUrlStr);
  1898. #region 货柜接口调用后日志
  1899. logsql = @"update ICSWMS_HGLog set ReturnResult='{0}'
  1900. where ID='{1}'";
  1901. logsql = string.Format(logsql, callresult, logID);
  1902. SqlHelper.CmdExecuteNonQueryLi(logsql);
  1903. #endregion
  1904. //if (!callresult.Contains("successo"))
  1905. //{
  1906. // ICSHGResult hgresult = JsonConvert.DeserializeObject<ICSHGResult>(callresult.TrimStart('[').TrimEnd(']'));
  1907. // throw new Exception("货柜单据传输接口调用报错,主要报错信息:" + hgresult.PrimaryError + ",次要报错信息:" + hgresult.SecondaryError + "");
  1908. //}
  1909. }
  1910. }
  1911. #endregion
  1912. foreach (DataRow PickLog in table.Rows)
  1913. {
  1914. pikTbLogsql += @" IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15')
  1915. BEGIN
  1916. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1917. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1918. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1919. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1920. MTIME,WorkPoint,EATTRIBUTE1)
  1921. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  1922. a.WarehouseCode,a.LocationCode,'','','{3}',
  1923. '','1','15','{4}','0','',
  1924. '','','','{5}' ,'{6}' ,
  1925. '{7}' ,'{8}' ,''
  1926. FROM ICSWareHouseLotInfo a
  1927. WHERE a.LotNo='{9}' AND a.WorkPoint='{8}'
  1928. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}'
  1929. END ";
  1930. pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString()
  1931. , BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString());
  1932. }
  1933. SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql);
  1934. #endregion
  1935. }
  1936. var result = ConvertCellToString(table);
  1937. if (Invmes.Rows.Count > 0)
  1938. {
  1939. result.Merge(Invmes, false);
  1940. }
  1941. return result;
  1942. }
  1943. catch (Exception ex)
  1944. {
  1945. throw new Exception(ex.Message);
  1946. }
  1947. }
  1948. /// <summary>
  1949. /// 工单领料推荐
  1950. /// </summary>
  1951. /// <param name="Id"></param>
  1952. /// <param name="workPoint"></param>
  1953. /// <returns></returns>
  1954. public DataTable GetICSMOPickMergeByWorkorder(string Id, string workPoint)
  1955. {
  1956. string sql = $@"SELECT row_number() over (partition by c.Code,c.InvCode order by c.Code,c.InvCode,d.MTIME) AS rowNo,
  1957. c.Code,
  1958. c.InvCode,
  1959. c.InvName,
  1960. c.InvStd,
  1961. c.InvUnit,
  1962. FLOOR(c.iQuantity) AS iQuantity,
  1963. d.WarehouseCode,
  1964. d.LotNO,
  1965. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1966. d.LocationCode LocationCode,
  1967. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1968. FLOOR(f.QTYTotal) QTYTotal
  1969. FROM
  1970. (select
  1971. a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1972. FROM
  1973. ICSMOApply a
  1974. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1975. WHERE a.ApplyCode in ({Id}) AND a.WorkPoint = '{workPoint}'
  1976. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID) c
  1977. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1978. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1979. and d.WorkPoint='{workPoint}' AND d.Quantity>0 ) d on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1980. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='1701' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  1981. order by c.Code,c.InvCode,d.MTIME";
  1982. var dataset = Repository().FindDataSetBySql(sql);
  1983. if (dataset.Tables.Count == 0)
  1984. return null;
  1985. DataTable table = dataset.Tables[0];
  1986. decimal qtyCount = 0;
  1987. bool remove = false;
  1988. List<int> removeList = new List<int>();
  1989. for (int i = 0; i < table.Rows.Count; i++)
  1990. {
  1991. if (i != 0
  1992. && !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()))
  1993. {
  1994. qtyCount = 0;
  1995. remove = false;
  1996. }
  1997. if (remove)
  1998. {
  1999. removeList.Add(i);
  2000. }
  2001. else
  2002. {
  2003. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  2004. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  2005. qtyCount += lotQty;
  2006. if (qtyCount >= orderQty)
  2007. {
  2008. remove = true;
  2009. }
  2010. }
  2011. }
  2012. if (removeList.Count > 0)
  2013. {
  2014. removeList.Reverse();
  2015. foreach (var item in removeList)
  2016. {
  2017. table.Rows.RemoveAt(item);
  2018. }
  2019. }
  2020. var result = ConvertCellToString(table);
  2021. if (Invmes.Rows.Count > 0)
  2022. {
  2023. result.Merge(Invmes, false);
  2024. }
  2025. return result;
  2026. }
  2027. public DataTable ConvertCellToString(DataTable data)
  2028. {
  2029. DataTable dtCloned = data.Clone();
  2030. foreach (DataColumn col in dtCloned.Columns)
  2031. {
  2032. col.DataType = typeof(string);
  2033. }
  2034. foreach (DataRow row in data.Rows)
  2035. {
  2036. DataRow newrow = dtCloned.NewRow();
  2037. foreach (DataColumn column in dtCloned.Columns)
  2038. {
  2039. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  2040. }
  2041. dtCloned.Rows.Add(newrow);
  2042. }
  2043. return dtCloned;
  2044. }
  2045. // public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  2046. // {
  2047. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2048. // #region sql
  2049. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  2050. // c.MergeID,
  2051. // c.Code,
  2052. // c.InvCode,
  2053. // c.InvName,
  2054. // c.InvStd,
  2055. //c.InvUnit,
  2056. // FLOOR(c.iQuantity) AS iQuantity,
  2057. // d.WarehouseCode,
  2058. // d.LocationCode,
  2059. // d.LotNO,
  2060. // FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  2061. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  2062. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  2063. // FROM
  2064. // ({0}) c
  2065. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  2066. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  2067. // LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  2068. //DECLARE @ItemCode VARCHAR(50),
  2069. // @QTY DECIMAL(18,3),
  2070. // @ItemCodeCurrent VARCHAR(50),
  2071. // @QTYCurrent DECIMAL(18,3),
  2072. // @iQuantityCurrent DECIMAL(18,3),
  2073. // @CanDelete BIT,
  2074. // @Row INT,
  2075. // @rowCurrent INT
  2076. //SET @Row = @@rowcount
  2077. //SET @rowCurrent=1
  2078. //SET @CanDelete=0
  2079. //SET @ItemCode=''
  2080. //WHILE @rowCurrent<=@Row
  2081. // BEGIN
  2082. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  2083. //PRINT(@rowCurrent)
  2084. // IF @ItemCode<>@ItemCodeCurrent
  2085. // BEGIN
  2086. // SET @ItemCode=@ItemCodeCurrent
  2087. // SET @QTY=0
  2088. // SET @CanDelete=0
  2089. // END
  2090. // IF @CanDelete=1
  2091. // BEGIN
  2092. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  2093. // SET @rowCurrent += 1
  2094. // CONTINUE
  2095. // END
  2096. // SET @QTY += @QTYCurrent
  2097. // IF @QTY>=@iQuantityCurrent
  2098. // BEGIN
  2099. // SET @CanDelete=1
  2100. // END
  2101. // SET @rowCurrent += 1
  2102. // END
  2103. //SELECT * FROM #temp
  2104. //DROP TABLE #temp
  2105. //";
  2106. // #endregion
  2107. // string sqls = "";
  2108. // if (Type == "1")
  2109. // {
  2110. // #region 工单备料sql
  2111. // sqls = @" select
  2112. // x.MergeID,
  2113. // c.MOCode as Code,
  2114. // a.InvCode,
  2115. // b.InvName,
  2116. // b.InvStd,
  2117. //b.InvUnit,
  2118. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2119. // a.WhCode,
  2120. //a.ExtensionID
  2121. // FROM
  2122. // ICSMOPick a
  2123. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2124. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  2125. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2126. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  2127. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2128. // #endregion
  2129. // }
  2130. // if (Type == "2")
  2131. // {
  2132. // #region 工单领料SQL
  2133. // sqls = @" select
  2134. // x.MergeID,
  2135. // a.ApplyCode as Code,
  2136. // a.InvCode,
  2137. // b.InvName,
  2138. // b.InvStd,
  2139. //b.InvUnit,
  2140. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2141. // a.WhCode,
  2142. // a.ExtensionID
  2143. // FROM
  2144. // ICSMOApply a
  2145. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2146. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2147. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2148. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2149. // #endregion
  2150. // }
  2151. // if (Type == "3")
  2152. // {
  2153. // #region 工单材料出库SQL
  2154. // sqls = @" select
  2155. // x.MergeID,
  2156. // a.IssueCode as Code,
  2157. // a.InvCode,
  2158. // b.InvName,
  2159. // b.InvStd,
  2160. //b.InvUnit,
  2161. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2162. // a.WhCode,
  2163. //a.ExtensionID
  2164. // FROM
  2165. // ICSMOIssue a
  2166. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2167. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2168. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2169. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2170. // #endregion
  2171. // }
  2172. // if (Type == "4")
  2173. // {
  2174. // #region 委外备料SQL
  2175. // sqls = @" select
  2176. // x.MergeID,
  2177. // c.OOCode as Code,
  2178. // a.InvCode,
  2179. // b.InvName,
  2180. // b.InvStd,
  2181. //b.InvUnit,
  2182. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2183. // a.WhCode,
  2184. //a.ExtensionID
  2185. // FROM
  2186. // ICSOOPick a
  2187. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2188. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  2189. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2190. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  2191. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  2192. // #endregion
  2193. // }
  2194. // if (Type == "5")
  2195. // {
  2196. // #region 委外领料SQL
  2197. // sqls = @" select
  2198. // x.MergeID,
  2199. // a.ApplyCode as Code,
  2200. // a.InvCode,
  2201. // b.InvName,
  2202. // b.InvStd,
  2203. //b.InvUnit,
  2204. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2205. // a.WhCode,
  2206. //a.ExtensionID
  2207. // FROM
  2208. // ICSOApply a
  2209. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2210. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2211. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2212. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2213. // #endregion
  2214. // }
  2215. // if (Type == "6")
  2216. // {
  2217. // #region 委外材料出库SQL
  2218. // sqls = @" select
  2219. // x.MergeID,
  2220. // a.IssueCode as Code,
  2221. // a.InvCode,
  2222. // b.InvName,
  2223. // b.InvStd,
  2224. //b.InvUnit,
  2225. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2226. // a.WhCode,
  2227. //a.ExtensionID
  2228. // FROM
  2229. // ICSOIssue a
  2230. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2231. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2232. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2233. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2234. // #endregion
  2235. // }
  2236. // if (Type == "7")
  2237. // {
  2238. // #region 销售发货SQL
  2239. // sqls = @" select
  2240. // x.MergeID,
  2241. // a.SDNCode as Code,
  2242. // a.InvCode,
  2243. // b.InvName,
  2244. // b.InvStd,
  2245. //b.InvUnit,
  2246. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2247. // a.WhCode,
  2248. //a.ExtensionID
  2249. // FROM
  2250. // ICSSDN a
  2251. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2252. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2253. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  2254. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2255. // #endregion
  2256. // }
  2257. // if (Type == "8")
  2258. // {
  2259. // #region 其它出库SQL
  2260. // sqls = @" select
  2261. // x.MergeID,
  2262. // a.OutCode as Code,
  2263. // a.InvCode,
  2264. // b.InvName,
  2265. // b.InvStd,
  2266. //b.InvUnit,
  2267. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2268. // a.WhCode,
  2269. //a.ExtensionID
  2270. // FROM
  2271. // ICSOtherOut a
  2272. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2273. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2274. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2275. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2276. // #endregion
  2277. // }
  2278. // if (Type == "9")
  2279. // {
  2280. // #region 借用SQL
  2281. // sqls = @" select
  2282. // x.MergeID,
  2283. // a.BrrowCode as Code,
  2284. // a.InvCode,
  2285. // b.InvName,
  2286. // b.InvStd,
  2287. //b.InvUnit,
  2288. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2289. // a.WhCode,
  2290. //a.ExtensionID
  2291. // FROM
  2292. // ICSBrrow a
  2293. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2294. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2295. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  2296. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2297. // #endregion
  2298. // }
  2299. // if (Type == "10")
  2300. // {
  2301. // #region 物料调拨
  2302. // sqls = @" select
  2303. // x.MergeID,
  2304. // a.TransferNO as Code,
  2305. // a.InvCode,
  2306. // b.InvName,
  2307. // b.InvStd,
  2308. //b.InvUnit,
  2309. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2310. // a.FromWarehouseCode as WhCode,
  2311. //a.ExtensionID
  2312. // FROM
  2313. // ICSTransfer a
  2314. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2315. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2316. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  2317. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  2318. // #endregion
  2319. // }
  2320. // if (Type == "11")
  2321. // {
  2322. // #region 两步调出
  2323. // sqls = @"select
  2324. // x.MergeID,
  2325. // a.OutCode as Code,
  2326. // a.InvCode,
  2327. // b.InvName,
  2328. // b.InvStd,
  2329. // b.InvUnit,
  2330. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2331. // a.WHCode as WhCode,
  2332. // a.ExtensionID
  2333. // FROM
  2334. // ICSOtherOut a
  2335. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2336. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2337. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2338. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2339. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  2340. // #endregion
  2341. // }
  2342. // sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2343. // sql = string.Format(sql, sqls, WorkPoint);
  2344. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  2345. // DataTable dtCloned = table.Clone();
  2346. // foreach (DataColumn col in dtCloned.Columns)
  2347. // {
  2348. // col.DataType = typeof(string);
  2349. // }
  2350. // foreach (DataRow row in table.Rows)
  2351. // {
  2352. // DataRow newrow = dtCloned.NewRow();
  2353. // foreach (DataColumn column in dtCloned.Columns)
  2354. // {
  2355. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  2356. // }
  2357. // dtCloned.Rows.Add(newrow);
  2358. // }
  2359. // if (Invmes.Rows.Count > 0)
  2360. // {
  2361. // dtCloned.Merge(Invmes, false);
  2362. // }
  2363. // return dtCloned;
  2364. // }
  2365. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  2366. {
  2367. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2368. string sqls = "";
  2369. if (Type == "1")
  2370. {
  2371. #region 工单备料sql
  2372. sqls = @" select
  2373. x.MergeID,
  2374. c.MOCode as Code,
  2375. a.InvCode,
  2376. b.InvName,
  2377. b.InvStd,
  2378. b.InvUnit,
  2379. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2380. a.WhCode,
  2381. a.ExtensionID
  2382. FROM
  2383. ICSMOPick a
  2384. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2385. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  2386. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2387. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  2388. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2389. #endregion
  2390. }
  2391. if (Type == "2" || Type == "12")
  2392. {
  2393. #region 工单领料SQL
  2394. sqls = @" select
  2395. x.MergeID,
  2396. a.ApplyCode as Code,
  2397. a.InvCode,
  2398. b.InvName,
  2399. b.InvStd,
  2400. b.InvUnit,
  2401. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2402. a.WhCode,
  2403. a.ExtensionID
  2404. FROM
  2405. ICSMOApply a
  2406. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2407. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2408. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2409. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  2410. #endregion
  2411. }
  2412. if (Type == "3")
  2413. {
  2414. #region 工单材料出库SQL
  2415. sqls = @" select
  2416. x.MergeID,
  2417. a.IssueCode as Code,
  2418. a.InvCode,
  2419. b.InvName,
  2420. b.InvStd,
  2421. b.InvUnit,
  2422. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2423. a.WhCode,
  2424. a.ExtensionID
  2425. FROM
  2426. ICSMOIssue a
  2427. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2428. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2429. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2430. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2431. #endregion
  2432. }
  2433. if (Type == "4")
  2434. {
  2435. #region 委外备料SQL
  2436. sqls = @" select
  2437. x.MergeID,
  2438. c.OOCode as Code,
  2439. a.InvCode,
  2440. b.InvName,
  2441. b.InvStd,
  2442. b.InvUnit,
  2443. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2444. a.WhCode,
  2445. a.ExtensionID
  2446. FROM
  2447. ICSOOPick a
  2448. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2449. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  2450. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2451. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  2452. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  2453. #endregion
  2454. }
  2455. if (Type == "5")
  2456. {
  2457. #region 委外领料SQL
  2458. sqls = @" select
  2459. x.MergeID,
  2460. a.ApplyCode as Code,
  2461. a.InvCode,
  2462. b.InvName,
  2463. b.InvStd,
  2464. b.InvUnit,
  2465. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2466. a.WhCode,
  2467. a.ExtensionID
  2468. FROM
  2469. ICSOApply a
  2470. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2471. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2472. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  2473. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2474. #endregion
  2475. }
  2476. if (Type == "6")
  2477. {
  2478. #region 委外材料出库SQL
  2479. sqls = @" select
  2480. x.MergeID,
  2481. a.IssueCode as Code,
  2482. a.InvCode,
  2483. b.InvName,
  2484. b.InvStd,
  2485. b.InvUnit,
  2486. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2487. a.WhCode,
  2488. a.ExtensionID
  2489. FROM
  2490. ICSOIssue a
  2491. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2492. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2493. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  2494. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2495. #endregion
  2496. }
  2497. if (Type == "7")
  2498. {
  2499. #region 销售发货SQL
  2500. sqls = @" select
  2501. x.MergeID,
  2502. a.SDNCode as Code,
  2503. a.InvCode,
  2504. b.InvName,
  2505. b.InvStd,
  2506. b.InvUnit,
  2507. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2508. a.WhCode,
  2509. a.ExtensionID
  2510. FROM
  2511. ICSSDN a
  2512. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2513. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2514. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND a.Type='1'
  2515. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2516. #endregion
  2517. }
  2518. if (Type == "8")
  2519. {
  2520. #region 其它出库SQL
  2521. sqls = @" select
  2522. x.MergeID,
  2523. a.OutCode as Code,
  2524. a.InvCode,
  2525. b.InvName,
  2526. b.InvStd,
  2527. b.InvUnit,
  2528. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2529. a.WhCode,
  2530. a.ExtensionID
  2531. FROM
  2532. ICSOtherOut a
  2533. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2534. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2535. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2536. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2537. #endregion
  2538. }
  2539. if (Type == "9")
  2540. {
  2541. #region 借用SQL
  2542. sqls = @" select
  2543. x.MergeID,
  2544. a.BrrowCode as Code,
  2545. a.InvCode,
  2546. b.InvName,
  2547. b.InvStd,
  2548. b.InvUnit,
  2549. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2550. a.WhCode,
  2551. a.ExtensionID
  2552. FROM
  2553. ICSBrrow a
  2554. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2555. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2556. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  2557. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2558. #endregion
  2559. }
  2560. if (Type == "10")
  2561. {
  2562. #region 物料调拨
  2563. sqls = @" select
  2564. x.MergeID,
  2565. a.TransferNO as Code,
  2566. a.InvCode,
  2567. b.InvName,
  2568. b.InvStd,
  2569. b.InvUnit,
  2570. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2571. a.FromWarehouseCode as WhCode,
  2572. a.ExtensionID
  2573. FROM
  2574. ICSTransfer a
  2575. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2576. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2577. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  2578. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  2579. #endregion
  2580. }
  2581. if (Type == "11")
  2582. {
  2583. #region 两步调出
  2584. sqls = @" select
  2585. x.MergeID,
  2586. a.OutCode as Code,
  2587. a.InvCode,
  2588. b.InvName,
  2589. b.InvStd,
  2590. b.InvUnit,
  2591. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2592. a.WHCode as WhCode,
  2593. a.ExtensionID
  2594. FROM
  2595. ICSOtherOut a
  2596. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2597. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2598. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2599. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2600. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  2601. #endregion
  2602. }
  2603. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2604. #region sql
  2605. string sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  2606. c.MergeID,
  2607. c.Code,
  2608. c.InvCode,
  2609. c.InvName,
  2610. c.InvStd,
  2611. c.InvUnit,
  2612. FLOOR(c.iQuantity) AS iQuantity,
  2613. d.WarehouseCode,
  2614. d.LocationCode,
  2615. d.LotNO,
  2616. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  2617. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  2618. FLOOR(f.QTYTotal) QTYTotal
  2619. FROM
  2620. ({sqls}) c
  2621. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  2622. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  2623. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2624. and d.WorkPoint='{WorkPoint}' AND d.Quantity>0 ) d
  2625. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  2626. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  2627. order by c.Code,c.InvCode,d.MTIME ";
  2628. #endregion
  2629. var dataset = Repository().FindDataSetBySql(sql);
  2630. if (dataset.Tables.Count == 0)
  2631. return null;
  2632. DataTable table = dataset.Tables[0];
  2633. decimal qtyCount = 0;
  2634. bool remove = false;
  2635. List<int> removeList = new List<int>();
  2636. for (int i = 0; i < table.Rows.Count; i++)
  2637. {
  2638. if (i != 0
  2639. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  2640. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
  2641. )
  2642. {
  2643. qtyCount = 0;
  2644. remove = false;
  2645. }
  2646. if (remove)
  2647. {
  2648. removeList.Add(i);
  2649. }
  2650. else
  2651. {
  2652. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  2653. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  2654. qtyCount += lotQty;
  2655. if (qtyCount >= orderQty)
  2656. {
  2657. remove = true;
  2658. }
  2659. }
  2660. }
  2661. if (removeList.Count > 0)
  2662. {
  2663. removeList.Reverse();
  2664. foreach (var item in removeList)
  2665. {
  2666. table.Rows.RemoveAt(item);
  2667. }
  2668. }
  2669. var result = ConvertCellToString(table);
  2670. if (Invmes.Rows.Count > 0)
  2671. {
  2672. result.Merge(Invmes, false);
  2673. }
  2674. return result;
  2675. }
  2676. public string MergeMaterial(string keyValue, string Type)
  2677. {
  2678. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2679. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2680. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2681. string msg = "";
  2682. string sql = string.Empty;
  2683. string dataList = string.Empty;
  2684. List<string> arry = keyValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2685. if (arry.Count > 0)
  2686. {
  2687. StringBuilder stringBuilder = new StringBuilder();
  2688. foreach (var i in arry)
  2689. {
  2690. stringBuilder.Append($@"'{i}',");
  2691. }
  2692. dataList = stringBuilder.ToString(0, stringBuilder.Length - 1);
  2693. }
  2694. Int64 Merge_ID = 0;
  2695. DateTime time = DateTime.Now;
  2696. string Tday = time.ToString("yyyyMMdd");
  2697. string sqls = string.Format(@"SELECT MAX(A.MergeID) AS SourceID FROM ICSMOPickMerge A WHERE A.MergeID LIKE '{0}%' AND LEN(a.MergeID) = 13", Tday);
  2698. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2699. DataTable dts = ds.Tables[0];
  2700. if (dts != null && dts.Rows.Count > 0)
  2701. {
  2702. string lot = dts.Rows[0]["SourceID"].ToString();
  2703. if (!string.IsNullOrWhiteSpace(lot))
  2704. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  2705. }
  2706. string MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  2707. string order = string.Empty;
  2708. string orderCode = string.Empty;
  2709. string quantity = string.Empty;
  2710. string sqlString1 = string.Empty;
  2711. string sqlString2 = string.Empty;
  2712. if (Type == "1")//工单备料
  2713. {
  2714. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2715. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2716. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2717. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  2718. where a.MOCode in ({5})
  2719. ";
  2720. }
  2721. if (Type == "2")//工单发料
  2722. {
  2723. order = "ICSMOApply";
  2724. orderCode = "b.ApplyCode";
  2725. quantity = "b.IssueQuantity";
  2726. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2727. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2728. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
  2729. from ICSMOApply a
  2730. where a.ApplyCode in ({5})";
  2731. }
  2732. if (Type == "3")//材料出库
  2733. {
  2734. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2735. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2736. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2737. from ICSMOIssue a
  2738. where a.IssueCode in ({5}) ";
  2739. }
  2740. if (Type == "4")//委外备料
  2741. {
  2742. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2743. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2744. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2745. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  2746. where a.OOCode in ({5})";
  2747. }
  2748. if (Type == "5")//委外领料
  2749. {
  2750. order = "ICSOApply";
  2751. orderCode = "b.ApplyCode";
  2752. quantity = "b.IssueQuantity";
  2753. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2754. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2755. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
  2756. from ICSOApply a
  2757. where a.ApplyCode in ({5})";
  2758. }
  2759. if (Type == "6")//委外材料出库
  2760. {
  2761. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2762. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2763. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2764. from ICSOIssue a
  2765. where a.IssueCode in ({5})";
  2766. }
  2767. if (Type == "7")//销售发货
  2768. {
  2769. order = "ICSSDN";
  2770. orderCode = "b.SDNCode";
  2771. quantity = "b.SDNQuantity";
  2772. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2773. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2774. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.SDNCode
  2775. from ICSSDN a
  2776. where a.SDNCode in ({5}) AND a.Type='1' ";
  2777. }
  2778. if (Type == "8")//其它出库
  2779. {
  2780. order = "ICSOtherOut";
  2781. orderCode = "b.OutCode";
  2782. quantity = "b.OutQuantity";
  2783. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2784. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2785. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.OutCode
  2786. from ICSOtherOut a
  2787. where a.OutCode in ({5})";
  2788. }
  2789. if (Type == "9")//借用单
  2790. {
  2791. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2792. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2793. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2794. from ICSBrrow a
  2795. where a.BrrowCode in ({5})";
  2796. }
  2797. if (Type == "10")//物料调拨
  2798. {
  2799. order = "ICSTransfer";
  2800. orderCode = "b.TransferNO";
  2801. quantity = "b.TransferQuantity";
  2802. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2803. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2804. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.TransferNO
  2805. from ICSTransfer a
  2806. where a.TransferNO in ({5})
  2807. ";
  2808. }
  2809. if (Type == "11")//两步调出
  2810. {
  2811. sql += @" INSERT INTO dbo.ICSMOPickMerge
  2812. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2813. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2814. from ICSOtherOut a
  2815. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2816. where a.OutCode in ({5})
  2817. ";
  2818. }
  2819. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, dataList);
  2820. sqlString1 += $@" SELECT a.ID FROM ICSMOPickMerge a WHERE a.SourceID IN (SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) )";
  2821. sqlString2 += $@" SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) AND {quantity}>0";
  2822. DataSet ds1 = SqlHelper.GetDataSetBySql(sqlString1);
  2823. DataSet ds2 = SqlHelper.GetDataSetBySql(sqlString2);
  2824. DataTable dts1 = ds1.Tables[0];
  2825. DataTable dts2 = ds2.Tables[0];
  2826. if ((dts1 != null && dts1.Rows.Count > 0))
  2827. {
  2828. }
  2829. else if (dts2 != null && dts2.Rows.Count > 0)
  2830. {
  2831. msg = "当前选择单据号存在已出库的单据号,合并 失败";
  2832. }
  2833. else
  2834. {
  2835. try
  2836. {
  2837. if (SqlHelper.CmdExecuteNonQueryLi(sql) == 0)
  2838. {
  2839. msg = "新增失败";
  2840. }
  2841. }
  2842. catch (Exception ex)
  2843. {
  2844. throw new Exception(ex.Message);
  2845. }
  2846. }
  2847. return msg;
  2848. }
  2849. public string CancelMergeMaterial(string keyValue, string Type)
  2850. {
  2851. string msg = "";
  2852. string sql = string.Empty;
  2853. keyValue = keyValue.TrimEnd(',');
  2854. List<string> arry = keyValue.Split(',').ToList();
  2855. string dataList = string.Empty;
  2856. if (arry.Count > 0)
  2857. {
  2858. foreach (var i in arry)
  2859. {
  2860. dataList += $@"'{i}',";
  2861. }
  2862. if (dataList.Any())
  2863. {
  2864. dataList = dataList.TrimEnd(',');
  2865. }
  2866. }
  2867. string sqls = $@" SELECT SourceID FROM ICSMOPickMerge WHERE EATTRIBUTE1 IN({dataList}) ";
  2868. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2869. DataTable dts = ds.Tables[0];
  2870. if (dts == null || dts.Rows.Count <= 0)
  2871. {
  2872. msg = "当前单据未合并拣料,取消合并拣料失败";
  2873. return msg;
  2874. }
  2875. string sqlStrring = string.Empty;
  2876. if (Type == "2")//工单发料
  2877. {
  2878. sqlStrring = $@"select ID from ICSMOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
  2879. }
  2880. if (Type == "5")//委外领料
  2881. {
  2882. sqlStrring = $@"select ID from ICSOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
  2883. }
  2884. if (Type == "7")//销售发货
  2885. {
  2886. sqlStrring = $@"select ID from ICSSDN a where a.ID in ({sqls}) and a.SDNQuantity=0 AND a.Type='1' ";
  2887. }
  2888. if (Type == "8")//其它出库
  2889. {
  2890. sqlStrring = $@"select ID
  2891. from ICSOtherOut a
  2892. where a.ID in ({sqls}) and a.OutQuantity=0";
  2893. }
  2894. if (Type == "10")//物料调拨
  2895. {
  2896. sqlStrring = $@"select ID from ICSTransfer a where a.ID in ({sqls}) and a.TransferQuantity=0 ";
  2897. }
  2898. DataSet dsdata = SqlHelper.GetDataSetBySql(sqlStrring);
  2899. DataTable dtdsdatas = dsdata.Tables[0];
  2900. if (dtdsdatas == null || dtdsdatas.Rows.Count <= 0)
  2901. {
  2902. msg = "当前物料已经出库,取消合并失败";
  2903. return msg;
  2904. }
  2905. sql = $@"DELETE FROM ICSMOPickMerge WHERE SourceID IN({sqls})";
  2906. try
  2907. {
  2908. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2909. {
  2910. }
  2911. else
  2912. {
  2913. msg = "取消合并失败";
  2914. }
  2915. }
  2916. catch (Exception ex)
  2917. {
  2918. throw new Exception(ex.Message);
  2919. }
  2920. return msg;
  2921. }
  2922. public string CheckQty(string objArr)
  2923. {
  2924. objArr = objArr.TrimEnd(',');
  2925. string sql = @"select * from ICSMOPickMerge a
  2926. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  2927. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  2928. where MOCode in ({0})";
  2929. sql = string.Format(sql, objArr);
  2930. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2931. if (dt != null && dt.Rows.Count > 0)
  2932. {
  2933. return "1";
  2934. }
  2935. return "0";
  2936. }
  2937. //删除占料
  2938. public string DelPickLog(string objCode)
  2939. {
  2940. //站点信息
  2941. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2942. string msg = "";
  2943. objCode = objCode.Substring(1, objCode.Length - 2);
  2944. string sql = string.Empty;
  2945. // sql += string.Format(@"update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),a.Quantity )
  2946. //from dbo.ICSWareHouseLotInfoLog a
  2947. //left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  2948. // where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
  2949. sql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  2950. from dbo.ICSWareHouseLotInfo b
  2951. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode in ({0})and TransType='15' and WorkPoint='{1}' group by LotNo) c
  2952. on c.LotNo =b.LotNo ", objCode.TrimEnd(','), WorkPoint);
  2953. sql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode in({0}) and TransType='15' and WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
  2954. try
  2955. {
  2956. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2957. {
  2958. }
  2959. }
  2960. catch (Exception ex)
  2961. {
  2962. throw new Exception(ex.Message);
  2963. }
  2964. return msg;
  2965. }
  2966. public int SeachPickLog(string objCode)
  2967. {
  2968. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2969. objCode = objCode.TrimEnd(',');
  2970. string[] parameters = objCode.Split(',');
  2971. int parameterCount = parameters.Length;
  2972. string sql = @" select distinct a.TransCode from dbo.ICSWareHouseLotInfoLog a
  2973. left join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  2974. where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'";
  2975. sql = string.Format(sql, objCode, WorkPoint);
  2976. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2977. int count = dt.Rows.Count;
  2978. return count;
  2979. }
  2980. public DataTable GetPickLogInfo(string ID)
  2981. {
  2982. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2983. DataTable dt = new DataTable();
  2984. List<DbParameter> parameter = new List<DbParameter>();
  2985. string sql = @"
  2986. select '' as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  2987. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  2988. from dbo.ICSWareHouseLotInfoLog a
  2989. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2990. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  2991. where a.TransCode in ({0}) and a.TransType='15' and a.WorkPoint='{1}'";
  2992. sql = string.Format(sql, ID.TrimEnd(','), WorkPoint);
  2993. return Repository().FindTableBySql(sql.ToString());
  2994. }
  2995. }
  2996. }