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.
442 lines
17 KiB
C#
442 lines
17 KiB
C#
|
|
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.MsRptCwBaoXiao;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.EntityDA;
|
|
using HcUtility.Comm;
|
|
using System.Web;
|
|
using System.Text.RegularExpressions;
|
|
using DSWeb.MvcShipping.Models.MonthDataSet;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
namespace DSWeb.Areas.MvcShipping.DAL.MsRptCwBaoXiaoDAL
|
|
{
|
|
public class MsRptCwBaoXiaoDAL
|
|
{
|
|
|
|
static public List<CwBaoXiao> ListData(string condition, string sort, string startdate, string enddate, string userid, string username, string companyid)
|
|
{
|
|
//var strDa = GetRangDAStr("index",userid, username,companyid);
|
|
|
|
//if (!string.IsNullOrEmpty(strDa))
|
|
//{
|
|
// if (!string.IsNullOrEmpty(condition))
|
|
// {
|
|
// condition = condition + " and " + strDa;
|
|
// }
|
|
// else
|
|
// {
|
|
// condition = strDa;
|
|
// }
|
|
//}
|
|
|
|
var startdata=new CwBaoXiao();
|
|
if (startdate!="")
|
|
startdata = GetStartData(condition,startdate);
|
|
|
|
var strSql2 = new StringBuilder();
|
|
strSql2.Append("SELECT * ");
|
|
//strSql2.Append(",(select BANKNAME from [sys_bank] where GID=B.ACCOUNT) as ACCOUNTREF");
|
|
//strSql2.Append(",(CASE WHEN FEETYPE=1 THEN '收' ELSE '付' END) as FEETYPEREF");
|
|
|
|
strSql2.Append(" FROM V_JKBX_DETAIL B ");
|
|
strSql2.Append(" WHERE 1=1 ");
|
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
{
|
|
strSql2.Append(" AND " + condition);
|
|
}
|
|
if (!string.IsNullOrEmpty(startdate))
|
|
{
|
|
strSql2.Append(" AND ENTERDATE>='" + startdate + "'");
|
|
}
|
|
if (!string.IsNullOrEmpty(enddate))
|
|
{
|
|
strSql2.Append(" AND ENTERDATE<='" + enddate + " 23:59:59'");
|
|
}
|
|
|
|
strSql2.Append(" ORDER BY ENTERDATE,OPTYPE DESC ");
|
|
|
|
|
|
return SetData(strSql2, startdata);
|
|
|
|
}
|
|
|
|
private static List<CwBaoXiao> SetData(StringBuilder strSql, CwBaoXiao stardata)
|
|
{
|
|
var headList = new List<CwBaoXiao>();
|
|
decimal balace =0;
|
|
decimal balaceusd = 0;
|
|
decimal balacehkd = 0;
|
|
|
|
|
|
if (stardata != null&&(stardata.BALANCE!=0||stardata.BALANCEUSD!=0||stardata.BALANCEHKD!=0))
|
|
{
|
|
headList.Add(stardata);
|
|
balace = stardata.BALANCE;
|
|
balaceusd = stardata.BALANCEUSD;
|
|
balacehkd = stardata.BALANCEHKD;
|
|
}
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CwBaoXiao data = new CwBaoXiao();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
data.ENTERDATE = Convert.ToDateTime(reader["ENTERDATE"]).ToString("yyyy-MM-dd");
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
data.REASON = Convert.ToString(reader["REASON"]);
|
|
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
|
|
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
|
|
data.DEPTID = Convert.ToString(reader["DEPTID"]);
|
|
data.JKSTATUS = Convert.ToString(reader["JKSTATUS"]);
|
|
data.JKTYPE = Convert.ToString(reader["JKTYPE"]);
|
|
data.REMARK = Convert.ToString(reader["REMARK"]);
|
|
data.CHEQUENO = Convert.ToString(reader["CHEQUENO"]);
|
|
if (reader["AMOUNT"] != DBNull.Value)
|
|
data.AMOUNTDR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
if (reader["AMOUNT"] != DBNull.Value)
|
|
{
|
|
if (Convert.ToString(reader["OPTYPE"]) == "借款")
|
|
{
|
|
if (Convert.ToString(reader["CURRENCY"]) == "RMB")
|
|
{
|
|
balace = balace + data.AMOUNTDR;
|
|
data.BALANCEHKD = balacehkd;
|
|
data.BALANCE = balace;
|
|
data.BALANCEUSD = balaceusd;
|
|
|
|
}
|
|
else if (Convert.ToString(reader["CURRENCY"]) == "USD")
|
|
{
|
|
data.AMOUNTUSDDR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
balaceusd = balaceusd + data.AMOUNTUSDDR;
|
|
data.BALANCEHKD = balacehkd;
|
|
data.BALANCE = balace;
|
|
data.BALANCEUSD = balaceusd;
|
|
|
|
}
|
|
else if (Convert.ToString(reader["CURRENCY"]) != "RMB"&& Convert.ToString(reader["CURRENCY"]) != "USD")
|
|
{
|
|
|
|
balacehkd = balacehkd + Convert.ToDecimal(reader["AMOUNT"]);
|
|
data.BALANCEHKD = balacehkd;
|
|
data.BALANCE = balace;
|
|
data.BALANCEUSD = balaceusd;
|
|
|
|
}
|
|
data.DR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if (Convert.ToString(reader["CURRENCY"]) == "RMB")
|
|
{
|
|
data.AMOUNTCR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
balace = balace- data.AMOUNTCR;
|
|
data.BALANCE = balace;
|
|
data.BALANCEUSD = balaceusd;
|
|
data.BALANCEHKD = balacehkd;
|
|
|
|
}
|
|
else if (Convert.ToString(reader["CURRENCY"]) == "USD")
|
|
{
|
|
data.AMOUNTUSDCR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
balaceusd = balaceusd - data.AMOUNTUSDCR;
|
|
data.BALANCEUSD = balaceusd;
|
|
data.BALANCE = balace;
|
|
data.BALANCEHKD = balacehkd;
|
|
|
|
}
|
|
else if (Convert.ToString(reader["CURRENCY"]) != "RMB" && Convert.ToString(reader["CURRENCY"]) != "USD")
|
|
{
|
|
|
|
balacehkd = balacehkd -Convert.ToDecimal(reader["AMOUNT"]);
|
|
data.BALANCEHKD = balacehkd;
|
|
data.BALANCE = balace;
|
|
data.BALANCEUSD = balaceusd;
|
|
|
|
}
|
|
data.CR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
headList.Add(data);
|
|
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
|
|
|
|
//private static List<CwBaoXiao> SetBankStartData(StringBuilder strSql)
|
|
//{
|
|
// var headList = new List<CwBaoXiao>();
|
|
|
|
// Database db = DatabaseFactory.CreateDatabase();
|
|
// using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
// {
|
|
// while (reader.Read())
|
|
// {
|
|
// CwBaoXiao data = new CwBaoXiao();
|
|
// #region Set DB data to Object
|
|
// data.GID = Convert.ToString(reader["GID"]);
|
|
// data.BILLDATE = Convert.ToDateTime(reader["BILLDATE"]).ToString("yyyy-MM-dd");
|
|
// data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
// data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
// data.FEENAME = Convert.ToString(reader["FEENAME"]);
|
|
// data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
|
|
// data.ACCOUNT = Convert.ToString(reader["ACCOUNT"]);
|
|
// data.ACCOUNTREF = Convert.ToString(reader["ACCOUNTREF"]);
|
|
// data.FEETYPE = Convert.ToString(reader["FEETYPEREF"]);
|
|
// data.BILLTYPE = Convert.ToString(reader["BILLTYPE"]);
|
|
// data.REMARK = Convert.ToString(reader["REMARK"]);
|
|
// data.SETTLEUSER = Convert.ToString(reader["SETTLEUSER"]);
|
|
// data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
|
|
// if (reader["EXCHANGERATE"] != DBNull.Value)
|
|
// data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
|
|
// if (reader["AMOUNT"] != DBNull.Value)
|
|
// {
|
|
// if (Convert.ToString(reader["FEETYPE"]) == "1")
|
|
// {
|
|
// data.DR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
// data.CR = 0;
|
|
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// data.CR = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
|
|
|
// }
|
|
// }
|
|
// #endregion
|
|
// headList.Add(data);
|
|
|
|
// }
|
|
// reader.Close();
|
|
// }
|
|
// return headList;
|
|
//}
|
|
|
|
|
|
static public CwBaoXiao GetStartData(string condition, string startdate)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT SUM(RMBAMOUTBAL) AS AMOUNTRMB ");
|
|
strSql.Append(",SUM(USDAMOUTBAL) AS AMOUNTUSD");
|
|
strSql.Append(",SUM(OTAMOUTBAL) AS AMOUNTHKD from V_JKBX_DETAIL");
|
|
strSql.Append(" where ENTERDATE<'" + startdate + "'");
|
|
if (!string.IsNullOrEmpty(condition))
|
|
{
|
|
strSql.Append(" AND " + condition);
|
|
}
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
var evList = new List<CwBaoXiao>();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CwBaoXiao Data = new CwBaoXiao();
|
|
Data.REMARK ="以前结余";
|
|
if (reader["AMOUNTRMB"] != DBNull.Value)
|
|
Data.BALANCE = Convert.ToDecimal(reader["AMOUNTRMB"]);
|
|
|
|
if (reader["AMOUNTUSD"] != DBNull.Value)
|
|
Data.BALANCEUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
|
|
|
|
if (reader["AMOUNTHKD"] != DBNull.Value)
|
|
Data.BALANCEHKD = Convert.ToDecimal(reader["AMOUNTHKD"]);
|
|
|
|
|
|
evList.Add(Data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
if (evList.Count > 0)
|
|
return evList[0];
|
|
else
|
|
return new CwBaoXiao();
|
|
}
|
|
|
|
static public List<CwBaoXiaoSum> GetSumData(string condition, string nocondition)
|
|
{
|
|
|
|
// var nodc = GetNODRCRData(nocondition);
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT SUM(CASE WHEN CURRENCY='RMB' THEN (CASE WHEN OPTYPE='报销' THEN AMOUNT ELSE -AMOUNT END) ELSE 0 END) AS AMOUNTRMB ");
|
|
strSql.Append(",SUM(CASE WHEN CURRENCY='USD' THEN (CASE WHEN OPTYPE='报销' THEN AMOUNT ELSE -AMOUNT END) ELSE 0 END) AS AMOUNTUSD");
|
|
strSql.Append(",SUM(CASE WHEN CURRENCY!='RMB' AND CURRENCY!='USD' THEN (CASE WHEN OPTYPE='报销' THEN AMOUNT ELSE -AMOUNT END) ELSE 0 END) AS AMOUNTHKD ");
|
|
strSql.Append(" from V_JKBX_DETAIL");
|
|
if (!string.IsNullOrEmpty(condition))
|
|
{
|
|
strSql.Append(" WHERE " + condition);
|
|
}
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
var evList = new List<CwBaoXiaoSum>();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CwBaoXiaoSum Data = new CwBaoXiaoSum();
|
|
|
|
if (reader["AMOUNTRMB"] != DBNull.Value)
|
|
Data.BALANCERMB = Convert.ToDecimal(reader["AMOUNTRMB"]);
|
|
|
|
if (reader["AMOUNTUSD"] != DBNull.Value)
|
|
Data.BALANCEUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
|
|
|
|
if (reader["AMOUNTHKD"] != DBNull.Value)
|
|
Data.BALANCEHKD = Convert.ToDecimal(reader["AMOUNTHKD"]);
|
|
|
|
if (reader["AMOUNTTTL"] != DBNull.Value)
|
|
Data.BALANCETTL = Convert.ToDecimal(reader["AMOUNTTTL"]);
|
|
|
|
Data.TTL = Data.BALANCETTL + Data.NODRTTL - Data.NOCRTTL;
|
|
|
|
evList.Add(Data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
|
|
return evList;
|
|
|
|
}
|
|
static public CwBaoXiaoSum GetNODRCRData(string condition)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT-SETTLEMENT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLDR,");
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT-SETTLEMENT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS BALTTLCR");
|
|
strSql.Append(" FROM CH_FEE F ");
|
|
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
var evList = new List<CwBaoXiaoSum>();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CwBaoXiaoSum Data = new CwBaoXiaoSum();
|
|
|
|
if (reader["BALTTLDR"] != DBNull.Value)
|
|
Data.NODRTTL = Convert.ToDecimal(reader["BALTTLDR"]);
|
|
|
|
if (reader["BALTTLCR"] != DBNull.Value)
|
|
Data.NOCRTTL = Convert.ToDecimal(reader["BALTTLCR"]);
|
|
|
|
|
|
evList.Add(Data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
if (evList.Count > 0)
|
|
return evList[0];
|
|
else
|
|
return new CwBaoXiaoSum();
|
|
}
|
|
|
|
public static string GetRangDAStr(string tb, string userid, string usercode, string companyid)
|
|
{
|
|
string str = "";
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
|
|
strSql.Append(" from VW_User_Authority ");
|
|
strSql.Append(" where [NAME]='modcwfundsRange' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
string visiblerange = "4";
|
|
string operaterange = "4";
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
|
|
while (reader.Read())
|
|
{
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
break;
|
|
}
|
|
reader.Close();
|
|
}
|
|
if (visiblerange == "4")
|
|
{
|
|
str = "1=2";
|
|
}
|
|
else if (visiblerange == "3")
|
|
{
|
|
|
|
str = " (SETTLEUSER='" + usercode + "')";
|
|
|
|
}
|
|
else if (visiblerange == "2")
|
|
{
|
|
if (tb == "index")
|
|
{
|
|
var rangeDa = new RangeDA();
|
|
var deptname = rangeDa.GetDEPTNAME(userid);
|
|
var userstr = new StringBuilder();
|
|
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
{
|
|
str = "";
|
|
while (reader.Read())
|
|
{
|
|
if (str == "")
|
|
{
|
|
str = " (SETTLEUSER='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
}
|
|
else
|
|
{
|
|
str = str + " or SETTLEUSER='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
};
|
|
}
|
|
str = str + ")";
|
|
reader.Close();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
else if (visiblerange == "1")
|
|
{
|
|
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
#region 参照部分
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|