You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/DAL/RptCwGLDetailColumnCompare/RptCwGLDetailColumnCompareD...

191 lines
8.7 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.RptCwGLDetailColumnCompare;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.DAL.RptCwGLDetailColumnCompareDAL
{
public class RptCwGLDetailColumnCompareDAL
{
#region 查询
static public List<RptCwGLDetailColumnCompare> GetDataList(string condition, string sort, string sumfieldtype, string startmonth, string endmonth, string userid, string username, string companyid)
{
var monthlist = GetMonthList(startmonth, endmonth);
var strSql = new StringBuilder();
strSql.Append("SELECT 1 as NO ");
foreach (var enumValue in monthlist)
{
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 ");
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 ");
if (sumfieldtype == "TEU")
strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then B.TEU ELSE 0 end) as ZL" + 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) ");
strSql.Append(" WHERE 1=1 ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" AND " + condition);
}
return SetData(strSql, monthlist);
}
private static List<RptCwGLDetailColumnCompare> SetData(StringBuilder strSql, List<MonthDataSet> monthlist)
{
var headList = new List<RptCwGLDetailColumnCompare>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
foreach (var enumValue in monthlist)
{
RptCwGLDetailColumnCompare data = new RptCwGLDetailColumnCompare();
#region Set DB data to Object
data.MONTHNAME = enumValue.MONTHNAME;
data.MONTHNO = enumValue.MONTHNO;
if (reader["ZL" + enumValue.MONTHNO.ToString() + "TTL"] != DBNull.Value)
data.MONTHNUM = Convert.ToDecimal(reader["ZL" + enumValue.MONTHNO.ToString() + "TTL"]);
else
data.MONTHNUM = 0;
#endregion
headList.Add(data);
}
}
reader.Close();
}
return headList;
}
static public List<MonthDataSet> GetMonthList(string startmonth, string endmonth)
{
var startdate = startmonth.Split('-');
var enddate = endmonth.Split('-');
int monthstart = Convert.ToInt16(startdate[0]) * 12 + Convert.ToInt16(startdate[1]);
int monthend = Convert.ToInt16(enddate[0]) * 12 + Convert.ToInt16(enddate[1]);
var betweenmonth = monthend - monthstart + 1;
DateTime dt = DateTime.ParseExact(startmonth, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
var evList = new List<MonthDataSet>();
var month = "";
for (int i = 0; i < betweenmonth; i++)
{
var evData = new MonthDataSet();
evData.MONTHNAME = dt.ToString("yyyy年MM月");
evData.MONTHNO = i;
month = dt.Month.ToString();
if (month.Length == 1) month = "0" + month;
evData.MONTHFIELDNAME = dt.Year.ToString() + "/" + month;
evList.Add(evData);
dt = dt.AddMonths(1);
}
return evList;
}
static public string GetDataListSQL(string strACCDATE, string strCURRENCY, string strACCID, string strCustNAME, string strDeptName, string strSALE, string strITEMNAME, string strSubjectAccount, string acctype, string sumfieldtype, string userid, string usercode, string companyid)
{
#region 基本变量
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string strCondition = "";
string sYear = DateTime.Parse(strACCDATE + "-01").Year.ToString();
//
string sFieldName = "";
if (strCURRENCY.Trim() == "综合本位币")
{
sFieldName = "(case when ACCATTRIBUTE='损益' THEN (case when DC='借' then sum(QTYLASTDR) else sum(QTYLASTCR) end) ELSE sum(QTYLASTBLC) END) as OBJNUM";
}
else if (strCURRENCY.Trim() == "RMB")
{
sFieldName = "(case when ACCATTRIBUTE='损益' THEN (case when DC='借' then sum(AMTLASTDR) else sum(AMTLASTCR) end) ELSE sum(AMTLASTBLC) END) as OBJNUM";
}
else//外币
{
sFieldName = "(case when ACCATTRIBUTE='损益' THEN (case when DC='借' then sum(FCYLASTDR) else sum(FCYLASTCR) end) ELSE sum(FCYLASTBLC) END) as OBJNUM";
}
//
if (!string.IsNullOrEmpty(sumfieldtype))
{
if (sumfieldtype.Trim() == "本期合计")
{
strCondition += " and ACCYEAR='" + sYear + "' and ACCDATE='" + strACCDATE + "'";
}
else//本年累计
{
strCondition += " and ACCYEAR='" + sYear + "' and ACCDATE<='" + strACCDATE + "' and YEAR='" + sYear + "'";
}
}
//
if (!string.IsNullOrEmpty(strACCID))
{
strCondition += "and ACCID like '" + strACCID + "%' and ACCID<>'" + strACCID + "'";
}
//
string SubjectAccount = "";
if (acctype.Trim() == "1")
{
sFieldName += ",ACCNAME as OBJNAME";
SubjectAccount = ",ACCNAME";
}
else
{
if (!string.IsNullOrEmpty(strSubjectAccount))
{
if (strSubjectAccount.Trim() == "客户")
{
if (!string.IsNullOrEmpty(strCustNAME))
{
strCondition += "and CORPACC='" + strCustNAME + "'";
}
sFieldName += ",CORPACC as OBJNAME";
SubjectAccount = ",CORPACC";
}
else if (strSubjectAccount.Trim() == "部门")
{
if (!string.IsNullOrEmpty(strDeptName))
{
strCondition += "and DEPTACC='" + strDeptName + "'";
}
sFieldName += ",DEPTACC as OBJNAME";
SubjectAccount = ",DEPTACC";
}
else if (strSubjectAccount.Trim() == "人员")
{
if (!string.IsNullOrEmpty(strSALE))
{
strCondition += "and EMPLACC='" + strSALE + "'";
}
sFieldName += ",EMPLACC as OBJNAME";
SubjectAccount = ",EMPLACC";
}
else if (strSubjectAccount.Trim() == "项目")
{
if (!string.IsNullOrEmpty(strITEMNAME))
{
strCondition += "and ITEMACC='" + strITEMNAME + "'";
}
sFieldName += ",ITEMACC as OBJNAME";
SubjectAccount = ",ITEMACC";
}
}
}
#endregion
var strSql = new StringBuilder();
strSql.Append("select OBJNAME, OBJNUM from (SELECT " + sFieldName + " from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "'" + strCondition + " group BY ACCATTRIBUTE,DC,ACCID,ACCNAME" + SubjectAccount + ") as a");
return strSql.ToString();
}
#endregion
}
}