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.

5095 lines
278 KiB

  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. using Newtonsoft.Json.Linq;
  18. using System.Web.UI.WebControls;
  19. using static NFine.Code.Net;
  20. namespace NFine.Application.WMS
  21. {
  22. public class PickMaterialApp : RepositoryFactory<ICSVendor>
  23. {
  24. public static DataTable Invmes = new DataTable();
  25. //工单备料(工单子件)
  26. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  27. {
  28. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  29. DataTable dt = new DataTable();
  30. var queryParam = queryJson.ToJObject();
  31. List<DbParameter> parameter = new List<DbParameter>();
  32. string sql = "";
  33. #region [SQL]
  34. // 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,
  35. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  36. //from ICSMOPick a
  37. //left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  38. //left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  39. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  40. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  41. // sql += " WHERE 1=1 and e.ID is null";
  42. sql = @"select distinct
  43. a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,d.MergeID AS IsNew,
  44. case when k.TransCode is null then '' else '' end as IsOccupy
  45. from ICSMO a
  46. inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  47. left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
  48. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.MOCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  49. where a.MOStatus<>'3' and a.WorkPoint='{0}'";
  50. sql = string.Format(sql, WorkPoint);
  51. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  52. #endregion
  53. if (!string.IsNullOrWhiteSpace(queryJson))
  54. {
  55. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  56. {
  57. sql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  58. }
  59. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  60. {
  61. sql += " and b.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  62. }
  63. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  64. {
  65. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  66. }
  67. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  68. {
  69. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  70. }
  71. }
  72. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  73. }
  74. //工单备料(工单子件)子表查询
  75. public DataTable GetSubGridJson1(string Code, string Mechanism,string InvCode, ref Pagination jqgridparam)
  76. {
  77. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  78. DataTable dt = new DataTable();
  79. //var queryParam = queryJson.ToJObject();
  80. List<DbParameter> parameter = new List<DbParameter>();
  81. 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,
  82. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  83. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  84. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  85. from ICSMOPick a
  86. left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint and b.MOStatus<>'3'
  87. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  88. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  89. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  90. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  91. where b.MOCode='{0}' and a.WorkPoint='{1}' and a.EATTRIBUTE1<>'1' ";
  92. if (!string.IsNullOrWhiteSpace(Mechanism))
  93. {
  94. sql += " and a.EATTRIBUTE2 = '" + Mechanism + "' ";
  95. }
  96. if (!string.IsNullOrWhiteSpace(InvCode))
  97. {
  98. sql += " and a.InvCode = '" + InvCode + "' ";
  99. }
  100. sql = string.Format(sql, Code, WorkPoint);
  101. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  102. }
  103. //工单领料(发料申请)
  104. public DataTable GetGridJson2(string queryJson, ref Pagination jqgridparam)
  105. {
  106. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  107. DataTable dt = new DataTable();
  108. var queryParam = queryJson.ToJObject();
  109. List<DbParameter> parameter = new List<DbParameter>();
  110. string sql = "";
  111. #region [SQL]
  112. // 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,
  113. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  114. // from ICSMOApply a
  115. // left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint = b.WorkPoint
  116. // left join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  117. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  118. sql = @"
  119. select distinct a.ApplyCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,e.MergeID AS IsNew,
  120. case when k.TransCode is null then '' else '' end as IsOccupy
  121. from ICSMOApply a
  122. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  123. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  124. where a.WorkPoint='{0}'";
  125. sql = string.Format(sql, WorkPoint);
  126. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  127. #endregion
  128. if (!string.IsNullOrWhiteSpace(queryJson))
  129. {
  130. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  131. {
  132. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  133. }
  134. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  135. {
  136. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  137. }
  138. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  139. {
  140. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  141. }
  142. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  143. {
  144. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  145. }
  146. }
  147. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  148. }
  149. //工单领料(发料申请)子表查询
  150. public DataTable GetSubGridJson2(string Code,string InvCode, ref Pagination jqgridparam)
  151. {
  152. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  153. DataTable dt = new DataTable();
  154. //var queryParam = queryJson.ToJObject();
  155. List<DbParameter> parameter = new List<DbParameter>();
  156. 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,
  157. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  158. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  159. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  160. from ICSMOApply a
  161. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  162. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  163. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  164. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  165. where a.ApplyCode='{0}' and a.WorkPoint='{1}'";
  166. if (!string.IsNullOrWhiteSpace(InvCode))
  167. {
  168. sql += " and a.InvCode = '" + InvCode + "' ";
  169. }
  170. sql = string.Format(sql, Code, WorkPoint);
  171. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  172. }
  173. //工单材料出库(材料出库)
  174. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  175. {
  176. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  177. DataTable dt = new DataTable();
  178. var queryParam = queryJson.ToJObject();
  179. List<DbParameter> parameter = new List<DbParameter>();
  180. string sql = "";
  181. #region [SQL]
  182. // 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,
  183. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  184. // from ICSMOIssue a
  185. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  186. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  187. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  188. // sql += " WHERE 1=1 and e.ID is null";
  189. sql = @"select distinct a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,e.MergeID AS IsNew,
  190. case when k.TransCode is null then '' else '' end as IsOccupy
  191. from ICSMOIssue a
  192. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  193. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.IssueCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  194. where a.WorkPoint='{0}'";
  195. sql = string.Format(sql, WorkPoint);
  196. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  197. #endregion
  198. if (!string.IsNullOrWhiteSpace(queryJson))
  199. {
  200. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  201. {
  202. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  203. }
  204. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  205. {
  206. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  207. }
  208. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  209. {
  210. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  211. }
  212. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  213. {
  214. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  215. }
  216. }
  217. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  218. {
  219. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  220. }
  221. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  222. }
  223. //工单材料出库(材料出库)子表查询
  224. public DataTable GetSubGridJson3(string Code, string InvCode, ref Pagination jqgridparam)
  225. {
  226. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  227. DataTable dt = new DataTable();
  228. //var queryParam = queryJson.ToJObject();
  229. List<DbParameter> parameter = new List<DbParameter>();
  230. 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,
  231. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  232. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  233. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  234. from ICSMOIssue a
  235. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  236. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  237. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  238. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  239. where a.IssueCode='{0}' and a.WorkPoint='{1}'";
  240. if (!string.IsNullOrWhiteSpace(InvCode))
  241. {
  242. sql += " and a.InvCode = '" + InvCode + "' ";
  243. }
  244. sql = string.Format(sql, Code, WorkPoint);
  245. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  246. }
  247. //委外备料(委外备料)
  248. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  249. {
  250. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  251. DataTable dt = new DataTable();
  252. var queryParam = queryJson.ToJObject();
  253. List<DbParameter> parameter = new List<DbParameter>();
  254. string sql = "";
  255. #region [SQL]
  256. sql = @"select distinct b.OOCode as Code, b.CreateDateTime as MTIME,b.CreatePerson as MUSER,e.MergeID AS IsNew,
  257. case when k.TransCode is null then '' else '' end as IsOccupy
  258. from ICSOOPick a
  259. inner join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  260. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  261. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on b.OOCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  262. WHERE b.WorkPoint='{0}'";
  263. sql = string.Format(sql, WorkPoint);
  264. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  265. #endregion
  266. if (!string.IsNullOrWhiteSpace(queryJson))
  267. {
  268. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  269. {
  270. sql += " and a.OOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  271. }
  272. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  273. {
  274. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  275. }
  276. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  277. {
  278. sql += " and convert(nvarchar(20),b.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  279. }
  280. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  281. {
  282. sql += " and convert(nvarchar(20),b.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  283. }
  284. }
  285. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  286. {
  287. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  288. }
  289. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  290. }
  291. //委外备料(委外备料)子表查询
  292. public DataTable GetSubGridJson4(string Code, string InvCode, ref Pagination jqgridparam)
  293. {
  294. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  295. DataTable dt = new DataTable();
  296. //var queryParam = queryJson.ToJObject();
  297. List<DbParameter> parameter = new List<DbParameter>();
  298. 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,
  299. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  300. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  301. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  302. from ICSOOPick a
  303. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  304. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  305. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  306. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  307. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  308. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  309. if (!string.IsNullOrWhiteSpace(InvCode))
  310. {
  311. sql += " and a.InvCode = '" + InvCode + "' ";
  312. }
  313. sql = string.Format(sql, Code, WorkPoint);
  314. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  315. }
  316. //委外领料(委外发料申请)
  317. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  318. {
  319. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  320. DataTable dt = new DataTable();
  321. var queryParam = queryJson.ToJObject();
  322. List<DbParameter> parameter = new List<DbParameter>();
  323. string sql = "";
  324. #region [SQL]
  325. // 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,
  326. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  327. // from ICSOApply a
  328. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  329. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  330. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  331. // sql += " WHERE 1=1 and e.ID is null";
  332. sql = @"select distinct a.ApplyCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  333. case when k.TransCode is null then '' else '' end as IsOccupy
  334. from ICSOApply a
  335. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  336. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  337. where a.WorkPoint='{0}'";
  338. sql = string.Format(sql, WorkPoint);
  339. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  340. #endregion
  341. if (!string.IsNullOrWhiteSpace(queryJson))
  342. {
  343. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  344. {
  345. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  346. }
  347. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  348. {
  349. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  350. }
  351. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  352. {
  353. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  354. }
  355. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  356. {
  357. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  358. }
  359. }
  360. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  361. {
  362. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  363. }
  364. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  365. }
  366. //委外领料(委外发料申请)子表查询
  367. public DataTable GetSubGridJson5(string Code, string InvCode, ref Pagination jqgridparam)
  368. {
  369. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  370. DataTable dt = new DataTable();
  371. //var queryParam = queryJson.ToJObject();
  372. List<DbParameter> parameter = new List<DbParameter>();
  373. 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,
  374. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  375. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  376. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  377. from ICSOApply a
  378. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  379. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  380. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  381. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  382. where a.ApplyCode='{0}' and b.WorkPoint='{1}'";
  383. if (!string.IsNullOrWhiteSpace(InvCode))
  384. {
  385. sql += " and a.InvCode = '" + InvCode + "' ";
  386. }
  387. sql = string.Format(sql, Code, WorkPoint);
  388. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  389. }
  390. //委外材料出库(委外发料申请)
  391. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  392. {
  393. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  394. DataTable dt = new DataTable();
  395. var queryParam = queryJson.ToJObject();
  396. List<DbParameter> parameter = new List<DbParameter>();
  397. string sql = "";
  398. #region [SQL]
  399. // 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,
  400. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  401. // from ICSOIssue a
  402. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  403. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  404. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  405. // sql += " WHERE 1=1 and e.ID is null";
  406. sql = @"select distinct a.IssueCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  407. case when k.TransCode is null then '' else '' end as IsOccupy
  408. from ICSOIssue a
  409. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  410. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.IssueCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  411. where a.WorkPoint='{0}'
  412. ";
  413. sql = string.Format(sql, WorkPoint);
  414. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  415. #endregion
  416. if (!string.IsNullOrWhiteSpace(queryJson))
  417. {
  418. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  419. {
  420. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  421. }
  422. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  423. {
  424. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  425. }
  426. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  427. {
  428. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  429. }
  430. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  431. {
  432. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  433. }
  434. }
  435. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  436. {
  437. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  438. }
  439. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  440. }
  441. //委外材料出库(委外发料申请)子表查询
  442. public DataTable GetSubGridJson6(string Code, string InvCode, ref Pagination jqgridparam)
  443. {
  444. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  445. DataTable dt = new DataTable();
  446. //var queryParam = queryJson.ToJObject();
  447. List<DbParameter> parameter = new List<DbParameter>();
  448. string sql = @"select a.ID,a.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,
  449. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  450. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  451. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  452. from ICSOIssue a
  453. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  454. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  455. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  456. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  457. where a.IssueCode='{0}' and b.WorkPoint='{1}'";
  458. if (!string.IsNullOrWhiteSpace(InvCode))
  459. {
  460. sql += " and a.InvCode = '" + InvCode + "' ";
  461. }
  462. sql = string.Format(sql, Code, WorkPoint);
  463. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  464. }
  465. //销售发货(销售发货)
  466. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  467. {
  468. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  469. DataTable dt = new DataTable();
  470. var queryParam = queryJson.ToJObject();
  471. List<DbParameter> parameter = new List<DbParameter>();
  472. string sql = "";
  473. #region [SQL]
  474. // 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,
  475. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  476. // from ICSSDN a
  477. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  478. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  479. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  480. // sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  481. sql = @"select distinct a.SDNCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  482. case when k.TransCode is null then '' else '' end as IsOccupy
  483. from ICSSDN a
  484. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  485. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.SDNCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  486. where a.WorkPoint='{0}' and a.Type='1'";
  487. sql = string.Format(sql, WorkPoint);
  488. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  489. #endregion
  490. if (!string.IsNullOrWhiteSpace(queryJson))
  491. {
  492. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  493. {
  494. sql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  495. }
  496. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  497. {
  498. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  499. }
  500. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  501. {
  502. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  503. }
  504. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  505. {
  506. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  507. }
  508. }
  509. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  510. {
  511. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  512. }
  513. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  514. }
  515. //销售发货(销售发货)子表查询
  516. public DataTable GetSubGridJson7(string Code, string InvCode, ref Pagination jqgridparam)
  517. {
  518. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  519. DataTable dt = new DataTable();
  520. //var queryParam = queryJson.ToJObject();
  521. List<DbParameter> parameter = new List<DbParameter>();
  522. 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,
  523. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  524. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  525. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.SDNQuantity as IssueQuantity
  526. from ICSSDN a
  527. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  528. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  529. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  530. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  531. where a.SDNCode='{0}' and b.WorkPoint='{1}'";
  532. if (!string.IsNullOrWhiteSpace(InvCode))
  533. {
  534. sql += " and a.InvCode = '" + InvCode + "' ";
  535. }
  536. sql = string.Format(sql, Code, WorkPoint);
  537. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  538. }
  539. //其它出库(其它出库)
  540. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  541. {
  542. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  543. DataTable dt = new DataTable();
  544. var queryParam = queryJson.ToJObject();
  545. List<DbParameter> parameter = new List<DbParameter>();
  546. string sql = "";
  547. #region [SQL]
  548. // 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,
  549. //case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  550. //from ICSOtherOut a
  551. //left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  552. //left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  553. //left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  554. // sql += " WHERE 1=1 and e.ID is null ";
  555. sql = @"select distinct a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  556. case when k.TransCode is null then '' else '' end as IsOccupy
  557. from ICSOtherOut a
  558. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  559. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.OutCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  560. where a.WorkPoint='{0}'";
  561. sql = string.Format(sql, WorkPoint);
  562. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  563. #endregion
  564. if (!string.IsNullOrWhiteSpace(queryJson))
  565. {
  566. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  567. {
  568. sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' ";
  569. }
  570. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  571. {
  572. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  573. }
  574. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  575. {
  576. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  577. }
  578. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  579. {
  580. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  581. }
  582. }
  583. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  584. {
  585. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  586. }
  587. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  588. }
  589. //其它出库(其它出库)子表查询
  590. public DataTable GetSubGridJson8(string Code, string InvCode, ref Pagination jqgridparam)
  591. {
  592. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  593. DataTable dt = new DataTable();
  594. //var queryParam = queryJson.ToJObject();
  595. List<DbParameter> parameter = new List<DbParameter>();
  596. 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,
  597. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  598. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  599. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  600. from ICSOtherOut a
  601. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  602. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  603. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  604. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  605. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  606. if (!string.IsNullOrWhiteSpace(InvCode))
  607. {
  608. sql += " and a.InvCode = '" + InvCode + "' ";
  609. }
  610. sql = string.Format(sql, Code, WorkPoint);
  611. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  612. }
  613. //借用(借用)
  614. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  615. {
  616. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  617. DataTable dt = new DataTable();
  618. var queryParam = queryJson.ToJObject();
  619. List<DbParameter> parameter = new List<DbParameter>();
  620. string sql = "";
  621. #region [SQL]
  622. // sql = @"
  623. //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,
  624. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  625. // from ICSBrrow a
  626. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  627. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  628. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  629. // sql += " WHERE 1=1 and e.ID is null ";
  630. sql = @"select distinct a.BrrowCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  631. case when k.TransCode is null then '' else '' end as IsOccupy
  632. from ICSBrrow a
  633. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  634. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.BrrowCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  635. where a.WorkPoint='{0}'";
  636. sql = string.Format(sql, WorkPoint);
  637. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  638. #endregion
  639. if (!string.IsNullOrWhiteSpace(queryJson))
  640. {
  641. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  642. {
  643. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  644. }
  645. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  646. {
  647. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  648. }
  649. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  650. {
  651. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  652. }
  653. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  654. {
  655. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  656. }
  657. }
  658. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  659. {
  660. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  661. }
  662. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  663. }
  664. //借用(借用)子表查询
  665. public DataTable GetSubGridJson9(string Code, string InvCode, ref Pagination jqgridparam)
  666. {
  667. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  668. DataTable dt = new DataTable();
  669. //var queryParam = queryJson.ToJObject();
  670. List<DbParameter> parameter = new List<DbParameter>();
  671. 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,
  672. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  673. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  674. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.BrrowQuantity as IssueQuantity
  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. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  680. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  681. if (!string.IsNullOrWhiteSpace(InvCode))
  682. {
  683. sql += " and a.InvCode = '" + InvCode + "' ";
  684. }
  685. sql = string.Format(sql, Code, WorkPoint);
  686. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  687. }
  688. //物料调拨
  689. public DataTable GetGridJson10(string queryJson, ref Pagination jqgridparam)
  690. {
  691. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  692. DataTable dt = new DataTable();
  693. var queryParam = queryJson.ToJObject();
  694. List<DbParameter> parameter = new List<DbParameter>();
  695. string sql = "";
  696. #region [SQL]
  697. // sql = @"
  698. //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,
  699. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  700. // from ICSBrrow a
  701. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  702. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  703. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  704. // sql += " WHERE 1=1 and e.ID is null ";
  705. sql = @"select distinct a.TransferNO as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  706. case when k.TransCode is null then '' else '' end as IsOccupy
  707. from ICSTransfer a
  708. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  709. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.TransferNO=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  710. where a.WorkPoint='{0}' and a.Status='1'";
  711. sql = string.Format(sql, WorkPoint);
  712. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  713. #endregion
  714. if (!string.IsNullOrWhiteSpace(queryJson))
  715. {
  716. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  717. {
  718. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  719. }
  720. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  721. {
  722. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  723. }
  724. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  725. {
  726. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  727. }
  728. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  729. {
  730. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  731. }
  732. }
  733. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  734. {
  735. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  736. }
  737. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  738. }
  739. //物料调拨子表查询
  740. public DataTable GetSubGridJson10(string Code, string InvCode, ref Pagination jqgridparam)
  741. {
  742. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  743. DataTable dt = new DataTable();
  744. //var queryParam = queryJson.ToJObject();
  745. List<DbParameter> parameter = new List<DbParameter>();
  746. 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,
  747. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  748. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  749. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.TransferQuantity as IssueQuantity
  750. from ICSTransfer a
  751. left join ICSWarehouse b on a.FromWarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  752. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  753. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  754. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  755. where a.TransferNO='{0}' and b.WorkPoint='{1}'";
  756. if (!string.IsNullOrWhiteSpace(InvCode))
  757. {
  758. sql += " and a.InvCode = '" + InvCode + "' ";
  759. }
  760. sql = string.Format(sql, Code, WorkPoint);
  761. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  762. }
  763. //两步调拨
  764. public DataTable GetGridJson11(string queryJson, ref Pagination jqgridparam)
  765. {
  766. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  767. DataTable dt = new DataTable();
  768. var queryParam = queryJson.ToJObject();
  769. List<DbParameter> parameter = new List<DbParameter>();
  770. string sql = "";
  771. #region [SQL]
  772. // sql = @"
  773. //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,
  774. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  775. // from ICSBrrow a
  776. // left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  777. // left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  778. // left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  779. // sql += " WHERE 1=1 and e.ID is null ";
  780. sql = @"select distinct a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  781. case when k.TransCode is null then '' else '' end as IsOccupy
  782. FROM ICSOtherOut a
  783. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  784. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  785. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.OutCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  786. where a.WorkPoint='{0}' and a.Status='2'";
  787. sql = string.Format(sql, WorkPoint);
  788. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  789. #endregion
  790. if (!string.IsNullOrWhiteSpace(queryJson))
  791. {
  792. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  793. {
  794. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  795. }
  796. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  797. {
  798. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  799. }
  800. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  801. {
  802. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  803. }
  804. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  805. {
  806. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  807. }
  808. }
  809. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  810. {
  811. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  812. }
  813. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  814. }
  815. //两步调拨子表查询
  816. public DataTable GetSubGridJson11(string Code, string InvCode, ref Pagination jqgridparam)
  817. {
  818. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  819. DataTable dt = new DataTable();
  820. //var queryParam = queryJson.ToJObject();
  821. List<DbParameter> parameter = new List<DbParameter>();
  822. 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,
  823. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  824. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  825. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.OutQuantity as IssueQuantity
  826. FROM ICSOtherOut a
  827. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  828. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  829. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  830. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  831. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  832. where a.OutCode='{0}' and b.WorkPoint='{1}'";
  833. if (!string.IsNullOrWhiteSpace(InvCode))
  834. {
  835. sql += " and a.InvCode = '" + InvCode + "' ";
  836. }
  837. sql = string.Format(sql, Code, WorkPoint);
  838. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  839. }
  840. #region 拣料旧逻辑
  841. // public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  842. // {
  843. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  844. // #region sql
  845. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  846. // c.Code,
  847. // c.InvCode,
  848. // c.InvName,
  849. // c.InvStd,
  850. //c.InvUnit,
  851. // FLOOR(c.iQuantity) AS iQuantity,
  852. // d.WarehouseCode,
  853. // d.LocationCode,
  854. // d.LotNO,
  855. // FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  856. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  857. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  858. // FROM
  859. // ({0}) c
  860. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
  861. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  862. // 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
  863. //DECLARE @ItemCode VARCHAR(50),
  864. // @QTY DECIMAL(18,3),
  865. // @ItemCodeCurrent VARCHAR(50),
  866. // @QTYCurrent DECIMAL(18,3),
  867. // @iQuantityCurrent DECIMAL(18,3),
  868. // @CanDelete BIT,
  869. // @Row INT,
  870. // @rowCurrent INT
  871. //SET @Row = @@rowcount
  872. //SET @rowCurrent=1
  873. //SET @CanDelete=0
  874. //SET @ItemCode=''
  875. //WHILE @rowCurrent<=@Row
  876. // BEGIN
  877. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  878. //PRINT(@rowCurrent)
  879. // IF @ItemCode<>@ItemCodeCurrent
  880. // BEGIN
  881. // SET @ItemCode=@ItemCodeCurrent
  882. // SET @QTY=0
  883. // SET @CanDelete=0
  884. // END
  885. // IF @CanDelete=1
  886. // BEGIN
  887. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  888. // SET @rowCurrent += 1
  889. // CONTINUE
  890. // END
  891. // SET @QTY += @QTYCurrent
  892. // IF @QTY>=@iQuantityCurrent
  893. // BEGIN
  894. // SET @CanDelete=1
  895. // END
  896. // SET @rowCurrent += 1
  897. // END
  898. //SELECT * FROM #temp
  899. //DROP TABLE #temp
  900. //";
  901. // #endregion
  902. // string sqls = "";
  903. // if (Type == "1")
  904. // {
  905. // #region 工单备料sql
  906. // sqls = @" SELECT
  907. // c.MOCode as Code,
  908. // a.InvCode,
  909. // b.InvName,
  910. // b.InvStd,
  911. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  912. // a.WhCode,
  913. //b.InvUnit,
  914. // a.ExtensionID
  915. // FROM
  916. // ICSMOPick a
  917. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  918. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  919. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  920. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  921. // #endregion
  922. // }
  923. // if (Type == "2")
  924. // {
  925. // #region 工单领料SQL
  926. // sqls = @" select
  927. // a.ApplyCode as Code,
  928. // a.InvCode,
  929. // b.InvName,
  930. // b.InvStd,
  931. //b.InvUnit,
  932. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  933. // a.WhCode,
  934. // a.ExtensionID
  935. // FROM
  936. // ICSMOApply a
  937. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  938. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  939. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  940. // #endregion
  941. // }
  942. // if (Type == "3")
  943. // {
  944. // #region 工单材料出库SQL
  945. // sqls = @" select
  946. // a.IssueCode as Code,
  947. // a.InvCode,
  948. // b.InvName,
  949. // b.InvStd,
  950. //b.InvUnit,
  951. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  952. // a.WhCode,
  953. // a.ExtensionID
  954. // FROM
  955. // ICSMOIssue a
  956. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  957. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  958. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  959. // #endregion
  960. // }
  961. // if (Type == "4")
  962. // {
  963. // #region 委外备料SQL
  964. // sqls = @" select
  965. // c.OOCode as Code,
  966. // a.InvCode,
  967. // b.InvName,
  968. // b.InvStd,
  969. //b.InvUnit,
  970. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  971. // a.WhCode,
  972. // a.ExtensionID
  973. // FROM
  974. // ICSOOPick a
  975. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  976. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  977. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  978. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  979. // #endregion
  980. // }
  981. // if (Type == "5")
  982. // {
  983. // #region 委外领料SQL
  984. // sqls = @" select
  985. // a.ApplyCode as Code,
  986. // a.InvCode,
  987. // b.InvName,
  988. // b.InvStd,
  989. //b.InvUnit,
  990. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  991. // a.WhCode,
  992. // a.ExtensionID
  993. // FROM
  994. // ICSOApply a
  995. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  996. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  997. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  998. // #endregion
  999. // }
  1000. // if (Type == "6")
  1001. // {
  1002. // #region 委外材料出库SQL
  1003. // sqls = @" select
  1004. // a.IssueCode as Code,
  1005. // a.InvCode,
  1006. // b.InvName,
  1007. // b.InvStd,
  1008. //b.InvUnit,
  1009. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1010. // a.WhCode,
  1011. //a.ExtensionID
  1012. // FROM
  1013. // ICSOIssue a
  1014. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1015. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1016. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1017. // #endregion
  1018. // }
  1019. // if (Type == "7")
  1020. // {
  1021. // #region 销售发货SQL
  1022. // sqls = @" select
  1023. // a.SDNCode as Code,
  1024. // a.InvCode,
  1025. // b.InvName,
  1026. // b.InvStd,
  1027. //b.InvUnit,
  1028. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1029. // a.WhCode,
  1030. //a.ExtensionID
  1031. // FROM
  1032. // ICSSDN a
  1033. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1034. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1035. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1036. // #endregion
  1037. // }
  1038. // if (Type == "8")
  1039. // {
  1040. // #region 其它出库SQL
  1041. // sqls = @" select
  1042. // a.OutCode as Code,
  1043. // a.InvCode,
  1044. // b.InvName,
  1045. // b.InvStd,
  1046. //b.InvUnit,
  1047. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1048. // a.WhCode,
  1049. //a.ExtensionID
  1050. // FROM
  1051. // ICSOtherOut a
  1052. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1053. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1054. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1055. // #endregion
  1056. // }
  1057. // if (Type == "9")
  1058. // {
  1059. // #region 借用SQL
  1060. // sqls = @"select
  1061. // a.BrrowCode as Code,
  1062. // a.InvCode,
  1063. // b.InvName,
  1064. // b.InvStd,
  1065. //b.InvUnit,
  1066. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1067. // a.WhCode,
  1068. //a.ExtensionID
  1069. // FROM
  1070. // ICSBrrow a
  1071. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1072. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1073. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1074. // #endregion
  1075. // }
  1076. // if (Type == "10")
  1077. // {
  1078. // #region 物料调拨
  1079. // sqls = @" select
  1080. // a.TransferNO as Code,
  1081. // a.InvCode,
  1082. // b.InvName,
  1083. // b.InvStd,
  1084. //b.InvUnit,
  1085. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1086. // a.FromWarehouseCode as WhCode,
  1087. //a.ExtensionID
  1088. // FROM
  1089. // ICSTransfer a
  1090. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1091. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1092. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1093. // #endregion
  1094. // }
  1095. // if (Type == "11")
  1096. // {
  1097. // #region 两步调出
  1098. // sqls = @"select
  1099. // a.OutCode as Code,
  1100. // a.InvCode,
  1101. // b.InvName,
  1102. // b.InvStd,
  1103. //b.InvUnit,
  1104. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1105. // a.WHCode ,
  1106. //a.ExtensionID
  1107. // from ICSOtherOut a
  1108. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1109. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1110. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1111. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1112. // #endregion
  1113. // }
  1114. // sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  1115. // sql = string.Format(sql, sqls, WorkPoint);
  1116. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  1117. // DataTable dtCloned = table.Clone();
  1118. // foreach (DataColumn col in dtCloned.Columns)
  1119. // {
  1120. // col.DataType = typeof(string);
  1121. // }
  1122. // foreach (DataRow row in table.Rows)
  1123. // {
  1124. // DataRow newrow = dtCloned.NewRow();
  1125. // foreach (DataColumn column in dtCloned.Columns)
  1126. // {
  1127. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1128. // }
  1129. // dtCloned.Rows.Add(newrow);
  1130. // }
  1131. // if (Invmes.Rows.Count > 0)
  1132. // {
  1133. // dtCloned.Merge(Invmes, false);
  1134. // }
  1135. // return dtCloned;
  1136. // }
  1137. #endregion
  1138. public DataTable GetICSMOPickMergeTemp(string ID, string Type, string Mechanism,string InvCode)
  1139. {
  1140. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1141. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1142. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1143. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  1144. string sqls = "";
  1145. string wheresql = "";
  1146. #region 各单据sql
  1147. string Code=SqlHelper.GetItemsDetailEnabledMark("MtimeControl");
  1148. if (Type == "1")
  1149. {
  1150. #region 工单备料sql
  1151. if (!string.IsNullOrWhiteSpace(Mechanism))
  1152. {
  1153. wheresql = " and a.EATTRIBUTE2 = '" + Mechanism + "' ";
  1154. }
  1155. if (!string.IsNullOrWhiteSpace(InvCode))
  1156. {
  1157. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1158. }
  1159. sqls = @" SELECT
  1160. c.MOCode as Code,
  1161. c.Sequence+'~'+a.Sequence as Sequence,
  1162. a.InvCode,
  1163. b.InvName,
  1164. b.InvStd,
  1165. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1166. a.WhCode,
  1167. b.InvUnit,
  1168. a.ExtensionID,
  1169. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1170. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1171. FROM
  1172. ICSMOPick a
  1173. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint and c.MOStatus<>'3'
  1174. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1175. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1176. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) and a.EATTRIBUTE1<>'1' " + wheresql + @" GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.Sequence+'~'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1177. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1178. #endregion
  1179. }
  1180. if (Type == "2")
  1181. {
  1182. if (!string.IsNullOrWhiteSpace(InvCode))
  1183. {
  1184. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1185. }
  1186. sqls = @"select
  1187. a.ApplyCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity, 0))) AS iQuantity, a.WhCode,a.ExtensionID,
  1188. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1189. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1190. FROM
  1191. ICSMOApply a
  1192. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1193. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1194. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  1195. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1196. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1197. }
  1198. if (Type == "3")
  1199. {
  1200. if (!string.IsNullOrWhiteSpace(InvCode))
  1201. {
  1202. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1203. }
  1204. #region 工单材料出库SQL
  1205. sqls = @" select
  1206. a.IssueCode as Code,
  1207. a.Sequence,
  1208. a.InvCode,
  1209. b.InvName,
  1210. b.InvStd,
  1211. b.InvUnit,
  1212. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1213. a.WhCode,
  1214. a.ExtensionID,
  1215. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1216. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1217. FROM
  1218. ICSMOIssue a
  1219. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1220. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1221. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  1222. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1223. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1224. #endregion
  1225. }
  1226. if (Type == "4")
  1227. {
  1228. if (!string.IsNullOrWhiteSpace(InvCode))
  1229. {
  1230. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1231. }
  1232. #region 委外备料SQL
  1233. sqls = @" select
  1234. c.OOCode as Code,
  1235. c.Sequence+'~'+a.Sequence as Sequence,
  1236. a.InvCode,
  1237. b.InvName,
  1238. b.InvStd,
  1239. b.InvUnit,
  1240. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1241. a.WhCode,
  1242. a.ExtensionID,
  1243. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1244. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1245. FROM
  1246. ICSOOPick a
  1247. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1248. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1249. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1250. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  1251. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID,c.Sequence+'~'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1252. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1253. #endregion
  1254. }
  1255. if (Type == "5")
  1256. {
  1257. if (!string.IsNullOrWhiteSpace(InvCode))
  1258. {
  1259. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1260. }
  1261. #region 委外领料SQL
  1262. sqls = @"select
  1263. a.ApplyCode as Code,
  1264. a.Sequence,
  1265. a.InvCode,
  1266. b.InvName,
  1267. b.InvStd,
  1268. b.InvUnit,
  1269. (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity,0))) AS iQuantity,
  1270. a.WhCode,a.ExtensionID,
  1271. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1272. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1273. FROM
  1274. ICSOApply a
  1275. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1276. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1277. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  1278. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1279. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1280. #endregion
  1281. }
  1282. if (Type == "6")
  1283. {
  1284. if (!string.IsNullOrWhiteSpace(InvCode))
  1285. {
  1286. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1287. }
  1288. #region 委外材料出库SQL
  1289. sqls = @" select
  1290. a.IssueCode as Code,
  1291. a.Sequence,
  1292. a.InvCode,
  1293. b.InvName,
  1294. b.InvStd,
  1295. b.InvUnit,
  1296. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1297. a.WhCode,
  1298. a.ExtensionID,
  1299. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1300. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1301. FROM
  1302. ICSOIssue a
  1303. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1304. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1305. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  1306. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1307. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1308. #endregion
  1309. }
  1310. if (Type == "7")
  1311. {
  1312. if (!string.IsNullOrWhiteSpace(InvCode))
  1313. {
  1314. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1315. }
  1316. #region 销售发货SQL
  1317. sqls = @" select
  1318. a.SDNCode as Code,
  1319. a.Sequence,
  1320. a.InvCode,
  1321. b.InvName,
  1322. b.InvStd,
  1323. b.InvUnit,
  1324. (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.SDNQuantity, 0))) AS iQuantity,
  1325. a.WhCode,
  1326. a.ExtensionID,
  1327. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1328. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1329. FROM
  1330. ICSSDN a
  1331. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1332. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1333. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.SDNQuantity, 0)
  1334. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1335. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1336. #endregion
  1337. }
  1338. if (Type == "8")
  1339. {
  1340. if (!string.IsNullOrWhiteSpace(InvCode))
  1341. {
  1342. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1343. }
  1344. #region 其它出库SQL
  1345. sqls = @" select
  1346. a.OutCode as Code,
  1347. a.Sequence,
  1348. a.InvCode,
  1349. b.InvName,
  1350. b.InvStd,
  1351. b.InvUnit,
  1352. (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.OutQuantity, 0))) AS iQuantity,
  1353. a.WhCode,
  1354. a.ExtensionID,
  1355. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1356. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1357. FROM
  1358. ICSOtherOut a
  1359. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1360. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1361. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  1362. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1363. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1364. #endregion
  1365. }
  1366. if (Type == "9")
  1367. {
  1368. if (!string.IsNullOrWhiteSpace(InvCode))
  1369. {
  1370. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1371. }
  1372. #region 借用SQL
  1373. sqls = @"select
  1374. a.BrrowCode as Code,
  1375. a.Sequence,
  1376. a.InvCode,
  1377. b.InvName,
  1378. b.InvStd,
  1379. b.InvUnit,
  1380. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1381. a.WhCode,
  1382. a.ExtensionID,
  1383. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1384. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1385. FROM
  1386. ICSBrrow a
  1387. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1388. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1389. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.BrrowQuantity, 0)
  1390. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1391. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1392. #endregion
  1393. }
  1394. if (Type == "10")
  1395. {
  1396. if (!string.IsNullOrWhiteSpace(InvCode))
  1397. {
  1398. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1399. }
  1400. #region 物料调拨
  1401. sqls = @"select
  1402. a.TransferNO as Code,
  1403. a.Sequence,
  1404. a.InvCode,
  1405. b.InvName,
  1406. b.InvStd,
  1407. b.InvUnit,
  1408. (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,
  1409. a.FromWarehouseCode as WhCode,
  1410. a.ExtensionID,
  1411. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1412. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1413. FROM
  1414. ICSTransfer a
  1415. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1416. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1417. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
  1418. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence,
  1419. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1420. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1421. #endregion
  1422. }
  1423. if (Type == "11")
  1424. {
  1425. if (!string.IsNullOrWhiteSpace(InvCode))
  1426. {
  1427. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1428. }
  1429. #region 两步调出
  1430. sqls = @"select
  1431. a.OutCode as Code,
  1432. a.Sequence,
  1433. a.InvCode,
  1434. b.InvName,
  1435. b.InvStd,
  1436. b.InvUnit,
  1437. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1438. a.WHCode ,
  1439. a.ExtensionID,
  1440. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1441. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1442. from ICSOtherOut a
  1443. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1444. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1445. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1446. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  1447. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1448. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1449. #endregion
  1450. }
  1451. if (Type == "12")
  1452. {
  1453. if (!string.IsNullOrWhiteSpace(InvCode))
  1454. {
  1455. wheresql = " and a.InvCode = '" + InvCode + "' ";
  1456. }
  1457. #region 补料
  1458. sqls = @" select
  1459. a.ReplenishmentCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity, 0))) AS iQuantity, a.WhCode,a.ExtensionID,
  1460. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1461. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1462. FROM
  1463. ICSMOReplenishment a
  1464. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1465. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1466. WHERE a.ReplenishmentCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  1467. GROUP BY a.ReplenishmentCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,
  1468. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1469. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  1470. #endregion
  1471. }
  1472. #endregion
  1473. sqls = string.Format(sqls, ID, WorkPoint);
  1474. string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1475. c.Code,
  1476. c.Sequence,
  1477. c.InvCode,
  1478. c.InvName,
  1479. c.InvStd,
  1480. c.InvUnit,
  1481. c.iQuantity AS iQuantity,
  1482. c.WHCode AS WarehouseCode,
  1483. d.LotNO,
  1484. ISNULL(d.Quantity, 0) AS QTY,
  1485. ISNULL(d.Quantity, 0) AS QTYLeft,
  1486. CONVERT(decimal(18,6),0) AS SendQTY,
  1487. d.LocationCode AS LocationCode,
  1488. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1489. f.QTYTotal QTYTotal,c.ExtensionID
  1490. FROM
  1491. ({sqls}) c
  1492. left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.inDate,d.LocationCode,m.ExtensionID ,m.ProductDate,m.ExpirationDate,
  1493. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  1494. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  1495. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  1496. LEFT JOIN ICSExtension f on m.ExtensionID=f.ID and m.WorkPoint=f.WorkPoint
  1497. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  1498. and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0
  1499. ) d
  1500. on c.InvCode=d.INVCode
  1501. AND (LEN(ISNULL(c.WHCode,''))<=0 OR (LEN(ISNULL(c.WHCode,''))>0 AND c.WHCode=d.WarehouseCode))
  1502. AND (LEN(ISNULL(c.ProjectCode,''))<=0 OR (LEN(ISNULL(c.ProjectCode,''))>0 AND c.ProjectCode=d.ProjectCode))
  1503. AND (LEN(ISNULL(c.BatchCode,''))<=0 OR (LEN(ISNULL(c.BatchCode,''))>0 AND c.BatchCode=d.BatchCode))
  1504. AND (LEN(ISNULL(c.Version,''))<=0 OR (LEN(ISNULL(c.Version,''))>0 AND c.Version=d.Version))
  1505. AND (LEN(ISNULL(c.Brand,''))<=0 OR (LEN(ISNULL(c.Brand,''))>0 AND c.Brand=d.Brand))
  1506. AND (LEN(ISNULL(c.cFree1,''))<=0 OR (LEN(ISNULL(c.cFree1,''))>0 AND c.cFree1=d.cFree1))
  1507. AND (LEN(ISNULL(c.cFree2,''))<=0 OR (LEN(ISNULL(c.cFree2,''))>0 AND c.cFree2=d.cFree2))
  1508. AND (LEN(ISNULL(c.cFree3,''))<=0 OR (LEN(ISNULL(c.cFree3,''))>0 AND c.cFree3=d.cFree3))
  1509. AND (LEN(ISNULL(c.cFree4,''))<=0 OR (LEN(ISNULL(c.cFree4,''))>0 AND c.cFree4=d.cFree4))
  1510. AND (LEN(ISNULL(c.cFree5,''))<=0 OR (LEN(ISNULL(c.cFree5,''))>0 AND c.cFree5=d.cFree5))
  1511. AND (LEN(ISNULL(c.cFree6,''))<=0 OR (LEN(ISNULL(c.cFree6,''))>0 AND c.cFree6=d.cFree6))
  1512. AND (LEN(ISNULL(c.cFree7,''))<=0 OR (LEN(ISNULL(c.cFree7,''))>0 AND c.cFree7=d.cFree7))
  1513. AND (LEN(ISNULL(c.cFree8,''))<=0 OR (LEN(ISNULL(c.cFree8,''))>0 AND c.cFree8=d.cFree8))
  1514. AND (LEN(ISNULL(c.cFree9,''))<=0 OR (LEN(ISNULL(c.cFree9,''))>0 AND c.cFree9=d.cFree9))
  1515. AND (LEN(ISNULL(c.cFree10,''))<=0 OR (LEN(ISNULL(c.cFree10,''))>0 AND c.cFree10=d.cFree10))
  1516. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  1517. ";
  1518. // sql = string.Format(sql, sqls)1;
  1519. if (Code == "MC00002")
  1520. {
  1521. sql += "order by d.inDate";
  1522. }
  1523. else if(Code == "MC00001")
  1524. {
  1525. sql += " order BY ISNULL(d.ProductDate,d.ExpirationDate)";
  1526. }
  1527. else
  1528. {
  1529. sql += " order BY ISNULL(d.ExpirationDate,d.ProductDate)";
  1530. }
  1531. var dataset = Repository().FindDataSetBySql(sql);
  1532. if (dataset.Tables[0].Rows.Count == 0)
  1533. return null;
  1534. DataTable table = dataset.Tables[0];
  1535. decimal qtyCount = 0;
  1536. bool remove = false;
  1537. List<int> removeList = new List<int>();
  1538. for (int i = 0; i < table.Rows.Count; i++)
  1539. {
  1540. if (i != 0
  1541. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  1542. || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
  1543. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  1544. || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  1545. )
  1546. {
  1547. qtyCount = 0;
  1548. remove = false;
  1549. }
  1550. if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0 && table.Rows[i]["LotNO"].ToString() != "")
  1551. {
  1552. table.Rows[i]["LotNO"] = "";
  1553. string a = "0.000000";
  1554. table.Rows[i]["QTY"] =Convert.ToDecimal(a);
  1555. //removeList.Add(i);
  1556. continue;
  1557. }
  1558. if (remove && table.Rows[i]["LotNO"].ToString() != "")
  1559. {
  1560. removeList.Add(i);
  1561. }
  1562. else
  1563. {
  1564. var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  1565. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  1566. qtyCount += lotQty;
  1567. foreach (DataRow dr in table.Rows)
  1568. {
  1569. if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  1570. {
  1571. if (qtyCount > orderQty)
  1572. {
  1573. dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  1574. }
  1575. else
  1576. {
  1577. dr["QTYLeft"] = 0;
  1578. }
  1579. }
  1580. }
  1581. if (qtyCount >= orderQty)
  1582. {
  1583. table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  1584. remove = true;
  1585. }
  1586. else
  1587. {
  1588. table.Rows[i]["SendQTY"] = lotQty;
  1589. }
  1590. }
  1591. }
  1592. if (removeList.Count > 0)
  1593. {
  1594. removeList.Reverse();
  1595. foreach (var item in removeList)
  1596. {
  1597. table.Rows.RemoveAt(item);
  1598. }
  1599. }
  1600. try
  1601. {
  1602. #region 旧卡控
  1603. //string chksql = "";
  1604. //if (Type == "2" || Type == "12")
  1605. //{
  1606. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSMOApply
  1607. // where ApplyCode in ({0}) and WorkPoint='{1}'
  1608. // GROUP BY InvCode,WHCode";
  1609. //}
  1610. //if (Type == "5")
  1611. //{
  1612. // #region 委外领料SQL
  1613. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOApply
  1614. // where ApplyCode in ({0}) and WorkPoint='{1}'
  1615. // GROUP BY InvCode,WHCode";
  1616. // #endregion
  1617. //}
  1618. //if (Type == "7")
  1619. //{
  1620. // #region 销售发货SQL
  1621. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSSDN
  1622. // where SDNCode in ({0}) and WorkPoint='{1}'
  1623. // GROUP BY InvCode,WHCode";
  1624. // #endregion
  1625. //}
  1626. //if (Type == "8")
  1627. //{
  1628. // #region 其它出库SQL
  1629. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOtherOut
  1630. // where OutCode in ({0}) and WorkPoint='{1}'
  1631. // GROUP BY InvCode,WHCode";
  1632. // #endregion
  1633. //}
  1634. //if (Type == "10")
  1635. //{
  1636. // #region 物料调拨
  1637. // chksql = @" select InvCode,FromWarehouseCode AS WHCode,SUM(Quantity) as Quantity from ICSTransfer
  1638. // where TransferNO in ({0}) and WorkPoint='{1}'
  1639. // GROUP BY InvCode,FromWarehouseCode";
  1640. // #endregion
  1641. //}
  1642. //chksql = string.Format(chksql, ID, WorkPoint);
  1643. //var chkdata = Repository().FindDataSetBySql(chksql);
  1644. //DataTable chktable = chkdata.Tables[0];
  1645. //foreach (DataRow chkdr in chktable.Rows)
  1646. //{
  1647. // decimal ZLQty = 0;
  1648. // for (int i = 0; i < table.Rows.Count; i++)
  1649. // {
  1650. // if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString()
  1651. // && table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString())
  1652. // {
  1653. // ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
  1654. // }
  1655. // }
  1656. // if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty)
  1657. // {
  1658. // throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。");
  1659. // }
  1660. //}
  1661. #endregion
  1662. DataRow[] dss = table.Select("LotNO=''");
  1663. foreach (var item in dss)
  1664. {
  1665. DataRow[] dsss = table.Select("Code='" + item["Code"].ToString() + "' and Sequence='" + item["Sequence"].ToString() + "' and LotNO <> '' ");
  1666. if (dsss != null && dsss.Length > 0)
  1667. {
  1668. table.Rows.Remove(item);
  1669. }
  1670. }
  1671. var result = ConvertCellToString(table);
  1672. if (Invmes.Rows.Count > 0)
  1673. {
  1674. result.Merge(Invmes, false);
  1675. }
  1676. return result;
  1677. }
  1678. catch (Exception ex)
  1679. {
  1680. throw new Exception(ex.Message);
  1681. }
  1682. }
  1683. public DataTable ConvertCellToString(DataTable data)
  1684. {
  1685. DataTable dtCloned = data.Clone();
  1686. foreach (DataColumn col in dtCloned.Columns)
  1687. {
  1688. col.DataType = typeof(string);
  1689. }
  1690. foreach (DataRow row in data.Rows)
  1691. {
  1692. DataRow newrow = dtCloned.NewRow();
  1693. foreach (DataColumn column in dtCloned.Columns)
  1694. {
  1695. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  1696. }
  1697. dtCloned.Rows.Add(newrow);
  1698. }
  1699. return dtCloned;
  1700. }
  1701. #region 合并拣料旧
  1702. // public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  1703. // {
  1704. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1705. // #region sql
  1706. // string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1707. // c.MergeID,
  1708. // c.Code,
  1709. // c.InvCode,
  1710. // c.InvName,
  1711. // c.InvStd,
  1712. //c.InvUnit,
  1713. // FLOOR(c.iQuantity) AS iQuantity,
  1714. // d.WarehouseCode,
  1715. // d.LocationCode,
  1716. // d.LotNO,
  1717. // FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1718. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1719. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1720. // FROM
  1721. // ({0}) c
  1722. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0)) AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
  1723. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1724. // 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
  1725. //DECLARE @ItemCode VARCHAR(50),
  1726. // @QTY DECIMAL(18,3),
  1727. // @ItemCodeCurrent VARCHAR(50),
  1728. // @QTYCurrent DECIMAL(18,3),
  1729. // @iQuantityCurrent DECIMAL(18,3),
  1730. // @CanDelete BIT,
  1731. // @Row INT,
  1732. // @rowCurrent INT
  1733. //SET @Row = @@rowcount
  1734. //SET @rowCurrent=1
  1735. //SET @CanDelete=0
  1736. //SET @ItemCode=''
  1737. //WHILE @rowCurrent<=@Row
  1738. // BEGIN
  1739. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1740. //PRINT(@rowCurrent)
  1741. // IF @ItemCode<>@ItemCodeCurrent
  1742. // BEGIN
  1743. // SET @ItemCode=@ItemCodeCurrent
  1744. // SET @QTY=0
  1745. // SET @CanDelete=0
  1746. // END
  1747. // IF @CanDelete=1
  1748. // BEGIN
  1749. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  1750. // SET @rowCurrent += 1
  1751. // CONTINUE
  1752. // END
  1753. // SET @QTY += @QTYCurrent
  1754. // IF @QTY>=@iQuantityCurrent
  1755. // BEGIN
  1756. // SET @CanDelete=1
  1757. // END
  1758. // SET @rowCurrent += 1
  1759. // END
  1760. //SELECT * FROM #temp
  1761. //DROP TABLE #temp
  1762. //";
  1763. // #endregion
  1764. // string sqls = "";
  1765. // if (Type == "1")
  1766. // {
  1767. // #region 工单备料sql
  1768. // sqls = @" select
  1769. // x.MergeID,
  1770. // c.MOCode as Code,
  1771. // a.InvCode,
  1772. // b.InvName,
  1773. // b.InvStd,
  1774. //b.InvUnit,
  1775. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1776. // a.WhCode,
  1777. //a.ExtensionID
  1778. // FROM
  1779. // ICSMOPick a
  1780. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1781. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1782. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1783. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  1784. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1785. // #endregion
  1786. // }
  1787. // if (Type == "2")
  1788. // {
  1789. // #region 工单领料SQL
  1790. // sqls = @" select
  1791. // x.MergeID,
  1792. // a.ApplyCode as Code,
  1793. // a.InvCode,
  1794. // b.InvName,
  1795. // b.InvStd,
  1796. //b.InvUnit,
  1797. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1798. // a.WhCode,
  1799. // a.ExtensionID
  1800. // FROM
  1801. // ICSMOApply a
  1802. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1803. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1804. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1805. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID";
  1806. // #endregion
  1807. // }
  1808. // if (Type == "3")
  1809. // {
  1810. // #region 工单材料出库SQL
  1811. // sqls = @" select
  1812. // x.MergeID,
  1813. // a.IssueCode as Code,
  1814. // a.InvCode,
  1815. // b.InvName,
  1816. // b.InvStd,
  1817. //b.InvUnit,
  1818. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1819. // a.WhCode,
  1820. //a.ExtensionID
  1821. // FROM
  1822. // ICSMOIssue a
  1823. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1824. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1825. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1826. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1827. // #endregion
  1828. // }
  1829. // if (Type == "4")
  1830. // {
  1831. // #region 委外备料SQL
  1832. // sqls = @" select
  1833. // x.MergeID,
  1834. // c.OOCode as Code,
  1835. // a.InvCode,
  1836. // b.InvName,
  1837. // b.InvStd,
  1838. //b.InvUnit,
  1839. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1840. // a.WhCode,
  1841. //a.ExtensionID
  1842. // FROM
  1843. // ICSOOPick a
  1844. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1845. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1846. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1847. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1848. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID";
  1849. // #endregion
  1850. // }
  1851. // if (Type == "5")
  1852. // {
  1853. // #region 委外领料SQL
  1854. // sqls = @" select
  1855. // x.MergeID,
  1856. // a.ApplyCode as Code,
  1857. // a.InvCode,
  1858. // b.InvName,
  1859. // b.InvStd,
  1860. //b.InvUnit,
  1861. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1862. // a.WhCode,
  1863. //a.ExtensionID
  1864. // FROM
  1865. // ICSOApply a
  1866. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1867. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1868. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1869. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1870. // #endregion
  1871. // }
  1872. // if (Type == "6")
  1873. // {
  1874. // #region 委外材料出库SQL
  1875. // sqls = @" select
  1876. // x.MergeID,
  1877. // a.IssueCode as Code,
  1878. // a.InvCode,
  1879. // b.InvName,
  1880. // b.InvStd,
  1881. //b.InvUnit,
  1882. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1883. // a.WhCode,
  1884. //a.ExtensionID
  1885. // FROM
  1886. // ICSOIssue a
  1887. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1888. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1889. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1890. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1891. // #endregion
  1892. // }
  1893. // if (Type == "7")
  1894. // {
  1895. // #region 销售发货SQL
  1896. // sqls = @" select
  1897. // x.MergeID,
  1898. // a.SDNCode as Code,
  1899. // a.InvCode,
  1900. // b.InvName,
  1901. // b.InvStd,
  1902. //b.InvUnit,
  1903. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1904. // a.WhCode,
  1905. //a.ExtensionID
  1906. // FROM
  1907. // ICSSDN a
  1908. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1909. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1910. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  1911. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1912. // #endregion
  1913. // }
  1914. // if (Type == "8")
  1915. // {
  1916. // #region 其它出库SQL
  1917. // sqls = @" select
  1918. // x.MergeID,
  1919. // a.OutCode as Code,
  1920. // a.InvCode,
  1921. // b.InvName,
  1922. // b.InvStd,
  1923. //b.InvUnit,
  1924. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1925. // a.WhCode,
  1926. //a.ExtensionID
  1927. // FROM
  1928. // ICSOtherOut a
  1929. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1930. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1931. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1932. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1933. // #endregion
  1934. // }
  1935. // if (Type == "9")
  1936. // {
  1937. // #region 借用SQL
  1938. // sqls = @" select
  1939. // x.MergeID,
  1940. // a.BrrowCode as Code,
  1941. // a.InvCode,
  1942. // b.InvName,
  1943. // b.InvStd,
  1944. //b.InvUnit,
  1945. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1946. // a.WhCode,
  1947. //a.ExtensionID
  1948. // FROM
  1949. // ICSBrrow a
  1950. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1951. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1952. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1953. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID";
  1954. // #endregion
  1955. // }
  1956. // if (Type == "10")
  1957. // {
  1958. // #region 物料调拨
  1959. // sqls = @" select
  1960. // x.MergeID,
  1961. // a.TransferNO as Code,
  1962. // a.InvCode,
  1963. // b.InvName,
  1964. // b.InvStd,
  1965. //b.InvUnit,
  1966. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1967. // a.FromWarehouseCode as WhCode,
  1968. //a.ExtensionID
  1969. // FROM
  1970. // ICSTransfer a
  1971. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1972. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1973. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1974. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID";
  1975. // #endregion
  1976. // }
  1977. // if (Type == "10")
  1978. // {
  1979. // #region 两步调出
  1980. // sqls = @"select
  1981. // x.MergeID,
  1982. // a.OutCode as Code,
  1983. // a.InvCode,
  1984. // b.InvName,
  1985. // b.InvStd,
  1986. //b.InvUnit,
  1987. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1988. // a.WHCode as WhCode,
  1989. //a.ExtensionID
  1990. // FROM
  1991. // ICSOtherOut a
  1992. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1993. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  1994. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1995. //WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1996. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID";
  1997. // #endregion
  1998. // }
  1999. // sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2000. // sql = string.Format(sql, sqls, WorkPoint);
  2001. // DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  2002. // DataTable dtCloned = table.Clone();
  2003. // foreach (DataColumn col in dtCloned.Columns)
  2004. // {
  2005. // col.DataType = typeof(string);
  2006. // }
  2007. // foreach (DataRow row in table.Rows)
  2008. // {
  2009. // DataRow newrow = dtCloned.NewRow();
  2010. // foreach (DataColumn column in dtCloned.Columns)
  2011. // {
  2012. // newrow[column.ColumnName] = row[column.ColumnName].ToString();
  2013. // }
  2014. // dtCloned.Rows.Add(newrow);
  2015. // }
  2016. // if (Invmes.Rows.Count > 0)
  2017. // {
  2018. // dtCloned.Merge(Invmes, false);
  2019. // }
  2020. // return dtCloned;
  2021. // }
  2022. #endregion
  2023. public DataTable GetICSMOPickMergeTemp2(string ID, string Type, string Mechanism,string InvCode)
  2024. {
  2025. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2026. string sqls = "";
  2027. string wheresql = "";
  2028. #region 各单据sql
  2029. string Code = SqlHelper.GetItemsDetailEnabledMark("MtimeControl");
  2030. if (Type == "1")
  2031. {
  2032. if (!string.IsNullOrWhiteSpace(Mechanism))
  2033. {
  2034. wheresql = " and a.EATTRIBUTE2 = '" + Mechanism + "' ";
  2035. }
  2036. if (!string.IsNullOrWhiteSpace(InvCode))
  2037. {
  2038. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2039. }
  2040. #region 工单备料sql
  2041. sqls = @" select
  2042. x.MergeID,
  2043. c.MOCode as Code,
  2044. c.Sequence+'~'+a.Sequence as Sequence,
  2045. a.InvCode,
  2046. b.InvName,
  2047. b.InvStd,
  2048. b.InvUnit,
  2049. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2050. a.WhCode,
  2051. a.ExtensionID,
  2052. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2053. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2054. FROM
  2055. ICSMOPick a
  2056. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2057. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint and c.MOStatus<>'3'
  2058. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2059. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2060. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) and a.EATTRIBUTE1<>'1' " + wheresql + @" GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID,c.Sequence+'~'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2061. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2062. #endregion
  2063. }
  2064. if (Type == "2")
  2065. {
  2066. if (!string.IsNullOrWhiteSpace(InvCode))
  2067. {
  2068. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2069. }
  2070. #region 工单领料SQL
  2071. sqls = @" select
  2072. x.MergeID,
  2073. a.ApplyCode as Code,
  2074. a.Sequence,
  2075. a.InvCode,
  2076. b.InvName,
  2077. b.InvStd,
  2078. b.InvUnit,
  2079. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2080. a.WhCode,
  2081. a.ExtensionID,
  2082. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2083. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2084. FROM
  2085. ICSMOApply a
  2086. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2087. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2088. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2089. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  2090. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID,a.Sequence,
  2091. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2092. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2093. #endregion
  2094. }
  2095. if (Type == "3")
  2096. {
  2097. if (!string.IsNullOrWhiteSpace(InvCode))
  2098. {
  2099. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2100. }
  2101. #region 工单材料出库SQL
  2102. sqls = @" select
  2103. x.MergeID,
  2104. a.IssueCode as Code,
  2105. a.Sequence,
  2106. a.InvCode,
  2107. b.InvName,
  2108. b.InvStd,
  2109. b.InvUnit,
  2110. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2111. a.WhCode,
  2112. a.ExtensionID,
  2113. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2114. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2115. FROM
  2116. ICSMOIssue a
  2117. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2118. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2119. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2120. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  2121. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,
  2122. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2123. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2124. #endregion
  2125. }
  2126. if (Type == "4")
  2127. {
  2128. if (!string.IsNullOrWhiteSpace(InvCode))
  2129. {
  2130. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2131. }
  2132. #region 委外备料SQL
  2133. sqls = @" select
  2134. x.MergeID,
  2135. c.OOCode as Code,
  2136. c.Sequence+'~'+a.Sequence as Sequence,
  2137. a.InvCode,
  2138. b.InvName,
  2139. b.InvStd,
  2140. b.InvUnit,
  2141. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2142. a.WhCode,
  2143. a.ExtensionID,
  2144. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2145. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2146. FROM
  2147. ICSOOPick a
  2148. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2149. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  2150. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2151. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2152. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  2153. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID,c.Sequence+'~'+a.Sequence,
  2154. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2155. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2156. #endregion
  2157. }
  2158. if (Type == "5")
  2159. {
  2160. if (!string.IsNullOrWhiteSpace(InvCode))
  2161. {
  2162. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2163. }
  2164. #region 委外领料SQL
  2165. sqls = @" select
  2166. x.MergeID,
  2167. a.ApplyCode as Code,
  2168. a.Sequence,
  2169. a.InvCode,
  2170. b.InvName,
  2171. b.InvStd,
  2172. b.InvUnit,
  2173. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2174. a.WhCode,
  2175. a.ExtensionID,
  2176. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2177. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2178. FROM
  2179. ICSOApply a
  2180. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2181. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2182. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2183. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  2184. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,
  2185. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2186. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2187. #endregion
  2188. }
  2189. if (Type == "6")
  2190. {
  2191. if (!string.IsNullOrWhiteSpace(InvCode))
  2192. {
  2193. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2194. }
  2195. #region 委外材料出库SQL
  2196. sqls = @" select
  2197. x.MergeID,
  2198. a.IssueCode as Code,
  2199. a.Sequence,
  2200. a.InvCode,
  2201. b.InvName,
  2202. b.InvStd,
  2203. b.InvUnit,
  2204. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2205. a.WhCode,
  2206. a.ExtensionID,
  2207. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2208. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2209. FROM
  2210. ICSOIssue a
  2211. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2212. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2213. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2214. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  2215. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,
  2216. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2217. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2218. #endregion
  2219. }
  2220. if (Type == "7")
  2221. {
  2222. if (!string.IsNullOrWhiteSpace(InvCode))
  2223. {
  2224. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2225. }
  2226. #region 销售发货SQL
  2227. sqls = @" select
  2228. x.MergeID,
  2229. a.SDNCode as Code,
  2230. a.Sequence,
  2231. a.InvCode,
  2232. b.InvName,
  2233. b.InvStd,
  2234. b.InvUnit,
  2235. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2236. a.WhCode,
  2237. a.ExtensionID,
  2238. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2239. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2240. FROM
  2241. ICSSDN a
  2242. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2243. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2244. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2245. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND a.Type='1' AND ISNULL(a.Quantity, 0)>ISNULL(a.SDNQuantity, 0)
  2246. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2247. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2248. #endregion
  2249. }
  2250. if (Type == "8")
  2251. {
  2252. if (!string.IsNullOrWhiteSpace(InvCode))
  2253. {
  2254. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2255. }
  2256. #region 其它出库SQL
  2257. sqls = @" select
  2258. x.MergeID,
  2259. a.OutCode as Code,
  2260. a.Sequence,
  2261. a.InvCode,
  2262. b.InvName,
  2263. b.InvStd,
  2264. b.InvUnit,
  2265. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2266. a.WhCode,
  2267. a.ExtensionID,
  2268. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2269. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2270. FROM
  2271. ICSOtherOut a
  2272. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2273. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2274. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2275. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  2276. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,
  2277. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2278. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2279. #endregion
  2280. }
  2281. if (Type == "9")
  2282. {
  2283. if (!string.IsNullOrWhiteSpace(InvCode))
  2284. {
  2285. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2286. }
  2287. #region 借用SQL
  2288. sqls = @" select
  2289. x.MergeID,
  2290. a.BrrowCode as Code,
  2291. a.Sequence,
  2292. a.InvCode,
  2293. b.InvName,
  2294. b.InvStd,
  2295. b.InvUnit,
  2296. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2297. a.WhCode,
  2298. a.ExtensionID,
  2299. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2300. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2301. FROM
  2302. ICSBrrow a
  2303. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2304. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2305. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2306. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.BrrowQuantity, 0)
  2307. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,
  2308. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2309. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2310. #endregion
  2311. }
  2312. if (Type == "10")
  2313. {
  2314. if (!string.IsNullOrWhiteSpace(InvCode))
  2315. {
  2316. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2317. }
  2318. #region 物料调拨
  2319. sqls = @" select
  2320. x.MergeID,
  2321. a.TransferNO as Code,
  2322. a.Sequence,
  2323. a.InvCode,
  2324. b.InvName,
  2325. b.InvStd,
  2326. b.InvUnit,
  2327. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2328. a.FromWarehouseCode as WhCode,
  2329. a.ExtensionID,
  2330. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2331. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2332. FROM
  2333. ICSTransfer a
  2334. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2335. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2336. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2337. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
  2338. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID,a.Sequence,
  2339. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2340. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2341. #endregion
  2342. }
  2343. if (Type == "11")
  2344. {
  2345. if (!string.IsNullOrWhiteSpace(InvCode))
  2346. {
  2347. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2348. }
  2349. #region 两步调出
  2350. sqls = @" select
  2351. x.MergeID,
  2352. a.OutCode as Code,
  2353. a.Sequence,
  2354. a.InvCode,
  2355. b.InvName,
  2356. b.InvStd,
  2357. b.InvUnit,
  2358. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2359. a.WHCode as WhCode,
  2360. a.ExtensionID,
  2361. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2362. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2363. FROM
  2364. ICSOtherOut a
  2365. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2366. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2367. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2368. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2369. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  2370. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID,a.Sequence,
  2371. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2372. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2373. #endregion
  2374. }
  2375. if (Type == "12")
  2376. {
  2377. if (!string.IsNullOrWhiteSpace(InvCode))
  2378. {
  2379. wheresql = " and a.InvCode = '" + InvCode + "' ";
  2380. }
  2381. #region 补料
  2382. sqls = @" select
  2383. x.MergeID,
  2384. a.ReplenishmentCode as Code,
  2385. a.Sequence,
  2386. a.InvCode,
  2387. b.InvName,
  2388. b.InvStd,
  2389. b.InvUnit,
  2390. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2391. a.WhCode,
  2392. a.ExtensionID,
  2393. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2394. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2395. FROM
  2396. ICSMOReplenishment a
  2397. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  2398. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2399. LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2400. WHERE a.ReplenishmentCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  2401. GROUP BY a.ReplenishmentCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID,a.Sequence,
  2402. f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2403. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  2404. #endregion
  2405. }
  2406. #endregion
  2407. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  2408. #region sql
  2409. string sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  2410. c.MergeID,
  2411. c.Code,
  2412. c.Sequence,
  2413. c.InvCode,
  2414. c.InvName,
  2415. c.InvStd,
  2416. c.InvUnit,
  2417. FLOOR(c.iQuantity) AS iQuantity,
  2418. d.WarehouseCode,
  2419. d.LocationCode,
  2420. d.LotNO,
  2421. ISNULL(d.Quantity, 0) AS QTY,
  2422. ISNULL(d.Quantity, 0) AS QTYLeft,
  2423. CONVERT(decimal(18,6),0) AS SendQTY,
  2424. d.LocationCode AS LocationCode,
  2425. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  2426. f.QTYTotal QTYTotal,c.ExtensionID
  2427. FROM
  2428. ({sqls}) c
  2429. inner join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.inDate,d.LocationCode,m.ExtensionID ,,m.ProductDate,m.ExpirationDate, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2430. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2431. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  2432. LEFT JOIN ICSExtension f on m.ExtensionID=f.ID and m.WorkPoint=f.WorkPoint
  2433. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2434. and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND isnull(d.Quantity,0)>0 ) d
  2435. on c.InvCode=d.INVCode
  2436. AND (LEN(ISNULL(c.WHCode,''))<=0 OR (LEN(ISNULL(c.WHCode,''))>0 AND c.WHCode=d.WarehouseCode))
  2437. AND (LEN(ISNULL(c.ProjectCode,''))<=0 OR (LEN(ISNULL(c.ProjectCode,''))>0 AND c.ProjectCode=d.ProjectCode))
  2438. AND (LEN(ISNULL(c.BatchCode,''))<=0 OR (LEN(ISNULL(c.BatchCode,''))>0 AND c.BatchCode=d.BatchCode))
  2439. AND (LEN(ISNULL(c.Version,''))<=0 OR (LEN(ISNULL(c.Version,''))>0 AND c.Version=d.Version))
  2440. AND (LEN(ISNULL(c.Brand,''))<=0 OR (LEN(ISNULL(c.Brand,''))>0 AND c.Brand=d.Brand))
  2441. AND (LEN(ISNULL(c.cFree1,''))<=0 OR (LEN(ISNULL(c.cFree1,''))>0 AND c.cFree1=d.cFree1))
  2442. AND (LEN(ISNULL(c.cFree2,''))<=0 OR (LEN(ISNULL(c.cFree2,''))>0 AND c.cFree2=d.cFree2))
  2443. AND (LEN(ISNULL(c.cFree3,''))<=0 OR (LEN(ISNULL(c.cFree3,''))>0 AND c.cFree3=d.cFree3))
  2444. AND (LEN(ISNULL(c.cFree4,''))<=0 OR (LEN(ISNULL(c.cFree4,''))>0 AND c.cFree4=d.cFree4))
  2445. AND (LEN(ISNULL(c.cFree5,''))<=0 OR (LEN(ISNULL(c.cFree5,''))>0 AND c.cFree5=d.cFree5))
  2446. AND (LEN(ISNULL(c.cFree6,''))<=0 OR (LEN(ISNULL(c.cFree6,''))>0 AND c.cFree6=d.cFree6))
  2447. AND (LEN(ISNULL(c.cFree7,''))<=0 OR (LEN(ISNULL(c.cFree7,''))>0 AND c.cFree7=d.cFree7))
  2448. AND (LEN(ISNULL(c.cFree8,''))<=0 OR (LEN(ISNULL(c.cFree8,''))>0 AND c.cFree8=d.cFree8))
  2449. AND (LEN(ISNULL(c.cFree9,''))<=0 OR (LEN(ISNULL(c.cFree9,''))>0 AND c.cFree9=d.cFree9))
  2450. AND (LEN(ISNULL(c.cFree10,''))<=0 OR (LEN(ISNULL(c.cFree10,''))>0 AND c.cFree10=d.cFree10))
  2451. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  2452. ";
  2453. #endregion
  2454. // sql = string.Format(sql, sqls);
  2455. if (Code == "MC00002")
  2456. {
  2457. sql += " order by d.inDate";
  2458. }
  2459. else if (Code == "MC00001")
  2460. {
  2461. sql += " order BY ISNULL(d.ProductDate,d.ExpirationDate)";
  2462. }
  2463. else
  2464. {
  2465. sql += " order BY ISNULL(d.ExpirationDate,d.ProductDate)";
  2466. }
  2467. var dataset = Repository().FindDataSetBySql(sql);
  2468. if (dataset.Tables[0].Rows.Count == 0)
  2469. return null;
  2470. DataTable table = dataset.Tables[0];
  2471. decimal qtyCount = 0;
  2472. bool remove = false;
  2473. List<int> removeList = new List<int>();
  2474. for (int i = 0; i < table.Rows.Count; i++)
  2475. {
  2476. if (i != 0
  2477. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  2478. || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
  2479. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  2480. || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  2481. )
  2482. {
  2483. qtyCount = 0;
  2484. remove = false;
  2485. }
  2486. if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0 && table.Rows[i]["LotNO"].ToString() != "")
  2487. {
  2488. table.Rows[i]["LotNO"] = "";
  2489. string a = "0.000000";
  2490. table.Rows[i]["QTY"] = Convert.ToDecimal(a);
  2491. //removeList.Add(i);
  2492. continue;
  2493. }
  2494. if (remove && table.Rows[i]["LotNO"].ToString() != "")
  2495. {
  2496. removeList.Add(i);
  2497. }
  2498. else
  2499. {
  2500. var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  2501. var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  2502. qtyCount += lotQty;
  2503. foreach (DataRow dr in table.Rows)
  2504. {
  2505. if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  2506. {
  2507. if (qtyCount > orderQty)
  2508. {
  2509. dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  2510. }
  2511. else
  2512. {
  2513. dr["QTYLeft"] = 0;
  2514. }
  2515. }
  2516. }
  2517. if (qtyCount >= orderQty)
  2518. {
  2519. table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  2520. remove = true;
  2521. }
  2522. else
  2523. {
  2524. table.Rows[i]["SendQTY"] = lotQty;
  2525. }
  2526. }
  2527. }
  2528. if (removeList.Count > 0)
  2529. {
  2530. removeList.Reverse();
  2531. foreach (var item in removeList)
  2532. {
  2533. table.Rows.RemoveAt(item);
  2534. }
  2535. }
  2536. try
  2537. {
  2538. #region 旧卡控
  2539. //string chksql = "";
  2540. //if (Type == "2" || Type == "12")
  2541. //{
  2542. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSMOApply
  2543. // where ApplyCode in ({0}) and WorkPoint='{1}'
  2544. // GROUP BY InvCode,WHCode";
  2545. //}
  2546. //if (Type == "5")
  2547. //{
  2548. // #region 委外领料SQL
  2549. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOApply
  2550. // where ApplyCode in ({0}) and WorkPoint='{1}'
  2551. // GROUP BY InvCode,WHCode";
  2552. // #endregion
  2553. //}
  2554. //if (Type == "7")
  2555. //{
  2556. // #region 销售发货SQL
  2557. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSSDN
  2558. // where SDNCode in ({0}) and WorkPoint='{1}'
  2559. // GROUP BY InvCode,WHCode";
  2560. // #endregion
  2561. //}
  2562. //if (Type == "8")
  2563. //{
  2564. // #region 其它出库SQL
  2565. // chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOtherOut
  2566. // where OutCode in ({0}) and WorkPoint='{1}'
  2567. // GROUP BY InvCode,WHCode";
  2568. // #endregion
  2569. //}
  2570. //if (Type == "10")
  2571. //{
  2572. // #region 物料调拨
  2573. // chksql = @" select InvCode,FromWarehouseCode AS WHCode,SUM(Quantity) as Quantity from ICSTransfer
  2574. // where TransferNO in ({0}) and WorkPoint='{1}'
  2575. // GROUP BY InvCode,FromWarehouseCode";
  2576. // #endregion
  2577. //}
  2578. //chksql = string.Format(chksql, ID.TrimEnd(','), WorkPoint);
  2579. //var chkdata = Repository().FindDataSetBySql(chksql);
  2580. //DataTable chktable = chkdata.Tables[0];
  2581. //foreach (DataRow chkdr in chktable.Rows)
  2582. //{
  2583. // decimal ZLQty = 0;
  2584. // for (int i = 0; i < table.Rows.Count; i++)
  2585. // {
  2586. // if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString()
  2587. // && table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString())
  2588. // {
  2589. // ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
  2590. // }
  2591. // }
  2592. // if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty)
  2593. // {
  2594. // throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。");
  2595. // }
  2596. //}
  2597. #endregion
  2598. DataRow[] dss = table.Select("LotNO=''");
  2599. foreach (var item in dss)
  2600. {
  2601. DataRow[] dsss = table.Select("Code='" + item["Code"].ToString() + "' and Sequence='" + item["Sequence"].ToString() + "' and LotNO <> '' ");
  2602. if (dsss != null && dsss.Length > 0)
  2603. {
  2604. table.Rows.Remove(item);
  2605. }
  2606. }
  2607. var result = ConvertCellToString(table);
  2608. if (Invmes.Rows.Count > 0)
  2609. {
  2610. result.Merge(Invmes, false);
  2611. }
  2612. return result;
  2613. }
  2614. catch (Exception ex)
  2615. {
  2616. throw new Exception(ex.Message);
  2617. }
  2618. }
  2619. public string BackMergeMaterial(string keyValues, string Type)
  2620. {
  2621. JArray res = (JArray)JsonConvert.DeserializeObject(keyValues);
  2622. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2623. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2624. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2625. string msg = "";
  2626. string sql = string.Empty;
  2627. string keyValue = "";
  2628. foreach (var item in res)
  2629. {
  2630. JObject jo = (JObject)item;
  2631. if (Type == "1")//工单备料
  2632. {
  2633. sql += @"IF EXISTS(SELECT * FROM ICSMO b
  2634. INNER join ICSMOPick c on c.MODetailID=b.MODetailID and c.WorkPoint=b.WorkPoint
  2635. where b.MOCode = '{0}' and c.IssueQuantity>0)
  2636. BEGIN
  2637. RAISERROR('{0}!',16,1);
  2638. RETURN
  2639. END
  2640. delete ICSMOPickMerge from ICSMOPickMerge a
  2641. INNER join ICSMOPick c on a.SourceID=c.id and a.WorkPoint=c.WorkPoint
  2642. LEFT JOIN ICSMO b on c.MODetailID=b.MODetailID and c.WorkPoint=b.WorkPoint and b.MOStatus<>'3'
  2643. where b.MOCode = '{0}'";
  2644. }
  2645. if (Type == "2")//工单发料
  2646. {
  2647. sql += @"IF EXISTS(SELECT * FROM ICSMOApply b
  2648. where b.ApplyCode = '{0}' and b.IssueQuantity>0)
  2649. BEGIN
  2650. RAISERROR('{0}!',16,1);
  2651. RETURN
  2652. END
  2653. delete ICSMOPickMerge from ICSMOPickMerge a
  2654. LEFT JOIN ICSMOApply b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2655. where b.ApplyCode = '{0}'";
  2656. }
  2657. if (Type == "3")//材料出库
  2658. {
  2659. sql += @"IF EXISTS(SELECT * FROM ICSMOIssue b
  2660. where b.IssueCode = '{0}' and b.IssueQuantity>0)
  2661. BEGIN
  2662. RAISERROR('{0}!',16,1);
  2663. RETURN
  2664. END
  2665. delete ICSMOPickMerge from ICSMOPickMerge a
  2666. LEFT JOIN ICSMOIssue b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2667. where b.IssueCode = '{0}' ";
  2668. }
  2669. if (Type == "4")//委外备料
  2670. {
  2671. sql += @"IF EXISTS(SELECT * FROM ICSOutsourcingOrder b
  2672. INNER join ICSOOPick c on c.OODetailID=b.OODetailID and c.WorkPoint=b.WorkPoint
  2673. where b.OOCode = '{0}' and c.IssueQuantity>0)
  2674. BEGIN
  2675. RAISERROR('{0}!',16,1);
  2676. RETURN
  2677. END
  2678. delete ICSMOPickMerge from ICSMOPickMerge a
  2679. INNER join ICSOOPick c on a.SourceID=c.id and a.WorkPoint=c.WorkPoint
  2680. LEFT JOIN ICSOutsourcingOrder b on c.OODetailID=b.OODetailID and c.WorkPoint=b.WorkPoint
  2681. where b.OOCode = '{0}'";
  2682. }
  2683. if (Type == "5")//委外领料
  2684. {
  2685. sql += @"IF EXISTS(SELECT * FROM ICSOApply b
  2686. where b.ApplyCode = '{0}' and b.IssueQuantity>0)
  2687. BEGIN
  2688. RAISERROR('{0}!',16,1);
  2689. RETURN
  2690. END
  2691. delete ICSMOPickMerge from ICSMOPickMerge a
  2692. LEFT JOIN ICSOApply b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2693. where b.ApplyCode = '{0}'";
  2694. }
  2695. if (Type == "6")//委外材料出库
  2696. {
  2697. sql += @"IF EXISTS(SELECT * FROM ICSOIssue b
  2698. where b.IssueCode = '{0}' and b.IssueQuantity>0)
  2699. BEGIN
  2700. RAISERROR('{0}!',16,1);
  2701. RETURN
  2702. END
  2703. delete ICSMOPickMerge from ICSMOPickMerge a
  2704. LEFT JOIN ICSOIssue b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2705. where b.IssueCode = '{0}'";
  2706. }
  2707. if (Type == "7")//销售发货
  2708. {
  2709. sql += @"IF EXISTS(SELECT * FROM ICSSDN b
  2710. where b.SDNCode = '{0}' and b.SDNQuantity>0)
  2711. BEGIN
  2712. RAISERROR('{0}!',16,1);
  2713. RETURN
  2714. END
  2715. delete ICSMOPickMerge from ICSMOPickMerge a
  2716. LEFT JOIN ICSSDN b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2717. where b.SDNCode = '{0}'";
  2718. }
  2719. if (Type == "8")//其它出库
  2720. {
  2721. sql += @"IF EXISTS(SELECT * FROM ICSOtherOut b
  2722. where b.OutCode = '{0}' and b.OutQuantity>0)
  2723. BEGIN
  2724. RAISERROR('{0}!',16,1);
  2725. RETURN
  2726. END
  2727. delete ICSMOPickMerge from ICSMOPickMerge a
  2728. LEFT JOIN ICSOtherOut b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2729. where b.OutCode = '{0}'";
  2730. }
  2731. if (Type == "9")//借用单
  2732. {
  2733. sql += @"IF EXISTS(SELECT * FROM ICSOtherOut b
  2734. where b.OutCode = '{0}' and b.OutQuantity>0)
  2735. BEGIN
  2736. RAISERROR('{0}!',16,1);
  2737. RETURN
  2738. END
  2739. delete ICSMOPickMerge from ICSMOPickMerge a
  2740. LEFT JOIN ICSOtherOut b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2741. where b.OutCode = '{0}'";
  2742. }
  2743. if (Type == "10")//物料调拨
  2744. {
  2745. sql += @"IF EXISTS(SELECT * FROM ICSTransfer b
  2746. where b.TransferNO = '{0}' and b.TransferQuantity>0)
  2747. BEGIN
  2748. RAISERROR('{0}!',16,1);
  2749. RETURN
  2750. END
  2751. delete ICSMOPickMerge from ICSMOPickMerge a
  2752. LEFT JOIN ICSTransfer b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2753. where b.TransferNO = '{0}'";
  2754. }
  2755. if (Type == "11")//两步调出
  2756. {
  2757. sql += @"IF EXISTS(SELECT * FROM ICSOtherOut b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2758. INNER JOIN ICSTransfer tra ON b.TransferDetailID=tra.TransferDetailID AND b.WorkPoint=tra.WorkPoint
  2759. where b.OutCode = '{0}' and b.OutQuantity>0)
  2760. BEGIN
  2761. RAISERROR('{0}!',16,1);
  2762. RETURN
  2763. END
  2764. delete ICSMOPickMerge from ICSMOPickMerge a
  2765. LEFT JOIN ICSOtherOut b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2766. INNER JOIN ICSTransfer tra ON b.TransferDetailID=tra.TransferDetailID AND b.WorkPoint=tra.WorkPoint
  2767. where b.OutCode = '{0}'";
  2768. }
  2769. if (Type == "12")//补料
  2770. {
  2771. sql += @"IF EXISTS(SELECT * FROM ICSMOReplenishment b
  2772. where b.ReplenishmentCode = '{0}' and b.IssueQuantity>0)
  2773. BEGIN
  2774. RAISERROR('{0}!',16,1);
  2775. RETURN
  2776. END
  2777. delete ICSMOPickMerge from ICSMOPickMerge a
  2778. LEFT JOIN ICSMOReplenishment b on a.SourceID=b.id and a.WorkPoint=b.WorkPoint
  2779. where b.ReplenishmentCode = '{0}'";
  2780. }
  2781. try
  2782. {
  2783. sql = string.Format(sql, jo["Code"].ToString());
  2784. SqlHelper.ExecuteNonQuery(sql);
  2785. }
  2786. catch (Exception ex)
  2787. {
  2788. msg = ex.Message;
  2789. //throw new Exception(ex.Message);
  2790. }
  2791. }
  2792. return msg;
  2793. }
  2794. public string MergeMaterial(string keyValues,string Type)
  2795. {
  2796. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2797. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2798. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2799. string msg = "";
  2800. string sql = string.Empty;
  2801. string keyValue = "";
  2802. //keyValue = keyValue.TrimEnd(',');
  2803. string[] keyvaluelist = keyValues.Split(',');
  2804. if (keyvaluelist.Count() > 1)
  2805. {
  2806. for (int i = 0; i < keyvaluelist.Count() - 1; i++)
  2807. {
  2808. if (keyValue == "")
  2809. {
  2810. keyValue += "'" + keyvaluelist[i] + "'";
  2811. }
  2812. else
  2813. {
  2814. keyValue += ",'" + keyvaluelist[i] + "'";
  2815. }
  2816. }
  2817. }
  2818. else
  2819. keyValue = keyValues.TrimEnd(',');
  2820. DateTime time = DateTime.Now;
  2821. string Tday = time.ToString("yyyyMMdd");
  2822. string sqls = string.Format(@"SELECT MAX(A.MergeID) AS SourceID FROM ICSMOPickMerge A WHERE A.MergeID LIKE '{0}%' AND LEN(a.MergeID) = 13", Tday);
  2823. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  2824. string MergeID = "";
  2825. Int64 Merge_ID = 0;
  2826. DataTable dts = ds.Tables[0];
  2827. if (dts != null && dts.Rows.Count > 0)
  2828. {
  2829. string lot = dts.Rows[0]["SourceID"].ToString();
  2830. if (!string.IsNullOrWhiteSpace(lot))
  2831. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  2832. }
  2833. MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  2834. if (Type == "1")//工单备料
  2835. {
  2836. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2837. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2838. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2839. from ICSMO a inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  2840. where a.MOStatus<>'3' and a.MOCode in ({5})
  2841. ";
  2842. }
  2843. if (Type == "2")//工单发料
  2844. {
  2845. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2846. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2847. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2848. from ICSMOApply a
  2849. where a.ApplyCode in ({5})";
  2850. }
  2851. if (Type == "3")//材料出库
  2852. {
  2853. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2854. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2855. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2856. from ICSMOIssue a
  2857. where a.IssueCode in ({5}) ";
  2858. }
  2859. if (Type == "4")//委外备料
  2860. {
  2861. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2862. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2863. select NEWID(),'{0}',b.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2864. from ICSOutsourcingOrder a inner join ICSOOPick b on a.OODetailID=b.OODetailID and b.WorkPoint=a.WorkPoint
  2865. where a.OOCode in ({5})";
  2866. }
  2867. if (Type == "5")//委外领料
  2868. {
  2869. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2870. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2871. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2872. from ICSOApply a
  2873. where a.ApplyCode in ({5})";
  2874. }
  2875. if (Type == "6")//委外材料出库
  2876. {
  2877. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2878. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2879. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2880. from ICSOIssue a
  2881. where a.IssueCode in ('{5}')";
  2882. }
  2883. if (Type == "7")//销售发货
  2884. {
  2885. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2886. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2887. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2888. from ICSSDN a
  2889. where a.SDNCode in ({5})";
  2890. }
  2891. if (Type == "8")//其它出库
  2892. {
  2893. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2894. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2895. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2896. from ICSOtherOut a
  2897. where a.OutCode in ({5})";
  2898. }
  2899. if (Type == "9")//借用单
  2900. {
  2901. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2902. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2903. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2904. from ICSOtherOut a
  2905. where a.OutCode in ({5})";
  2906. }
  2907. if (Type == "10")//物料调拨
  2908. {
  2909. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2910. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2911. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2912. from ICSTransfer a
  2913. where a.TransferNO in ({5})
  2914. ";
  2915. }
  2916. if (Type == "11")//两步调出
  2917. {
  2918. sql += @" INSERT INTO dbo.ICSMOPickMerge
  2919. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2920. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2921. from ICSOtherOut a
  2922. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  2923. where a.OutCode in ({5})
  2924. ";
  2925. }
  2926. if (Type == "12")//补料
  2927. {
  2928. sql += @"INSERT INTO dbo.ICSMOPickMerge
  2929. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  2930. select NEWID(),'{0}',a.ID ,'{1}','{2}','{3}',GETDATE(),'{4}'
  2931. from ICSMOReplenishment a
  2932. where a.ReplenishmentCode in ({5})";
  2933. }
  2934. sql = string.Format(sql, MergeID, Type, MUSER, MUSERNAME, WorkPoint, keyValue);
  2935. try
  2936. {
  2937. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2938. {
  2939. }
  2940. else
  2941. {
  2942. msg = "新增失败";
  2943. }
  2944. }
  2945. catch (Exception ex)
  2946. {
  2947. throw new Exception(ex.Message);
  2948. }
  2949. return msg;
  2950. }
  2951. public string CheckQty(string objArr)
  2952. {
  2953. objArr= objArr.TrimEnd(',');
  2954. string sql = @"select * from ICSMOPickMerge a
  2955. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  2956. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint and c.MOStatus<>'3'
  2957. where MOCode in ({0})";
  2958. sql = string.Format(sql, objArr);
  2959. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  2960. if (dt != null&&dt.Rows.Count>0)
  2961. {
  2962. return "1";
  2963. }
  2964. return "0";
  2965. }
  2966. public string SaveSeizeMaterial(string ID, string Type,string LotNoInfo,string obj)
  2967. {
  2968. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2969. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2970. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2971. string msg = "";
  2972. string sql = string.Empty;
  2973. string pikTbLogsql = string.Empty;
  2974. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  2975. try
  2976. {
  2977. #region 旧逻辑
  2978. // if (Type == "1")
  2979. // {
  2980. // #region 工单备料sql
  2981. // sqls = @" SELECT
  2982. // c.MOCode as Code,
  2983. //c.Sequence+'~'+a.Sequence as Sequence,
  2984. // a.InvCode,
  2985. // b.InvName,
  2986. // b.InvStd,
  2987. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  2988. // a.WhCode,
  2989. // b.InvUnit,
  2990. // a.ExtensionID,
  2991. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  2992. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  2993. // FROM
  2994. // ICSMOPick a
  2995. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  2996. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  2997. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  2998. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) and a.EATTRIBUTE1<>'1'
  2999. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.Sequence+'~'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3000. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3001. // #endregion
  3002. // }
  3003. // if (Type == "2")
  3004. // {
  3005. // #region 工单领料sql
  3006. // sqls = @"select
  3007. // a.ApplyCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity, 0))) AS iQuantity, a.WhCode,a.ExtensionID,
  3008. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3009. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3010. // FROM
  3011. // ICSMOApply a
  3012. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3013. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3014. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3015. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3016. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3017. // #endregion
  3018. // }
  3019. // if (Type == "3")
  3020. // {
  3021. // #region 工单材料出库SQL
  3022. // sqls = @" select
  3023. // a.IssueCode as Code,
  3024. //a.Sequence,
  3025. // a.InvCode,
  3026. // b.InvName,
  3027. // b.InvStd,
  3028. // b.InvUnit,
  3029. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3030. // a.WhCode,
  3031. // a.ExtensionID,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3032. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3033. // FROM
  3034. // ICSMOIssue a
  3035. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3036. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3037. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3038. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3039. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3040. // #endregion
  3041. // }
  3042. // if (Type == "4")
  3043. // {
  3044. // #region 委外备料SQL
  3045. // sqls = @" select
  3046. // c.OOCode as Code,
  3047. //c.Sequence+'~'+a.Sequence as Sequence,
  3048. // a.InvCode,
  3049. // b.InvName,
  3050. // b.InvStd,
  3051. // b.InvUnit,
  3052. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3053. // a.WhCode,
  3054. // a.ExtensionID, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3055. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3056. // FROM
  3057. // ICSOOPick a
  3058. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  3059. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3060. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3061. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3062. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID,c.Sequence+'~'+a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3063. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3064. // #endregion
  3065. // }
  3066. // if (Type == "5")
  3067. // {
  3068. // #region 委外领料SQL
  3069. // sqls = @"select
  3070. // a.ApplyCode as Code,
  3071. //a.Sequence,
  3072. // a.InvCode,
  3073. // b.InvName,
  3074. // b.InvStd,
  3075. // b.InvUnit,
  3076. // (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity,0))) AS iQuantity,
  3077. // a.WhCode,a.ExtensionID,
  3078. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3079. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3080. // FROM
  3081. // ICSOApply a
  3082. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3083. //LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3084. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3085. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3086. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3087. // #endregion
  3088. // }
  3089. // if (Type == "6")
  3090. // {
  3091. // #region 委外材料出库SQL
  3092. // sqls = @" select
  3093. // a.IssueCode as Code,
  3094. //a.Sequence,
  3095. // a.InvCode,
  3096. // b.InvName,
  3097. // b.InvStd,
  3098. // b.InvUnit,
  3099. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3100. // a.WhCode,
  3101. // a.ExtensionID,
  3102. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3103. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3104. // FROM
  3105. // ICSOIssue a
  3106. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3107. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3108. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3109. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3110. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3111. // #endregion
  3112. // }
  3113. // if (Type == "7")
  3114. // {
  3115. // #region 销售发货SQL
  3116. // sqls = @" select
  3117. // a.SDNCode as Code,
  3118. //a.Sequence,
  3119. // a.InvCode,
  3120. // b.InvName,
  3121. // b.InvStd,
  3122. // b.InvUnit,
  3123. // (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.SDNQuantity, 0))) AS iQuantity,
  3124. // a.WhCode,
  3125. // a.ExtensionID,
  3126. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3127. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3128. // FROM
  3129. // ICSSDN a
  3130. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3131. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3132. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.SDNQuantity, 0)
  3133. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,
  3134. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3135. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3136. // #endregion
  3137. // }
  3138. // if (Type == "8")
  3139. // {
  3140. // #region 其它出库SQL
  3141. // sqls = @" select
  3142. // a.OutCode as Code,
  3143. //a.Sequence,
  3144. // a.InvCode,
  3145. // b.InvName,
  3146. // b.InvStd,
  3147. // b.InvUnit,
  3148. // (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.OutQuantity, 0))) AS iQuantity,
  3149. // a.WhCode,
  3150. // a.ExtensionID,
  3151. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3152. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3153. // FROM
  3154. // ICSOtherOut a
  3155. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3156. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3157. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  3158. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3159. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3160. // #endregion
  3161. // }
  3162. // if (Type == "9")
  3163. // {
  3164. // #region 借用SQL
  3165. // sqls = @"select
  3166. // a.BrrowCode as Code,
  3167. //a.Sequence,
  3168. // a.InvCode,
  3169. // b.InvName,
  3170. // b.InvStd,
  3171. // b.InvUnit,
  3172. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3173. // a.WhCode,
  3174. // a.ExtensionID,
  3175. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3176. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3177. // FROM
  3178. // ICSBrrow a
  3179. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3180. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3181. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.BrrowQuantity, 0)
  3182. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3183. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3184. // #endregion
  3185. // }
  3186. // if (Type == "10")
  3187. // {
  3188. // #region 物料调拨
  3189. // sqls = @"select
  3190. // a.TransferNO as Code,
  3191. //a.Sequence,
  3192. // a.InvCode,
  3193. // b.InvName,
  3194. // b.InvStd,
  3195. // b.InvUnit,
  3196. // (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,
  3197. // a.FromWarehouseCode as WhCode,
  3198. // a.ExtensionID,
  3199. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3200. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3201. // FROM
  3202. // ICSTransfer a
  3203. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3204. //LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3205. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
  3206. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence,
  3207. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3208. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3209. // #endregion
  3210. // }
  3211. // if (Type == "11")
  3212. // {
  3213. // #region 两步调出
  3214. // sqls = @"select
  3215. // a.OutCode as Code,
  3216. //a.Sequence,
  3217. // a.InvCode,
  3218. // b.InvName,
  3219. // b.InvStd,
  3220. // b.InvUnit,
  3221. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3222. // a.WHCode ,
  3223. // a.ExtensionID,
  3224. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3225. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3226. // from ICSOtherOut a
  3227. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  3228. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3229. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3230. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  3231. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3232. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3233. // #endregion
  3234. // }
  3235. // if (Type == "12")
  3236. // {
  3237. // #region 补料sql
  3238. // sqls = @"select
  3239. // a.ReplenishmentCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity, 0))) AS iQuantity, a.WhCode,a.ExtensionID, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3240. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3241. // FROM
  3242. // ICSMOReplenishment a
  3243. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3244. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3245. // WHERE a.ReplenishmentCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3246. // GROUP BY a.ReplenishmentCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3247. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3248. // #endregion
  3249. // }
  3250. // sqls = string.Format(sqls, ID, WorkPoint);
  3251. // #region sql结果 处理
  3252. // sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  3253. // c.Code,
  3254. //c.Sequence,
  3255. // c.InvCode,
  3256. // c.InvName,
  3257. // c.InvStd,
  3258. // c.InvUnit,
  3259. // c.iQuantity AS iQuantity,
  3260. // c.WHCode AS WarehouseCode,
  3261. // d.LotNO,
  3262. // ISNULL(d.Quantity, 0) AS QTY,
  3263. // ISNULL(d.Quantity, 0) AS QTYLeft,
  3264. // CONVERT(decimal(18,6),0) AS SendQTY,
  3265. // d.LocationCode AS LocationCode,
  3266. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  3267. // f.QTYTotal QTYTotal,c.ExtensionID
  3268. // FROM
  3269. // ({sqls}) c
  3270. // left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3271. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3272. // from ICSWareHouseLotInfo d ,ICSInventoryLot m
  3273. //LEFT JOIN ICSExtension f on m.ExtensionID=f.ID and m.WorkPoint=f.WorkPoint
  3274. // where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3275. // and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0
  3276. // ) d
  3277. // on c.InvCode=d.INVCode
  3278. //AND (LEN(ISNULL(c.WHCode,''))<=0 OR (LEN(ISNULL(c.WHCode,''))>0 AND c.WHCode=d.WarehouseCode))
  3279. // AND (LEN(ISNULL(c.ProjectCode,''))<=0 OR (LEN(ISNULL(c.ProjectCode,''))>0 AND c.ProjectCode=d.ProjectCode))
  3280. // AND (LEN(ISNULL(c.BatchCode,''))<=0 OR (LEN(ISNULL(c.BatchCode,''))>0 AND c.BatchCode=d.BatchCode))
  3281. // AND (LEN(ISNULL(c.Version,''))<=0 OR (LEN(ISNULL(c.Version,''))>0 AND c.Version=d.Version))
  3282. // AND (LEN(ISNULL(c.Brand,''))<=0 OR (LEN(ISNULL(c.Brand,''))>0 AND c.Brand=d.Brand))
  3283. // AND (LEN(ISNULL(c.cFree1,''))<=0 OR (LEN(ISNULL(c.cFree1,''))>0 AND c.cFree1=d.cFree1))
  3284. // AND (LEN(ISNULL(c.cFree2,''))<=0 OR (LEN(ISNULL(c.cFree2,''))>0 AND c.cFree2=d.cFree2))
  3285. // AND (LEN(ISNULL(c.cFree3,''))<=0 OR (LEN(ISNULL(c.cFree3,''))>0 AND c.cFree3=d.cFree3))
  3286. // AND (LEN(ISNULL(c.cFree4,''))<=0 OR (LEN(ISNULL(c.cFree4,''))>0 AND c.cFree4=d.cFree4))
  3287. // AND (LEN(ISNULL(c.cFree5,''))<=0 OR (LEN(ISNULL(c.cFree5,''))>0 AND c.cFree5=d.cFree5))
  3288. // AND (LEN(ISNULL(c.cFree6,''))<=0 OR (LEN(ISNULL(c.cFree6,''))>0 AND c.cFree6=d.cFree6))
  3289. // AND (LEN(ISNULL(c.cFree7,''))<=0 OR (LEN(ISNULL(c.cFree7,''))>0 AND c.cFree7=d.cFree7))
  3290. // AND (LEN(ISNULL(c.cFree8,''))<=0 OR (LEN(ISNULL(c.cFree8,''))>0 AND c.cFree8=d.cFree8))
  3291. // AND (LEN(ISNULL(c.cFree9,''))<=0 OR (LEN(ISNULL(c.cFree9,''))>0 AND c.cFree9=d.cFree9))
  3292. // AND (LEN(ISNULL(c.cFree10,''))<=0 OR (LEN(ISNULL(c.cFree10,''))>0 AND c.cFree10=d.cFree10))
  3293. // LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  3294. // order by c.Code,c.Sequence,d.MTIME,d.LotNO ";
  3295. // #endregion
  3296. // var dataset = Repository().FindDataSetBySql(sql);
  3297. // if (dataset.Tables[0].Rows.Count == 0)
  3298. // return null;
  3299. // DataTable table = dataset.Tables[0];
  3300. // decimal qtyCount = 0;
  3301. // bool remove = false;
  3302. // List<int> removeList = new List<int>();
  3303. // for (int i = 0; i < table.Rows.Count; i++)
  3304. // {
  3305. // if (i != 0
  3306. // && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  3307. // || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
  3308. // || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  3309. // || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  3310. // )
  3311. // {
  3312. // qtyCount = 0;
  3313. // remove = false;
  3314. // }
  3315. // if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
  3316. // {
  3317. // removeList.Add(i);
  3318. // continue;
  3319. // }
  3320. // if (remove)
  3321. // {
  3322. // removeList.Add(i);
  3323. // }
  3324. // else
  3325. // {
  3326. // var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  3327. // var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  3328. // qtyCount += lotQty;
  3329. // foreach (DataRow dr in table.Rows)
  3330. // {
  3331. // if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  3332. // {
  3333. // if (qtyCount > orderQty)
  3334. // {
  3335. // dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  3336. // }
  3337. // else
  3338. // {
  3339. // dr["QTYLeft"] = 0;
  3340. // }
  3341. // }
  3342. // }
  3343. // if (qtyCount >= orderQty)
  3344. // {
  3345. // table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  3346. // remove = true;
  3347. // }
  3348. // else
  3349. // {
  3350. // table.Rows[i]["SendQTY"] = lotQty;
  3351. // }
  3352. // }
  3353. // }
  3354. // if (removeList.Count > 0)
  3355. // {
  3356. // removeList.Reverse();
  3357. // foreach (var item in removeList)
  3358. // {
  3359. // table.Rows.RemoveAt(item);
  3360. // }
  3361. // }
  3362. // try
  3363. // {
  3364. // //string[] strArray = LotNoInfo.Split(',');
  3365. // //// 创建一个HashSet集合
  3366. // //HashSet<string> strSet = new HashSet<string>();
  3367. // //// 将切割后的字符串数组添加到集合中
  3368. // //foreach (string elem in strArray)
  3369. // //{
  3370. // // strSet.Add(elem);
  3371. // //}
  3372. // decimal ZLQty = 0;
  3373. // decimal DJQty = 0;
  3374. // for (int i = 0; i < table.Rows.Count; i++)
  3375. // {
  3376. // ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
  3377. // DJQty += Convert.ToDecimal(table.Rows[i]["iQuantity"].ToString());
  3378. // }
  3379. // if (ZLQty!= DJQty)
  3380. // {
  3381. // throw new Exception("单据所匹配条码与单据数量不符,无法保存!");
  3382. // }
  3383. #endregion
  3384. var dataSet = JsonConvert.DeserializeObject<DataTable>(obj);
  3385. DataTable table = dataSet;
  3386. table = table.Select("LotNO<>''").CopyToDataTable();//排除空的条码
  3387. if (table.Rows.Count != 0)
  3388. {
  3389. #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
  3390. string BusinessCode = string.Empty;
  3391. string TransType = string.Empty;
  3392. if (Type == "1") { BusinessCode = "13"; TransType = "生产发料-生产订单备料表"; }
  3393. if (Type == "2") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; }
  3394. if (Type == "3") { BusinessCode = "15"; TransType = "生产发料-材料出库单"; }
  3395. if (Type == "4") { BusinessCode = "5"; TransType = "委外发料-委外订单备料表"; }
  3396. if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; }
  3397. if (Type == "6") { BusinessCode = "7"; TransType = "委外发料-委外材料出库单"; }
  3398. if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; }
  3399. if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; }
  3400. if (Type == "9") { BusinessCode = "26"; TransType = "借用"; }
  3401. if (Type == "10") { BusinessCode = "46"; TransType = "调拨"; }
  3402. if (Type == "11") { BusinessCode = "22"; TransType = "两步调出"; }
  3403. string Identification = Guid.NewGuid().ToString();
  3404. var pikTbLogTime = DateTime.Now;
  3405. List<string> DocNoList = new List<string>();
  3406. pikTbLogsql = @"update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  3407. from dbo.ICSWareHouseLotInfo b
  3408. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog
  3409. where TransCode in ({0})and TransType='15' and WorkPoint='{1}' group by LotNo) c
  3410. on c.LotNo =b.LotNo
  3411. delete dbo.ICSWareHouseLotInfoLog where TransCode in({0}) and TransType='15' and WorkPoint='{1}'";
  3412. pikTbLogsql = string.Format(pikTbLogsql, ID, WorkPoint);
  3413. foreach (DataRow PickLog in table.Rows)
  3414. {
  3415. pikTbLogsql += @"
  3416. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' AND Quantity-LockQuantity-"+ PickLog["SendQTY"].ToString() + @"<0)
  3417. BEGIN
  3418. RAISERROR(':"+ PickLog["LotNO"].ToString() + @"',16,1);
  3419. RETURN
  3420. END
  3421. IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15')
  3422. BEGIN
  3423. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3424. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3425. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3426. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3427. MTIME,WorkPoint,EATTRIBUTE1)
  3428. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  3429. a.WarehouseCode,a.LocationCode,'','','{3}',
  3430. '','1','15','{4}','0','',
  3431. '','','','{5}' ,'{6}' ,
  3432. '{7}' ,'{8}' ,''
  3433. FROM ICSWareHouseLotInfo a
  3434. WHERE a.LotNo='{9}' AND a.WorkPoint='{8}'
  3435. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}'
  3436. END
  3437. UPDATE ICSMOApply SET MUSER='{6}' WHERE ApplyCode='{1}' and Sequence='{2}' ; ";
  3438. pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString()
  3439. , BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString());
  3440. }
  3441. #endregion
  3442. }
  3443. if (SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql) > 0)
  3444. {
  3445. }
  3446. else
  3447. {
  3448. msg = "占料信息保存失败";
  3449. }
  3450. }
  3451. catch (Exception ex)
  3452. {
  3453. msg = ex.Message;
  3454. }
  3455. return msg;
  3456. }
  3457. public string SaveSeizeMaterial2(string ID, string Type,string LotNoInfo,string obj)
  3458. {
  3459. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3460. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3461. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3462. string msg = "";
  3463. string sql = string.Empty;
  3464. string pikTbLogsql = string.Empty;
  3465. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  3466. string sqls = "";
  3467. try
  3468. {
  3469. #region 就逻辑
  3470. // #region 各单据sql
  3471. // if (Type == "1")
  3472. // {
  3473. // #region 工单备料sql
  3474. // sqls = @" select
  3475. // x.MergeID,
  3476. // c.MOCode as Code,
  3477. //c.Sequence+'~'+a.Sequence as Sequence,
  3478. // a.InvCode,
  3479. // b.InvName,
  3480. // b.InvStd,
  3481. // b.InvUnit,
  3482. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3483. // a.WhCode,
  3484. // a.ExtensionID,
  3485. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3486. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3487. // FROM
  3488. // ICSMOPick a
  3489. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3490. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  3491. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3492. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3493. // WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) and a.EATTRIBUTE1<>'1'
  3494. // GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID,c.Sequence+'~'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3495. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3496. // #endregion
  3497. // }
  3498. // if (Type == "2")
  3499. // {
  3500. // #region 工单领料SQL
  3501. // sqls = @" select
  3502. // x.MergeID,
  3503. // a.ApplyCode as Code,
  3504. //a.Sequence,
  3505. // a.InvCode,
  3506. // b.InvName,
  3507. // b.InvStd,
  3508. //b.InvUnit,
  3509. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3510. // a.WhCode,
  3511. // a.ExtensionID,
  3512. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3513. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3514. // FROM
  3515. // ICSMOApply a
  3516. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3517. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3518. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3519. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3520. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3521. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3522. // #endregion
  3523. // }
  3524. // if (Type == "3")
  3525. // {
  3526. // #region 工单材料出库SQL
  3527. // sqls = @" select
  3528. // x.MergeID,
  3529. // a.IssueCode as Code,
  3530. //a.Sequence,
  3531. // a.InvCode,
  3532. // b.InvName,
  3533. // b.InvStd,
  3534. // b.InvUnit,
  3535. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3536. // a.WhCode,
  3537. // a.ExtensionID,
  3538. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3539. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3540. // FROM
  3541. // ICSMOIssue a
  3542. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3543. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3544. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3545. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3546. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3547. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3548. // #endregion
  3549. // }
  3550. // if (Type == "4")
  3551. // {
  3552. // #region 委外备料SQL
  3553. // sqls = @" select
  3554. // x.MergeID,
  3555. // c.OOCode as Code,
  3556. //c.Sequence+'~'+a.Sequence as Sequence,
  3557. // a.InvCode,
  3558. // b.InvName,
  3559. // b.InvStd,
  3560. // b.InvUnit,
  3561. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3562. // a.WhCode,
  3563. // a.ExtensionID,
  3564. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3565. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3566. // FROM
  3567. // ICSOOPick a
  3568. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3569. // left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  3570. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3571. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3572. // WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3573. // GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID, x.MergeID,c.Sequence+'~'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3574. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3575. // #endregion
  3576. // }
  3577. // if (Type == "5")
  3578. // {
  3579. // #region 委外领料SQL
  3580. // sqls = @" select
  3581. // x.MergeID,
  3582. // a.ApplyCode as Code,
  3583. //a.Sequence,
  3584. // a.InvCode,
  3585. // b.InvName,
  3586. // b.InvStd,
  3587. // b.InvUnit,
  3588. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3589. // a.WhCode,
  3590. // a.ExtensionID,
  3591. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3592. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3593. // FROM
  3594. // ICSOApply a
  3595. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3596. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3597. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3598. // WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3599. // GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3600. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3601. // #endregion
  3602. // }
  3603. // if (Type == "6")
  3604. // {
  3605. // #region 委外材料出库SQL
  3606. // sqls = @" select
  3607. // x.MergeID,
  3608. // a.IssueCode as Code,
  3609. //a.Sequence,
  3610. // a.InvCode,
  3611. // b.InvName,
  3612. // b.InvStd,
  3613. // b.InvUnit,
  3614. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3615. // a.WhCode,
  3616. // a.ExtensionID,
  3617. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3618. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3619. // FROM
  3620. // ICSOIssue a
  3621. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3622. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3623. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3624. // WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3625. // GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3626. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3627. // #endregion
  3628. // }
  3629. // if (Type == "7")
  3630. // {
  3631. // #region 销售发货SQL
  3632. // sqls = @" select
  3633. // x.MergeID,
  3634. // a.SDNCode as Code,
  3635. //a.Sequence,
  3636. // a.InvCode,
  3637. // b.InvName,
  3638. // b.InvStd,
  3639. // b.InvUnit,
  3640. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3641. // a.WhCode,
  3642. // a.ExtensionID,
  3643. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3644. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3645. // FROM
  3646. // ICSSDN a
  3647. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3648. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3649. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3650. // WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND a.Type='1' AND ISNULL(a.Quantity, 0)>ISNULL(a.SDNQuantity, 0)
  3651. // GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3652. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3653. // #endregion
  3654. // }
  3655. // if (Type == "8")
  3656. // {
  3657. // #region 其它出库SQL
  3658. // sqls = @" select
  3659. // x.MergeID,
  3660. // a.OutCode as Code,
  3661. //a.Sequence,
  3662. // a.InvCode,
  3663. // b.InvName,
  3664. // b.InvStd,
  3665. // b.InvUnit,
  3666. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3667. // a.WhCode,
  3668. // a.ExtensionID,
  3669. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3670. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3671. // FROM
  3672. // ICSOtherOut a
  3673. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3674. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3675. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3676. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  3677. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3678. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3679. // #endregion
  3680. // }
  3681. // if (Type == "9")
  3682. // {
  3683. // #region 借用SQL
  3684. // sqls = @" select
  3685. // x.MergeID,
  3686. // a.BrrowCode as Code,
  3687. //a.Sequence,
  3688. // a.InvCode,
  3689. // b.InvName,
  3690. // b.InvStd,
  3691. // b.InvUnit,
  3692. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3693. // a.WhCode,
  3694. // a.ExtensionID,
  3695. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3696. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3697. // FROM
  3698. // ICSBrrow a
  3699. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3700. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3701. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3702. // WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.BrrowQuantity, 0)
  3703. // GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3704. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3705. // #endregion
  3706. // }
  3707. // if (Type == "10")
  3708. // {
  3709. // #region 物料调拨
  3710. // sqls = @" select
  3711. // x.MergeID,
  3712. // a.TransferNO as Code,
  3713. //a.Sequence,
  3714. // a.InvCode,
  3715. // b.InvName,
  3716. // b.InvStd,
  3717. // b.InvUnit,
  3718. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3719. // a.FromWarehouseCode as WhCode,
  3720. // a.ExtensionID,
  3721. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3722. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3723. // FROM
  3724. // ICSTransfer a
  3725. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3726. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3727. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3728. // WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
  3729. // GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3730. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3731. // #endregion
  3732. // }
  3733. // if (Type == "11")
  3734. // {
  3735. // #region 两步调出
  3736. // sqls = @" select
  3737. // x.MergeID,
  3738. // a.OutCode as Code,
  3739. //a.Sequence,
  3740. // a.InvCode,
  3741. // b.InvName,
  3742. // b.InvStd,
  3743. // b.InvUnit,
  3744. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3745. // a.WHCode as WhCode,
  3746. // a.ExtensionID,
  3747. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3748. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3749. // FROM
  3750. // ICSOtherOut a
  3751. // INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  3752. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3753. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3754. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3755. // WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0)
  3756. // GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,x.MergeID,a.Sequence, f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3757. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3758. // #endregion
  3759. // }
  3760. // if (Type == "12")
  3761. // {
  3762. // #region 补料SQL
  3763. // sqls = @" select
  3764. // x.MergeID,
  3765. // a.ReplenishmentCode as Code,
  3766. //a.Sequence,
  3767. // a.InvCode,
  3768. // b.InvName,
  3769. // b.InvStd,
  3770. //b.InvUnit,
  3771. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  3772. // a.WhCode,
  3773. // a.ExtensionID,
  3774. //f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3775. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3776. // FROM
  3777. // ICSMOReplenishment a
  3778. // inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  3779. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  3780. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3781. // WHERE a.ReplenishmentCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0)
  3782. // GROUP BY a.ReplenishmentCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,x.MergeID,a.ExtensionID,a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3783. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  3784. // #endregion
  3785. // }
  3786. // #endregion
  3787. // sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  3788. // #region sql
  3789. // sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  3790. // c.MergeID,
  3791. // c.Code,
  3792. //c.Sequence,
  3793. // c.InvCode,
  3794. // c.InvName,
  3795. // c.InvStd,
  3796. // c.InvUnit,
  3797. // FLOOR(c.iQuantity) AS iQuantity,
  3798. // d.WarehouseCode,
  3799. // d.LocationCode,
  3800. // d.LotNO,
  3801. // ISNULL(d.Quantity, 0) AS QTY,
  3802. // ISNULL(d.Quantity, 0) AS QTYLeft,
  3803. // CONVERT(decimal(18,6),0) AS SendQTY,
  3804. // d.LocationCode AS LocationCode,
  3805. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  3806. // f.QTYTotal QTYTotal,c.ExtensionID
  3807. // FROM
  3808. // ({sqls}) c
  3809. // inner join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID , f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  3810. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  3811. // from ICSWareHouseLotInfo d ,ICSInventoryLot m
  3812. // LEFT JOIN ICSExtension f on m.ExtensionID=f.ID and m.WorkPoint=f.WorkPoint
  3813. // where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3814. // and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND isnull(d.Quantity,0)>0 ) d
  3815. // on c.InvCode=d.INVCode
  3816. // AND (LEN(ISNULL(c.WHCode,''))<=0 OR (LEN(ISNULL(c.WHCode,''))>0 AND c.WHCode=d.WarehouseCode))
  3817. // AND (LEN(ISNULL(c.ProjectCode,''))<=0 OR (LEN(ISNULL(c.ProjectCode,''))>0 AND c.ProjectCode=d.ProjectCode))
  3818. // AND (LEN(ISNULL(c.BatchCode,''))<=0 OR (LEN(ISNULL(c.BatchCode,''))>0 AND c.BatchCode=d.BatchCode))
  3819. // AND (LEN(ISNULL(c.Version,''))<=0 OR (LEN(ISNULL(c.Version,''))>0 AND c.Version=d.Version))
  3820. // AND (LEN(ISNULL(c.Brand,''))<=0 OR (LEN(ISNULL(c.Brand,''))>0 AND c.Brand=d.Brand))
  3821. // AND (LEN(ISNULL(c.cFree1,''))<=0 OR (LEN(ISNULL(c.cFree1,''))>0 AND c.cFree1=d.cFree1))
  3822. // AND (LEN(ISNULL(c.cFree2,''))<=0 OR (LEN(ISNULL(c.cFree2,''))>0 AND c.cFree2=d.cFree2))
  3823. // AND (LEN(ISNULL(c.cFree3,''))<=0 OR (LEN(ISNULL(c.cFree3,''))>0 AND c.cFree3=d.cFree3))
  3824. // AND (LEN(ISNULL(c.cFree4,''))<=0 OR (LEN(ISNULL(c.cFree4,''))>0 AND c.cFree4=d.cFree4))
  3825. // AND (LEN(ISNULL(c.cFree5,''))<=0 OR (LEN(ISNULL(c.cFree5,''))>0 AND c.cFree5=d.cFree5))
  3826. // AND (LEN(ISNULL(c.cFree6,''))<=0 OR (LEN(ISNULL(c.cFree6,''))>0 AND c.cFree6=d.cFree6))
  3827. // AND (LEN(ISNULL(c.cFree7,''))<=0 OR (LEN(ISNULL(c.cFree7,''))>0 AND c.cFree7=d.cFree7))
  3828. // AND (LEN(ISNULL(c.cFree8,''))<=0 OR (LEN(ISNULL(c.cFree8,''))>0 AND c.cFree8=d.cFree8))
  3829. // AND (LEN(ISNULL(c.cFree9,''))<=0 OR (LEN(ISNULL(c.cFree9,''))>0 AND c.cFree9=d.cFree9))
  3830. // AND (LEN(ISNULL(c.cFree10,''))<=0 OR (LEN(ISNULL(c.cFree10,''))>0 AND c.cFree10=d.cFree10))
  3831. // LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  3832. // order by c.Code,c.InvCode,c.Sequence,d.MTIME ";
  3833. // #endregion
  3834. // var dataset = Repository().FindDataSetBySql(sql);
  3835. // if (dataset.Tables[0].Rows.Count == 0)
  3836. // return null;
  3837. // DataTable table = dataset.Tables[0];
  3838. // decimal qtyCount = 0;
  3839. // bool remove = false;
  3840. // List<int> removeList = new List<int>();
  3841. // for (int i = 0; i < table.Rows.Count; i++)
  3842. // {
  3843. // if (i != 0
  3844. // && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  3845. // || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
  3846. // || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  3847. // || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  3848. // )
  3849. // {
  3850. // qtyCount = 0;
  3851. // remove = false;
  3852. // }
  3853. // if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
  3854. // {
  3855. // removeList.Add(i);
  3856. // continue;
  3857. // }
  3858. // if (remove)
  3859. // {
  3860. // removeList.Add(i);
  3861. // }
  3862. // else
  3863. // {
  3864. // var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  3865. // var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  3866. // qtyCount += lotQty;
  3867. // foreach (DataRow dr in table.Rows)
  3868. // {
  3869. // if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  3870. // {
  3871. // if (qtyCount > orderQty)
  3872. // {
  3873. // dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  3874. // }
  3875. // else
  3876. // {
  3877. // dr["QTYLeft"] = 0;
  3878. // }
  3879. // }
  3880. // }
  3881. // if (qtyCount >= orderQty)
  3882. // {
  3883. // table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  3884. // remove = true;
  3885. // }
  3886. // else
  3887. // {
  3888. // table.Rows[i]["SendQTY"] = lotQty;
  3889. // }
  3890. // }
  3891. // }
  3892. // if (removeList.Count > 0)
  3893. // {
  3894. // removeList.Reverse();
  3895. // foreach (var item in removeList)
  3896. // {
  3897. // table.Rows.RemoveAt(item);
  3898. // }
  3899. // }
  3900. // try
  3901. // {
  3902. // decimal ZLQty = 0;
  3903. // decimal DJQty = 0;
  3904. // for (int i = 0; i < table.Rows.Count; i++)
  3905. // {
  3906. // ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
  3907. // DJQty += Convert.ToDecimal(table.Rows[i]["iQuantity"].ToString());
  3908. // }
  3909. // if (ZLQty != DJQty)
  3910. // {
  3911. // throw new Exception("单据所匹配条码与单据数量不符,无法保存!");
  3912. // }
  3913. #endregion
  3914. var dataSet = JsonConvert.DeserializeObject<DataTable>(obj);
  3915. DataTable table = dataSet;
  3916. table= table.Select("LotNO<>''").CopyToDataTable();//排除空的条码
  3917. if (table.Rows.Count != 0)
  3918. {
  3919. #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
  3920. string BusinessCode = string.Empty;
  3921. string TransType = string.Empty;
  3922. if (Type == "1") { BusinessCode = "13"; TransType = "生产发料-生产订单备料表"; }
  3923. if (Type == "2") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; }
  3924. if (Type == "3") { BusinessCode = "15"; TransType = "生产发料-材料出库单"; }
  3925. if (Type == "4") { BusinessCode = "5"; TransType = "委外发料-委外订单备料表"; }
  3926. if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; }
  3927. if (Type == "6") { BusinessCode = "7"; TransType = "委外发料-委外材料出库单"; }
  3928. if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; }
  3929. if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; }
  3930. if (Type == "9") { BusinessCode = "26"; TransType = "借用"; }
  3931. if (Type == "10") { BusinessCode = "46"; TransType = "调拨"; }
  3932. if (Type == "11") { BusinessCode = "22"; TransType = "两步调出"; }
  3933. if (Type == "12") { BusinessCode = "49"; TransType = "补料"; }
  3934. string Identification = Guid.NewGuid().ToString();
  3935. var pikTbLogTime = DateTime.Now;
  3936. List<string> DocNoList = new List<string>();
  3937. pikTbLogsql = @"update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  3938. from dbo.ICSWareHouseLotInfo b
  3939. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog
  3940. where TransCode in ({0})and TransType='15' and WorkPoint='{1}' group by LotNo) c
  3941. on c.LotNo =b.LotNo
  3942. delete dbo.ICSWareHouseLotInfoLog where TransCode in({0}) and TransType='15' and WorkPoint='{1}'";
  3943. pikTbLogsql = string.Format(pikTbLogsql, ID, WorkPoint);
  3944. foreach (DataRow PickLog in table.Rows)
  3945. {
  3946. pikTbLogsql += @" IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' AND Quantity-LockQuantity-"+ PickLog["SendQTY"].ToString()+ @"<0)
  3947. BEGIN
  3948. RAISERROR(':"+ PickLog["LotNO"].ToString() + @"',16,1);
  3949. RETURN
  3950. END
  3951. IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15')
  3952. BEGIN
  3953. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3954. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3955. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3956. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3957. MTIME,WorkPoint,EATTRIBUTE1)
  3958. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  3959. a.WarehouseCode,a.LocationCode,'','','{3}',
  3960. '','1','15','{4}','0','',
  3961. '','','','{5}' ,'{6}' ,
  3962. '{7}' ,'{8}' ,''
  3963. FROM ICSWareHouseLotInfo a
  3964. WHERE a.LotNo='{9}' AND a.WorkPoint='{8}'
  3965. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}'
  3966. END
  3967. UPDATE ICSMOApply SET MUSER='{6}' WHERE ApplyCode='{1}' and Sequence='{2}' ; ";
  3968. pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString()
  3969. , BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString());
  3970. }
  3971. #endregion
  3972. }
  3973. if (SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql) > 0)
  3974. {
  3975. }
  3976. else
  3977. {
  3978. msg = "占料信息保存失败";
  3979. }
  3980. }
  3981. catch (Exception ex)
  3982. {
  3983. msg= ex.Message;
  3984. }
  3985. return msg;
  3986. }
  3987. public object SeachPickingListType(string Type)
  3988. {
  3989. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3990. string sql = @" select b.F_EnabledMark as flag from Sys_SRM_Items a left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  3991. where a.F_EnCode='PL00001' and b.F_ItemCode='{0}' order by cast(b.F_SortCode as int) asc";
  3992. sql = string.Format(sql, Type);
  3993. object flag =SqlHelper.ExecuteScalar(sql);
  3994. return flag;
  3995. }
  3996. //查询占料(工单备料(工单子件))
  3997. public DataTable GetGridJsonSeizeM(string queryJson, ref Pagination jqgridparam)
  3998. {
  3999. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4000. DataTable dt = new DataTable();
  4001. var queryParam = queryJson.ToJObject();
  4002. List<DbParameter> parameter = new List<DbParameter>();
  4003. string sql = "";
  4004. #region [SQL]
  4005. sql = @"select distinct
  4006. a.MOCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,d.MergeID AS IsNew,
  4007. case when k.TransCode is null then '' else '' end as IsOccupy
  4008. from ICSMO a
  4009. inner join ICSMOPick b on b.MODetailID=a.MODetailID and b.WorkPoint=a.WorkPoint
  4010. left join ICSMOPickMerge d on d.SourceID=b.ID and d.WorkPoint=b.WorkPoint
  4011. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.MOCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4012. where a.MOStatus<>'3' and isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'
  4013. ";
  4014. sql = string.Format(sql, WorkPoint);
  4015. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4016. #endregion
  4017. #region 条件
  4018. if (!string.IsNullOrWhiteSpace(queryJson))
  4019. {
  4020. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4021. {
  4022. sql += " and b.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4023. }
  4024. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4025. {
  4026. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4027. }
  4028. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4029. {
  4030. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4031. }
  4032. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4033. {
  4034. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4035. }
  4036. }
  4037. #endregion
  4038. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4039. }
  4040. //查询占料(工单备料(工单子件))子表查询
  4041. public DataTable GetSubGridJsonSeizeM1(string Code, ref Pagination jqgridparam)
  4042. {
  4043. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4044. DataTable dt = new DataTable();
  4045. //var queryParam = queryJson.ToJObject();
  4046. List<DbParameter> parameter = new List<DbParameter>();
  4047. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4048. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4049. from ICSMO k
  4050. inner join ICSMOPick d on d.MODetailID=k.MODetailID and d.WorkPoint=k.WorkPoint
  4051. left join ICSMOPickMerge e on d.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4052. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.MOCode and d.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4053. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4054. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4055. where k.MOStatus<>'3' and k.MOCode='{0}' and a.WorkPoint='{1}'";
  4056. sql = string.Format(sql, Code, WorkPoint);
  4057. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4058. }
  4059. //查询占料(工单备料(工单子件))子表查询
  4060. public DataTable GetSubGridJsonSeizeM3(string Code, ref Pagination jqgridparam)
  4061. {
  4062. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4063. DataTable dt = new DataTable();
  4064. //var queryParam = queryJson.ToJObject();
  4065. List<DbParameter> parameter = new List<DbParameter>();
  4066. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4067. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4068. from ICSMO k
  4069. inner join ICSMOPick d on d.MODetailID=k.MODetailID and d.WorkPoint=k.WorkPoint
  4070. left join ICSMOPickMerge e on d.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4071. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.MOCode and d.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4072. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4073. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4074. where k.MOStatus<>'3' and k.MOCode='{0}' and a.WorkPoint='{1}'";
  4075. sql = string.Format(sql, Code, WorkPoint);
  4076. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4077. }
  4078. //查询占料(工单领料(发料申请))
  4079. public DataTable GetGridJsonSeizeM2(string queryJson, ref Pagination jqgridparam)
  4080. {
  4081. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4082. DataTable dt = new DataTable();
  4083. var queryParam = queryJson.ToJObject();
  4084. List<DbParameter> parameter = new List<DbParameter>();
  4085. string sql = "";
  4086. #region [SQL]
  4087. sql = @"
  4088. select distinct a.ApplyCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,e.MergeID AS IsNew,
  4089. case when k.TransCode is null then '' else '' end as IsOccupy
  4090. from ICSMOApply a
  4091. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4092. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4093. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'";
  4094. sql = string.Format(sql, WorkPoint);
  4095. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4096. #endregion
  4097. #region 条件
  4098. if (!string.IsNullOrWhiteSpace(queryJson))
  4099. {
  4100. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4101. {
  4102. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4103. }
  4104. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4105. {
  4106. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4107. }
  4108. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4109. {
  4110. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4111. }
  4112. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4113. {
  4114. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4115. }
  4116. }
  4117. #endregion
  4118. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4119. }
  4120. //查询占料(工单领料(发料申请))子表查询
  4121. public DataTable GetSubGridJsonSeizeM2(string Code, ref Pagination jqgridparam)
  4122. {
  4123. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4124. DataTable dt = new DataTable();
  4125. //var queryParam = queryJson.ToJObject();
  4126. List<DbParameter> parameter = new List<DbParameter>();
  4127. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4128. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4129. from ICSMOApply k
  4130. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4131. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.ApplyCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4132. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4133. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4134. where k.ApplyCode='{0}' and a.WorkPoint='{1}'";
  4135. sql = string.Format(sql, Code, WorkPoint);
  4136. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4137. }
  4138. //查询占料(工单材料出库(材料出库))
  4139. public DataTable GetGridJsonSeizeM3(string queryJson, ref Pagination jqgridparam)
  4140. {
  4141. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4142. DataTable dt = new DataTable();
  4143. var queryParam = queryJson.ToJObject();
  4144. List<DbParameter> parameter = new List<DbParameter>();
  4145. string sql = "";
  4146. #region [SQL]
  4147. sql = @"select distinct a.IssueCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,e.MergeID AS IsNew,
  4148. case when k.TransCode is null then '' else '' end as IsOccupy
  4149. from ICSMOIssue a
  4150. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4151. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.IssueCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4152. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'";
  4153. sql = string.Format(sql, WorkPoint);
  4154. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4155. #endregion
  4156. #region 条件
  4157. if (!string.IsNullOrWhiteSpace(queryJson))
  4158. {
  4159. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4160. {
  4161. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4162. }
  4163. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4164. {
  4165. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4166. }
  4167. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4168. {
  4169. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4170. }
  4171. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4172. {
  4173. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4174. }
  4175. }
  4176. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4177. {
  4178. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4179. }
  4180. #endregion
  4181. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4182. }
  4183. //查询占料(工单材料出库(材料出库))子表查询
  4184. public DataTable GetSubGridJsonSeizeM3(string Code)
  4185. {
  4186. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4187. DataTable dt = new DataTable();
  4188. //var queryParam = queryJson.ToJObject();
  4189. List<DbParameter> parameter = new List<DbParameter>();
  4190. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4191. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4192. from ICSMOApply k
  4193. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4194. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.ApplyCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4195. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4196. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4197. where k.ApplyCode='{0}' and a.WorkPoint='{1}'";
  4198. sql = string.Format(sql, Code, WorkPoint);
  4199. return Repository().FindTableBySql(sql.ToString());
  4200. }
  4201. //查询占料(委外备料(委外备料))
  4202. public DataTable GetGridJsonSeizeM4(string queryJson, ref Pagination jqgridparam)
  4203. {
  4204. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4205. DataTable dt = new DataTable();
  4206. var queryParam = queryJson.ToJObject();
  4207. List<DbParameter> parameter = new List<DbParameter>();
  4208. string sql = "";
  4209. #region [SQL]
  4210. sql = @"select distinct b.OOCode as Code, b.CreateDateTime as MTIME,b.CreatePerson as MUSER,e.MergeID AS IsNew,
  4211. case when k.TransCode is null then '' else '' end as IsOccupy
  4212. from ICSOOPick a
  4213. inner join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  4214. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4215. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on b.OOCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4216. WHERE isnull(k.TransCode,'')<>'' and b.WorkPoint='{0}'";
  4217. sql = string.Format(sql, WorkPoint);
  4218. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4219. #endregion
  4220. #region 条件
  4221. if (!string.IsNullOrWhiteSpace(queryJson))
  4222. {
  4223. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4224. {
  4225. sql += " and a.OOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4226. }
  4227. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4228. {
  4229. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4230. }
  4231. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4232. {
  4233. sql += " and convert(nvarchar(20),b.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4234. }
  4235. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4236. {
  4237. sql += " and convert(nvarchar(20),b.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4238. }
  4239. }
  4240. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4241. {
  4242. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4243. }
  4244. #endregion
  4245. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4246. }
  4247. //查询占料(委外备料(委外备料))子表查询
  4248. public DataTable GetSubGridJsonSeizeM4(string Code, ref Pagination jqgridparam)
  4249. {
  4250. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4251. DataTable dt = new DataTable();
  4252. //var queryParam = queryJson.ToJObject();
  4253. List<DbParameter> parameter = new List<DbParameter>();
  4254. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4255. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4256. from ICSOOPick k
  4257. inner join ICSOutsourcingOrder d on k.OODetailID=d.OODetailID and k.WorkPoint=d.WorkPoint
  4258. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4259. inner join ICSWareHouseLotInfoLog a on a.TransCode=d.OOCode and d.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4260. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4261. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4262. where d.OOCode='{0}' and a.WorkPoint='{1}'";
  4263. sql = string.Format(sql, Code, WorkPoint);
  4264. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4265. }
  4266. //查询占料(委外领料(委外发料申请))
  4267. public DataTable GetGridJsonSeizeM5(string queryJson, ref Pagination jqgridparam)
  4268. {
  4269. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4270. DataTable dt = new DataTable();
  4271. var queryParam = queryJson.ToJObject();
  4272. List<DbParameter> parameter = new List<DbParameter>();
  4273. string sql = "";
  4274. #region [SQL]
  4275. sql = @"select distinct a.ApplyCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4276. case when k.TransCode is null then '' else '' end as IsOccupy
  4277. from ICSOApply a
  4278. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4279. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ApplyCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4280. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'";
  4281. sql = string.Format(sql, WorkPoint);
  4282. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4283. #endregion
  4284. #region 条件
  4285. if (!string.IsNullOrWhiteSpace(queryJson))
  4286. {
  4287. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4288. {
  4289. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4290. }
  4291. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4292. {
  4293. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4294. }
  4295. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4296. {
  4297. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4298. }
  4299. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4300. {
  4301. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4302. }
  4303. }
  4304. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4305. {
  4306. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4307. }
  4308. #endregion
  4309. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4310. }
  4311. //查询占料(委外领料(委外发料申请))子表查询
  4312. public DataTable GetSubGridJsonSeizeM5(string Code, ref Pagination jqgridparam)
  4313. {
  4314. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4315. DataTable dt = new DataTable();
  4316. //var queryParam = queryJson.ToJObject();
  4317. List<DbParameter> parameter = new List<DbParameter>();
  4318. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4319. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4320. from ICSOApply k
  4321. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4322. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.ApplyCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4323. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4324. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4325. where k.ApplyCode='{0}' and a.WorkPoint='{1}'";
  4326. sql = string.Format(sql, Code, WorkPoint);
  4327. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4328. }
  4329. //查询占料(委外材料出库(委外发料申请))
  4330. public DataTable GetGridJsonSeizeM6(string queryJson, ref Pagination jqgridparam)
  4331. {
  4332. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4333. DataTable dt = new DataTable();
  4334. var queryParam = queryJson.ToJObject();
  4335. List<DbParameter> parameter = new List<DbParameter>();
  4336. string sql = "";
  4337. #region [SQL]
  4338. sql = @"select distinct a.IssueCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4339. case when k.TransCode is null then '' else '' end as IsOccupy
  4340. from ICSOIssue a
  4341. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4342. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.IssueCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4343. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'
  4344. ";
  4345. sql = string.Format(sql, WorkPoint);
  4346. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4347. #endregion
  4348. #region 条件
  4349. if (!string.IsNullOrWhiteSpace(queryJson))
  4350. {
  4351. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4352. {
  4353. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4354. }
  4355. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4356. {
  4357. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4358. }
  4359. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4360. {
  4361. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4362. }
  4363. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4364. {
  4365. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4366. }
  4367. }
  4368. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4369. {
  4370. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4371. }
  4372. #endregion
  4373. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4374. }
  4375. //查询占料(委外材料出库(委外发料申请))子表查询
  4376. public DataTable GetSubGridJsonSeizeM6(string Code, ref Pagination jqgridparam)
  4377. {
  4378. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4379. DataTable dt = new DataTable();
  4380. //var queryParam = queryJson.ToJObject();
  4381. List<DbParameter> parameter = new List<DbParameter>();
  4382. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4383. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4384. from ICSOIssue k
  4385. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4386. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.IssueCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4387. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4388. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4389. where k.IssueCode='{0}' and a.WorkPoint='{1}'";
  4390. sql = string.Format(sql, Code, WorkPoint);
  4391. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4392. }
  4393. //查询占料(销售发货(销售发货))
  4394. public DataTable GetGridJsonSeizeM7(string queryJson, ref Pagination jqgridparam)
  4395. {
  4396. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4397. DataTable dt = new DataTable();
  4398. var queryParam = queryJson.ToJObject();
  4399. List<DbParameter> parameter = new List<DbParameter>();
  4400. string sql = "";
  4401. #region [SQL]
  4402. sql = @"select distinct a.SDNCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4403. case when k.TransCode is null then '' else '' end as IsOccupy
  4404. from ICSSDN a
  4405. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4406. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.SDNCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4407. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'";
  4408. sql = string.Format(sql, WorkPoint);
  4409. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4410. #endregion
  4411. #region 条件
  4412. if (!string.IsNullOrWhiteSpace(queryJson))
  4413. {
  4414. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4415. {
  4416. sql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4417. }
  4418. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4419. {
  4420. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4421. }
  4422. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4423. {
  4424. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4425. }
  4426. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4427. {
  4428. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4429. }
  4430. }
  4431. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4432. {
  4433. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4434. }
  4435. #endregion
  4436. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4437. }
  4438. //查询占料(销售发货(销售发货))子表查询
  4439. public DataTable GetSubGridJsonSeizeM7(string Code, ref Pagination jqgridparam)
  4440. {
  4441. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4442. DataTable dt = new DataTable();
  4443. //var queryParam = queryJson.ToJObject();
  4444. List<DbParameter> parameter = new List<DbParameter>();
  4445. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4446. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4447. from ICSSDN k
  4448. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4449. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.SDNCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4450. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4451. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4452. where k.SDNCode='{0}' and a.WorkPoint='{1}'";
  4453. sql = string.Format(sql, Code, WorkPoint);
  4454. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4455. }
  4456. //查询占料(其它出库(其它出库))
  4457. public DataTable GetGridJsonSeizeM8(string queryJson, ref Pagination jqgridparam)
  4458. {
  4459. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4460. DataTable dt = new DataTable();
  4461. var queryParam = queryJson.ToJObject();
  4462. List<DbParameter> parameter = new List<DbParameter>();
  4463. string sql = "";
  4464. #region [SQL]
  4465. sql = @"select distinct a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4466. case when k.TransCode is null then '' else '' end as IsOccupy
  4467. from ICSOtherOut a
  4468. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4469. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.OutCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4470. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'";
  4471. sql = string.Format(sql, WorkPoint);
  4472. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4473. #endregion
  4474. #region 条件
  4475. if (!string.IsNullOrWhiteSpace(queryJson))
  4476. {
  4477. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4478. {
  4479. sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4480. }
  4481. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4482. {
  4483. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4484. }
  4485. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4486. {
  4487. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4488. }
  4489. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4490. {
  4491. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4492. }
  4493. }
  4494. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4495. {
  4496. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4497. }
  4498. #endregion
  4499. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4500. }
  4501. //查询占料(其它出库(其它出库))子表查询
  4502. public DataTable GetSubGridJsonSeizeM8(string Code, ref Pagination jqgridparam)
  4503. {
  4504. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4505. DataTable dt = new DataTable();
  4506. //var queryParam = queryJson.ToJObject();
  4507. List<DbParameter> parameter = new List<DbParameter>();
  4508. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4509. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4510. from ICSOtherOut k
  4511. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4512. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.OutCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4513. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4514. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4515. where k.OutCode='{0}' and a.WorkPoint='{1}'";
  4516. sql = string.Format(sql, Code, WorkPoint);
  4517. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4518. }
  4519. //查询占料(借用(借用))
  4520. public DataTable GetGridJsonSeizeM9(string queryJson, ref Pagination jqgridparam)
  4521. {
  4522. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4523. DataTable dt = new DataTable();
  4524. var queryParam = queryJson.ToJObject();
  4525. List<DbParameter> parameter = new List<DbParameter>();
  4526. string sql = "";
  4527. #region [SQL]
  4528. sql = @"select distinct a.BrrowCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4529. case when k.TransCode is null then '' else '' end as IsOccupy
  4530. from ICSBrrow a
  4531. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4532. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.BrrowCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4533. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}'";
  4534. sql = string.Format(sql, WorkPoint);
  4535. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4536. #endregion
  4537. #region 条件
  4538. if (!string.IsNullOrWhiteSpace(queryJson))
  4539. {
  4540. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4541. {
  4542. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4543. }
  4544. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4545. {
  4546. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4547. }
  4548. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4549. {
  4550. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4551. }
  4552. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4553. {
  4554. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4555. }
  4556. }
  4557. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4558. {
  4559. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4560. }
  4561. #endregion
  4562. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4563. }
  4564. //查询占料(借用(借用))子表查询
  4565. public DataTable GetSubGridJsonSeizeM9(string Code, ref Pagination jqgridparam)
  4566. {
  4567. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4568. DataTable dt = new DataTable();
  4569. //var queryParam = queryJson.ToJObject();
  4570. List<DbParameter> parameter = new List<DbParameter>();
  4571. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4572. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4573. from ICSBrrow k
  4574. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4575. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.BrrowCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4576. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4577. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4578. where k.BrrowCode='{0}' and a.WorkPoint='{1}'";
  4579. sql = string.Format(sql, Code, WorkPoint);
  4580. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4581. }
  4582. //查询占料(物料调拨)
  4583. public DataTable GetGridJsonSeizeM10(string queryJson, ref Pagination jqgridparam)
  4584. {
  4585. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4586. DataTable dt = new DataTable();
  4587. var queryParam = queryJson.ToJObject();
  4588. List<DbParameter> parameter = new List<DbParameter>();
  4589. string sql = "";
  4590. #region [SQL]
  4591. sql = @"select distinct a.TransferNO as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4592. case when k.TransCode is null then '' else '' end as IsOccupy
  4593. from ICSTransfer a
  4594. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4595. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.TransferNO=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4596. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}' and a.Status='1'";
  4597. sql = string.Format(sql, WorkPoint);
  4598. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4599. #endregion
  4600. #region 条件
  4601. if (!string.IsNullOrWhiteSpace(queryJson))
  4602. {
  4603. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4604. {
  4605. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4606. }
  4607. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4608. {
  4609. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4610. }
  4611. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4612. {
  4613. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4614. }
  4615. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4616. {
  4617. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4618. }
  4619. }
  4620. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4621. {
  4622. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4623. }
  4624. #endregion
  4625. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4626. }
  4627. //查询占料(物料调拨)子表查询
  4628. public DataTable GetSubGridJsonSeizeM10(string Code, ref Pagination jqgridparam)
  4629. {
  4630. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4631. DataTable dt = new DataTable();
  4632. //var queryParam = queryJson.ToJObject();
  4633. List<DbParameter> parameter = new List<DbParameter>();
  4634. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4635. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4636. from ICSTransfer k
  4637. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4638. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.TransferNO and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4639. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4640. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4641. where k.TransferNO='{0}' and a.WorkPoint='{1}'";
  4642. sql = string.Format(sql, Code, WorkPoint);
  4643. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4644. }
  4645. //两步调拨
  4646. public DataTable GetGridJsonSeizeM11(string queryJson, ref Pagination jqgridparam)
  4647. {
  4648. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4649. DataTable dt = new DataTable();
  4650. var queryParam = queryJson.ToJObject();
  4651. List<DbParameter> parameter = new List<DbParameter>();
  4652. string sql = "";
  4653. #region [SQL]
  4654. sql = @"select distinct a.OutCode as Code, a.CreateDateTime as MTIME,a.CreatePerson as MUSER,e.MergeID AS IsNew,
  4655. case when k.TransCode is null then '' else '' end as IsOccupy
  4656. FROM ICSOtherOut a
  4657. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  4658. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4659. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.OutCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='15'
  4660. where isnull(k.TransCode,'')<>'' and a.WorkPoint='{0}' and a.Status='2'";
  4661. sql = string.Format(sql, WorkPoint);
  4662. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4663. #endregion
  4664. #region 条件
  4665. if (!string.IsNullOrWhiteSpace(queryJson))
  4666. {
  4667. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4668. {
  4669. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4670. }
  4671. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4672. {
  4673. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4674. }
  4675. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4676. {
  4677. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4678. }
  4679. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4680. {
  4681. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4682. }
  4683. }
  4684. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4685. {
  4686. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4687. }
  4688. #endregion
  4689. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4690. }
  4691. //查询占料(物料调拨)子表查询
  4692. public DataTable GetSubGridJsonSeizeM11(string Code, ref Pagination jqgridparam)
  4693. {
  4694. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4695. DataTable dt = new DataTable();
  4696. //var queryParam = queryJson.ToJObject();
  4697. List<DbParameter> parameter = new List<DbParameter>();
  4698. string sql = @"select isnull(e.MergeID,'') as MergeID,a.TransCode as Code,a.TransSequence as Sequence,a.InvCode as InvCode, b.InvName as InvName,b.InvStd as InvStd,b.InvUnit as InvSInvUnittd,a.Quantity as iQuantity,
  4699. a.FromWarehouseCode as WarehouseCode,a.FromLocationCode as LocationCode,a.LotNO,a.MTIME,c.Quantity as QTY
  4700. FROM ICSOtherOut k
  4701. INNER JOIN ICSTransfer tra ON k.TransferDetailID=tra.TransferDetailID AND k.WorkPoint=tra.WorkPoint
  4702. left join ICSMOPickMerge e on k.ID=e.SourceID and k.WorkPoint=e.WorkPoint
  4703. inner join ICSWareHouseLotInfoLog a on a.TransCode=k.OutCode and k.Sequence=a.TransSequence and a.TransType='15' and a.WorkPoint=k.WorkPoint
  4704. left join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  4705. left join dbo.ICSWareHouseLotInfo c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  4706. where k.OutCode='{0}' and a.WorkPoint='{1}'";
  4707. sql = string.Format(sql, Code, WorkPoint);
  4708. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4709. }
  4710. //删除占料
  4711. public string DelPickLog(string objCode)
  4712. {
  4713. //站点信息
  4714. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4715. string msg = "";
  4716. objCode = objCode.Substring(1, objCode.Length - 2);
  4717. string sql = string.Empty;
  4718. sql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  4719. from dbo.ICSWareHouseLotInfo b
  4720. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode in ({0})and TransType='15' and WorkPoint='{1}' group by LotNo) c
  4721. on c.LotNo =b.LotNo ", objCode.TrimEnd(','), WorkPoint);
  4722. sql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode in({0}) and TransType='15' and WorkPoint='{1}'", objCode.TrimEnd(','), WorkPoint);
  4723. try
  4724. {
  4725. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  4726. {
  4727. }
  4728. }
  4729. catch (Exception ex)
  4730. {
  4731. throw new Exception(ex.Message);
  4732. }
  4733. return msg;
  4734. }
  4735. //补料
  4736. public DataTable GetGridJson12(string queryJson, ref Pagination jqgridparam)
  4737. {
  4738. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4739. DataTable dt = new DataTable();
  4740. var queryParam = queryJson.ToJObject();
  4741. List<DbParameter> parameter = new List<DbParameter>();
  4742. string sql = "";
  4743. #region [SQL]
  4744. sql = @"
  4745. select distinct a.ReplenishmentCode as Code,a.CreateDateTime as MTIME,a.createperson as MUSER,e.MergeID AS IsNew,
  4746. case when k.TransCode is null then '' else '' end as IsOccupy
  4747. from ICSMOReplenishment a
  4748. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4749. left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLotInfoLog ) k on a.ReplenishmentCode=k.TransCode and a.WorkPoint=k.WorkPoint and k.TransType='3'
  4750. where a.WorkPoint='{0}'";
  4751. sql = string.Format(sql, WorkPoint);
  4752. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4753. #endregion
  4754. if (!string.IsNullOrWhiteSpace(queryJson))
  4755. {
  4756. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4757. {
  4758. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4759. }
  4760. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4761. {
  4762. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4763. }
  4764. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4765. {
  4766. sql += " and convert(nvarchar(20),a.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4767. }
  4768. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4769. {
  4770. sql += " and convert(nvarchar(20),a.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4771. }
  4772. }
  4773. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4774. }
  4775. //补料子表查询
  4776. public DataTable GetSubGridJson12(string Code, string InvCode, ref Pagination jqgridparam)
  4777. {
  4778. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4779. DataTable dt = new DataTable();
  4780. //var queryParam = queryJson.ToJObject();
  4781. List<DbParameter> parameter = new List<DbParameter>();
  4782. string sql = @" select a.ID,a.ReplenishmentCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  4783. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  4784. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  4785. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  4786. from ICSMOReplenishment a
  4787. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  4788. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  4789. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint
  4790. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  4791. where a.ReplenishmentCode='{0}' and a.WorkPoint='{1}'";
  4792. if (!string.IsNullOrWhiteSpace(InvCode))
  4793. {
  4794. sql += " and a.InvCode = '" + InvCode + "' ";
  4795. }
  4796. sql = string.Format(sql, Code, WorkPoint);
  4797. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4798. }
  4799. }
  4800. }