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

2602 lines
132 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
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
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
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
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
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
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
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
3 years ago
3 years ago
3 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. namespace NFine.Application.WMS
  18. {
  19. public class PickMaterialApp : RepositoryFactory<ICSVendor>
  20. {
  21. public static DataTable Invmes = new DataTable();
  22. //工单备料(工单子件)
  23. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  24. {
  25. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  26. DataTable dt = new DataTable();
  27. var queryParam = queryJson.ToJObject();
  28. List<DbParameter> parameter = new List<DbParameter>();
  29. StringBuilder sqlstring = new StringBuilder();
  30. #region [SQL]
  31. // 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,
  32. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  33. //from ICSMOPick a
  34. //left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  35. //left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  36. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  37. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  38. // sql += " WHERE 1=1 and e.ID is null";
  39. sqlstring.Append($@"select a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  40. case when max(d.SourceID) is null then '' else '' end as IsNew,
  41. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,
  42. f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  43. from ICSMO a
  44. inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  45. left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
  46. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  47. where a.WorkPoint='{WorkPoint}' ");
  48. if (!string.IsNullOrWhiteSpace(queryJson))
  49. {
  50. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  51. {
  52. sqlstring.Append($" and a.MOCode like '%{queryParam["POCode"]}%' ");
  53. }
  54. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  55. {
  56. sqlstring.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  57. }
  58. }
  59. sqlstring.Append(@" group by a.MOCode, a.WorkPoint,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,
  60. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  61. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10");
  62. #endregion
  63. return Repository().FindTablePageBySql(sqlstring.ToString(), parameter.ToArray(), ref jqgridparam);
  64. }
  65. //工单备料(工单子件)子表查询
  66. public DataTable GetSubGridJson1(string Code)
  67. {
  68. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  69. DataTable dt = new DataTable();
  70. //var queryParam = queryJson.ToJObject();
  71. List<DbParameter> parameter = new List<DbParameter>();
  72. 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,
  73. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  74. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  75. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  76. from ICSMOPick a
  77. left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  78. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  79. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  80. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  81. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  82. where b.MOCode='{0}' and a.WorkPoint='{1}'";
  83. sql = string.Format(sql, Code, WorkPoint);
  84. return Repository().FindTableBySql(sql.ToString());
  85. }
  86. //工单领料(发料申请)
  87. public DataTable GetGridJson2(string queryJson, ref Pagination jqgridparam)
  88. {
  89. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  90. DataTable dt = new DataTable();
  91. var queryParam = queryJson.ToJObject();
  92. List<DbParameter> parameter = new List<DbParameter>();
  93. StringBuilder sqlString = new StringBuilder();
  94. #region [SQL]
  95. // 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,
  96. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  97. // from ICSMOApply a
  98. // left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
  99. // left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  100. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  101. sqlString.Append($@"
  102. SELECT * from (select row_number() over(partition by a.ApplyCode ORDER BY a.ApplyCode) as row,
  103. a.ApplyCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,a.WHCode,detail.LocationCode AS Area,
  104. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  105. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  106. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,
  107. case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName != 'JOB' then ''
  108. else (case when sum(a.Quantity) =sum(IssueQuantity) and a.MUSERName = 'JOB' then '' else '' end) end as Status,
  109. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,
  110. f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.ID
  111. from ICSMOApply a
  112. left JOIN ICSInventory b ON b.InvCode=a.InvCode
  113. LEFT JOIN ICSInventoryDetail detail ON b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  114. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  115. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  116. where a.WorkPoint='{WorkPoint}' ");
  117. if (!string.IsNullOrWhiteSpace(queryJson))
  118. {
  119. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  120. {
  121. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  122. }
  123. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  124. {
  125. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  126. }
  127. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  128. {
  129. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  130. }
  131. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  132. {
  133. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  134. }
  135. }
  136. sqlString.Append(@" group by a.ApplyCode, a.WorkPoint,a.IssueQuantity,a.CreateDateTime,a.createperson,
  137. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  138. 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,
  139. 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");
  140. #endregion
  141. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  142. }
  143. //工单领料(发料申请)子表查询
  144. public DataTable GetSubGridJson2(string queryJson, string Code)
  145. {
  146. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  147. DataTable dt = new DataTable();
  148. var queryParam = queryJson.ToJObject();
  149. List<DbParameter> parameter = new List<DbParameter>();
  150. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  151. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,
  152. a.EATTRIBUTE,a.Sets,a.OrderInvCode,a.OrderInvDescribe,a.BillType,a.Remarks,a.Desks,a.DispatchNumber,a.DispatcherName,
  153. a.ReceiverNumber,a.ReceiverName,a.Urgency,a.NeedDate,a.NeedTime,a.RemarksTerm,a.TextNumber,a.InvDescribe,a.Unit,a.StockIndicator,
  154. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,detail.LocationCode AS Area,
  155. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  156. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  157. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  158. from ICSMOApply a
  159. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  160. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  161. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  162. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  163. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  164. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  165. if (!string.IsNullOrWhiteSpace(queryJson))
  166. {
  167. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  168. {
  169. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  170. }
  171. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  172. {
  173. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  174. }
  175. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  176. {
  177. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  178. }
  179. }
  180. sql += " ) c WHERE c.row=1 ";
  181. sql = string.Format(sql, Code, WorkPoint);
  182. return Repository().FindTableBySql(sql.ToString());
  183. }
  184. //工单材料出库(材料出库)
  185. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  186. {
  187. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  188. DataTable dt = new DataTable();
  189. var queryParam = queryJson.ToJObject();
  190. List<DbParameter> parameter = new List<DbParameter>();
  191. StringBuilder sqlString = new StringBuilder();
  192. #region [SQL]
  193. // 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,
  194. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  195. // from ICSMOIssue a
  196. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  197. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  198. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  199. // sql += " WHERE 1=1 and e.ID is null";
  200. sqlString.Append($@"SELECT * FROM(SELECT row_number ( ) OVER ( partition BY a.IssueCode ORDER BY a.IssueCode ) AS row,
  201. a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  202. case when max(e.SourceID) is null then '' else ''
  203. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  204. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  205. from ICSMOIssue a
  206. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  207. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  208. where a.WorkPoint = '{WorkPoint}' ");
  209. if (!string.IsNullOrWhiteSpace(queryJson))
  210. {
  211. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  212. {
  213. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  214. }
  215. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  216. {
  217. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  218. }
  219. }
  220. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,f.BatchCode,
  221. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  222. f.cFree8, f.cFree9, f.cFree10 ) AS t WHERE t.row= 1 ");
  223. #endregion
  224. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  225. }
  226. //工单材料出库(材料出库)子表查询
  227. public DataTable GetSubGridJson3(string Code)
  228. {
  229. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  230. DataTable dt = new DataTable();
  231. //var queryParam = queryJson.ToJObject();
  232. List<DbParameter> parameter = new List<DbParameter>();
  233. 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,
  234. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  235. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  236. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  237. from ICSMOIssue a
  238. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  239. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  240. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  241. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  242. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  243. sql = string.Format(sql, Code, WorkPoint);
  244. return Repository().FindTableBySql(sql.ToString());
  245. }
  246. //委外备料(委外备料)
  247. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  248. {
  249. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  250. DataTable dt = new DataTable();
  251. var queryParam = queryJson.ToJObject();
  252. List<DbParameter> parameter = new List<DbParameter>();
  253. StringBuilder sqlString = new StringBuilder();
  254. #region [SQL]
  255. sqlString.Append($@"select * from (select row_number() over(partition by b.OOCode order by b.OOCode) row, b.OOCode as Code,
  256. b.CreateDateTime as MTIME,
  257. b.CreatePerson as MUSER,
  258. case
  259. when max(e.SourceID) is null then ''
  260. else ''
  261. end as IsNew,
  262. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  263. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  264. from ICSOOPick a
  265. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.WorkPoint = b.WorkPoint
  266. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  267. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  268. WHERE b.WorkPoint = '{WorkPoint}' ");
  269. if (!string.IsNullOrWhiteSpace(queryJson))
  270. {
  271. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  272. {
  273. sqlString.Append($@" and a.OOCode like '%{queryParam["POCode"]}%' ");
  274. }
  275. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  276. {
  277. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  278. }
  279. }
  280. sqlString.Append(@" group by b.OOCode,b.CreateDateTime,b.CreatePerson,f.Colspan ,f.ProjectCode ,
  281. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  282. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10) t where t.row=1");
  283. #endregion
  284. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  285. }
  286. //委外备料(委外备料)子表查询
  287. public DataTable GetSubGridJson4(string Code)
  288. {
  289. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  290. DataTable dt = new DataTable();
  291. //var queryParam = queryJson.ToJObject();
  292. List<DbParameter> parameter = new List<DbParameter>();
  293. 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,
  294. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  295. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  296. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  297. from ICSOOPick a
  298. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  299. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  300. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  301. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  302. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  303. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  304. sql = string.Format(sql, Code, WorkPoint);
  305. return Repository().FindTableBySql(sql.ToString());
  306. }
  307. //委外领料(委外发料申请)
  308. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  309. {
  310. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  311. DataTable dt = new DataTable();
  312. var queryParam = queryJson.ToJObject();
  313. List<DbParameter> parameter = new List<DbParameter>();
  314. StringBuilder sqlString = new StringBuilder();
  315. #region [SQL]
  316. // 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,
  317. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  318. // from ICSOApply a
  319. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  320. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  321. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  322. // sql += " WHERE 1=1 and e.ID is null";
  323. sqlString.Append($@"select * from (select row_number() over (partition by a.ApplyCode order by a.ApplyCode ) row, a.ApplyCode as Code,a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  324. case when max(e.SourceID) is null then ''
  325. else ''
  326. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  327. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID
  328. from ICSOApply a
  329. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  330. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  331. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  332. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  333. where a.WorkPoint = '{WorkPoint}'");
  334. if (!string.IsNullOrWhiteSpace(queryJson))
  335. {
  336. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  337. {
  338. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  339. }
  340. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  341. {
  342. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  343. }
  344. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  345. {
  346. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  347. }
  348. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  349. {
  350. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  351. }
  352. }
  353. sqlString.Append(@"group by a.ApplyCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  354. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  355. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID ) t where row=1");
  356. #endregion
  357. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  358. }
  359. //委外领料(委外发料申请)子表查询
  360. public DataTable GetSubGridJson5(string Code, string queryJson)
  361. {
  362. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  363. DataTable dt = new DataTable();
  364. var queryParam = queryJson.ToJObject();
  365. List<DbParameter> parameter = new List<DbParameter>();
  366. string sql = @"SELECT * FROM (select row_number() over(partition by a.ApplyCode,a.InvCode,a.Sequence ORDER BY a.ApplyCode) as row,
  367. a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode, a.SourceCode,a.SourceSequence,a.VenCode,a.VenName,
  368. b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  369. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity,detail.LocationCode AS Area,
  370. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  371. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  372. from ICSOApply a
  373. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  374. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  375. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  376. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  377. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  378. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  379. if (!string.IsNullOrWhiteSpace(queryJson))
  380. {
  381. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  382. {
  383. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  384. }
  385. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  386. {
  387. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  388. }
  389. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  390. {
  391. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  392. }
  393. }
  394. sql += " ) c WHERE c.row=1 ";
  395. sql = string.Format(sql, Code, WorkPoint);
  396. return Repository().FindTableBySql(sql.ToString());
  397. }
  398. //委外材料出库(委外发料申请)
  399. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  400. {
  401. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  402. DataTable dt = new DataTable();
  403. var queryParam = queryJson.ToJObject();
  404. List<DbParameter> parameter = new List<DbParameter>();
  405. StringBuilder sqlString = new StringBuilder();
  406. #region [SQL]
  407. // 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,
  408. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  409. // from ICSOIssue a
  410. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  411. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  412. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  413. // sql += " WHERE 1=1 and e.ID is null";
  414. sqlString.Append($@"select * from(select row_number() over(partition by a.IssueCode order by a.IssueCode) row, a.IssueCode as Code,
  415. a.CreateDateTime as MTIME,
  416. a.CreatePerson as MUSER,
  417. case
  418. when max(e.SourceID) is null then ''
  419. else ''
  420. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  421. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  422. f.cFree8,f.cFree9,f.cFree10
  423. from ICSOIssue a
  424. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  425. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  426. where a.WorkPoint = '{WorkPoint}'");
  427. if (!string.IsNullOrWhiteSpace(queryJson))
  428. {
  429. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  430. {
  431. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  432. }
  433. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  434. {
  435. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  436. }
  437. }
  438. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  439. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  440. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10) t where t.row=1");
  441. #endregion
  442. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  443. }
  444. //委外材料出库(委外发料申请)子表查询
  445. public DataTable GetSubGridJson6(string Code)
  446. {
  447. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  448. DataTable dt = new DataTable();
  449. //var queryParam = queryJson.ToJObject();
  450. List<DbParameter> parameter = new List<DbParameter>();
  451. 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,
  452. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  453. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  454. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  455. from ICSOIssue a
  456. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  457. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  458. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  459. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  460. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  461. sql = string.Format(sql, Code, WorkPoint);
  462. return Repository().FindTableBySql(sql.ToString());
  463. }
  464. //销售发货(销售发货)
  465. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  466. {
  467. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  468. DataTable dt = new DataTable();
  469. var queryParam = queryJson.ToJObject();
  470. List<DbParameter> parameter = new List<DbParameter>();
  471. StringBuilder sqlString = new StringBuilder();
  472. #region [SQL]
  473. // 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,
  474. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  475. // from ICSSDN a
  476. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  477. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  478. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  479. // sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  480. sqlString.Append($@"SELECT * from (SELECT Row_Number() over(partition by a.SDNCode Order by a.SDNCode) as r, a.SDNCode AS Code,
  481. a.CreateDateTime AS MTIME,
  482. a.CreatePerson AS MUSER,
  483. a.CusCode,a.CusName,
  484. (CASE WHEN max(e.SourceID) IS NULL THEN '' ELSE '' END) AS IsNew,
  485. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  486. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10,a.ID
  487. FROM ICSSDN a
  488. LEFT JOIN ICSMOPickMerge e ON a.ID = e.SourceID AND a.WorkPoint = e.WorkPoint
  489. LEFT JOIN ICSExtension f ON a.ExtensionID = f.ID AND a.WorkPoint = f.WorkPoint
  490. LEFT JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  491. WHERE a.WorkPoint = '{WorkPoint}' ");
  492. if (!string.IsNullOrWhiteSpace(queryJson))
  493. {
  494. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  495. {
  496. sqlString.Append($" and a.SDNCode like '%{queryParam["POCode"]}%' ");
  497. }
  498. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  499. {
  500. sqlString.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  501. }
  502. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  503. {
  504. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  505. }
  506. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  507. {
  508. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  509. }
  510. }
  511. sqlString.Append(@"GROUP BY a.SDNCode, a.CreateDateTime, a.CreatePerson, f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  512. 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");
  513. #endregion
  514. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  515. }
  516. //销售发货(销售发货)子表查询
  517. public DataTable GetSubGridJson7(string Code, string queryJson)
  518. {
  519. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  520. DataTable dt = new DataTable();
  521. var queryParam = queryJson.ToJObject();
  522. List<DbParameter> parameter = new List<DbParameter>();
  523. string sql = @"SELECT * FROM (select row_number() over(partition by a.SDNCode,a.InvCode,a.Sequence ORDER BY a.SDNCode) as row,
  524. a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode
  525. ,a.WorkPoint,a.Points,a.DeliveryType,a.DeliveryDescribe,a.InvDescribe,a.OtherDescribe,a.CusCode,a.CusName,
  526. a.SalesUnit,a.StockIndicator,a.IsSerialNumber,
  527. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  528. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity,detail.LocationCode AS Area
  529. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  530. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.SDNQuantity as IssueQuantity
  531. from ICSSDN a
  532. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  533. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  534. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  535. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  536. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  537. where a.SDNCode='{0}' and a.WorkPoint='{1}'";
  538. if (!string.IsNullOrWhiteSpace(queryJson))
  539. {
  540. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  541. {
  542. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  543. }
  544. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  545. {
  546. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  547. }
  548. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  549. {
  550. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  551. }
  552. }
  553. sql += " ) c WHERE c.row=1 ";
  554. sql = string.Format(sql, Code, WorkPoint);
  555. return Repository().FindTableBySql(sql.ToString());
  556. }
  557. //其它出库(其它出库)
  558. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  559. {
  560. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  561. DataTable dt = new DataTable();
  562. var queryParam = queryJson.ToJObject();
  563. List<DbParameter> parameter = new List<DbParameter>();
  564. StringBuilder sqlString = new StringBuilder();
  565. #region [SQL]
  566. // 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,
  567. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  568. //from ICSOtherOut a
  569. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  570. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  571. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  572. // sql += " WHERE 1=1 and e.ID is null ";
  573. sqlString.Append($@"select * from(select row_number() over(partition by a.OutCode order by a.OutCode) row, a.OutCode as Code,
  574. a.CreateDateTime as MTIME,
  575. a.CreatePerson as MUSER,
  576. case
  577. when max(e.SourceID) is null then ''
  578. else ''
  579. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  580. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID
  581. from ICSOtherOut a
  582. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  583. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  584. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  585. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  586. where a.WorkPoint = '{WorkPoint}'");
  587. #endregion
  588. if (!string.IsNullOrWhiteSpace(queryJson))
  589. {
  590. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  591. {
  592. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  593. }
  594. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  595. {
  596. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  597. }
  598. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  599. {
  600. sqlString.Append($@" and a.WHCode like '%{queryParam["WHCode"]}%' ");
  601. }
  602. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  603. {
  604. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  605. }
  606. }
  607. sqlString.Append(@" group by a.OutCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,f.BatchCode,
  608. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,
  609. f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID) t where t.row=1");
  610. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  611. }
  612. //其它出库(其它出库)子表查询
  613. public DataTable GetSubGridJson8(string Code, string queryJson)
  614. {
  615. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  616. DataTable dt = new DataTable();
  617. var queryParam = queryJson.ToJObject();
  618. List<DbParameter> parameter = new List<DbParameter>();
  619. string sql = @"SELECT * FROM (select row_number() over(partition by a.OutCode,a.InvCode,a.Sequence ORDER BY a.OutCode) as row,
  620. a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.Quantity,
  621. a.InvCode,a.WorkPoint,a.OrderType, a.TypeDescribe,a.CostCenter,a.Remarks,a.PersonNumber,a.InvDescribe,
  622. a.Unit,a.StockIndicator,
  623. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  624. case when e.SourceID is null then '' else '' end as IsNew,detail.LocationCode AS Area
  625. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  626. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  627. from ICSOtherOut a
  628. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  629. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  630. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  631. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  632. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  633. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  634. if (!string.IsNullOrWhiteSpace(queryJson))
  635. {
  636. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  637. {
  638. sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  639. }
  640. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  641. {
  642. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  643. }
  644. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  645. {
  646. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  647. }
  648. }
  649. sql += " ) c WHERE c.row=1 ";
  650. sql = string.Format(sql, Code, WorkPoint);
  651. return Repository().FindTableBySql(sql.ToString());
  652. }
  653. //借用(借用)
  654. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  655. {
  656. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  657. DataTable dt = new DataTable();
  658. var queryParam = queryJson.ToJObject();
  659. List<DbParameter> parameter = new List<DbParameter>();
  660. StringBuilder sqlString = new StringBuilder();
  661. #region [SQL]
  662. // sql = @"
  663. //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,
  664. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  665. // from ICSBrrow a
  666. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  667. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  668. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  669. // sql += " WHERE 1=1 and e.ID is null ";
  670. sqlString.Append($@"select * from(select row_number() over(partition by a.BrrowCode order by a.BrrowCode) row, a.BrrowCode as Code,
  671. a.CreateDateTime as MTIME,
  672. a.CreatePerson as MUSER,
  673. case
  674. when max(e.SourceID) is null then ''
  675. else ''
  676. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  677. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  678. f.cFree8,f.cFree9,f.cFree10
  679. from ICSBrrow a
  680. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  681. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  682. where a.WorkPoint = '{WorkPoint}'");
  683. if (!string.IsNullOrWhiteSpace(queryJson))
  684. {
  685. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  686. {
  687. sqlString.Append($@" and a.BrrowCode like '%{queryParam["POCode"]}%' ");
  688. }
  689. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  690. {
  691. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  692. }
  693. }
  694. sqlString.Append(@"group by a.BrrowCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  695. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  696. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,
  697. f.cFree10) t where t.row=1");
  698. #endregion
  699. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  700. }
  701. //借用(借用)子表查询
  702. public DataTable GetSubGridJson9(string Code)
  703. {
  704. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  705. DataTable dt = new DataTable();
  706. //var queryParam = queryJson.ToJObject();
  707. List<DbParameter> parameter = new List<DbParameter>();
  708. 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,
  709. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  710. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  711. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.BrrowQuantity as IssueQuantity
  712. from ICSBrrow a
  713. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  714. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  715. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  716. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  717. where a.BrrowCode='{0}' and a.WorkPoint='{1}'";
  718. sql = string.Format(sql, Code, WorkPoint);
  719. return Repository().FindTableBySql(sql.ToString());
  720. }
  721. //物料调拨
  722. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  723. {
  724. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  725. DataTable dt = new DataTable();
  726. var queryParam = queryJson.ToJObject();
  727. List<DbParameter> parameter = new List<DbParameter>();
  728. StringBuilder sqlString = new StringBuilder();
  729. #region [SQL]
  730. // sql = @"
  731. //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,
  732. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  733. // from ICSBrrow 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 e.ID is null ";
  738. sqlString.Append($@"select * from (select row_number() over(partition by a.TransferNO order by a.TransferNO) row,
  739. a.TransferNO as Code,a.ID,a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  740. case
  741. when max(e.SourceID) is null then ''
  742. else ''
  743. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  744. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  745. from ICSTransfer a
  746. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  747. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  748. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  749. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.ToWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  750. where a.WorkPoint = '{WorkPoint}' and a.Status = '2'");
  751. if (!string.IsNullOrWhiteSpace(queryJson))
  752. {
  753. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  754. {
  755. sqlString.Append($@" and a.TransferNO like '%{queryParam["POCode"]}%' ");
  756. }
  757. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  758. {
  759. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  760. }
  761. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  762. {
  763. sqlString.Append($@" and a.ToWarehouseCode like '%{queryParam["WHCode"]}%' ");
  764. }
  765. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  766. {
  767. sqlString.Append($@" and detail.LocationCode like '%{queryParam["Area"]}%' ");
  768. }
  769. }
  770. sqlString.Append(@"group by a.TransferNO,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  771. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  772. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10,a.ID) t where t.row=1");
  773. #endregion
  774. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  775. }
  776. //物料调拨子表查询
  777. public DataTable GetSubGridJson10(string Code, string queryJson)
  778. {
  779. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  780. DataTable dt = new DataTable();
  781. var queryParam = queryJson.ToJObject();
  782. List<DbParameter> parameter = new List<DbParameter>();
  783. string sql = @"SELECT * from (select row_number() over(partition by a.TransferNO,a.InvCode,
  784. 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,
  785. a.InvCode,a.ToWarehouseCode,a.EATTRIBUTE1 AS ReceiveWork,a.WorkPoint,a.OrderType,
  786. a.TypeDescribe,a.Remarks,a.PersonNumber,a.InvDescribe,
  787. a.Unit,a.StockIndicator,a.ReceiveInvCode,a.ReceiveInvDescribe,
  788. a.ReceiveStock,a.ReceiveSales,a.ReceiveSequence,a.Remark2,
  789. d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  790. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  791. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  792. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.TransferQuantity as IssueQuantity
  793. from ICSTransfer a
  794. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  795. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  796. LEFT JOIN ICSInventoryDetail detail ON d.InvCode=detail.INVCode AND a.ToWarehouseCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  797. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  798. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  799. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  800. if (!string.IsNullOrWhiteSpace(queryJson))
  801. {
  802. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  803. {
  804. sql += " and a.ToWarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  805. }
  806. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  807. {
  808. sql += " and detail.LocationCode like '%" + queryParam["Area"].ToString() + "%' ";
  809. }
  810. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  811. {
  812. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  813. }
  814. }
  815. sql += " ) as t where t.row=1";
  816. sql = string.Format(sql, Code, WorkPoint);
  817. return Repository().FindTableBySql(sql.ToString());
  818. }
  819. //两步调拨
  820. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  821. {
  822. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  823. DataTable dt = new DataTable();
  824. var queryParam = queryJson.ToJObject();
  825. List<DbParameter> parameter = new List<DbParameter>();
  826. StringBuilder sqlString = new StringBuilder();
  827. #region [SQL]
  828. // sql = @"
  829. //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,
  830. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  831. // from ICSBrrow a
  832. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  833. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  834. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  835. // sql += " WHERE 1=1 and e.ID is null ";
  836. 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,
  837. case when max(e.SourceID) is null then '' else '' end as IsNew,a.EATTRIBUTE1 AS ReceiveWork,tra.ToWarehouseCode,
  838. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  839. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10
  840. FROM ICSOtherOut a
  841. INNER JOIN ICSTransfer tra ON a.TransferDetailID = tra.TransferDetailID AND a.WorkPoint = tra.WorkPoint
  842. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  843. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  844. where a.WorkPoint = '{WorkPoint}'
  845. and a.Status = '2' ");
  846. if (!string.IsNullOrWhiteSpace(queryJson))
  847. {
  848. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  849. {
  850. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  851. }
  852. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  853. {
  854. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  855. }
  856. }
  857. sqlString.Append(@" group by a.OutCode, a.CreateDateTime, a.CreatePerson,a.EATTRIBUTE1 ,tra.ToWarehouseCode, f.Colspan ,f.ProjectCode ,
  858. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,
  859. f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10) t where t.row=1");
  860. #endregion
  861. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  862. }
  863. //两步调拨子表查询
  864. public DataTable GetSubGridJson11(string Code)
  865. {
  866. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  867. DataTable dt = new DataTable();
  868. //var queryParam = queryJson.ToJObject();
  869. List<DbParameter> parameter = new List<DbParameter>();
  870. 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,
  871. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  872. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  873. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  874. FROM ICSOtherOut a
  875. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  876. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  877. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  878. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  879. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  880. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  881. sql = string.Format(sql, Code, WorkPoint);
  882. return Repository().FindTableBySql(sql.ToString());
  883. }
  884. // public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  885. // {
  886. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  887. // ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  888. // #region sql
  889. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  890. // c.Code,
  891. // c.InvCode,
  892. // c.InvName,
  893. // c.InvStd,
  894. // c.InvUnit,
  895. // FLOOR(c.iQuantity) AS iQuantity,
  896. // d.WarehouseCode,
  897. // m.LotNO,
  898. // (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
  899. // (case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
  900. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  901. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  902. // FROM
  903. // ({0}) c
  904. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  905. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  906. // 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
  907. //DECLARE @ItemCode VARCHAR(50),
  908. // @QTY DECIMAL(18,3),
  909. // @ItemCodeCurrent VARCHAR(50),
  910. // @Lotno VARCHAR(50),
  911. // @QTYCurrent DECIMAL(18,3),
  912. // @iQuantityCurrent DECIMAL(18,3),
  913. // @CanDelete BIT,
  914. // @Row INT,
  915. // @rowCurrent INT
  916. //SET @Row = @@rowcount
  917. //SET @rowCurrent=1
  918. //SET @CanDelete=0
  919. //SET @ItemCode=''
  920. //SET @Lotno = ''
  921. //WHILE @rowCurrent<=@Row
  922. // BEGIN
  923. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
  924. //PRINT(@rowCurrent)
  925. // IF @ItemCode<>@ItemCodeCurrent
  926. // BEGIN
  927. // SET @ItemCode=@ItemCodeCurrent
  928. // SET @QTY=0
  929. // SET @CanDelete=0
  930. // END
  931. // IF @CanDelete=1
  932. // BEGIN
  933. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  934. // SET @rowCurrent += 1
  935. // CONTINUE
  936. // END
  937. // SET @QTY += @QTYCurrent
  938. // IF @LotNo is null or @QTY>=@iQuantityCurrent
  939. // BEGIN
  940. // SET @CanDelete=1
  941. // END
  942. // SET @rowCurrent += 1
  943. // END
  944. //SELECT * FROM #temp
  945. //DROP TABLE #temp
  946. //";
  947. // #endregion
  948. // string sqls = "";
  949. // if (Type=="1")
  950. // {
  951. // #region 工单备料sql
  952. // sqls = @" SELECT
  953. // c.MOCode as Code,
  954. // a.InvCode,
  955. // b.InvName,
  956. // b.InvStd,
  957. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  958. // a.WhCode,
  959. // b.InvUnit,
  960. // a.ExtensionID
  961. // FROM
  962. // ICSMOPick a
  963. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  964. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  965. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  966. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  967. // #endregion
  968. // }
  969. // if (Type == "2")
  970. // {
  971. // return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
  972. // }
  973. // if (Type=="3")
  974. // {
  975. // #region 工单材料出库SQL
  976. // sqls = @" select
  977. // a.IssueCode as Code,
  978. // a.InvCode,
  979. // b.InvName,
  980. // b.InvStd,
  981. // b.InvUnit,
  982. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  983. // a.WhCode,
  984. // a.ExtensionID
  985. // FROM
  986. // ICSMOIssue a
  987. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  988. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  989. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  990. // #endregion
  991. // }
  992. // if (Type=="4")
  993. // {
  994. // #region 委外备料SQL
  995. // sqls = @" select
  996. // c.OOCode as Code,
  997. // a.InvCode,
  998. // b.InvName,
  999. // b.InvStd,
  1000. // b.InvUnit,
  1001. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1002. // a.WhCode,
  1003. // a.ExtensionID
  1004. // FROM
  1005. // ICSOOPick a
  1006. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1007. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1008. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1009. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  1010. // #endregion
  1011. // }
  1012. // if (Type=="5")
  1013. // {
  1014. // #region 委外领料SQL
  1015. // sqls = @" select
  1016. // a.ApplyCode as Code,
  1017. // a.InvCode,
  1018. // b.InvName,
  1019. // b.InvStd,
  1020. //b.InvUnit,
  1021. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1022. // a.WhCode,
  1023. // a.ExtensionID
  1024. // FROM
  1025. // ICSOApply a
  1026. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1027. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1028. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1029. // #endregion
  1030. // }
  1031. // if (Type=="6")
  1032. // {
  1033. // #region 委外材料出库SQL
  1034. // sqls = @" select
  1035. // a.IssueCode as Code,
  1036. // a.InvCode,
  1037. // b.InvName,
  1038. // b.InvStd,
  1039. //b.InvUnit,
  1040. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1041. // a.WhCode,
  1042. //a.ExtensionID
  1043. // FROM
  1044. // ICSOIssue a
  1045. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1046. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1047. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1048. // #endregion
  1049. // }
  1050. // if (Type=="7")
  1051. // {
  1052. // #region 销售发货SQL
  1053. // sqls = @" select
  1054. // a.SDNCode as Code,
  1055. // a.InvCode,
  1056. // b.InvName,
  1057. // b.InvStd,
  1058. //b.InvUnit,
  1059. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1060. // a.WhCode,
  1061. //a.ExtensionID
  1062. // FROM
  1063. // ICSSDN a
  1064. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1065. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1066. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1067. // #endregion
  1068. // }
  1069. // if (Type=="8")
  1070. // {
  1071. // #region 其它出库SQL
  1072. // sqls = @" select
  1073. // a.OutCode as Code,
  1074. // a.InvCode,
  1075. // b.InvName,
  1076. // b.InvStd,
  1077. // b.InvUnit,
  1078. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1079. // a.WhCode,
  1080. // a.ExtensionID
  1081. // FROM
  1082. // ICSOtherOut a
  1083. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1084. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1085. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1086. // #endregion
  1087. // }
  1088. // if (Type == "9")
  1089. // {
  1090. // #region 借用SQL
  1091. // sqls = @"select
  1092. // a.BrrowCode as Code,
  1093. // a.InvCode,
  1094. // b.InvName,
  1095. // b.InvStd,
  1096. //b.InvUnit,
  1097. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1098. // a.WhCode,
  1099. //a.ExtensionID
  1100. // FROM
  1101. // ICSBrrow a
  1102. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1103. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1104. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1105. // #endregion
  1106. // }
  1107. // if (Type == "10")
  1108. // {
  1109. // #region 物料调拨
  1110. // sqls = @" select
  1111. // a.TransferNO as Code,
  1112. // a.InvCode,
  1113. // b.InvName,
  1114. // b.InvStd,
  1115. //b.InvUnit,
  1116. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1117. // a.FromWarehouseCode as WhCode,
  1118. //a.ExtensionID
  1119. // FROM
  1120. // ICSTransfer a
  1121. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1122. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1123. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1124. // #endregion
  1125. // }
  1126. // if (Type == "11")
  1127. // {
  1128. // #region 两步调出
  1129. // sqls = @"select
  1130. // a.OutCode as Code,
  1131. // a.InvCode,
  1132. // b.InvName,
  1133. // b.InvStd,
  1134. //b.InvUnit,
  1135. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1136. // a.WHCode ,
  1137. //a.ExtensionID
  1138. // from ICSOtherOut a
  1139. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1140. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1141. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1142. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1143. // #endregion
  1144. // }
  1145. // sqls = string.Format(sqls, ID,WorkPoint);
  1146. // sql = string.Format(sql, sqls, WorkPoint);
  1147. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1148. // DataTable dtCloned = table.Clone();
  1149. // foreach (DataColumn col in dtCloned.Columns)
  1150. // {
  1151. // col.DataType = typeof(string);
  1152. // }
  1153. // foreach (DataRow row in table.Rows)
  1154. // {
  1155. // DataRow newrow = dtCloned.NewRow();
  1156. // foreach (DataColumn column in dtCloned.Columns)
  1157. // {
  1158. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1159. // }
  1160. // dtCloned.Rows.Add(newrow);
  1161. // }
  1162. // if (Invmes.Rows.Count > 0)
  1163. // {
  1164. // dtCloned.Merge(Invmes, false);
  1165. // }
  1166. // return dtCloned;
  1167. // }
  1168. public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  1169. {
  1170. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1171. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1172. #region sql
  1173. #endregion
  1174. string sqls = "";
  1175. if (Type == "1")
  1176. {
  1177. #region 工单备料sql
  1178. sqls = @" SELECT
  1179. c.MOCode as Code,
  1180. a.InvCode,
  1181. b.InvName,
  1182. b.InvStd,
  1183. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1184. a.WhCode,
  1185. b.InvUnit,
  1186. a.ExtensionID
  1187. FROM
  1188. ICSMOPick a
  1189. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1190. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1191. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1192. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1193. #endregion
  1194. }
  1195. if (Type == "2")
  1196. {
  1197. sqls = @"select
  1198. a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1199. FROM
  1200. ICSMOApply a
  1201. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1202. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1203. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1204. }
  1205. if (Type == "3")
  1206. {
  1207. #region 工单材料出库SQL
  1208. sqls = @" select
  1209. a.IssueCode as Code,
  1210. a.InvCode,
  1211. b.InvName,
  1212. b.InvStd,
  1213. b.InvUnit,
  1214. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1215. a.WhCode,
  1216. a.ExtensionID
  1217. FROM
  1218. ICSMOIssue a
  1219. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1220. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1221. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1222. #endregion
  1223. }
  1224. if (Type == "4")
  1225. {
  1226. #region 委外备料SQL
  1227. sqls = @" select
  1228. c.OOCode as Code,
  1229. a.InvCode,
  1230. b.InvName,
  1231. b.InvStd,
  1232. b.InvUnit,
  1233. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1234. a.WhCode,
  1235. a.ExtensionID
  1236. FROM
  1237. ICSOOPick a
  1238. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1239. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1240. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1241. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  1242. #endregion
  1243. }
  1244. if (Type == "5")
  1245. {
  1246. #region 委外领料SQL
  1247. sqls = @"select
  1248. a.ApplyCode as Code,
  1249. a.InvCode,
  1250. b.InvName,
  1251. b.InvStd,
  1252. b.InvUnit,
  1253. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1254. a.WhCode,a.ExtensionID
  1255. FROM
  1256. ICSOApply a
  1257. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1258. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1259. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1260. #endregion
  1261. }
  1262. if (Type == "6")
  1263. {
  1264. #region 委外材料出库SQL
  1265. sqls = @" select
  1266. a.IssueCode as Code,
  1267. a.InvCode,
  1268. b.InvName,
  1269. b.InvStd,
  1270. b.InvUnit,
  1271. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1272. a.WhCode,
  1273. a.ExtensionID
  1274. FROM
  1275. ICSOIssue a
  1276. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1277. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1278. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1279. #endregion
  1280. }
  1281. if (Type == "7")
  1282. {
  1283. #region 销售发货SQL
  1284. sqls = @" select
  1285. a.SDNCode as Code,
  1286. a.InvCode,
  1287. b.InvName,
  1288. b.InvStd,
  1289. b.InvUnit,
  1290. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1291. a.WhCode,
  1292. a.ExtensionID
  1293. FROM
  1294. ICSSDN a
  1295. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1296. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1297. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1298. #endregion
  1299. }
  1300. if (Type == "8")
  1301. {
  1302. #region 其它出库SQL
  1303. sqls = @" select
  1304. a.OutCode as Code,
  1305. a.InvCode,
  1306. b.InvName,
  1307. b.InvStd,
  1308. b.InvUnit,
  1309. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1310. a.WhCode,
  1311. a.ExtensionID
  1312. FROM
  1313. ICSOtherOut a
  1314. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1315. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1316. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1317. #endregion
  1318. }
  1319. if (Type == "9")
  1320. {
  1321. #region 借用SQL
  1322. sqls = @"select
  1323. a.BrrowCode as Code,
  1324. a.InvCode,
  1325. b.InvName,
  1326. b.InvStd,
  1327. b.InvUnit,
  1328. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1329. a.WhCode,
  1330. a.ExtensionID
  1331. FROM
  1332. ICSBrrow a
  1333. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1334. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1335. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1336. #endregion
  1337. }
  1338. if (Type == "10")
  1339. {
  1340. #region 物料调拨
  1341. sqls = @"select
  1342. a.TransferNO as Code,
  1343. a.InvCode,
  1344. b.InvName,
  1345. b.InvStd,
  1346. b.InvUnit,
  1347. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1348. a.FromWarehouseCode as WhCode,
  1349. a.ExtensionID
  1350. FROM
  1351. ICSTransfer a
  1352. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1353. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1354. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1355. #endregion
  1356. }
  1357. if (Type == "11")
  1358. {
  1359. #region 两步调出
  1360. sqls = @"select
  1361. a.OutCode as Code,
  1362. a.InvCode,
  1363. b.InvName,
  1364. b.InvStd,
  1365. b.InvUnit,
  1366. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1367. a.WHCode ,
  1368. a.ExtensionID
  1369. from ICSOtherOut a
  1370. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1371. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1372. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1373. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1374. #endregion
  1375. }
  1376. sqls = string.Format(sqls, ID, WorkPoint);
  1377. string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1378. c.Code,
  1379. c.InvCode,
  1380. c.InvName,
  1381. c.InvStd,
  1382. c.InvUnit,
  1383. FLOOR(c.iQuantity) AS iQuantity,
  1384. c.WHCode AS WarehouseCode,
  1385. d.LotNO,
  1386. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1387. d.LocationCode AS LocationCode,
  1388. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1389. FLOOR(f.QTYTotal) QTYTotal
  1390. FROM
  1391. ({sqls}) c
  1392. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  1393. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1394. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1395. and d.WorkPoint='{WorkPoint}' AND d.Quantity>0
  1396. 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
  1397. WHERE
  1398. F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)) d
  1399. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1400. 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
  1401. order by c.Code,c.InvCode,d.MTIME ";
  1402. var dataset = Repository().FindDataSetBySql(sql);
  1403. if (dataset.Tables.Count == 0)
  1404. return null;
  1405. DataTable table = dataset.Tables[0];
  1406. decimal qtyCount = 0;
  1407. bool remove = false;
  1408. List<int> removeList = new List<int>();
  1409. for (int i = 0; i < table.Rows.Count; i++)
  1410. {
  1411. if (i != 0
  1412. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  1413. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
  1414. )
  1415. {
  1416. qtyCount = 0;
  1417. remove = false;
  1418. }
  1419. if (remove)
  1420. {
  1421. removeList.Add(i);
  1422. }
  1423. else
  1424. {
  1425. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  1426. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1427. qtyCount += lotQty;
  1428. if (qtyCount >= orderQty)
  1429. {
  1430. remove = true;
  1431. }
  1432. }
  1433. }
  1434. if (removeList.Count > 0)
  1435. {
  1436. removeList.Reverse();
  1437. foreach (var item in removeList)
  1438. {
  1439. table.Rows.RemoveAt(item);
  1440. }
  1441. }
  1442. var result = ConvertCellToString(table);
  1443. if (Invmes.Rows.Count > 0)
  1444. {
  1445. result.Merge(Invmes, false);
  1446. }
  1447. return result;
  1448. }
  1449. /// <summary>
  1450. /// 工单领料推荐
  1451. /// </summary>
  1452. /// <param name="Id"></param>
  1453. /// <param name="workPoint"></param>
  1454. /// <returns></returns>
  1455. public DataTable GetICSMOPickMergeByWorkorder(string Id, string workPoint)
  1456. {
  1457. string sql = $@"SELECT row_number() over (partition by c.Code,c.InvCode order by c.Code,c.InvCode,d.MTIME) AS rowNo,
  1458. c.Code,
  1459. c.InvCode,
  1460. c.InvName,
  1461. c.InvStd,
  1462. c.InvUnit,
  1463. FLOOR(c.iQuantity) AS iQuantity,
  1464. d.WarehouseCode,
  1465. d.LotNO,
  1466. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1467. d.LocationCode LocationCode,
  1468. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1469. FLOOR(f.QTYTotal) QTYTotal
  1470. FROM
  1471. (select
  1472. a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1473. FROM
  1474. ICSMOApply a
  1475. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1476. WHERE a.ApplyCode in ({Id}) AND a.WorkPoint = '{workPoint}'
  1477. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID) c
  1478. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1479. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1480. and d.WorkPoint='{workPoint}' AND d.Quantity>0 ) d on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1481. 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
  1482. order by c.Code,c.InvCode,d.MTIME";
  1483. var dataset = Repository().FindDataSetBySql(sql);
  1484. if (dataset.Tables.Count == 0)
  1485. return null;
  1486. DataTable table = dataset.Tables[0];
  1487. decimal qtyCount = 0;
  1488. bool remove = false;
  1489. List<int> removeList = new List<int>();
  1490. for (int i = 0; i < table.Rows.Count; i++)
  1491. {
  1492. if (i != 0
  1493. && !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()))
  1494. {
  1495. qtyCount = 0;
  1496. remove = false;
  1497. }
  1498. if (remove)
  1499. {
  1500. removeList.Add(i);
  1501. }
  1502. else
  1503. {
  1504. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  1505. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1506. qtyCount += lotQty;
  1507. if (qtyCount >= orderQty)
  1508. {
  1509. remove = true;
  1510. }
  1511. }
  1512. }
  1513. if (removeList.Count > 0)
  1514. {
  1515. removeList.Reverse();
  1516. foreach (var item in removeList)
  1517. {
  1518. table.Rows.RemoveAt(item);
  1519. }
  1520. }
  1521. var result = ConvertCellToString(table);
  1522. if (Invmes.Rows.Count > 0)
  1523. {
  1524. result.Merge(Invmes, false);
  1525. }
  1526. return result;
  1527. }
  1528. public DataTable ConvertCellToString(DataTable data)
  1529. {
  1530. DataTable dtCloned = data.Clone();
  1531. foreach (DataColumn col in dtCloned.Columns)
  1532. {
  1533. col.DataType = typeof(string);
  1534. }
  1535. foreach (DataRow row in data.Rows)
  1536. {
  1537. DataRow newrow = dtCloned.NewRow();
  1538. foreach (DataColumn column in dtCloned.Columns)
  1539. {
  1540. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1541. }
  1542. dtCloned.Rows.Add(newrow);
  1543. }
  1544. return dtCloned;
  1545. }
  1546. // public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1547. // {
  1548. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1549. // #region sql
  1550. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1551. // c.MergeID,
  1552. // c.Code,
  1553. // c.InvCode,
  1554. // c.InvName,
  1555. // c.InvStd,
  1556. //c.InvUnit,
  1557. // FLOOR(c.iQuantity) AS iQuantity,
  1558. // d.WarehouseCode,
  1559. // d.LocationCode,
  1560. // d.LotNO,
  1561. // FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1562. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1563. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1564. // FROM
  1565. // ({0}) c
  1566. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1567. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1568. // 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
  1569. //DECLARE @ItemCode VARCHAR(50),
  1570. // @QTY DECIMAL(18,3),
  1571. // @ItemCodeCurrent VARCHAR(50),
  1572. // @QTYCurrent DECIMAL(18,3),
  1573. // @iQuantityCurrent DECIMAL(18,3),
  1574. // @CanDelete BIT,
  1575. // @Row INT,
  1576. // @rowCurrent INT
  1577. //SET @Row = @@rowcount
  1578. //SET @rowCurrent=1
  1579. //SET @CanDelete=0
  1580. //SET @ItemCode=''
  1581. //WHILE @rowCurrent<=@Row
  1582. // BEGIN
  1583. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1584. //PRINT(@rowCurrent)
  1585. // IF @ItemCode<>@ItemCodeCurrent
  1586. // BEGIN
  1587. // SET @ItemCode=@ItemCodeCurrent
  1588. // SET @QTY=0
  1589. // SET @CanDelete=0
  1590. // END
  1591. // IF @CanDelete=1
  1592. // BEGIN
  1593. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  1594. // SET @rowCurrent += 1
  1595. // CONTINUE
  1596. // END
  1597. // SET @QTY += @QTYCurrent
  1598. // IF @QTY>=@iQuantityCurrent
  1599. // BEGIN
  1600. // SET @CanDelete=1
  1601. // END
  1602. // SET @rowCurrent += 1
  1603. // END
  1604. //SELECT * FROM #temp
  1605. //DROP TABLE #temp
  1606. //";
  1607. // #endregion
  1608. // string sqls = "";
  1609. // if (Type == "1")
  1610. // {
  1611. // #region 工单备料sql
  1612. // sqls = @" select
  1613. // x.MergeID,
  1614. // c.MOCode as Code,
  1615. // a.InvCode,
  1616. // b.InvName,
  1617. // b.InvStd,
  1618. //b.InvUnit,
  1619. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1620. // a.WhCode,
  1621. //a.ExtensionID
  1622. // FROM
  1623. // ICSMOPick a
  1624. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1625. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1626. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1627. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1628. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1629. // #endregion
  1630. // }
  1631. // if (Type == "2")
  1632. // {
  1633. // #region 工单领料SQL
  1634. // sqls = @" select
  1635. // x.MergeID,
  1636. // a.ApplyCode as Code,
  1637. // a.InvCode,
  1638. // b.InvName,
  1639. // b.InvStd,
  1640. //b.InvUnit,
  1641. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1642. // a.WhCode,
  1643. // a.ExtensionID
  1644. // FROM
  1645. // ICSMOApply a
  1646. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1647. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1648. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1649. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1650. // #endregion
  1651. // }
  1652. // if (Type == "3")
  1653. // {
  1654. // #region 工单材料出库SQL
  1655. // sqls = @" select
  1656. // x.MergeID,
  1657. // a.IssueCode as Code,
  1658. // a.InvCode,
  1659. // b.InvName,
  1660. // b.InvStd,
  1661. //b.InvUnit,
  1662. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1663. // a.WhCode,
  1664. //a.ExtensionID
  1665. // FROM
  1666. // ICSMOIssue a
  1667. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1668. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1669. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1670. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1671. // #endregion
  1672. // }
  1673. // if (Type == "4")
  1674. // {
  1675. // #region 委外备料SQL
  1676. // sqls = @" select
  1677. // x.MergeID,
  1678. // c.OOCode as Code,
  1679. // a.InvCode,
  1680. // b.InvName,
  1681. // b.InvStd,
  1682. //b.InvUnit,
  1683. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1684. // a.WhCode,
  1685. //a.ExtensionID
  1686. // FROM
  1687. // ICSOOPick a
  1688. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1689. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1690. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1691. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1692. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  1693. // #endregion
  1694. // }
  1695. // if (Type == "5")
  1696. // {
  1697. // #region 委外领料SQL
  1698. // sqls = @" select
  1699. // x.MergeID,
  1700. // a.ApplyCode as Code,
  1701. // a.InvCode,
  1702. // b.InvName,
  1703. // b.InvStd,
  1704. //b.InvUnit,
  1705. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1706. // a.WhCode,
  1707. //a.ExtensionID
  1708. // FROM
  1709. // ICSOApply a
  1710. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1711. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1712. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1713. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1714. // #endregion
  1715. // }
  1716. // if (Type == "6")
  1717. // {
  1718. // #region 委外材料出库SQL
  1719. // sqls = @" select
  1720. // x.MergeID,
  1721. // a.IssueCode as Code,
  1722. // a.InvCode,
  1723. // b.InvName,
  1724. // b.InvStd,
  1725. //b.InvUnit,
  1726. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1727. // a.WhCode,
  1728. //a.ExtensionID
  1729. // FROM
  1730. // ICSOIssue a
  1731. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1732. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1733. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1734. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1735. // #endregion
  1736. // }
  1737. // if (Type == "7")
  1738. // {
  1739. // #region 销售发货SQL
  1740. // sqls = @" select
  1741. // x.MergeID,
  1742. // a.SDNCode as Code,
  1743. // a.InvCode,
  1744. // b.InvName,
  1745. // b.InvStd,
  1746. //b.InvUnit,
  1747. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1748. // a.WhCode,
  1749. //a.ExtensionID
  1750. // FROM
  1751. // ICSSDN a
  1752. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1753. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1754. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1755. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1756. // #endregion
  1757. // }
  1758. // if (Type == "8")
  1759. // {
  1760. // #region 其它出库SQL
  1761. // sqls = @" select
  1762. // x.MergeID,
  1763. // a.OutCode as Code,
  1764. // a.InvCode,
  1765. // b.InvName,
  1766. // b.InvStd,
  1767. //b.InvUnit,
  1768. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1769. // a.WhCode,
  1770. //a.ExtensionID
  1771. // FROM
  1772. // ICSOtherOut a
  1773. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1774. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1775. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1776. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1777. // #endregion
  1778. // }
  1779. // if (Type == "9")
  1780. // {
  1781. // #region 借用SQL
  1782. // sqls = @" select
  1783. // x.MergeID,
  1784. // a.BrrowCode as Code,
  1785. // a.InvCode,
  1786. // b.InvName,
  1787. // b.InvStd,
  1788. //b.InvUnit,
  1789. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1790. // a.WhCode,
  1791. //a.ExtensionID
  1792. // FROM
  1793. // ICSBrrow a
  1794. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1795. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1796. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1797. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1798. // #endregion
  1799. // }
  1800. // if (Type == "10")
  1801. // {
  1802. // #region 物料调拨
  1803. // sqls = @" select
  1804. // x.MergeID,
  1805. // a.TransferNO as Code,
  1806. // a.InvCode,
  1807. // b.InvName,
  1808. // b.InvStd,
  1809. //b.InvUnit,
  1810. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1811. // a.FromWarehouseCode as WhCode,
  1812. //a.ExtensionID
  1813. // FROM
  1814. // ICSTransfer a
  1815. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1816. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1817. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1818. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  1819. // #endregion
  1820. // }
  1821. // if (Type == "11")
  1822. // {
  1823. // #region 两步调出
  1824. // sqls = @"select
  1825. // x.MergeID,
  1826. // a.OutCode as Code,
  1827. // a.InvCode,
  1828. // b.InvName,
  1829. // b.InvStd,
  1830. // b.InvUnit,
  1831. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1832. // a.WHCode as WhCode,
  1833. // a.ExtensionID
  1834. // FROM
  1835. // ICSOtherOut a
  1836. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1837. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1838. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1839. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1840. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  1841. // #endregion
  1842. // }
  1843. // sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  1844. // sql = string.Format(sql, sqls, WorkPoint);
  1845. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1846. // DataTable dtCloned = table.Clone();
  1847. // foreach (DataColumn col in dtCloned.Columns)
  1848. // {
  1849. // col.DataType = typeof(string);
  1850. // }
  1851. // foreach (DataRow row in table.Rows)
  1852. // {
  1853. // DataRow newrow = dtCloned.NewRow();
  1854. // foreach (DataColumn column in dtCloned.Columns)
  1855. // {
  1856. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1857. // }
  1858. // dtCloned.Rows.Add(newrow);
  1859. // }
  1860. // if (Invmes.Rows.Count > 0)
  1861. // {
  1862. // dtCloned.Merge(Invmes, false);
  1863. // }
  1864. // return dtCloned;
  1865. // }
  1866. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1867. {
  1868. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1869. string sqls = "";
  1870. if (Type == "1")
  1871. {
  1872. #region 工单备料sql
  1873. sqls = @" select
  1874. x.MergeID,
  1875. c.MOCode as Code,
  1876. a.InvCode,
  1877. b.InvName,
  1878. b.InvStd,
  1879. b.InvUnit,
  1880. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1881. a.WhCode,
  1882. a.ExtensionID
  1883. FROM
  1884. ICSMOPick a
  1885. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1886. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1887. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1888. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1889. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1890. #endregion
  1891. }
  1892. if (Type == "2")
  1893. {
  1894. #region 工单领料SQL
  1895. sqls = @" select
  1896. x.MergeID,
  1897. a.ApplyCode as Code,
  1898. a.InvCode,
  1899. b.InvName,
  1900. b.InvStd,
  1901. b.InvUnit,
  1902. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1903. a.WhCode,
  1904. a.ExtensionID
  1905. FROM
  1906. ICSMOApply a
  1907. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1908. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1909. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1910. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1911. #endregion
  1912. }
  1913. if (Type == "3")
  1914. {
  1915. #region 工单材料出库SQL
  1916. sqls = @" select
  1917. x.MergeID,
  1918. a.IssueCode as Code,
  1919. a.InvCode,
  1920. b.InvName,
  1921. b.InvStd,
  1922. b.InvUnit,
  1923. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1924. a.WhCode,
  1925. a.ExtensionID
  1926. FROM
  1927. ICSMOIssue a
  1928. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1929. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1930. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1931. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1932. #endregion
  1933. }
  1934. if (Type == "4")
  1935. {
  1936. #region 委外备料SQL
  1937. sqls = @" select
  1938. x.MergeID,
  1939. c.OOCode as Code,
  1940. a.InvCode,
  1941. b.InvName,
  1942. b.InvStd,
  1943. b.InvUnit,
  1944. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1945. a.WhCode,
  1946. a.ExtensionID
  1947. FROM
  1948. ICSOOPick a
  1949. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1950. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1951. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1952. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1953. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  1954. #endregion
  1955. }
  1956. if (Type == "5")
  1957. {
  1958. #region 委外领料SQL
  1959. sqls = @" select
  1960. x.MergeID,
  1961. a.ApplyCode as Code,
  1962. a.InvCode,
  1963. b.InvName,
  1964. b.InvStd,
  1965. b.InvUnit,
  1966. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1967. a.WhCode,
  1968. a.ExtensionID
  1969. FROM
  1970. ICSOApply a
  1971. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1972. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1973. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1974. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1975. #endregion
  1976. }
  1977. if (Type == "6")
  1978. {
  1979. #region 委外材料出库SQL
  1980. sqls = @" select
  1981. x.MergeID,
  1982. a.IssueCode as Code,
  1983. a.InvCode,
  1984. b.InvName,
  1985. b.InvStd,
  1986. b.InvUnit,
  1987. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1988. a.WhCode,
  1989. a.ExtensionID
  1990. FROM
  1991. ICSOIssue a
  1992. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1993. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1994. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1995. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1996. #endregion
  1997. }
  1998. if (Type == "7")
  1999. {
  2000. #region 销售发货SQL
  2001. sqls = @" select
  2002. x.MergeID,
  2003. a.SDNCode as Code,
  2004. a.InvCode,
  2005. b.InvName,
  2006. b.InvStd,
  2007. b.InvUnit,
  2008. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2009. a.WhCode,
  2010. a.ExtensionID
  2011. FROM
  2012. ICSSDN a
  2013. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2014. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2015. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND a.Type='1'
  2016. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2017. #endregion
  2018. }
  2019. if (Type == "8")
  2020. {
  2021. #region 其它出库SQL
  2022. sqls = @" select
  2023. x.MergeID,
  2024. a.OutCode as Code,
  2025. a.InvCode,
  2026. b.InvName,
  2027. b.InvStd,
  2028. b.InvUnit,
  2029. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2030. a.WhCode,
  2031. a.ExtensionID
  2032. FROM
  2033. ICSOtherOut a
  2034. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2035. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2036. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2037. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2038. #endregion
  2039. }
  2040. if (Type == "9")
  2041. {
  2042. #region 借用SQL
  2043. sqls = @" select
  2044. x.MergeID,
  2045. a.BrrowCode as Code,
  2046. a.InvCode,
  2047. b.InvName,
  2048. b.InvStd,
  2049. b.InvUnit,
  2050. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2051. a.WhCode,
  2052. a.ExtensionID
  2053. FROM
  2054. ICSBrrow a
  2055. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2056. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2057. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  2058. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  2059. #endregion
  2060. }
  2061. if (Type == "10")
  2062. {
  2063. #region 物料调拨
  2064. sqls = @" select
  2065. x.MergeID,
  2066. a.TransferNO as Code,
  2067. a.InvCode,
  2068. b.InvName,
  2069. b.InvStd,
  2070. b.InvUnit,
  2071. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2072. a.FromWarehouseCode as WhCode,
  2073. a.ExtensionID
  2074. FROM
  2075. ICSTransfer a
  2076. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2077. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2078. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  2079. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  2080. #endregion
  2081. }
  2082. if (Type == "11")
  2083. {
  2084. #region 两步调出
  2085. sqls = @" select
  2086. x.MergeID,
  2087. a.OutCode as Code,
  2088. a.InvCode,
  2089. b.InvName,
  2090. b.InvStd,
  2091. b.InvUnit,
  2092. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2093. a.WHCode as WhCode,
  2094. a.ExtensionID
  2095. FROM
  2096. ICSOtherOut a
  2097. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2098. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2099. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2100. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  2101. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  2102. #endregion
  2103. }
  2104. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2105. #region sql
  2106. string sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  2107. c.MergeID,
  2108. c.Code,
  2109. c.InvCode,
  2110. c.InvName,
  2111. c.InvStd,
  2112. c.InvUnit,
  2113. FLOOR(c.iQuantity) AS iQuantity,
  2114. d.WarehouseCode,
  2115. d.LocationCode,
  2116. d.LotNO,
  2117. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  2118. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  2119. FLOOR(f.QTYTotal) QTYTotal
  2120. FROM
  2121. ({sqls}) c
  2122. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  2123. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  2124. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2125. and d.WorkPoint='{WorkPoint}' AND d.Quantity>0 ) d
  2126. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  2127. 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
  2128. order by c.Code,c.InvCode,d.MTIME ";
  2129. #endregion
  2130. var dataset = Repository().FindDataSetBySql(sql);
  2131. if (dataset.Tables.Count == 0)
  2132. return null;
  2133. DataTable table = dataset.Tables[0];
  2134. decimal qtyCount = 0;
  2135. bool remove = false;
  2136. List<int> removeList = new List<int>();
  2137. for (int i = 0; i < table.Rows.Count; i++)
  2138. {
  2139. if (i != 0
  2140. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  2141. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
  2142. )
  2143. {
  2144. qtyCount = 0;
  2145. remove = false;
  2146. }
  2147. if (remove)
  2148. {
  2149. removeList.Add(i);
  2150. }
  2151. else
  2152. {
  2153. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  2154. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  2155. qtyCount += lotQty;
  2156. if (qtyCount >= orderQty)
  2157. {
  2158. remove = true;
  2159. }
  2160. }
  2161. }
  2162. if (removeList.Count > 0)
  2163. {
  2164. removeList.Reverse();
  2165. foreach (var item in removeList)
  2166. {
  2167. table.Rows.RemoveAt(item);
  2168. }
  2169. }
  2170. var result = ConvertCellToString(table);
  2171. if (Invmes.Rows.Count > 0)
  2172. {
  2173. result.Merge(Invmes, false);
  2174. }
  2175. return result;
  2176. }
  2177. public string MergeMaterial(string keyValue, string Type)
  2178. {
  2179. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2180. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2181. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2182. string msg = "";
  2183. string sql = string.Empty;
  2184. string dataList = string.Empty;
  2185. List<string> arry = keyValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2186. if (arry.Count > 0)
  2187. {
  2188. StringBuilder stringBuilder = new StringBuilder();
  2189. foreach (var i in arry)
  2190. {
  2191. stringBuilder.Append($@"'{i}',");
  2192. }
  2193. dataList = stringBuilder.ToString(0, stringBuilder.Length - 1);
  2194. }
  2195. Int64 Merge_ID = 0;
  2196. DateTime time = DateTime.Now;
  2197. string Tday = time.ToString("yyyyMMdd");
  2198. string sqls = string.Format(@"SELECT MAX(A.MergeID) AS SourceID FROM ICSMOPickMerge A WHERE A.MergeID LIKE '{0}%' AND LEN(a.MergeID) = 13", Tday);
  2199. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2200. DataTable dts = ds.Tables[0];
  2201. if (dts != null && dts.Rows.Count > 0)
  2202. {
  2203. string lot = dts.Rows[0]["SourceID"].ToString();
  2204. if (!string.IsNullOrWhiteSpace(lot))
  2205. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  2206. }
  2207. string MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  2208. string order = string.Empty;
  2209. string orderCode = string.Empty;
  2210. string quantity = string.Empty;
  2211. string sqlString1 = string.Empty;
  2212. string sqlString2 = string.Empty;
  2213. if (Type == "1")//工单备料
  2214. {
  2215. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2216. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2217. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2218. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  2219. where a.MOCode in ({5})
  2220. ";
  2221. }
  2222. if (Type == "2")//工单发料
  2223. {
  2224. order = "ICSMOApply";
  2225. orderCode = "b.ApplyCode";
  2226. quantity = "b.IssueQuantity";
  2227. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2228. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2229. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
  2230. from ICSMOApply a
  2231. where a.ApplyCode in ({5})";
  2232. }
  2233. if (Type == "3")//材料出库
  2234. {
  2235. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2236. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2237. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2238. from ICSMOIssue a
  2239. where a.IssueCode in ({5}) ";
  2240. }
  2241. if (Type == "4")//委外备料
  2242. {
  2243. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2244. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2245. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2246. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  2247. where a.OOCode in ({5})";
  2248. }
  2249. if (Type == "5")//委外领料
  2250. {
  2251. order = "ICSOApply";
  2252. orderCode = "b.ApplyCode";
  2253. quantity = "b.IssueQuantity";
  2254. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2255. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2256. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.ApplyCode
  2257. from ICSOApply a
  2258. where a.ApplyCode in ({5})";
  2259. }
  2260. if (Type == "6")//委外材料出库
  2261. {
  2262. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2263. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2264. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2265. from ICSOIssue a
  2266. where a.IssueCode in ({5})";
  2267. }
  2268. if (Type == "7")//销售发货
  2269. {
  2270. order = "ICSSDN";
  2271. orderCode = "b.SDNCode";
  2272. quantity = "b.SDNQuantity";
  2273. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2274. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2275. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.SDNCode
  2276. from ICSSDN a
  2277. where a.SDNCode in ({5}) AND a.Type='1' ";
  2278. }
  2279. if (Type == "8")//其它出库
  2280. {
  2281. order = "ICSOtherOut";
  2282. orderCode = "b.OutCode";
  2283. quantity = "b.OutQuantity";
  2284. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2285. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2286. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.OutCode
  2287. from ICSOtherOut a
  2288. where a.OutCode in ({5})";
  2289. }
  2290. if (Type == "9")//借用单
  2291. {
  2292. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2293. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2294. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2295. from ICSBrrow a
  2296. where a.BrrowCode in ({5})";
  2297. }
  2298. if (Type == "10")//物料调拨
  2299. {
  2300. order = "ICSTransfer";
  2301. orderCode = "b.TransferNO";
  2302. quantity = "b.TransferQuantity";
  2303. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2304. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2305. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}',a.TransferNO
  2306. from ICSTransfer a
  2307. where a.TransferNO in ({5})
  2308. ";
  2309. }
  2310. if (Type == "11")//两步调出
  2311. {
  2312. sql += @" INSERT INTO dbo.ICSMOPickMerge
  2313. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2314. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2315. from ICSOtherOut a
  2316. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2317. where a.OutCode in ({5})
  2318. ";
  2319. }
  2320. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, dataList);
  2321. sqlString1 += $@" SELECT a.ID FROM ICSMOPickMerge a WHERE a.SourceID IN (SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) )";
  2322. sqlString2 += $@" SELECT b.ID FROM {order} b WHERE {orderCode} IN({dataList}) AND {quantity}>0";
  2323. DataSet ds1 = SqlHelper.GetDataSetBySql(sqlString1);
  2324. DataSet ds2 = SqlHelper.GetDataSetBySql(sqlString2);
  2325. DataTable dts1 = ds1.Tables[0];
  2326. DataTable dts2 = ds2.Tables[0];
  2327. if ((dts1 != null && dts1.Rows.Count > 0))
  2328. {
  2329. }
  2330. else if (dts2 != null && dts2.Rows.Count > 0)
  2331. {
  2332. msg = "当前选择单据号存在已出库的单据号,合并拣料失败";
  2333. }
  2334. else
  2335. {
  2336. try
  2337. {
  2338. if (SqlHelper.CmdExecuteNonQueryLi(sql) == 0)
  2339. {
  2340. msg = "新增失败";
  2341. }
  2342. }
  2343. catch (Exception ex)
  2344. {
  2345. throw new Exception(ex.Message);
  2346. }
  2347. }
  2348. return msg;
  2349. }
  2350. public string CancelMergeMaterial(string keyValue, string Type)
  2351. {
  2352. string msg = "";
  2353. string sql = string.Empty;
  2354. keyValue = keyValue.TrimEnd(',');
  2355. List<string> arry = keyValue.Split(',').ToList();
  2356. string dataList = string.Empty;
  2357. if (arry.Count > 0)
  2358. {
  2359. foreach (var i in arry)
  2360. {
  2361. dataList += $@"'{i}',";
  2362. }
  2363. if (dataList.Any())
  2364. {
  2365. dataList = dataList.TrimEnd(',');
  2366. }
  2367. }
  2368. string sqls = $@" SELECT SourceID FROM ICSMOPickMerge WHERE EATTRIBUTE1 IN({dataList}) ";
  2369. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2370. DataTable dts = ds.Tables[0];
  2371. if (dts == null || dts.Rows.Count <= 0)
  2372. {
  2373. msg = "当前单据未合并拣料,取消合并拣料失败";
  2374. return msg;
  2375. }
  2376. string sqlStrring = string.Empty;
  2377. if (Type == "2")//工单发料
  2378. {
  2379. sqlStrring = $@"select ID from ICSMOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
  2380. }
  2381. if (Type == "5")//委外领料
  2382. {
  2383. sqlStrring = $@"select ID from ICSOApply a where a.ID in ({sqls}) and a.IssueQuantity=0 ";
  2384. }
  2385. if (Type == "7")//销售发货
  2386. {
  2387. sqlStrring = $@"select ID from ICSSDN a where a.ID in ({sqls}) and a.SDNQuantity=0 AND a.Type='1' ";
  2388. }
  2389. if (Type == "8")//其它出库
  2390. {
  2391. sqlStrring = $@"select ID
  2392. from ICSOtherOut a
  2393. where a.ID in ({sqls}) and a.OutQuantity=0";
  2394. }
  2395. if (Type == "10")//物料调拨
  2396. {
  2397. sqlStrring = $@"select ID from ICSTransfer a where a.ID in ({sqls}) and a.TransferQuantity=0 ";
  2398. }
  2399. DataSet dsdata = SqlHelper.GetDataSetBySql(sqlStrring);
  2400. DataTable dtdsdatas = dsdata.Tables[0];
  2401. if (dtdsdatas == null || dtdsdatas.Rows.Count <= 0)
  2402. {
  2403. msg = "当前物料已经出库,取消合并失败";
  2404. return msg;
  2405. }
  2406. sql = $@"DELETE FROM ICSMOPickMerge WHERE SourceID IN({sqls})";
  2407. try
  2408. {
  2409. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2410. {
  2411. }
  2412. else
  2413. {
  2414. msg = "取消合并失败";
  2415. }
  2416. }
  2417. catch (Exception ex)
  2418. {
  2419. throw new Exception(ex.Message);
  2420. }
  2421. return msg;
  2422. }
  2423. public string CheckQty(string objArr)
  2424. {
  2425. objArr = objArr.TrimEnd(',');
  2426. string sql = @"select * from ICSMOPickMerge a
  2427. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  2428. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  2429. where MOCode in ({0})";
  2430. sql = string.Format(sql, objArr);
  2431. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2432. if (dt != null && dt.Rows.Count > 0)
  2433. {
  2434. return "1";
  2435. }
  2436. return "0";
  2437. }
  2438. }
  2439. }