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

1625 lines
78 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
  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 b.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. string sql = "";
  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. sql = @"
  102. select a.ApplyCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  103. case when max(e.SourceID) is null then '' else '' end as IsNew,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  104. from ICSMOApply a
  105. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  106. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  107. where a.WorkPoint='{0}'
  108. group by a.ApplyCode, a.WorkPoint,a.CreateDateTime,a.createperson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  109. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  110. sql = string.Format(sql, WorkPoint);
  111. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  112. #endregion
  113. if (!string.IsNullOrWhiteSpace(queryJson))
  114. {
  115. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  116. {
  117. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  118. }
  119. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  120. {
  121. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  122. }
  123. }
  124. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  125. }
  126. //工单领料(发料申请)子表查询
  127. public DataTable GetSubGridJson2(string Code)
  128. {
  129. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  130. DataTable dt = new DataTable();
  131. //var queryParam = queryJson.ToJObject();
  132. List<DbParameter> parameter = new List<DbParameter>();
  133. 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,
  134. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  135. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  136. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  137. from ICSMOApply a
  138. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  139. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  140. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  141. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  142. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  143. sql = string.Format(sql, Code, WorkPoint);
  144. return Repository().FindTableBySql(sql.ToString());
  145. }
  146. //工单材料出库(材料出库)
  147. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  148. {
  149. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  150. DataTable dt = new DataTable();
  151. var queryParam = queryJson.ToJObject();
  152. List<DbParameter> parameter = new List<DbParameter>();
  153. string sql = "";
  154. #region [SQL]
  155. // 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,
  156. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  157. // from ICSMOIssue a
  158. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  159. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  160. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  161. // sql += " WHERE 1=1 and e.ID is null";
  162. sql = @"select a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,
  163. case when max(e.SourceID) is null then '' else '' end as IsNew
  164. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  165. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  166. from ICSMOIssue a
  167. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  168. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  169. where a.WorkPoint='{0}'
  170. group by a.IssueCode, a.CreateDateTime,a.createperson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  171. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  172. sql = string.Format(sql, WorkPoint);
  173. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  174. #endregion
  175. if (!string.IsNullOrWhiteSpace(queryJson))
  176. {
  177. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  178. {
  179. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  180. }
  181. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  182. {
  183. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  184. }
  185. }
  186. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  187. {
  188. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  189. }
  190. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  191. }
  192. //工单材料出库(材料出库)子表查询
  193. public DataTable GetSubGridJson3(string Code)
  194. {
  195. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  196. DataTable dt = new DataTable();
  197. //var queryParam = queryJson.ToJObject();
  198. List<DbParameter> parameter = new List<DbParameter>();
  199. 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,
  200. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  201. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  202. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  203. from ICSMOIssue a
  204. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  205. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  206. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  207. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  208. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  209. sql = string.Format(sql, Code, WorkPoint);
  210. return Repository().FindTableBySql(sql.ToString());
  211. }
  212. //委外备料(委外备料)
  213. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  214. {
  215. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  216. DataTable dt = new DataTable();
  217. var queryParam = queryJson.ToJObject();
  218. List<DbParameter> parameter = new List<DbParameter>();
  219. string sql = "";
  220. #region [SQL]
  221. sql = @"select b.OOCode as Code, b.CreateDateTime as MTIME,b.CreatePerson as MUSER,
  222. case when max(e.SourceID) is null then '' else '' end as IsNew
  223. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  224. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  225. from ICSOOPick a
  226. inner join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  227. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  228. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  229. WHERE b.WorkPoint='{0}'
  230. group by b.OOCode,b.CreateDateTime,b.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  231. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  232. sql = string.Format(sql, WorkPoint);
  233. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  234. #endregion
  235. if (!string.IsNullOrWhiteSpace(queryJson))
  236. {
  237. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  238. {
  239. sql += " and a.OOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  240. }
  241. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  242. {
  243. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  244. }
  245. }
  246. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  247. {
  248. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  249. }
  250. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  251. }
  252. //委外备料(委外备料)子表查询
  253. public DataTable GetSubGridJson4(string Code)
  254. {
  255. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  256. DataTable dt = new DataTable();
  257. //var queryParam = queryJson.ToJObject();
  258. List<DbParameter> parameter = new List<DbParameter>();
  259. 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,
  260. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  261. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  262. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  263. from ICSOOPick a
  264. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  265. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  266. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  267. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  268. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  269. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  270. sql = string.Format(sql, Code, WorkPoint);
  271. return Repository().FindTableBySql(sql.ToString());
  272. }
  273. //委外领料(委外发料申请)
  274. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  275. {
  276. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  277. DataTable dt = new DataTable();
  278. var queryParam = queryJson.ToJObject();
  279. List<DbParameter> parameter = new List<DbParameter>();
  280. string sql = "";
  281. #region [SQL]
  282. // 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,
  283. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  284. // from ICSOApply a
  285. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  286. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  287. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  288. // sql += " WHERE 1=1 and e.ID is null";
  289. sql = @"select a.ApplyCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  290. case when max(e.SourceID) is null then '' else '' end as IsNew
  291. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  292. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  293. from ICSOApply a
  294. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  295. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  296. where a.WorkPoint='{0}'
  297. group by a.ApplyCode,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  298. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  299. sql = string.Format(sql, WorkPoint);
  300. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  301. #endregion
  302. if (!string.IsNullOrWhiteSpace(queryJson))
  303. {
  304. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  305. {
  306. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  307. }
  308. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  309. {
  310. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  311. }
  312. }
  313. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  314. {
  315. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  316. }
  317. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  318. }
  319. //委外领料(委外发料申请)子表查询
  320. public DataTable GetSubGridJson5(string Code)
  321. {
  322. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  323. DataTable dt = new DataTable();
  324. //var queryParam = queryJson.ToJObject();
  325. List<DbParameter> parameter = new List<DbParameter>();
  326. 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,
  327. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  328. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  329. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  330. from ICSOApply a
  331. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  332. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  333. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  334. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  335. where a.ApplyCode='{0}' and b.WorkPoint='{1}'";
  336. sql = string.Format(sql, Code, WorkPoint);
  337. return Repository().FindTableBySql(sql.ToString());
  338. }
  339. //委外材料出库(委外发料申请)
  340. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  341. {
  342. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  343. DataTable dt = new DataTable();
  344. var queryParam = queryJson.ToJObject();
  345. List<DbParameter> parameter = new List<DbParameter>();
  346. string sql = "";
  347. #region [SQL]
  348. // 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,
  349. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  350. // from ICSOIssue a
  351. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  352. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  353. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  354. // sql += " WHERE 1=1 and e.ID is null";
  355. sql = @"select a.IssueCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  356. case when max(e.SourceID) is null then '' else '' end as IsNew
  357. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  358. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  359. from ICSOIssue a
  360. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  361. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  362. where a.WorkPoint='{0}'
  363. group by a.IssueCode,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  364. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  365. sql = string.Format(sql, WorkPoint);
  366. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  367. #endregion
  368. if (!string.IsNullOrWhiteSpace(queryJson))
  369. {
  370. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  371. {
  372. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  373. }
  374. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  375. {
  376. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  377. }
  378. }
  379. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  380. {
  381. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  382. }
  383. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  384. }
  385. //委外材料出库(委外发料申请)子表查询
  386. public DataTable GetSubGridJson6(string Code)
  387. {
  388. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  389. DataTable dt = new DataTable();
  390. //var queryParam = queryJson.ToJObject();
  391. List<DbParameter> parameter = new List<DbParameter>();
  392. 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,
  393. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  394. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  395. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  396. from ICSOIssue a
  397. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  398. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  399. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  400. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  401. where a.IssueCode='{0}' and b.WorkPoint='{1}'";
  402. sql = string.Format(sql, Code, WorkPoint);
  403. return Repository().FindTableBySql(sql.ToString());
  404. }
  405. //销售发货(销售发货)
  406. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  407. {
  408. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  409. DataTable dt = new DataTable();
  410. var queryParam = queryJson.ToJObject();
  411. List<DbParameter> parameter = new List<DbParameter>();
  412. StringBuilder sqlString = new StringBuilder();
  413. #region [SQL]
  414. // 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,
  415. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  416. // from ICSSDN a
  417. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  418. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  419. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  420. // sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  421. sqlString.Append($@"SELECT a.SDNCode AS CODE,
  422. a.CreateDateTime AS MTIME,
  423. a.CreatePerson AS MUSER,
  424. (CASE WHEN max(e.SourceID) IS NULL THEN '' ELSE '' END) AS IsNew,
  425. f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  426. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10
  427. FROM ICSSDN a
  428. LEFT JOIN ICSMOPickMerge e ON a.ID = e.SourceID AND a.WorkPoint = e.WorkPoint
  429. LEFT JOIN ICSExtension f ON a.ExtensionID = f.ID AND a.WorkPoint = f.WorkPoint
  430. WHERE a.WorkPoint = '{WorkPoint}' ");
  431. if (!string.IsNullOrWhiteSpace(queryJson))
  432. {
  433. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  434. {
  435. sqlString.Append($" and a.SDNCode like '%{queryParam["POCode"]}%' ");
  436. }
  437. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  438. {
  439. sqlString.Append($" and a.InvCode like '%{queryParam["InvCode"]}%' ");
  440. }
  441. }
  442. sqlString.Append(@"GROUP BY a.SDNCode, a.CreateDateTime, a.CreatePerson, f.Colspan, f.ProjectCode, f.BatchCode, f.Version, f.Brand,
  443. f.cFree1, f.cFree2, f.cFree3, f.cFree4, f.cFree5, f.cFree6, f.cFree7, f.cFree8, f.cFree9, f.cFree10");
  444. #endregion
  445. string test=sqlString.ToString();
  446. return Repository().FindTablePageBySql(sqlString.ToString(), parameter.ToArray(), ref jqgridparam);
  447. }
  448. //销售发货(销售发货)子表查询
  449. public DataTable GetSubGridJson7(string Code)
  450. {
  451. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  452. DataTable dt = new DataTable();
  453. //var queryParam = queryJson.ToJObject();
  454. List<DbParameter> parameter = new List<DbParameter>();
  455. 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,
  456. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  457. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  458. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.SDNQuantity as IssueQuantity
  459. from ICSSDN a
  460. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  461. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  462. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  463. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  464. where a.SDNCode='{0}' and b.WorkPoint='{1}'";
  465. sql = string.Format(sql, Code, WorkPoint);
  466. return Repository().FindTableBySql(sql.ToString());
  467. }
  468. //其它出库(其它出库)
  469. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  470. {
  471. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  472. DataTable dt = new DataTable();
  473. var queryParam = queryJson.ToJObject();
  474. List<DbParameter> parameter = new List<DbParameter>();
  475. string sql = "";
  476. #region [SQL]
  477. // 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,
  478. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  479. //from ICSOtherOut a
  480. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  481. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  482. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  483. // sql += " WHERE 1=1 and e.ID is null ";
  484. sql = @"select a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  485. case when max(e.SourceID) is null then '' else '' end as IsNew
  486. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  487. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  488. from ICSOtherOut a
  489. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  490. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  491. where a.WorkPoint='{0}'
  492. group by a.OutCode,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  493. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  494. sql = string.Format(sql, WorkPoint);
  495. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  496. #endregion
  497. if (!string.IsNullOrWhiteSpace(queryJson))
  498. {
  499. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  500. {
  501. sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' ";
  502. }
  503. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  504. {
  505. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  506. }
  507. }
  508. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  509. {
  510. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  511. }
  512. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  513. }
  514. //其它出库(其它出库)子表查询
  515. public DataTable GetSubGridJson8(string Code)
  516. {
  517. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  518. DataTable dt = new DataTable();
  519. //var queryParam = queryJson.ToJObject();
  520. List<DbParameter> parameter = new List<DbParameter>();
  521. 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,
  522. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  523. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  524. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  525. from ICSOtherOut a
  526. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  527. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  528. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  529. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  530. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  531. sql = string.Format(sql, Code, WorkPoint);
  532. return Repository().FindTableBySql(sql.ToString());
  533. }
  534. //借用(借用)
  535. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  536. {
  537. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  538. DataTable dt = new DataTable();
  539. var queryParam = queryJson.ToJObject();
  540. List<DbParameter> parameter = new List<DbParameter>();
  541. string sql = "";
  542. #region [SQL]
  543. // sql = @"
  544. //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,
  545. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  546. // from ICSBrrow a
  547. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  548. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  549. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  550. // sql += " WHERE 1=1 and e.ID is null ";
  551. sql = @"select a.BrrowCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  552. case when max(e.SourceID) is null then '' else '' end as IsNew
  553. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  554. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  555. from ICSBrrow a
  556. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  557. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  558. where a.WorkPoint='{0}'
  559. group by a.BrrowCode,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  560. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  561. sql = string.Format(sql, WorkPoint);
  562. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  563. #endregion
  564. if (!string.IsNullOrWhiteSpace(queryJson))
  565. {
  566. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  567. {
  568. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  569. }
  570. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  571. {
  572. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  573. }
  574. }
  575. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  576. {
  577. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  578. }
  579. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  580. }
  581. //借用(借用)子表查询
  582. public DataTable GetSubGridJson9(string Code)
  583. {
  584. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  585. DataTable dt = new DataTable();
  586. //var queryParam = queryJson.ToJObject();
  587. List<DbParameter> parameter = new List<DbParameter>();
  588. 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,
  589. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  590. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  591. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.BrrowQuantity as IssueQuantity
  592. from ICSBrrow a
  593. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  594. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  595. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  596. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  597. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  598. sql = string.Format(sql, Code, WorkPoint);
  599. return Repository().FindTableBySql(sql.ToString());
  600. }
  601. //物料调拨
  602. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  603. {
  604. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  605. DataTable dt = new DataTable();
  606. var queryParam = queryJson.ToJObject();
  607. List<DbParameter> parameter = new List<DbParameter>();
  608. string sql = "";
  609. #region [SQL]
  610. // sql = @"
  611. //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,
  612. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  613. // from ICSBrrow a
  614. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  615. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  616. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  617. // sql += " WHERE 1=1 and e.ID is null ";
  618. sql = @"select a.TransferNO as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  619. case when max(e.SourceID) is null then '' else '' end as IsNew
  620. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  621. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  622. from ICSTransfer a
  623. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  624. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  625. where a.WorkPoint='{0}' and a.Status='1'
  626. group by a.TransferNO,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  627. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  628. sql = string.Format(sql, WorkPoint);
  629. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  630. #endregion
  631. if (!string.IsNullOrWhiteSpace(queryJson))
  632. {
  633. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  634. {
  635. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  636. }
  637. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  638. {
  639. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  640. }
  641. }
  642. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  643. {
  644. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  645. }
  646. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  647. }
  648. //物料调拨子表查询
  649. public DataTable GetSubGridJson10(string Code)
  650. {
  651. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  652. DataTable dt = new DataTable();
  653. //var queryParam = queryJson.ToJObject();
  654. List<DbParameter> parameter = new List<DbParameter>();
  655. 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,
  656. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  657. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  658. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.TransferQuantity as IssueQuantity
  659. from ICSTransfer a
  660. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  661. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  662. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  663. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  664. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  665. sql = string.Format(sql, Code, WorkPoint);
  666. return Repository().FindTableBySql(sql.ToString());
  667. }
  668. //两步调拨
  669. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  670. {
  671. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  672. DataTable dt = new DataTable();
  673. var queryParam = queryJson.ToJObject();
  674. List<DbParameter> parameter = new List<DbParameter>();
  675. string sql = "";
  676. #region [SQL]
  677. // sql = @"
  678. //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,
  679. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  680. // from ICSBrrow a
  681. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  682. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  683. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  684. // sql += " WHERE 1=1 and e.ID is null ";
  685. sql = @"select a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  686. case when max(e.SourceID) is null then '' else '' end as IsNew
  687. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  688. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  689. FROM ICSOtherOut a
  690. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  691. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  692. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  693. where a.WorkPoint='{0}' and a.Status='2'
  694. group by a.OutCode,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  695. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  696. sql = string.Format(sql, WorkPoint);
  697. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  698. #endregion
  699. if (!string.IsNullOrWhiteSpace(queryJson))
  700. {
  701. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  702. {
  703. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  704. }
  705. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  706. {
  707. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  708. }
  709. }
  710. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  711. {
  712. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  713. }
  714. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  715. }
  716. //两步调拨子表查询
  717. public DataTable GetSubGridJson11(string Code)
  718. {
  719. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  720. DataTable dt = new DataTable();
  721. //var queryParam = queryJson.ToJObject();
  722. List<DbParameter> parameter = new List<DbParameter>();
  723. 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,
  724. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  725. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  726. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  727. FROM ICSOtherOut a
  728. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  729. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  730. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  731. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  732. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  733. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  734. sql = string.Format(sql, Code, WorkPoint);
  735. return Repository().FindTableBySql(sql.ToString());
  736. }
  737. public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  738. {
  739. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  740. #region sql
  741. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  742. c.Code,
  743. c.InvCode,
  744. c.InvName,
  745. c.InvStd,
  746. c.InvUnit,
  747. FLOOR(c.iQuantity) AS iQuantity,
  748. d.WarehouseCode,
  749. d.LocationCode,
  750. d.LotNO,
  751. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  752. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  753. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  754. FROM
  755. ({0}) c
  756. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  757. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  758. 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
  759. DECLARE @ItemCode VARCHAR(50),
  760. @QTY DECIMAL(18,3),
  761. @ItemCodeCurrent VARCHAR(50),
  762. @QTYCurrent DECIMAL(18,3),
  763. @iQuantityCurrent DECIMAL(18,3),
  764. @CanDelete BIT,
  765. @Row INT,
  766. @rowCurrent INT
  767. SET @Row = @@rowcount
  768. SET @rowCurrent=1
  769. SET @CanDelete=0
  770. SET @ItemCode=''
  771. WHILE @rowCurrent<=@Row
  772. BEGIN
  773. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  774. PRINT(@rowCurrent)
  775. IF @ItemCode<>@ItemCodeCurrent
  776. BEGIN
  777. SET @ItemCode=@ItemCodeCurrent
  778. SET @QTY=0
  779. SET @CanDelete=0
  780. END
  781. IF @CanDelete=1
  782. BEGIN
  783. DELETE FROM #temp WHERE rowNo=@rowCurrent
  784. SET @rowCurrent += 1
  785. CONTINUE
  786. END
  787. SET @QTY += @QTYCurrent
  788. IF @QTY>=@iQuantityCurrent
  789. BEGIN
  790. SET @CanDelete=1
  791. END
  792. SET @rowCurrent += 1
  793. END
  794. SELECT * FROM #temp
  795. DROP TABLE #temp
  796. ";
  797. #endregion
  798. string sqls = "";
  799. if (Type=="1")
  800. {
  801. #region 工单备料sql
  802. sqls = @" SELECT
  803. c.MOCode as Code,
  804. a.InvCode,
  805. b.InvName,
  806. b.InvStd,
  807. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  808. a.WhCode,
  809. b.InvUnit,
  810. a.ExtensionID
  811. FROM
  812. ICSMOPick a
  813. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  814. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  815. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  816. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  817. #endregion
  818. }
  819. if (Type == "2")
  820. {
  821. #region 工单领料SQL
  822. sqls = @" select
  823. a.ApplyCode as Code,
  824. a.InvCode,
  825. b.InvName,
  826. b.InvStd,
  827. b.InvUnit,
  828. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  829. a.WhCode,
  830. a.ExtensionID
  831. FROM
  832. ICSMOApply a
  833. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  834. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  835. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  836. #endregion
  837. }
  838. if (Type=="3")
  839. {
  840. #region 工单材料出库SQL
  841. sqls = @" select
  842. a.IssueCode as Code,
  843. a.InvCode,
  844. b.InvName,
  845. b.InvStd,
  846. b.InvUnit,
  847. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  848. a.WhCode,
  849. a.ExtensionID
  850. FROM
  851. ICSMOIssue a
  852. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  853. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  854. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  855. #endregion
  856. }
  857. if (Type=="4")
  858. {
  859. #region 委外备料SQL
  860. sqls = @" select
  861. c.OOCode as Code,
  862. a.InvCode,
  863. b.InvName,
  864. b.InvStd,
  865. b.InvUnit,
  866. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  867. a.WhCode,
  868. a.ExtensionID
  869. FROM
  870. ICSOOPick a
  871. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  872. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  873. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  874. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  875. #endregion
  876. }
  877. if (Type=="5")
  878. {
  879. #region 委外领料SQL
  880. sqls = @" select
  881. a.ApplyCode as Code,
  882. a.InvCode,
  883. b.InvName,
  884. b.InvStd,
  885. b.InvUnit,
  886. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  887. a.WhCode,
  888. a.ExtensionID
  889. FROM
  890. ICSOApply a
  891. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  892. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  893. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  894. #endregion
  895. }
  896. if (Type=="6")
  897. {
  898. #region 委外材料出库SQL
  899. sqls = @" select
  900. a.IssueCode as Code,
  901. a.InvCode,
  902. b.InvName,
  903. b.InvStd,
  904. b.InvUnit,
  905. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  906. a.WhCode,
  907. a.ExtensionID
  908. FROM
  909. ICSOIssue a
  910. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  911. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  912. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  913. #endregion
  914. }
  915. if (Type=="7")
  916. {
  917. #region 销售发货SQL
  918. sqls = @" select
  919. a.SDNCode as Code,
  920. a.InvCode,
  921. b.InvName,
  922. b.InvStd,
  923. b.InvUnit,
  924. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  925. a.WhCode,
  926. a.ExtensionID
  927. FROM
  928. ICSSDN a
  929. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  930. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  931. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  932. #endregion
  933. }
  934. if (Type=="8")
  935. {
  936. #region 其它出库SQL
  937. sqls = @" select
  938. a.OutCode as Code,
  939. a.InvCode,
  940. b.InvName,
  941. b.InvStd,
  942. b.InvUnit,
  943. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  944. a.WhCode,
  945. a.ExtensionID
  946. FROM
  947. ICSOtherOut a
  948. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  949. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  950. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  951. #endregion
  952. }
  953. if (Type == "9")
  954. {
  955. #region 借用SQL
  956. sqls = @"select
  957. a.BrrowCode as Code,
  958. a.InvCode,
  959. b.InvName,
  960. b.InvStd,
  961. b.InvUnit,
  962. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  963. a.WhCode,
  964. a.ExtensionID
  965. FROM
  966. ICSBrrow a
  967. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  968. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  969. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  970. #endregion
  971. }
  972. if (Type == "10")
  973. {
  974. #region 物料调拨
  975. sqls = @" select
  976. a.TransferNO as Code,
  977. a.InvCode,
  978. b.InvName,
  979. b.InvStd,
  980. b.InvUnit,
  981. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  982. a.FromWarehouseCode as WhCode,
  983. a.ExtensionID
  984. FROM
  985. ICSTransfer a
  986. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  987. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  988. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  989. #endregion
  990. }
  991. if (Type == "11")
  992. {
  993. #region 两步调出
  994. sqls = @"select
  995. a.OutCode as Code,
  996. a.InvCode,
  997. b.InvName,
  998. b.InvStd,
  999. b.InvUnit,
  1000. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1001. a.WHCode ,
  1002. a.ExtensionID
  1003. from ICSOtherOut a
  1004. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1005. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1006. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1007. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1008. #endregion
  1009. }
  1010. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID)?"''":ID.TrimEnd(','),WorkPoint);
  1011. sql = string.Format(sql, sqls, WorkPoint);
  1012. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1013. DataTable dtCloned = table.Clone();
  1014. foreach (DataColumn col in dtCloned.Columns)
  1015. {
  1016. col.DataType = typeof(string);
  1017. }
  1018. foreach (DataRow row in table.Rows)
  1019. {
  1020. DataRow newrow = dtCloned.NewRow();
  1021. foreach (DataColumn column in dtCloned.Columns)
  1022. {
  1023. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1024. }
  1025. dtCloned.Rows.Add(newrow);
  1026. }
  1027. if (Invmes.Rows.Count > 0)
  1028. {
  1029. dtCloned.Merge(Invmes, false);
  1030. }
  1031. return dtCloned;
  1032. }
  1033. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1034. {
  1035. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1036. #region sql
  1037. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1038. c.MergeID,
  1039. c.Code,
  1040. c.InvCode,
  1041. c.InvName,
  1042. c.InvStd,
  1043. c.InvUnit,
  1044. FLOOR(c.iQuantity) AS iQuantity,
  1045. d.WarehouseCode,
  1046. d.LocationCode,
  1047. d.LotNO,
  1048. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1049. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1050. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1051. FROM
  1052. ({0}) c
  1053. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1054. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1055. 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
  1056. DECLARE @ItemCode VARCHAR(50),
  1057. @QTY DECIMAL(18,3),
  1058. @ItemCodeCurrent VARCHAR(50),
  1059. @QTYCurrent DECIMAL(18,3),
  1060. @iQuantityCurrent DECIMAL(18,3),
  1061. @CanDelete BIT,
  1062. @Row INT,
  1063. @rowCurrent INT
  1064. SET @Row = @@rowcount
  1065. SET @rowCurrent=1
  1066. SET @CanDelete=0
  1067. SET @ItemCode=''
  1068. WHILE @rowCurrent<=@Row
  1069. BEGIN
  1070. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1071. PRINT(@rowCurrent)
  1072. IF @ItemCode<>@ItemCodeCurrent
  1073. BEGIN
  1074. SET @ItemCode=@ItemCodeCurrent
  1075. SET @QTY=0
  1076. SET @CanDelete=0
  1077. END
  1078. IF @CanDelete=1
  1079. BEGIN
  1080. DELETE FROM #temp WHERE rowNo=@rowCurrent
  1081. SET @rowCurrent += 1
  1082. CONTINUE
  1083. END
  1084. SET @QTY += @QTYCurrent
  1085. IF @QTY>=@iQuantityCurrent
  1086. BEGIN
  1087. SET @CanDelete=1
  1088. END
  1089. SET @rowCurrent += 1
  1090. END
  1091. SELECT * FROM #temp
  1092. DROP TABLE #temp
  1093. ";
  1094. #endregion
  1095. string sqls = "";
  1096. if (Type == "1")
  1097. {
  1098. #region 工单备料sql
  1099. sqls = @" select
  1100. x.MergeID,
  1101. c.MOCode as Code,
  1102. a.InvCode,
  1103. b.InvName,
  1104. b.InvStd,
  1105. b.InvUnit,
  1106. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1107. a.WhCode,
  1108. a.ExtensionID
  1109. FROM
  1110. ICSMOPick a
  1111. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1112. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1113. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1114. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1115. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1116. #endregion
  1117. }
  1118. if (Type == "2")
  1119. {
  1120. #region 工单领料SQL
  1121. sqls = @" select
  1122. x.MergeID,
  1123. a.ApplyCode as Code,
  1124. a.InvCode,
  1125. b.InvName,
  1126. b.InvStd,
  1127. b.InvUnit,
  1128. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1129. a.WhCode,
  1130. a.ExtensionID
  1131. FROM
  1132. ICSMOApply a
  1133. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1134. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1135. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  1136. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1137. #endregion
  1138. }
  1139. if (Type == "3")
  1140. {
  1141. #region 工单材料出库SQL
  1142. sqls = @" select
  1143. x.MergeID,
  1144. a.IssueCode 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. ICSMOIssue a
  1154. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1155. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1156. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1157. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1158. #endregion
  1159. }
  1160. if (Type == "4")
  1161. {
  1162. #region 委外备料SQL
  1163. sqls = @" select
  1164. x.MergeID,
  1165. c.OOCode as Code,
  1166. a.InvCode,
  1167. b.InvName,
  1168. b.InvStd,
  1169. b.InvUnit,
  1170. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1171. a.WhCode,
  1172. a.ExtensionID
  1173. FROM
  1174. ICSOOPick a
  1175. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1176. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1177. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1178. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1179. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  1180. #endregion
  1181. }
  1182. if (Type == "5")
  1183. {
  1184. #region 委外领料SQL
  1185. sqls = @" select
  1186. x.MergeID,
  1187. a.ApplyCode as Code,
  1188. a.InvCode,
  1189. b.InvName,
  1190. b.InvStd,
  1191. b.InvUnit,
  1192. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1193. a.WhCode,
  1194. a.ExtensionID
  1195. FROM
  1196. ICSOApply a
  1197. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1198. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1199. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1200. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1201. #endregion
  1202. }
  1203. if (Type == "6")
  1204. {
  1205. #region 委外材料出库SQL
  1206. sqls = @" select
  1207. x.MergeID,
  1208. a.IssueCode as Code,
  1209. a.InvCode,
  1210. b.InvName,
  1211. b.InvStd,
  1212. b.InvUnit,
  1213. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1214. a.WhCode,
  1215. a.ExtensionID
  1216. FROM
  1217. ICSOIssue a
  1218. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1219. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1220. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1221. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1222. #endregion
  1223. }
  1224. if (Type == "7")
  1225. {
  1226. #region 销售发货SQL
  1227. sqls = @" select
  1228. x.MergeID,
  1229. a.SDNCode as Code,
  1230. a.InvCode,
  1231. b.InvName,
  1232. b.InvStd,
  1233. b.InvUnit,
  1234. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1235. a.WhCode,
  1236. a.ExtensionID
  1237. FROM
  1238. ICSSDN a
  1239. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1240. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1241. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1242. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1243. #endregion
  1244. }
  1245. if (Type == "8")
  1246. {
  1247. #region 其它出库SQL
  1248. sqls = @" select
  1249. x.MergeID,
  1250. a.OutCode as Code,
  1251. a.InvCode,
  1252. b.InvName,
  1253. b.InvStd,
  1254. b.InvUnit,
  1255. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1256. a.WhCode,
  1257. a.ExtensionID
  1258. FROM
  1259. ICSOtherOut a
  1260. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1261. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1262. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1263. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1264. #endregion
  1265. }
  1266. if (Type == "9")
  1267. {
  1268. #region 借用SQL
  1269. sqls = @" select
  1270. x.MergeID,
  1271. a.BrrowCode as Code,
  1272. a.InvCode,
  1273. b.InvName,
  1274. b.InvStd,
  1275. b.InvUnit,
  1276. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1277. a.WhCode,
  1278. a.ExtensionID
  1279. FROM
  1280. ICSBrrow a
  1281. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1282. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1283. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1284. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1285. #endregion
  1286. }
  1287. if (Type == "10")
  1288. {
  1289. #region 物料调拨
  1290. sqls = @" select
  1291. x.MergeID,
  1292. a.TransferNO as Code,
  1293. a.InvCode,
  1294. b.InvName,
  1295. b.InvStd,
  1296. b.InvUnit,
  1297. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1298. a.FromWarehouseCode as WhCode,
  1299. a.ExtensionID
  1300. FROM
  1301. ICSTransfer a
  1302. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1303. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1304. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1305. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  1306. #endregion
  1307. }
  1308. if (Type == "10")
  1309. {
  1310. #region 两步调出
  1311. sqls = @"select
  1312. x.MergeID,
  1313. a.OutCode as Code,
  1314. a.InvCode,
  1315. b.InvName,
  1316. b.InvStd,
  1317. b.InvUnit,
  1318. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1319. a.WHCode as WhCode,
  1320. a.ExtensionID
  1321. FROM
  1322. ICSOtherOut a
  1323. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1324. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1325. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1326. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1327. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  1328. #endregion
  1329. }
  1330. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  1331. sql = string.Format(sql, sqls, WorkPoint);
  1332. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1333. DataTable dtCloned = table.Clone();
  1334. foreach (DataColumn col in dtCloned.Columns)
  1335. {
  1336. col.DataType = typeof(string);
  1337. }
  1338. foreach (DataRow row in table.Rows)
  1339. {
  1340. DataRow newrow = dtCloned.NewRow();
  1341. foreach (DataColumn column in dtCloned.Columns)
  1342. {
  1343. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1344. }
  1345. dtCloned.Rows.Add(newrow);
  1346. }
  1347. if (Invmes.Rows.Count > 0)
  1348. {
  1349. dtCloned.Merge(Invmes, false);
  1350. }
  1351. return dtCloned;
  1352. }
  1353. public string MergeMaterial(string keyValue,string Type)
  1354. {
  1355. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1356. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1357. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1358. string msg = "";
  1359. string sql = string.Empty;
  1360. keyValue = keyValue.TrimEnd(',');
  1361. DateTime time = DateTime.Now;
  1362. string Tday = time.ToString("yyyyMMdd");
  1363. string sqls = string.Format(@"SELECT MAX(A.SourceID) AS SourceID FROM ICSMOPickMerge A WHERE A.SourceID LIKE '{0}%' AND LEN(a.SourceID) = 13", Tday);
  1364. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  1365. string MergeID = "";
  1366. Int64 Merge_ID = 0;
  1367. DataTable dts = ds.Tables[0];
  1368. if (dts != null && dts.Rows.Count > 0)
  1369. {
  1370. string lot = dts.Rows[0]["SourceID"].ToString();
  1371. if (!string.IsNullOrWhiteSpace(lot))
  1372. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  1373. }
  1374. MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  1375. if (Type == "1")//工单备料
  1376. {
  1377. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1378. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1379. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1380. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  1381. where a.MOCode in ({5})
  1382. ";
  1383. }
  1384. if (Type == "2")//工单发料
  1385. {
  1386. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1387. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1388. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1389. from ICSMOApply a
  1390. where a.ApplyCode in ({5})";
  1391. }
  1392. if (Type == "3")//材料出库
  1393. {
  1394. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1395. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1396. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1397. from ICSMOIssue a
  1398. where a.IssueCode in ({5}) ";
  1399. }
  1400. if (Type == "4")//委外备料
  1401. {
  1402. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1403. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1404. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1405. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  1406. where a.OOCode in ({5})";
  1407. }
  1408. if (Type == "5")//委外领料
  1409. {
  1410. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1411. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1412. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1413. from ICSOApply a
  1414. where a.ApplyCode in ({5})";
  1415. }
  1416. if (Type == "6")//委外材料出库
  1417. {
  1418. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1419. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1420. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1421. from ICSOIssue a
  1422. where a.IssueCode in ('{5}')";
  1423. }
  1424. if (Type == "7")//销售发货
  1425. {
  1426. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1427. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1428. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1429. from ICSOIssue a
  1430. where a.IssueCode in ({5})";
  1431. }
  1432. if (Type == "8")//其它出库
  1433. {
  1434. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1435. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1436. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1437. from ICSSDN a
  1438. where a.SDNCode in ({5})";
  1439. }
  1440. if (Type == "9")//借用单
  1441. {
  1442. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1443. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1444. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1445. from ICSOtherOut a
  1446. where a.OutCode in ({5})";
  1447. }
  1448. if (Type == "10")//物料调拨
  1449. {
  1450. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1451. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1452. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1453. from ICSTransfer a
  1454. where a.TransferNO in ({5})
  1455. ";
  1456. }
  1457. if (Type == "11")//两步调出
  1458. {
  1459. sql += @" INSERT INTO dbo.ICSMOPickMerge
  1460. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1461. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1462. from ICSOtherOut a
  1463. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1464. where a.OutCode in ({5})
  1465. ";
  1466. }
  1467. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, keyValue);
  1468. try
  1469. {
  1470. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  1471. {
  1472. }
  1473. else
  1474. {
  1475. msg = "新增失败";
  1476. }
  1477. }
  1478. catch (Exception ex)
  1479. {
  1480. throw new Exception(ex.Message);
  1481. }
  1482. return msg;
  1483. }
  1484. public string CheckQty(string objArr)
  1485. {
  1486. objArr= objArr.TrimEnd(',');
  1487. string sql = @"select * from ICSMOPickMerge a
  1488. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  1489. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  1490. where MOCode in ({0})";
  1491. sql = string.Format(sql, objArr);
  1492. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  1493. if (dt != null&&dt.Rows.Count>0)
  1494. {
  1495. return "1";
  1496. }
  1497. return "0";
  1498. }
  1499. }
  1500. }