|
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DSWeb.MvcShipping.Models.RptCwVouchersGl;
|
|
|
|
|
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.RptCwVouchersGlDAL
|
|
|
|
|
{
|
|
|
|
|
public class RptCwVouchersGlDAL
|
|
|
|
|
{
|
|
|
|
|
#region 查询
|
|
|
|
|
static public List<RptCwVouchersGl> GetDataList(string strCondition, string strCbZKM, string VOUDATEbgn, string userid, string companyid, string sort = null)
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
string sSql = GetDataListSQL(strCondition, strCbZKM, VOUDATEbgn, userid, companyid);
|
|
|
|
|
strSql.Append(sSql);
|
|
|
|
|
//
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" order by ACCID,ACCNAME");
|
|
|
|
|
}
|
|
|
|
|
return SetData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public List<RptCwVouchersGl> GetDataSumList(string strCondition, string strCbZKM, string VOUDATEbgn, string userid, string companyid)
|
|
|
|
|
{
|
|
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("select '合计:' as [GID],'' as [ACCID],'' as [ACCNAME],'' as [ACCGID],'' as [PACCGID],isnull(sum(DR),0) as [DR],isnull(sum(CR),0) as [CR],'' as CREATEUSER, '' as CORPID,'" + strCwSTARTGID + "' as STARTGID from [cw_vouitems_gl_rpt_temp] where STARTGID='" + strCwSTARTGID + "' and CREATEUSER='" + userid + "' and CORPID='" + companyid + "' and (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY')");
|
|
|
|
|
return SetData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<RptCwVouchersGl> SetData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var headList = new List<RptCwVouchersGl>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
RptCwVouchersGl data = new RptCwVouchersGl();
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
|
|
|
|
|
data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]));//科目编码
|
|
|
|
|
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]));//科目名称
|
|
|
|
|
data.DR = (reader["DR"] == null ? 0 : Convert.ToDecimal(reader["DR"]));//借方
|
|
|
|
|
data.CR = (reader["CR"] == null ? 0 : Convert.ToDecimal(reader["CR"]));//贷方
|
|
|
|
|
//data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司代码
|
|
|
|
|
data.STARTGID = (reader["STARTGID"] == null ? "" : Convert.ToString(reader["STARTGID"]));
|
|
|
|
|
#endregion
|
|
|
|
|
headList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
return headList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public string GetDataListStr(string strCondition, string strCbZKM, string VOUDATEbgn, string userid, string companyid)
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
string sSql = GetDataListSQL(strCondition, strCbZKM, VOUDATEbgn, userid, companyid);
|
|
|
|
|
strSql.Append(sSql);
|
|
|
|
|
strSql.Append(" order by ACCID,ACCNAME");
|
|
|
|
|
return strSql.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public string GetDataListSQL(string strCondition, string strCbZKM, string VOUDATEbgn, string userid, string companyid)
|
|
|
|
|
{
|
|
|
|
|
#region 基础变量
|
|
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
|
|
string strACCDATE = DateTime.Parse(VOUDATEbgn).ToString("yyyy-MM");
|
|
|
|
|
string strYEAR = DateTime.Parse(VOUDATEbgn).Year.ToString();
|
|
|
|
|
int iState = 0;
|
|
|
|
|
int result = 0;
|
|
|
|
|
//
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{
|
|
|
|
|
strCondition = " and " + strCondition;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 插入临时表_合计到一起的事物(暂时屏蔽)
|
|
|
|
|
/*
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 清理临时表
|
|
|
|
|
String sSql = "delete from [cw_vouitems_gl_rpt_temp] where CREATEUSER='" + userid + "' and CORPID='" + companyid + "'";//STARTGID='" + strCwSTARTGID + "' and
|
|
|
|
|
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
|
|
|
|
|
if (iState < 0)
|
|
|
|
|
{
|
|
|
|
|
result = -3;
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 1.插入【cw_vouitems_gl_rpt_temp】
|
|
|
|
|
sSql = "insert into [cw_vouitems_gl_rpt_temp]([GID],[ACCID],[ACCNAME],[ACCGID],[PACCGID],[DR],[CR],[CREATEUSER],[CORPID],[STARTGID]) "
|
|
|
|
|
+ "select newid() as GID,ACCID,ACCNAME,ACCGID,PACCGID,ISNULL(SUM(DR),0) as DR,ISNULL(SUM(CR),0) as CR, '" + userid + "' as CREATEUSER, '" + companyid + "' as CORPID,'" + strCwSTARTGID + "' as STARTGID from (select ACCID,ACCNAME,ACCGID=(select top 1 gid from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]='" + strYEAR + "'),PACCGID=(select top 1 PACCGID from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),(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 and ISCHECKED=1" + strCondition + ") as a GROUP BY ACCID,ACCNAME,ACCGID,PACCGID";
|
|
|
|
|
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
|
|
|
|
|
if (iState < 0)
|
|
|
|
|
{
|
|
|
|
|
result = -4;
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 查询
|
|
|
|
|
sSql = "select PACCGID from (select ACCID,ACCNAME,ACCGID=(select top 1 gid from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),PACCGID=(select top 1 PACCGID from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),(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 and ISCHECKED=1" + strCondition + ") as a GROUP BY PACCGID";
|
|
|
|
|
DataSet dsVCVVG = T_ALL_DA.GetAllSQL(sSql);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 插入父类合计到【cw_vouitems_gl_rpt_temp】表
|
|
|
|
|
if (dsVCVVG != null)
|
|
|
|
|
{
|
|
|
|
|
if (dsVCVVG.Tables[0].Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < dsVCVVG.Tables[0].Rows.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
string PACCGID = dsVCVVG.Tables[0].Rows[j]["PACCGID"].ToString().Trim();
|
|
|
|
|
//ZC','FZ','GT','QY','CB','SY
|
|
|
|
|
if (PACCGID != "0" && PACCGID != "ZC" && PACCGID != "FZ" && PACCGID != "GT" && PACCGID != "QY" && PACCGID != "CB" && PACCGID != "SY")
|
|
|
|
|
{
|
|
|
|
|
string sSQL = "SELECT GID,ACCID,ACCNAME,DETAILED,DC,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,REMARKS,[YEAR],[MONTH],PACCGID,ACCATTRIBUTE,ISENABLE,ACCTYPE,PACCID=(select top 1 ACCID from [cw_accitems_gl] as a where a.gid=cw_accitems_gl.PACCGID),PACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] as b where b.gid=cw_accitems_gl.PACCGID),gid as [id],ACCID+' '+ACCNAME as [NAME],0 as DR,0 as CR from [cw_accitems_gl] WITH(NOLOCK) where [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' order by [YEAR],ACCID";//=(case when (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY') then '0' else PACCGID end)
|
|
|
|
|
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
|
|
if (ds != null)
|
|
|
|
|
{
|
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
while (PACCGID.Trim() != "")
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (ds.Tables[0].Rows[i]["GID"].ToString().Trim() == PACCGID)
|
|
|
|
|
{
|
|
|
|
|
#region 2.插入【cw_vouitems_gl_rpt_temp】
|
|
|
|
|
sSQL = "insert into [cw_vouitems_gl_rpt_temp]([GID],[ACCID],[ACCNAME],[ACCGID],[PACCGID],[DR],[CR],[CREATEUSER],[CORPID],[STARTGID]) "
|
|
|
|
|
+ "select newid() as GID,'" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "' as ACCID,'" + ds.Tables[0].Rows[i]["ACCNAME"].ToString().Trim() + "' as ACCNAME,'" + ds.Tables[0].Rows[i]["GID"].ToString().Trim() + "' as ACCGID,'" + ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() + "' as PACCGID,ISNULL(SUM(DR),0) as DR,ISNULL(SUM(CR),0) as CR, '" + userid + "' as CREATEUSER, '" + companyid + "' as CORPID,'" + strCwSTARTGID + "' as STARTGID from (select ACCID,ACCNAME,ACCGID=(select top 1 gid from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),PACCGID=(select top 1 PACCGID from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),(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 and ISCHECKED=1" + strCondition + ") as a where (PACCGID='" + PACCGID.Trim() + "' or ACCID like '" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "%') and '" + ds.Tables[0].Rows[i]["GID"].ToString().Trim() + "' not in (select ACCGID from [cw_vouitems_gl_rpt_temp] where CREATEUSER='" + userid + "' and CORPID='" + companyid + "' and STARTGID='" + strCwSTARTGID + "')";
|
|
|
|
|
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
|
|
|
|
|
if (iState < 0)
|
|
|
|
|
{
|
|
|
|
|
result = -5;
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
//
|
|
|
|
|
if (ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "0" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "ZC" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "FZ" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "GT" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "QY" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "CB" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "SY")
|
|
|
|
|
{
|
|
|
|
|
PACCGID = "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PACCGID = ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
result = 1;//状态为1表示删除成功
|
|
|
|
|
sqlTran.Commit();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception execError)
|
|
|
|
|
{
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
result = -6;//插入异常,事务已回滚成功
|
|
|
|
|
throw execError;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SqlHelper.CloseConnection();
|
|
|
|
|
sqlTran.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 子科目插入临时表
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 清理临时表
|
|
|
|
|
String sSql = "delete from [cw_vouitems_gl_rpt_temp] where CREATEUSER='" + userid + "' and CORPID='" + companyid + "'";//STARTGID='" + strCwSTARTGID + "' and
|
|
|
|
|
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
|
|
|
|
|
if (iState < 0)
|
|
|
|
|
{
|
|
|
|
|
result = -3;
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 1.插入【cw_vouitems_gl_rpt_temp】
|
|
|
|
|
sSql = "insert into [cw_vouitems_gl_rpt_temp]([GID],[ACCID],[ACCNAME],[ACCGID],[PACCGID],[DR],[CR],[CREATEUSER],[CORPID],[STARTGID]) "
|
|
|
|
|
+ "select newid() as GID,ACCID,ACCNAME,ACCGID,PACCGID,ISNULL(SUM(DR),0) as DR,ISNULL(SUM(CR),0) as CR, '" + userid + "' as CREATEUSER, '" + companyid + "' as CORPID,'" + strCwSTARTGID + "' as STARTGID from (select ACCID,ACCNAME,ACCGID=(select top 1 gid from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]='" + strYEAR + "'),PACCGID=(select top 1 PACCGID from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),(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 and ISCHECKED=1" + strCondition + ") as a GROUP BY ACCID,ACCNAME,ACCGID,PACCGID";
|
|
|
|
|
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
|
|
|
|
|
if (iState < 0)
|
|
|
|
|
{
|
|
|
|
|
result = -4;
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
result = 1;//状态为1表示删除成功
|
|
|
|
|
sqlTran.Commit();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception execError)
|
|
|
|
|
{
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
result = -6;//插入异常,事务已回滚成功
|
|
|
|
|
throw execError;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SqlHelper.CloseConnection();
|
|
|
|
|
sqlTran.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 插入父类合计到【cw_vouitems_gl_rpt_temp】表
|
|
|
|
|
#region 查询
|
|
|
|
|
string sSql1 = "select PACCGID from (select ACCID,ACCNAME,ACCGID=(select top 1 gid from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),PACCGID=(select top 1 PACCGID from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),(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 and ISCHECKED=1" + strCondition + ") as a GROUP BY PACCGID";
|
|
|
|
|
DataSet dsVCVVG = T_ALL_DA.GetAllSQL(sSql1);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 插入父类合计到【cw_vouitems_gl_rpt_temp】表
|
|
|
|
|
if (dsVCVVG != null)
|
|
|
|
|
{
|
|
|
|
|
if (dsVCVVG.Tables[0].Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < dsVCVVG.Tables[0].Rows.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
string PACCGID = dsVCVVG.Tables[0].Rows[j]["PACCGID"].ToString().Trim();
|
|
|
|
|
//ZC','FZ','GT','QY','CB','SY
|
|
|
|
|
if (PACCGID != "0" && PACCGID != "ZC" && PACCGID != "FZ" && PACCGID != "GT" && PACCGID != "QY" && PACCGID != "CB" && PACCGID != "SY")
|
|
|
|
|
{
|
|
|
|
|
string sSQL = "SELECT GID,ACCID,ACCNAME,DETAILED,DC,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,REMARKS,[YEAR],[MONTH],PACCGID,ACCATTRIBUTE,ISENABLE,ACCTYPE,PACCID=(select top 1 ACCID from [cw_accitems_gl] as a where a.gid=cw_accitems_gl.PACCGID),PACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] as b where b.gid=cw_accitems_gl.PACCGID),gid as [id],ACCID+' '+ACCNAME as [NAME],0 as DR,0 as CR from [cw_accitems_gl] WITH(NOLOCK) where [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' order by [YEAR],ACCID";//=(case when (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY') then '0' else PACCGID end)
|
|
|
|
|
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
|
|
if (ds != null)
|
|
|
|
|
{
|
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
while (PACCGID.Trim() != "")
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (ds.Tables[0].Rows[i]["GID"].ToString().Trim() == PACCGID)
|
|
|
|
|
{
|
|
|
|
|
#region 2.插入【cw_vouitems_gl_rpt_temp】
|
|
|
|
|
sSQL = "insert into [cw_vouitems_gl_rpt_temp]([GID],[ACCID],[ACCNAME],[ACCGID],[PACCGID],[DR],[CR],[CREATEUSER],[CORPID],[STARTGID]) "
|
|
|
|
|
+ "select newid() as GID,'" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "' as ACCID,'" + ds.Tables[0].Rows[i]["ACCNAME"].ToString().Trim() + "' as ACCNAME,'" + ds.Tables[0].Rows[i]["GID"].ToString().Trim() + "' as ACCGID,'" + ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() + "' as PACCGID,ISNULL(SUM(DR),0) as DR,ISNULL(SUM(CR),0) as CR, '" + userid + "' as CREATEUSER, '" + companyid + "' as CORPID,'" + strCwSTARTGID + "' as STARTGID from (select ACCID,ACCNAME,ACCGID=(select top 1 gid from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),PACCGID=(select top 1 PACCGID from cw_accitems_gl WHERE ACCID=VW_cw_vouchers_vouitems_gl.ACCID and [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'),(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 and ISCHECKED=1" + strCondition + ") as a where (PACCGID='" + PACCGID.Trim() + "' or ACCID like '" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "%') and '" + ds.Tables[0].Rows[i]["GID"].ToString().Trim() + "' not in (select ACCGID from [cw_vouitems_gl_rpt_temp] where CREATEUSER='" + userid + "' and CORPID='" + companyid + "' and STARTGID='" + strCwSTARTGID + "')";
|
|
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
|
|
|
|
|
if (!bl)
|
|
|
|
|
{
|
|
|
|
|
result = -5;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
//
|
|
|
|
|
if (ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "0" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "ZC" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "FZ" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "GT" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "QY" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "CB" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "SY")
|
|
|
|
|
{
|
|
|
|
|
PACCGID = "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PACCGID = ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 清理借贷同为0的数据
|
|
|
|
|
string sSql2 = "delete from [cw_vouitems_gl_rpt_temp] where STARTGID='" + strCwSTARTGID + "' and DR=0 and CR=0 and CREATEUSER='" + userid + "' and CORPID='" + companyid + "'";//
|
|
|
|
|
bool bl2 = T_ALL_DA.GetExecuteSqlCommand(sSql2);
|
|
|
|
|
if (!bl2)
|
|
|
|
|
{
|
|
|
|
|
result = -2;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 插入临时表——合计行
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 1.插入【cw_vouitems_gl_rpt_temp】
|
|
|
|
|
string sSql = "insert into [cw_vouitems_gl_rpt_temp]([GID],[ACCID],[ACCNAME],[ACCGID],[PACCGID],[DR],[CR],[CREATEUSER],[CORPID],[STARTGID]) "
|
|
|
|
|
+ "(select newid() as [GID],'合计:' as [ACCID],'' as [ACCNAME],'' as [ACCGID],'' as [PACCGID],isnull(sum(DR),0) as [DR],isnull(sum(CR),0) as [CR],'" + userid + "' as CREATEUSER, '" + companyid + "' as CORPID,'" + strCwSTARTGID + "' as STARTGID from [cw_vouitems_gl_rpt_temp] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and CREATEUSER='" + userid + "' and CORPID='" + companyid + "' and (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY'))";
|
|
|
|
|
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
|
|
|
|
|
if (iState < 0)
|
|
|
|
|
{
|
|
|
|
|
result = -7;
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
result = 1;//状态为1表示删除成功
|
|
|
|
|
sqlTran.Commit();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception execError)
|
|
|
|
|
{
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
result = -8;//插入异常,事务已回滚成功
|
|
|
|
|
throw execError;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SqlHelper.CloseConnection();
|
|
|
|
|
sqlTran.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 从临时表中提取数据列表,并返回js页面
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT * from [cw_vouitems_gl_rpt_temp] where STARTGID='" + strCwSTARTGID + "' and CREATEUSER='" + userid + "' and CORPID='" + companyid + "' and (ACCID='合计:'" + strCbZKM + ")");
|
|
|
|
|
#endregion
|
|
|
|
|
return strSql.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public String GetData(string strUserID)
|
|
|
|
|
{
|
|
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
|
|
string strCwSTARTNAME = BasicDataRefDAL.GetCwSTARTNAME(strUserID);
|
|
|
|
|
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
|
|
|
|
|
//
|
|
|
|
|
DateTime d1 = DateTime.Parse(strCwACCDATE + "-01");
|
|
|
|
|
DateTime d2 = d1.AddMonths(1).AddDays(-1);
|
|
|
|
|
string sYEAR = d2.Year.ToString();
|
|
|
|
|
string sMonth = d2.Month.ToString();
|
|
|
|
|
if (sMonth.Length == 1)
|
|
|
|
|
{
|
|
|
|
|
sMonth = "0" + sMonth;
|
|
|
|
|
}
|
|
|
|
|
string sDay = d2.Day.ToString();
|
|
|
|
|
string s1 = sYEAR + "-" + sMonth + "-01";
|
|
|
|
|
string s2 = sYEAR + "-" + sMonth + "-" + sDay;
|
|
|
|
|
//
|
|
|
|
|
return strCwSTARTGID + "&" + strCwSTARTNAME + "&" + strCwACCDATE + "&" + strCwACCDATE.Substring(0, 4) + "&" + strCwACCDATE.Substring(5, 2) + "&" + s1 + "&" + s2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public String getlbTitle(string strCondition, string strCbZKM, string VOUDATEbgn, string strUserID)
|
|
|
|
|
{
|
|
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{
|
|
|
|
|
strCondition = " and " + strCondition;
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
|
|
string sSql = "select count(VOUALLNO) as inum from (select VOUALLNO from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and ISDELETE=0 and ISCHECKED=1" + strCondition + " group by VOUALLNO) as a";
|
|
|
|
|
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSql));
|
|
|
|
|
sSql = "select isnull(sum(ATTACHS),0) as inum from (select VOUALLNO,ATTACHS from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and ISDELETE=0 and ISCHECKED=1" + strCondition + " group by VOUALLNO,ATTACHS) as a";
|
|
|
|
|
int inum2 = int.Parse(T_ALL_DA.GetStrSQL("inum", sSql));
|
|
|
|
|
//
|
|
|
|
|
return "【凭证数:" + inum + " 张,附件数:" + inum2 + " 张】";
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|