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 ");
condition=condition+" and (B.ISCANCEL IS NULL OR B.ISCANCEL=0 ) ";
}
else
{
condition=" (B.ISCANCEL IS NULL OR B.ISCANCEL=0 ) ";
}
}
if(objtype=="会计期间")
{
startmonth=startmonth+"-01";
endmonth=endmonth+"-01";
}
varmonthlist=GetMonthList(startmonth,endmonth);
varstrSql=newStringBuilder();
strSql.Append("SELECT 1 as NO ");
foreach(varenumValueinmonthlist)
{
if(objtype=="会计期间")
{
if(sumfieldtype=="利润")
{
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 ");
strSql.Append(",sum(case when OPTYPE='普通货' and 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 ");
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 ");
strSql.Append(",sum(case when OPTYPE='普通货' and 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 ");
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");