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/Controllers/RptCwGLDetailColumnCompareC...

777 lines
44 KiB
C#

3 years ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.Models.MonthDataSet;
using DSWeb.MvcShipping.DAL.RptCwGLDetailColumnCompareDAL;
namespace DSWeb.MvcShipping.Controllers
{
/// <summary>
/// 业务走势对比图表分析
/// </summary>
[JsonRequestBehavior]
public class RptCwGLDetailColumnCompareController : Controller
{
public ActionResult Index()
{
return View();
}
public ContentResult GetDataList(string condition, string sort, string printstr, string sumfieldtype, string startmonth, string endmonth)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
var dataList = RptCwGLDetailColumnCompareDAL.GetDataList(condition, sort, sumfieldtype, startmonth, endmonth, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetObjListData(string OBJNAME, string sumfieldtype, string strACCDATEbgn, string strACCDATEend, string strCURRENCY, string strACCID, string strCustNAME, string strDeptName, string strSALE, string strITEMNAME, string strSubjectAccount, string acctype)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
var dataList = GetObjList(OBJNAME, sumfieldtype, strACCDATEbgn, strACCDATEend, strCURRENCY, strACCID, strCustNAME, strDeptName, strSALE, strITEMNAME, strSubjectAccount, acctype, Convert.ToString(Session["USERID"]).Trim());
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = dataList.ToList() });
return new ContentResult() { Content = json };
}
static public List<MonthDataSet> GetObjList(string OBJNAME, string sumfieldtype, string strACCDATEbgn, string strACCDATEend, string strCURRENCY, string strACCID, string strCustNAME, string strDeptName, string strSALE, string strITEMNAME, string strSubjectAccount, string acctype, string strUserID)
{
#region 基本变量
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string sYear = DateTime.Parse(strACCDATEbgn + "-01").Year.ToString();
string strCondition = " and ACCYEAR='" + sYear + "' and ACCDATE>='" + strACCDATEbgn + "' and ACCDATE<='" + strACCDATEend + "'";
//
string sFieldName = "";
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";
}
}
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";
}
}
//
string SubjectAccount = "";
if (acctype.Trim() == "1")
{
if (!string.IsNullOrEmpty(strACCID))
{
if (OBJNAME.Trim() == "对比")
{
if (strSubjectAccount == "-1")
{
strCondition += " and ACCID like '" + strACCID + "%'";
}
else
{
strCondition += " and ACCID like '" + strACCID + "%' and ACCID<>'" + strACCID + "'";
}
}
else
{
strCondition += " and ACCID='" + strACCID + "'";
}
}
//
sFieldName += ",ACCNAME as OBJNAME";
SubjectAccount = ",ACCNAME";
}
else
{
if (!string.IsNullOrEmpty(strACCID))
{
if (OBJNAME.Trim() == "对比")
{
strCondition += " and ACCID like '" + strACCID + "%'";
//
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";
}
else
{
sFieldName += ",ACCNAME as OBJNAME";
SubjectAccount = ",ACCNAME";
strCondition += " and ACCID='" + strACCID + "'";
}
}
else
{
sFieldName += ",ACCNAME as OBJNAME";
SubjectAccount = ",ACCNAME";
strCondition += " and ACCID='" + strACCID + "'";
}
}
else
{
sFieldName += ",ACCNAME as OBJNAME";
SubjectAccount = ",ACCNAME";
strCondition += " and ACCID='" + strACCID + "'";
}
}
}
#endregion
var strSql = new StringBuilder();
strSql.Append("select OBJNAME, OBJNUM,ACCID from (SELECT " + sFieldName + ",ACCID from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "'" + strCondition + " group BY STARTGID,ACCATTRIBUTE,DC,ACCID,ACCNAME" + SubjectAccount + ") as a where OBJNUM<>0 order by ACCID");
//
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<MonthDataSet>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
var i = 1;
while (reader.Read() && i<12)//11
{
var evData = new MonthDataSet();
evData.MONTHNAME = Convert.ToString(reader["OBJNAME"]).Replace(" ","");
evData.MONTHNO = i;
evList.Add(evData);
i = i + 1;
}
reader.Close();
}
return evList;
}
public ContentResult SumListData(string OBJNAME, string sumfieldtype, string strACCDATEbgn, string strACCDATEend, string strCURRENCY, string strACCID, string strCustNAME, string strDeptName, string strSALE, string strITEMNAME, string strSubjectAccount, string acctype)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
var monthlist = GetMonthList(strACCDATEbgn + "-01", strACCDATEend + "-01");
var objlist = GetObjList(OBJNAME, sumfieldtype, strACCDATEbgn, strACCDATEend, strCURRENCY, strACCID, strCustNAME, strDeptName, strSALE, strITEMNAME, strSubjectAccount, acctype, Convert.ToString(Session["USERID"]));
//
#region 基本变量
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(Convert.ToString(Session["USERID"]));
string sYear = DateTime.Parse(strACCDATEbgn + "-01").Year.ToString();
string strCondition = " and ACCYEAR='" + sYear + "' and ACCDATE>='" + strACCDATEbgn + "' and ACCDATE<='" + strACCDATEend + "'";
//
string sFieldName = "";
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";
}
}
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";
}
}
//
string sSAName = "";
string SubjectAccount = "";
if (acctype.Trim() == "1")
{
if (!string.IsNullOrEmpty(strACCID))
{
if (OBJNAME.Trim() == "对比")
{
if (strSubjectAccount == "-1")
{
strCondition += "and ACCID like '" + strACCID + "%'";
}
else
{
strCondition += "and ACCID like '" + strACCID + "%' and ACCID<>'" + strACCID + "'";
}
}
else
{
strCondition += "and ACCID='" + strACCID + "'";
}
}
//
SubjectAccount = ",ACCNAME";
sSAName = "ACCNAME";
}
else
{
if (!string.IsNullOrEmpty(strACCID))
{
if (OBJNAME.Trim() == "对比")
{
strCondition += "and ACCID like '" + strACCID + "%'";
//
if (!string.IsNullOrEmpty(strSubjectAccount))
{
if (strSubjectAccount.Trim() == "客户")
{
strCondition += " and CORPACC<>''";
if (!string.IsNullOrEmpty(strCustNAME))
{
strCondition += "and CORPACC='" + strCustNAME + "'";
}
SubjectAccount = ",CORPACC";
sSAName = "CORPACC";
}
else if (strSubjectAccount.Trim() == "部门")
{
strCondition += " and DEPTACC<>''";
if (!string.IsNullOrEmpty(strDeptName))
{
strCondition += "and DEPTACC='" + strDeptName + "'";
}
SubjectAccount = ",DEPTACC";
sSAName = "DEPTACC";
}
else if (strSubjectAccount.Trim() == "人员")
{
strCondition += " and EMPLACC<>''";
if (!string.IsNullOrEmpty(strSALE))
{
strCondition += "and EMPLACC='" + strSALE + "'";
}
SubjectAccount = ",EMPLACC";
sSAName = "EMPLACC";
}
else if (strSubjectAccount.Trim() == "项目")
{
strCondition += " and ITEMACC<>''";
if (!string.IsNullOrEmpty(strITEMNAME))
{
strCondition += "and ITEMACC='" + strITEMNAME + "'";
}
SubjectAccount = ",ITEMACC";
sSAName = "ITEMACC";
}
else
{
SubjectAccount = ",ACCNAME";
sSAName = "ACCNAME";
strCondition += "and ACCID='" + strACCID + "'";
}
}
else
{
SubjectAccount = ",ACCNAME";
sSAName = "ACCNAME";
strCondition += "and ACCID='" + strACCID + "'";
}
}
else
{
SubjectAccount = ",ACCNAME";
sSAName = "ACCNAME";
strCondition += "and ACCID='" + strACCID + "'";
}
}
}
#endregion
//
var strSql = new StringBuilder();
strSql.Append("SELECT ACCDATE as MONTHNAME");
foreach (var enumValue in objlist)
{
strSql.Append(",Z" + enumValue.MONTHNAME + "=(SELECT " + sFieldName + " FROM VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=a.ACCDATE and " + sSAName + "='" + enumValue.MONTHNAME + "'" + strCondition + " group BY STARTGID,ACCATTRIBUTE,DC,ACCDATE,ACCID" + SubjectAccount + ")");
}
strSql.Append(" FROM VW_cw_genleg_accitems_gl as a where STARTGID='" + strCwSTARTGID + "'" + strCondition + " group BY STARTGID,ACCATTRIBUTE,DC,ACCDATE order by ACCDATE");
//
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(0, 2000, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
#region 月度数
public ContentResult GetMonthsData(string startmonth, string endmonth)
{
var dataList = GetMonthList(startmonth, endmonth);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = dataList.ToList() });
return new ContentResult() { Content = json };
}
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;
}
#endregion
//显示科目明细信息
public string GetDataListDetail(int adjest, bool isAnalyze, string strACCDATE, string strCURRENCY, string strACCID, string strInquireClass, string strInquireField, string sumfieldtype, string acctype) // string strSubjectAccount,
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(Convert.ToString(Session["USERID"]));
string strCondition = "";
string sYear = DateTime.Parse(strACCDATE + "-01").Year.ToString();
string accDateBgn = "and ACCDATE='" + strACCDATE + "'";
string accDateEnd = "and ACCDATE='" + strACCDATE + "'";
string sCondition = "";
string sHSKM = "";
string createUser = Convert.ToString(Session["USERID"]);
string corpID = Convert.ToString(Session["COMPANYID"]);
string strSQLContent = "";
if (isAnalyze)
{
if (adjest==1) { sHSKM = strInquireClass; }
}
else
{
if (adjest==1) { sHSKM = strInquireClass; }
else if (adjest == 2 || adjest == 0) //从数据库查询判断sHKM值
{
/*strCondition = "ACCID='" + strACCID + "'";
if (!string.IsNullOrEmpty(strCondition))
{
sCondition += "and " + strCondition;
}
sCondition += " and [YEAR]='" + sYear + "'";
string strSqlAdjust = "select top 1 * from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'" + sCondition;
DataSet ds = T_ALL_DA.GetAllSQL(strSqlAdjust);
if (ds != null) //获得sHSKM
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISCORPACC"].ToString() == "True")
{
sHSKM = "客户";
}
if (ds.Tables[0].Rows[0]["ISDEPTACC"].ToString() == "True")
{
sHSKM = "部门";
}
if (ds.Tables[0].Rows[0]["ISEMPLACC"].ToString() == "True")
{
sHSKM = "人员";
}
if (ds.Tables[0].Rows[0]["ISITEMACC"].ToString() == "True")
{
sHSKM = "项目";
}
}
}*/
sHSKM = strInquireClass;
}
}
strCondition = "";
#region 基本变量
string strParam1 = "";
string strParam2 = "";
switch (sHSKM)
{
case "客户":
if (adjest == 1 || adjest == 0)
{
//判断有无明细科目
string sConditionDetail = "";
if (!string.IsNullOrEmpty(strACCID))
{
sConditionDetail += " and ACCID='" + strCondition + "'";
}
//string sYear = DateTime.Parse(ACCDATEbgn + "-01").Year.ToString();
sCondition += " and [YEAR]='" + sYear + "'";
//
string sSQLDetail = "select COUNT(*) as inum from cw_accitems_gl where PACCGID in (select GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'" + sCondition + ")";
//
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQLDetail));
if (inum == 0) //没有子科目
{/**/
if (!string.IsNullOrEmpty(strInquireField))
{
//strParam1 = " and CUSTOMERNAME='" + strInquireField + "'";
strParam1 = " and ACCNAME='" + strInquireField + "'";
}
}
/*else if(inum>0)
{
strParam1 = "";
}*/
}
else if (adjest == 2)
{
strParam1 = " and CUSTOMERNAME='" + strInquireField + "'";
}
break;
case "部门":
if (adjest == 1 || adjest == 0)
{
//判断有无明细科目
string sConditionDetail = "";
if (!string.IsNullOrEmpty(strACCID))
{
sConditionDetail += " and ACCID='" + strCondition + "'";
}
//string sYear = DateTime.Parse(ACCDATEbgn + "-01").Year.ToString();
sCondition += " and [YEAR]='" + sYear + "'";
//
string sSQLDetail = "select COUNT(*) as inum from cw_accitems_gl where PACCGID in (select GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'" + sCondition + ")";
//
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQLDetail));
if (inum == 0) //没有子科目
{/**/
if (!string.IsNullOrEmpty(strInquireField))
{
//strParam1 = " and DEPTNAME='" + strInquireField + "'";
strParam1 = " and ACCNAME='" + strInquireField + "'";
}
}
/*else if (inum > 0)
{
strParam1 = "";
}*/
}
else if (adjest == 2)
{
strParam1 = " and DEPTNAME='" + strInquireField + "'";
}
break;
case "人员":
if (adjest == 1 || adjest == 0)
{
//判断有无明细科目
string sConditionDetail = "";
if (!string.IsNullOrEmpty(strACCID))
{
sConditionDetail += " and ACCID='" + strCondition + "'";
}
//string sYear = DateTime.Parse(ACCDATEbgn + "-01").Year.ToString();
sCondition += " and [YEAR]='" + sYear + "'";
//
string sSQLDetail = "select COUNT(*) as inum from cw_accitems_gl where PACCGID in (select GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'" + sCondition + ")";
//
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQLDetail));
if (inum == 0) //没有子科目
{/**/
if (!string.IsNullOrEmpty(strInquireField))
{
//strParam1 = " and SALE='" + strInquireField + "'";
strParam1 = " and ACCNAME='" + strInquireField + "'";
}
}
/*else if (inum > 0)
{
strParam1 = "";
}*/
}
else if (adjest == 2)
{
strParam1 = " and SALE='" + strInquireField + "'";
}
break;
case "项目":
if (adjest == 1 || adjest == 0)
{
//判断有无明细科目
string sConditionDetail = "";
if (!string.IsNullOrEmpty(strACCID))
{
sConditionDetail += " and ACCID='" + strCondition + "'";
}
//string sYear = DateTime.Parse(ACCDATEbgn + "-01").Year.ToString();
sCondition += " and [YEAR]='" + sYear + "'";
//
string sSQLDetail = "select COUNT(*) as inum from cw_accitems_gl where PACCGID in (select GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'" + sCondition + ")";
//
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQLDetail));
if (inum == 0) //没有子科目
{/**/
if (!string.IsNullOrEmpty(strInquireField))
{
//strParam1 = " and ITEMNAME='" + strInquireField + "'";
strParam1 = " and ACCNAME='" + strInquireField + "'";
}
}
/*else if (inum > 0)
{
strParam1 = "";
}*/
}
else if (adjest == 2)
{
strParam1 = " and ITEMNAME='" + strInquireField + "'";
}
break;
default:
if (!string.IsNullOrEmpty(strInquireField))
{
//判断有无明细科目
string sConditionDetail = "";
if (!string.IsNullOrEmpty(strACCID))
{
sConditionDetail += " and ACCID='" + strCondition + "'";
}
//string sYear = DateTime.Parse(ACCDATEbgn + "-01").Year.ToString();
sCondition += " and [YEAR]='" + sYear + "'";
//
string sSQLDetail = "select COUNT(*) as inum from cw_accitems_gl where PACCGID in (select GID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "'" + sCondition + ")";
//
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQLDetail));
if (inum > 0) //有子科目
{
strParam2 = " and LINKACCID like (select top 1 ACCID from cw_accitems_gl where ACCNAME='" + strInquireField + "' and [STARTGID]='" + strCwSTARTGID + "')+'%'";
}
else //无子科目
{
strParam2 = " and LINKACCID = (select top 1 ACCID from cw_accitems_gl where ACCNAME='" + strInquireField + "' and [STARTGID]='" + strCwSTARTGID + "')";
//if(isAnalyze==true
}
}
break;
}
#endregion
strCondition = "ACCDATE>='" + strACCDATE + "' and ACCDATE<='" + strACCDATE + "'";
#region 基本查询语句
StringBuilder strSql = new StringBuilder();
if (strCURRENCY.Trim() == "综合本位币")
{
#region 综合本位币
strSql.Append("select LINKACCID,GID,ORDNO,VKNO,VOUNO,VOUDATE,EXPLAN,EXPLAN2,DC=(SELECT top 1 DC FROM cw_accitems_gl WHERE GID=a.LINKGID),DR,CR,isnull((CASE WHEN DC='借' THEN (DR-CR) ELSE (CR-DR) END),0) as BLC,'" + createUser + "' as [CREATEUSER],'" + corpID + "' as [CORPID] from (select GID,ORDNO,LINKACCID=(SELECT top 1 ACCID FROM cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "'),LINKGID=(SELECT top 1 GID FROM cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "'),VKNO,VOUNO,VOUDATE,(ACCYEAR+'-'+ACCMONTH) as ACCDATE,EXPLAN,2 as EXPLAN2,DC=(CASE WHEN DC='D' THEN '借' ELSE '贷' END),(case when isnull(AMTDR,0)=0 THEN isnull(convert(numeric(8,2),round(FCYDR*FCYEXRATE,2)),0) else isnull(AMTDR,0) END) as DR,(case when isnull(AMTCR,0)=0 THEN isnull(convert(numeric(8,2),round(FCYCR*FCYEXRATE,2)),0) else isnull(AMTCR,0) END) as CR from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ISCHECKED=1" + strParam1 + ") as a where (DR<>0 OR CR<>0) and LINKGID in (select GID from cw_accitems_gl where ACCID like '" + strACCID + "%' and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "') " + strParam2);
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("order by VOUDATE asc ");
/*strSql.Append(" union ");
strSql.Append("(SELECT newid() as GID,'' as ORDNO,'' as VKNO,0 as VOUNO,CONVERT(varchar(100),(DATEADD(mm,1,(ACCDATE+'-01'))-1),23) as VOUDATE,'本期合计' as EXPLAN,3 as EXPLAN2,DC");
strSql.Append(",isnull(sum(QTYDR),0) as DR,isnull(sum(QTYCR),0) as CR,isnull(sum(QTYBLC),0) as BLC,'" + createUser + "' as [CREATEUSER],'" + corpID + "' as [CORPID]");
strSql.Append(" from (");
strSql.Append("select *,DC=(select top 1 DC from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID) from cw_genleg_accitems where ISDELETE=0 and ISENABLE=1 and (QTYLASTBLC<>0 OR QTYDR<>0 OR QTYCR<>0 or QTYLASTDR<>0 or QTYLASTCR<>0) and LINKGID in (select GID from cw_accitems_gl where ACCID like '" + strACCID + "' and [YEAR]='" + sYear + "')" + strCustNAME2 + strDeptName2 + strSALE2 + strITEMNAME2);
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//strSql.Append(" and CORPID='" + corpID + "'");
strSql.Append(") as a");
strSql.Append(" group by LINKGID,ACCDATE,DC)");*/
#endregion
}
else if (strCURRENCY.Trim() == "RMB")
{
#region RMB
strSql.Append("select LINKACCID,GID,ORDNO,VKNO,VOUNO,VOUDATE,EXPLAN,EXPLAN2,DC=(SELECT top 1 DC FROM cw_accitems_gl WHERE GID=a.LINKGID),DR,CR,BLC,'" + createUser + "' as [CREATEUSER],'" + corpID + "' as [CORPID] from (select GID,ORDNO,LINKACCID=(SELECT top 1 ACCID FROM cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "'),LINKGID=(SELECT top 1 GID FROM cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "'),VKNO,VOUNO,VOUDATE,(ACCYEAR+'-'+ACCMONTH) as ACCDATE,EXPLAN,2 as EXPLAN2,DC=(CASE WHEN DC='D' THEN '借' ELSE '贷' END),AMTDR as DR,AMTCR as CR,isnull((CASE WHEN DC='D' THEN (AMTDR-AMTCR) ELSE (AMTCR-AMTDR) END),0) as BLC from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ISCHECKED=1 and (AMTDR<>0 OR AMTCR<>0)" + strParam1 + " and (case when FCY='USD' then FCY else 'RMB' end)='" + strCURRENCY + "') as a where LINKGID in (select GID from cw_accitems_gl where ACCID like '" + strACCID + "%' and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "') " + strParam2);// and CURRENCY='" + strCURRENCY + "'
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("order by VOUDATE asc ");
/*strSql.Append(" union ");
strSql.Append("(SELECT newid() as GID,'' as ORDNO,'' as VKNO,0 as VOUNO,CONVERT(varchar(100),(DATEADD(mm,1,(ACCDATE+'-01'))-1),23) as VOUDATE,'本期合计' as EXPLAN,3 as EXPLAN2,DC");
strSql.Append(",isnull(sum(AMTDR),0) as DR,isnull(sum(AMTCR),0) as CR,isnull(sum(AMTBLC),0) as BLC,'" + userid + "' as [CREATEUSER],'" + corpID + "' as [CORPID]");
strSql.Append(" from (");
strSql.Append("select *,DC=(select top 1 DC from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID) from cw_genleg_accitems where ISDELETE=0 and ISENABLE=1 and CURRENCY='" + strCURRENCY + "' and (QTYLASTBLC<>0 OR QTYDR<>0 OR QTYCR<>0 or QTYLASTDR<>0 or QTYLASTCR<>0) and LINKGID in (select GID from cw_accitems_gl where ACCID like '" + strACCID + "' and [YEAR]='" + sYear + "')" + strCustNAME2 + strDeptName2 + strSALE2 + strITEMNAME2);
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//strSql.Append(" and CORPID='" + corpID + "'");
strSql.Append(") as a");
strSql.Append(" group by LINKGID,ACCDATE,DC)");*/
#endregion
}
else//外币
{
#region 外币
strSql.Append("select LINKACCID,GID,ORDNO,VKNO,VOUNO,VOUDATE,EXPLAN,EXPLAN2,DC=(SELECT top 1 DC FROM cw_accitems_gl WHERE GID=a.LINKGID),DR,CR,BLC,'" + createUser + "' as [CREATEUSER],'" + corpID + "' as [CORPID] from (select GID,ORDNO,LINKACCID=(SELECT top 1 ACCID FROM cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "'),LINKGID=(SELECT top 1 GID FROM cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "'),VKNO,VOUNO,VOUDATE,(ACCYEAR+'-'+ACCMONTH) as ACCDATE,EXPLAN,2 as EXPLAN2,DC=(CASE WHEN DC='D' THEN '借' ELSE '贷' END),FCYDR as DR,FCYCR as CR,isnull((CASE WHEN DC='D' THEN (FCYDR-FCYCR) ELSE (FCYCR-FCYDR) END),0) as BLC from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ISCHECKED=1 and (FCYDR<>0 OR FCYCR<>0)" + strParam1 + " and (case when FCY='USD' then FCY else 'RMB' end)='" + strCURRENCY + "') as a where LINKGID in (select GID from cw_accitems_gl where ACCID like '" + strACCID + "%' and STARTGID='" + strCwSTARTGID + "' and [YEAR]='" + sYear + "' )" + strParam2);// and CURRENCY='" + strCURRENCY + "'
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("order by VOUDATE asc ");
/*strSql.Append(" union ");
strSql.Append("(SELECT newid() as GID,'' as ORDNO,'' as VKNO,0 as VOUNO,CONVERT(varchar(100),(DATEADD(mm,1,(ACCDATE+'-01'))-1),23) as VOUDATE,'本期合计' as EXPLAN,3 as EXPLAN2,DC");
strSql.Append(",isnull(sum(FCYDR),0) as DR,isnull(sum(FCYCR),0) as CR,isnull(sum(FCYBLC),0) as BLC,'" + userid + "' as [CREATEUSER],'" + corpID + "' as [CORPID]");
strSql.Append(" from (");
strSql.Append("select *,DC=(select top 1 DC from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID) from cw_genleg_accitems where ISDELETE=0 and ISENABLE=1 and CURRENCY='" + strCURRENCY + "' and (QTYLASTBLC<>0 OR QTYDR<>0 OR QTYCR<>0 or QTYLASTDR<>0 or QTYLASTCR<>0) and LINKGID in (select GID from cw_accitems_gl where ACCID like '" + strACCID + "' and [YEAR]='" + sYear + "')" + strCustNAME2 + strDeptName2 + strSALE2 + strITEMNAME2);
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//strSql.Append(" and CORPID='" + corpID + "'");
strSql.Append(") as a");
strSql.Append(" group by LINKGID,ACCDATE,DC)");*/
#endregion
}
#endregion
Database db = DatabaseFactory.CreateDatabase();
string evList = string.Empty;
evList = "[";
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
var i = 1;
while (reader.Read())
{
evList += "{";
//evList += "MONTHNAME:\"" + Convert.ToString(reader["MONTHNAME"]) + "\",MBLNO:\"" + Convert.ToString(reader["MBLNO"]) + "\",CUSTOMERNAME:\"" + Convert.ToString(reader["CUSTOMERNAME"]) + "\",CNTRTOTAL:\"" + Convert.ToString(reader["CNTRTOTAL"]) + "\",PORTDISCHARGE:\"" + Convert.ToString(reader["PORTDISCHARGE"]) + "\",OP:\"" + Convert.ToString(reader["OP"]) + "\",SALE:\"" + Convert.ToString(reader["SALE"]) + "\",BSSOURCE:\"" + Convert.ToString(reader["BSSOURCE"]) + "\",BSTYPE:\"" + Convert.ToString(reader["BSTYPE"]) + "\",LANE:\"" + Convert.ToString(reader["LANE"]) + "\",RMBAMOUNT:\"" + Convert.ToString(reader["RMBAMOUNT"]) + "\",SUMRMBAMOUNT:\"" + Convert.ToString(reader["SUMRMBAMOUNT"]) + "\",USDAMOUNT:\"" + Convert.ToString(reader["USDAMOUNT"]) + "\",SUMUSDAMOUNT:\"" + Convert.ToString(reader["SUMUSDAMOUNT"]) + "\",OTAMOUNT:\"" + Convert.ToString(reader["OTAMOUNT"]) + "\",SUMOTAMOUNT:\"" + Convert.ToString(reader["SUMOTAMOUNT"]) + "\",TTLAMOUNT:\"" + Math.Round(decimal.Parse(Convert.ToString(reader["TTLAMOUNT"])), 2, MidpointRounding.AwayFromZero) + "\",SUMTTLAMOUNT:\"" + Math.Round(decimal.Parse(Convert.ToString(reader["SUMTTLAMOUNT"])), 2, MidpointRounding.AwayFromZero) + "\",INPUTBY:\"" + Convert.ToString(reader["INPUTBY"]) + "\"";
//OBJNAME, OBJNUM, ACCATTRIBUTE, ACCNAME, DC, ACCDATE, ACCTYPE
//evList += "OBJNAME:\"" + Convert.ToString(reader["OBJNAME"]) + "\",OBJNUM:\"" + Convert.ToString(reader["OBJNUM"]) + "\",ACCATTRIBUTE:\"" + Convert.ToString(reader["ACCATTRIBUTE"]) + "\",ACCNAME:\"" + Convert.ToString(reader["ACCNAME"]) + "\",DC:\"" + Convert.ToString(reader["DC"]) + "\",ACCDATE:\"" + Convert.ToString(reader["ACCDATE"]) + "\",ACCTYPE:\"" + Convert.ToString(reader["ACCTYPE"]) + "\"";
evList += "VOUDATE:\"" + Convert.ToString(reader["VOUDATE"]) + "\",VKNO:\"" + Convert.ToString(reader["VKNO"]) + "\",VOUNO:\"" + Convert.ToString(reader["VOUNO"]) + "\",EXPLAN:\"" + Convert.ToString(reader["EXPLAN"]) + "\",DR:\"" + Convert.ToString(reader["DR"]) + "\",CR:\"" + Convert.ToString(reader["CR"]) + "\",DC:\"" + Convert.ToString(reader["DC"]) + "\"";
evList += "},";
i = i + 1;
}
reader.Close();
}
evList = evList.Substring(0, evList.Length - 1);
evList += "]";
return evList;
}
}
}