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; using Newtonsoft.Json.Linq; using NFine.Domain._03_Entity.WMS; using System.Net; using System.IO; namespace NFine.Application.DHAY { public class DHICSRCVIQCsApp : RepositoryFactory { /// /// 采购 /// /// /// public DataTable GetICSInspection(ref Pagination jqgridparam, string queryJson) { string ERPSign = Configs.GetValue("ERPSign"); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; if (ERPSign == "U8") { sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_1 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, d.ID , h.ID as JYID, a.DNCode , -- a.Sequence , a.ASNCode , l.POCode, c.InvCode , c.InvName , c.INVSTD , c.ClassName, c.EATTRIBUTE3 as InvEATTRIBUTE3, CAST(b.DNQuantity as decimal(18,4)) as AllNumber, CAST(ISNULL(h.QualifiedQuantity, b.DNQuantity)as decimal(18,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY, CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint, --CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity, c.InvUnit , b.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue, j.BadCode as BCCodeValue, j.BadDesc as BadDesc, k.ContainerID, q.ContainerCode, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime, CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime, CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, a.VenCode, m.VenName, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0) WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,o.Editable ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2 WHERE hH2.LotNo=b.LotNo AND hH2.WorkPoint=b.WorkPoint),0) WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK ,case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC into #TempLLData_1 FROM ICSDeliveryNotice a inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1' inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.ExtensionID=d.ExtensionID AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint LEFT JOIN ICSContainer q on k.ContainerID=q.ContainerID AND k.WorkPoint=q.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND d.WorkPoint=l.WorkPoint left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND b.DNQuantity BETWEEN p.SetValueMin AND p.SetValueMax where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0} select * into #TempLLData_1_1 from #TempLLData_1 where InvIQC='1' "; } else { sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,SampleQuantity, MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_1 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, d.ID , h.ID as JYID, a.DNCode , a.Sequence , a.ASNCode , l.POCode, c.InvCode , c.InvName , c.INVSTD , c.ClassName, c.EATTRIBUTE3 as InvEATTRIBUTE3, CAST(d.Quantity as decimal(18,4)) as AllNumber, CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY, CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint, -- CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity, c.InvUnit , d.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue, j.BadCode as BCCodeValue, j.BadDesc as BadDesc, k.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime, CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime, CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, a.VenCode, m.VenName, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0) WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,o.Editable ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2 WHERE hH2.LotNo=d.LotNo AND hH2.WorkPoint=a.WorkPoint),0) WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK , case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC into #TempLLData_1 FROM ICSDeliveryNotice a --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1' inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND a.WorkPoint=l.WorkPoint left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where d.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0} select * into #TempLLData_1_1 from #TempLLData_1 "; } string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetInspectionFile(ref Pagination jqgridparam, string queryJson, string JYID) { var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"SELECT * FROM dbo.ICSInspectionFile WHERE InspectionID='{0}'"; sql = string.Format(sql, JYID); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 根据批次获取检验信息 /// /// /// /// public DataTable GetICSInspectionBatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_1 from dbo.ICSInspection where workpoint='{1}' and Enable='1' SELECT a.ASNCode,A.DNCode,a.Sequence,e.BatchCode,l.POCode,j.InvCode ,j.InvName ,j.INVSTD ,j.InvUnit ,j.InvDesc,a.WorkPoint,n.VenName,n.VenCode,c.MTIME as CreateDateTime,CAST(ISNULL(SUM(c.Quantity),0)AS DECIMAL (18,4) ) as AllNumber, CAST(ISNULL(SUM(h.QualifiedQuantity), 0)as decimal(18,4))as YLOTQTY , CAST ( ISNULL( SUM(h.UnqualifiedQuantity), 0 ) AS DECIMAL (18, 4) ) AS NLOTQTY,CAST ( ISNULL( SUM(h.WaiveQuantity), 0 ) AS DECIMAL (18, 4) ) AS SpecialQTY,CAST ( ISNULL( SUM(h.SampleQuantity), 0 ) AS DECIMAL (18, 4) ) AS SampleQuantity into #TempLLData_1 FROM ICSDeliveryNotice a INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode left JOIN #TempIcsinsp_1 h ON c.LotNo=h.LotNo AND h.WorkPoint= c.WorkPoint LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID LEFT JOIN ICSExtension e ON e.ID=a.ExtensionID AND e.WorkPoint =a.WorkPoint LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint INNER JOIN ICSPurchaseOrder l ON m.TransCode = l.POCode AND m.TransSequence= l.Sequence AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID AND l.PODetailID=a.PODetailID LEFT JOIN ICSVendor n ON a.VenCode= n.VenCode AND a.WorkPoint= n.WorkPoint INNER JOIN ICSInventory j ON a.invCode=j.invCode AND a.WorkPoint=j.workPoint AND j.InvIQC='1' where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and n.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and j.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case b.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += "GROUP BY a.ASNCode,A.DNCode,e.BatchCode,l.POCode,j.InvCode ,j.InvName ,j.INVSTD , j.InvUnit ,j.InvDesc ,j.InvIQC,a.WorkPoint,n.VenName,n.VenCode,c.MTIME,a.Sequence; select * into #TempLLData_1_1 from #TempLLData_1 ; "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 根据单据和行获取检验信息 /// /// /// /// public DataTable GetICSInspectionDocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_1 from dbo.ICSInspection where workpoint='{1}' and Enable='1' SELECT a.ASNCode,A.DNCode,a.Sequence,l.POCode,j.InvCode ,j.InvName ,j.INVSTD ,j.InvUnit ,j.InvDesc,a.WorkPoint,n.VenName,n.VenCode,c.MTIME as CreateDateTime,CAST(ISNULL(SUM(c.Quantity),0)AS DECIMAL (18,4) ) as AllNumber, CAST(ISNULL(SUM(h.QualifiedQuantity), 0)as decimal(18,4))as YLOTQTY , CAST ( ISNULL( SUM(h.UnqualifiedQuantity), 0 ) AS DECIMAL (18, 4) ) AS NLOTQTY,CAST ( ISNULL( SUM(h.WaiveQuantity), 0 ) AS DECIMAL (18, 4) ) AS SpecialQTY,CAST ( ISNULL( SUM(h.SampleQuantity), 0 ) AS DECIMAL (18, 4) ) AS SampleQuantity into #TempLLData_1 FROM ICSDeliveryNotice a INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode left JOIN #TempIcsinsp_1 h ON c.LotNo=h.LotNo AND h.WorkPoint= c.WorkPoint LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID LEFT JOIN ICSExtension e ON e.ID=a.ExtensionID AND e.WorkPoint =a.WorkPoint LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint INNER JOIN ICSPurchaseOrder l ON m.TransCode = l.POCode AND m.TransSequence= l.Sequence AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID AND l.PODetailID=a.PODetailID LEFT JOIN ICSVendor n ON a.VenCode= n.VenCode AND a.WorkPoint= n.WorkPoint INNER JOIN ICSInventory j ON a.invCode=j.invCode AND a.WorkPoint=j.workPoint AND j.InvIQC='1' where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and n.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and j.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case b.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += "GROUP BY a.ASNCode,A.DNCode,l.POCode,j.InvCode ,j.InvName ,j.INVSTD , j.InvUnit ,j.InvDesc ,j.InvIQC,a.WorkPoint,n.VenName,n.VenCode,c.MTIME,a.Sequence; select * into #TempLLData_1_1 from #TempLLData_1 ; "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 根据单据获取检验信息 /// /// /// /// public DataTable GetICSInspectionDoc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_1 from dbo.ICSInspection where workpoint='{1}' and Enable='1' SELECT a.ASNCode,A.DNCode,l.POCode,a.WorkPoint,c.MTIME as CreateDateTime,CAST(ISNULL(SUM(c.Quantity),0)AS DECIMAL (18,4) ) as AllNumber, CAST(ISNULL(SUM(h.QualifiedQuantity), 0)as decimal(18,4))as YLOTQTY , CAST ( ISNULL( SUM(h.UnqualifiedQuantity), 0 ) AS DECIMAL (18, 4) ) AS NLOTQTY,CAST ( ISNULL( SUM(h.WaiveQuantity), 0 ) AS DECIMAL (18, 4) ) AS SpecialQTY,CAST ( ISNULL( SUM(h.SampleQuantity), 0 ) AS DECIMAL (18, 4) ) AS SampleQuantity into #TempLLData_1 FROM ICSDeliveryNotice a INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode left JOIN #TempIcsinsp_1 h ON c.LotNo=h.LotNo AND h.WorkPoint= c.WorkPoint LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID LEFT JOIN ICSExtension e ON e.ID=a.ExtensionID AND e.WorkPoint =a.WorkPoint LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint INNER JOIN ICSPurchaseOrder l ON m.TransCode = l.POCode AND m.TransSequence= l.Sequence AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID AND l.PODetailID=a.PODetailID LEFT JOIN ICSVendor n ON a.VenCode= n.VenCode AND a.WorkPoint= n.WorkPoint INNER JOIN ICSInventory j ON a.invCode=j.invCode AND a.WorkPoint=j.workPoint AND j.InvIQC='1' where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and n.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and j.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case b.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += "GROUP BY a.ASNCode,A.DNCode,l.POCode,a.WorkPoint,c.MTIME; select * into #TempLLData_1_1 from #TempLLData_1 ; "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1')) drop table #TempLLData_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1')) drop table #TempIcsinsp_1 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1')) drop table #TempLLData_1_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } //委外 public DataTable GetICSInspection2(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_2 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, d.ID ,h.ID as JYID, a.ODNCode as DNCode ,a.Sequence ,a.OASNCode ,l.OOCode,c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, CAST(b.ODNQuantity as NUMERIC(10,4)) as AllNumber, c.EATTRIBUTE3 as InvEATTRIBUTE3, CAST(ISNULL(h.QualifiedQuantity, b.ODNQuantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint, c.InvUnit , b.LotNo , g.BadReasonDesc as BadReasonDesc ,g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, k.ContainerID,isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime, CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState,a.VenCode,m.VenName, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2 WHERE hH2.LotNo=b.LotNo AND hH2.WorkPoint=b.WorkPoint),0) WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK ,case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC into #TempWWLLData_2 FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1' inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint LEFT JOIN #TempIcsinsp_2 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint -- and Enable='1' LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0} and a.workpoint='{1}' select * into #TempWWLLData_2_1 from #TempWWLLData_2 where InvIQC='1' "; #region 无SRM逻辑 // sql = @"UNION all //select // a.ID as DHID, // d.ID , // h.ID as JYID, // a.ODNCode as DNCode , // a.Sequence , // a.OASNCode , // c.InvCode , // c.InvName , // c.INVSTD , // c.ClassName, // f.BatchCode , // CAST(d.Quantity as NUMERIC(10,4)) as AllNumber, // CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY , // CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, // CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, // c.InvUnit , // d.LotNo , // g.BadReasonDesc as BadReasonDesc , // g.BadReasonCode as BRCodeValue, // j.BadCode as BCCodeValue, // j.BadDesc as BadDesc, // k.ContainerID, // isnull(h.MUSERName,'开发者') MUSERName, // CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime, // CONVERT(VARCHAR(100),h.MTIME,23) as MTIME, // CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState // FROM ICSODeliveryNotice a // inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint // inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint // LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint // LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint // left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint // left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint // LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint // left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint // where 1=1 {0}"; #endregion string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempWWLLData_2_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //委外批次维度检验 public DataTable GetICSInspection2BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_2 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, a.ODNCode as DNCode ,a.Sequence ,a.OASNCode ,l.OOCode,c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, CAST(ISNULL(Sum(b.ODNQuantity), 0) as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(Sum(h.QualifiedQuantity), Sum(b.ODNQuantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(Sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(Sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit , CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,a.VenCode,m.VenName, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a. EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 into #TempWWLLData_2 FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1' inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint LEFT JOIN #TempIcsinsp_2 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.ODNCode ,a.Sequence ,a.OASNCode ,l.OOCode,c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,c.InvUnit , a.CreateDateTime,a.MTIME,a.VenCode,m.VenName, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a. EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10;select * into #TempWWLLData_2_1 from #TempWWLLData_2 ;"; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempWWLLData_2_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 委外按单据维度检验 /// /// /// /// public DataTable GetICSInspection2Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_2 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ODNCode as DNCode ,a.OASNCode ,l.OOCode, CAST(ISNULL(Sum(b.ODNQuantity), 0) as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(Sum(h.QualifiedQuantity), Sum(b.ODNQuantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(Sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(Sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity into #TempWWLLData_2 FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1' inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint LEFT JOIN #TempIcsinsp_2 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ODNCode ,a.OASNCode ,l.OOCode; select * into #TempWWLLData_2_1 from #TempWWLLData_2 "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempWWLLData_2_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 委外按单据行维度检验 /// /// /// /// public DataTable GetICSInspection2DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode into #TempIcsinsp_2 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, a.ODNCode as DNCode ,a.Sequence ,a.OASNCode ,l.OOCode,c.InvCode , c.InvName , c.INVSTD , c.ClassName, CAST(ISNULL(Sum(b.ODNQuantity), 0) as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(Sum(h.QualifiedQuantity), Sum(b.ODNQuantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(Sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(Sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit , CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,a.VenCode,m.VenName, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a. EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 into #TempWWLLData_2 FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1' inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint LEFT JOIN #TempIcsinsp_2 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) { wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) { wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString())) { wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.ODNCode ,a.Sequence ,a.OASNCode ,l.OOCode,c.InvCode , c.InvName , c.INVSTD , c.ClassName, c.InvUnit , a.CreateDateTime,a.MTIME,a.VenCode,m.VenName, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a. EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10;select * into #TempWWLLData_2_1 from #TempWWLLData_2 "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempWWLLData_2_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2')) drop table #TempWWLLData_2 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1')) drop table #TempWWLLData_2_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2')) drop table #TempIcsinsp_2 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //工单 public DataTable GetICSInspection3(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_3 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, e.ID , a.MOCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, e.Quantity as AllNumber, CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') ='' and c.InvFQC='1' THEN '未检验' WHEN c.InvFQC='0' then '免检' ELSE '已检验' END AS TestState, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10--,c.InvIQC ,c.InvFQC into #TempMOData_3 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_3 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where a.MOStatus<>'3' and e.LotNO is not null {0} and isnull(e.EATTRIBUTE1,'' )='' and a.workpoint='{1}' select * into #TempMOData_3_1 from #TempMOData_3 where --InvIQC='1' InvFQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_3_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 工单检验(批次维度) /// /// /// /// public DataTable GetICSInspection3BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_3 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.MOCode as DNCode, a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, sum(e.Quantity)as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,c.EATTRIBUTE3 as InvEATTRIBUTE3, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ,c.InvFQC into #TempMOData_3 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_3 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where a.MOStatus<>'3' and e.LotNO is not null {0} and isnull(e.EATTRIBUTE1,'' )='' and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.MOCode , a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 , c.InvUnit , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ,c.InvFQC ;select * into #TempMOData_3_1 from #TempMOData_3 where --InvIQC='1' InvFQC='1';"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_3_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 工单检验(单据行维度) /// /// /// /// public DataTable GetICSInspection3DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_3 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.MOCode as DNCode, a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvDesc, sum(e.Quantity)as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ,c.InvFQC into #TempMOData_3 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_3 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where a.MOStatus<>'3' and e.LotNO is not null {0} and isnull(e.EATTRIBUTE1,'' )='' and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.MOCode , a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvDesc, c.InvUnit , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ,c.InvFQC ;select * into #TempMOData_3_1 from #TempMOData_3 where --InvIQC='1' InvFQC='1';"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_3_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 工单检验(单据维度) /// /// /// /// public DataTable GetICSInspection3Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_3 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.MOCode as DNCode, sum(e.Quantity)as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity into #TempMOData_3 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint and c.InvFQC='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_3 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where a.MOStatus<>'3' and e.LotNO is not null {0} and isnull(e.EATTRIBUTE1,'' )='' and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.MOCode ;select * into #TempMOData_3_1 from #TempMOData_3 ;"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_3_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3')) drop table #TempMOData_3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1')) drop table #TempMOData_3_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3')) drop table #TempIcsinsp_3", "connstr", parameter.ToArray(), ref jqgridparam); } //其他入库 public DataTable GetICSInspection4(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_4 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, e.ID , a.InCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, e.Quantity as AllNumber, c.EATTRIBUTE3 as InvEATTRIBUTE3, CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2 WHERE hH2.LotNo=e.LotNo AND hH2.WorkPoint=b.WorkPoint and hh2.InvCode=e.InvCode),0) WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK ,case e.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC INTO #TempQTLLData_4 from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.InCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')='' left join ICSExtension f on e.ExtensionID=f.ID and e.WorkPoint=f.WorkPoint LEFT JOIN #TempIcsinsp_4 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where e.LotNO is not null {0} and a.workpoint='{1}' select * into #TempQTLLData_4_1 from #TempQTLLData_4 where InvIQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case e.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempQTLLData_4_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 其他入库检验(批次维度) /// /// /// /// public DataTable GetICSInspection4BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_4 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.InCode as DNCode, a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 INTO #TempQTLLData_4 from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint and c.InvIQC='1' left join ICSInventoryLotDetail b on a.InCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')='' left join ICSExtension f on e.ExtensionID=f.ID and e.WorkPoint=f.WorkPoint LEFT JOIN #TempIcsinsp_4 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case e.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID ,a.InCode , a.Sequence ,c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10;select * into #TempQTLLData_4_1 from #TempQTLLData_4 "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempQTLLData_4_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 其他入库检验(单据行维度) /// /// /// /// public DataTable GetICSInspection4DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_4 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.InCode as DNCode, c.InvCode , c.InvName , c.INVSTD , c.ClassName, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 INTO #TempQTLLData_4 from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint and c.InvIQC='1' left join ICSInventoryLotDetail b on a.InCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')='' left join ICSExtension f on e.ExtensionID=f.ID and e.WorkPoint=f.WorkPoint LEFT JOIN #TempIcsinsp_4 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case e.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.InCode ,c.InvCode , c.InvName , c.INVSTD , c.ClassName, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 ;select * into #TempQTLLData_4_1 from #TempQTLLData_4 "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempQTLLData_4_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 其他入库检验(单据维度) /// /// /// /// public DataTable GetICSInspection4Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_4 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.InCode as DNCode, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity INTO #TempQTLLData_4 from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint and c.InvIQC='1' left join ICSInventoryLotDetail b on a.InCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')='' left join ICSExtension f on e.ExtensionID=f.ID and e.WorkPoint=f.WorkPoint LEFT JOIN #TempIcsinsp_4 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString())) { wheresql += " and case e.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString())) { string printState = queryParam["selIsPrint"].ToString(); if (printState == "否") wheresql += " and isnull(task.ValueParameters,'') ='' "; else if (printState == "是") wheresql += " and isnull(task.ValueParameters,'') <>''"; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.InCode ;select * into #TempQTLLData_4_1 from #TempQTLLData_4 "; sql = string.Format(sql, wheresql, WorkPoint); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempQTLLData_4_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4')) drop table #TempQTLLData_4 if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1')) drop table #TempQTLLData_4_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4')) drop table #TempIcsinsp_4 ", "connstr", parameter.ToArray(), ref jqgridparam); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } //生产退料 public DataTable GetICSInspection5(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_5 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, e.ID , a.ApplyNegCode as DNCode, ad.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, e.Quantity as AllNumber, CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,c.EATTRIBUTE3 as InvEATTRIBUTE3, g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_5 from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode=ad.ApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.ApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_5 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint-- and Enable='1' left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON ad.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where e.LotNO is not null {0} AND A.Workpoint='{1}' select * into #TempMOData_5_1 from #TempMOData_5 where InvIQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_5_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 生产退料(批次维度) /// /// /// /// public DataTable GetICSInspection5BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_5 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.ApplyNegCode as DNCode, ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_5 from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode=ad.ApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.ApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_5 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint-- and Enable='1' where e.LotNO is not null {0} AND A.Workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.ApplyNegCode , ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,c.InvUnit , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC ; select * into #TempMOData_5_1 from #TempMOData_5 where InvIQC='1' "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_5_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 生产退料(单据行维度) /// /// /// /// public DataTable GetICSInspection5DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_5 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select a.ID as GDID, a.ApplyNegCode as DNCode, ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_5 from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode=ad.ApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.ApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_5 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint-- and Enable='1' where e.LotNO is not null {0} AND A.Workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.ApplyNegCode , ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC ; select * into #TempMOData_5_1 from #TempMOData_5 where InvIQC='1' "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_5_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 生产退料(单据维度) /// /// /// /// public DataTable GetICSInspection5Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_5 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select a.ApplyNegCode as DNCode, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity into #TempMOData_5 from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode=ad.ApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint and c.InvIQC='1' left join ICSInventoryLotDetail b on a.ApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_5 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint-- and Enable='1' where e.LotNO is not null {0} AND A.Workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ApplyNegCode ; select * into #TempMOData_5_1 from #TempMOData_5 "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_5_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5')) drop table #TempMOData_5 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1')) drop table #TempMOData_5_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5')) drop table #TempIcsinsp_5 ", "connstr", parameter.ToArray(), ref jqgridparam); } //委外退料 public DataTable GetICSInspection6(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_6 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, e.ID , a.OApplyNegCode as DNCode, ad.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, e.Quantity as AllNumber, c.EATTRIBUTE3 as InvEATTRIBUTE3, CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_6 from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode=ad.OApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.OApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_6 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where e.LotNO is not null {0} and a.workpoint='{1}' select * into #TempMOData_6_1 from #TempMOData_6 where InvIQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_6_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外退料(批次维度) /// /// /// /// public DataTable GetICSInspection6BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_6 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.OApplyNegCode as DNCode, ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_6 from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode=ad.OApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.OApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_6 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' where e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.OApplyNegCode , ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC; select * into #TempMOData_6_1 from #TempMOData_6 where InvIQC='1' ;"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_6_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外退料(单据行维度) /// /// /// /// public DataTable GetICSInspection6DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_6 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.OApplyNegCode as DNCode, ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_6 from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode=ad.OApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.OApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_6 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' where e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.OApplyNegCode , ad.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC; select * into #TempMOData_6_1 from #TempMOData_6 where InvIQC='1' ;"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_6_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外退料(单据维度) /// /// /// /// public DataTable GetICSInspection6Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_6 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.OApplyNegCode as DNCode, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity into #TempMOData_6 from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode=ad.OApplyNegCode AND a.WorkPoint=ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint and c.InvIQC='1' left join ICSInventoryLotDetail b on a.OApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_6 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' where e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.OApplyNegCode; select * into #TempMOData_6_1 from #TempMOData_6 ;"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_6_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6')) drop table #TempMOData_6 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1')) drop table #TempMOData_6_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6')) drop table #TempIcsinsp_6 ", "connstr", parameter.ToArray(), ref jqgridparam); } //销售退货 public DataTable GetICSInspection7(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_7 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, e.ID , a.SDNCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, e.Quantity as AllNumber, c.EATTRIBUTE3 as InvEATTRIBUTE3, CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_7 from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.SDNCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_7 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where e.LotNO is not null AND a.Type='2' {0} and a.workpoint='{1}' select * into #TempMOData_7_1 from #TempMOData_7 where InvIQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_7_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 销售退货(批次维度) /// /// /// /// public DataTable GetICSInspection7BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_7 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.SDNCode as DNCode, a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_7 from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.SDNCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_7 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' where e.LotNO is not null AND a.Type='2' {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.SDNCode , a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC ;select * into #TempMOData_7_1 from #TempMOData_7 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_7_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 销售退货(单据行维度) /// /// /// /// public DataTable GetICSInspection7DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_7 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.SDNCode as DNCode, a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_7 from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.SDNCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_7 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1' where e.LotNO is not null AND a.Type='2' {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.SDNCode , a.Sequence , c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC ;select * into #TempMOData_7_1 from #TempMOData_7 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_7_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 销售退货(单据维度) /// /// /// /// public DataTable GetICSInspection7Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_7 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.SDNCode as DNCode, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity into #TempMOData_7 from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint and c.InvIQC='1' left join ICSInventoryLotDetail b on a.SDNCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_7 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint where e.LotNO is not null AND a.Type='2' {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.SDNCode ;select * into #TempMOData_7_1 from #TempMOData_7 "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_7_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7')) drop table #TempMOData_7 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1')) drop table #TempMOData_7_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7')) drop table #TempIcsinsp_7 ", "connstr", parameter.ToArray(), ref jqgridparam); } //获取不良原因 public DataTable Select_ICSBadReason(string InvCode) { string sql = string.Empty; DataTable dt = null; sql = @"select '' as BadReasonCode,'' as BadReasonDesc from ICSBadReason a left join ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID union select a.BadReasonCode,a.BadReasonDesc from ICSBadReason a left join ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID where b.InvCode='{0}'"; sql = string.Format(sql, InvCode); dt = SqlHelper.GetDataTableBySql(sql); return dt; } //获取不良代码 public DataTable GetSelectICSBadCode(string InvCode) { string sql = string.Empty; DataTable dt = null; sql = @" select '' as BadCode ,'' as BadDesc from dbo.ICSBadCode a left join ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID union select BadCode,BadDesc from dbo.ICSBadCode a left join ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID where b.InvCode='{0}'"; // sql = @"select BadCode,BadDesc from dbo.ICSBadCode a left join //ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID //where b.InvCode='{0}'"; sql = string.Format(sql, InvCode); dt = SqlHelper.GetDataTableBySql(sql); return dt; } /// /// 新增检验 /// /// /// public string CreateICSInspection(string keyValue, string ICSInspections) { 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; JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections); try { foreach (var item in res) { object CARID = Guid.NewGuid(); JObject jo = (JObject)item; string sqls = string.Empty; string type = jo["Type"].ToString(); if (jo["FlagVersion"].ToString() == "1") { #region 2024-08-09 检验添加是否入库验证 var checksql = $@"SELECT ID FROM ICSWareHouseLotInfo WHERE LotNo='{jo["LotNo"]}' AND WorkPoint='{WorkPoint}'"; var checkdt = SqlHelper.CmdExecuteDataTable(checksql); if (checkdt.Rows.Count > 0) { msg = $"条码:{jo["LotNo"]}已经入库,不能再次检验"; return msg; } #endregion if (!string.IsNullOrWhiteSpace(jo["JYID"].ToString())) { sqls += "update ICSInspectionDetailGroup set InspectionID='{2}' WHERE InspectionID='{3}' and WorkPoint='{1}' "; } sqls += @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'"; sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint, CARID, jo["JYID"].ToString()); SqlHelper.CmdExecuteNonQueryLi(sqls); sql += @"INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE1) Values('{13}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1','{12}','{14}','{15}') "; sql = string.Format(sql, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["AllNumber"].ToString(), jo["YLOTQTY"].ToString(), jo["NLOTQTY"].ToString(), jo["SpecialQTY"].ToString(), jo["BCCode"].ToString(), jo["BRCode"].ToString(), jo["Type"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["SampleQuantity"].ToString(), CARID, jo["Result"].ToString(), jo["FlagVersion"].ToString()); } else { var lotNosql = string.Empty; var dt = new DataTable(); if (jo["FlagVersion"].ToString() == "2") { //获取各种单据类型的条码数量信息 if (type == "1") { lotNosql = $@"SELECT b.LotNo,b.Quantity,b.InvCode FROM ICSDeliveryNotice a INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode INNER JOIN ICSExtension d ON d.ID=b.ExtensionID AND b.WorkPoint=d.WorkPoint LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint INNER JOIN ICSPurchaseOrder l ON m.TransID = l.ID AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID AND l.PODetailID=a.PODetailID WHERE d.BatchCode='{jo["BatchCode"]}' AND a.WorkPoint='{WorkPoint}' AND a.DNCode='{jo["DNCode"]}' AND a.Sequence='{jo["Sequence"]}' AND a.DNType='1'"; } else if (type == "2") { lotNosql = $@"SELECT d.LotNo,d.Quantity,d.InvCode FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode = b.OASNCode AND a.WorkPoint = b.WorkPoint inner JOIN ICSInventoryLot d ON b.LotNo = d.LotNo AND a.InvCode = d.InvCode AND b.WorkPoint = d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransID = l.ID AND d.WorkPoint = l.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' AND a.ODNType = '1'"; } else if (type == "3") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND e.ExtensionID = f.ID WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "4") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.InCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')= '' left join ICSExtension f on e.ExtensionID = f.ID and e.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.InCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "5") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode = ad.ApplyNegCode AND a.WorkPoint = ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.ApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "6") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode = ad.OApplyNegCode AND a.WorkPoint = ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.OApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.OApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "7") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.SDNCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.SDNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "8") { lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSDeliveryNotice a left join ICSInventoryLotDetail e on a.DNCode = e.TransCode and a.Sequence = e.TransSequence and a.WorkPoint = e.WorkPoint inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint-- and c.InvIQC = '1' inner JOIN ICSInventoryLot d ON e.LotNo = d.LotNo AND a.InvCode = d.InvCode AND a.WorkPoint = d.WorkPoint and d.type = '7' left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.DNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' and a.DNType = '1' "; } else if (type == "9") { lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode = a.ODNCode AND e.TransSequence = a.Sequence AND e.WorkPoint = a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint and d.type = '8' inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' LEFT JOIN dbo.ICSInspection h ON h.LotNo = d.LotNo AND h.WorkPoint = d.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "10") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' LEFT JOIN ICSMOPick pick ON a.MODetailID = pick.MODetailID AND a.WorkPoint = pick.WorkPoint AND pick.EATTRIBUTE1 = '1' left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence + '~' + pick.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' AND a.MOStatus <> '3' "; } } else if (jo["FlagVersion"].ToString() == "3") { if (type == "1") { lotNosql = $@"SELECT b.LotNo,b.Quantity,b.InvCode FROM ICSDeliveryNotice a INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode INNER JOIN ICSExtension d ON d.ID=b.ExtensionID AND b.WorkPoint=d.WorkPoint LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint INNER JOIN ICSPurchaseOrder l ON m.TransID = l.ID AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID AND l.PODetailID=a.PODetailID WHERE a.WorkPoint='{WorkPoint}' AND a.DNCode='{jo["DNCode"]}' AND a.Sequence='{jo["Sequence"]}' AND a.DNType='1'"; } else if (type == "2") { lotNosql = $@"SELECT d.LotNo,d.Quantity,d.InvCode FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode = b.OASNCode AND a.WorkPoint = b.WorkPoint inner JOIN ICSInventoryLot d ON b.LotNo = d.LotNo AND a.InvCode = d.InvCode AND b.WorkPoint = d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransID = l.ID AND d.WorkPoint = l.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND a.ODNType = '1'"; } else if (type == "3") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND e.ExtensionID=f.ID WHERE a.WorkPoint='{WorkPoint}' AND a.MOCode='{jo["DNCode"]}' AND a.Sequence='{jo["Sequence"]}' "; } else if (type == "4") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.InCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')= '' left join ICSExtension f on e.ExtensionID = f.ID and e.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.InCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' "; } else if (type == "5") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode = ad.ApplyNegCode AND a.WorkPoint = ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.ApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' "; } else if (type == "6") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode = ad.OApplyNegCode AND a.WorkPoint = ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.OApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.OApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' "; } else if (type == "7") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.SDNCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.SDNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' "; } else if (type == "8") { lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSDeliveryNotice a left join ICSInventoryLotDetail e on a.DNCode = e.TransCode and a.Sequence = e.TransSequence and a.WorkPoint = e.WorkPoint inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint-- and c.InvIQC = '1' inner JOIN ICSInventoryLot d ON e.LotNo = d.LotNo AND a.InvCode = d.InvCode AND a.WorkPoint = d.WorkPoint and d.type = '7' left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.DNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' and a.DNType = '1' "; } else if (type == "9") { lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode = a.ODNCode AND e.TransSequence = a.Sequence AND e.WorkPoint = a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint and d.type = '8' inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' LEFT JOIN dbo.ICSInspection h ON h.LotNo = d.LotNo AND h.WorkPoint = d.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' "; } else if (type == "10") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' LEFT JOIN ICSMOPick pick ON a.MODetailID = pick.MODetailID AND a.WorkPoint = pick.WorkPoint AND pick.EATTRIBUTE1 = '1' left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence + '~' + pick.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND a.MOStatus <> '3' "; } } else { if (type == "1") { lotNosql = $@"SELECT b.LotNo,b.Quantity,b.InvCode FROM ICSDeliveryNotice a INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode INNER JOIN ICSExtension d ON d.ID=b.ExtensionID AND b.WorkPoint=d.WorkPoint LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint INNER JOIN ICSPurchaseOrder l ON m.TransID = l.ID AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID AND l.PODetailID=a.PODetailID WHERE a.WorkPoint='{WorkPoint}' AND a.DNCode='{jo["DNCode"]}' AND a.DNType='1'"; } else if (type == "2") { lotNosql = $@"SELECT d.LotNo,d.Quantity,d.InvCode FROM ICSODeliveryNotice a LEFT JOIN ICSOASNDetail b ON a.OASNCode = b.OASNCode AND a.WorkPoint = b.WorkPoint inner JOIN ICSInventoryLot d ON b.LotNo = d.LotNo AND a.InvCode = d.InvCode AND b.WorkPoint = d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransID = l.ID AND d.WorkPoint = l.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.ODNType = '1'"; } else if (type == "3") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND e.ExtensionID=f.ID WHERE a.WorkPoint='{WorkPoint}' AND a.MOCode='{jo["DNCode"]}' "; } else if (type == "4") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSOtherIn a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.InCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')= '' left join ICSExtension f on e.ExtensionID = f.ID and e.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.InCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' "; } else if (type == "5") { lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMOApplyNeg a LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode = ad.ApplyNegCode AND a.WorkPoint = ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.ApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ApplyNegCode = '{jo["DNCode"]}' "; } else if (type == "6") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode = ad.OApplyNegCode AND a.WorkPoint = ad.WorkPoint inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.OApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.OApplyNegCode = '{jo["DNCode"]}' "; } else if (type == "7") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a from ICSSDN a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' left join ICSInventoryLotDetail b on a.SDNCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.SDNCode = '{jo["DNCode"]}' "; } else if (type == "8") { lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSDeliveryNotice a left join ICSInventoryLotDetail e on a.DNCode = e.TransCode and a.Sequence = e.TransSequence and a.WorkPoint = e.WorkPoint inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint-- and c.InvIQC = '1' inner JOIN ICSInventoryLot d ON e.LotNo = d.LotNo AND a.InvCode = d.InvCode AND a.WorkPoint = d.WorkPoint and d.type = '7' left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.DNCode = '{jo["DNCode"]}' and a.DNType = '1' "; } else if (type == "9") { lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode = a.ODNCode AND e.TransSequence = a.Sequence AND e.WorkPoint = a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint and d.type = '8' inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' LEFT JOIN dbo.ICSInspection h ON h.LotNo = d.LotNo AND h.WorkPoint = d.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' "; } else if (type == "10") { lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1' LEFT JOIN ICSMOPick pick ON a.MODetailID = pick.MODetailID AND a.WorkPoint = pick.WorkPoint AND pick.EATTRIBUTE1 = '1' left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence + '~' + pick.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.MOStatus <> '3' "; } } dt = SqlHelper.CmdExecuteDataTable(lotNosql); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { #region 2024-08-09 检验添加是否入库验证 var checksql = $@"SELECT ID FROM ICSWareHouseLotInfo WHERE LotNo='{dt.Rows[i]["LotNo"]}' AND WorkPoint='{WorkPoint}'"; var checkdt = SqlHelper.CmdExecuteDataTable(checksql); if (checkdt.Rows.Count > 0) { msg = $"条码:{jo["LotNo"]}已经入库,不能再次检验"; return msg; } #endregion object id = Guid.NewGuid(); sql += $@" update ICSInspectionDetailGroup set InspectionID='{id}' WHERE InspectionID=(Select ID from ICSInspection WHERE LotNO='{dt.Rows[i]["LotNo"]}' and Enable='1' and WorkPoint='{WorkPoint}') and WorkPoint='{WorkPoint}' ; update ICSInspection set Enable='0' WHERE LotNO='{dt.Rows[i]["LotNo"]}' and Enable='1' and WorkPoint='{WorkPoint}' ; INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE1) Values('{id}','{dt.Rows[i]["LotNo"]}','{dt.Rows[i]["InvCode"]}','{dt.Rows[i]["Quantity"]}','{dt.Rows[i]["Quantity"]}','0','0','','','{type}',getdate(),'{MUSER}','{MUSERNAME}','{WorkPoint}','1','0','1','{jo["FlagVersion"]}') ; "; } } } } //} if (SqlHelper.ExecuteNonQuery(sql) > 0) { } else { msg = "新增失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 在库检验保存检验结果 /// /// /// public string ICSWHLotInspection(string keyValue, string ICSInspections) { 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; JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections); string sqls = string.Empty; foreach (var item in res) { JObject jo = (JObject)item; object CARID = Guid.NewGuid(); decimal YLotQty = Convert.ToDecimal(jo["YLOTQTY"].ToString()); sqls += @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'"; sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint); sqls += @"INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE1) Values('{13}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1','{12}','{14}','{15}') "; sqls = string.Format(sqls, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["AllNumber"].ToString(), jo["YLOTQTY"].ToString() , jo["NLOTQTY"].ToString(), "0", jo["BCCode"].ToString(), jo["BRCode"].ToString() , jo["Type"].ToString(), MUSER, MUSERNAME, WorkPoint, "0", CARID, jo["Result"].ToString(), jo["DNCode"].ToString()); sqls += @"update ICSInspectDetail set InspectQuantity={2},MTIME=GETDATE(),MUSER='{5}',MUSERName='{6}',EATTRIBUTE1='已检验' where InspectCode='{0}' and LotNo='{3}' and WorkPoint='{1}' "; //if (YLotQty == 0) //{ // sqls += @"update ICSWareHouseLotInfo set Quantity=ISNULL(LockQuantity,0) // where LotNo='{3}' and WorkPoint='{1}' "; //} //else //{ // sqls += @"update ICSWareHouseLotInfo set Quantity={4}+ISNULL(LockQuantity,0) // where LotNo='{3}' and WorkPoint='{1}' // UPDATE ICSInventoryLot SET ExpirationDate='{7}' // WHERE LotNo='{3}' AND WorkPoint='{1}' "; //} sqls = string.Format(sqls, jo["DNCode"].ToString(), WorkPoint, jo["YLOTQTY"].ToString(), jo["LotNo"].ToString(), YLotQty, MUSER, MUSERNAME, Convert.ToDateTime(jo["ExpirationDate"])); } try { if (SqlHelper.ExecuteNonQuery(sqls) > 0) { } else { msg = "保存失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 在库检验审核 /// /// /// public string ApproveWHLotInspection(string keyValue, string ICSInspections) { 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; JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections); string sqls = string.Empty; foreach (var item in res) { JObject jo = (JObject)item; sqls += @"update ICSInspectDetail set EATTRIBUTE1='已审核',EATTRIBUTE2='{3}',EATTRIBUTE3='{4}' where InspectCode='{0}' and LotNo='{1}' and WorkPoint='{2}' "; sqls = string.Format(sqls, jo["DNCode"].ToString(), jo["LotNo"].ToString(), WorkPoint, MUSER, MUSERNAME); } try { if (SqlHelper.ExecuteNonQuery(sqls) > 0) { } else { msg = "审核失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 在库检验复审 /// /// /// public string SecApproveWHLotInspection(string keyValue, string ICSInspections) { 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 = ""; bool IsCQ = false; string sql = string.Empty; JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections); string chksql = @"select Type from ICSInspect where InspectCode='{0}' and WorkPoint='{1}'"; chksql = string.Format(chksql, res[0]["DNCode"].ToString(), WorkPoint); DataTable chkdt = SqlHelper.GetDataTableBySql(chksql); if (chkdt.Rows[0]["Type"].ToString() == "0") { IsCQ = false; } else { IsCQ = true; } string sqls = string.Empty; foreach (var item in res) { JObject jo = (JObject)item; object CARID = Guid.NewGuid(); decimal YLotQty = Convert.ToDecimal(jo["YLOTQTY"].ToString()); sqls += @"update ICSInspectDetail set EATTRIBUTE1='已复审',EATTRIBUTE4='{3}',EATTRIBUTE5='{4}' where InspectCode='{0}' and LotNo='{1}' and WorkPoint='{2}' "; if (YLotQty == 0) { sqls += @"update ICSWareHouseLotInfo set Quantity=ISNULL(LockQuantity,0) where LotNo='{1}' and WorkPoint='{2}' "; } else { if (IsCQ == false) { sqls += @"update ICSWareHouseLotInfo set Quantity={5}+ISNULL(LockQuantity,0) where LotNo='{1}' and WorkPoint='{2}' "; } else { sqls += @"update ICSWareHouseLotInfo set Quantity={5}+ISNULL(LockQuantity,0) where LotNo='{1}' and WorkPoint='{2}' UPDATE ICSInventoryLot SET ExpirationDate=DateAdd(DAY,Convert(Int,(select F_Define1 from Sys_SRM_ItemsDetail where F_ItemCode='Delay_day')),Convert(DateTime,ExpirationDate)) WHERE LotNo='{1}' AND WorkPoint='{2}' "; } } sqls = string.Format(sqls, jo["DNCode"].ToString(), jo["LotNo"].ToString(), WorkPoint, MUSER, MUSERNAME, YLotQty); } try { if (SqlHelper.ExecuteNonQuery(sqls) > 0) { } else { msg = "保存失败"; } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } //生成采购拒收单 public string CreateRejection(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode,a.Sequence from ICSDeliveryNotice a inner join ICSASNDetail b on a.ASNCode=b.ASNCode left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND c.ExtensionID=a.ExtensionID left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")"; // string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a //left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint //left join dbo.ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint //inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint //WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo from ICSDeliveryNotice a left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1' WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") "; // string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,d.LotNo //from ICSDeliveryNotice a //left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint //left join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint // inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint //left join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1' //WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { RejectionHead ass = new RejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["DNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.DNCode = dt.Rows[i]["DNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { RejectionBody DetailList = new RejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.DNDetailID = drs[j]["DNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDoc/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } /// /// 比博专用拒收单 /// /// /// public string CreateRejection4BB(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a inner join ICSASNDetail b on a.ASNCode=b.ASNCode left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")"; // string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a //left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint //left join dbo.ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint //inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint //WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo from ICSASNDetail b left join ICSInventoryLot c on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND c.WorkPoint=l.WorkPoint left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1' LEFT JOIN ICSDeliveryNotice a ON a.ASNCode=b.ASNCode AND a.PODetailID=l.PODetailID AND a.ExtensionID=c.ExtensionID WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") "; // string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,d.LotNo //from ICSDeliveryNotice a //left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint //left join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint // inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint //left join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1' //WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { RejectionHead ass = new RejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["DNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.DNCode = dt.Rows[i]["DNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { RejectionBody DetailList = new RejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.DNDetailID = drs[j]["DNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDoc/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } /// /// 卡博士专用拒收单 /// /// /// public string CreateRejection4KBS(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a inner join ICSASNDetail b on a.ASNCode=b.ASNCode left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")"; // string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a //left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint //left join dbo.ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint //inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint //WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNID,b.LotNo from ICSDeliveryNotice a left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1' WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") "; // string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,d.LotNo //from ICSDeliveryNotice a //left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint //left join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint // inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint //left join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1' //WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { RejectionHead ass = new RejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["DNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.DNCode = dt.Rows[i]["DNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { RejectionBody DetailList = new RejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); //DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();//这个字段不能串,会导致表体重复,最后条码重复无法创建拒收单 DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDoc/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } //生成采购拒收单(无来源) public string CreateWLYRejection(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; //string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a // inner join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint // left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint // left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint // inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint // WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")"; string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint left join dbo.ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint -- left JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); //string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo // from ICSDeliveryNotice a // left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint // left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint // left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint // inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint // left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint // WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") "; string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,d.LotNo from ICSDeliveryNotice a left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint left join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint left join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1' WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { RejectionHead ass = new RejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["DNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.DNCode = dt.Rows[i]["DNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { RejectionBody DetailList = new RejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.DNDetailID = drs[j]["DNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDocNoTrans/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } //生成委外拒收单 public string CreateWWRejection(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,b.LotNo from ICSODeliveryNotice a inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint inner join ICSInspection d on c.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint and d.Enable='1' WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { WWRejectionHead ass = new WWRejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["ODNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.ODNCode = dt.Rows[i]["ODNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { WWRejectionBody DetailList = new WWRejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } //生成委外拒收单 public string CreateBBWWRejection(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,b.LotNo from ICSODeliveryNotice a inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND a.ExtensionID=c.ExtensionID left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint inner join ICSInspection d on c.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint and d.Enable='1' WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { WWRejectionHead ass = new WWRejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["ODNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.ODNCode = dt.Rows[i]["ODNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { WWRejectionBody DetailList = new WWRejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } public string CreateWWRejection4KBS(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,b.LotNo from ICSODeliveryNotice a inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint and a.ExtensionID=c.ExtensionID left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint inner join ICSInspection d on c.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint and d.Enable='1' WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { WWRejectionHead ass = new WWRejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["ODNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.ODNCode = dt.Rows[i]["ODNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { WWRejectionBody DetailList = new WWRejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } // var group = ass.detail.GroupBy(x => x.InvCode).ToList(); asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } //生成委外拒收单(无来源) public string CreateWWWLYRejection(string keyValue) { string msg = ""; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a left join ICSInventoryLotDetail e on a.ODNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND e.WorkPoint=d.WorkPoint left JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ")"; DataTable dt = Repository().FindTableBySql(sqlAsn.ToString()); string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,c.LotNo from ICSODeliveryNotice a left join ICSInventoryLotDetail e on a.ODNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and e.WorkPoint=c.WorkPoint inner join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1' WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ") "; DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString()); List asn = new List(); for (int i = 0; i < dt.Rows.Count; i++) { WWRejectionHead ass = new WWRejectionHead(); ass.VenCode = dt.Rows[i]["VenCode"].ToString(); ass.ID = dt.Rows[i]["ODNID"].ToString(); ass.DepCode = dt.Rows[i]["DepCode"].ToString(); ass.ODNCode = dt.Rows[i]["ODNCode"].ToString(); ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; ass.MTIME = System.DateTime.Now.ToString("s"); ass.WorkPoint = WorkPoint; DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'"); for (int j = 0; j < drs.Length; j++) { WWRejectionBody DetailList = new WWRejectionBody(); DetailList.Sequence = (j + 1).ToString(); DetailList.InvCode = drs[j]["InvCode"].ToString(); DetailList.Quantity = drs[j]["Quantity"].ToString(); DetailList.Amount = drs[j]["Amount"].ToString(); DetailList.Currency = drs[j]["Currency"].ToString(); DetailList.UnitPrice = drs[j]["UnitPrice"].ToString(); DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString(); DetailList.LotNo = drs[j]["LotNo"].ToString(); ass.detail.Add(DetailList); } asn.Add(ass); } string input = JsonConvert.SerializeObject(asn); string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDocNoTrans/Create"; string result = HttpPost(APIURL, input); JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText); string MessAge = Obj["Message"].ToString(); string Success = Obj["Success"].ToString(); if (Success.ToUpper() == "FALSE") { msg = MessAge; } return msg; } public static string HttpPost(string url, string body) { try { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*"; request.ContentType = "application/json; charset=utf-8"; byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } catch (WebException ex) { throw new Exception(ex.Message); } } /// /// 删除拒收单 /// /// 传入ID /// public string DelectRejection(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 删除委外拒收单 /// /// 传入ID /// public string DelectWWRejection(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql = string.Format(@"DELETE FROM dbo.ICSODeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } public DataTable GetInventoryInspection(ref Pagination jqgridparam, string InvCode, int SampleQuantity, string ResultINp) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); List parameter = new List(); string sql = string.Empty; if (ResultINp == "") { sql = "SELECT 1 AS NUM INTO #TEmpType"; for (int i = 2; i <= SampleQuantity; i++) { sql += @" UNION SELECT " + i + " AS NUM"; } sql += @" select c.ID,a.GroupCode,a.GroupName,c.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,c.SetValue,CASE WHEN c.Result='0' THEN '不合格' when ISNULL(c.Result,'')='' THEN '' ELSE '合格' END AS Result INTO #TEmpTypedetail from ICSInventoryInspectionGroup a left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint left join ICSInspectionDetail c on b.ListCode=c.ListCode and b.ListName=c.ListName and b.WorkPoint=c.WorkPoint where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}' SELECT a.NUM, NEWID() AS ID,b.GroupCode,b.GroupName,b.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,b.SetValue,CASE WHEN b.Result='0' THEN '不合格' when ISNULL(b.Result,'')='' THEN '' ELSE '合格' END AS Result INTO ##SUMCount FROM #TEmpType a ,#TEmpTypedetail b ORDER BY a.NUM,b.GroupCode ASC "; sql = string.Format(sql, InvCode, WorkPoint); return SqlHelper.FindTablePageBySql_OtherTemp(sql.ToString(), " " + "##SUMCount" + " ", " DROP TABLE #TEmpType;DROP TABLE #TEmpTypedetail;DROP TABLE ##SUMCount", parameter.ToArray(), ref jqgridparam); } else { sql += @" select c.EATTRIBUTE1 as NUM, c.ID,a.GroupCode,a.GroupName,c.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,c.SetValue,CASE WHEN c.Result='0' THEN '不合格' when ISNULL(c.Result,'')='' THEN '' ELSE '合格' END AS Result from ICSInventoryInspectionGroup a left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint left join ICSInspectionDetail c on b.ListCode=c.ListCode and b.ListName=c.ListName and b.WorkPoint=c.WorkPoint where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}' "; sql = string.Format(sql, InvCode, WorkPoint); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } } public string SaveICSInspectionDetail(string ICSMTDOC, string InvCode, string ResultINp) { string msg = ""; try { 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 sql = string.Empty; JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC); bool ISOK = false; string ID = string.Empty; foreach (var item in res) { JObject jo = (JObject)item; ID = jo["InspectionID"].ToString(); if (string.IsNullOrWhiteSpace(ResultINp)) { sql += @" INSERT INTO dbo.ICSInspectionDetail ( ID ,InspectionID ,ListCode ,ListName , Unit ,SetValueMax ,SetValueMin ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName,EATTRIBUTE1) values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate(),'{10}','{11}','{12}','{13}')"; sql = string.Format(sql, jo["InspectionID"].ToString(), jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(), jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString(), jo["NUM"].ToString()); } else { sql += @" update ICSInspectionDetail set InspectionID='{0}',ListCode='{1}',ListName='{2}', Unit='{3}' ,SetValueMax='{4}' ,SetValueMin='{5}' ,SetValue='{6}' ,Result='{7}', MUSER='{8}' ,MUSERName='{9}' ,MTIME=getdate(), WorkPoint='{10}', GroupCode='{11}', GroupName='{12}',EATTRIBUTE1='{14}' where ID='{13}'"; sql = string.Format(sql, jo["InspectionID"].ToString(), jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(), jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString(), jo["ID"].ToString(), jo["NUM"].ToString()); } if (jo["Result"].ToString() == "0") { ISOK = true; } } if (ISOK == true) { sql += @" update ICSInspection set Result='{0}' where ID='{1}'"; sql = string.Format(sql, 0, ID); } else { sql += @" update ICSInspection set Result='{0}' where ID='{1}'"; sql = string.Format(sql, 1, ID); } if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } else { msg = "绑定失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 上传招标文件 /// /// /// public int InsertICSInspectionFile(string ID, string UploadfileName, string fileName) { DataTable dt = new DataTable(); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string sql = ""; sql += string.Format(@"Insert into ICSInspectionFile(ID,InspectionID,FileCode,FileName,MUSER,MUSERName,MTIME,WorkPoint) values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GetDate(),'{5}')", ID, UploadfileName, fileName, MUSER, MUSERName, WorkPoint); sql += "\r\n"; StringBuilder Str = new StringBuilder(sql); return Repository().ExecuteBySql(Str); } public DataTable GetICSInspection8(ref Pagination jqgridparam, string queryJson) { //string ERPSign = Configs.GetValue("ERPSign"); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_8 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, d.ID , h.ID as JYID, a.DNCode , a.Sequence , a.ASNCode , --l.POCode, c.InvCode , c.InvName , c.INVSTD , c.ClassName, CAST(d.Quantity as decimal(18,4)) as AllNumber, CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , d.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue, j.BadCode as BCCodeValue, j.BadDesc as BadDesc, k.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime, CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime, CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, a.VenCode, m.VenName,c.EATTRIBUTE3 as InvEATTRIBUTE3, isnull(h.MUSERName,'') as Surveyor, h.mtime as ProvingTime ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, n.FileName,c.InvIQC into #TempMOData_8 FROM ICSDeliveryNotice a --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint-- and c.InvIQC='1' inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint and d.type='7' LEFT JOIN #TempIcsinsp_8 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint --and Enable='1' left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where d.LotNo is not null and a.DNType='1' {0} and a.workpoint='{1}' and Isnull(d.EATTRIBUTE1,'') = '' select * into #TempMOData_8_1 from #TempMOData_8 where InvIQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_8_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 采购到货检验(批次维度) /// /// /// /// public DataTable GetICSInspection8BatchCode(ref Pagination jqgridparam, string queryJson) { //string ERPSign = Configs.GetValue("ERPSign"); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_8 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, a.DNCode , a.Sequence , a.ASNCode , --l.POCode, c.InvCode , c.InvName , c.INVSTD , c.ClassName, CAST(sum(d.Quantity) as decimal(18,4)) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity), sum(d.Quantity))as decimal(18,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as decimal(18,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as decimal(18,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as decimal(18,4)) as SampleQuantity, c.InvUnit , a.VenCode, m.VenName,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,c.InvIQC into #TempMOData_8 FROM ICSDeliveryNotice a --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint-- and c.InvIQC='1' inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint and d.type='7' LEFT JOIN #TempIcsinsp_8 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint --and Enable='1' left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint where d.LotNo is not null and a.DNType='1' {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID,a.DNCode ,a.Sequence ,a.ASNCode ,--l.POCode c.InvCode ,c.InvName ,c.INVSTD ,c.ClassName,c.InvUnit ,a.VenCode,m.VenName,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,c.InvIQC ;select * into #TempMOData_8_1 from #TempMOData_8 where InvIQC='1' "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_8_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 采购到货检验(单据行维度) /// /// /// /// public DataTable GetICSInspection8DocSequence(ref Pagination jqgridparam, string queryJson) { //string ERPSign = Configs.GetValue("ERPSign"); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_8 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as DHID, a.DNCode , a.Sequence , a.ASNCode , --l.POCode, c.InvCode , c.InvName , c.INVSTD , c.ClassName, CAST(sum(d.Quantity) as decimal(18,4)) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity), sum(d.Quantity))as decimal(18,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as decimal(18,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as decimal(18,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as decimal(18,4)) as SampleQuantity, c.InvUnit , a.VenCode, m.VenName,c.InvIQC into #TempMOData_8 FROM ICSDeliveryNotice a --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint-- and c.InvIQC='1' inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint and d.type='7' LEFT JOIN #TempIcsinsp_8 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint --and Enable='1' left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint where d.LotNo is not null and a.DNType='1' {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID,a.DNCode ,a.Sequence ,a.ASNCode ,--l.POCode c.InvCode ,c.InvName ,c.INVSTD ,c.ClassName,c.InvUnit ,a.VenCode,m.VenName,c.InvIQC ;select * into #TempMOData_8_1 from #TempMOData_8 where InvIQC='1' "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_8_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 采购到货检验(单据维度) /// /// /// /// public DataTable GetICSInspection8Doc(ref Pagination jqgridparam, string queryJson) { //string ERPSign = Configs.GetValue("ERPSign"); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_8 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.DNCode ,a.ASNCode , CAST(sum(d.Quantity) as decimal(18,4)) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity), sum(d.Quantity))as decimal(18,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as decimal(18,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as decimal(18,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as decimal(18,4)) as SampleQuantity into #TempMOData_8 FROM ICSDeliveryNotice a --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1' inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint and d.type='7' LEFT JOIN #TempIcsinsp_8 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint --and Enable='1' left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint where d.LotNo is not null and a.DNType='1' {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.DNCode ,a.ASNCode ;select * into #TempMOData_8_1 from #TempMOData_8 "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_8_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8')) drop table #TempMOData_8 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1')) drop table #TempMOData_8_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8')) drop table #TempIcsinsp_8 ", "connstr", parameter.ToArray(), ref jqgridparam); } public DataTable GetICSInspection9(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); #region string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 select a.ID as DHID, d.ID , h.ID as JYID, a.ODNCode as DNCode , a.Sequence , a.OASNCode , c.InvCode , c.InvName , c.INVSTD , c.ClassName, f.BatchCode , CAST(d.Quantity as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit ,c.EATTRIBUTE3 as InvEATTRIBUTE3, d.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue, j.BadCode as BCCodeValue, j.BadDesc as BadDesc, k.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime, CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState,c.InvIQC into #TempMOData_9 FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='8' inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where 1=1 {0} and a.workpoint='{1}' select * into #TempMOData_9_1 from #TempMOData_9 where InvIQC='1'"; #endregion string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_9_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验(批次维度) /// /// /// /// public DataTable GetICSInspection9BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); #region string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 select a.ID as DHID,a.ODNCode as DNCode ,a.Sequence , a.OASNCode ,c.InvCode ,c.InvName ,c.INVSTD ,c.ClassName, f.BatchCode , CAST(sum(d.Quantity) as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity), sum(d.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as decimal(18,4)) as SampleQuantity, c.InvUnit ,c.InvIQC into #TempMOData_9 FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='8' inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint where 1=1 {0} and a.workpoint='{1}' "; #endregion string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID ,a.ODNCode ,a.Sequence , a.OASNCode ,c.InvCode ,c.InvName ,c.INVSTD ,c.ClassName, f.BatchCode ,c.InvUnit ,c.InvIQC ;select * into #TempMOData_9_1 from #TempMOData_9 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_9_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验(单据行维度) /// /// /// /// public DataTable GetICSInspection9DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); #region string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 select a.ID as DHID,a.ODNCode as DNCode ,a.Sequence , a.OASNCode ,c.InvCode ,c.InvName ,c.INVSTD ,c.ClassName, CAST(sum(d.Quantity) as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity), sum(d.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as decimal(18,4)) as SampleQuantity, c.InvUnit ,c.InvIQC into #TempMOData_9 FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='8' inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint where 1=1 {0} and a.workpoint='{1}' "; #endregion string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID ,a.ODNCode ,a.Sequence , a.OASNCode ,c.InvCode ,c.InvName ,c.INVSTD ,c.ClassName,c.InvUnit ,c.InvIQC ;select * into #TempMOData_9_1 from #TempMOData_9 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_9_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验(单据维度) /// /// /// /// public DataTable GetICSInspection9Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); #region string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 select distinct a.ODNCode as DNCode ,a.OASNCode , CAST(sum(d.Quantity) as NUMERIC(10,4)) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity), sum(d.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(Sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as decimal(18,4)) as SampleQuantity into #TempMOData_9 FROM ICSODeliveryNotice a inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='8' inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1' LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint where 1=1 {0} and a.workpoint='{1}' "; #endregion string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' "; } //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString())) //{ // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' "; //} //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString())) //{ // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' "; //} if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString())) { wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString())) { wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ODNCode , a.OASNCode ;select * into #TempMOData_9_1 from #TempMOData_9 "; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_9_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9')) drop table #TempMOData_9 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1')) drop table #TempMOData_9_1 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验 /// /// /// /// public DataTable GetICSInspection10(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_10 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, e.ID , a.MOCode as DNCode, a.Sequence , h.ID as JYID, pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, e.Quantity as AllNumber, CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY, CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity , c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc , g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID, isnull(h.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME, CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState, isnull(h.MUSERName,'') as Surveyor, h.mtime as ProvingTime ,CASE WHEN h.Result='0' THEN '不合格' when ISNULL(h.Result,'')='' THEN '' ELSE '合格' END AS Result, c.EATTRIBUTE3 as InvEATTRIBUTE3,n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_10 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN ICSMOPick pick ON a.MODetailID=pick.MODetailID AND a.WorkPoint=pick.WorkPoint AND pick.EATTRIBUTE1='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence+'~'+ pick.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_10 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin where a.MOStatus<>'3' and e.LotNO is not null {0} and a.workpoint='{1}' select * into #TempMOData_10_1 from #TempMOData_10 where InvIQC='1' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_10_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验(批次维度) /// /// /// /// public DataTable GetICSInspection10BatchCode(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_10 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.MOCode as DNCode, a.Sequence , pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(Sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_10 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN ICSMOPick pick ON a.MODetailID=pick.MODetailID AND a.WorkPoint=pick.WorkPoint AND pick.EATTRIBUTE1='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence+'~'+ pick.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_10 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where a.MOStatus<>'3' and e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.MOCode, a.Sequence , pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC;select * into #TempMOData_10_1 from #TempMOData_10 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_10_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验(单据行维度) /// /// /// /// public DataTable GetICSInspection10DocSequence(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_10 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.ID as GDID, a.MOCode as DNCode, a.Sequence , pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(Sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC into #TempMOData_10 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN ICSMOPick pick ON a.MODetailID=pick.MODetailID AND a.WorkPoint=pick.WorkPoint AND pick.EATTRIBUTE1='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence+'~'+ pick.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_10 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where a.MOStatus<>'3' and e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.ID , a.MOCode, a.Sequence , pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, c.InvUnit ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC ;select * into #TempMOData_10_1 from #TempMOData_10 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_10_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 ", "connstr", parameter.ToArray(), ref jqgridparam); } /// /// 委外采购到货单检验(单据维度) /// /// /// /// public DataTable GetICSInspection10Doc(ref Pagination jqgridparam, string queryJson) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity, SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode into #TempIcsinsp_10 from dbo.ICSInspection where workpoint='" + WorkPoint + @"' and Enable='1' select DISTINCT a.MOCode as DNCode, sum(e.Quantity) as AllNumber, CAST(ISNULL(sum(h.QualifiedQuantity),sum(e.Quantity))as NUMERIC(10,4))as YLOTQTY , CAST(ISNULL(sum(h.UnqualifiedQuantity), 0) as NUMERIC(10,4)) as NLOTQTY, CAST(ISNULL(Sum(h.WaiveQuantity), 0) as NUMERIC(10,4)) as SpecialQTY, CAST(ISNULL(sum(h.SampleQuantity), 0) as NUMERIC(10,4)) as SampleQuantity into #TempMOData_10 from ICSMO a inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1' LEFT JOIN ICSMOPick pick ON a.MODetailID=pick.MODetailID AND a.WorkPoint=pick.WorkPoint AND pick.EATTRIBUTE1='1' left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence+'~'+ pick.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint LEFT JOIN #TempIcsinsp_10 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1' where a.MOStatus<>'3' and e.LotNO is not null {0} and a.workpoint='{1}' "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'"; else if (ReleaseState == "0") wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0"; else if (selEnableShow == "0") wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0"; } } sql += @" GROUP BY a.MOCode ;select * into #TempMOData_10_1 from #TempMOData_10 where InvIQC='1'"; sql = string.Format(sql, wheresql, WorkPoint); // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_10_1", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10')) drop table #TempMOData_10 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1')) drop table #TempMOData_10_1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10')) drop table #TempIcsinsp_10 ", "connstr", parameter.ToArray(), ref jqgridparam); } //在库检验 public DataTable GetICSInspection11(ref Pagination jqgridparam, string queryJson) { try { string DataActionsql = DataActionSqlGet(); DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select DISTINCT a.ID as GDID, e.ID AS LotID , a.InspectCode as DNCode, d.Sequence , d.ID as ID, e.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10, g.Quantity-ISNULL(g.LockQuantity,0) as AllNumber, Case When d.EATTRIBUTE1='未检验' Then 0 Else d.InspectQuantity END as YLOTQTY , Case When d.EATTRIBUTE1='未检验' Then 0 Else Convert(decimal(18,4),d.Quantity)-Convert(decimal(18,4),d.InspectQuantity) END as NLOTQTY, Case When a.Type=0 Then '标准检验' ELSE '超期检验' END AS DocType, c.InvUnit , d.LotNo ,i.ContainerID,CONVERT(varchar(100), e.ExpirationDate, 23) AS ExpirationDate, isnull(a.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),a.MTIME,120) as MTIME, d.EATTRIBUTE1 AS TestState,c.EATTRIBUTE3 as InvEATTRIBUTE3, isnull(d.MUSERName,'') as Surveyor, d.MTIME as ProvingTime, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10,K.BadReasonDesc as BadReasonDesc , K.BadReasonCode as BRCodeValue,L.BadCode as BCCodeValue, L.BadDesc as BadDesc from ICSInspect a inner join ICSInspectDetail d on d.InspectCode=a.InspectCode and d.WorkPoint=a.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=d.LotNo AND e.WorkPoint=d.WorkPoint LEFT JOIN dbo.ICSWareHouseLotInfo g ON g.LotNo=e.LotNo and g.WorkPoint=e.WorkPoint inner JOIN dbo.ICSInventory c ON c.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint --and c.InvIQC='1' left join ICSExtension f on f.ID=e.ExtensionID and f.WorkPoint=e.WorkPoint LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint LEFT JOIN DBO.ICSInspection J ON J.LotNo=D.LotNo AND J.EATTRIBUTE1=d.InspectCode AND J.WorkPoint=d.WorkPoint AND J.Enable=1 LEFT JOIN DBO.ICSBadReason K ON K.BadReasonCode=J.BRCode AND K.WorkPoint=J.WorkPoint LEFT JOIN DBO.ICSBadCode L ON L.BadCode=J.BCCode AND L.WorkPoint=J.WorkPoint where g.LotNO is not null {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InspectCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and e.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNo like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and d.EATTRIBUTE1='已检验'"; else if (ReleaseState == "0") wheresql += " and d.EATTRIBUTE1='未检验'"; else if (ReleaseState == "3") wheresql += " and d.EATTRIBUTE1='已审核'"; else if (ReleaseState == "4") wheresql += " and d.EATTRIBUTE1='已复审'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; else if (selEnableShow == "0") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))!=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; } } if (DataActionsql != "") { sql += DataActionsql; } sql = string.Format(sql, wheresql); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 在库检验(批次维度) /// /// /// /// /// public DataTable GetICSInspection11BatchCode(ref Pagination jqgridparam, string queryJson) { try { string DataActionsql = DataActionSqlGet(); DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select DISTINCT a.InspectCode as DNCode, sum(g.Quantity)-ISNULL(sum(g.LockQuantity),0) as AllNumber, Case When d.EATTRIBUTE1='未检验' Then 0 Else sum(d.InspectQuantity) END as YLOTQTY , Case When d.EATTRIBUTE1='未检验' Then 0 Else Convert(decimal(18,4),sum(d.Quantity))-Convert(decimal(18,4),sum(d.InspectQuantity)) END as NLOTQTY, Case When a.Type=0 Then '标准检验' ELSE '超期检验' END AS DocType, isnull(a.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),a.MTIME,120) as MTIME, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSInspect a inner join ICSInspectDetail d on d.InspectCode=a.InspectCode and d.WorkPoint=a.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=d.LotNo AND e.WorkPoint=d.WorkPoint LEFT JOIN dbo.ICSWareHouseLotInfo g ON g.LotNo=e.LotNo and g.WorkPoint=e.WorkPoint inner JOIN dbo.ICSInventory c ON c.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint --and c.InvIQC='1' left join ICSExtension f on f.ID=e.ExtensionID and f.WorkPoint=e.WorkPoint where g.LotNO is not null {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InspectCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and e.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNo like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and d.EATTRIBUTE1='已检验'"; else if (ReleaseState == "0") wheresql += " and d.EATTRIBUTE1='未检验'"; else if (ReleaseState == "3") wheresql += " and d.EATTRIBUTE1='已审核'"; else if (ReleaseState == "4") wheresql += " and d.EATTRIBUTE1='已复审'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; else if (selEnableShow == "0") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))!=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; } } if (DataActionsql != "") { sql += DataActionsql; } sql += @" GROUP BY a.InspectCode ,a.MUSERName, a.MTIME,d.EATTRIBUTE1 , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,a.Type"; sql = string.Format(sql, wheresql); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 在库检验(单据行维度) /// /// /// /// /// public DataTable GetICSInspection11DocSequence(ref Pagination jqgridparam, string queryJson) { try { string DataActionsql = DataActionSqlGet(); DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select DISTINCT a.ID as GDID, a.InspectCode as DNCode, d.Sequence , d.ID as ID, e.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, sum(g.Quantity)-ISNULL(sum(g.LockQuantity),0) as AllNumber, Case When d.EATTRIBUTE1='未检验' Then 0 Else sum(d.InspectQuantity) END as YLOTQTY , Case When d.EATTRIBUTE1='未检验' Then 0 Else Convert(decimal(18,4),sum(d.Quantity))-Convert(decimal(18,4),sum(d.InspectQuantity)) END as NLOTQTY, Case When a.Type=0 Then '标准检验' ELSE '超期检验' END AS DocType, c.InvUnit , isnull(a.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),a.MTIME,120) as MTIME, d.EATTRIBUTE1 AS TestState, isnull(d.MUSERName,'') as Surveyor, d.MTIME as ProvingTime, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSInspect a inner join ICSInspectDetail d on d.InspectCode=a.InspectCode and d.WorkPoint=a.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=d.LotNo AND e.WorkPoint=d.WorkPoint LEFT JOIN dbo.ICSWareHouseLotInfo g ON g.LotNo=e.LotNo and g.WorkPoint=e.WorkPoint inner JOIN dbo.ICSInventory c ON c.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint --and c.InvIQC='1' left join ICSExtension f on f.ID=e.ExtensionID and f.WorkPoint=e.WorkPoint where g.LotNO is not null {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InspectCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and e.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNo like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and d.EATTRIBUTE1='已检验'"; else if (ReleaseState == "0") wheresql += " and d.EATTRIBUTE1='未检验'"; else if (ReleaseState == "3") wheresql += " and d.EATTRIBUTE1='已审核'"; else if (ReleaseState == "4") wheresql += " and d.EATTRIBUTE1='已复审'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; else if (selEnableShow == "0") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))!=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; } } if (DataActionsql != "") { sql += DataActionsql; } sql += @" GROUP BY a.ID , a.InspectCode , d.Sequence , d.ID , e.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, c.InvUnit ,a.MUSERName, a.MTIME,d.EATTRIBUTE1 ,d.MUSERName, d.MTIME , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,a.Type"; sql = string.Format(sql, wheresql); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 在库检验(单据维度) /// /// /// /// /// public DataTable GetICSInspection11Doc(ref Pagination jqgridparam, string queryJson) { try { string DataActionsql = DataActionSqlGet(); DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @" select DISTINCT a.ID as GDID, a.InspectCode as DNCode, d.Sequence , d.ID as ID, e.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, sum(g.Quantity)-ISNULL(sum(g.LockQuantity),0) as AllNumber, Case When d.EATTRIBUTE1='未检验' Then 0 Else sum(d.InspectQuantity) END as YLOTQTY , Case When d.EATTRIBUTE1='未检验' Then 0 Else Convert(decimal(18,4),sum(d.Quantity))-Convert(decimal(18,4),sum(d.InspectQuantity)) END as NLOTQTY, Case When a.Type=0 Then '标准检验' ELSE '超期检验' END AS DocType, c.InvUnit , d.LotNo , isnull(a.MUSERName,'开发者') MUSERName, CONVERT(VARCHAR(100),a.MTIME,120) as MTIME, d.EATTRIBUTE1 AS TestState, isnull(d.MUSERName,'') as Surveyor, d.MTIME as ProvingTime, a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSInspect a inner join ICSInspectDetail d on d.InspectCode=a.InspectCode and d.WorkPoint=a.WorkPoint LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=d.LotNo AND e.WorkPoint=d.WorkPoint LEFT JOIN dbo.ICSWareHouseLotInfo g ON g.LotNo=e.LotNo and g.WorkPoint=e.WorkPoint inner JOIN dbo.ICSInventory c ON c.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint --and c.InvIQC='1' left join ICSExtension f on f.ID=e.ExtensionID and f.WorkPoint=e.WorkPoint where g.LotNO is not null {0} "; string wheresql = ""; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { wheresql += " and a.InspectCode like '%" + queryParam["POCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString())) { wheresql += " and e.InvCode like '%" + queryParam["InvCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString())) { wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString())) { wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString())) { wheresql += " and d.LotNo like '%" + queryParam["LotNO"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString())) { string ReleaseState = queryParam["ReleaseState"].ToString(); if (ReleaseState == "1") wheresql += " and d.EATTRIBUTE1='已检验'"; else if (ReleaseState == "0") wheresql += " and d.EATTRIBUTE1='未检验'"; else if (ReleaseState == "3") wheresql += " and d.EATTRIBUTE1='已审核'"; else if (ReleaseState == "4") wheresql += " and d.EATTRIBUTE1='已复审'"; else wheresql += " "; } if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString())) { string selEnableShow = queryParam["selEnableShow"].ToString(); if (selEnableShow == "1") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; else if (selEnableShow == "0") wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))!=Convert(decimal(18,4),ISNULL(d.Quantity,0))"; } } if (DataActionsql != "") { sql += DataActionsql; } sql += @" GROUP BY a.ID , a.InspectCode , d.Sequence , d.ID , e.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc, c.InvUnit , d.LotNo ,a.MUSERName, a.MTIME,d.EATTRIBUTE1 ,d.MUSERName, d.MTIME , a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,a.EATTRIBUTE9,a.EATTRIBUTE10,a.Type"; sql = string.Format(sql, wheresql); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } catch (Exception ex) { throw new Exception(ex.Message); } } public DataTable GetInventoryInspectionNew(ref Pagination jqgridparam, string InvCode, int SampleQuantity, string ResultINp, string JYID) { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; DataTable dt = new DataTable(); List parameter = new List(); string sql = string.Empty; if (ResultINp == "") { sql += @" select DISTINCT b.ID,a.GroupCode,a.GroupName,d.ID as InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN '不合格' when ISNULL(c.Result,'')='' THEN '' ELSE '合格' END AS Result from ICSInventoryInspectionGroup a inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint and c.InspectionID='{2}' left JOIN ICSInspectionDetail d ON c.InspectionID=d.ID AND c.WorkPoint=d.WorkPoint where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}' "; sql = string.Format(sql, InvCode, WorkPoint, JYID); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } else { sql += @" declare @sql varchar(8000) select b.ID,a.GroupCode,a.GroupName,c.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN '不合格' when ISNULL(c.Result,'')='' THEN '' ELSE '合格' END AS Result,d.Sequence into #TempSORRFQ from ICSInventoryInspectionGroup a inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'and c.InspectionID='{2}' select @sql=isnull(@sql+',','')+' ['+Sequence+']' from(select distinct Sequence from #TempSORRFQ)as a set @sql='SELECT STUFF((select'','' + Sequence from (SELECT DISTINCT Sequence FROM #TempSORRFQ ) DD for xml path('''')),1,1,'''') as IsTou,* FROM #TempSORRFQ PIVOT(MAX(SetValue) FOR Sequence IN ('+@sql+'))a ' exec(@sql) "; sql = string.Format(sql, InvCode, WorkPoint, JYID); return SqlHelper.FindTablePageBySql_OtherTempSORRFQ(sql.ToString(), " " + "#TempSORRFQ" + " ", " drop table #TempSORRFQ", parameter.ToArray(), ref jqgridparam); } } public DataTable GetRulesDetail(string LotNo) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; //增加pp子表查询 主要查询U8到货单数量 sql = @"select DISTINCT CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity, b.LotNo , b.Quantity, '抽检', g.RulesCode, g.InvCode, c.InvStd, c.InvName FROM ICSDeliveryNotice a inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1' inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint --and Enable='1' LEFT JOIN ICSInventoryInspectionRulesGroup g ON c.InvCode=g.InvCode AND c.WorkPoint=g.WorkPoint Where b.LotNo='" + LotNo + "'"; return Repository().FindTableBySql(sql.ToString()); } /// /// 检验保存 /// /// /// /// /// public string SaveICSInspectionDetailNew(string ICSMTDOC, string InvCode, string JYID, string AllNumber, string YLOTQTY, string NLOTQTY, string WaiveQuantity, string BCCode, string BRCode, string ResultINp, string Lot, string Type, decimal CJQty) { string msg = ""; try { object CARID = Guid.NewGuid(); 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 sql = string.Empty; JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC); bool ISOK = false; string ID = string.Empty; if (string.IsNullOrEmpty(JYID) || JYID == "null") { sql += $@" INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity) Values('{CARID}','{Lot}','{InvCode}','{AllNumber}','{YLOTQTY}','{NLOTQTY}','{WaiveQuantity}','{BCCode}','{BRCode}','{Type}',getdate(),'{MUSER}','{MUSERNAME}','{WorkPoint}','1','{CJQty}') "; } else { CARID = JYID; } foreach (var item in res) { string Guids = Guid.NewGuid().ToString(); JObject jo = (JObject)item; JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString()); sql += @" INSERT INTO dbo.ICSInspectionDetailGroup ( ID ,InspectionID,ListCode ,ListName , Unit ,SetValueMax ,SetValueMin ,UnqualifiedQuantity ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',getdate(),'{11}','{12}','{13}')"; sql = string.Format(sql, Guids, CARID, jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(), jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString() , MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString()); foreach (var itemdetail in detailres) { JObject jodetail = (JObject)itemdetail; if (string.IsNullOrWhiteSpace(ResultINp)) { sql += @" INSERT INTO dbo.ICSInspectionDetail ( ID ,DetailGroupID,Sequence ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint) values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}',getdate(),'{6}')"; sql = string.Format(sql, Guids, jodetail["FiledNamekey"].ToString(), jodetail["FiledNamevalue"].ToString(), jo["Result"].ToString(), MUSER, MUSERNAME, WorkPoint); } else { sql += @" update ICSInspectionDetail set InspectionID='{0}',ListCode='{1}',ListName='{2}', Unit='{3}' ,SetValueMax='{4}' ,SetValueMin='{5}' ,SetValue='{6}' ,Result='{7}', MUSER='{8}' ,MUSERName='{9}' ,MTIME=getdate(), WorkPoint='{10}', GroupCode='{11}', GroupName='{12}',EATTRIBUTE1='{14}' where ID='{13}'"; sql = string.Format(sql, jodetail["InspectionID"].ToString(), jodetail["ListCode"].ToString(), jodetail["ListName"].ToString(), jodetail["Unit"].ToString(), jodetail["SetValueMax"].ToString(), jodetail["SetValueMin"].ToString(), jodetail["SetValue"].ToString(), jodetail["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jodetail["GroupCode"].ToString(), jodetail["GroupName"].ToString(), jodetail["ID"].ToString(), jodetail["NUM"].ToString()); } if (jo["Result"].ToString() == "0") { ISOK = true; } } ID = jo["InspectionID"].ToString(); } if (ISOK == true) { sql += @" update ICSInspection set Result='{0}' where ID='{1}'"; sql = string.Format(sql, 0, CARID); } else { sql += @" update ICSInspection set Result='{0}' where ID='{1}'"; sql = string.Format(sql, 1, CARID); } if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } else { msg = "绑定失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 检验修改 /// /// /// /// /// public string UpdateICSInspectionDetailNew(string ICSMTDOC, string JYID, string ResultINp) { string msg = ""; try { 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 sql = string.Empty; JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC); bool ISOK = false; string ID = string.Empty; sql = @"DELETE c from ICSInspection a left join ICSInspectionDetailGroup b on a.ID = b.inspectionID and a.workPoint = b.workPoint left join ICSInspectionDetail c on b.id = c.DetailGroupID and b.workPoint = c.workPoint Where a.ID='" + JYID + "'"; sql += "DELETE ICSInspectionDetailGroup where inspectionID='" + JYID + "'"; foreach (var item in res) { string Guids = Guid.NewGuid().ToString(); JObject jo = (JObject)item; JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString()); sql += @" INSERT INTO dbo.ICSInspectionDetailGroup ( ID ,InspectionID,ListCode ,ListName , Unit ,SetValueMax ,SetValueMin ,UnqualifiedQuantity ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',getdate(),'{11}','{12}','{13}')"; sql = string.Format(sql, Guids, jo["InspectionID"].ToString(), jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(), jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), 0, jo["Result"].ToString() , MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString()); foreach (var itemdetail in detailres) { JObject jodetail = (JObject)itemdetail; //if (string.IsNullOrWhiteSpace(ResultINp)) //{ sql += @" INSERT INTO dbo.ICSInspectionDetail ( ID ,DetailGroupID,Sequence ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint) values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}',getdate(),'{6}')"; sql = string.Format(sql, Guids, jodetail["FiledNamekey"].ToString(), jodetail["FiledNamevalue"].ToString(), jo["Result"].ToString(), MUSER, MUSERNAME, WorkPoint); //} //else //{ // sql += @" update ICSInspectionDetail set InspectionID='{0}',ListCode='{1}',ListName='{2}', Unit='{3}' ,SetValueMax='{4}' ,SetValueMin='{5}' ,SetValue='{6}' ,Result='{7}', MUSER='{8}' ,MUSERName='{9}' ,MTIME=getdate(), WorkPoint='{10}', GroupCode='{11}', GroupName='{12}',EATTRIBUTE1='{14}' where ID='{13}'"; // sql = string.Format(sql, jodetail["InspectionID"].ToString(), jodetail["ListCode"].ToString(), jodetail["ListName"].ToString(), jodetail["Unit"].ToString(), jodetail["SetValueMax"].ToString(), jodetail["SetValueMin"].ToString(), jodetail["SetValue"].ToString(), jodetail["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jodetail["GroupCode"].ToString(), jodetail["GroupName"].ToString(), jodetail["ID"].ToString(), jodetail["NUM"].ToString()); //} if (jo["Result"].ToString() == "0") { ISOK = true; } } ID = jo["InspectionID"].ToString(); } if (ISOK == true) { sql += @" update ICSInspection set Result='{0}' where ID='{1}'"; sql = string.Format(sql, 0, ID); } else { sql += @" update ICSInspection set Result='{0}' where ID='{1}'"; sql = string.Format(sql, 1, ID); } if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } else { msg = "绑定失败"; } } catch (Exception ex) { msg = ex.Message; } return msg; } public DataTable SelectSORRFQColumnName(string InvCode, string JYID) { string sql = @"declare @sql varchar(8000) SELECT d.Sequence,d.SetValue into #Temp from ICSInventoryInspectionGroup a inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint and c.InspectionID='{1}' left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint where a.InvCode='{0}' and b.Enable='1' select distinct Sequence as ColCaption,Sequence as ColFiledName from #Temp drop table #Temp"; sql = string.Format(sql, InvCode, JYID); DataTable dt = SqlHelper.GetDataTableBySql(sql); return dt; } public DataTable GetDeleteRulesDetail(string InvCode, string JYID) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; //增加pp子表查询 主要查询U8到货单数量 sql = @" select a.ID as inspectionID,c.ID,a.lotNO,a.Invcode,c.SetValue from ICSInspection a left join ICSInspectionDetailGroup b on a.ID=b.inspectionID and a.workPoint=b.workPoint left join ICSInspectionDetail c on b.id=c.DetailGroupID and b.workPoint=c.workPoint where a.id='{0}' and a.Invcode='{1}'"; sql = string.Format(sql, JYID, InvCode); return Repository().FindTableBySql(sql.ToString()); } public string DeleteICSInspection(string DetailID) { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string sql = string.Empty; sql = @"delete FROM ICSInspectionDetail where ID in ({0})"; sql = string.Format(sql, DetailID.TrimEnd(',')); string msg = ""; try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { msg = ex.Message; } return msg; } public string DataActionSqlGet() { OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sqlstr = string.Empty; try { string sql = @" select B.DataActionId from Sys_SRM_User A INNER JOIN Sys_RoleDataPower B ON B.RoleId=A.F_RoleId where F_Account='{0}' and F_Location='{1}'"; sql = string.Format(sql, MUSER, WorkPoint); DataTable dt = SqlHelper.GetDataTableBySql(sql); if (dt.Rows.Count == 0) { sqlstr = ""; } else { string DataActionID = ""; foreach (DataRow dr in dt.Rows) { DataActionID += "'" + dr["DataActionId"].ToString() + "',"; } sql = @" SELECT CCaption 条件名称, CValueBegin 起始值,CValueEnd 结束值 from Sys_FormDataAction con where con.ID in ({0})"; sql = string.Format(sql, DataActionID.TrimEnd(',')); dt = SqlHelper.GetDataTableBySql(sql); foreach (DataRow dr in dt.Rows) { if (dr["起始值"].ToString() != "" && dr["结束值"].ToString() != "") { sqlstr += " and " + dr["条件名称"].ToString() + " >= '" + dr["起始值"].ToString() + @"' and " + dr["条件名称"].ToString() + " <= '" + dr["结束值"].ToString() + "'"; } else if (dr["起始值"].ToString() == "" && dr["结束值"].ToString() == "") { continue; } else { if (dr["起始值"].ToString() != "") { sqlstr += " and " + dr["条件名称"].ToString() + " = '" + dr["起始值"].ToString() + "'"; } else { sqlstr += " and " + dr["条件名称"].ToString() + " = '" + dr["结束值"].ToString() + "'"; } } if (dr["起始值"].ToString().Contains("[AppConfig.WorkPointCode]") || dr["起始值"].ToString().Contains("[AppConfig.UserId]") || dr["起始值"].ToString().Contains("[AppConfig.UserCode]") || dr["起始值"].ToString().Contains("[AppConfig.UserName]") || dr["起始值"].ToString().Contains("[AppConfig.RoleCode]")) { sqlstr = sqlstr.Replace("[AppConfig.WorkPointCode]", oo.Location); sqlstr = sqlstr.Replace("[AppConfig.UserId]", oo.UserId); sqlstr = sqlstr.Replace("[AppConfig.UserCode]", oo.UserCode); sqlstr = sqlstr.Replace("[AppConfig.UserName]", oo.UserName); sqlstr = sqlstr.Replace("[AppConfig.RoleCode]", oo.RoleEnCode); } } } } catch (Exception ex) { throw new Exception(ex.Message); } return sqlstr; } } }