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

1606 lines
77 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
  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. string sql = "";
  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. sql = @"select
  40. a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,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 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  42. from ICSMO a
  43. inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  44. left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
  45. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  46. where a.WorkPoint='{0}'
  47. group by a.MOCode, a.WorkPoint,a.CreateDateTime,a.createperson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  48. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  49. sql = string.Format(sql, WorkPoint);
  50. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  51. #endregion
  52. if (!string.IsNullOrWhiteSpace(queryJson))
  53. {
  54. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  55. {
  56. sql += " and b.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  57. }
  58. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  59. {
  60. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  61. }
  62. }
  63. return Repository().FindTablePageBySql(sql.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
  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
  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
  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
  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
  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
  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. string sql = "";
  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. sql = @"select a.SDNCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  422. case when max(e.SourceID) is null then '' else '' end as IsNew
  423. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  424. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  425. from ICSSDN a
  426. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  427. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  428. where a.WorkPoint='{0}'
  429. group by a.SDNCode,a.CreateDateTime,a.CreatePerson,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  430. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  431. sql = string.Format(sql, WorkPoint);
  432. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  433. #endregion
  434. if (!string.IsNullOrWhiteSpace(queryJson))
  435. {
  436. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  437. {
  438. sql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  439. }
  440. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  441. {
  442. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  443. }
  444. }
  445. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  446. {
  447. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  448. }
  449. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  450. }
  451. //销售发货(销售发货)子表查询
  452. public DataTable GetSubGridJson7(string Code)
  453. {
  454. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  455. DataTable dt = new DataTable();
  456. //var queryParam = queryJson.ToJObject();
  457. List<DbParameter> parameter = new List<DbParameter>();
  458. 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,
  459. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  460. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  461. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  462. from ICSSDN a
  463. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  464. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  465. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  466. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  467. where a.SDNCode='{0}' and b.WorkPoint='{1}'";
  468. sql = string.Format(sql, Code, WorkPoint);
  469. return Repository().FindTableBySql(sql.ToString());
  470. }
  471. //其它出库(其它出库)
  472. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  473. {
  474. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  475. DataTable dt = new DataTable();
  476. var queryParam = queryJson.ToJObject();
  477. List<DbParameter> parameter = new List<DbParameter>();
  478. string sql = "";
  479. #region [SQL]
  480. // 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,
  481. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  482. //from ICSOtherOut a
  483. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  484. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  485. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  486. // sql += " WHERE 1=1 and e.ID is null ";
  487. sql = @"select a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  488. case when max(e.SourceID) is null then '' else '' end as IsNew
  489. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  490. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  491. from ICSOtherOut a
  492. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  493. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  494. where a.WorkPoint='{0}'
  495. 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
  496. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  497. sql = string.Format(sql, WorkPoint);
  498. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  499. #endregion
  500. if (!string.IsNullOrWhiteSpace(queryJson))
  501. {
  502. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  503. {
  504. sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' ";
  505. }
  506. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  507. {
  508. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  509. }
  510. }
  511. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  512. {
  513. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  514. }
  515. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  516. }
  517. //其它出库(其它出库)子表查询
  518. public DataTable GetSubGridJson8(string Code)
  519. {
  520. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  521. DataTable dt = new DataTable();
  522. //var queryParam = queryJson.ToJObject();
  523. List<DbParameter> parameter = new List<DbParameter>();
  524. 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,
  525. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  526. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  527. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  528. from ICSOtherOut a
  529. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  530. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  531. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  532. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  533. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  534. sql = string.Format(sql, Code, WorkPoint);
  535. return Repository().FindTableBySql(sql.ToString());
  536. }
  537. //借用(借用)
  538. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  539. {
  540. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  541. DataTable dt = new DataTable();
  542. var queryParam = queryJson.ToJObject();
  543. List<DbParameter> parameter = new List<DbParameter>();
  544. string sql = "";
  545. #region [SQL]
  546. // sql = @"
  547. //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,
  548. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  549. // from ICSBrrow a
  550. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  551. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  552. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  553. // sql += " WHERE 1=1 and e.ID is null ";
  554. sql = @"select a.BrrowCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  555. case when max(e.SourceID) is null then '' else '' end as IsNew
  556. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  557. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  558. from ICSBrrow a
  559. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  560. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  561. where a.WorkPoint='{0}'
  562. 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
  563. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  564. sql = string.Format(sql, WorkPoint);
  565. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  566. #endregion
  567. if (!string.IsNullOrWhiteSpace(queryJson))
  568. {
  569. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  570. {
  571. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  572. }
  573. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  574. {
  575. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  576. }
  577. }
  578. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  579. {
  580. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  581. }
  582. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  583. }
  584. //借用(借用)子表查询
  585. public DataTable GetSubGridJson9(string Code)
  586. {
  587. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  588. DataTable dt = new DataTable();
  589. //var queryParam = queryJson.ToJObject();
  590. List<DbParameter> parameter = new List<DbParameter>();
  591. 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,
  592. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  593. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  594. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  595. from ICSBrrow a
  596. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  597. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  598. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  599. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  600. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  601. sql = string.Format(sql, Code, WorkPoint);
  602. return Repository().FindTableBySql(sql.ToString());
  603. }
  604. //物料调拨
  605. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  606. {
  607. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  608. DataTable dt = new DataTable();
  609. var queryParam = queryJson.ToJObject();
  610. List<DbParameter> parameter = new List<DbParameter>();
  611. string sql = "";
  612. #region [SQL]
  613. // sql = @"
  614. //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,
  615. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  616. // from ICSBrrow a
  617. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  618. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  619. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  620. // sql += " WHERE 1=1 and e.ID is null ";
  621. sql = @"select a.TransferNO as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  622. case when max(e.SourceID) is null then '' else '' end as IsNew
  623. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  624. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  625. from ICSTransfer a
  626. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  627. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  628. where a.WorkPoint='{0}' and a.Status='1'
  629. 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
  630. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  631. sql = string.Format(sql, WorkPoint);
  632. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  633. #endregion
  634. if (!string.IsNullOrWhiteSpace(queryJson))
  635. {
  636. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  637. {
  638. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  639. }
  640. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  641. {
  642. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  643. }
  644. }
  645. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  646. {
  647. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  648. }
  649. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  650. }
  651. //物料调拨子表查询
  652. public DataTable GetSubGridJson10(string Code)
  653. {
  654. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  655. DataTable dt = new DataTable();
  656. //var queryParam = queryJson.ToJObject();
  657. List<DbParameter> parameter = new List<DbParameter>();
  658. 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,
  659. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  660. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  661. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  662. from ICSTransfer a
  663. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  664. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  665. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  666. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  667. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  668. sql = string.Format(sql, Code, WorkPoint);
  669. return Repository().FindTableBySql(sql.ToString());
  670. }
  671. //两步调拨
  672. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  673. {
  674. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  675. DataTable dt = new DataTable();
  676. var queryParam = queryJson.ToJObject();
  677. List<DbParameter> parameter = new List<DbParameter>();
  678. string sql = "";
  679. #region [SQL]
  680. // sql = @"
  681. //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,
  682. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  683. // from ICSBrrow a
  684. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  685. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  686. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  687. // sql += " WHERE 1=1 and e.ID is null ";
  688. sql = @"select a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,
  689. case when max(e.SourceID) is null then '' else '' end as IsNew
  690. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  691. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  692. FROM ICSOtherOut a
  693. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  694. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  695. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  696. where a.WorkPoint='{0}' and a.Status='2'
  697. 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
  698. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  699. sql = string.Format(sql, WorkPoint);
  700. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  701. #endregion
  702. if (!string.IsNullOrWhiteSpace(queryJson))
  703. {
  704. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  705. {
  706. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  707. }
  708. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  709. {
  710. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  711. }
  712. }
  713. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  714. {
  715. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  716. }
  717. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  718. }
  719. //两步调拨子表查询
  720. public DataTable GetSubGridJson11(string Code)
  721. {
  722. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  723. DataTable dt = new DataTable();
  724. //var queryParam = queryJson.ToJObject();
  725. List<DbParameter> parameter = new List<DbParameter>();
  726. 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,
  727. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  728. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  729. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  730. FROM ICSOtherOut a
  731. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  732. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  733. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  734. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  735. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  736. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  737. sql = string.Format(sql, Code, WorkPoint);
  738. return Repository().FindTableBySql(sql.ToString());
  739. }
  740. public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  741. {
  742. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  743. #region sql
  744. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  745. c.Code,
  746. c.InvCode,
  747. c.InvName,
  748. c.InvStd,
  749. FLOOR(c.iQuantity) AS iQuantity,
  750. d.WarehouseCode,
  751. d.LocationCode,
  752. d.LotNO,
  753. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  754. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  755. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  756. FROM
  757. ({0}) c
  758. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  759. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  760. 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
  761. DECLARE @ItemCode VARCHAR(50),
  762. @QTY DECIMAL(18,3),
  763. @ItemCodeCurrent VARCHAR(50),
  764. @QTYCurrent DECIMAL(18,3),
  765. @iQuantityCurrent DECIMAL(18,3),
  766. @CanDelete BIT,
  767. @Row INT,
  768. @rowCurrent INT
  769. SET @Row = @@rowcount
  770. SET @rowCurrent=1
  771. SET @CanDelete=0
  772. SET @ItemCode=''
  773. WHILE @rowCurrent<=@Row
  774. BEGIN
  775. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  776. PRINT(@rowCurrent)
  777. IF @ItemCode<>@ItemCodeCurrent
  778. BEGIN
  779. SET @ItemCode=@ItemCodeCurrent
  780. SET @QTY=0
  781. SET @CanDelete=0
  782. END
  783. IF @CanDelete=1
  784. BEGIN
  785. DELETE FROM #temp WHERE rowNo=@rowCurrent
  786. SET @rowCurrent += 1
  787. CONTINUE
  788. END
  789. SET @QTY += @QTYCurrent
  790. IF @QTY>=@iQuantityCurrent
  791. BEGIN
  792. SET @CanDelete=1
  793. END
  794. SET @rowCurrent += 1
  795. END
  796. SELECT * FROM #temp
  797. DROP TABLE #temp
  798. ";
  799. #endregion
  800. string sqls = "";
  801. if (Type=="1")
  802. {
  803. #region 工单备料sql
  804. sqls = @" SELECT
  805. c.MOCode as Code,
  806. a.InvCode,
  807. b.InvName,
  808. b.InvStd,
  809. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  810. a.WhCode,
  811. a.ExtensionID
  812. FROM
  813. ICSMOPick a
  814. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  815. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  816. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  817. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  818. #endregion
  819. }
  820. if (Type == "2")
  821. {
  822. #region 工单领料SQL
  823. sqls = @" select
  824. a.ApplyCode as Code,
  825. a.InvCode,
  826. b.InvName,
  827. b.InvStd,
  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,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. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  847. a.WhCode,
  848. a.ExtensionID
  849. FROM
  850. ICSMOIssue a
  851. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  852. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  853. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  854. #endregion
  855. }
  856. if (Type=="4")
  857. {
  858. #region 委外备料SQL
  859. sqls = @" select
  860. c.OOCode as Code,
  861. a.InvCode,
  862. b.InvName,
  863. b.InvStd,
  864. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  865. a.WhCode,
  866. a.ExtensionID
  867. FROM
  868. ICSOOPick a
  869. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  870. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  871. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  872. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode, a.ExtensionID";
  873. #endregion
  874. }
  875. if (Type=="5")
  876. {
  877. #region 委外领料SQL
  878. sqls = @" select
  879. a.ApplyCode as Code,
  880. a.InvCode,
  881. b.InvName,
  882. b.InvStd,
  883. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  884. a.WhCode,
  885. a.ExtensionID
  886. FROM
  887. ICSOApply a
  888. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  889. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  890. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  891. #endregion
  892. }
  893. if (Type=="6")
  894. {
  895. #region 委外材料出库SQL
  896. sqls = @" select
  897. a.IssueCode as Code,
  898. a.InvCode,
  899. b.InvName,
  900. b.InvStd,
  901. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  902. a.WhCode,
  903. a.ExtensionID
  904. FROM
  905. ICSOIssue a
  906. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  907. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  908. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  909. #endregion
  910. }
  911. if (Type=="7")
  912. {
  913. #region 销售发货SQL
  914. sqls = @" select
  915. a.SDNCode as Code,
  916. a.InvCode,
  917. b.InvName,
  918. b.InvStd,
  919. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  920. a.WhCode,
  921. a.ExtensionID
  922. FROM
  923. ICSSDN a
  924. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  925. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  926. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  927. #endregion
  928. }
  929. if (Type=="8")
  930. {
  931. #region 其它出库SQL
  932. sqls = @" select
  933. a.OutCode as Code,
  934. a.InvCode,
  935. b.InvName,
  936. b.InvStd,
  937. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  938. a.WhCode,
  939. a.ExtensionID
  940. FROM
  941. ICSOtherOut a
  942. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  943. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  944. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  945. #endregion
  946. }
  947. if (Type == "9")
  948. {
  949. #region 借用SQL
  950. sqls = @"select
  951. a.BrrowCode as Code,
  952. a.InvCode,
  953. b.InvName,
  954. b.InvStd,
  955. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  956. a.WhCode,
  957. a.ExtensionID
  958. FROM
  959. ICSBrrow a
  960. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  961. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  962. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID";
  963. #endregion
  964. }
  965. if (Type == "10")
  966. {
  967. #region 物料调拨
  968. sqls = @" select
  969. a.TransferNO as Code,
  970. a.InvCode,
  971. b.InvName,
  972. b.InvStd,
  973. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  974. a.FromWarehouseCode as WhCode,
  975. a.ExtensionID
  976. FROM
  977. ICSTransfer a
  978. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  979. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  980. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,a.FromWarehouseCode,a.ExtensionID";
  981. #endregion
  982. }
  983. if (Type == "11")
  984. {
  985. #region 两步调出
  986. sqls = @"select
  987. a.OutCode as Code,
  988. a.InvCode,
  989. b.InvName,
  990. b.InvStd,
  991. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  992. a.WHCode ,
  993. a.ExtensionID
  994. from ICSOtherOut a
  995. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  996. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  997. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  998. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WHCode,a.ExtensionID";
  999. #endregion
  1000. }
  1001. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID)?"''":ID.TrimEnd(','),WorkPoint);
  1002. sql = string.Format(sql, sqls, WorkPoint);
  1003. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1004. DataTable dtCloned = table.Clone();
  1005. foreach (DataColumn col in dtCloned.Columns)
  1006. {
  1007. col.DataType = typeof(string);
  1008. }
  1009. foreach (DataRow row in table.Rows)
  1010. {
  1011. DataRow newrow = dtCloned.NewRow();
  1012. foreach (DataColumn column in dtCloned.Columns)
  1013. {
  1014. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1015. }
  1016. dtCloned.Rows.Add(newrow);
  1017. }
  1018. if (Invmes.Rows.Count > 0)
  1019. {
  1020. dtCloned.Merge(Invmes, false);
  1021. }
  1022. return dtCloned;
  1023. }
  1024. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1025. {
  1026. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1027. #region sql
  1028. string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1029. c.MergeID,
  1030. c.Code,
  1031. c.InvCode,
  1032. c.InvName,
  1033. c.InvStd,
  1034. FLOOR(c.iQuantity) AS iQuantity,
  1035. d.WarehouseCode,
  1036. d.LocationCode,
  1037. d.LotNO,
  1038. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1039. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1040. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1041. FROM
  1042. ({0}) c
  1043. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1044. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1045. 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
  1046. DECLARE @ItemCode VARCHAR(50),
  1047. @QTY DECIMAL(18,3),
  1048. @ItemCodeCurrent VARCHAR(50),
  1049. @QTYCurrent DECIMAL(18,3),
  1050. @iQuantityCurrent DECIMAL(18,3),
  1051. @CanDelete BIT,
  1052. @Row INT,
  1053. @rowCurrent INT
  1054. SET @Row = @@rowcount
  1055. SET @rowCurrent=1
  1056. SET @CanDelete=0
  1057. SET @ItemCode=''
  1058. WHILE @rowCurrent<=@Row
  1059. BEGIN
  1060. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1061. PRINT(@rowCurrent)
  1062. IF @ItemCode<>@ItemCodeCurrent
  1063. BEGIN
  1064. SET @ItemCode=@ItemCodeCurrent
  1065. SET @QTY=0
  1066. SET @CanDelete=0
  1067. END
  1068. IF @CanDelete=1
  1069. BEGIN
  1070. DELETE FROM #temp WHERE rowNo=@rowCurrent
  1071. SET @rowCurrent += 1
  1072. CONTINUE
  1073. END
  1074. SET @QTY += @QTYCurrent
  1075. IF @QTY>=@iQuantityCurrent
  1076. BEGIN
  1077. SET @CanDelete=1
  1078. END
  1079. SET @rowCurrent += 1
  1080. END
  1081. SELECT * FROM #temp
  1082. DROP TABLE #temp
  1083. ";
  1084. #endregion
  1085. string sqls = "";
  1086. if (Type == "1")
  1087. {
  1088. #region 工单备料sql
  1089. sqls = @" select
  1090. x.MergeID,
  1091. c.MOCode as Code,
  1092. a.InvCode,
  1093. b.InvName,
  1094. b.InvStd,
  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,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. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1117. a.WhCode,
  1118. a.ExtensionID
  1119. FROM
  1120. ICSMOApply a
  1121. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1122. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1123. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  1124. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,x.MergeID,a.ExtensionID";
  1125. #endregion
  1126. }
  1127. if (Type == "3")
  1128. {
  1129. #region 工单材料出库SQL
  1130. sqls = @" select
  1131. x.MergeID,
  1132. a.IssueCode as Code,
  1133. a.InvCode,
  1134. b.InvName,
  1135. b.InvStd,
  1136. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1137. a.WhCode,
  1138. a.ExtensionID
  1139. FROM
  1140. ICSMOIssue a
  1141. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1142. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1143. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1144. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,x.MergeID";
  1145. #endregion
  1146. }
  1147. if (Type == "4")
  1148. {
  1149. #region 委外备料SQL
  1150. sqls = @" select
  1151. x.MergeID,
  1152. c.OOCode as Code,
  1153. a.InvCode,
  1154. b.InvName,
  1155. b.InvStd,
  1156. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1157. a.WhCode,
  1158. a.ExtensionID
  1159. FROM
  1160. ICSOOPick a
  1161. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1162. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1163. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1164. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1165. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID, x.MergeID";
  1166. #endregion
  1167. }
  1168. if (Type == "5")
  1169. {
  1170. #region 委外领料SQL
  1171. sqls = @" select
  1172. x.MergeID,
  1173. a.ApplyCode as Code,
  1174. a.InvCode,
  1175. b.InvName,
  1176. b.InvStd,
  1177. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1178. a.WhCode,
  1179. a.ExtensionID
  1180. FROM
  1181. ICSOApply a
  1182. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1183. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1184. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1185. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,x.MergeID";
  1186. #endregion
  1187. }
  1188. if (Type == "6")
  1189. {
  1190. #region 委外材料出库SQL
  1191. sqls = @" select
  1192. x.MergeID,
  1193. a.IssueCode as Code,
  1194. a.InvCode,
  1195. b.InvName,
  1196. b.InvStd,
  1197. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1198. a.WhCode,
  1199. a.ExtensionID
  1200. FROM
  1201. ICSOIssue a
  1202. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1203. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1204. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1205. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,x.MergeID";
  1206. #endregion
  1207. }
  1208. if (Type == "7")
  1209. {
  1210. #region 销售发货SQL
  1211. sqls = @" select
  1212. x.MergeID,
  1213. a.SDNCode as Code,
  1214. a.InvCode,
  1215. b.InvName,
  1216. b.InvStd,
  1217. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1218. a.WhCode,
  1219. a.ExtensionID
  1220. FROM
  1221. ICSSDN a
  1222. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1223. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1224. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1225. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,x.MergeID";
  1226. #endregion
  1227. }
  1228. if (Type == "8")
  1229. {
  1230. #region 其它出库SQL
  1231. sqls = @" select
  1232. x.MergeID,
  1233. a.OutCode as Code,
  1234. a.InvCode,
  1235. b.InvName,
  1236. b.InvStd,
  1237. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1238. a.WhCode,
  1239. a.ExtensionID
  1240. FROM
  1241. ICSOtherOut a
  1242. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1243. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1244. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1245. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,x.MergeID";
  1246. #endregion
  1247. }
  1248. if (Type == "9")
  1249. {
  1250. #region 借用SQL
  1251. sqls = @" select
  1252. x.MergeID,
  1253. a.BrrowCode as Code,
  1254. a.InvCode,
  1255. b.InvName,
  1256. b.InvStd,
  1257. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1258. a.WhCode,
  1259. a.ExtensionID
  1260. FROM
  1261. ICSBrrow a
  1262. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1263. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1264. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1265. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,x.MergeID";
  1266. #endregion
  1267. }
  1268. if (Type == "10")
  1269. {
  1270. #region 物料调拨
  1271. sqls = @" select
  1272. x.MergeID,
  1273. a.TransferNO as Code,
  1274. a.InvCode,
  1275. b.InvName,
  1276. b.InvStd,
  1277. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1278. a.FromWarehouseCode as WhCode,
  1279. a.ExtensionID
  1280. FROM
  1281. ICSTransfer a
  1282. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1283. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1284. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1285. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  1286. #endregion
  1287. }
  1288. if (Type == "10")
  1289. {
  1290. #region 两步调出
  1291. sqls = @"select
  1292. x.MergeID,
  1293. a.OutCode as Code,
  1294. a.InvCode,
  1295. b.InvName,
  1296. b.InvStd,
  1297. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1298. a.WHCode as WhCode,
  1299. a.ExtensionID
  1300. FROM
  1301. ICSOtherOut a
  1302. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1303. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1304. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1305. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1306. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WHCode,a.ExtensionID,x.MergeID";
  1307. #endregion
  1308. }
  1309. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  1310. sql = string.Format(sql, sqls, WorkPoint);
  1311. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1312. DataTable dtCloned = table.Clone();
  1313. foreach (DataColumn col in dtCloned.Columns)
  1314. {
  1315. col.DataType = typeof(string);
  1316. }
  1317. foreach (DataRow row in table.Rows)
  1318. {
  1319. DataRow newrow = dtCloned.NewRow();
  1320. foreach (DataColumn column in dtCloned.Columns)
  1321. {
  1322. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1323. }
  1324. dtCloned.Rows.Add(newrow);
  1325. }
  1326. if (Invmes.Rows.Count > 0)
  1327. {
  1328. dtCloned.Merge(Invmes, false);
  1329. }
  1330. return dtCloned;
  1331. }
  1332. public string MergeMaterial(string keyValue,string Type)
  1333. {
  1334. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1335. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1336. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1337. string msg = "";
  1338. string sql = string.Empty;
  1339. keyValue = keyValue.TrimEnd(',');
  1340. DateTime time = DateTime.Now;
  1341. string Tday = time.ToString("yyyyMMdd");
  1342. string sqls = string.Format(@"SELECT MAX(A.SourceID) AS SourceID FROM ICSMOPickMerge A WHERE A.SourceID LIKE '{0}%' AND LEN(a.SourceID) = 13", Tday);
  1343. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  1344. string MergeID = "";
  1345. Int64 Merge_ID = 0;
  1346. DataTable dts = ds.Tables[0];
  1347. if (dts != null && dts.Rows.Count > 0)
  1348. {
  1349. string lot = dts.Rows[0]["SourceID"].ToString();
  1350. if (!string.IsNullOrWhiteSpace(lot))
  1351. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  1352. }
  1353. MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  1354. if (Type == "1")//工单备料
  1355. {
  1356. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1357. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1358. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1359. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  1360. where a.MOCode in ({5})
  1361. ";
  1362. }
  1363. if (Type == "2")//工单发料
  1364. {
  1365. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1366. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1367. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1368. from ICSMOApply a
  1369. where a.ApplyCode in ({5})";
  1370. }
  1371. if (Type == "3")//材料出库
  1372. {
  1373. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1374. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1375. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1376. from ICSMOIssue a
  1377. where a.IssueCode in ({5}) ";
  1378. }
  1379. if (Type == "4")//委外备料
  1380. {
  1381. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1382. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1383. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1384. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  1385. where a.OOCode in ({5})";
  1386. }
  1387. if (Type == "5")//委外领料
  1388. {
  1389. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1390. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1391. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1392. from ICSOApply a
  1393. where a.ApplyCode in ({5})";
  1394. }
  1395. if (Type == "6")//委外材料出库
  1396. {
  1397. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1398. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1399. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1400. from ICSOIssue a
  1401. where a.IssueCode in ('{5}')";
  1402. }
  1403. if (Type == "7")//销售发货
  1404. {
  1405. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1406. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1407. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1408. from ICSOIssue a
  1409. where a.IssueCode in ({5})";
  1410. }
  1411. if (Type == "8")//其它出库
  1412. {
  1413. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1414. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1415. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1416. from ICSSDN a
  1417. where a.SDNCode in ({5})";
  1418. }
  1419. if (Type == "9")//借用单
  1420. {
  1421. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1422. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1423. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1424. from ICSOtherOut a
  1425. where a.OutCode in ({5})";
  1426. }
  1427. if (Type == "10")//物料调拨
  1428. {
  1429. sql += @"INSERT INTO dbo.ICSMOPickMerge
  1430. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1431. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1432. from ICSTransfer a
  1433. where a.TransferNO in ({5})
  1434. ";
  1435. }
  1436. if (Type == "11")//两步调出
  1437. {
  1438. sql += @" INSERT INTO dbo.ICSMOPickMerge
  1439. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  1440. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  1441. from ICSOtherOut a
  1442. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1443. where a.OutCode in ({5})
  1444. ";
  1445. }
  1446. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, keyValue);
  1447. try
  1448. {
  1449. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  1450. {
  1451. }
  1452. else
  1453. {
  1454. msg = "新增失败";
  1455. }
  1456. }
  1457. catch (Exception ex)
  1458. {
  1459. throw new Exception(ex.Message);
  1460. }
  1461. return msg;
  1462. }
  1463. public string CheckQty(string objArr)
  1464. {
  1465. objArr= objArr.TrimEnd(',');
  1466. string sql = @"select * from ICSMOPickMerge a
  1467. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  1468. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint
  1469. where MOCode in ({0})";
  1470. sql = string.Format(sql, objArr);
  1471. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  1472. if (dt != null&&dt.Rows.Count>0)
  1473. {
  1474. return "1";
  1475. }
  1476. return "0";
  1477. }
  1478. }
  1479. }