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.

2201 lines
102 KiB
C#

10 months 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;
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,string lan="")
{
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");
if (lan=="en-us")
strSql.Append(",(select EnumValueName_2 from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF");
else
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 ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} ORDER BY NUM ", start, start + limit));
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;
var list = GetDataList(0,1,condition,userid,usercode,orgcode);
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 ");
strSql.Append("f.DUINO,f.BSNO,f.GID AS CH_ID");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.NoTaxAmount,f.Remark");
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
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"]);
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;
strduiCondition = strduiCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
strduiCondition = 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");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.INSPECTIONNO,b.CONTRACTNO,(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 ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,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) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
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,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,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) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
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,");
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) 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) END) END)ELSE 0 END),0) AS OTCR,");
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");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
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,b.INSPECTIONNO,b.CONTRACTNO,f.CUSTOMERNAME");
var sortstring = DatasetSort.Getsortstring(sort);
if (isdebit == "1")
{
strSql.Append(" UNION ");
strSql.Append("SELECT F.DEBITNO 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");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.INSPECTIONNO,b.CONTRACTNO,(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 ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,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) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
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,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,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) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
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,");
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) 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) END) END)ELSE 0 END),0) AS OTCR,");
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(strduiCondition))
{
strSql.Append(" where F.ISDEBIT=1 AND " + strduiCondition);
}
else {
strSql.Append(" where F.ISDEBIT=1 " );
}
strSql.Append(" GROUP BY F.DEBITNO,b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
strSql.Append(",b.CUSTOMERNAME");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD");
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,b.INSPECTIONNO,b.CONTRACTNO,f.CUSTOMERNAME");
}
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME");
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"]);
if (reader["ATD"] != DBNull.Value)
data.ATD = Convert.ToString(reader["ATD"]);
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"]);
data.INSPECTIONNO = Convert.ToString(reader["INSPECTIONNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
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,string sort=null)
{
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 * from (");
if (isdebit == "是")
{
strSql.Append("SELECT ");
strSql.Append("f.BSNO,f.GID AS CH_ID");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName,f.amount,f.balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE");
strSql.Append(" from v_dui_fee f ");
}
else {
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 ");
strSql.Append("f.BSNO,f.GID AS CH_ID");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE");
strSql.Append(" from ch_fee f ");
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" ) as v ");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by feeName ");
}
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"]);
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"]);
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"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]);
#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 = "";
if (isdebit == "是") {
var cmdinsertdetail = db.GetSqlStringCommand("insert into ch_dui_detail(DUINO,BSNO,CH_ID) values (@DUINO,@BSNO,@CH_ID)");
if (bodyList != null)
{
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);
db.ExecuteNonQuery(cmdinsertdetail, tran);
}
}
}
else
{
var cmdUpdate =
db.GetSqlStringCommand(
@" update ch_fee set ISDEBIT=1,DEBITNO=@DUINO WHERE Gid=@CH_ID");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
bsno = enumValue.BSNO;
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@CH_ID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdate, "@DUINO", DbType.String, duino);
db.ExecuteNonQuery(cmdUpdate, 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 )");
//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;
}
public static DBResult DelDetail ( string feesql, string duisql )
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdfee = db.GetSqlStringCommand("update ch_fee set ISDEBIT=0,DEBITNO='' WHERE " + feesql);
db.ExecuteNonQuery(cmdfee, tran);
var deletefee = db.GetSqlStringCommand("delete from ch_dui_detail WHERE " + duisql);
db.ExecuteNonQuery(deletefee, 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 AddBill(string duino, string duicust, List<MsOpDuiBill> workList,string feesql,string userid)
{
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 + "'))";
}
//feesql = feesql.Replace("", custstr);
var cmdfee = db.GetSqlStringCommand("update ch_fee set ISDEBIT=1,DEBITNO=@DUINO from ch_fee f WHERE " + feesql + custstr+" AND (ISDEBIT=0 or ISDEBIT IS NULL) ");
db.AddInParameter(cmdfee, "@DUINO", DbType.String, duino);
cmdfee.CommandTimeout = 120000; //要加这一句
db.ExecuteNonQuery(cmdfee, tran);
//var cmd = db.GetSqlStringCommand("insert ch_dui_bill(DUINO,BSNO) SELECT @DUINO,BSNO from v_op_bill where EXISTS (select 1 FROM ch_fee where DEBITNO=@DUINO and ch_fee.BSNO=v_op_bill.BSNO)"
//+ " and not EXISTS (select 1 from ch_dui_bill where duino=@DUINO2 and ch_dui_bill.BSNO=v_op_bill.BSNO)");
//db.AddInParameter(cmd, "@DUINO", DbType.String, duino);
//db.AddInParameter(cmd, "@DUINO2", DbType.String, duino);
//cmd.CommandTimeout = 120000; //要加这一句
//db.ExecuteNonQuery(cmd, tran);
}
if (workList != null)
{
//var cmd = db.GetStoredProcCommand("sMsAddChDuiBill");
var cmdinsertdetail = db.GetSqlStringCommand("insert ch_dui_detail(DUINO,BSNO,CH_ID) SELECT @DUINO,@BSNO,GID from ch_fee "
+ " where DEBITNO=@DUINO2 AND BSNO=@BSNO2");
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();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
//var feelist = MsChFeeDAL.MsChFeeDAL.GetAllDataList(" exists(select 1 from V_dui_fee where duino='" + duino + "') ");
//var nofeelist = MsChFeeDAL.MsChFeeDAL.GetAllDataList(" exists(select 1 from V_dui_fee where duino='" + duino + "') ");
//var makeNewDUINO = db.GetSqlStringCommand("update ch_fee set DEBITNO=(select min(duino) from ch_dui_detail where CH_ID=ch_fee.GID and DUINO<>ch_fee.DEBITNO) where EXISTS(select 1 from v_dui_fee where gid=ch_fee.gid and DUINO='" + duino + "') and DEBITNO='" + duino + "'");
//db.ExecuteNonQuery(makeNewDUINO, tran);
//用于将“还有退路”即ch_fee 的debitno=duino ,同时还存在其他对账单(在ch_dui_detail当中有"其他"对账单明细)的费用,其对账编号改为最旧的"其他对账单"
//这样将不会导致删除某费用的第一个对账单时 将该费用的对账状态变为未对账。
var cmdfee = db.GetSqlStringCommand("update ch_fee set ISDEBIT=0,DEBITNO='' WHERE DEBITNO='" + duino + "' and " + feesql);
db.ExecuteNonQuery(cmdfee, tran);
var cmdbill = db.GetSqlStringCommand("delete from ch_dui_bill WHERE DUINO='"+duino+"' and " + feesql);
db.ExecuteNonQuery(cmdbill, tran);
var cmdbillfee = db.GetSqlStringCommand("delete from ch_dui_detail WHERE DUINO='" + duino + "' and " + feesql);
db.ExecuteNonQuery(cmdbillfee, tran);
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;
}
#region 参照部分
public static String GetPrintStr(ChDui headData)
{
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"]).Replace("-", "") + 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"]).Replace("-","") + 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"]).Replace("-", "") + 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"]).Replace("-", "") + 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, 1000,"DUINO='"+bill+"'","");
var optype = "op_seae";
if (billList != null && billList.Count != 0) {
optype = billList[0].OPLB;
}
try
{
foreach (var headdata in billList)
{
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);
}
else
{
result = new DBResult();
result.Success = true;
result.Message = "提交成功(没有数据要提交)";
}
}
}
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, 1000, "DUINO='" + bill + "'", "");
var optype = "op_seae";
foreach (var bs in bsList)
{
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);
}
else
{
result = new DBResult();
result.Success = true;
result.Message = "提交成功(没有数据要提交)";
}
}
}
}
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 + "'))"
//+ " )";
var deptid = rangeDa.GetDEPTGID(userid);
str = $" exists(select 1 from vw_user where deptgid='{deptid}' and SHOWNAME in(B.OP,B.SALE,B.CUSTSERVICE,B.DOC)) ";
}
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 + "'))"
//+ " )";
str = $" exists(select 1 from vw_user where COMPANYID='{companyid}' and SHOWNAME in(B.OP,B.SALE,B.CUSTSERVICE,B.DOC)) ";
}
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")
{
str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID IN (select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1))))";
//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
}
}