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

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