using ICSSoft.ERPWMS.Entity; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ICSSoft.ERPWMS.SQL { public class GetPOInfo { public static Result Get(POCondition condition) { Result res = new Result(); try { if (condition.PageIndex ==null) { throw new Exception("页码未传!"); } if (condition.PageSize == null) { throw new Exception("每页数量未传!"); } if (string.IsNullOrWhiteSpace(condition.WorkPoint)) { throw new Exception("站点未传!"); } string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint); if (WorkPoint == "NotExit") { throw new Exception("站点编码不存在!"); } string sql = @"select a.cPOID as '采购订单号',b.ivouchrowno as '采购订单行号',a.cVenCode as '供应商代码',a.cDepCode as '部门代码',a.cPersonCode as '业务员代码', '标准' as '采购类型名称',b.cInvCode as '物料代码',b.iQuantity as '数量',b.iNum as '辅计量数量',b.iUnitPrice as '原币无税单价',b.cFree1 '料品版本', b.iMoney as '原币无税金额',b.iTaxPrice as '原币含税单价',b.iPerTaxRate as '税率',b.iTax as '原币税额',b.iSum as '原币价税合计', a.cexch_name as '币种',a.nflat as '汇率',a.iverifystateex as '状态',b.dArriveDate as '计划到货日期',a.cMemo as '头备注',b.cbMemo as '行备注', a.cMaker as '创建人',a.cmaketime as '创建时间',a.dCloseDate as '停用日期',a.cChanger as '变更人', case when a.cChangAuditTime >=(case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end) then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) then a.cChangAuditTime else (case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end) then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) end as '变更日期', case when b.iArrQTY is null then isnull(b.iReceivedQTY,0) when cast(b.iArrQTY as int)=0 then isnull(b.iReceivedQTY,0) else b.iArrQTY end as '到货数量', b.cbCloser as '行关闭人',xx.chdefine31 '订单送货地址',xx.chdefine32 '发票接收地址' from {0}.dbo.PO_Pomain a left join {0}.dbo.PO_Podetails b on a.POID = b.POID LEFT JOIN {0}.dbo.ICSPoModifyTimeRecord hh on a.POID = hh.POID left join {0}.dbo.po_pomain_extradefine xx on a.poid = xx.poid left join (select PO_Pomain.cPOID as 'cpocode',MAX(PU_ArrivalVouch.cMakeTime) as 'cMakeTime' from {0}.dbo.PU_ArrivalVouch left join {0}.dbo.PU_ArrivalVouchs on PU_ArrivalVouch.id = PU_ArrivalVouchs.ID left join {0}.dbo.PO_Podetails on PO_Podetails.ID = PU_ArrivalVouchs.iPOsID left join {0}.dbo.PO_Pomain on PO_Pomain.POID = PO_Podetails.POID group by PO_Pomain.cPOID) yy on a.cPOID = yy.cpocode where a.cVerifier is not null and a.cVerifier!=''"; string sql2 = @"select c.cCode as '采购订单号',d.iVouchRowNo as '采购订单行号',c.cVenCode as '供应商代码',c.cDepCode as '部门代码',c.cPersonCode as '业务员代码', '委外' as '采购类型名称',d.cInvCode as '物料代码',d.iQuantity as '数量',d.iNum as '辅计量数量',d.iUnitPrice as '原币无税单价',d.cFree1 '料品版本', d.iMoney as '原币无税金额',d.iTaxPrice as '原币含税单价',d.iPerTaxRate as '税率',d.iTax as '原币税额',d.iSum as '原币价税合计', c.cexch_name as '币种',c.nflat as '汇率',c.iVerifyStateNew as '状态',d.dArriveDate as '计划到货日期',yy.chdefine39 as '头备注',d.cbMemo as '行备注', c.cMaker as '创建人',c.dCreateTime as '创建时间',c.dCloseDate as '停用日期',c.cChanger as '变更人', case when c.dChangeVerifyTime >=(case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) then c.dChangeVerifyTime ELSE (case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) end as '变更日期', case when d.iArrQTY is null then isnull(d.iReceivedQTY,0) when cast(d.iArrQTY as int)=0 then isnull(d.iReceivedQTY,0) else d.iArrQTY end as '到货数量', d.cbCloser as '行关闭人',yy.chdefine31 '订单送货地址',yy.chdefine32 '发票接收地址' from {0}.dbo.OM_MOMain c left join {0}.dbo.OM_MODetails d on c.MOID = d.MOID left join {0}.dbo.OM_MOMain_extradefine yy on c.MOID = yy.MOID left join (select OM_MOMain.cCode as 'cpocode',MAX(PU_ArrivalVouch.cMakeTime) as 'cMakeTime' from {0}.dbo.PU_ArrivalVouch left join {0}.dbo.PU_ArrivalVouchs on PU_ArrivalVouch.id = PU_ArrivalVouchs.ID left join {0}.dbo.OM_MODetails on OM_MODetails.MODetailsID = PU_ArrivalVouchs.iPOsID left join {0}.dbo.OM_MOMain on OM_MOMain.MOID = OM_MODetails.MOID group by OM_MOMain.cCode) xx on c.cCode = xx.cpocode where c.cVerifier is not null and c.cVerifier!=''"; sql = string.Format(sql, WorkPoint); sql2 = string.Format(sql2, WorkPoint); if (condition.dModifyDateFrom != null) { sql += @" and (case when a.cChangAuditTime >=(case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end) then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) then a.cChangAuditTime else (case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end) then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) end) >= '{0}'"; sql = string.Format(sql, condition.dModifyDateFrom); sql2 += @" and (case when c.dChangeVerifyTime >=(case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) then c.dChangeVerifyTime ELSE (case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) end) >= '{0}'"; sql2 = string.Format(sql2, condition.dModifyDateFrom); } if (condition.dModifyDateTo != null) { sql += @" and (case when a.cChangAuditTime >=(case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end) then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) then a.cChangAuditTime else (case when yy.cMakeTime>=(case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end) then yy.cMakeTime else (case when b.cbCloseTime >= (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) then b.cbCloseTime else (case when hh.ModifyTime >= (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) then hh.ModifyTime else (case when a.cAuditTime >= ISNULL(a.cModifyTime, a.cmaketime) then a.cAuditTime else ISNULL(a.cModifyTime, a.cmaketime) end) end) end)end) end) <= '{0}'"; sql = string.Format(sql, condition.dModifyDateTo); sql2 += @" and (case when c.dChangeVerifyTime >=(case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) then c.dChangeVerifyTime ELSE (case when xx.cMakeTime >=(case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) then xx.cMakeTime else (case when d.dbCloseTime >= (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) then d.dbCloseTime else (case when c.dAlterTime >= (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) then c.dAlterTime else (case when c.dVerifyTime >= ISNULL(c.dModifyTime,c.dCreateTime) then c.dVerifyTime else ISNULL(c.dModifyTime,c.dCreateTime) end) end) end) end) end) <= '{0}'"; ; sql2 = string.Format(sql2, condition.dModifyDateTo); } if (condition.POCode != null) { sql += " and a.cPOID like '%{0}%'"; sql = string.Format(sql, condition.POCode); sql2 += " and c.cCode like '%{0}%'"; sql2 = string.Format(sql2, condition.POCode); } sql = sql + " Union All " + sql2; string sqlNew = @" select * from (select aa.*,rn=dense_rank() over(order by 采购订单号) from( "; sqlNew += sql; sqlNew += ") aa)bb where bb.rn between {0} and {1} "; sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize); DataTable dt = ICSHelper.GetDataTableERP(sqlNew); List entityList = new List(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { POEntity entity = new POEntity(); entity.POCode = dr["采购订单号"].ToString(); entity.Sequence = string.IsNullOrWhiteSpace(dr["采购订单行号"].ToString()) ? 0 : Convert.ToInt32(dr["采购订单行号"].ToString()); entity.VenCode = dr["供应商代码"].ToString(); entity.DepCode = dr["部门代码"].ToString(); entity.PersonCode = dr["业务员代码"].ToString(); entity.POType = dr["采购类型名称"].ToString() == "标准" ? 1 : 2; entity.InvCode = dr["物料代码"].ToString(); entity.Quantity = string.IsNullOrWhiteSpace(dr["数量"].ToString()) ? 0 : float.Parse(dr["数量"].ToString()); entity.Amount = string.IsNullOrWhiteSpace(dr["辅计量数量"].ToString()) ? 0 : float.Parse(dr["辅计量数量"].ToString()); entity.UnitPrice = string.IsNullOrWhiteSpace(dr["原币无税单价"].ToString()) ? 0 : float.Parse(dr["原币无税单价"].ToString()); entity.iMoney = string.IsNullOrWhiteSpace(dr["原币无税金额"].ToString()) ? 0 : float.Parse(dr["原币无税金额"].ToString()); entity.iTaxPrice = string.IsNullOrWhiteSpace(dr["原币含税单价"].ToString()) ? 0 : float.Parse(dr["原币含税单价"].ToString()); entity.iPerTaxRate = string.IsNullOrWhiteSpace(dr["原币含税单价"].ToString()) ? 0 : float.Parse(dr["税率"].ToString()); entity.iTax = string.IsNullOrWhiteSpace(dr["原币税额"].ToString()) ? 0 : float.Parse(dr["原币税额"].ToString()); entity.iSum = string.IsNullOrWhiteSpace(dr["原币价税合计"].ToString()) ? 0 : float.Parse(dr["原币价税合计"].ToString()); entity.Currency = dr["币种"].ToString(); entity.nFlat = string.IsNullOrWhiteSpace(dr["汇率"].ToString()) ? 0 : float.Parse(dr["汇率"].ToString()); entity.Status = string.IsNullOrWhiteSpace(dr["状态"].ToString()) ? 0 : Convert.ToInt32(dr["状态"].ToString()); if (!string.IsNullOrWhiteSpace(dr["行关闭人"].ToString())) { entity.Status = 3; } entity.cMemo = dr["头备注"].ToString(); entity.cbMemo = dr["行备注"].ToString(); entity.CreatePerson = dr["创建人"].ToString(); entity.CreateDateTime = dr["创建时间"].ToString(); entity.cModifyPerson = dr["变更人"].ToString(); if (string.IsNullOrWhiteSpace(dr["计划到货日期"].ToString())) { entity.dArriveDate = null; } else { entity.dArriveDate = Convert.ToDateTime(dr["计划到货日期"].ToString()); } if (string.IsNullOrWhiteSpace(dr["停用日期"].ToString())) { entity.dEndDate = null; } else { entity.dEndDate = Convert.ToDateTime(dr["停用日期"].ToString()); } if (string.IsNullOrWhiteSpace(dr["变更日期"].ToString())) { entity.dModifyDate = null; } else { entity.dModifyDate = Convert.ToDateTime(dr["变更日期"].ToString()); } entity.iReceivedQTY = string.IsNullOrWhiteSpace(dr["到货数量"].ToString()) ? 0.00f : float.Parse(dr["到货数量"].ToString()); entity.ShipAddress = dr["订单送货地址"].ToString(); entity.AcceptAddress = dr["发票接收地址"].ToString(); entity.InvVersion = dr["料品版本"].ToString(); entityList.Add(entity); } res.IsSuccess = true; res.Message = "执行成功!"; res.data = entityList; return res; } else { res.IsSuccess = true; res.Message = "查询无数据!"; res.data = entityList; return res; } } catch (Exception ex) { res.IsSuccess = false; res.Message = ex.Message; return res; } } } }