using NFine.Data.Extensions; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using NFine.Code; using NFine.Repository; using System.Data.Common; using NFine.Domain._03_Entity.SRM; using ICS.Application.Entity; using Newtonsoft.Json; using System.Configuration; using System.Data.SqlClient; using ICS.Data; namespace NFine.Application.WMS { public class PickMaterialApp : RepositoryFactory { public static DataTable Invmes = new DataTable(); //工单备料(工单子件) public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSMOPick a left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and b.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //工单领料(发料申请) public DataTable GetGridJson2(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSMOApply a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //工单材料出库(材料出库) public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSMOIssue a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint "; sql += " WHERE 1=1 and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //委外备料(委外备料) public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSOOPick a left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.OOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //委外领料(委外发料申请) public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSOApply a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //委外材料出库(委外发料申请) public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSOIssue a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //销售发货(销售发货) public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSSDN a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and a.Type='1' and e.ID is null"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //其它出库(其它出库) public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSOtherOut a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null "; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //借用(借用) public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = ""; #region [SQL] 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, case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity from ICSBrrow a left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint"; sql += " WHERE 1=1 and e.ID is null "; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") //{ // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; //} return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetICSMOPickMergeTemp(string ID,string Type) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; #region sql string sql = @"SELECT row_number() over (order by c.Code) AS rowNo, c.Code, c.InvCode, c.InvName, c.InvStd, FLOOR(c.iQuantity) AS iQuantity, d.WarehouseCode, d.LocationCode, d.LotNO, FLOOR(ISNULL(d.Quantity, 0)) AS QTY, CONVERT(varchar(100),d.MTIME, 23) MTIME, FLOOR(f.QTYTotal) QTYTotal INTO #temp FROM ({0}) c LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='6000' AND d.Quantity>0 LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='6000' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode ORDER BY c.InvCode,d.MTIME,d.LotNO DECLARE @ItemCode VARCHAR(50), @QTY DECIMAL(18,3), @ItemCodeCurrent VARCHAR(50), @QTYCurrent DECIMAL(18,3), @iQuantityCurrent DECIMAL(18,3), @CanDelete BIT, @Row INT, @rowCurrent INT SET @Row = @@rowcount SET @rowCurrent=1 SET @CanDelete=0 SET @ItemCode='' WHILE @rowCurrent<=@Row BEGIN SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent PRINT(@rowCurrent) IF @ItemCode<>@ItemCodeCurrent BEGIN SET @ItemCode=@ItemCodeCurrent SET @QTY=0 SET @CanDelete=0 END IF @CanDelete=1 BEGIN DELETE FROM #temp WHERE rowNo=@rowCurrent SET @rowCurrent += 1 CONTINUE END SET @QTY += @QTYCurrent IF @QTY>=@iQuantityCurrent BEGIN SET @CanDelete=1 END SET @rowCurrent += 1 END SELECT * FROM #temp DROP TABLE #temp "; #endregion string sqls = ""; if (Type=="1") { #region 工单备料sql sqls = @" SELECT c.MOCode as Code, a.Sequence, a.InvCode, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSMOPick a inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE c.MOCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type == "2") { #region 工单领料SQL sqls = @" select a.ApplyCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSMOApply a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.ApplyCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type=="3") { #region 工单材料出库SQL sqls = @" select a.IssueCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSMOIssue a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.IssueCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type=="4") { #region 委外备料SQL sqls = @" select c.OOCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOOPick a left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE c.OOCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type=="5") { #region 委外领料SQL sqls = @" select a.ApplyCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOApply a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.ApplyCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type=="6") { #region 委外材料出库SQL sqls = @" select a.IssueCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOIssue a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.IssueCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type=="7") { #region 销售发货SQL sqls = @" select a.SDNCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSSDN a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.SDNCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type=="8") { #region 其它出库SQL sqls = @" select a.OutCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOtherOut a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.OutCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } if (Type == "9") { #region 借用SQL sqls = @"select a.BrrowCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSBrrow a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.BrrowCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence"; #endregion } sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID)?"''":ID.TrimEnd(','),WorkPoint); sql = string.Format(sql, sqls); DataTable table = Repository().FindDataSetBySql(sql).Tables[0]; DataTable dtCloned = table.Clone(); foreach (DataColumn col in dtCloned.Columns) { col.DataType = typeof(string); } foreach (DataRow row in table.Rows) { DataRow newrow = dtCloned.NewRow(); foreach (DataColumn column in dtCloned.Columns) { newrow[column.ColumnName] = row[column.ColumnName].ToString(); } dtCloned.Rows.Add(newrow); } if (Invmes.Rows.Count > 0) { dtCloned.Merge(Invmes, false); } return dtCloned; } public DataTable GetICSMOPickMergeTemp2(string ID, string Type) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; #region sql string sql = @"SELECT row_number() over (order by c.Code) AS rowNo, c.MergeID, c.Code, c.InvCode, c.InvName, c.InvStd, FLOOR(c.iQuantity) AS iQuantity, d.WarehouseCode, d.LocationCode, d.LotNO, FLOOR(ISNULL(d.Quantity, 0)) AS QTY, CONVERT(varchar(100),d.MTIME, 23) MTIME, FLOOR(f.QTYTotal) QTYTotal INTO #temp FROM ({0}) c LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='6000' AND d.Quantity>0 LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='6000' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode ORDER BY c.InvCode,d.MTIME,d.LotNO DECLARE @ItemCode VARCHAR(50), @QTY DECIMAL(18,3), @ItemCodeCurrent VARCHAR(50), @QTYCurrent DECIMAL(18,3), @iQuantityCurrent DECIMAL(18,3), @CanDelete BIT, @Row INT, @rowCurrent INT SET @Row = @@rowcount SET @rowCurrent=1 SET @CanDelete=0 SET @ItemCode='' WHILE @rowCurrent<=@Row BEGIN SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent PRINT(@rowCurrent) IF @ItemCode<>@ItemCodeCurrent BEGIN SET @ItemCode=@ItemCodeCurrent SET @QTY=0 SET @CanDelete=0 END IF @CanDelete=1 BEGIN DELETE FROM #temp WHERE rowNo=@rowCurrent SET @rowCurrent += 1 CONTINUE END SET @QTY += @QTYCurrent IF @QTY>=@iQuantityCurrent BEGIN SET @CanDelete=1 END SET @rowCurrent += 1 END SELECT * FROM #temp DROP TABLE #temp "; #endregion string sqls = ""; if (Type == "1") { #region 工单备料sql sqls = @" select x.MergeID, c.MOCode as Code, a.Sequence, a.InvCode, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSMOPick a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "2") { #region 工单领料SQL sqls = @" select x.MergeID, a.ApplyCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSMOApply a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "3") { #region 工单材料出库SQL sqls = @" select x.MergeID, a.IssueCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSMOIssue a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "4") { #region 委外备料SQL sqls = @" select x.MergeID, c.OOCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOOPick a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence, x.MergeID"; #endregion } if (Type == "5") { #region 委外领料SQL sqls = @" select x.MergeID, a.ApplyCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOApply a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "6") { #region 委外材料出库SQL sqls = @" select x.MergeID, a.IssueCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOIssue a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "7") { #region 销售发货SQL sqls = @" select x.MergeID, a.SDNCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSSDN a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "8") { #region 其它出库SQL sqls = @" select x.MergeID, a.OutCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSOtherOut a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } if (Type == "9") { #region 借用SQL sqls = @" select x.MergeID, a.BrrowCode as Code, a.InvCode, a.Sequence, b.InvName, b.InvStd, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode FROM ICSBrrow a inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID"; #endregion } sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint); sql = string.Format(sql, sqls); DataTable table = Repository().FindDataSetBySql(sql).Tables[0]; DataTable dtCloned = table.Clone(); foreach (DataColumn col in dtCloned.Columns) { col.DataType = typeof(string); } foreach (DataRow row in table.Rows) { DataRow newrow = dtCloned.NewRow(); foreach (DataColumn column in dtCloned.Columns) { newrow[column.ColumnName] = row[column.ColumnName].ToString(); } dtCloned.Rows.Add(newrow); } if (Invmes.Rows.Count > 0) { dtCloned.Merge(Invmes, false); } return dtCloned; } public string MergeMaterial(string keyValue,string Type) { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; keyValue = keyValue.TrimEnd(','); string[] str = keyValue.Split(','); DateTime time = DateTime.Now; string Tday = time.ToString("yyyyMMdd"); string sqls = string.Format(@"SELECT MAX(A.SourceID) AS SourceID FROM ICSMOPickMerge A WHERE A.SourceID LIKE '{0}%' AND LEN(a.SourceID) = 13", Tday); DataSet ds = SqlHelper.GetDataSetBySql(sqls); string MergeID = ""; Int64 Merge_ID = 0; DataTable dts = ds.Tables[0]; if (dts != null && dts.Rows.Count > 0) { string lot = dts.Rows[0]["SourceID"].ToString(); if (!string.IsNullOrWhiteSpace(lot)) Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5)); } foreach (var item in str) { MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0'); sql += @"INSERT INTO dbo.ICSMOPickMerge ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint) Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{5}') "; sql = string.Format(sql, MergeID, item, Type, MUSER, MUSERNAME, WorkPoint); } try { if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public string CheckQty(string objArr) { objArr= objArr.TrimEnd(','); string sql = @"select * from ICSMOPickMerge where SourceID in ({0})"; sql = string.Format(sql, objArr); DataTable dt = SqlHelper.GetDataTableBySql(sql); if (dt != null&&dt.Rows.Count>0) { return "1"; } return "0"; } } }