strSql.Append(",case OPDATE when '' then 0 else case when BALTTLDR<>0 OR BALTTLCR<>0 then DATEDIFF([day],CASE WHEN STLDATE IS NULL THEN OPDATE ELSE STLDATE END,GETDATE()) ");
strSql.Append(" else (DATEDIFF([day],CASE WHEN STLDATE IS NULL THEN OPDATE ELSE STLDATE END,SETTLETIME)) end end AS NODAY");
strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP,B.SERVICECONTRACTNO");
strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS,B.SALECORPID,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE B.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'RMB' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVRMB,");
strSql.Append("isnull(SUM(CASE CURRENCY WHEN 'USD' THEN ISNULL(INVOICE,0) ELSE 0 END),0) AS INVUSD,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLCR");
strSql.Append(",case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, GETDATE()) end) ");
strSql.Append(" else (case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else DATEDIFF([day],B.OPDATE, S.SETTLETIME) end) end AS ACTUALDAY,S.SETTLETIME");
if(NORPTSTLDATETYPE.PARAMVALUE=="1")
{
strSql.Append(",[dbo].[GetCustStlDay](B.OPDATE,F.CUSTOMERNAME,B.SALE) AS STLDATE");
}
else
{
strSql.Append(",CASE WHEN B.STLDATE IS NULL THEN B.OPDATE ELSE B.STLDATE END STLDATE");
}
//strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then 0 else case when isnull(SUM(F.AMOUNT),0)<>isnull(SUM(F.SETTLEMENT),0) then DATEDIFF([day],B.OPDATE,(CASE C.STLNAME WHEN '月结' THEN ");
//strSql.Append("DATEADD(month,1,DATEADD(day,ISNULL(CAST(C.STLDATE AS INT),1),DATEADD(day,-Day(B.OPDATE)+1,B.OPDATE)))");
//strSql.Append("WHEN '半月结' THEN (CASE WHEN DATEPART(DAY, GETDATE())<=15 THEN DATEADD(day,ISNULL(CAST(C.STLFIRSTHALFDATE AS INT),16),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))");
//strSql.Append("ELSE DATEADD(MONTH,1,DATEADD(day,ISNULL(CAST(C.STLMIDDLEDATE AS INT),1),DATEADD(Day,-Day(B.OPDATE)+1,B.OPDATE))) END)");
//strSql.Append("ELSE GETDATE() END)) else (DATEDIFF([day],B.OPDATE, S.SETTLETIME)) end end AS NODAY");
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
strSql.Append(" LEFT JOIN V_MAX_SETTLEMENTTIME S ON (S.CUSTOMERNAME=F.CUSTOMERNAME AND S.BSNO=B.BSNO) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" GROUP BY B.BSNO,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,");
strSql.Append("SELECT F.GID,F.FEETYPE,F.FEENAME,F.FEEDESCRIPTION,F.CUSTOMERNAME AS CUSTNAME,F.UNIT,F.UNITPRICE,F.QUANTITY,F.AMOUNT,F.CURRENCY,F.EXCHANGERATE");
strSql.Append("SELECT F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLCR");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) ");
if(!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where "+condition);
}
strSql.Append(" Group by F.CUSTOMERNAME,C.[DESCRIPTION] ");
strSql.Append("SELECT isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS TTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS TTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS STLTTLCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLCR");
strSql.Append(" FROM CH_FEE F ");
strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
str=" (B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"' ";
}
else
{
str=str+" or B.Corpid='"+Convert.ToString(reader["COMPANYID"])+"' or B.SALECORPID='"+Convert.ToString(reader["COMPANYID"])+"'";
};
}
str=str+")";
reader.Close();
}
}
elseif(visiblerange=="6")
{
varuserstr=newStringBuilder();
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='"+userid+"' and AUTHORITYID='"+AUTHORITYID+"' and VISIBLERANGE=1");
str=" (B.OP='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.SALE='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.CUSTSERVICE='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.DOC='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.FRCUSTSERVICE='"+Convert.ToString(reader["SHOWNAME"])+"' ";
}
else
{
str=str+" or B.OP='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.SALE='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.CUSTSERVICE='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.DOC='"+Convert.ToString(reader["SHOWNAME"])+"' OR B.FRCUSTSERVICE='"+Convert.ToString(reader["SHOWNAME"])+"' ";
};
}
str=str+")";
reader.Close();
}
}
elseif(visiblerange=="3")
{
str=" (B.OP='"+usercode+"' OR B.SALE='"+usercode+"')";
}
elseif(visiblerange=="2")
{
if(tb=="index")
{
varrangeDa=newRangeDA();
vardeptname=rangeDa.GetDEPTNAME(userid);
varuserstr=newStringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='"+companyid+"') and GID in (select userid from user_baseinfo where DEPTNAME='"+deptname+"')");