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

1620 lines
80 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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 = '1'");
  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. #region sql
  728. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  729. c.Code,
  730. c.InvCode,
  731. c.InvName,
  732. c.InvStd,
  733. c.InvUnit,
  734. FLOOR(c.iQuantity) AS iQuantity,
  735. d.WarehouseCode,
  736. d.LocationCode,
  737. m.LotNO,
  738. (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
  739. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  740. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  741. FROM
  742. ({0}) c
  743. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  744. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  745. 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
  746. DECLARE @ItemCode VARCHAR(50),
  747. @QTY DECIMAL(18,3),
  748. @ItemCodeCurrent VARCHAR(50),
  749. @Lotno VARCHAR(50),
  750. @QTYCurrent DECIMAL(18,3),
  751. @iQuantityCurrent DECIMAL(18,3),
  752. @CanDelete BIT,
  753. @Row INT,
  754. @rowCurrent INT
  755. SET @Row = @@rowcount
  756. SET @rowCurrent=1
  757. SET @CanDelete=0
  758. SET @ItemCode=''
  759. SET @Lotno = ''
  760. WHILE @rowCurrent<=@Row
  761. BEGIN
  762. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
  763. PRINT(@rowCurrent)
  764. IF @ItemCode<>@ItemCodeCurrent
  765. BEGIN
  766. SET @ItemCode=@ItemCodeCurrent
  767. SET @QTY=0
  768. SET @CanDelete=0
  769. END
  770. IF @CanDelete=1
  771. BEGIN
  772. DELETE FROM #temp WHERE rowNo=@rowCurrent
  773. SET @rowCurrent += 1
  774. CONTINUE
  775. END
  776. SET @QTY += @QTYCurrent
  777. IF @LotNo is null or @QTY>=@iQuantityCurrent
  778. BEGIN
  779. SET @CanDelete=1
  780. END
  781. SET @rowCurrent += 1
  782. END
  783. SELECT * FROM #temp
  784. DROP TABLE #temp
  785. ";
  786. #endregion
  787. string sqls = "";
  788. if (Type=="1")
  789. {
  790. #region 工单备料sql
  791. sqls = @" SELECT
  792. c.MOCode as Code,
  793. a.InvCode,
  794. b.InvName,
  795. b.InvStd,
  796. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  797. a.WhCode,
  798. b.InvUnit,
  799. a.ExtensionID
  800. FROM
  801. ICSMOPick a
  802. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  803. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  804. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  805. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  806. #endregion
  807. }
  808. if (Type == "2")
  809. {
  810. #region 工单领料SQL
  811. sqls = @" select
  812. a.ApplyCode as Code,
  813. a.InvCode,
  814. b.InvName,
  815. b.InvStd,
  816. b.InvUnit,
  817. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  818. a.WhCode,
  819. a.ExtensionID
  820. FROM
  821. ICSMOApply a
  822. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  823. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  824. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  825. #endregion
  826. }
  827. if (Type=="3")
  828. {
  829. #region 工单材料出库SQL
  830. sqls = @" select
  831. a.IssueCode as Code,
  832. a.InvCode,
  833. b.InvName,
  834. b.InvStd,
  835. b.InvUnit,
  836. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  837. a.WhCode,
  838. a.ExtensionID
  839. FROM
  840. ICSMOIssue a
  841. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  842. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  843. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  844. #endregion
  845. }
  846. if (Type=="4")
  847. {
  848. #region 委外备料SQL
  849. sqls = @" select
  850. c.OOCode as Code,
  851. a.InvCode,
  852. b.InvName,
  853. b.InvStd,
  854. b.InvUnit,
  855. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  856. a.WhCode,
  857. a.ExtensionID
  858. FROM
  859. ICSOOPick a
  860. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  861. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  862. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  863. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  864. #endregion
  865. }
  866. if (Type=="5")
  867. {
  868. #region 委外领料SQL
  869. sqls = @" select
  870. a.ApplyCode as Code,
  871. a.InvCode,
  872. b.InvName,
  873. b.InvStd,
  874. b.InvUnit,
  875. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  876. a.WhCode,
  877. a.ExtensionID
  878. FROM
  879. ICSOApply a
  880. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  881. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  882. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  883. #endregion
  884. }
  885. if (Type=="6")
  886. {
  887. #region 委外材料出库SQL
  888. sqls = @" select
  889. a.IssueCode as Code,
  890. a.InvCode,
  891. b.InvName,
  892. b.InvStd,
  893. b.InvUnit,
  894. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  895. a.WhCode,
  896. a.ExtensionID
  897. FROM
  898. ICSOIssue a
  899. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  900. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  901. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  902. #endregion
  903. }
  904. if (Type=="7")
  905. {
  906. #region 销售发货SQL
  907. sqls = @" select
  908. a.SDNCode as Code,
  909. a.InvCode,
  910. b.InvName,
  911. b.InvStd,
  912. b.InvUnit,
  913. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  914. a.WhCode,
  915. a.ExtensionID
  916. FROM
  917. ICSSDN a
  918. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  919. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  920. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  921. #endregion
  922. }
  923. if (Type=="8")
  924. {
  925. #region 其它出库SQL
  926. sqls = @" select
  927. a.OutCode as Code,
  928. a.InvCode,
  929. b.InvName,
  930. b.InvStd,
  931. b.InvUnit,
  932. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  933. a.WhCode,
  934. a.ExtensionID
  935. FROM
  936. ICSOtherOut a
  937. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  938. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  939. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  940. #endregion
  941. }
  942. if (Type == "9")
  943. {
  944. #region 借用SQL
  945. sqls = @"select
  946. a.BrrowCode as Code,
  947. a.InvCode,
  948. b.InvName,
  949. b.InvStd,
  950. b.InvUnit,
  951. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  952. a.WhCode,
  953. a.ExtensionID
  954. FROM
  955. ICSBrrow a
  956. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  957. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  958. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  959. #endregion
  960. }
  961. if (Type == "10")
  962. {
  963. #region 物料调拨
  964. sqls = @" select
  965. a.TransferNO as Code,
  966. a.InvCode,
  967. b.InvName,
  968. b.InvStd,
  969. b.InvUnit,
  970. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  971. a.FromWarehouseCode as WhCode,
  972. a.ExtensionID
  973. FROM
  974. ICSTransfer a
  975. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  976. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  977. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  978. #endregion
  979. }
  980. if (Type == "11")
  981. {
  982. #region 两步调出
  983. sqls = @"select
  984. a.OutCode as Code,
  985. a.InvCode,
  986. b.InvName,
  987. b.InvStd,
  988. b.InvUnit,
  989. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  990. a.WHCode ,
  991. a.ExtensionID
  992. from ICSOtherOut a
  993. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  994. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  995. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  996. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  997. #endregion
  998. }
  999. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID)?"''":ID.TrimEnd(','),WorkPoint);
  1000. sql = string.Format(sql, sqls, WorkPoint);
  1001. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1002. DataTable dtCloned = table.Clone();
  1003. foreach (DataColumn col in dtCloned.Columns)
  1004. {
  1005. col.DataType = typeof(string);
  1006. }
  1007. foreach (DataRow row in table.Rows)
  1008. {
  1009. DataRow newrow = dtCloned.NewRow();
  1010. foreach (DataColumn column in dtCloned.Columns)
  1011. {
  1012. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1013. }
  1014. dtCloned.Rows.Add(newrow);
  1015. }
  1016. if (Invmes.Rows.Count > 0)
  1017. {
  1018. dtCloned.Merge(Invmes, false);
  1019. }
  1020. return dtCloned;
  1021. }
  1022. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1023. {
  1024. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1025. #region sql
  1026. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1027. c.MergeID,
  1028. c.Code,
  1029. c.InvCode,
  1030. c.InvName,
  1031. c.InvStd,
  1032. c.InvUnit,
  1033. FLOOR(c.iQuantity) AS iQuantity,
  1034. d.WarehouseCode,
  1035. d.LocationCode,
  1036. d.LotNO,
  1037. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1038. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1039. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1040. FROM
  1041. ({0}) c
  1042. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1043. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1044. 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
  1045. DECLARE @ItemCode VARCHAR(50),
  1046. @QTY DECIMAL(18,3),
  1047. @ItemCodeCurrent VARCHAR(50),
  1048. @QTYCurrent DECIMAL(18,3),
  1049. @iQuantityCurrent DECIMAL(18,3),
  1050. @CanDelete BIT,
  1051. @Row INT,
  1052. @rowCurrent INT
  1053. SET @Row = @@rowcount
  1054. SET @rowCurrent=1
  1055. SET @CanDelete=0
  1056. SET @ItemCode=''
  1057. WHILE @rowCurrent<=@Row
  1058. BEGIN
  1059. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1060. PRINT(@rowCurrent)
  1061. IF @ItemCode<>@ItemCodeCurrent
  1062. BEGIN
  1063. SET @ItemCode=@ItemCodeCurrent
  1064. SET @QTY=0
  1065. SET @CanDelete=0
  1066. END
  1067. IF @CanDelete=1
  1068. BEGIN
  1069. DELETE FROM #temp WHERE rowNo=@rowCurrent
  1070. SET @rowCurrent += 1
  1071. CONTINUE
  1072. END
  1073. SET @QTY += @QTYCurrent
  1074. IF @QTY>=@iQuantityCurrent
  1075. BEGIN
  1076. SET @CanDelete=1
  1077. END
  1078. SET @rowCurrent += 1
  1079. END
  1080. SELECT * FROM #temp
  1081. DROP TABLE #temp
  1082. ";
  1083. #endregion
  1084. string sqls = "";
  1085. if (Type == "1")
  1086. {
  1087. #region 工单备料sql
  1088. sqls = @" select
  1089. x.MergeID,
  1090. c.MOCode as Code,
  1091. a.InvCode,
  1092. b.InvName,
  1093. b.InvStd,
  1094. b.InvUnit,
  1095. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1096. a.WhCode,
  1097. a.ExtensionID
  1098. FROM
  1099. ICSMOPick a
  1100. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1101. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1102. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1103. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1104. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1105. #endregion
  1106. }
  1107. if (Type == "2")
  1108. {
  1109. #region 工单领料SQL
  1110. sqls = @" select
  1111. x.MergeID,
  1112. a.ApplyCode as Code,
  1113. a.InvCode,
  1114. b.InvName,
  1115. b.InvStd,
  1116. b.InvUnit,
  1117. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1118. a.WhCode,
  1119. a.ExtensionID
  1120. FROM
  1121. ICSMOApply a
  1122. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1123. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1124. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  1125. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1126. #endregion
  1127. }
  1128. if (Type == "3")
  1129. {
  1130. #region 工单材料出库SQL
  1131. sqls = @" select
  1132. x.MergeID,
  1133. a.IssueCode as Code,
  1134. a.InvCode,
  1135. b.InvName,
  1136. b.InvStd,
  1137. b.InvUnit,
  1138. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1139. a.WhCode,
  1140. a.ExtensionID
  1141. FROM
  1142. ICSMOIssue a
  1143. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1144. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1145. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1146. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1147. #endregion
  1148. }
  1149. if (Type == "4")
  1150. {
  1151. #region 委外备料SQL
  1152. sqls = @" select
  1153. x.MergeID,
  1154. c.OOCode as Code,
  1155. a.InvCode,
  1156. b.InvName,
  1157. b.InvStd,
  1158. b.InvUnit,
  1159. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1160. a.WhCode,
  1161. a.ExtensionID
  1162. FROM
  1163. ICSOOPick a
  1164. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1165. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1166. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1167. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1168. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  1169. #endregion
  1170. }
  1171. if (Type == "5")
  1172. {
  1173. #region 委外领料SQL
  1174. sqls = @" select
  1175. x.MergeID,
  1176. a.ApplyCode as Code,
  1177. a.InvCode,
  1178. b.InvName,
  1179. b.InvStd,
  1180. b.InvUnit,
  1181. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1182. a.WhCode,
  1183. a.ExtensionID
  1184. FROM
  1185. ICSOApply a
  1186. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1187. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1188. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1189. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1190. #endregion
  1191. }
  1192. if (Type == "6")
  1193. {
  1194. #region 委外材料出库SQL
  1195. sqls = @" select
  1196. x.MergeID,
  1197. a.IssueCode as Code,
  1198. a.InvCode,
  1199. b.InvName,
  1200. b.InvStd,
  1201. b.InvUnit,
  1202. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1203. a.WhCode,
  1204. a.ExtensionID
  1205. FROM
  1206. ICSOIssue a
  1207. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1208. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1209. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1210. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1211. #endregion
  1212. }
  1213. if (Type == "7")
  1214. {
  1215. #region 销售发货SQL
  1216. sqls = @" select
  1217. x.MergeID,
  1218. a.SDNCode as Code,
  1219. a.InvCode,
  1220. b.InvName,
  1221. b.InvStd,
  1222. b.InvUnit,
  1223. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1224. a.WhCode,
  1225. a.ExtensionID
  1226. FROM
  1227. ICSSDN a
  1228. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1229. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1230. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1231. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1232. #endregion
  1233. }
  1234. if (Type == "8")
  1235. {
  1236. #region 其它出库SQL
  1237. sqls = @" select
  1238. x.MergeID,
  1239. a.OutCode as Code,
  1240. a.InvCode,
  1241. b.InvName,
  1242. b.InvStd,
  1243. b.InvUnit,
  1244. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1245. a.WhCode,
  1246. a.ExtensionID
  1247. FROM
  1248. ICSOtherOut a
  1249. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1250. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1251. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1252. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1253. #endregion
  1254. }
  1255. if (Type == "9")
  1256. {
  1257. #region 借用SQL
  1258. sqls = @" select
  1259. x.MergeID,
  1260. a.BrrowCode as Code,
  1261. a.InvCode,
  1262. b.InvName,
  1263. b.InvStd,
  1264. b.InvUnit,
  1265. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1266. a.WhCode,
  1267. a.ExtensionID
  1268. FROM
  1269. ICSBrrow a
  1270. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1271. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1272. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1273. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1274. #endregion
  1275. }
  1276. if (Type == "10")
  1277. {
  1278. #region 物料调拨
  1279. sqls = @" select
  1280. x.MergeID,
  1281. a.TransferNO as Code,
  1282. a.InvCode,
  1283. b.InvName,
  1284. b.InvStd,
  1285. b.InvUnit,
  1286. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1287. a.FromWarehouseCode as WhCode,
  1288. a.ExtensionID
  1289. FROM
  1290. ICSTransfer a
  1291. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1292. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1293. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1294. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  1295. #endregion
  1296. }
  1297. if (Type == "10")
  1298. {
  1299. #region 两步调出
  1300. sqls = @"select
  1301. x.MergeID,
  1302. a.OutCode as Code,
  1303. a.InvCode,
  1304. b.InvName,
  1305. b.InvStd,
  1306. b.InvUnit,
  1307. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1308. a.WHCode as WhCode,
  1309. a.ExtensionID
  1310. FROM
  1311. ICSOtherOut a
  1312. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1313. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1314. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1315. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1316. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  1317. #endregion
  1318. }
  1319. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  1320. sql = string.Format(sql, sqls, WorkPoint);
  1321. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1322. DataTable dtCloned = table.Clone();
  1323. foreach (DataColumn col in dtCloned.Columns)
  1324. {
  1325. col.DataType = typeof(string);
  1326. }
  1327. foreach (DataRow row in table.Rows)
  1328. {
  1329. DataRow newrow = dtCloned.NewRow();
  1330. foreach (DataColumn column in dtCloned.Columns)
  1331. {
  1332. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1333. }
  1334. dtCloned.Rows.Add(newrow);
  1335. }
  1336. if (Invmes.Rows.Count > 0)
  1337. {
  1338. dtCloned.Merge(Invmes, false);
  1339. }
  1340. return dtCloned;
  1341. }
  1342. public string MergeMaterial(string keyValue,string Type)
  1343. {
  1344. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1345. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1346. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1347. string msg = "";
  1348. string sql = string.Empty;
  1349. keyValue = keyValue.TrimEnd(',');
  1350. DateTime time = DateTime.Now;
  1351. string Tday = time.ToString("yyyyMMdd");
  1352. string sqls = string.Format(@"SELECT MAX(A.SourceID) AS SourceID FROM ICSMOPickMerge A WHERE A.SourceID LIKE '{0}%' AND LEN(a.SourceID) = 13", Tday);
  1353. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  1354. string MergeID = "";
  1355. Int64 Merge_ID = 0;
  1356. DataTable dts = ds.Tables[0];
  1357. if (dts != null && dts.Rows.Count > 0)
  1358. {
  1359. string lot = dts.Rows[0]["SourceID"].ToString();
  1360. if (!string.IsNullOrWhiteSpace(lot))
  1361. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  1362. }
  1363. MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  1364. if (Type == "1")//工单备料
  1365. {
  1366. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1367. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1368. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1369. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  1370. where a.MOCode in ({5})
  1371. ";
  1372. }
  1373. if (Type == "2")//工单发料
  1374. {
  1375. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1376. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1377. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1378. from ICSMOApply a
  1379. where a.ApplyCode in ({5})";
  1380. }
  1381. if (Type == "3")//材料出库
  1382. {
  1383. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1384. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1385. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1386. from ICSMOIssue a
  1387. where a.IssueCode in ({5}) ";
  1388. }
  1389. if (Type == "4")//委外备料
  1390. {
  1391. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1392. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1393. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1394. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  1395. where a.OOCode in ({5})";
  1396. }
  1397. if (Type == "5")//委外领料
  1398. {
  1399. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1400. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1401. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1402. from ICSOApply a
  1403. where a.ApplyCode in ({5})";
  1404. }
  1405. if (Type == "6")//委外材料出库
  1406. {
  1407. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1408. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1409. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1410. from ICSOIssue a
  1411. where a.IssueCode in ('{5}')";
  1412. }
  1413. if (Type == "7")//销售发货
  1414. {
  1415. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1416. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1417. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1418. from ICSOIssue a
  1419. where a.IssueCode in ({5})";
  1420. }
  1421. if (Type == "8")//其它出库
  1422. {
  1423. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1424. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1425. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1426. from ICSSDN a
  1427. where a.SDNCode in ({5})";
  1428. }
  1429. if (Type == "9")//借用单
  1430. {
  1431. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1432. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1433. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1434. from ICSOtherOut a
  1435. where a.OutCode in ({5})";
  1436. }
  1437. if (Type == "10")//物料调拨
  1438. {
  1439. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1440. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1441. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1442. from ICSTransfer a
  1443. where a.TransferNO in ({5})
  1444. ";
  1445. }
  1446. if (Type == "11")//两步调出
  1447. {
  1448. sql += @" INSERT INTO dbo.ICSMOPickMerge
  1449. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1450. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1451. from ICSOtherOut a
  1452. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1453. where a.OutCode in ({5})
  1454. ";
  1455. }
  1456. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, keyValue);
  1457. try
  1458. {
  1459. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  1460. {
  1461. }
  1462. else
  1463. {
  1464. msg = "新增失败";
  1465. }
  1466. }
  1467. catch (Exception ex)
  1468. {
  1469. throw new Exception(ex.Message);
  1470. }
  1471. return msg;
  1472. }
  1473. public string CheckQty(string objArr)
  1474. {
  1475. objArr= objArr.TrimEnd(',');
  1476. string sql = @"select * from ICSMOPickMerge a
  1477. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  1478. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  1479. where MOCode in ({0})";
  1480. sql = string.Format(sql, objArr);
  1481. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  1482. if (dt != null&&dt.Rows.Count>0)
  1483. {
  1484. return "1";
  1485. }
  1486. return "0";
  1487. }
  1488. }
  1489. }