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.

1249 lines
92 KiB
C#

10 months ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.DAL.MsCtInitialBalanceDAL;
using DSWeb.MvcShipping.Models.MsCtBankJournal;
using DSWeb.MvcShipping.Models.RptCtGenlegAccitems;
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.MsCtBankJournalDAL
{
public class MsCtBankJournalDAL
{
#region 查询主表
static public List<MsCtBankJournal> GetDataList2(string strCondition, string userid, string usercode, string companyid,string sort = null)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("SELECT *,CREATEUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.CREATEUSER),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.MODIFIEDUSER),ACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=ct_bank_journal.ACCGID),SETTLETYPENAME=isnull((select top 1 STLNAME from [code_stlmode] where STLCODE=ct_bank_journal.SETTLETYPE),''),ISCHECKING=(case when CHECKINGGID='' then '' else (case when CHECKINGGID like 'auto%' then '*' else '**' end) end) from ct_bank_journal WITH(NOLOCK) where STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by VOUDATE desc,convert(decimal(10),ITEMNO) desc");
}
return SetData(strSql);
}
static public MsCtBankJournal GetData(string condition, string companyid, string strUserID)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(strUserID);
var strSql = new StringBuilder();
strSql.Append("SELECT *,CREATEUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.CREATEUSER),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.MODIFIEDUSER),ACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=ct_bank_journal.ACCGID),SETTLETYPENAME=isnull((select top 1 STLNAME from [code_stlmode] where STLCODE=ct_bank_journal.SETTLETYPE),''),ISCHECKING=(case when CHECKINGGID='' then '' else (case when CHECKINGGID like 'auto%' then '*' else '**' end) end) from ct_bank_journal WITH(NOLOCK) where STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsCtBankJournal();
}
private static List<MsCtBankJournal> SetData(StringBuilder strSql)
{
var headList = new List<MsCtBankJournal>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCtBankJournal data = new MsCtBankJournal();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//惟一值
data.ACCGID = (reader["ACCGID"] == null ? "" : Convert.ToString(reader["ACCGID"]));//科目GID
data.FCYNO = (reader["FCYNO"] == null ? "" : Convert.ToString(reader["FCYNO"]));//外币编号usd
//data.VOUDATE = (reader["VOUDATE"] == null ? "" : Convert.ToString(reader["VOUDATE"]));//凭证日期
if (reader["VOUDATE"] != null && reader["VOUDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["VOUDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["VOUDATE"].ToString().Trim() != "")
{
data.VOUDATE = Convert.ToDateTime(reader["VOUDATE"]);//凭证日期
}
data.ITEMNO = (reader["ITEMNO"] == null ? 0 : Convert.ToInt32(reader["ITEMNO"]));//当日序号
data.VGID = (reader["VGID"] == null ? "" : Convert.ToString(reader["VGID"]));//凭证明细GID
data.VKNO = (reader["VKNO"] == null ? "" : Convert.ToString(reader["VKNO"]));//凭证字
data.VOUNO = (reader["VOUNO"] == null ? "" : Convert.ToString(reader["VOUNO"]));//凭证号
data.FENTRYID = (reader["FENTRYID"] == null ? 0 : Convert.ToInt32(reader["FENTRYID"]));//分录号
data.ACCDATE = (reader["ACCDATE"] == null ? "" : Convert.ToString(reader["ACCDATE"]));//会计期间
data.SETTLETYPE = (reader["SETTLETYPE"] == null ? 0 : Convert.ToInt32(reader["SETTLETYPE"]));//结算方式
data.BILLNO = (reader["BILLNO"] == null ? "" : Convert.ToString(reader["BILLNO"]));//结算号
//data.SVOUDATE = (reader["SVOUDATE"] == null ? "" : Convert.ToString(reader["SVOUDATE"]));//结算日期
if (reader["SVOUDATE"] != null && reader["SVOUDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["SVOUDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["SVOUDATE"].ToString().Trim() != "")
{
data.SVOUDATE = Convert.ToDateTime(reader["SVOUDATE"]);//结算日期
}
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]));//借贷方向
data.DR = (reader["DR"] == null ? 0 : Convert.ToDecimal(reader["DR"]));//原币借方金额(互斥)
data.CR = (reader["CR"] == null ? 0 : Convert.ToDecimal(reader["CR"]));//原币贷方金额(互斥)
data.FCYEXRATE = (reader["FCYEXRATE"] == null ? 0 : Convert.ToDecimal(reader["FCYEXRATE"]));//汇率
data.QTYDR = (reader["QTYDR"] == null ? 0 : Convert.ToDecimal(reader["QTYDR"]));//折合本位币借方
data.QTYCR = (reader["QTYCR"] == null ? 0 : Convert.ToDecimal(reader["QTYCR"]));//折合本位币贷方
data.BLC = (reader["BLC"] == null ? 0 : Convert.ToDecimal(reader["BLC"]));//原币余额
data.EXPLAN = (reader["EXPLAN"] == null ? "" : Convert.ToString(reader["EXPLAN"]));//摘要,规则生成
data.ENTERED = (reader["ENTERED"] == null ? "" : Convert.ToString(reader["ENTERED"]));//经手人
data.ISINITIAL = (reader["ISINITIAL"] == null ? false : Convert.ToBoolean(reader["ISINITIAL"]));//是否期初
data.CHECKINGGID = (reader["CHECKINGGID"] == null ? "" : Convert.ToString(reader["CHECKINGGID"]));//对账GID
data.STARTGID = (reader["STARTGID"] == null ? "" : Convert.ToString(reader["STARTGID"]));//账套启用GID
data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司GID
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//制单人GID
if (reader["CREATETIME"] != null && reader["CREATETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CREATETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CREATETIME"].ToString().Trim() != "")
{
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
}
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//最后一次更改操作人GID
if (reader["MODIFIEDTIME"] != null && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME"].ToString().Trim() != "")
{
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更改操作时间
}
data.SETTLETYPENAME = (reader["SETTLETYPENAME"] == null ? "" : Convert.ToString(reader["SETTLETYPENAME"]));//结算方式
data.CREATEUSERNAME = (reader["CREATEUSERNAME"] == null ? "" : Convert.ToString(reader["CREATEUSERNAME"]));//制单人
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//最后一次更改操作人
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]));//科目
data.ISCHECKING = (reader["ISCHECKING"] == null ? "" : Convert.ToString(reader["ISCHECKING"]));//对账状态
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<MsCtBankJournal> GetDataList(string strCondition, string strCondition3, string userid, string usercode, string companyid, string sort = null)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("( ");
strSql.Append("SELECT *,CREATEUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.CREATEUSER),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.MODIFIEDUSER),ACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=ct_bank_journal.ACCGID),SETTLETYPENAME=(select top 1 STLNAME from [code_stlmode] where STLCODE=ct_bank_journal.SETTLETYPE),ISCHECKING=(case when CHECKINGGID='' then '' else (case when CHECKINGGID like 'auto%' then '*' else '**' end) end),linenum=1,convert(decimal(10),ITEMNO) as ITEMNO1 from ct_bank_journal WITH(NOLOCK) where ISINITIAL=0 and STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(") union (");
//本日合计
strSql.Append("select newid() as GID,'','',VOUDATE,0 as ITEMNO,'','','',0,'','','','',DC=(case when isnull(SUM(BLC),0)<0 then '贷' else '借' end),DR=isnull(SUM(DR),0),CR=isnull(SUM(CR),0),1,QTYDR=0,QTYCR=0,BLC,'本日合计' as EXPLAN,'','','','','','','','','','','','','','',2 as linenum,'0' as ITEMNO1 ");
strSql.Append("from (select newid() as GID,VOUDATE,DR=isnull(DR,0),CR=isnull(CR,0),QTYDR=0,QTYCR=0,BLC=isnull((SELECT top 1 (CASE WHEN CURRENCY='RMB' THEN AMTLASTBLC ELSE FCYLASTBLC END) as BLC from ct_genleg_accitems WITH(NOLOCK) WHERE STARTGID='" + strCtSTARTGID + "' AND ([YEAR]+'-'+[MONTH]+'-'+[DAY])=convert(varchar,ct_bank_journal.VOUDATE,23)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition.Trim().Replace("FCYNO", "CURRENCY").Replace("ACCGID", "LINKGID").Replace("ACCDATE", "([YEAR]+'-'+[MONTH])").Replace("VOUDATE", "([YEAR]+'-'+[MONTH]+'-'+[DAY])"));
}
strSql.Append(" ORDER by [YEAR] desc,[MONTH] desc,[DAY] desc),0) from ct_bank_journal WITH(NOLOCK) where ISINITIAL=0 and STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(") as als group by VOUDATE,BLC");
strSql.Append(") union (");
//本期合计
strSql.Append("select newid() as GID,'','',VOUDATE,0 as ITEMNO,'','','',0,'','','','',DC=(case when isnull(SUM(BLC),0)<0 then '贷' else '借' end),DR=isnull(SUM(DR),0),CR=isnull(SUM(CR),0),1,QTYDR=0,QTYCR=0,BLC,EXPLAN='本期合计','','','','','','','','','','','','','','',linenum=3,'0' as ITEMNO1 from (");
strSql.Append("select newid() as GID,(ACCDATE+'-'+CONVERT(nvarchar(2), DATEDIFF(day,(ACCDATE+'-01'),DATEADD(month,1,(ACCDATE+'-01'))))) as VOUDATE,DR=isnull(DR,0),CR=isnull(CR,0),QTYDR=0,QTYCR=0,BLC=isnull((SELECT top 1 (CASE WHEN CURRENCY='RMB' THEN AMTLASTBLC ELSE FCYLASTBLC END) as BLC from ct_genleg_accitems WHERE STARTGID='" + strCtSTARTGID + "' AND ([YEAR]+'-'+[MONTH])=ct_bank_journal.ACCDATE");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition.Trim().Replace("FCYNO", "CURRENCY").Replace("ACCGID", "LINKGID").Replace("ACCDATE", "([YEAR]+'-'+[MONTH])").Replace("VOUDATE", "([YEAR]+'-'+[MONTH]+'-'+[DAY])"));
}
strSql.Append(" ORDER by [YEAR] desc,[MONTH] desc,[DAY] desc),0) from ct_bank_journal WITH(NOLOCK) where ISINITIAL=0 and STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(") as bls group by VOUDATE,BLC");
strSql.Append(") union (");
//合计
strSql.Append("select newid() as GID,'','','9999-12-31 00:00:00.000',0,'','','',0,'','','','',DC=(case when BLC<0 then '贷' else '借' end),DR=isnull(SUM(DR),0),CR=isnull(SUM(CR),0),1,QTYDR=0,QTYCR=0,BLC,EXPLAN='合计','','','','','','','','','','','','','','',linenum=4,'0' as ITEMNO1 from (");
strSql.Append("select newid() as GID,DR=isnull(DR,0),CR=isnull(CR,0),QTYDR=0,QTYCR=0,BLC=isnull((SELECT top 1 (CASE WHEN CURRENCY='RMB' THEN AMTLASTBLC ELSE FCYLASTBLC END) as BLC from ct_genleg_accitems WITH(NOLOCK) WHERE STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition.Trim().Replace("FCYNO", "CURRENCY").Replace("ACCGID", "LINKGID").Replace("ACCDATE", "([YEAR]+'-'+[MONTH])").Replace("VOUDATE", "([YEAR]+'-'+[MONTH]+'-'+[DAY])"));
}
strSql.Append(" ORDER by [YEAR] desc,[MONTH] desc,[DAY] desc),0) from ct_bank_journal WITH(NOLOCK) where ISINITIAL=0 and STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(") as bls group by BLC");
strSql.Append(") union (");
//期初余额
strSql.Append("select top 1 GID,'','','' as VOUDATE,0,'','','',0,'','','','',DC=(case when (case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end)<0 then '贷' else '借' end),DR=0,CR=0,1,QTYDR=0,QTYCR=0,BLC=isnull((case when (case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end)<0 then -(case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end) else (case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end) end),0),EXPLAN='(期初余额)','','','','','','','','','','','','','','',linenum=0,'0' as ITEMNO1 from ct_genleg_accitems WITH(NOLOCK) where STARTGID='" + strCtSTARTGID + "'");
if (!string.IsNullOrEmpty(strCondition3))
{
strSql.Append(" and " + strCondition3);
}
strSql.Append(" and DAY='01' )");
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by VOUDATE,linenum,ITEMNO1");
}
return SetData(strSql);
}
#endregion
#region 查询明细表
static public List<MsCtBankJournal> GetDetailList(string strCondition, string userid, string usercode, string companyid)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
//
string sSQL = "select top 1 ACCDAY from ct_carry_over where STARTGID='" + sCtSTARTGID.Trim() + "' order by STARTGID,ACCDAY desc";
string sACCDAY = T_ALL_DA.GetStrSQL("ACCDAY", sSQL);
if (sACCDAY != "")
{
sACCDAY = DateTime.Parse(sACCDAY).ToString("yyyy-MM-dd");
sACCDAY = " and VOUDATE>'" + sACCDAY + "'";
}
//
var strSql = new StringBuilder();
strSql.Append("SELECT *,CREATEUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.CREATEUSER),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.MODIFIEDUSER),ACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=ct_bank_journal.ACCGID),SETTLETYPENAME=isnull((select top 1 STLNAME from [code_stlmode] where STLCODE=ct_bank_journal.SETTLETYPE),''),ISCHECKING=(case when CHECKINGGID='' then '' else (case when CHECKINGGID like 'auto%' then '*' else '**' end) end) from ct_bank_journal WITH(NOLOCK) where STARTGID='" + sCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null)" + sACCDAY);
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by VOUDATE,convert(decimal(10),ITEMNO)");
return SetData(strSql);
}
#endregion
#region 返回出纳当前账套和会计期间
public static string GetInitData(string isInitial, string strCompanyID, string strUserID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(strUserID);
if (strCtSTARTGID == "")
{
return "-1";
}
string sSTARTMONTH = T_ALL_DA.GetStrSQL("STARTMONTH", "select top 1 STARTMONTH from ct_design_startusing WITH(NOLOCK) where gid='" + strCtSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
string strACCDATE = BasicDataRefDAL.GetCtACCDATE(strUserID);
if (strACCDATE == "")
{
return "-1";
}
//
if (isInitial=="1")
{
string strACCDAY = DateTime.Parse(sSTARTMONTH + "-01").AddDays(-1).ToString("yyyy-MM-dd");
sSTARTMONTH = strACCDAY.Substring(0, 7);
string strACCTODAY = sSTARTMONTH + "-" + DateTime.Now.Day.ToString();
return strCtSTARTGID + "" + sSTARTMONTH + "" + strACCDAY + "" + strACCTODAY;
}
else
{
string strACCDAY = DateTime.Parse(strACCDATE + "-01").AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
string strACCTODAY = strACCDATE + "-" + DateTime.Now.Day.ToString();
return strCtSTARTGID + "" + strACCDATE + "" + strACCDAY + "" + strACCTODAY;
}
}
#endregion
#region 更新科目总账表ct_genleg_accitems
public static void onCtGenlegAccitems(MsCtBankJournal headRow, string companyid, string userid)
{
#region 默认值
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sYear = headRow.VOUDATE.Year.ToString();
string sMonth = headRow.VOUDATE.Month.ToString();
if (sMonth.Trim().Length == 1)
{
sMonth = "0" + sMonth;
}
string sDay = headRow.VOUDATE.Day.ToString();
if (sDay.Trim().Length == 1)
{
sDay = "0" + sDay;
}
string sYear2 = headRow.VOUDATE.AddDays(1).Year.ToString();
string sMonth2 = headRow.VOUDATE.AddDays(1).Month.ToString();
if (sMonth2.Trim().Length == 1)
{
sMonth2 = "0" + sMonth2;
}
string sDay2 = headRow.VOUDATE.AddDays(1).Day.ToString();
if (sDay2.Trim().Length == 1)
{
sDay2 = "0" + sDay2;
}
string strCtACCDATE = BasicDataRefDAL.GetCtACCDATE(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
string sSQL = "select DC from cw_accitems_gl where STARTGID='" + strCtSTARTGID + "' AND GID='" + headRow.ACCGID.ToString() + "'";
string ACCDC = T_ALL_DA.GetStrSQL("DC", sSQL);
sSQL = "select top 1 GID from ct_genleg_accitems WITH(NOLOCK) WHERE STARTGID='" + strCtSTARTGID + "' AND YEAR='" + sYear + "' and MONTH='" + sMonth + "' and DAY='" + sDay + "' and LINKGID='" + headRow.ACCGID.ToString() + "' and CURRENCY='" + headRow.FCYNO.ToString() + "'";
string sGID = T_ALL_DA.GetStrSQL("GID", sSQL);
sSQL = "select top 1 GID from ct_genleg_accitems WITH(NOLOCK) WHERE STARTGID='" + strCtSTARTGID + "' AND YEAR='" + sYear2 + "' and MONTH='" + sMonth2 + "' and DAY='" + sDay2 + "' and LINKGID='" + headRow.ACCGID.ToString() + "' and CURRENCY='" + headRow.FCYNO.ToString() + "'";
string sGID2 = T_ALL_DA.GetStrSQL("GID", sSQL);
sSQL = "select top 1 * from ct_genleg_accitems WITH(NOLOCK) WHERE STARTGID='" + strCtSTARTGID + "' AND LINKGID='" + headRow.ACCGID.ToString() + "' and CURRENCY='" + headRow.FCYNO.ToString() + "' and convert(varchar,([Year] + '-' + [Month] + '-' + [Day]),23)<'" + headRow.VOUDATE.ToString("yyyy-MM-dd") + "' order by [YEAR] desc,[MONTH] desc,[DAY] desc";
DataSet dsCtGenlegAccitems = T_ALL_DA.GetAllSQL(sSQL);
#endregion
#region 当日总账表
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (sGID.Trim() == "")
{
#region 插入当日总账表
sSQL = "INSERT INTO [ct_genleg_accitems]([GID],[YEAR],[MONTH],[DAY],[LINKGID],[CURRENCY],[AMTYEARDR],[AMTYEARCR],[AMTYEARBLC],[AMTDR],[AMTCR],[AMTBLC],[AMTLASTDR],[AMTLASTCR],[AMTLASTBLC],[FCYYEARDR],[FCYYEARCR],[FCYYEARBLC],[FCYDR],[FCYCR],[FCYBLC],[FCYLASTDR],[FCYLASTCR],[FCYLASTBLC],[QTYYEARDR],[QTYYEARCR],[QTYYEARBLC],[QTYDR],[QTYCR],[QTYBLC],[QTYLASTDR],[QTYLASTCR],[QTYLASTBLC],[IsInitialEntry],[CORPID],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME],[ACCDATE],[STARTGID])"
+ " select NEWID() as GID,'" + sYear + "' as [YEAR],'" + sMonth + "' as [MONTH],'" + sDay + "' as [DAY],'" + headRow.ACCGID.ToString() + "' as [LINKGID],'" + headRow.FCYNO.ToString() + "' as [CURRENCY]";
#region 判断是否有之前数据余额
if (dsCtGenlegAccitems!=null)
{
if(dsCtGenlegAccitems.Tables[0].Rows.Count>0)
{
sSQL += ",AMTYEARDR=" + (ACCDC=="借" ? dsCtGenlegAccitems.Tables[0].Rows[0]["AMTLASTBLC"].ToString() : "0")
+ ",AMTYEARCR=" + (ACCDC == "贷" ? dsCtGenlegAccitems.Tables[0].Rows[0]["AMTLASTBLC"].ToString() : "0")
+ ",AMTYEARBLC=" + dsCtGenlegAccitems.Tables[0].Rows[0]["AMTLASTBLC"].ToString()
+ ",AMTDR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end)"
+ ",AMTCR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end)"
+ ",AMTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",AMTLASTDR=" + (ACCDC == "借" ? dsCtGenlegAccitems.Tables[0].Rows[0]["AMTLASTBLC"].ToString() : "0") + "+(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end)"
+ ",AMTLASTCR=" + (ACCDC == "贷" ? dsCtGenlegAccitems.Tables[0].Rows[0]["AMTLASTBLC"].ToString() : "0") + "+(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end)"
+ ",AMTLASTBLC=" + dsCtGenlegAccitems.Tables[0].Rows[0]["AMTLASTBLC"].ToString() + "+(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",FCYYEARDR=" + (ACCDC == "借" ? dsCtGenlegAccitems.Tables[0].Rows[0]["FCYLASTBLC"].ToString() : "0")
+ ",FCYYEARCR=" + (ACCDC == "贷" ? dsCtGenlegAccitems.Tables[0].Rows[0]["FCYLASTBLC"].ToString() : "0")
+ ",FCYYEARBLC=" + dsCtGenlegAccitems.Tables[0].Rows[0]["FCYLASTBLC"].ToString()
+ ",FCYDR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end)"
+ ",FCYCR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end)"
+ ",FCYBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",FCYLASTDR=" + (ACCDC == "借" ? dsCtGenlegAccitems.Tables[0].Rows[0]["FCYLASTBLC"].ToString() : "0") + "+(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end)"
+ ",FCYLASTCR=" + (ACCDC == "贷" ? dsCtGenlegAccitems.Tables[0].Rows[0]["FCYLASTBLC"].ToString() : "0") + "+(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end)"
+ ",FCYLASTBLC=" + dsCtGenlegAccitems.Tables[0].Rows[0]["FCYLASTBLC"].ToString() + "+(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",QTYYEARDR=" + (ACCDC == "借" ? dsCtGenlegAccitems.Tables[0].Rows[0]["QTYLASTBLC"].ToString() : "0")
+ ",QTYYEARCR=" + (ACCDC == "贷" ? dsCtGenlegAccitems.Tables[0].Rows[0]["QTYLASTBLC"].ToString() : "0")
+ ",QTYYEARBLC=" + dsCtGenlegAccitems.Tables[0].Rows[0]["QTYLASTBLC"].ToString()
+ ",QTYDR=isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)"
+ ",QTYCR=isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)"
+ ",QTYBLC=(case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end)"
+ ",QTYLASTDR=" + (ACCDC == "借" ? dsCtGenlegAccitems.Tables[0].Rows[0]["QTYLASTBLC"].ToString() : "0") + "+isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)"
+ ",QTYLASTCR=" + (ACCDC == "贷" ? dsCtGenlegAccitems.Tables[0].Rows[0]["QTYLASTBLC"].ToString() : "0") + "+isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)"
+ ",QTYLASTBLC=" + dsCtGenlegAccitems.Tables[0].Rows[0]["QTYLASTBLC"].ToString() + "+(case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end)";
}
else
{
sSQL += ",AMTYEARDR=0,AMTYEARCR=0,AMTYEARBLC=0"
+ ",AMTDR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end)"
+ ",AMTCR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end)"
+ ",AMTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",AMTLASTDR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end)"
+ ",AMTLASTCR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end)"
+ ",AMTLASTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",FCYYEARDR=0,FCYYEARCR=0,FCYYEARBLC=0"
+ ",FCYDR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end)"
+ ",FCYCR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end)"
+ ",FCYBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",FCYLASTDR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end)"
+ ",FCYLASTCR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end)"
+ ",FCYLASTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",QTYYEARDR=0,QTYYEARCR=0,QTYYEARBLC=0"
+ ",QTYDR=isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)"
+ ",QTYCR=isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)"
+ ",QTYBLC=(case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end)"
+ ",QTYLASTDR=isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)"
+ ",QTYLASTCR=isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)"
+ ",QTYLASTBLC=(case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end)";
}
}
else
{
sSQL += ",AMTYEARDR=0,AMTYEARCR=0,AMTYEARBLC=0"
+ ",AMTDR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end)"
+ ",AMTCR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end)"
+ ",AMTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",AMTLASTDR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end)"
+ ",AMTLASTCR=(case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end)"
+ ",AMTLASTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",FCYYEARDR=0,FCYYEARCR=0,FCYYEARBLC=0"
+ ",FCYDR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end)"
+ ",FCYCR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end)"
+ ",FCYBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",FCYLASTDR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end)"
+ ",FCYLASTCR=(case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end)"
+ ",FCYLASTBLC=(case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end)"
+ ",QTYYEARDR=0,QTYYEARCR=0,QTYYEARBLC=0"
+ ",QTYDR=isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)"
+ ",QTYCR=isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)"
+ ",QTYBLC=(case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end)"
+ ",QTYLASTDR=isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)"
+ ",QTYLASTCR=isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)"
+ ",QTYLASTBLC=(case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end)";
}
#endregion
sSQL += ",0 as IsInitialEntry,'" + companyid + "' as CORPID,'" + userid + "' as CREATEUSER,getdate() as CREATETIME,'" + userid + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'" + sYear + "-" + sMonth + "' as ACCDATE,'" + strCtSTARTGID + "' as STARTGID"
+ " FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0";
#endregion
var cmdSql = db.GetSqlStringCommand(sSQL);
db.ExecuteNonQuery(cmdSql, tran);
}
else//edit
{
#region 更新当日总账表
sSQL = "update [ct_genleg_accitems] set"
+ " AMTDR=(select (case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",AMTCR=(select (case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",AMTBLC=(select (case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",AMTLASTDR=AMTYEARDR+(select (case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(DR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",AMTLASTCR=AMTYEARCR+(select (case when '" + headRow.FCYNO.ToString() + "'='RMB' then isnull(sum(CR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",AMTLASTBLC=AMTYEARBLC+(select (case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",FCYDR=(select (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",FCYCR=(select (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",FCYBLC=(select (case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",FCYLASTDR=FCYYEARDR+(select (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(DR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",FCYLASTCR=FCYYEARCR+(select (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then isnull(sum(CR),0) else 0 end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",FCYLASTBLC=FCYYEARBLC+(select (case when '" + ACCDC + "'='借' then (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else 0 end) else (case when '" + headRow.FCYNO.ToString() + "'<>'RMB' then (isnull(sum(CR),0)-isnull(sum(DR),0)) else 0 end) end) FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",QTYDR=(select isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0) as QTYDR FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",QTYCR=(select isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0) as QTYCR FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",QTYBLC=(select (case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end) as QTYBLC FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",QTYLASTDR=QTYYEARDR+(select isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0) as QTYDR FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",QTYLASTCR=QTYYEARCR+(select isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0) as QTYCR FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",QTYLASTBLC=QTYYEARBLC+(select (case when '" + ACCDC + "'='借' then (isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)) else (isnull(sum(Convert(decimal(18,2),(CR*FCYEXRATE))),0)-isnull(sum(Convert(decimal(18,2),(DR*FCYEXRATE))),0)) end) as QTYBLC FROM ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0)"
+ ",[MODIFIEDUSER]='" + userid + "',[MODIFIEDTIME]=getdate() where STARTGID='" + strCtSTARTGID + "' and GID='" + sGID + "'";
#endregion
var cmdSql = db.GetSqlStringCommand(sSQL);
db.ExecuteNonQuery(cmdSql, tran);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
#endregion
#region 今日父类总账表
MsCtInitialBalanceDAL.MsCtInitialBalanceDAL.SaveRow(headRow.ACCGID.ToString(), headRow.FCYNO.ToString(), headRow.VOUDATE.ToString("yyyy-MM-dd"), strCtSTARTGID, false, companyid, userid);
#endregion
#region 明日总账表
MsCtInitialBalanceDAL.MsCtInitialBalanceDAL.onCtGenlegAccitemsFor(headRow.ACCGID.ToString(), headRow.FCYNO.ToString(), headRow.VOUDATE.ToString("yyyy-MM-dd"), strCtSTARTGID, strCtACCDATE, companyid, userid);
#endregion
}
#endregion
#region 插入更新余额
public static void onBLC(MsCtBankJournal headRow, bool isHJ, string companyid, string userid)
{
#region 默认值
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "select DC from cw_accitems_gl where GID='" + headRow.ACCGID.ToString() + "'";
string ACCDC = T_ALL_DA.GetStrSQL("DC", sSQL);
//本期期初数
string sSQL2 = "select top 1 GID,LINKGID as ACCGID,CURRENCY as FCYNO,([YEAR]+'-'+[MONTH]+'-'+[DAY]) as VOUDATE,0 as ITEMNO,'' as VGID,'' as VKNO,'' as VOUNO,'' as FENTRYID,([YEAR]+'-'+[MONTH]) as ACCDATE,'' as SETTLETYPE,'' as BILLNO,([YEAR]+'-'+[MONTH]+'-'+[DAY]) as SVOUDATE"
+ ",DC=(case when (case when CURRENCY='RMB' then AMTLASTBLC else FCYLASTBLC end)<0 then '贷' else '借' end)"
+ ",DR=isnull((case when (case when CURRENCY='RMB' then AMTLASTDR else FCYLASTDR end)<0 then -(case when CURRENCY='RMB' then AMTLASTDR else FCYLASTDR end) else (case when CURRENCY='RMB' then AMTLASTDR else FCYLASTDR end) end),0)"
+ ",CR=isnull((case when (case when CURRENCY='RMB' then AMTLASTCR else FCYLASTCR end)<0 then -(case when CURRENCY='RMB' then AMTLASTCR else FCYLASTCR end) else (case when CURRENCY='RMB' then AMTLASTCR else FCYLASTCR end) end),0)"
+ ",1 as FCYEXRATE,0 as QTYDR,0 as QTYCR"
+ ",BLC=isnull((case when (case when CURRENCY='RMB' then AMTLASTBLC else FCYLASTBLC end)<0 then -(case when CURRENCY='RMB' then AMTLASTBLC else FCYLASTBLC end) else (case when CURRENCY='RMB' then AMTLASTBLC else FCYLASTBLC end) end),0)"
+ ",'' as EXPLAN,'' as ENTERED,0 as ISINITIAL,'' as CHECKINGGID,STARTGID,CORPID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME"
+ " from ct_genleg_accitems WITH(NOLOCK)"
+ " where STARTGID='" + strCtSTARTGID + "' and LINKGID='" + headRow.ACCGID.ToString() + "' and CURRENCY='" + headRow.FCYNO.ToString() + "' and ([YEAR]+'-'+[MONTH])<'" + headRow.VOUDATE.ToString("yyyy-MM") + "' order by ACCDATE desc,VOUDATE desc";
DataSet dsCtGenlegAccitems = T_ALL_DA.GetAllSQL(sSQL2);
Decimal dlCtGenlegAccitemsBLC = 0;
if (dsCtGenlegAccitems != null)
{
dlCtGenlegAccitemsBLC = Decimal.Parse(dsCtGenlegAccitems.Tables[0].Rows[0]["BLC"].ToString());
}
//本期日记账数据
sSQL = "select GID,ACCGID,FCYNO,VOUDATE,ITEMNO,VGID,VKNO,VOUNO,FENTRYID,ACCDATE,SETTLETYPE,BILLNO,SVOUDATE,DC,DR,CR,FCYEXRATE,QTYDR,QTYCR,BLC,EXPLAN,ENTERED,ISINITIAL,CHECKINGGID,STARTGID,CORPID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME from ct_bank_journal WITH(NOLOCK) where STARTGID='" + strCtSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0 and VOUDATE>='" + headRow.VOUDATE.ToString("yyyy-MM") + "-01'"
+ " order by VOUDATE,ITEMNO,VKNO,VOUNO,FENTRYID";
DataSet dsCtBankJournal = T_ALL_DA.GetAllSQL(sSQL);
#endregion
#region 循环更新余额
Decimal dBLC = dlCtGenlegAccitemsBLC;
if (dsCtBankJournal != null)
{
if (dsCtBankJournal.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsCtBankJournal.Tables[0].Rows.Count; i++)
{
if (ACCDC == "借")
{
dBLC = Decimal.Parse((Decimal.Parse(dsCtBankJournal.Tables[0].Rows[i]["DR"].ToString()) - Decimal.Parse(dsCtBankJournal.Tables[0].Rows[i]["CR"].ToString()) + dBLC).ToString("F2"));
}
else
{
dBLC = Decimal.Parse((Decimal.Parse(dsCtBankJournal.Tables[0].Rows[i]["CR"].ToString()) - Decimal.Parse(dsCtBankJournal.Tables[0].Rows[i]["DR"].ToString()) + dBLC).ToString("F2"));
}
//
sSQL = "update [ct_bank_journal] set BLC=" + dBLC + " where gid='" + dsCtBankJournal.Tables[0].Rows[i]["GID"].ToString() + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
}
}
}
#endregion
#region 单个更新余额语句_停用
/*
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
#region 循环更新余额
sSQL = "update [ct_bank_journal] set BLC=("
+ "select (case when '" + headRow.FCYNO.ToString() + "'='RMB' then (case when '" + ACCDC + "'='借' then (isnull(sum(DR),0)-isnull(sum(CR),0)) else (isnull(sum(CR),0)-isnull(sum(DR),0)) end) else 0 end)"
+ " FROM ("
+ "select top 1 GID,LINKGID as ACCGID,CURRENCY as FCYNO,([YEAR]+'-'+[MONTH]+'-'+[DAY]) as VOUDATE,0 as ITEMNO,'' as VGID,'' as VKNO,'' as VOUNO,'' as FENTRYID,([YEAR]+'-'+[MONTH]) as ACCDATE,'' as SETTLETYPE,'' as BILLNO,([YEAR]+'-'+[MONTH]+'-'+[DAY]) as SVOUDATE"
+ ",DC=(case when (case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end)<0 then '贷' else '借' end)"
+ ",DR=isnull((case when (case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end)<0 then -(case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end) else (case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end) end),0)"
+ ",CR=isnull((case when (case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end)<0 then -(case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end) else (case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end) end),0)"
+ ",1 as FCYEXRATE,0 as QTYDR,0 as QTYCR"
+ ",BLC=isnull((case when (case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end)<0 then -(case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end) else (case when CURRENCY='RMB' then AMTYEARBLC else FCYYEARBLC end) end),0)"
+ ",'' as EXPLAN,'' as ENTERED,0 as ISINITIAL,'' as CHECKINGGID,STARTGID,CORPID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME"
+ " from ct_genleg_accitems WITH(NOLOCK)"
+ " where STARTGID='" + strSTARTGID + "' and ([YEAR]+'-'+[MONTH])='" + headRow.VOUDATE.ToString("yyyy-MM") + "' and LINKGID='" + headRow.ACCGID.ToString() + "' and CURRENCY='" + headRow.FCYNO.ToString() + "'"
+ " union "
+ "select GID,ACCGID,FCYNO,VOUDATE,ITEMNO,VGID,VKNO,VOUNO,FENTRYID,ACCDATE,SETTLETYPE,BILLNO,SVOUDATE,DC,DR,CR,FCYEXRATE,QTYDR,QTYCR,BLC,EXPLAN,ENTERED,ISINITIAL,CHECKINGGID,STARTGID,CORPID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME from ct_bank_journal WITH(NOLOCK) where STARTGID='" + strSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0"// and VOUDATE>='" + headRow.VOUDATE.ToString() + "'
+ ") as a where STARTGID='" + strSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and a.ITEMNO<=ct_bank_journal.ITEMNO and a.VOUDATE<=ct_bank_journal.VOUDATE"
+ ") where STARTGID='" + strSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0";// and VOUDATE>='" + headRow.VOUDATE.ToString() + "'
#endregion
var cmdSql = db.GetSqlStringCommand(sSQL);
db.ExecuteNonQuery(cmdSql, tran);
//
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
*/
#endregion
#region 根据科目方向更新余额和余额方向
Database db2 = DatabaseFactory.CreateDatabase();
using (var conn = db2.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
#region 循环更新余额
//sSQL = "update [ct_bank_journal] set "
//+ "DC=(select (case when '" + ACCDC + "'='借' then (case when BLC>=0 then '借' else '贷' end) else (case when BLC>=0 then '贷' else '借' end) end) as DC FROM ct_bank_journal as a where a.STARTGID='" + strCtSTARTGID + "' and a.GID=ct_bank_journal.GID)"
//+ ",BLC=(select (case when BLC>=0 then BLC else -BLC end) as BLC FROM ct_bank_journal as b where b.STARTGID='" + strCtSTARTGID + "' and b.GID=ct_bank_journal.GID)"
//+ " where STARTGID='" + strCtSTARTGID + "' and VOUDATE>='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0";
sSQL = "update [ct_bank_journal] set "
+ "DC=(select (case when '" + ACCDC + "'='借' then (case when BLC>=0 then 'D' else 'C' end) else (case when BLC>=0 then 'C' else 'D' end) end) as DC FROM ct_bank_journal as a where a.STARTGID='" + strCtSTARTGID + "' and a.GID=ct_bank_journal.GID)"
+ ",BLC=(select (case when BLC>=0 then BLC else -BLC end) as BLC FROM ct_bank_journal as b where b.STARTGID='" + strCtSTARTGID + "' and b.GID=ct_bank_journal.GID)"
+ " where STARTGID='" + strCtSTARTGID + "' and VOUDATE>='" + headRow.VOUDATE.ToString() + "' and ACCGID='" + headRow.ACCGID.ToString() + "' and FCYNO='" + headRow.FCYNO.ToString() + "' and ISINITIAL=0";
#endregion
var cmdSql = db2.GetSqlStringCommand(sSQL);
db2.ExecuteNonQuery(cmdSql, tran);
//
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
#endregion
}
#endregion
#region 更新期初余额
public static void onINITIAL(MsCtBankJournal headRow, string companyid, string userid)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
#region 更新期初余额
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
#region 更新期初对账单
string sSQL = "update [ct_initial_balance] set QTYYEARDR_B=(select isnull(sum(DR),0) as DR from ct_bank_journal where ISINITIAL=1 and STARTGID='" + strCtSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString().Trim() + "' and FCYNO='" + headRow.FCYNO.ToString().Trim() + "'),QTYYEARCR_B=(select isnull(sum(CR),0) as CR from ct_bank_journal where ISINITIAL=1 and STARTGID='" + strCtSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString().Trim() + "' and FCYNO='" + headRow.FCYNO.ToString().Trim() + "') where STARTGID='" + strCtSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString().Trim() + "' and CURRENCY='" + headRow.FCYNO.ToString().Trim() + "'";
var cmdSql = db.GetSqlStringCommand(sSQL);
db.ExecuteNonQuery(cmdSql, tran);
sSQL = "update [ct_initial_balance] set QTYYEARBLC_BH=isnull((QTYYEARBLC_B+QTYYEARDR_B-QTYYEARCR_B),0) where STARTGID='" + strCtSTARTGID + "' and ACCGID='" + headRow.ACCGID.ToString().Trim() + "' and CURRENCY='" + headRow.FCYNO.ToString().Trim() + "'";
cmdSql = db.GetSqlStringCommand(sSQL);
db.ExecuteNonQuery(cmdSql, tran);
#endregion
//
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
#endregion
}
#endregion
#region 删除
public static DBResult Delete(string gids, string companyid, string userid)
{
#region 默认值
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
var result = new DBResult();
var sGids = " and GID in ('" + gids.Replace(",", "','") + "')";
var headList = new List<MsCtBankJournal>();
var strSql = new StringBuilder();
strSql.Append("SELECT *,CREATEUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.CREATEUSER),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_bank_journal.MODIFIEDUSER),ACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=ct_bank_journal.ACCGID),SETTLETYPENAME=isnull((select top 1 STLNAME from [code_stlmode] where STLCODE=ct_bank_journal.SETTLETYPE),''),ISCHECKING=(case when CHECKINGGID='' then '' else (case when CHECKINGGID like 'auto%' then '*' else '**' end) end) from ct_bank_journal WITH(NOLOCK) where STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null)" + sGids);
strSql.Append(" order by VOUDATE,convert(decimal(10),ITEMNO)");
headList = SetData(strSql);
#endregion
#region 判断是否符合删除条件
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "select count(*) as inum from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID<>'' and CHECKINGGID is not null)" + sGids;
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
if (inum > 0)
{
result.Success = false;
result.Message = "操作错误,已经对账的数据,不允许操作!";//或轧账
return result;
}
#endregion
#region 插入更新余额_查询符合条件的数据
strSql.Clear();
strSql.Append("SELECT ACCGID,FCYNO,VOUDATE=(dateadd(dd,-day(ACCDATE+'-01'),dateadd(m,1,(ACCDATE+'-01'))))");
strSql.Append(" from ct_bank_journal WITH(NOLOCK)");
strSql.Append(" where STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null)" + sGids);
strSql.Append(" group by ACCGID,FCYNO,ACCDATE order by ACCGID,FCYNO");
DataSet ds2 = T_ALL_DA.GetAllSQL(strSql.ToString());
#endregion
#region 插入更新总账表_查询符合条件的数据
strSql.Clear();
strSql.Append("SELECT ACCGID,FCYNO,VOUDATE");
strSql.Append(" from ct_bank_journal WITH(NOLOCK)");
strSql.Append(" where STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null)" + sGids);
strSql.Append(" group by ACCGID,FCYNO,VOUDATE order by ACCGID,FCYNO,VOUDATE");
DataSet ds3 = T_ALL_DA.GetAllSQL(strSql.ToString());
#endregion
#region 删除
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from ct_bank_journal where STARTGID='" + strCtSTARTGID + "'" + sGids);
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试!";
return result;
}
}
#endregion
#region 插入更新余额
if (ds2 != null)
{
if (ds2.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds2.Tables[0].Rows)
{
MsCtBankJournal headRow = new MsCtBankJournal();
headRow.ACCGID = dr["ACCGID"].ToString();//科目GID
headRow.FCYNO = dr["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(dr["VOUDATE"].ToString());//凭证日期
//插入更新余额
onBLC(headRow, true, companyid, userid);
}
}
}
#endregion
#region 插入更新总账表
if (ds3 != null)
{
if (ds3.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds3.Tables[0].Rows)
{
MsCtBankJournal headRow = new MsCtBankJournal();
headRow.ACCGID = dr["ACCGID"].ToString();//科目GID
headRow.FCYNO = dr["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(dr["VOUDATE"].ToString());//凭证日期
//插入更新总账表
onCtGenlegAccitems(headRow, companyid, userid);
}
}
}
#endregion
result.Success = true;
result.Message = "操作成功";
return result;
}
public static void DeleteDetail(MsCtBankJournal headRow, string companyid, string userid)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and GID='" + headRow.GID.ToString() + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
onCtGenlegAccitems(headRow, companyid, userid);
}
#endregion
#region 导入
//判断是否有重复数据
public static DBResult isImportExcelGID(string condition, string companyid, string userid)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
string strCtACCDATE = BasicDataRefDAL.GetCtACCDATE(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string sGID = "";
#region 查询出符合条件的_重复GID
var strSql2 = new StringBuilder();
strSql2.Append("SELECT *,sCtGID=isnull((select gid from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VGID=VW_cw_vouchers_vouitems_gl.GID),'') from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null))");
if (!string.IsNullOrEmpty(condition))
{
strSql2.Append(" and " + condition);
}
DataSet ds = T_ALL_DA.GetAllSQL(strSql2.ToString());
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (i == ds.Tables[0].Rows.Count-1)
{
sGID += "第" + ds.Tables[0].Rows[i]["ACCMONTH"].ToString() + "期" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "字" + ds.Tables[0].Rows[i]["VOUNO"].ToString() + "号第" + ds.Tables[0].Rows[i]["ITEMNO"].ToString() + "条分录<br/>";//以上数据已经存在对应的日记账记录,是否覆盖,请确认?
}
else
{
sGID += "第" + ds.Tables[0].Rows[i]["ACCMONTH"].ToString() + "期" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "字" + ds.Tables[0].Rows[i]["VOUNO"].ToString() + "号第" + ds.Tables[0].Rows[i]["ITEMNO"].ToString() + "条分录<br/>";//以上数据已经存在对应的日记账记录,是否覆盖,请确认?
}
}
}
}
#endregion
//
#region 重复但不覆盖的GID 行数
var strSql3 = new StringBuilder();
strSql3.Append("SELECT count(*) as inum from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "' and CHECKINGGID<>'' and CHECKINGGID is not null)");
if (!string.IsNullOrEmpty(condition))
{
strSql3.Append(" and " + condition);
}
#endregion
int inumContinue = int.Parse(T_ALL_DA.GetStrSQL("inum", strSql3.ToString()));
#region 查询出符合条件的_不重复GID
var strSql = new StringBuilder();
strSql.Append("SELECT count(*) as inum from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid not in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "')");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
#endregion
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", strSql.ToString()));
if (sGID == "")
{
if (inum == 0)
{
result.Success = true;
result.Message = "";
return result;
}
else
{
result.Success = true;
result.Message = "true";
return result;
}
}
if (inumContinue == 0)
{
sGID = "以下" + ds.Tables[0].Rows.Count + "条数据已经存在对应的日记账记录,是否覆盖,请确认?<br/>" + sGID;
}
else
{
sGID = "以下" + (ds.Tables[0].Rows.Count + inumContinue) + "条数据已经存在对应的日记账记录,其中有已经对账的" + inumContinue + "条数据不允许覆盖,其他的是否覆盖,请确认?<br/>" + sGID;
}
result.Success = true;
result.Message = sGID;
return result;
}
//获取符合条件的所有GID的字符串
public static DBResult onImportExcelData(string condition, string sTYPE, string companyid, string userid)
{
var strSql = new StringBuilder();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
string strCtACCDATE = BasicDataRefDAL.GetCtACCDATE(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string sError = "";
int inumINSERT = 0;
int inumUpdate = 0;
int inumContinue = 0;
#region 重复GID 行数
strSql.Append("SELECT count(*) as inum from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null))");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
#endregion
inumUpdate = int.Parse(T_ALL_DA.GetStrSQL("inum", strSql.ToString()));
//
#region 重复但不覆盖的GID 行数
strSql.Clear();
strSql.Append("SELECT count(*) as inum from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "' and CHECKINGGID<>'' and CHECKINGGID is not null)");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
#endregion
inumContinue = int.Parse(T_ALL_DA.GetStrSQL("inum", strSql.ToString()));
//
#region 不重复GID 行数
strSql.Clear();
strSql.Append("SELECT count(*) as inum from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid not in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "')");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
#endregion
inumINSERT = int.Parse(T_ALL_DA.GetStrSQL("inum", strSql.ToString()));
sError = "导入" + inumINSERT + "条数据";
//
if (sTYPE == "UPDATE")
{
#region 覆盖出符合条件的_重复GID
strSql.Clear();
strSql.Append("SELECT *,sCtGID=isnull((select gid from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VGID=VW_cw_vouchers_vouitems_gl.GID),'') from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null))");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append("order by voudate,vouno,vkno,itemno");
#endregion
DataSet ds = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
onImportExcelGID(ds, sTYPE, companyid, userid);
}
}
sError += ",覆盖" + inumUpdate + "条数据!";
if (inumContinue!=0)
{
sError += "因已经对账不允许覆盖的" + inumContinue + "条数据!";
}
}
else
{
sError += ",跳过" + (inumUpdate + inumContinue) + "条数据!";
}
#region 查询出符合条件的_不重复GID
strSql.Clear();
strSql.Append("SELECT *,sCtGID=isnull((select gid from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VGID=VW_cw_vouchers_vouitems_gl.GID),'') from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid not in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "')");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append("order by voudate,vouno,vkno,itemno");
#endregion
DataSet ds1 = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
onImportExcelGID(ds1, "INSERT", companyid, userid);
}
}
//
#region 插入更新余额
strSql.Clear();
strSql.Append("SELECT ACCGID,FCYNO,VOUDATE=(dateadd(dd,-day(ACCDATE+'-01'),dateadd(m,1,(ACCDATE+'-01'))))");
strSql.Append(" from ct_bank_journal WITH(NOLOCK)");
strSql.Append(" where STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null)");
strSql.Append(" and VGID in (SELECT GID from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "'");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(")");
strSql.Append(" group by ACCGID,FCYNO,ACCDATE order by ACCGID,FCYNO");
DataSet ds2 = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds2 != null)
{
if (ds2.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds2.Tables[0].Rows)
{
MsCtBankJournal headRow = new MsCtBankJournal();
headRow.ACCGID = dr["ACCGID"].ToString();//科目GID
headRow.FCYNO = dr["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(dr["VOUDATE"].ToString());//凭证日期
//插入更新余额
onBLC(headRow, true, companyid, userid);
}
}
}
#endregion
#region 插入更新总账表
strSql.Clear();
strSql.Append("SELECT ACCGID,FCYNO,VOUDATE");
strSql.Append(" from ct_bank_journal WITH(NOLOCK)");
strSql.Append(" where STARTGID='" + strCtSTARTGID + "' and (CHECKINGGID='' or CHECKINGGID is null)");
strSql.Append(" and VGID in(SELECT GID from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "'");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
strSql.Append(")");
strSql.Append(" group by ACCGID,FCYNO,VOUDATE order by ACCGID,FCYNO,VOUDATE");
DataSet ds3 = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds3 != null)
{
if (ds3.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds3.Tables[0].Rows)
{
MsCtBankJournal headRow = new MsCtBankJournal();
headRow.ACCGID = dr["ACCGID"].ToString();//科目GID
headRow.FCYNO = dr["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(dr["VOUDATE"].ToString());//凭证日期
//插入更新总账表
onCtGenlegAccitems(headRow, companyid, userid);
}
}
}
#endregion
result.Success = true;
result.Message = sError;
return result;
}
//按条导入或覆盖数据
public static void onImportExcelGID(DataSet ds, string sTYPE, string companyid, string userid)
{
DBResult result = new DBResult();
var sVOUDATE = "";
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
//
for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
#region 按条导入或覆盖数据
MsCtBankJournal headRow = new MsCtBankJournal();
#region 默认值
headRow.ISINITIAL = false;//是否期初
headRow.ACCGID = ds.Tables[0].Rows[i]["ACCGID"].ToString();//科目GID
headRow.FCYNO = ds.Tables[0].Rows[i]["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(ds.Tables[0].Rows[i]["VOUDATE"].ToString());//凭证日期
sVOUDATE = headRow.VOUDATE.ToString("yyyy-MM-dd");
string sMonth = headRow.VOUDATE.Month.ToString();
if (sMonth.Length == 1)
{
sMonth = "0" + sMonth;
}
string sSQL = "select isnull((select top 1 isnull(ITEMNO,0) as iITEMNO from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + sVOUDATE + "' order by VOUDATE desc,convert(decimal(10),ITEMNO) desc),0) as iITEMNO";
int iITEMNO = int.Parse(T_ALL_DA.GetStrSQL("iITEMNO", sSQL));
headRow.ITEMNO = iITEMNO + 1;//当日序号
headRow.VGID = ds.Tables[0].Rows[i]["GID"].ToString();//凭证明细GID
headRow.VKNO = ds.Tables[0].Rows[i]["VKNO"].ToString();//凭证字
headRow.VOUNO = ds.Tables[0].Rows[i]["VOUNO"].ToString();//凭证号
headRow.FENTRYID = ds.Tables[0].Rows[i]["ITEMNO"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["ITEMNO"].ToString());//分录号
headRow.ACCDATE = ds.Tables[0].Rows[i]["ACCDATE"].ToString();//会计期间
headRow.SETTLETYPE = ds.Tables[0].Rows[i]["FSETTLCODE"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["FSETTLCODE"].ToString());//结算方式
headRow.BILLNO = ds.Tables[0].Rows[i]["FSETTLENO"].ToString();//结算号
headRow.SVOUDATE = headRow.VOUDATE;//结算日期
headRow.DC = ds.Tables[0].Rows[i]["DC"].ToString();//余额方向
headRow.DR = ds.Tables[0].Rows[i]["AMTDR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[i]["AMTDR"].ToString());//原币借方金额(互斥)
headRow.CR = ds.Tables[0].Rows[i]["AMTCR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[i]["AMTCR"].ToString());//原币贷方金额(互斥)
if (headRow.FCYNO.ToString().Trim() != "RMB")
{
headRow.DR = ds.Tables[0].Rows[i]["FCYDR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[i]["FCYDR"].ToString());//原币借方金额(互斥)
headRow.CR = ds.Tables[0].Rows[i]["FCYCR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[i]["FCYCR"].ToString());//原币贷方金额(互斥)
}
headRow.FCYEXRATE = ds.Tables[0].Rows[i]["FCYEXRATE"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[i]["FCYEXRATE"].ToString());//汇率
headRow.QTYDR = Math.Round((headRow.DR * headRow.FCYEXRATE), 2, MidpointRounding.AwayFromZero);//折合本位币借方
headRow.QTYCR = Math.Round((headRow.CR * headRow.FCYEXRATE), 2, MidpointRounding.AwayFromZero);//折合本位币贷方
headRow.BLC = 0;//原币余额
headRow.EXPLAN = ds.Tables[0].Rows[i]["EXPLAN"].ToString();//摘要,规则生成
headRow.ENTERED = ds.Tables[0].Rows[i]["PREPARED"].ToString();//经手人
headRow.CHECKINGGID = "";//对账GID
headRow.STARTGID = strCtSTARTGID;//账套启用GID
headRow.CORPID = companyid;//分公司GID
headRow.CREATEUSER = userid;//制单人GID
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = userid;//最后一次更改操作人GID
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更改操作时间
#endregion
if (sTYPE.Trim() == "INSERT")//"add"
{
headRow.GID = Guid.NewGuid().ToString();
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
headRow.GID = ds.Tables[0].Rows[i]["sCtGID"].ToString().Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
var modb = new ModelObjectDB();
result = modb.Save(headRow);
#endregion
}
}
//获取符合条件的所有GID的字符串
public static DBResult onImportExcelData2(string condition, string companyid, string userid)
{
#region 查询出符合条件的_重复GID
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
string strCtACCDATE = BasicDataRefDAL.GetCtACCDATE(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string sGID = "";
var strSql2 = new StringBuilder();
strSql2.Append("SELECT *,sCtGID=isnull((select gid from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VGID=VW_cw_vouchers_vouitems_gl.GID),'') from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "')");
if (!string.IsNullOrEmpty(condition))
{
strSql2.Append(" and " + condition);
}
DataSet ds = T_ALL_DA.GetAllSQL(strSql2.ToString());
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
sGID += "," + ds.Tables[0].Rows[i]["GID"].ToString().Trim() + "。" + "第" + ds.Tables[0].Rows[i]["ACCMONTH"].ToString() + "期" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "字" + ds.Tables[0].Rows[i]["VOUNO"].ToString() + "号第" + ds.Tables[0].Rows[i]["ITEMNO"].ToString() + "条分录已经存在对应的日记账记录,是否覆盖,请确认?" + "。" + ds.Tables[0].Rows[i]["sCtGID"].ToString().Trim();
}
}
}
#endregion
#region 查询出符合条件的_不重复GID
int inum = 0;
var strSql = new StringBuilder();
strSql.Append("SELECT *,sCtGID=isnull((select gid from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VGID=VW_cw_vouchers_vouitems_gl.GID),'') from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCtACCDATE + "' and gid not in (select VGID from ct_bank_journal where VGID<>'' and VGID is not null and STARTGID='" + strCtSTARTGID + "')");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
ds = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DBResult result3 = onImportExcelGID2(ds.Tables[0].Rows[i]["GID"].ToString().Trim(), "INSERT", "", companyid, userid);
if (result3.Success)
{
inum++;
}
}
}
}
#endregion
if (sGID == "" && inum == 0)
{
result.Success = true;
result.Message = "";
return result;
}
sGID = inum.ToString() + sGID;
result.Success = true;
result.Message = sGID;
return result;
}
//判断是否有重复数据
public static DBResult isImportExcelGID2(string gids, string companyid, string userid)
{
#region 判断是否有重复数据
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
var strSql = new StringBuilder();
strSql.Append("SELECT top 1 * from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and GID in (SELECT VGID from [ct_bank_journal] where STARTGID='" + strCtSTARTGID + "' and VGID='" + gids + "')");
DataSet ds = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
result.Success = false;
result.Message = "第" + ds.Tables[0].Rows[0]["ACCMONTH"].ToString() + "期" + ds.Tables[0].Rows[0]["VKNO"].ToString() + "字" + ds.Tables[0].Rows[0]["VOUNO"].ToString() + "号第" + ds.Tables[0].Rows[0]["ITEMNO"].ToString() + "条分录已经存在对应的日记账记录,是否覆盖,请确认?";
return result;
}
}
#endregion
result.Success = true;
result.Message = "";
return result;
}
//按条导入或覆盖数据
public static DBResult onImportExcelGID2(string gids, string sTYPE, string sCtGID, string companyid, string userid)
{
#region 按条导入或覆盖数据
DBResult result = new DBResult();
var sVOUDATE = "";
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strSql = "SELECT top 1 * from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and GID='" + gids + "'";
DataSet ds = T_ALL_DA.GetAllSQL(strSql);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
MsCtBankJournal headRow = new MsCtBankJournal();
#region 默认值
headRow.ISINITIAL = false;//是否期初
headRow.ACCGID = ds.Tables[0].Rows[0]["ACCGID"].ToString();//科目GID
headRow.FCYNO = ds.Tables[0].Rows[0]["FCYNO"].ToString();//外币编号usd
headRow.VOUDATE = DateTime.Parse(ds.Tables[0].Rows[0]["VOUDATE"].ToString());//凭证日期
sVOUDATE = headRow.VOUDATE.ToString("yyyy-MM-dd");
string sMonth = headRow.VOUDATE.Month.ToString();
if (sMonth.Length == 1)
{
sMonth = "0" + sMonth;
}
int iITEMNO = int.Parse(T_ALL_DA.GetStrSQL("iITEMNO", "select isnull((select top 1 isnull(ITEMNO,0) as iITEMNO from ct_bank_journal where STARTGID='" + strCtSTARTGID + "' and VOUDATE='" + sVOUDATE + "' order by VOUDATE desc,convert(decimal(10),ITEMNO) desc),0) as iITEMNO"));
headRow.ITEMNO = iITEMNO + 1;//当日序号
headRow.VGID = ds.Tables[0].Rows[0]["GID"].ToString();//凭证明细GID
headRow.VKNO = ds.Tables[0].Rows[0]["VKNO"].ToString();//凭证字
headRow.VOUNO = ds.Tables[0].Rows[0]["VOUNO"].ToString();//凭证号
headRow.FENTRYID = ds.Tables[0].Rows[0]["ITEMNO"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[0]["ITEMNO"].ToString());//分录号
headRow.ACCDATE = ds.Tables[0].Rows[0]["ACCDATE"].ToString();//会计期间
headRow.SETTLETYPE = ds.Tables[0].Rows[0]["FSETTLCODE"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[0]["FSETTLCODE"].ToString());//结算方式
headRow.BILLNO = ds.Tables[0].Rows[0]["FSETTLENO"].ToString();//结算号
headRow.SVOUDATE = headRow.VOUDATE;//结算日期
headRow.DC = ds.Tables[0].Rows[0]["DC"].ToString();//余额方向
headRow.DR = ds.Tables[0].Rows[0]["AMTDR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[0]["AMTDR"].ToString());//原币借方金额(互斥)
headRow.CR = ds.Tables[0].Rows[0]["AMTCR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[0]["AMTCR"].ToString());//原币贷方金额(互斥)
if (headRow.FCYNO.ToString().Trim()!="RMB")
{
headRow.DR = ds.Tables[0].Rows[0]["FCYDR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[0]["FCYDR"].ToString());//原币借方金额(互斥)
headRow.CR = ds.Tables[0].Rows[0]["FCYCR"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[0]["FCYCR"].ToString());//原币贷方金额(互斥)
}
headRow.FCYEXRATE = ds.Tables[0].Rows[0]["FCYEXRATE"].ToString() == "" ? 0 : Decimal.Parse(ds.Tables[0].Rows[0]["FCYEXRATE"].ToString());//汇率
headRow.QTYDR = Math.Round((headRow.DR * headRow.FCYEXRATE), 2, MidpointRounding.AwayFromZero);//折合本位币借方
headRow.QTYCR = Math.Round((headRow.CR * headRow.FCYEXRATE), 2, MidpointRounding.AwayFromZero);//折合本位币贷方
headRow.BLC = 0;//原币余额
headRow.EXPLAN = ds.Tables[0].Rows[0]["EXPLAN"].ToString();//摘要,规则生成
headRow.ENTERED = ds.Tables[0].Rows[0]["PREPARED"].ToString();//经手人
headRow.CHECKINGGID = "";//对账GID
headRow.STARTGID = strCtSTARTGID;//账套启用GID
headRow.CORPID = companyid;//分公司GID
headRow.CREATEUSER = userid;//制单人GID
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = userid;//最后一次更改操作人GID
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更改操作时间
#endregion
if (sTYPE.Trim() == "INSERT")//"add"
{
headRow.GID = Guid.NewGuid().ToString();
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
headRow.GID = sCtGID.Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
var modb = new ModelObjectDB();
result = modb.Save(headRow);
if (result.Success)
{
//插入更新余额
MsCtBankJournalDAL.onBLC(headRow, false, companyid, userid);
//插入更新总账表
MsCtBankJournalDAL.onCtGenlegAccitems(headRow, companyid, userid);
}
}
}
#endregion
return result;
}
#endregion
}
}