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

1991 lines
98 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  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,
  104. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,
  105. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,
  106. f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  107. from ICSMOApply a
  108. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  109. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  110. where a.WorkPoint='{WorkPoint}' ");
  111. if (!string.IsNullOrWhiteSpace(queryJson))
  112. {
  113. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  114. {
  115. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  116. }
  117. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  118. {
  119. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  120. }
  121. }
  122. sqlString.Append(@" group by a.ApplyCode, a.WorkPoint,a.CreateDateTime,a.createperson,
  123. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  124. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10) as t where t.row=1");
  125. #endregion
  126. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  127. }
  128. //工单领料(发料申请)子表查询
  129. public DataTable GetSubGridJson2(string Code)
  130. {
  131. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  132. DataTable dt = new DataTable();
  133. //var queryParam = queryJson.ToJObject();
  134. List<DbParameter> parameter = new List<DbParameter>();
  135. string 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,
  136. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  137. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  138. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  139. from ICSMOApply a
  140. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  141. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  142. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  143. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  144. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  145. sql = string.Format(sql, Code, WorkPoint);
  146. return Repository().FindTableBySql(sql.ToString());
  147. }
  148. //工单材料出库(材料出库)
  149. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  150. {
  151. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  152. DataTable dt = new DataTable();
  153. var queryParam = queryJson.ToJObject();
  154. List<DbParameter> parameter = new List<DbParameter>();
  155. StringBuilder sqlString = new StringBuilder();
  156. #region [SQL]
  157. // 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,
  158. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  159. // from ICSMOIssue a
  160. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  161. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  162. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  163. // sql += " WHERE 1=1 and e.ID is null";
  164. sqlString.Append($@"SELECT * FROM(SELECT row_number ( ) OVER ( partition BY a.IssueCode ORDER BY a.IssueCode ) AS row,
  165. a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  166. case when max(e.SourceID) is null then '' else ''
  167. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  168. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  169. from ICSMOIssue a
  170. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  171. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  172. where a.WorkPoint = '{WorkPoint}' ");
  173. if (!string.IsNullOrWhiteSpace(queryJson))
  174. {
  175. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  176. {
  177. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  178. }
  179. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  180. {
  181. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  182. }
  183. }
  184. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.createperson,f.Colspan,f.ProjectCode,f.BatchCode,
  185. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  186. f.cFree8, f.cFree9, f.cFree10 ) AS t WHERE t.row= 1 ");
  187. #endregion
  188. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  189. }
  190. //工单材料出库(材料出库)子表查询
  191. public DataTable GetSubGridJson3(string Code)
  192. {
  193. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  194. DataTable dt = new DataTable();
  195. //var queryParam = queryJson.ToJObject();
  196. List<DbParameter> parameter = new List<DbParameter>();
  197. 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,
  198. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  199. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  200. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  201. from ICSMOIssue a
  202. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  203. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  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.IssueCode='{0}' and a.WorkPoint='{1}'";
  207. sql = string.Format(sql, Code, WorkPoint);
  208. return Repository().FindTableBySql(sql.ToString());
  209. }
  210. //委外备料(委外备料)
  211. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  212. {
  213. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  214. DataTable dt = new DataTable();
  215. var queryParam = queryJson.ToJObject();
  216. List<DbParameter> parameter = new List<DbParameter>();
  217. StringBuilder sqlString = new StringBuilder();
  218. #region [SQL]
  219. sqlString.Append($@"select * from (select row_number() over(partition by b.OOCode order by b.OOCode) row, b.OOCode as Code,
  220. b.CreateDateTime as MTIME,
  221. b.CreatePerson as MUSER,
  222. case
  223. when max(e.SourceID) is null then ''
  224. else ''
  225. end as IsNew,
  226. f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,
  227. f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  228. from ICSOOPick a
  229. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.WorkPoint = b.WorkPoint
  230. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  231. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  232. WHERE b.WorkPoint = '{WorkPoint}' ");
  233. if (!string.IsNullOrWhiteSpace(queryJson))
  234. {
  235. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  236. {
  237. sqlString.Append($@" and a.OOCode like '%{queryParam["POCode"]}%' ");
  238. }
  239. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  240. {
  241. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  242. }
  243. }
  244. sqlString.Append(@" group by b.OOCode,b.CreateDateTime,b.CreatePerson,f.Colspan ,f.ProjectCode ,
  245. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4,
  246. f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10) t where t.row=1");
  247. #endregion
  248. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  249. }
  250. //委外备料(委外备料)子表查询
  251. public DataTable GetSubGridJson4(string Code)
  252. {
  253. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  254. DataTable dt = new DataTable();
  255. //var queryParam = queryJson.ToJObject();
  256. List<DbParameter> parameter = new List<DbParameter>();
  257. 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,
  258. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  259. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  260. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  261. from ICSOOPick a
  262. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  263. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  264. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  265. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  266. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  267. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  268. sql = string.Format(sql, Code, WorkPoint);
  269. return Repository().FindTableBySql(sql.ToString());
  270. }
  271. //委外领料(委外发料申请)
  272. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  273. {
  274. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  275. DataTable dt = new DataTable();
  276. var queryParam = queryJson.ToJObject();
  277. List<DbParameter> parameter = new List<DbParameter>();
  278. StringBuilder sqlString=new StringBuilder();
  279. #region [SQL]
  280. // 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,
  281. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  282. // from ICSOApply a
  283. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  284. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  285. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  286. // sql += " WHERE 1=1 and e.ID is null";
  287. 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,
  288. case when max(e.SourceID) is null then ''
  289. else ''
  290. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  291. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  292. from ICSOApply a
  293. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  294. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  295. where a.WorkPoint = '{WorkPoint}'");
  296. if (!string.IsNullOrWhiteSpace(queryJson))
  297. {
  298. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  299. {
  300. sqlString.Append($@" and a.ApplyCode like '%{queryParam["POCode"]}%' ");
  301. }
  302. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  303. {
  304. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  305. }
  306. }
  307. sqlString.Append(@"group by a.ApplyCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  308. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  309. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10 ) t where row=1");
  310. #endregion
  311. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  312. }
  313. //委外领料(委外发料申请)子表查询
  314. public DataTable GetSubGridJson5(string Code)
  315. {
  316. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  317. DataTable dt = new DataTable();
  318. //var queryParam = queryJson.ToJObject();
  319. List<DbParameter> parameter = new List<DbParameter>();
  320. string 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,
  321. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  322. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  323. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  324. from ICSOApply a
  325. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  326. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  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. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  330. sql = string.Format(sql, Code, WorkPoint);
  331. return Repository().FindTableBySql(sql.ToString());
  332. }
  333. //委外材料出库(委外发料申请)
  334. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  335. {
  336. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  337. DataTable dt = new DataTable();
  338. var queryParam = queryJson.ToJObject();
  339. List<DbParameter> parameter = new List<DbParameter>();
  340. StringBuilder sqlString=new StringBuilder();
  341. #region [SQL]
  342. // 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,
  343. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  344. // from ICSOIssue a
  345. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  346. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  347. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  348. // sql += " WHERE 1=1 and e.ID is null";
  349. sqlString.Append($@"select * from(select row_number() over(partition by a.IssueCode order by a.IssueCode) row, a.IssueCode as Code,
  350. a.CreateDateTime as MTIME,
  351. a.CreatePerson as MUSER,
  352. case
  353. when max(e.SourceID) is null then ''
  354. else ''
  355. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  356. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  357. f.cFree8,f.cFree9,f.cFree10
  358. from ICSOIssue a
  359. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  360. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  361. where a.WorkPoint = '{WorkPoint}'");
  362. if (!string.IsNullOrWhiteSpace(queryJson))
  363. {
  364. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  365. {
  366. sqlString.Append($@" and a.IssueCode like '%{queryParam["POCode"]}%' ");
  367. }
  368. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  369. {
  370. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  371. }
  372. }
  373. sqlString.Append(@"group by a.IssueCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  374. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,
  375. f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10) t where t.row=1");
  376. #endregion
  377. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  378. }
  379. //委外材料出库(委外发料申请)子表查询
  380. public DataTable GetSubGridJson6(string Code)
  381. {
  382. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  383. DataTable dt = new DataTable();
  384. //var queryParam = queryJson.ToJObject();
  385. List<DbParameter> parameter = new List<DbParameter>();
  386. 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,
  387. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  388. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  389. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  390. from ICSOIssue a
  391. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  392. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  393. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  394. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  395. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  396. sql = string.Format(sql, Code, WorkPoint);
  397. return Repository().FindTableBySql(sql.ToString());
  398. }
  399. //销售发货(销售发货)
  400. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  401. {
  402. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  403. DataTable dt = new DataTable();
  404. var queryParam = queryJson.ToJObject();
  405. List<DbParameter> parameter = new List<DbParameter>();
  406. StringBuilder sqlString = new StringBuilder();
  407. #region [SQL]
  408. // 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,
  409. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  410. // from ICSSDN a
  411. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  412. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  413. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  414. // sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  415. sqlString.Append($@"SELECT * from (SELECT Row_Number() over(partition by a.SDNCode Order by a.SDNCode) as r, a.SDNCode AS Code,
  416. a.CreateDateTime AS MTIME,
  417. a.CreatePerson AS MUSER,
  418. (CASE WHEN max(e.SourceID) IS NULL THEN '' ELSE '' END) AS IsNew,
  419. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  420. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10
  421. FROM ICSSDN a
  422. LEFT JOIN ICSMOPickMerge e ON a.ID = e.SourceID AND a.WorkPoint = e.WorkPoint
  423. LEFT JOIN ICSExtension f ON a.ExtensionID = f.ID AND a.WorkPoint = f.WorkPoint
  424. WHERE a.WorkPoint = '{WorkPoint}' ");
  425. if (!string.IsNullOrWhiteSpace(queryJson))
  426. {
  427. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  428. {
  429. sqlString.Append($" and a.SDNCode like '%{queryParam["POCode"]}%' ");
  430. }
  431. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  432. {
  433. sqlString.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  434. }
  435. }
  436. sqlString.Append(@"GROUP BY a.SDNCode, a.CreateDateTime, a.CreatePerson, f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  437. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10) t WHERE t.r=1");
  438. #endregion
  439. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  440. }
  441. //销售发货(销售发货)子表查询
  442. public DataTable GetSubGridJson7(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.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,
  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.SDNQuantity as IssueQuantity
  452. from ICSSDN 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.SDNCode='{0}' and a.WorkPoint='{1}'";
  458. sql = string.Format(sql, Code, WorkPoint);
  459. return Repository().FindTableBySql(sql.ToString());
  460. }
  461. //其它出库(其它出库)
  462. public DataTable GetGridJson8(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.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,
  471. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  472. //from ICSOtherOut 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 e.ID is null ";
  477. sqlString.Append($@"select * from(select row_number() over(partition by a.OutCode order by a.OutCode) row, a.OutCode as Code,
  478. a.CreateDateTime as MTIME,
  479. a.CreatePerson as MUSER,
  480. case
  481. when max(e.SourceID) is null then ''
  482. else ''
  483. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  484. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  485. from ICSOtherOut a
  486. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  487. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  488. where a.WorkPoint = '{WorkPoint}'");
  489. #endregion
  490. if (!string.IsNullOrWhiteSpace(queryJson))
  491. {
  492. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  493. {
  494. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  495. }
  496. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  497. {
  498. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  499. }
  500. }
  501. sqlString.Append(@" group by a.OutCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,f.BatchCode,
  502. f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,
  503. f.cFree7,f.cFree8,f.cFree9,f.cFree10) t where t.row=1");
  504. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  505. }
  506. //其它出库(其它出库)子表查询
  507. public DataTable GetSubGridJson8(string Code)
  508. {
  509. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  510. DataTable dt = new DataTable();
  511. //var queryParam = queryJson.ToJObject();
  512. List<DbParameter> parameter = new List<DbParameter>();
  513. 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,
  514. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  515. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  516. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  517. from ICSOtherOut a
  518. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  519. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  520. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  521. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  522. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  523. sql = string.Format(sql, Code, WorkPoint);
  524. return Repository().FindTableBySql(sql.ToString());
  525. }
  526. //借用(借用)
  527. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  528. {
  529. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  530. DataTable dt = new DataTable();
  531. var queryParam = queryJson.ToJObject();
  532. List<DbParameter> parameter = new List<DbParameter>();
  533. StringBuilder sqlString=new StringBuilder();
  534. #region [SQL]
  535. // sql = @"
  536. //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,
  537. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  538. // from ICSBrrow a
  539. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  540. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  541. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  542. // sql += " WHERE 1=1 and e.ID is null ";
  543. sqlString.Append($@"select * from(select row_number() over(partition by a.BrrowCode order by a.BrrowCode) row, a.BrrowCode as Code,
  544. a.CreateDateTime as MTIME,
  545. a.CreatePerson as MUSER,
  546. case
  547. when max(e.SourceID) is null then ''
  548. else ''
  549. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,
  550. f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,
  551. f.cFree8,f.cFree9,f.cFree10
  552. from ICSBrrow a
  553. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  554. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  555. where a.WorkPoint = '{WorkPoint}'");
  556. if (!string.IsNullOrWhiteSpace(queryJson))
  557. {
  558. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  559. {
  560. sqlString.Append($@" and a.BrrowCode like '%{queryParam["POCode"]}%' ");
  561. }
  562. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  563. {
  564. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  565. }
  566. }
  567. sqlString.Append(@"group by a.BrrowCode,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  568. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  569. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,
  570. f.cFree10) t where t.row=1");
  571. #endregion
  572. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  573. }
  574. //借用(借用)子表查询
  575. public DataTable GetSubGridJson9(string Code)
  576. {
  577. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  578. DataTable dt = new DataTable();
  579. //var queryParam = queryJson.ToJObject();
  580. List<DbParameter> parameter = new List<DbParameter>();
  581. 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,
  582. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  583. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  584. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.BrrowQuantity as IssueQuantity
  585. from ICSBrrow a
  586. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  587. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  588. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  589. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  590. where a.BrrowCode='{0}' and a.WorkPoint='{1}'";
  591. sql = string.Format(sql, Code, WorkPoint);
  592. return Repository().FindTableBySql(sql.ToString());
  593. }
  594. //物料调拨
  595. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  596. {
  597. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  598. DataTable dt = new DataTable();
  599. var queryParam = queryJson.ToJObject();
  600. List<DbParameter> parameter = new List<DbParameter>();
  601. StringBuilder sqlString=new StringBuilder();
  602. #region [SQL]
  603. // sql = @"
  604. //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,
  605. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  606. // from ICSBrrow a
  607. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  608. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  609. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  610. // sql += " WHERE 1=1 and e.ID is null ";
  611. sqlString.Append($@"select * from (select row_number() over(partition by a.TransferNO order by a.TransferNO) row,
  612. a.TransferNO as Code,a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  613. case
  614. when max(e.SourceID) is null then ''
  615. else ''
  616. end as IsNew,f.Colspan,f.ProjectCode,f.BatchCode,f.Version,f.Brand,f.cFree1,
  617. f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  618. from ICSTransfer a
  619. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  620. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  621. where a.WorkPoint = '{WorkPoint}' and a.Status = '2'");
  622. if (!string.IsNullOrWhiteSpace(queryJson))
  623. {
  624. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  625. {
  626. sqlString.Append($@" and a.BrrowCode like '%{queryParam["POCode"]}%' ");
  627. }
  628. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  629. {
  630. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  631. }
  632. }
  633. sqlString.Append(@"group by a.TransferNO,a.CreateDateTime,a.CreatePerson,f.Colspan,f.ProjectCode,
  634. f.BatchCode,f.Version,f.Brand,f.cFree1,f.cFree2,f.cFree3,f.cFree4,
  635. f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10) t where t.row=1");
  636. #endregion
  637. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  638. }
  639. //物料调拨子表查询
  640. public DataTable GetSubGridJson10(string Code)
  641. {
  642. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  643. DataTable dt = new DataTable();
  644. //var queryParam = queryJson.ToJObject();
  645. List<DbParameter> parameter = new List<DbParameter>();
  646. string sql = @"select a.ID,a.TransferNO as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.FromWarehouseCode as WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  647. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  648. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  649. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.TransferQuantity as IssueQuantity
  650. from ICSTransfer a
  651. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  652. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  653. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  654. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  655. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  656. sql = string.Format(sql, Code, WorkPoint);
  657. return Repository().FindTableBySql(sql.ToString());
  658. }
  659. //两步调拨
  660. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  661. {
  662. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  663. DataTable dt = new DataTable();
  664. var queryParam = queryJson.ToJObject();
  665. List<DbParameter> parameter = new List<DbParameter>();
  666. StringBuilder sqlString=new StringBuilder();
  667. #region [SQL]
  668. // sql = @"
  669. //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,
  670. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  671. // from ICSBrrow a
  672. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  673. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  674. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  675. // sql += " WHERE 1=1 and e.ID is null ";
  676. 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,
  677. case when max(e.SourceID) is null then '' else '' end as IsNew,
  678. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  679. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10
  680. FROM ICSOtherOut a
  681. INNER JOIN ICSTransfer tra ON a.TransferDetailID = tra.TransferDetailID AND a.WorkPoint = tra.WorkPoint
  682. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  683. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  684. where a.WorkPoint = '{WorkPoint}'
  685. and a.Status = '2' ");
  686. if (!string.IsNullOrWhiteSpace(queryJson))
  687. {
  688. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  689. {
  690. sqlString.Append($@" and a.OutCode like '%{queryParam["POCode"]}%' ");
  691. }
  692. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  693. {
  694. sqlString.Append($@" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  695. }
  696. }
  697. sqlString.Append(@" group by a.OutCode, a.CreateDateTime, a.CreatePerson, f.Colspan ,f.ProjectCode ,
  698. f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,
  699. f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10) t where t.row=1");
  700. #endregion
  701. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  702. }
  703. //两步调拨子表查询
  704. public DataTable GetSubGridJson11(string Code)
  705. {
  706. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  707. DataTable dt = new DataTable();
  708. //var queryParam = queryJson.ToJObject();
  709. List<DbParameter> parameter = new List<DbParameter>();
  710. 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,
  711. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  712. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  713. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  714. FROM ICSOtherOut a
  715. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  716. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  717. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  718. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  719. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  720. where a.OutCode='{0}' and a.WorkPoint='{1}'";
  721. sql = string.Format(sql, Code, WorkPoint);
  722. return Repository().FindTableBySql(sql.ToString());
  723. }
  724. // public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  725. // {
  726. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  727. // ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  728. // #region sql
  729. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  730. // c.Code,
  731. // c.InvCode,
  732. // c.InvName,
  733. // c.InvStd,
  734. // c.InvUnit,
  735. // FLOOR(c.iQuantity) AS iQuantity,
  736. // d.WarehouseCode,
  737. // m.LotNO,
  738. // (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
  739. // (case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
  740. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  741. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  742. // FROM
  743. // ({0}) c
  744. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  745. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  746. // 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
  747. //DECLARE @ItemCode VARCHAR(50),
  748. // @QTY DECIMAL(18,3),
  749. // @ItemCodeCurrent VARCHAR(50),
  750. // @Lotno VARCHAR(50),
  751. // @QTYCurrent DECIMAL(18,3),
  752. // @iQuantityCurrent DECIMAL(18,3),
  753. // @CanDelete BIT,
  754. // @Row INT,
  755. // @rowCurrent INT
  756. //SET @Row = @@rowcount
  757. //SET @rowCurrent=1
  758. //SET @CanDelete=0
  759. //SET @ItemCode=''
  760. //SET @Lotno = ''
  761. //WHILE @rowCurrent<=@Row
  762. // BEGIN
  763. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
  764. //PRINT(@rowCurrent)
  765. // IF @ItemCode<>@ItemCodeCurrent
  766. // BEGIN
  767. // SET @ItemCode=@ItemCodeCurrent
  768. // SET @QTY=0
  769. // SET @CanDelete=0
  770. // END
  771. // IF @CanDelete=1
  772. // BEGIN
  773. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  774. // SET @rowCurrent += 1
  775. // CONTINUE
  776. // END
  777. // SET @QTY += @QTYCurrent
  778. // IF @LotNo is null or @QTY>=@iQuantityCurrent
  779. // BEGIN
  780. // SET @CanDelete=1
  781. // END
  782. // SET @rowCurrent += 1
  783. // END
  784. //SELECT * FROM #temp
  785. //DROP TABLE #temp
  786. //";
  787. // #endregion
  788. // string sqls = "";
  789. // if (Type=="1")
  790. // {
  791. // #region 工单备料sql
  792. // sqls = @" SELECT
  793. // c.MOCode as Code,
  794. // a.InvCode,
  795. // b.InvName,
  796. // b.InvStd,
  797. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  798. // a.WhCode,
  799. // b.InvUnit,
  800. // a.ExtensionID
  801. // FROM
  802. // ICSMOPick a
  803. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  804. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  805. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  806. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  807. // #endregion
  808. // }
  809. // if (Type == "2")
  810. // {
  811. // return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
  812. // }
  813. // if (Type=="3")
  814. // {
  815. // #region 工单材料出库SQL
  816. // sqls = @" select
  817. // a.IssueCode as Code,
  818. // a.InvCode,
  819. // b.InvName,
  820. // b.InvStd,
  821. // b.InvUnit,
  822. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  823. // a.WhCode,
  824. // a.ExtensionID
  825. // FROM
  826. // ICSMOIssue a
  827. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  828. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  829. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  830. // #endregion
  831. // }
  832. // if (Type=="4")
  833. // {
  834. // #region 委外备料SQL
  835. // sqls = @" select
  836. // c.OOCode as Code,
  837. // a.InvCode,
  838. // b.InvName,
  839. // b.InvStd,
  840. // b.InvUnit,
  841. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  842. // a.WhCode,
  843. // a.ExtensionID
  844. // FROM
  845. // ICSOOPick a
  846. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  847. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  848. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  849. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  850. // #endregion
  851. // }
  852. // if (Type=="5")
  853. // {
  854. // #region 委外领料SQL
  855. // sqls = @" select
  856. // a.ApplyCode as Code,
  857. // a.InvCode,
  858. // b.InvName,
  859. // b.InvStd,
  860. //b.InvUnit,
  861. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  862. // a.WhCode,
  863. // a.ExtensionID
  864. // FROM
  865. // ICSOApply a
  866. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  867. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  868. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  869. // #endregion
  870. // }
  871. // if (Type=="6")
  872. // {
  873. // #region 委外材料出库SQL
  874. // sqls = @" select
  875. // a.IssueCode as Code,
  876. // a.InvCode,
  877. // b.InvName,
  878. // b.InvStd,
  879. //b.InvUnit,
  880. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  881. // a.WhCode,
  882. //a.ExtensionID
  883. // FROM
  884. // ICSOIssue a
  885. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  886. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  887. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  888. // #endregion
  889. // }
  890. // if (Type=="7")
  891. // {
  892. // #region 销售发货SQL
  893. // sqls = @" select
  894. // a.SDNCode as Code,
  895. // a.InvCode,
  896. // b.InvName,
  897. // b.InvStd,
  898. //b.InvUnit,
  899. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  900. // a.WhCode,
  901. //a.ExtensionID
  902. // FROM
  903. // ICSSDN a
  904. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  905. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  906. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  907. // #endregion
  908. // }
  909. // if (Type=="8")
  910. // {
  911. // #region 其它出库SQL
  912. // sqls = @" select
  913. // a.OutCode as Code,
  914. // a.InvCode,
  915. // b.InvName,
  916. // b.InvStd,
  917. // b.InvUnit,
  918. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  919. // a.WhCode,
  920. // a.ExtensionID
  921. // FROM
  922. // ICSOtherOut a
  923. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  924. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  925. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  926. // #endregion
  927. // }
  928. // if (Type == "9")
  929. // {
  930. // #region 借用SQL
  931. // sqls = @"select
  932. // a.BrrowCode as Code,
  933. // a.InvCode,
  934. // b.InvName,
  935. // b.InvStd,
  936. //b.InvUnit,
  937. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  938. // a.WhCode,
  939. //a.ExtensionID
  940. // FROM
  941. // ICSBrrow a
  942. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  943. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  944. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  945. // #endregion
  946. // }
  947. // if (Type == "10")
  948. // {
  949. // #region 物料调拨
  950. // sqls = @" select
  951. // a.TransferNO as Code,
  952. // a.InvCode,
  953. // b.InvName,
  954. // b.InvStd,
  955. //b.InvUnit,
  956. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  957. // a.FromWarehouseCode as WhCode,
  958. //a.ExtensionID
  959. // FROM
  960. // ICSTransfer a
  961. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  962. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  963. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  964. // #endregion
  965. // }
  966. // if (Type == "11")
  967. // {
  968. // #region 两步调出
  969. // sqls = @"select
  970. // a.OutCode as Code,
  971. // a.InvCode,
  972. // b.InvName,
  973. // b.InvStd,
  974. //b.InvUnit,
  975. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  976. // a.WHCode ,
  977. //a.ExtensionID
  978. // from ICSOtherOut a
  979. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  980. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  981. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  982. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  983. // #endregion
  984. // }
  985. // sqls = string.Format(sqls, ID,WorkPoint);
  986. // sql = string.Format(sql, sqls, WorkPoint);
  987. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  988. // DataTable dtCloned = table.Clone();
  989. // foreach (DataColumn col in dtCloned.Columns)
  990. // {
  991. // col.DataType = typeof(string);
  992. // }
  993. // foreach (DataRow row in table.Rows)
  994. // {
  995. // DataRow newrow = dtCloned.NewRow();
  996. // foreach (DataColumn column in dtCloned.Columns)
  997. // {
  998. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  999. // }
  1000. // dtCloned.Rows.Add(newrow);
  1001. // }
  1002. // if (Invmes.Rows.Count > 0)
  1003. // {
  1004. // dtCloned.Merge(Invmes, false);
  1005. // }
  1006. // return dtCloned;
  1007. // }
  1008. public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  1009. {
  1010. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1011. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1012. #region sql
  1013. #endregion
  1014. string sqls = "";
  1015. if (Type == "1")
  1016. {
  1017. #region 工单备料sql
  1018. sqls = @" SELECT
  1019. c.MOCode as Code,
  1020. a.InvCode,
  1021. b.InvName,
  1022. b.InvStd,
  1023. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1024. a.WhCode,
  1025. b.InvUnit,
  1026. a.ExtensionID
  1027. FROM
  1028. ICSMOPick a
  1029. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1030. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1031. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1032. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1033. #endregion
  1034. }
  1035. if (Type == "2")
  1036. {
  1037. sqls = @"select
  1038. a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1039. FROM
  1040. ICSMOApply a
  1041. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1042. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1043. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1044. }
  1045. if (Type == "3")
  1046. {
  1047. #region 工单材料出库SQL
  1048. sqls = @" select
  1049. a.IssueCode as Code,
  1050. a.InvCode,
  1051. b.InvName,
  1052. b.InvStd,
  1053. b.InvUnit,
  1054. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1055. a.WhCode,
  1056. a.ExtensionID
  1057. FROM
  1058. ICSMOIssue a
  1059. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1060. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1061. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1062. #endregion
  1063. }
  1064. if (Type == "4")
  1065. {
  1066. #region 委外备料SQL
  1067. sqls = @" select
  1068. c.OOCode as Code,
  1069. a.InvCode,
  1070. b.InvName,
  1071. b.InvStd,
  1072. b.InvUnit,
  1073. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1074. a.WhCode,
  1075. a.ExtensionID
  1076. FROM
  1077. ICSOOPick a
  1078. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1079. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1080. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1081. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  1082. #endregion
  1083. }
  1084. if (Type == "5")
  1085. {
  1086. #region 委外领料SQL
  1087. sqls = @"select
  1088. a.ApplyCode 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,a.ExtensionID
  1095. FROM
  1096. ICSOApply a
  1097. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1098. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1099. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1100. #endregion
  1101. }
  1102. if (Type == "6")
  1103. {
  1104. #region 委外材料出库SQL
  1105. sqls = @" select
  1106. a.IssueCode as Code,
  1107. a.InvCode,
  1108. b.InvName,
  1109. b.InvStd,
  1110. b.InvUnit,
  1111. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1112. a.WhCode,
  1113. a.ExtensionID
  1114. FROM
  1115. ICSOIssue a
  1116. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1117. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1118. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1119. #endregion
  1120. }
  1121. if (Type == "7")
  1122. {
  1123. #region 销售发货SQL
  1124. sqls = @" select
  1125. a.SDNCode as Code,
  1126. a.InvCode,
  1127. b.InvName,
  1128. b.InvStd,
  1129. b.InvUnit,
  1130. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1131. a.WhCode,
  1132. a.ExtensionID
  1133. FROM
  1134. ICSSDN a
  1135. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1136. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1137. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1138. #endregion
  1139. }
  1140. if (Type == "8")
  1141. {
  1142. #region 其它出库SQL
  1143. sqls = @" select
  1144. a.OutCode as Code,
  1145. a.InvCode,
  1146. b.InvName,
  1147. b.InvStd,
  1148. b.InvUnit,
  1149. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1150. a.WhCode,
  1151. a.ExtensionID
  1152. FROM
  1153. ICSOtherOut a
  1154. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1155. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1156. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1157. #endregion
  1158. }
  1159. if (Type == "9")
  1160. {
  1161. #region 借用SQL
  1162. sqls = @"select
  1163. a.BrrowCode as Code,
  1164. a.InvCode,
  1165. b.InvName,
  1166. b.InvStd,
  1167. b.InvUnit,
  1168. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1169. a.WhCode,
  1170. a.ExtensionID
  1171. FROM
  1172. ICSBrrow a
  1173. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1174. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1175. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1176. #endregion
  1177. }
  1178. if (Type == "10")
  1179. {
  1180. #region 物料调拨
  1181. sqls = @"select
  1182. a.TransferNO as Code,
  1183. a.InvCode,
  1184. b.InvName,
  1185. b.InvStd,
  1186. b.InvUnit,
  1187. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1188. a.FromWarehouseCode as WhCode,
  1189. a.ExtensionID
  1190. FROM
  1191. ICSTransfer a
  1192. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1193. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1194. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1195. #endregion
  1196. }
  1197. if (Type == "11")
  1198. {
  1199. #region 两步调出
  1200. sqls = @"select
  1201. a.OutCode as Code,
  1202. a.InvCode,
  1203. b.InvName,
  1204. b.InvStd,
  1205. b.InvUnit,
  1206. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1207. a.WHCode ,
  1208. a.ExtensionID
  1209. from ICSOtherOut a
  1210. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1211. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1212. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1213. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1214. #endregion
  1215. }
  1216. sqls = string.Format(sqls, ID, WorkPoint);
  1217. string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1218. c.Code,
  1219. c.InvCode,
  1220. c.InvName,
  1221. c.InvStd,
  1222. c.InvUnit,
  1223. FLOOR(c.iQuantity) AS iQuantity,
  1224. c.WHCode AS WarehouseCode,
  1225. d.LotNO,
  1226. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1227. d.LocationCode AS LocationCode,
  1228. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1229. FLOOR(f.QTYTotal) QTYTotal
  1230. FROM
  1231. ({sqls}) c
  1232. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  1233. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1234. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1235. and d.WorkPoint='{WorkPoint}' AND d.Quantity>0 ) d
  1236. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1237. 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
  1238. order by c.Code,c.InvCode,d.MTIME ";
  1239. var dataset = Repository().FindDataSetBySql(sql);
  1240. if (dataset.Tables.Count == 0)
  1241. return null;
  1242. DataTable table = dataset.Tables[0];
  1243. decimal qtyCount = 0;
  1244. bool remove = false;
  1245. List<int> removeList = new List<int>();
  1246. for (int i = 0; i < table.Rows.Count; i++)
  1247. {
  1248. if (i != 0
  1249. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  1250. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
  1251. )
  1252. {
  1253. qtyCount = 0;
  1254. remove = false;
  1255. }
  1256. if (remove)
  1257. {
  1258. removeList.Add(i);
  1259. }
  1260. else
  1261. {
  1262. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  1263. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1264. qtyCount += lotQty;
  1265. if (qtyCount >= orderQty)
  1266. {
  1267. remove = true;
  1268. }
  1269. }
  1270. }
  1271. if (removeList.Count > 0)
  1272. {
  1273. removeList.Reverse();
  1274. foreach (var item in removeList)
  1275. {
  1276. table.Rows.RemoveAt(item);
  1277. }
  1278. }
  1279. var result = ConvertCellToString(table);
  1280. if (Invmes.Rows.Count > 0)
  1281. {
  1282. result.Merge(Invmes, false);
  1283. }
  1284. return result;
  1285. }
  1286. /// <summary>
  1287. /// 工单领料推荐
  1288. /// </summary>
  1289. /// <param name="Id"></param>
  1290. /// <param name="workPoint"></param>
  1291. /// <returns></returns>
  1292. public DataTable GetICSMOPickMergeByWorkorder(string Id,string workPoint)
  1293. {
  1294. string sql = $@"SELECT row_number() over (partition by c.Code,c.InvCode order by c.Code,c.InvCode,d.MTIME) AS rowNo,
  1295. c.Code,
  1296. c.InvCode,
  1297. c.InvName,
  1298. c.InvStd,
  1299. c.InvUnit,
  1300. FLOOR(c.iQuantity) AS iQuantity,
  1301. d.WarehouseCode,
  1302. d.LotNO,
  1303. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1304. d.LocationCode LocationCode,
  1305. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1306. FLOOR(f.QTYTotal) QTYTotal
  1307. FROM
  1308. (select
  1309. a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
  1310. FROM
  1311. ICSMOApply a
  1312. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1313. WHERE a.ApplyCode in ({Id}) AND a.WorkPoint = '{workPoint}'
  1314. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID) c
  1315. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1316. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1317. and d.WorkPoint='{workPoint}' AND d.Quantity>0 ) d on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  1318. 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
  1319. order by c.Code,c.InvCode,d.MTIME";
  1320. var dataset = Repository().FindDataSetBySql(sql);
  1321. if (dataset.Tables.Count == 0)
  1322. return null;
  1323. DataTable table = dataset.Tables[0];
  1324. decimal qtyCount = 0;
  1325. bool remove = false;
  1326. List<int> removeList = new List<int>();
  1327. for (int i = 0; i < table.Rows.Count; i++)
  1328. {
  1329. if(i != 0
  1330. && !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i-1]["InvCode"].ToString()))
  1331. {
  1332. qtyCount = 0;
  1333. remove = false;
  1334. }
  1335. if (remove)
  1336. {
  1337. removeList.Add(i);
  1338. }
  1339. else
  1340. {
  1341. var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
  1342. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1343. qtyCount += lotQty;
  1344. if (qtyCount >= orderQty)
  1345. {
  1346. remove = true;
  1347. }
  1348. }
  1349. }
  1350. if(removeList.Count > 0)
  1351. {
  1352. removeList.Reverse();
  1353. foreach (var item in removeList)
  1354. {
  1355. table.Rows.RemoveAt(item);
  1356. }
  1357. }
  1358. var result = ConvertCellToString(table);
  1359. if (Invmes.Rows.Count > 0)
  1360. {
  1361. result.Merge(Invmes, false);
  1362. }
  1363. return result;
  1364. }
  1365. public DataTable ConvertCellToString(DataTable data)
  1366. {
  1367. DataTable dtCloned = data.Clone();
  1368. foreach (DataColumn col in dtCloned.Columns)
  1369. {
  1370. col.DataType = typeof(string);
  1371. }
  1372. foreach (DataRow row in data.Rows)
  1373. {
  1374. DataRow newrow = dtCloned.NewRow();
  1375. foreach (DataColumn column in dtCloned.Columns)
  1376. {
  1377. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1378. }
  1379. dtCloned.Rows.Add(newrow);
  1380. }
  1381. return dtCloned;
  1382. }
  1383. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1384. {
  1385. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1386. #region sql
  1387. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1388. c.MergeID,
  1389. c.Code,
  1390. c.InvCode,
  1391. c.InvName,
  1392. c.InvStd,
  1393. c.InvUnit,
  1394. FLOOR(c.iQuantity) AS iQuantity,
  1395. d.WarehouseCode,
  1396. d.LocationCode,
  1397. d.LotNO,
  1398. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1399. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1400. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1401. FROM
  1402. ({0}) c
  1403. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1404. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1405. 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
  1406. DECLARE @ItemCode VARCHAR(50),
  1407. @QTY DECIMAL(18,3),
  1408. @ItemCodeCurrent VARCHAR(50),
  1409. @QTYCurrent DECIMAL(18,3),
  1410. @iQuantityCurrent DECIMAL(18,3),
  1411. @CanDelete BIT,
  1412. @Row INT,
  1413. @rowCurrent INT
  1414. SET @Row = @@rowcount
  1415. SET @rowCurrent=1
  1416. SET @CanDelete=0
  1417. SET @ItemCode=''
  1418. WHILE @rowCurrent<=@Row
  1419. BEGIN
  1420. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1421. PRINT(@rowCurrent)
  1422. IF @ItemCode<>@ItemCodeCurrent
  1423. BEGIN
  1424. SET @ItemCode=@ItemCodeCurrent
  1425. SET @QTY=0
  1426. SET @CanDelete=0
  1427. END
  1428. IF @CanDelete=1
  1429. BEGIN
  1430. DELETE FROM #temp WHERE rowNo=@rowCurrent
  1431. SET @rowCurrent += 1
  1432. CONTINUE
  1433. END
  1434. SET @QTY += @QTYCurrent
  1435. IF @QTY>=@iQuantityCurrent
  1436. BEGIN
  1437. SET @CanDelete=1
  1438. END
  1439. SET @rowCurrent += 1
  1440. END
  1441. SELECT * FROM #temp
  1442. DROP TABLE #temp
  1443. ";
  1444. #endregion
  1445. string sqls = "";
  1446. if (Type == "1")
  1447. {
  1448. #region 工单备料sql
  1449. sqls = @" select
  1450. x.MergeID,
  1451. c.MOCode as Code,
  1452. a.InvCode,
  1453. b.InvName,
  1454. b.InvStd,
  1455. b.InvUnit,
  1456. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1457. a.WhCode,
  1458. a.ExtensionID
  1459. FROM
  1460. ICSMOPick a
  1461. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1462. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1463. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1464. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1465. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1466. #endregion
  1467. }
  1468. if (Type == "2")
  1469. {
  1470. #region 工单领料SQL
  1471. sqls = @" select
  1472. x.MergeID,
  1473. a.ApplyCode as Code,
  1474. a.InvCode,
  1475. b.InvName,
  1476. b.InvStd,
  1477. b.InvUnit,
  1478. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1479. a.WhCode,
  1480. a.ExtensionID
  1481. FROM
  1482. ICSMOApply a
  1483. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1484. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1485. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  1486. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1487. #endregion
  1488. }
  1489. if (Type == "3")
  1490. {
  1491. #region 工单材料出库SQL
  1492. sqls = @" select
  1493. x.MergeID,
  1494. a.IssueCode as Code,
  1495. a.InvCode,
  1496. b.InvName,
  1497. b.InvStd,
  1498. b.InvUnit,
  1499. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1500. a.WhCode,
  1501. a.ExtensionID
  1502. FROM
  1503. ICSMOIssue a
  1504. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1505. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1506. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1507. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1508. #endregion
  1509. }
  1510. if (Type == "4")
  1511. {
  1512. #region 委外备料SQL
  1513. sqls = @" select
  1514. x.MergeID,
  1515. c.OOCode as Code,
  1516. a.InvCode,
  1517. b.InvName,
  1518. b.InvStd,
  1519. b.InvUnit,
  1520. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1521. a.WhCode,
  1522. a.ExtensionID
  1523. FROM
  1524. ICSOOPick a
  1525. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1526. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1527. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1528. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1529. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  1530. #endregion
  1531. }
  1532. if (Type == "5")
  1533. {
  1534. #region 委外领料SQL
  1535. sqls = @" select
  1536. x.MergeID,
  1537. a.ApplyCode as Code,
  1538. a.InvCode,
  1539. b.InvName,
  1540. b.InvStd,
  1541. b.InvUnit,
  1542. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1543. a.WhCode,
  1544. a.ExtensionID
  1545. FROM
  1546. ICSOApply a
  1547. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1548. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1549. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1550. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1551. #endregion
  1552. }
  1553. if (Type == "6")
  1554. {
  1555. #region 委外材料出库SQL
  1556. sqls = @" select
  1557. x.MergeID,
  1558. a.IssueCode as Code,
  1559. a.InvCode,
  1560. b.InvName,
  1561. b.InvStd,
  1562. b.InvUnit,
  1563. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1564. a.WhCode,
  1565. a.ExtensionID
  1566. FROM
  1567. ICSOIssue a
  1568. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1569. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1570. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1571. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1572. #endregion
  1573. }
  1574. if (Type == "7")
  1575. {
  1576. #region 销售发货SQL
  1577. sqls = @" select
  1578. x.MergeID,
  1579. a.SDNCode as Code,
  1580. a.InvCode,
  1581. b.InvName,
  1582. b.InvStd,
  1583. b.InvUnit,
  1584. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1585. a.WhCode,
  1586. a.ExtensionID
  1587. FROM
  1588. ICSSDN a
  1589. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1590. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1591. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1592. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1593. #endregion
  1594. }
  1595. if (Type == "8")
  1596. {
  1597. #region 其它出库SQL
  1598. sqls = @" select
  1599. x.MergeID,
  1600. a.OutCode as Code,
  1601. a.InvCode,
  1602. b.InvName,
  1603. b.InvStd,
  1604. b.InvUnit,
  1605. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1606. a.WhCode,
  1607. a.ExtensionID
  1608. FROM
  1609. ICSOtherOut a
  1610. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1611. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1612. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1613. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1614. #endregion
  1615. }
  1616. if (Type == "9")
  1617. {
  1618. #region 借用SQL
  1619. sqls = @" select
  1620. x.MergeID,
  1621. a.BrrowCode as Code,
  1622. a.InvCode,
  1623. b.InvName,
  1624. b.InvStd,
  1625. b.InvUnit,
  1626. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1627. a.WhCode,
  1628. a.ExtensionID
  1629. FROM
  1630. ICSBrrow a
  1631. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1632. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1633. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1634. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1635. #endregion
  1636. }
  1637. if (Type == "10")
  1638. {
  1639. #region 物料调拨
  1640. sqls = @" select
  1641. x.MergeID,
  1642. a.TransferNO as Code,
  1643. a.InvCode,
  1644. b.InvName,
  1645. b.InvStd,
  1646. b.InvUnit,
  1647. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1648. a.FromWarehouseCode as WhCode,
  1649. a.ExtensionID
  1650. FROM
  1651. ICSTransfer a
  1652. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1653. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1654. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1655. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  1656. #endregion
  1657. }
  1658. if (Type == "10")
  1659. {
  1660. #region 两步调出
  1661. sqls = @"select
  1662. x.MergeID,
  1663. a.OutCode as Code,
  1664. a.InvCode,
  1665. b.InvName,
  1666. b.InvStd,
  1667. b.InvUnit,
  1668. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1669. a.WHCode as WhCode,
  1670. a.ExtensionID
  1671. FROM
  1672. ICSOtherOut a
  1673. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1674. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1675. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1676. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1677. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  1678. #endregion
  1679. }
  1680. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  1681. sql = string.Format(sql, sqls, WorkPoint);
  1682. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1683. DataTable dtCloned = table.Clone();
  1684. foreach (DataColumn col in dtCloned.Columns)
  1685. {
  1686. col.DataType = typeof(string);
  1687. }
  1688. foreach (DataRow row in table.Rows)
  1689. {
  1690. DataRow newrow = dtCloned.NewRow();
  1691. foreach (DataColumn column in dtCloned.Columns)
  1692. {
  1693. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1694. }
  1695. dtCloned.Rows.Add(newrow);
  1696. }
  1697. if (Invmes.Rows.Count > 0)
  1698. {
  1699. dtCloned.Merge(Invmes, false);
  1700. }
  1701. return dtCloned;
  1702. }
  1703. public string MergeMaterial(string keyValue,string Type)
  1704. {
  1705. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1706. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1707. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1708. string msg = "";
  1709. string sql = string.Empty;
  1710. keyValue = keyValue.TrimEnd(',');
  1711. DateTime time = DateTime.Now;
  1712. string Tday = time.ToString("yyyyMMdd");
  1713. string sqls = string.Format(@"SELECT MAX(A.SourceID) AS SourceID FROM ICSMOPickMerge A WHERE A.SourceID LIKE '{0}%' AND LEN(a.SourceID) = 13", Tday);
  1714. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  1715. string MergeID = "";
  1716. Int64 Merge_ID = 0;
  1717. DataTable dts = ds.Tables[0];
  1718. if (dts != null && dts.Rows.Count > 0)
  1719. {
  1720. string lot = dts.Rows[0]["SourceID"].ToString();
  1721. if (!string.IsNullOrWhiteSpace(lot))
  1722. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  1723. }
  1724. MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  1725. if (Type == "1")//工单备料
  1726. {
  1727. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1728. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1729. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1730. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  1731. where a.MOCode in ({5})
  1732. ";
  1733. }
  1734. if (Type == "2")//工单发料
  1735. {
  1736. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1737. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1738. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1739. from ICSMOApply a
  1740. where a.ApplyCode in ({5})";
  1741. }
  1742. if (Type == "3")//材料出库
  1743. {
  1744. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1745. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1746. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1747. from ICSMOIssue a
  1748. where a.IssueCode in ({5}) ";
  1749. }
  1750. if (Type == "4")//委外备料
  1751. {
  1752. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1753. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1754. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1755. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  1756. where a.OOCode in ({5})";
  1757. }
  1758. if (Type == "5")//委外领料
  1759. {
  1760. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1761. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1762. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1763. from ICSOApply a
  1764. where a.ApplyCode in ({5})";
  1765. }
  1766. if (Type == "6")//委外材料出库
  1767. {
  1768. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1769. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1770. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1771. from ICSOIssue a
  1772. where a.IssueCode in ('{5}')";
  1773. }
  1774. if (Type == "7")//销售发货
  1775. {
  1776. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1777. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1778. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1779. from ICSOIssue a
  1780. where a.IssueCode in ({5})";
  1781. }
  1782. if (Type == "8")//其它出库
  1783. {
  1784. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1785. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1786. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1787. from ICSSDN a
  1788. where a.SDNCode in ({5})";
  1789. }
  1790. if (Type == "9")//借用单
  1791. {
  1792. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1793. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1794. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1795. from ICSOtherOut a
  1796. where a.OutCode in ({5})";
  1797. }
  1798. if (Type == "10")//物料调拨
  1799. {
  1800. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1801. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1802. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1803. from ICSTransfer a
  1804. where a.TransferNO in ({5})
  1805. ";
  1806. }
  1807. if (Type == "11")//两步调出
  1808. {
  1809. sql += @" INSERT INTO dbo.ICSMOPickMerge
  1810. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1811. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1812. from ICSOtherOut a
  1813. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1814. where a.OutCode in ({5})
  1815. ";
  1816. }
  1817. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, keyValue);
  1818. try
  1819. {
  1820. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  1821. {
  1822. }
  1823. else
  1824. {
  1825. msg = "新增失败";
  1826. }
  1827. }
  1828. catch (Exception ex)
  1829. {
  1830. throw new Exception(ex.Message);
  1831. }
  1832. return msg;
  1833. }
  1834. public string CheckQty(string objArr)
  1835. {
  1836. objArr= objArr.TrimEnd(',');
  1837. string sql = @"select * from ICSMOPickMerge a
  1838. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  1839. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  1840. where MOCode in ({0})";
  1841. sql = string.Format(sql, objArr);
  1842. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  1843. if (dt != null&&dt.Rows.Count>0)
  1844. {
  1845. return "1";
  1846. }
  1847. return "0";
  1848. }
  1849. }
  1850. }