using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.RptCwGLDetailColumnChart; 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.RptCwGLDetailColumnChartDAL { public class RptCwGLDetailColumnChartDAL { #region 查询 static public String GetDataList(string strACCDATE, string strCURRENCY, string strACCID, string strCustNAME, string strDeptName, string strSALE, string strITEMNAME, string strSubjectAccount, string acctype, string sumfieldtype, string isDETAILED, string userid, string usercode, string companyid, string sort = null) { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var strSql = new StringBuilder(); string sSql = GetDataListSQL(strACCDATE, strCURRENCY, strACCID, strCustNAME, strDeptName, strSALE, strITEMNAME, strSubjectAccount, acctype, sumfieldtype, isDETAILED, userid, usercode, companyid); strSql.Append(sSql); // var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by OBJNUM desc"); } //return SetData(strSql); return strSql.ToString(); } static public string GetDataListStr(string strACCDATE, string strCURRENCY, string strACCID, string strCustNAME, string strDeptName, string strSALE, string strITEMNAME, string strSubjectAccount, string acctype, string sumfieldtype, string isDETAILED, string userid, string usercode, string companyid) { var strSql = new StringBuilder(); string sSql = GetDataListSQL(strACCDATE, strCURRENCY, strACCID, strCustNAME, strDeptName, strSALE, strITEMNAME, strSubjectAccount, acctype, sumfieldtype, isDETAILED, userid, usercode, companyid); strSql.Append(sSql); strSql.Append(" order by OBJNUM desc"); return strSql.ToString(); } 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 isDETAILED, string userid, string usercode, string companyid) { #region 基本变量 string strCondition = ""; string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid); string sYear = DateTime.Parse(strACCDATE + "-01").Year.ToString(); // string sFieldName = ""; if (!string.IsNullOrEmpty(sumfieldtype)) { if (sumfieldtype.Trim() == "本期合计") { if (strCURRENCY.Trim() == "综合本位币") { sFieldName = "(case when ACCATTRIBUTE='损益' THEN (case when DC='借' then sum(QTYDR) else sum(QTYCR) end) ELSE sum(QTYBLC) END) as OBJNUM"; } else if (strCURRENCY.Trim() == "RMB") { sFieldName = "(case when ACCATTRIBUTE='损益' THEN (case when DC='借' then sum(AMTDR) else sum(AMTCR) end) ELSE sum(AMTBLC) END) as OBJNUM"; } else//外币 { sFieldName = "(case when ACCATTRIBUTE='损益' THEN (case when DC='借' then sum(FCYDR) else sum(FCYCR) end) ELSE sum(FCYBLC) END) as OBJNUM"; } strCondition += " and ACCYEAR='" + sYear + "' and ACCDATE='" + strACCDATE + "'"; } else//本年累计 { 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(FCYLASTCR) else sum(FCYLASTCR) end) ELSE sum(FCYLASTBLC) END) as OBJNUM"; } strCondition += " and ACCYEAR='" + sYear + "' and ACCDATE='" + strACCDATE + "' and YEAR='" + sYear + "'"; } } // if (!string.IsNullOrEmpty(strACCID)) { strCondition += " and ACCID like '" + strACCID + "%'"; if (isDETAILED == "false") { strCondition += " and ACCID<>'" + strACCID + "'"; } } // string SubjectAccount = ""; if (acctype.Trim() == "1") { sFieldName += ",ACCNAME as OBJNAME"; SubjectAccount = ",ACCNAME"; } else { if (!string.IsNullOrEmpty(strSubjectAccount)) { if (strSubjectAccount.Trim() == "客户") { strCondition += "and CORPACC<>''"; if (!string.IsNullOrEmpty(strCustNAME)) { strCondition += "and CORPACC='" + strCustNAME + "'"; } sFieldName += ",CORPACC as OBJNAME"; SubjectAccount = ",CORPACC"; } else if (strSubjectAccount.Trim() == "部门") { strCondition += "and DEPTACC<>''"; if (!string.IsNullOrEmpty(strDeptName)) { strCondition += "and DEPTACC='" + strDeptName + "'"; } sFieldName += ",DEPTACC as OBJNAME"; SubjectAccount = ",DEPTACC"; } else if (strSubjectAccount.Trim() == "人员") { strCondition += "and EMPLACC<>''"; if (!string.IsNullOrEmpty(strSALE)) { strCondition += "and EMPLACC='" + strSALE + "'"; } sFieldName += ",EMPLACC as OBJNAME"; SubjectAccount = ",EMPLACC"; } else if (strSubjectAccount.Trim() == "项目") { strCondition += "and ITEMACC<>''"; 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 where OBJNUM<>0"); return strSql.ToString(); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { RptCwGLDetailColumnChart data = new RptCwGLDetailColumnChart(); #region Set DB data to Object data.OBJNAME = (reader["OBJNAME"] == null ? "" : Convert.ToString(reader["OBJNAME"])); data.OBJNUM = (reader["OBJNUM"] == null ? "" : Convert.ToString(reader["OBJNUM"])); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion } }