strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then B.OPXS ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
else
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then B.OPXS ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then G.TTLDR-G.TTLCR ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then G.RMBDR-G.RMBCR ELSE 0 end) as ZLRMB"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then G.USDDR-G.USDCR ELSE 0 end) as ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
if(sumfieldtype=="欠费")
{
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then G.TTLDR-G.STLTTLDR ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then G.RMBDR-G.STLRMBDR ELSE 0 end) as ZLRMB"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then G.USDDR-G.STLUSDDR ELSE 0 end) as ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
if(sumfieldtype=="TEU")
strSql.Append(",sum(case when OPTYPE='普通货' and B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then B.TEU ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
if(sumfieldtype=="毛重")
strSql.Append(",sum(case when OPTYPE='普通货' and B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then B.KGS ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
if(sumfieldtype=="计费重")
strSql.Append(",sum(case when OPTYPE='普通货' and B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then B.FEEKGS ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
if(sumfieldtype=="票数")
strSql.Append(",sum(case when B.ACCDATE='"+enumValue.MONTHFIELDNAME.Replace('/','-')+"' then 1 ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
else
{
if(sumfieldtype=="利润")
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR-G.TTLCR ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.RMBDR-G.RMBCR ELSE 0 end) as ZLRMB"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.USDDR-G.USDCR ELSE 0 end) as ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
if(sumfieldtype=="欠费")
{
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.TTLDR-G.STLTTLDR ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.RMBDR-G.STLRMBDR ELSE 0 end) as ZLRMB"+enumValue.MONTHNO.ToString()+"TTL ");
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then G.USDDR-G.STLUSDDR ELSE 0 end) as ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
if(sumfieldtype=="TEU")
strSql.Append(",sum(case when OPTYPE='普通货' and SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then B.TEU ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
if(sumfieldtype=="毛重")
strSql.Append(",sum(case when OPTYPE='普通货' and SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then B.KGS ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
if(sumfieldtype=="计费重")
strSql.Append(",sum(case when OPTYPE='普通货' and SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then B.FEEKGS ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
if(sumfieldtype=="票数")
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='"+enumValue.MONTHFIELDNAME+"' then 1 ELSE 0 end) as ZL"+enumValue.MONTHNO.ToString()+"TTL,0 ZLRMB"+enumValue.MONTHNO.ToString()+"TTL,0 ZLUSD"+enumValue.MONTHNO.ToString()+"TTL ");
}
}
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
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+"')");
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");