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.

247 lines
14 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCwVouchersGlSettlementEntity;
using DSWeb.MvcShipping.Models.MsCwAccitemsGl;
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;
using DSWeb.Areas.Account.Models.MsCwVouchersGl3;
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlSettlementDAL
{
public class MsCwVouchersGlSettlementDAL
{
#region 查询
static public List<MsCwVouchersGlSettlementEntity> GetDataList(int start, int limit, string strCondition, string companyid, string strUSERID, string sort = null)
{
var strSql = new StringBuilder();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
if (sortstring.IndexOf("SETTLETIME") > 0)
strSql.Append(" order by " + sortstring);
else
strSql.Append(" order by " + sortstring + ",SETTLETIME DESC");
}
else
{
strSql.Append(" order by BILLTYPE,BILLNO DESC,SETTLETIME DESC");
}
strSql.Append(@") as num , ");
strSql.Append(" GID,BILLNO,BILLDATE,SETTLEMODE,CUSTOMERNAME,SETTLETYPE ,AMOUNTRMB,ACCOUNTRMB,RATE,ISNOTVOU ");
strSql.Append(" ,AMOUNTUSD,ACCOUNTUSD,BILLTYPE,BILLTYPENAME=(case when BILLTYPE=2 then '应付结算' else '应收结算' end)");
strSql.Append(" ,VOUCHERNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_settlement' and STARTGID='" + strCwSTARTGID + "')");
strSql.Append(" ,SETTLEUSER,SETTLETIME,AUDITUSER,AUDITTIME,CREATEUSER,CREATETIME");
strSql.Append(" ,ISEXPORT,FINANCIALVOUCHER,BILLSTATUS,REMARK,COMPANYID,CUSTBANK,CUSTACCOUNT,VOUNO,ACCOUNTS_CURRENCY ");
strSql.Append(" ,ACCOUNTS_RATE,ACCOUNTS_MONEY,PREPAY_CURRENCY,PREPAY_RATE,PREPAY_MONEY,AHSR_CURRENCY ");
strSql.Append(" ,AHSR_RATE,AHSR_MONEY,FINANCIAL_CURRENCY,FINANCIAL_RATE,FINANCIAL_MONEY,ADVANCE_CURRENCY,ADVANCE_RATE,ADVANCE_MONEY,CURR ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=cm.SETTLEUSER) as SETTLEUSERREF");
strSql.Append(",(select ShowName from [user] where GID=cm.CREATEUSER) as CREATEUSERREF");
strSql.Append(",(select STLNAME from [code_stlmode] where STLCODE=cm.SETTLETYPE) as SETTLETYPEREF");
strSql.Append(",(select BANKNAME from [sys_bank] where GID=cm.ACCOUNTRMB) as ACCOUNTRMBREF");
strSql.Append(",(select BANKNAME from [sys_bank] where GID=cm.ACCOUNTUSD) as ACCOUNTUSDREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97007 and EnumValueID=cm.SETTLEMODE) as SETTLEMODEREF");
strSql.Append(",ISNULL((select sum(isnull(amount,0)-isnull(invoice,0)) as noinvoice from ch_fee where ISINVOICE<>1 and gid in (select feeid from ch_fee_do where BILLNO=cm.BILLNO)),0) as NOINVOICE");
strSql.Append(",SALECORP FROM v_settlement cm where BILLSTATUS=1 ");//BILLSTATUS=1只取锁定的数据//ch_fee_settlement
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num ", start, start + limit)); //
//
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string companyid, string strUSERID, string sort = null)
{
var strSql = new StringBuilder();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
strSql.Append("SELECT GID,BILLNO,BILLDATE,SETTLEMODE,CUSTOMERNAME,SETTLETYPE ,AMOUNTRMB,ACCOUNTRMB,RATE,ISNOTVOU ");
strSql.Append(" ,AMOUNTUSD,ACCOUNTUSD,BILLTYPE,BILLTYPENAME=(case when BILLTYPE=2 then '应付结算' else '应收结算' end)");
strSql.Append(" ,VOUCHERNO=(select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=cm.GID and BSTABLENAME='ch_fee_settlement' and STARTGID='" + strCwSTARTGID + "')");
strSql.Append(" ,SETTLEUSER,SETTLETIME,AUDITUSER,AUDITTIME,CREATEUSER,CREATETIME");
strSql.Append(" ,ISEXPORT,FINANCIALVOUCHER,BILLSTATUS,REMARK,COMPANYID,CUSTBANK,CUSTACCOUNT,VOUNO,ACCOUNTS_CURRENCY ");
strSql.Append(" ,ACCOUNTS_RATE,ACCOUNTS_MONEY,PREPAY_CURRENCY,PREPAY_RATE,PREPAY_MONEY,AHSR_CURRENCY ");
strSql.Append(" ,AHSR_RATE,AHSR_MONEY,FINANCIAL_CURRENCY,FINANCIAL_RATE,FINANCIAL_MONEY,ADVANCE_CURRENCY,ADVANCE_RATE,ADVANCE_MONEY,CURR ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=cm.SETTLEUSER) as SETTLEUSERREF");
strSql.Append(",(select ShowName from [user] where GID=cm.CREATEUSER) as CREATEUSERREF");
strSql.Append(",(select STLNAME from [code_stlmode] where STLCODE=cm.SETTLETYPE) as SETTLETYPEREF");
strSql.Append(",CASE WHEN CURR='RMB' THEN AMOUNTRMB ELSE AMOUNTUSD END as AMOUNT");
strSql.Append(",CASE WHEN CURR='RMB' THEN ACCOUNTRMB ELSE ACCOUNTUSD END as ACCOUNT");
strSql.Append(",CASE WHEN CURR='RMB' THEN (select BANKNAME from [sys_bank] where GID=cm.ACCOUNTRMB) ELSE (select BANKNAME from [sys_bank] where GID=cm.ACCOUNTUSD) END as ACCOUNTREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97007 and EnumValueID=cm.SETTLEMODE) as SETTLEMODEREF");
strSql.Append(",ISNULL((select sum(isnull(amount,0)-isnull(invoice,0)) as noinvoice from ch_fee where ISINVOICE<>1 and gid in (select feeid from ch_fee_do where BILLNO=cm.BILLNO)),0) as NOINVOICE");
strSql.Append(",SALECORP FROM v_settlement cm where BILLSTATUS=1 ");//BILLSTATUS=1只取锁定的数据//ch_fee_settlement
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
if (sortstring.IndexOf("SETTLETIME") > 0)
strSql.Append(" order by " + sortstring);
else
strSql.Append(" order by " + sortstring + ",SETTLETIME DESC");
}
else
{
strSql.Append(" order by BILLTYPE,BILLNO DESC,SETTLETIME DESC");
}
//
return strSql.ToString();
}
public static int getTotalCount(string strCondition, string userid, string usercode, string orgcode)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" from v_settlement cm where BILLSTATUS=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
private static List<MsCwVouchersGlSettlementEntity> SetData(StringBuilder strSql)
{
var headList = new List<MsCwVouchersGlSettlementEntity>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwVouchersGlSettlementEntity data = new MsCwVouchersGlSettlementEntity();
#region Set DB data to Object
data.SALECORP = Convert.ToString(reader["SALECORP"]);
data.GID = Convert.ToString(reader["GID"]);
data.BILLNO = Convert.ToString(reader["BILLNO"]);
if (reader["BILLDATE"] != DBNull.Value)
data.BILLDATE = Convert.ToDateTime(reader["BILLDATE"]);
data.SETTLEMODE = Convert.ToInt32(reader["SETTLEMODE"]);
data.SETTLEMODEREF = Convert.ToString(reader["SETTLEMODEREF"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["SETTLETYPE"] != DBNull.Value)
data.SETTLETYPE = Convert.ToInt32(reader["SETTLETYPE"]);
data.SETTLETYPEREF = Convert.ToString(reader["SETTLETYPEREF"]);
if (reader["AMOUNTRMB"] != DBNull.Value)
data.AMOUNTRMB = Convert.ToDecimal(reader["AMOUNTRMB"]);
data.ACCOUNTRMB = Convert.ToString(reader["ACCOUNTRMB"]);
if (reader["RATE"] != DBNull.Value)
data.RATE = Convert.ToDecimal(reader["RATE"]);
if (reader["AMOUNTUSD"] != DBNull.Value)
data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
data.ACCOUNTUSD = Convert.ToString(reader["ACCOUNTUSD"]);
data.CURR = Convert.ToString(reader["CURR"]);
if (data.CURR == "RMB")
{
data.AMOUNT = data.AMOUNTRMB;
data.ACCOUNT = data.ACCOUNTRMB;
data.ACCOUNTREF = Convert.ToString(reader["ACCOUNTRMBREF"]);
}
else
{
data.AMOUNT = data.AMOUNTUSD;
data.ACCOUNT = data.ACCOUNTUSD;
data.ACCOUNTREF = Convert.ToString(reader["ACCOUNTUSDREF"]);
}
data.BILLTYPE = Convert.ToInt32(reader["BILLTYPE"]);
data.BILLTYPENAME = Convert.ToString(reader["BILLTYPENAME"]);
data.VOUCHERNO = Convert.ToString(reader["VOUCHERNO"]);
data.SETTLEUSER = Convert.ToString(reader["SETTLEUSER"]);
data.SETTLEUSERREF = Convert.ToString(reader["SETTLEUSERREF"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd");
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]);
data.AUDITUSER = Convert.ToString(reader["AUDITUSER"]);
if (reader["ISEXPORT"] != DBNull.Value)
data.ISEXPORT = Convert.ToBoolean(reader["ISEXPORT"]);
data.FINANCIALVOUCHER = Convert.ToString(reader["FINANCIALVOUCHER"]);
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.VOUNO = Convert.ToString(reader["VOUNO"]);
data.CUSTBANK = Convert.ToString(reader["CUSTBANK"]);
data.CUSTACCOUNT = Convert.ToString(reader["CUSTACCOUNT"]);
data.ACCOUNTS_CURRENCY = Convert.ToString(reader["ACCOUNTS_CURRENCY"]);
data.ACCOUNTS_RATE = Convert.ToDecimal(reader["ACCOUNTS_RATE"]);
data.ACCOUNTS_MONEY = Convert.ToDecimal(reader["ACCOUNTS_MONEY"]);
data.PREPAY_CURRENCY = Convert.ToString(reader["PREPAY_CURRENCY"]);
data.PREPAY_RATE = Convert.ToDecimal(reader["PREPAY_RATE"]);
data.PREPAY_MONEY = Convert.ToDecimal(reader["PREPAY_MONEY"]);
data.AHSR_CURRENCY = Convert.ToString(reader["AHSR_CURRENCY"]);
data.AHSR_RATE = Convert.ToDecimal(reader["AHSR_RATE"]);
data.AHSR_MONEY = Convert.ToDecimal(reader["AHSR_MONEY"]);
data.FINANCIAL_CURRENCY = Convert.ToString(reader["FINANCIAL_CURRENCY"]);
data.FINANCIAL_RATE = Convert.ToDecimal(reader["FINANCIAL_RATE"]);
data.FINANCIAL_MONEY = Convert.ToDecimal(reader["FINANCIAL_MONEY"]);
data.ADVANCE_CURRENCY = Convert.ToString(reader["ADVANCE_CURRENCY"]);
data.ADVANCE_RATE = Convert.ToDecimal(reader["ADVANCE_RATE"]);
data.ADVANCE_MONEY = Convert.ToDecimal(reader["ADVANCE_MONEY"]);
data.NOINVOICE = Convert.ToDecimal(reader["NOINVOICE"]);
if (reader["ISNOTVOU"] != DBNull.Value)
data.ISNOTVOU = Convert.ToBoolean(reader["ISNOTVOU"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
}
}