You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/DAL/MsChDui/MsChDuiDAL.cs

2273 lines
104 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsChDui;
using DSWeb.MvcShipping.Models.MsChDuiView;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using DSWeb.EntityDA;
using HcUtility.Comm;
using DSWeb.Areas.Account.Models.BillChfeeDetail;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.Models.MsChFee;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using System.Data.SqlClient;
using DSWeb.MvcShipping.DAL.MsInfoClient;
2 years ago
using DSWeb.Areas.Account.Models.BSNOLB;
2 years ago
namespace DSWeb.MvcShipping.DAL.MsChDui
{
public class MsChDuiDAL
{
#region Inquery DataList
static public List<ChDui> GetDataList(int start, int limit, string strCondition, string userid, string usercode, string orgcode, string sort = null)
{
var rangstr = GetRangDAStr("", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
//sortstring = sortstring.Replace("BALRMBDR", "SUM(f.RMBDR-f.STLRMBDR)");
//sortstring = sortstring.Replace("BALRMBCR", "SUM(f.RMBCR-f.STLRMBCR)");
//sortstring = sortstring.Replace("BALUSDDR", "SUM(f.USDDR-f.STLUSDDR)");
//sortstring = sortstring.Replace("BALUSDCR", "SUM(f.USDCR-f.STLUSDCR)");
//sortstring = sortstring.Replace("BALOTDR", "SUM(f.OTDR-f.STLOTDR)");
//sortstring = sortstring.Replace("BALOTCR", "SUM(f.OTCR-f.STLOTCR)");
//sortstring = sortstring.Replace("BALTTLDR", "SUM(f.TTLDR-f.STLTTLDR)");
//sortstring = sortstring.Replace("BALTTLCR", "SUM(f.TTLCR-f.STLTTLCR)");
//sortstring = sortstring.Replace(" RMBDR ", " SUM(f.RMBDR) ");
//sortstring = sortstring.Replace(" RMBCR ", " SUM(f.RMBCR) ");
//sortstring = sortstring.Replace(" USDDR ", " SUM(f.USDDR) ");
//sortstring = sortstring.Replace(" USDCR ", " SUM(f.USDCR) ");
//sortstring = sortstring.Replace(" OTDR ", " SUM(f.OTDR) ");
//sortstring = sortstring.Replace(" OTCR ", " SUM(f.OTCR) ");
//sortstring = sortstring.Replace(" TTLDR ", " SUM(f.TTLDR) ");
//sortstring = sortstring.Replace(" TTLCR ", " SUM(f.TTLCR) ");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by DUIDATE DESC");
}
strSql.Append(@") as num , * from (select ");
// strSql.Append("SELECT ");
strSql.Append("DUINO,CUSTNAME");
strSql.Append(",DUIDATE");
strSql.Append(",OP,DUINAME");
strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,ISNOTAX,BILLSTATUS");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",SUM(f.RMBDR) AS RMBDR,SUM(f.RMBCR) RMBCR,SUM(f.RMBDR-f.STLRMBDR) AS BALRMBDR,SUM(f.RMBCR-f.STLRMBCR) AS BALRMBCR,");
strSql.Append("SUM(f.USDDR) AS USDDR,SUM(f.USDCR) USDCR");
strSql.Append(",SUM(f.USDDR-f.STLUSDDR) AS BALUSDDR,SUM(f.USDCR-f.STLUSDCR) AS BALUSDCR,SUM(f.OTDR) OTDR,SUM(f.OTCR) OTCR,");
strSql.Append("SUM(f.OTDR-f.STLOTDR) AS BALOTDR,SUM(f.OTCR-f.STLOTCR) as BALOTCR");
strSql.Append(",SUM(f.TTLDR) AS TTLDR,SUM(f.TTLCR) AS TTLCR,SUM(f.TTLDR-f.STLTTLDR) AS BALTTLDR,SUM(f.TTLCR-f.STLTTLCR) as BALTTLCR,SUM(f.NOINVOICE) as NOINVOICE");
strSql.Append(" from ch_dui ");
strSql.Append(" left join v_dui_allfee_sum f on (f.DEBITNO=ch_dui.DUINO)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append("GROUP BY DUINO,CUSTNAME");
strSql.Append(",DUIDATE");
strSql.Append(",OP,DUINAME");
strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,BILLSTATUS,ISNOTAX) as v ");
strSql.Append(@")as t ");
2 years ago
strSql.Append(string.Format("where t.num>{0} and t.num<={1} ORDER BY NUM ", start, start + limit));
2 years ago
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string userid, string usercode, string orgcode, string sort = null)
{
var rangstr = GetRangDAStr("", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT DUINO,CUSTNAME");
strSql.Append(",DUIDATE");
strSql.Append(",OP,DUINAME");
strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,ISNOTAX,BILLSTATUS");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",SUM(f.RMBDR) AS RMBDR,SUM(f.RMBCR) RMBCR,SUM(f.RMBDR-f.STLRMBDR) AS BALRMBDR,SUM(f.RMBCR-f.STLRMBCR) AS BALRMBCR,");
strSql.Append("SUM(f.USDDR) AS USDDR,SUM(f.USDCR) USDCR");
strSql.Append(",SUM(f.USDDR-f.STLUSDDR) AS BALUSDDR,SUM(f.USDCR-f.STLUSDCR) AS BALUSDCR,SUM(f.OTDR) OTDR,SUM(f.OTCR) OTCR,");
strSql.Append("SUM(f.OTDR-f.STLOTDR) AS BALOTDR,SUM(f.OTCR-f.STLOTCR) as BALOTCR");
strSql.Append(",SUM(f.TTLDR) AS TTLDR,SUM(f.TTLCR) AS TTLCR,SUM(f.TTLDR-f.STLTTLDR) AS BALTTLDR,SUM(f.TTLCR-f.STLTTLCR) as BALTTLCR,SUM(f.NOINVOICE) as NOINVOICE");
strSql.Append(" from ch_dui ");
strSql.Append(" left join v_dui_allfee_sum f on (f.DEBITNO=ch_dui.DUINO)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append("GROUP BY DUINO,CUSTNAME");
strSql.Append(",DUIDATE");
strSql.Append(",OP,DUINAME");
strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,BILLSTATUS,ISNOTAX");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by DUIDATE DESC");
}
return strSql.ToString();
}
public static int getTotalCount(string strCondition, string userid, string usercode, string companyid)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT COUNT(*) ");
strSql.Append(" from ch_dui ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + 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;
}
static public ChDui GetData(string condition, string userid, string usercode, string orgcode)
{
ChDui data = null;
2 years ago
var list = GetDataList(0,1,condition,userid,usercode,orgcode);
2 years ago
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new ChDui();
}
return data;
}
private static List<ChDui> SetData(StringBuilder strSql)
{
var headList = new List<ChDui>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChDui data = new ChDui();
#region Set DB data to Object
data.DUINO = Convert.ToString(reader["DUINO"]);
data.CUSTNAME = Convert.ToString(reader["CUSTNAME"]);
data.OP = Convert.ToString(reader["OP"]);
data.DUINAME = Convert.ToString(reader["DUINAME"]);
if (reader["BILLSTATUS"] != DBNull.Value)
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
data.DM_ID = Convert.ToString(reader["DM_ID"]);
data.DC = Convert.ToString(reader["DC"]);
data.ISNOSTL = Convert.ToString(reader["ISNOSTL"]);
data.ISNOTAX = Convert.ToString(reader["ISNOTAX"]);
if (reader["DUIDATE"] != DBNull.Value)
data.DUIDATE = Convert.ToString(reader["DUIDATE"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.BALRMBDR = Convert.ToDecimal(reader["BALRMBDR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.BALRMBCR = Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.BALUSDDR = Convert.ToDecimal(reader["BALUSDDR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.BALUSDCR = Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.BALOTDR = Convert.ToDecimal(reader["BALOTDR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.BALOTCR = Convert.ToDecimal(reader["BALOTCR"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["BALTTLDR"] != DBNull.Value)
data.BALTTLDR = Convert.ToDecimal(reader["BALTTLDR"]);
if (reader["BALTTLCR"] != DBNull.Value)
data.BALTTLCR = Convert.ToDecimal(reader["BALTTLCR"]);
if (reader["NOINVOICE"] != DBNull.Value && Convert.ToDecimal(reader["NOINVOICE"]) == 0)
data.ISINVOICE = "是";
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region Bill DataList
static public List<ChDuiBillView> GetBillList(int start, int limit, string strCondition,string sort=null)
{
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ETD,MBLNO ");
}
strSql.Append(@") as num ,v.* from (");
// strSql.Append(" ");
strSql.Append(" select d.BSNO,d.DUINO,dbo.F_GetDuiFeeStatus(d.BSNO,d.DUINO) DUIFEESTATUS");
strSql.Append(",b.OPLB,b.OPLBNAME,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMERNAME,b.VESSEL,b.VOYNO,b.ETD,b.CUSTOMNO,b.ORDERNO,b.PORTDISCHARGE");
strSql.Append(",b.ACCDATE,b.SALE,b.OP,b.CNTRTOTAL,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",f.RMBDR,f.RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.USDDR,f.USDCR");
strSql.Append(",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.OTDR,f.OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR");
strSql.Append(",f.TTLDR,f.TTLCR,f.TTLDR-f.STLTTLDR AS BALTTLDR,f.TTLCR-f.STLTTLCR as BALTTLCR,f.RMBORDERINVOICEDR,f.USDORDERINVOICEDR,f.RMBORDERAMOUNTCR,f.USDORDERAMOUNTCR");
strSql.Append(" from ch_dui_bill d ");
strSql.Append(" left join v_op_bill b on (b.BSNO=d.BSNO)");
strSql.Append(" left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" ) as V ");
strSql.Append( @")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
return SetBillData(strSql);
}
public static int getDetailTotalCount(string strCondition)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(d.BSNO) ");
strSql.Append(" from ch_dui_bill d ");
strSql.Append(" left join v_op_bill b on (b.BSNO=d.BSNO)");
strSql.Append(" left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + 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<ChDuiBillView> SetBillData(StringBuilder strSql)
{
var headList = new List<ChDuiBillView>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChDuiBillView data = new ChDuiBillView();
#region Set DB data to Object
data.DUINO = Convert.ToString(reader["DUINO"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.DUIFEESTATUS = getfeestatus(Convert.ToString(reader["DUIFEESTATUS"]));
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.OP = Convert.ToString(reader["OP"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.BALRMBDR = Convert.ToDecimal(reader["BALRMBDR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.BALRMBCR = Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.BALUSDDR = Convert.ToDecimal(reader["BALUSDDR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.BALUSDCR = Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.BALOTDR = Convert.ToDecimal(reader["BALOTDR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.BALOTCR = Convert.ToDecimal(reader["BALOTCR"]);
if (reader["TTLDR"] != DBNull.Value)
data.TTLDR = Convert.ToDecimal(reader["TTLDR"]);
if (reader["TTLCR"] != DBNull.Value)
data.TTLCR = Convert.ToDecimal(reader["TTLCR"]);
if (reader["BALTTLDR"] != DBNull.Value)
data.BALTTLDR = Convert.ToDecimal(reader["BALTTLDR"]);
if (reader["BALTTLCR"] != DBNull.Value)
data.BALTTLCR = Convert.ToDecimal(reader["BALTTLCR"]);
if (reader["RMBORDERINVOICEDR"] != DBNull.Value)
data.RMBORDERINVOICEDR = Convert.ToDecimal(reader["RMBORDERINVOICEDR"]);
if (reader["USDORDERINVOICEDR"] != DBNull.Value)
data.USDORDERINVOICEDR = Convert.ToDecimal(reader["USDORDERINVOICEDR"]);
if (reader["RMBORDERAMOUNTCR"] != DBNull.Value)
data.RMBORDERAMOUNTCR = Convert.ToDecimal(reader["RMBORDERAMOUNTCR"]);
if (reader["USDORDERAMOUNTCR"] != DBNull.Value)
data.USDORDERAMOUNTCR = Convert.ToDecimal(reader["USDORDERAMOUNTCR"]);
data.SALECORP = Convert.ToString(reader["SALECORP"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static string getfeestatus(string feestatusint)
{
var result = "";
if (feestatusint == "0:")
{
return "审核通过";
}
else if (feestatusint == "1:")
{
return "录入状态";
}
else if (feestatusint == "2:")
{
return "提交审核";
}
else if (feestatusint == "8:")
{
return "部分结算";
}
else if (feestatusint == "9:")
{
return "结算完毕";
}
else if (feestatusint == "")
{
return "未录入";
}
else if (feestatusint == "3:")
{
return "申请修改";
}
else if (feestatusint == "4:")
{
return "申请删除";
}
else if (feestatusint == "6:")
{
return "驳回提交";
}
else if (feestatusint == "7:")
{
return "驳回申请";
}
else if (feestatusint.IndexOf("9:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("8:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("0:") > -1)
{
return "部分审核";
}
else if (feestatusint.IndexOf("2:") > -1)
{
return "部分提交";
}
return result;
}
#endregion
#region detail DataList
static public List<ChDuiDetailView> GetDetailList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
2 years ago
strSql.Append("f.DUINO,f.DO_ID,f.BSNO,f.GID AS CH_ID,f.ISDEBIT");
2 years ago
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
2 years ago
strSql.Append(",f.feeName,f.customerName,f.amount,f.DEBITAMOUNT,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.NoTaxAmount,f.Remark");
2 years ago
strSql.Append(" from v_dui_fee f");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetDetailData(strSql);
}
static public ChDuiDetailView GetDetailData(string condition)
{
ChDuiDetailView data = null;
var list = GetDetailList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new ChDuiDetailView();
}
return data;
}
private static List<ChDuiDetailView> SetDetailData(StringBuilder strSql)
{
var headList = new List<ChDuiDetailView>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChDuiDetailView data = new ChDuiDetailView();
#region Set DB data to Object
2 years ago
data.DO_ID = Convert.ToString(reader["DO_ID"]);
data.ISDEBIT = Convert.ToString(reader["ISDEBIT"]);
2 years ago
data.DUINO = Convert.ToString(reader["DUINO"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.CH_ID = Convert.ToString(reader["CH_ID"]);
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeName = Convert.ToString(reader["feeName"]);
data.CustomerName = Convert.ToString(reader["customerName"]);
if (reader["Amount"] != DBNull.Value)
data.Amount = Convert.ToDecimal(reader["Amount"]);
2 years ago
if (reader["DEBITAMOUNT"] != DBNull.Value)
data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]);
2 years ago
if (reader["BalAmount"] != DBNull.Value)
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
data.Currency = Convert.ToString(reader["Currency"]);
if (reader["exChangerate"] != DBNull.Value)
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
if (reader["NoTaxAmount"] != DBNull.Value)
data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]);
data.Remark = Convert.ToString(reader["Remark"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region Inquery FeeDataList
static public List<MsOpDuiBill> GetFeeDataList(string strCondition, string strduiCondition, string isdebit, string userid, string usercode, string orgcode,string sort)
{
/*
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
strduiCondition = strduiCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
strduiCondition = rangstr;
}
}
*/
var strSql = new StringBuilder();
strSql.Append("SELECT '' AS DUINO,'否' as ISDEBIT,");
strSql.Append("BSNO,OPLB,OPLBNAME,BSSTATUS,ACCDATE,MBLNO,HBLNO,CUSTNO");
strSql.Append(",CUSTOMERNAME");
strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD");
strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE");
strSql.Append(",DOC,SALE");
strSql.Append(" from v_op_bill B ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (isdebit == "1") {
strSql.Append(" UNION ");
strSql.Append("SELECT DUINO,'是' as ISDEBIT,");
strSql.Append("BSNO,OPLB,OPLBNAME,BSSTATUS,ACCDATE,MBLNO,HBLNO,CUSTNO");
strSql.Append(",CUSTOMERNAME");
strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD");
strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE");
strSql.Append(",DOC,SALE");
strSql.Append(" from v_dui_opbill B");
if (!string.IsNullOrEmpty(strduiCondition))
{
strSql.Append(" where " + strduiCondition);
}
}
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BsNo");
}
return SetFeeData(strSql);
}
private static List<MsOpDuiBill> SetFeeData(StringBuilder strSql)
{
var headList = new List<MsOpDuiBill>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpDuiBill data = new MsOpDuiBill();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.DUINO = Convert.ToString(reader["DUINO"]);
data.ISDEBIT = Convert.ToString(reader["ISDEBIT"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToString(reader["ETD"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 添加列表
static public List<ChDuiBillView> GetAddBillList(string strCondition, string strduiCondition, string isdebit, string userid, string usercode, string orgcode, string sort)
{
var rangstr = "";
rangstr = GetBillRangDAStr("index", userid, usercode, orgcode);
var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
var isopenstr = "";
if (isopen == false)
{
isopenstr = " ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND (f.ISOPEN=0 OR f.ISOPEN IS NULL))) ";
if (!string.IsNullOrEmpty(rangstr))
rangstr = rangstr + " and " + isopenstr;
else
rangstr = isopenstr;
}
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var DUIFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='DUIFEESTATUS'");
if (DUIFEESTATUS.PARAMVALUE != "" && DUIFEESTATUS.PARAMVALUE != "1") {
var feestatusstr = " 1=1 ";
if (DUIFEESTATUS.PARAMVALUE == "2")
feestatusstr = " f.FEESTATUS<>1 ";
else if (DUIFEESTATUS.PARAMVALUE == "0")
feestatusstr = " f.FEESTATUS IN (0,8,9) ";
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + feestatusstr;
}
else
{
strCondition = feestatusstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT '' AS DUINO,'否' as ISDEBIT,");
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
strSql.Append(",b.CUSTOMERNAME");
2 years ago
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
2 years ago
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
2 years ago
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
strSql.Append(",b.CUSTOMERNAME");
2 years ago
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
2 years ago
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL,B.SALECORPID,b.FEESTATUS");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,f.CUSTOMERNAME");
var sortstring = DatasetSort.Getsortstring(sort);
if (isdebit == "1")
{
strSql.Append(" UNION ");
2 years ago
strSql.Append("SELECT F.DUINO,'是' as ISDEBIT,");
2 years ago
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
strSql.Append(",b.CUSTOMERNAME");
2 years ago
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
2 years ago
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP");
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
2 years ago
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.DEBITAMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.DEBITAMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(DEBITAMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(DEBITAMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
2 years ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
2 years ago
strSql.Append(" FROM v_dui_fee F ");
2 years ago
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
if (!string.IsNullOrEmpty(strduiCondition))
{
2 years ago
strSql.Append(" where 1=1 AND " + strduiCondition);
2 years ago
}
else {
2 years ago
strSql.Append(" where 1=1 ");
2 years ago
}
2 years ago
strSql.Append(" GROUP BY F.DUINO,b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
2 years ago
strSql.Append(",b.CUSTOMERNAME");
2 years ago
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
2 years ago
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL,B.SALECORPID,b.FEESTATUS");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,f.CUSTOMERNAME");
}
if (!string.IsNullOrEmpty(sortstring))
{
2 years ago
sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME");
2 years ago
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by b.ETD,b.MBLNO,b.BsNo");
}
return SetAddBillData(strSql);
}
private static List<ChDuiBillView> SetAddBillData(StringBuilder strSql)
{
var headList = new List<ChDuiBillView>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 120000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
ChDuiBillView data = new ChDuiBillView();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.DUINO = Convert.ToString(reader["DUINO"]);
data.ISDEBIT = Convert.ToString(reader["ISDEBIT"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToString(reader["ETD"]);
2 years ago
if (reader["ATD"] != DBNull.Value)
data.ATD = Convert.ToString(reader["ATD"]);
2 years ago
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDR = Convert.ToDecimal(reader["RMBDR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.BALRMBDR = Convert.ToDecimal(reader["BALRMBDR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCR = Convert.ToDecimal(reader["RMBCR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.BALRMBCR = Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDR = Convert.ToDecimal(reader["USDDR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.BALUSDDR = Convert.ToDecimal(reader["BALUSDDR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCR = Convert.ToDecimal(reader["USDCR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.BALUSDCR = Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDR = Convert.ToDecimal(reader["OTDR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.BALOTDR = Convert.ToDecimal(reader["BALOTDR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCR = Convert.ToDecimal(reader["OTCR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.BALOTCR = Convert.ToDecimal(reader["BALOTCR"]);
data.SALECORP = Convert.ToString(reader["SALECORP"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region SELECT SUM
public static List<SelectSum> GetSelectSum(string feesql, string duisql, string duino)
{
var evList = new List<SelectSum>();
Database db = DatabaseFactory.CreateDatabase();
if (feesql != "")
{
var strSql = new StringBuilder();
strSql.Append("SELECT A.CURRENCY,SUM(A.DR) DR,SUM(A.CR) CR,SUM(A.NODR) NODR,SUM(A.NOCR) NOCR FROM ");
strSql.Append("(SELECT CURRENCY,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NODR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NOCR from ch_fee F WHERE " + feesql + " AND (ISDEBIT=0 or ISDEBIT IS NULL) ");
strSql.Append(" GROUP BY CURRENCY");
strSql.Append(" UNION ");
strSql.Append("SELECT CURRENCY,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NODR ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NOCR from v_dui_fee F WHERE " + duisql + "and GID NOT IN (SELECT GID from v_dui_fee where duino='" + duino + "')");
strSql.Append(" GROUP BY CURRENCY) AS A ");
strSql.Append(" GROUP BY A.CURRENCY ");
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SelectSum Data = new SelectSum();
Data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
Data.DR = Convert.ToDecimal(reader["DR"]);
Data.NODR = Convert.ToDecimal(reader["NODR"]);
Data.CR = Convert.ToDecimal(reader["CR"]);
Data.NOCR = Convert.ToDecimal(reader["NOCR"]);
evList.Add(Data);
}
reader.Close();
}
}
return evList;
}
#endregion
#region feedetail DataList
static public List<ChFeeDetail> GetFeeDetailList(string strCondition,string isdebit,string userid)
{
var DUIFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='DUIFEESTATUS'");
if (DUIFEESTATUS.PARAMVALUE != "" && DUIFEESTATUS.PARAMVALUE != "1")
{
var feestatusstr = " 1=1 ";
if (DUIFEESTATUS.PARAMVALUE == "2")
feestatusstr = " f.FEESTATUS<>1 ";
else if (DUIFEESTATUS.PARAMVALUE == "0")
feestatusstr = " f.FEESTATUS IN (0,8,9) ";
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + feestatusstr;
}
else
{
strCondition = feestatusstr;
}
}
var strSql = new StringBuilder();
2 years ago
2 years ago
if (isdebit == "是")
{
strSql.Append("SELECT ");
2 years ago
strSql.Append("f.BSNO,f.GID AS CH_ID,DUINO");
2 years ago
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
2 years ago
strSql.Append(",f.feeName,f.customerName,f.amount,f.DEBITAMOUNT,f.balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE");
2 years ago
strSql.Append(" from v_dui_fee f ");
}
2 years ago
else
{
2 years ago
var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
var isopenstr = "";
if (isopen == false)
{
isopenstr = " ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND (f.ISOPEN=0 OR f.ISOPEN IS NULL))) ";
if (!string.IsNullOrEmpty(strCondition))
strCondition = strCondition + " and " + isopenstr;
else
strCondition = isopenstr;
}
strSql.Append("SELECT ");
2 years ago
strSql.Append("f.BSNO,f.GID AS CH_ID,'' DUINO");
2 years ago
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
2 years ago
strSql.Append(",f.feeName,f.customerName,f.amount,f.DEBITAMOUNT,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE");
2 years ago
strSql.Append(" from ch_fee f ");
2 years ago
2 years ago
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetFeeDetailData(strSql);
}
private static List<ChFeeDetail> SetFeeDetailData(StringBuilder strSql)
{
var headList = new List<ChFeeDetail>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 120000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
ChFeeDetail data = new ChFeeDetail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.CH_ID = Convert.ToString(reader["CH_ID"]);
2 years ago
data.DUINO = Convert.ToString(reader["DUINO"]);
2 years ago
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeName = Convert.ToString(reader["feeName"]);
data.CustomerName = Convert.ToString(reader["customerName"]);
if (reader["Amount"] != DBNull.Value)
data.Amount = Convert.ToDecimal(reader["Amount"]);
2 years ago
if (reader["DEBITAMOUNT"] != DBNull.Value)
data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]);
data.DuiAmount = data.Amount-data.DEBITAMOUNT;
2 years ago
if (reader["BalAmount"] != DBNull.Value)
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
data.Currency = Convert.ToString(reader["Currency"]);
if (reader["exChangerate"] != DBNull.Value)
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
if (reader["NoTaxAmount"] != DBNull.Value)
data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]);
data.Remark = Convert.ToString(reader["Remark"]);
2 years ago
if (reader["UNITPRICE"] != DBNull.Value)
data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]);
2 years ago
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult AddDetail(string duino,List<ChDuiDetailView> bodyList,string isdebit)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var bsno = "";
2 years ago
//if (isdebit == "是") {
var cmdinsertdetail = db.GetSqlStringCommand("insert into ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT,ISDEBIT) values (@DUINO,@BSNO,@CH_ID,@DEBITAMOUNT,@ISDEBIT)");
var cmdupdatechfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)+@DEBITAMOUNT where GID=@CH_ID");
if (bodyList != null)
2 years ago
{
foreach (var enumValue in bodyList)
{
bsno = enumValue.BSNO;
cmdinsertdetail.Parameters.Clear();
db.AddInParameter(cmdinsertdetail, "@DUINO", DbType.String, duino);
db.AddInParameter(cmdinsertdetail, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdinsertdetail, "@CH_ID", DbType.String, enumValue.CH_ID);
2 years ago
db.AddInParameter(cmdinsertdetail, "@DEBITAMOUNT", DbType.Decimal, enumValue.DuiAmount);
if (isdebit != "是")
db.AddInParameter(cmdinsertdetail, "@ISDEBIT", DbType.String, "0");
else db.AddInParameter(cmdinsertdetail, "@ISDEBIT", DbType.String, "1");
db.ExecuteNonQuery(cmdinsertdetail, tran);
if (isdebit != "是")
{
cmdupdatechfee.Parameters.Clear();
db.AddInParameter(cmdupdatechfee, "@CH_ID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdupdatechfee, "@DEBITAMOUNT", DbType.Decimal, enumValue.DuiAmount);
db.ExecuteNonQuery(cmdupdatechfee, tran);
}
2 years ago
}
}
2 years ago
//}
//else
//{
2 years ago
2 years ago
// var cmdUpdate =
// db.GetSqlStringCommand(
// @" update ch_fee set ISDEBIT=1,DEBITNO=@DUINO WHERE Gid=@CH_ID");
2 years ago
2 years ago
// if (bodyList != null)
// {
// foreach (var enumValue in bodyList)
// {
// bsno = enumValue.BSNO;
2 years ago
2 years ago
// cmdUpdate.Parameters.Clear();
// db.AddInParameter(cmdUpdate, "@CH_ID", DbType.String, enumValue.CH_ID);
// db.AddInParameter(cmdUpdate, "@DUINO", DbType.String, duino);
// db.ExecuteNonQuery(cmdUpdate, tran);
// }
// }
//}
2 years ago
var cmdinsertbill = db.GetSqlStringCommand("insert into ch_dui_bill(BSNO,DUINO) SELECT distinct BSNO, DUINO FROM v_dui_fee where DUINO = '" + duino + "' "
+ " AND NOT EXISTS (SELECT 1 from ch_dui_bill where DUINO='" + duino + "' AND BSNO=v_dui_fee.BSNO )");
//var cmd = db.GetStoredProcCommand("sMsAddChDuiBill");
//db.AddInParameter(cmd, "@ps_BsNo", DbType.String, bsno);
//db.AddInParameter(cmd, "@ps_DuiNo", DbType.String, duino);
//db.AddOutParameter(cmd, "@pi_Result", DbType.Int32, 20);
//db.AddOutParameter(cmd, "@ps_Message", DbType.String, 2000);
db.ExecuteNonQuery(cmdinsertbill, tran);
result.Success =true;
result.Message = "对账成功!";
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员"+e.Message;
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
2 years ago
public static DBResult DelDetail (List<ChDuiDetailView> bodyList )
2 years ago
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
2 years ago
var cmdinsertdetail = db.GetSqlStringCommand("delete from ch_dui_detail where DO_ID=@DO_ID");
var cmdupdatechfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)-@DEBITAMOUNT where GID=@CH_ID");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdinsertdetail.Parameters.Clear();
db.AddInParameter(cmdinsertdetail, "@DO_ID", DbType.String, enumValue.DO_ID);
db.ExecuteNonQuery(cmdinsertdetail, tran);
if (enumValue.ISDEBIT != "1")
{
cmdupdatechfee.Parameters.Clear();
db.AddInParameter(cmdupdatechfee, "@CH_ID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdupdatechfee, "@DEBITAMOUNT", DbType.Decimal, enumValue.DEBITAMOUNT);
db.ExecuteNonQuery(cmdupdatechfee, tran);
}
}
}
2 years ago
result = new DBResult();
result.Success = true;
result.Message = "成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
2 years ago
public static DBResult AddBill(string duino, string duicust, List<ChDuiBillView> workList, string feesql,string userid)
2 years ago
{
var result = new DBResult();
var custgroup = MsInfoClientDAL.GetClientGroupData("SHORTNAME='"+ duicust + "'").PCORPNAME;
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (feesql != "")
{
//while (feesql.Contains("F.")){
// feesql = feesql.Replace("F.", " ");
//}
var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
var isopenstr = "";
if (isopen == false)
{
isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) ";
if (!string.IsNullOrEmpty(feesql))
feesql = feesql + " and " + isopenstr;
else
feesql = isopenstr;
}
var DUIFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='DUIFEESTATUS'");
if (DUIFEESTATUS.PARAMVALUE != "" && DUIFEESTATUS.PARAMVALUE != "1")
{
var feestatusstr = " 1=1 ";
if (DUIFEESTATUS.PARAMVALUE == "2")
feestatusstr = " FEESTATUS<>1 ";
else if (DUIFEESTATUS.PARAMVALUE == "0")
feestatusstr = " FEESTATUS IN (0,8,9) ";
feesql = feesql + " and " + feestatusstr;
}
var custstr= " AND CUSTOMERNAME='" + duicust + "'";
if (custgroup != "") {
custstr = " AND (CUSTOMERNAME='" + duicust + "' or exists (select 1 from info_client where f.CUSTOMERNAME=info_client.SHORTNAME AND PCORPNAME='" + custgroup + "'))";
}
2 years ago
var cmdinsertdetail = db.GetSqlStringCommand("insert ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT) SELECT @DUINO,BSNO,GID,AMOUNT-ISNULL(DEBITAMOUNT,0) from ch_fee F "
+ " where " + feesql + custstr);
cmdinsertdetail.Parameters.Clear();
db.AddInParameter(cmdinsertdetail, "@DUINO", DbType.String, duino);
db.ExecuteNonQuery(cmdinsertdetail, tran);
2 years ago
//feesql = feesql.Replace("", custstr);
2 years ago
var cmdfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=AMOUNT from ch_fee f WHERE " + feesql + custstr);
2 years ago
db.AddInParameter(cmdfee, "@DUINO", DbType.String, duino);
cmdfee.CommandTimeout = 120000; //要加这一句
db.ExecuteNonQuery(cmdfee, tran);
2 years ago
2 years ago
}
if (workList != null)
{
//var cmd = db.GetStoredProcCommand("sMsAddChDuiBill");
2 years ago
var cmdinsertdetail = db.GetSqlStringCommand("insert ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT,ISDEBIT) SELECT @DUINO,@BSNO,GID,DEBITAMOUNT,'1' from v_dui_fee "
+ " where DUINO=@DUINO2 AND BSNO=@BSNO2");
2 years ago
foreach (var enumValue in workList)
{
cmdinsertdetail.Parameters.Clear();
db.AddInParameter(cmdinsertdetail, "@DUINO", DbType.String, duino);
db.AddInParameter(cmdinsertdetail, "@DUINO2", DbType.String, enumValue.DUINO);
db.AddInParameter(cmdinsertdetail, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdinsertdetail, "@BSNO2", DbType.String, enumValue.BSNO);
db.ExecuteNonQuery(cmdinsertdetail, tran);
}
}
var cmdinsertbill = db.GetSqlStringCommand("insert into ch_dui_bill(BSNO,DUINO) SELECT distinct BSNO, DUINO FROM v_dui_fee where DUINO = '" + duino + "' "
+ " AND NOT EXISTS (SELECT 1 from ch_dui_bill where DUINO='" + duino + "' AND BSNO=v_dui_fee.BSNO )");
db.ExecuteNonQuery(cmdinsertbill, tran);
result = new DBResult();
result.Success =true;
result.Message ="成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult UpdateBill(string duino)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdbill = db.GetSqlStringCommand("insert ch_dui_bill(DUINO,BSNO) SELECT DUINO DEBITNO,BSNO from ch_dui_detail WHERE DUINO='"+duino+"'");
db.ExecuteNonQuery(cmdbill, tran);
result = new DBResult();
result.Success = true;
result.Message = "成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult DelBill ( string duino, string feesql)
{
var result = new DBResult();
2 years ago
var feeduilist=GetDetailList(feesql+ " and DUINO='"+ duino + "'");
2 years ago
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
2 years ago
if (feeduilist != null) {
foreach (var feedui in feeduilist) {
var cmdbillfee = db.GetSqlStringCommand("delete from ch_dui_detail WHERE DO_ID=" + feedui.DO_ID);
db.ExecuteNonQuery(cmdbillfee, tran);
if (feedui.ISDEBIT != "1")
{
var cmdfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)-" + feedui.DEBITAMOUNT + " where GID='" + feedui.CH_ID+"'");
db.ExecuteNonQuery(cmdfee, tran);
}
}
}
2 years ago
var cmdbill = db.GetSqlStringCommand("delete from ch_dui_bill WHERE DUINO='"+duino+"' and " + feesql);
db.ExecuteNonQuery(cmdbill, tran);
2 years ago
2 years ago
var cmdautodui = db.GetSqlStringCommand("update ch_fee_autoDui set DUINO='' where DUINO='" + duino + "'");
db.ExecuteNonQuery(cmdautodui, tran);
result = new DBResult();
result.Success = true;
result.Message = "成功";
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误<"+e.Message+">,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
2 years ago
static public List<BSNOLB> GetDuiPayBodyList(string duino)
{
var strSql = new StringBuilder();
strSql.Append("select distinct BSNO,MBLNO FROM v_op_bill WHERE BSNO IN (");
strSql.Append("SELECT BSNO FROM v_dui_fee WHERE DUINO='"+ duino + "'");
strSql.Append(" AND ((AMOUNT >= 0 AND((BALAMOUNT < DEBITAMOUNT) OR(DEBITAMOUNT > (AMOUNT - ORDERAMOUNT))))");
strSql.Append(" OR(AMOUNT < 0 AND((DEBITAMOUNT < BALAMOUNT) OR(DEBITAMOUNT < (AMOUNT - ORDERAMOUNT))))))");
strSql.Append(") ");
return SetDuiPayBodyData(strSql);
}
private static List<BSNOLB> SetDuiPayBodyData(StringBuilder strSql)
{
var bodyList = new List<BSNOLB>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BSNOLB data = new BSNOLB();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.CUSTNO = Convert.ToString(reader["MBLNO"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
public static string IsDuiPayStr(string duino = "")
{
var error = "";
var duipanylist = GetDuiPayBodyList(duino);
if (duipanylist != null && duipanylist.Count!=0) {
foreach (var duipay in duipanylist) {
{ error = error + "<br />"+duipay.CUSTNO; }
}
}
return error;
}
#region 参照部分
2 years ago
2 years ago
public static String GetPrintStr(ChDui headData)
2 years ago
{
var sqlstr = " SELECT d.DB_ID,d.DUINO,b.*,dbo.GetOtherFee(b.bsno,d.DUINO,u.DM_ID,1,'" + headData.ISNOSTL + "') as OTHERDRFEESTR,dbo.GetOtherFee(b.bsno,d.DUINO,u.DM_ID,2,'" + headData.ISNOSTL + "') as OTHERCRFEESTR"
+",f.RMBDR,f.RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.USDDR,f.USDCR"
+",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.OTDR,f.OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR"
+ ",O.OTHERUSDDR,O.OTHERUSDCR,O.OTHEROTDR,O.OTHEROTCR,O.OTHERRMBDR,O.OTHERRMBCR,O.OTHERTTLDR,O.OTHERTTLCR";
var fieldnamestr = "";
var fieldnamesumstr = "SELECT BSNO ";
var strSql = new StringBuilder();
strSql.Append("Select FEETYPE,FEENAME,CURRENCY ");
strSql.Append(" from code_dui_format_fee ");
strSql.Append(" where DM_ID='"+headData.DM_ID+"'");
strSql.Append(" order by FEENAME");
Database db = DatabaseFactory.CreateDatabase();
if (headData.ISNOSTL == "B")
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]);
fieldnamestr = fieldnamestr + "," + fieldname;
fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN "
+ "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname;
}
reader.Close();
}
sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+ "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr
+ " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+ " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) "
+ " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END)"
+ " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END) "
+ " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(BALAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+ " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(BALAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+ " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+ " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'";
}
else
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]);
fieldnamestr = fieldnamestr + "," + fieldname;
fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN "
+ "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname;
}
reader.Close();
}
sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+ "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr
+ " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+ " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) "
+ " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)"
+ " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) "
+ " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+ " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+ " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+ " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'";
}
var sortSql = new StringBuilder();
sortSql.Append("Select FIELDNAME,SORTTYPE ");
sortSql.Append(" from code_dui_format_sort ");
sortSql.Append(" where DM_ID='" + headData.DM_ID + "'");
sortSql.Append(" order by SORTNUM");
var sortstr = "";
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sortSql.ToString()))
{
while (reader.Read())
{
var fieldname ="b."+ Convert.ToString(reader["FIELDNAME"]);
if (Convert.ToInt16(reader["SORTTYPE"]) == 2) {
fieldname = fieldname + " DESC ";
};
if (sortstr == "")
{
sortstr = fieldname;
}
else {
sortstr =sortstr+","+fieldname;
}
}
reader.Close();
}
sqlstr = sqlstr +" order by "+sortstr;
return sqlstr;
}
public static String GetNoTaxPrintStr(ChDui headData)
{
var sqlstr = " SELECT d.DB_ID,d.DUINO,b.*,dbo.GetNoTaxOtherFee(b.bsno,d.DUINO,u.DM_ID,1,'" + headData.ISNOSTL + "') as OTHERDRFEESTR,dbo.GetNoTaxOtherFee(b.bsno,d.DUINO,u.DM_ID,2,'" + headData.ISNOSTL + "') as OTHERCRFEESTR"
+ ",f.NOTAXRMBDR RMBDR,f.NOTAXRMBCR RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.NOTAXUSDDR USDDR,f.NOTAXUSDCR USDCR"
+ ",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.NOTAXOTDR OTDR,f.NOTAXOTCR OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR"
+ ",O.OTHERUSDDR,O.OTHERUSDCR,O.OTHEROTDR,O.OTHEROTCR,O.OTHERRMBDR,O.OTHERRMBCR,O.OTHERTTLDR,O.OTHERTTLCR";
var fieldnamestr = "";
var fieldnamesumstr = "SELECT BSNO ";
var strSql = new StringBuilder();
strSql.Append("Select FEETYPE,FEENAME,CURRENCY ");
strSql.Append(" from code_dui_format_fee ");
strSql.Append(" where DM_ID='" + headData.DM_ID + "'");
strSql.Append(" order by FEENAME");
Database db = DatabaseFactory.CreateDatabase();
if (headData.ISNOSTL == "B")
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]);
fieldnamestr = fieldnamestr + "," + fieldname;
fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN "
+ "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname;
}
reader.Close();
}
sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+ "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr
+ " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+ " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) "
+ " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END)"
+ " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END) "
+ " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(BALAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+ " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(BALAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+ " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+ " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'";
}
else
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]);
fieldnamestr = fieldnamestr + "," + fieldname;
fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN "
+ "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname;
}
reader.Close();
}
sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) "
+ "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr
+ " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join ("
+ " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) "
+ " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END)"
+ " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) "
+ " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)"
+ " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR,"
+ " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR"
+ " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)"
+ " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'";
}
var sortSql = new StringBuilder();
sortSql.Append("Select FIELDNAME,SORTTYPE ");
sortSql.Append(" from code_dui_format_sort ");
sortSql.Append(" where DM_ID='" + headData.DM_ID + "'");
sortSql.Append(" order by SORTNUM");
var sortstr = "";
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sortSql.ToString()))
{
while (reader.Read())
{
var fieldname = "b." + Convert.ToString(reader["FIELDNAME"]);
if (Convert.ToInt16(reader["SORTTYPE"]) == 2)
{
fieldname = fieldname + " DESC ";
};
if (sortstr == "")
{
sortstr = fieldname;
}
else
{
sortstr = sortstr + "," + fieldname;
}
}
reader.Close();
}
sqlstr = sqlstr + " order by " + sortstr;
return sqlstr;
}
#region 提交审核和撤销审核
public static DBResult Lock(string bill)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=1 where DUINO=@DUINO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "锁定成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "锁定错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult LockList(String bills)
{
var result = new DBResult();
var billList = bills.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var bill in billList)
{
var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=1 where DUINO=@DUINO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "锁定成功";
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "锁定错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult UnLock(String bill)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=2 where DUINO=@DUINO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "撤销锁定成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销锁定错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult UnLockList(String bills)
{
var result = new DBResult();
var billList = bills.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var bill in billList)
{
var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=2 where DUINO=@DUINO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "撤销锁定成功";
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销锁定错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult SubmitFee(string bill,string userid,string companyid)
{
var result = new DBResult();
var billList = MsChDuiDAL.GetBillList(0, 1,"DUINO='"+bill+"'","");
var optype = "op_seae";
if (billList != null && billList.Count != 0) {
optype = billList[0].OPLB;
}
try
{
2 years ago
foreach (var headdata in billList)
{
2 years ago
2 years ago
var dataList = DSWeb.MvcShipping.DAL.MsChFeeDAL.MsChFeeDAL.GetAllDataList("DEBITNO='" + bill + "' AND FEESTATUS=1 AND BSNO='"+headdata.BSNO+"' ");
if (dataList != null && dataList.Count != 0)
{
optype = headdata.OPLB;
result = Chfee_AuditDAL.Chfee_AuditDAL.SubmitAuditNew(optype, userid, dataList, false, "", "0", companyid);
2 years ago
2 years ago
}
else
{
2 years ago
2 years ago
result = new DBResult();
result.Success = true;
result.Message = "提交成功(没有数据要提交)";
}
}
2 years ago
}
catch (Exception)
{
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
return result;
}
return result;
}
public static DBResult SubmitFeeList(String bills, string userid, string companyid)
{
var result = new DBResult();
var billList = bills.Split(',');
try
{
foreach (var bill in billList)
{
var bsList = MsChDuiDAL.GetBillList(0, 1, "DUINO='" + bill + "'", "");
var optype = "op_seae";
2 years ago
//if (bsList != null && bsList.Count != 0)
//{
// optype = bsList[0].OPLB;
2 years ago
2 years ago
//}
2 years ago
2 years ago
foreach (var bs in bsList)
2 years ago
{
2 years ago
var dataList = DSWeb.MvcShipping.DAL.MsChFeeDAL.MsChFeeDAL.GetAllDataList("DEBITNO='" + bill + "' AND FEESTATUS=1 and BSNO='"+bs.BSNO+"'");
if (dataList != null && dataList.Count != 0)
{
optype = bs.OPLB;
result = Chfee_AuditDAL.Chfee_AuditDAL.SubmitAuditNew(optype, userid, dataList, false, "", "0", companyid);
2 years ago
2 years ago
}
else
{
2 years ago
2 years ago
result = new DBResult();
result.Success = true;
result.Message = "提交成功(没有数据要提交)";
}
2 years ago
}
}
}
catch (Exception)
{
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
return result;
}
return result;
}
#endregion
public static string GetBillRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modChDuiAddBillList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
string VSSQL = "";
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"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
VSSQL = Convert.ToString(reader["VSSQL"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (b.OP='" + username + "' OR b.SALE='" + username + "' OR b.DOC='" + username + "' OR b.CUSTSERVICE='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (b.OP='" + username + "' OR b.SALE='" + username + "' OR b.DOC='" + username + "' OR b.CUSTSERVICE='" + username + "' )";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (b.OP in (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 + "'))"
+ " OR b.SALE in (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 + "'))"
+ " OR b.DOC in (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 + "'))"
+ " OR b.CUSTSERVICE in (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 + "'))"
+ " )";
}
else if (visiblerange == "1")
{
str = " (b.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR b.SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR b.DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR b.CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " )";
}
else if (visiblerange == "5")
{
if (tb == "index")
{
var userstr = new StringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (B.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or B.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "' ";
}
else
{
str = str + " or B.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or B.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else
{
str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') ";
}
}
else if (visiblerange == "6")
{
if (tb == "index")
{
str = " EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where (B.OP=U.SHOWNAME OR B.SALE=U.SHOWNAME OR B.CUSTSERVICE=U.SHOWNAME OR B.DOC=U.SHOWNAME OR B.FRCUSTSERVICE=U.SHOWNAME OR B.INPUTBY=U.SHOWNAME) AND P.userid='" + userid + "' and P.AUTHORITYID='" + AUTHORITYID + "' and P.VISIBLERANGE=1) ";
}
else
{
str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') ";
}
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
return str;
}
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modChDuiFeeList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
string VSSQL = "";
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"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
VSSQL = Convert.ToString(reader["VSSQL"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (OP='" + username /*+ "' OR INPUTBY='" + username*/ + "')";
}
else if (visiblerange == "3")
{
str = " (OP='" + username /*+ "' OR INPUTBY='" + username*/ + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID=(select GID from [company] where codename='" + companyid + "')) and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))";
//+ " OR INPUTBY in (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 + "')))";
}
else if (visiblerange == "1")
{
str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID=(select GID from [company] where codename='" + companyid + "'))))";
//+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')))";
}
else if (visiblerange == "5")
{
var userstr = new StringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "'";
}
else
{
str = str + " or COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "6")
{
var userstr = new StringBuilder();
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (OP='" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
str = str + " or OP='" + Convert.ToString(reader["SHOWNAME"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
return str;
}
#endregion
}
}