爱思开
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.

1598 lines
76 KiB

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