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/Account/DAL/Chfee_Invoicehexiao/Chfee_InvoicehexiaoDAL.cs

3167 lines
143 KiB
C#

2 years ago
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.Account.Models.Chfee_Invoicehexiao;
using DSWeb.Areas.Account.Models.Chfee_do_detail;
using DSWeb.Areas.Account.Models.Chfee_do_Sum;
using DSWeb.Areas.Account.Models.MsOpBill;
using DSWeb.Areas.Account.Models.ChfeeDetail;
using DSWeb.Areas.Account.Models.Chfee_Exrate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using DSWeb.EntityDA;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Account.Models.BillChfeeDetail;
using DSWeb.Areas.Account.Models.Chfee_Payapplication;
using DSWeb.Areas.Account.Models.TruckChfee_do_detail;
namespace DSWeb.Areas.Account.DAL.Chfee_Invoicehexiao
{
public partial class ChinvoicehexiaoDAL
{
#region 发票核销列表
static public List<ChInvoicehexiao> GetDataList(int start, int limit, string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
{
if (userid != "")
{
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))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by OPDATE DESC");
}
strSql.Append(@") as num , ");
strSql.Append(" BILLNO,BILLSTATUS,CUSTOMERNAME,INVNO,INVOICECUSTNAME, ");
strSql.Append("CURR,AMOUNT,REMARKS,INVDATE,TAXCODE,INVOICECATEGORY");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=ch_fee_invoicehexiao.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",ADDRTEL,BANK,OP,OPDATE,INVAMOUNT,TAXRATE,TAX,BALBILLNO,ISAPP,dbo.GetPayNoByInvHxNo(BILLNO) as PAYBILLNO,dbo.GetStlNoByInvHxNo(BILLNO) as STLBILLNO,YuanBiJinE ");
2 years ago
strSql.Append(",SALECORPID,(select [NAME] from [company] where GID=ch_fee_invoicehexiao.SALECORPID) as SALECORP,SUBMITOP");
strSql.Append(",AUDITUSER,AUDITTIME,(select ShowName from [user] where GID=ch_fee_invoicehexiao.AUDITUSER) as AUDITUSERREF");
strSql.Append(",MODIFIEDUSER,MODIFIEDTIME,(select ShowName from [user] where GID=ch_fee_invoicehexiao.MODIFIEDUSER) as MODIFIEDUSERREF");
1 year ago
2 years ago
strSql.Append(" FROM ch_fee_invoicehexiao where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
return SetData(strSql);
}
public static int getTotalCount(string strCondition, string userid, string usercode, string companyid)
{
var rangstr = GetRangDAStr("", 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_fee_invoicehexiao where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
static public ChInvoicehexiao GetData(string condition)
{
var list = GetDataList(0,1,condition);
if (list.Count > 0)
return list[0];
return new ChInvoicehexiao();
}
static public List<ChInvoicehexiao> GetAuditDataList(string strCondition, string userid, string isaudit, string username, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT i.BILLNO,i.BILLSTATUS,i.CUSTOMERNAME,i.INVNO,i.INVOICECUSTNAME, ");
strSql.Append("i.CURR,i.AMOUNT,i.REMARKS,i.INVDATE,i.TAXCODE,i.INVOICECATEGORY");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=i.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",i.ADDRTEL,i.BANK,i.OP,i.OPDATE,i.INVAMOUNT,i.TAXRATE,i.TAX,i.BALBILLNO,i.YuanBiJinE,i.ISAPP,dbo.GetPayNoByInvHxNo(i.BILLNO) as PAYBILLNO,dbo.GetStlNoByInvHxNo(BILLNO) as STLBILLNO ");
2 years ago
strSql.Append(",i.SALECORPID,(select [NAME] from [company] where GID=i.SALECORPID) as SALECORP,i.SUBMITOP");
strSql.Append(",AUDITUSER,AUDITTIME,(select ShowName from [user] where GID=i.AUDITUSER) as AUDITUSERREF");
strSql.Append(",MODIFIEDUSER,MODIFIEDTIME,(select ShowName from [user] where GID=i.MODIFIEDUSER) as MODIFIEDUSERREF");
2 years ago
strSql.Append(" FROM ch_fee_invoicehexiao i left join workflow_using wu on wu.bsno=i.billno where 1=1 ");
if (isaudit == "1")
strSql.Append(" and i.BILLSTATUS='提交审核' and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 ");
else if (isaudit == "2")
strSql.Append(" and i.BILLSTATUS='审核通过' AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) ");
else if (isaudit == "")
{
//strSql.Append(" and (dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 ");
//strSql.Append(" or (I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ))) ");
var rangstr = GetAuditRangDAStr("", userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
strSql.Append(" and " + rangstr);
}
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by OPDATE DESC");
}
return SetData(strSql);
}
private static List<ChInvoicehexiao> SetData(StringBuilder strSql)
{
var headList = new List<ChInvoicehexiao>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChInvoicehexiao data = new ChInvoicehexiao();
#region Set DB data to Object
data.BILLNO = Convert.ToString(reader["BILLNO"]);
data.BILLSTATUS = Convert.ToString(reader["BILLSTATUS"]);
data.INVOICECUSTNAME = Convert.ToString(reader["INVOICECUSTNAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.INVNO = Convert.ToString(reader["INVNO"]);
data.OP = Convert.ToString(reader["OP"]);
data.CURR = Convert.ToString(reader["CURR"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
if (reader["INVAMOUNT"] != DBNull.Value)
data.INVAMOUNT = Convert.ToDecimal(reader["INVAMOUNT"]);
if (reader["TAXRATE"] != DBNull.Value)
data.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]);
if (reader["TAX"] != DBNull.Value)
data.TAX = Convert.ToDecimal(reader["TAX"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.INVDATE = Convert.ToString(reader["INVDATE"]);
data.TAXCODE = Convert.ToString(reader["TAXCODE"]);
data.ADDRTEL = Convert.ToString(reader["ADDRTEL"]);
data.BANK = Convert.ToString(reader["BANK"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.BALBILLNO = Convert.ToString(reader["BALBILLNO"]);
data.PAYBILLNO = Convert.ToString(reader["PAYBILLNO"]);
data.YuanBiJinE = Convert.ToString(reader["YuanBiJinE"]);
if (reader["ISAPP"] != DBNull.Value)
data.ISAPP = Convert.ToBoolean(reader["ISAPP"]);
data.INVOICECATEGORY = Convert.ToString(reader["INVOICECATEGORY"]);
data.INVOICECATEGORYREF = Convert.ToString(reader["INVOICECATEGORYREF"]);
data.STLBILLNO = Convert.ToString(reader["STLBILLNO"]);
data.SALECORPID = Convert.ToString(reader["SALECORPID"]);//分公司代码
data.SALECORP = Convert.ToString(reader["SALECORP"]);//分公司代码
2 years ago
data.SUBMITOP = Convert.ToString(reader["SUBMITOP"]);//分公司代码
1 year ago
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd hh:mm:ss");
1 year ago
data.AUDITUSER = Convert.ToString(reader["AUDITUSER"]);
data.AUDITUSERREF = Convert.ToString(reader["AUDITUSERREF"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd hh:mm:ss");
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDUSERREF = Convert.ToString(reader["MODIFIEDUSERREF"]);
2 years ago
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 发票核销费用明细
static public List<Chfee_do_detail> GetBodyList(string strCondition,string sort=null)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT c.GID,c.BSNO,c.FEEID,c.FEETYPE,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,c.EXCHANGERATE ");
2 years ago
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
2 years ago
strSql.Append(",b.CUSTOMERNAME");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
2 years ago
strSql.Append(",b.DOC,b.SALE,f.TaxUnitPrice,f.Quantity,f.taxrate,f.amount-f.notaxamount TAX");
1 year ago
strSql.Append(",f.UNIT UNIT");
1 year ago
strSql.Append(",b.DESTINATION,b.GOODSNAME");
2 years ago
strSql.Append(" FROM ch_fee_do_invoice c");
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
2 years ago
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
2 years ago
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by c.CREATETIME,b.ETD,b.MBLNO ");
}
return BodySetData(strSql);
}
private static List<Chfee_do_detail> BodySetData(StringBuilder strSql)
{
var headList = new List<Chfee_do_detail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Chfee_do_detail data = new Chfee_do_detail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.FEEDOID = Convert.ToString(reader["GID"]);
data.FEEID = Convert.ToString(reader["FEEID"]);
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
data.DOAMOUNT = Convert.ToDecimal(reader["DOAMOUNT"]);
data.ORIGCURRENCY = Convert.ToString(reader["ORIGCURRENCY"]);
data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"]);
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToString(reader["ETD"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
2 years ago
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
2 years ago
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"]);
1 year ago
data.DESTINATION = Convert.ToString(reader["DESTINATION"]);
2 years ago
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"]);
1 year ago
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
2 years ago
if (reader["BSSTATUS"] != DBNull.Value)
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
2 years ago
if (reader["TaxUnitPrice"] != DBNull.Value)
data.TaxUnitPrice = Convert.ToDecimal(reader["TaxUnitPrice"]);
if (reader["Quantity"] != DBNull.Value)
data.Quantity = Convert.ToDecimal(reader["Quantity"]);
if (reader["TaxRate"] != DBNull.Value)
data.TaxRate = Convert.ToDecimal(reader["TaxRate"]);
if (reader["Tax"] != DBNull.Value)
data.Tax = Convert.ToDecimal(reader["Tax"]);
1 year ago
data.UNIT = Convert.ToString(reader["UNIT"]);
2 years ago
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<TruckChfee_do_detail> GetTruckBodyList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT c.GID,c.BSNO,c.FEEID,c.FEETYPE,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,c.EXCHANGERATE ");
strSql.Append(" ,B.TRANSTYPE,B.TRANSSTATUS,B.CUSTOMERNAME,B.CUSTNO,B.CONTRACTNO,B.ORDERNO,B.BSDATE,B.MBLNO,B.CNTRTOTAL,");
strSql.Append("B.ETD,B.ETA,B.OP,B.SALE,B.CUSTSERVICE,B.CUSTATTN,B.CUSTTEL,B.CONSIGNEENAME,B.CONSIGNEEATTN,B.CONSIGNEETEL,B.CONSIGNEEADDR,");
strSql.Append("B.PORTLOAD,B.PORTDISCHARGE,B.GOODSNAME,B.KGS,B.NETWEIGHT,B.CBM,B.PKGS,B.KINDPKGS,B.TRUCKER,B.TRUCKNO");
strSql.Append(" FROM ch_fee_do_invoice c");
strSql.Append(" left join v_op_truck_bulk b on (b.bsno=c.bsno)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by c.CREATETIME,b.ETD,b.MBLNO ");
}
return TruckBodySetData(strSql);
}
private static List<TruckChfee_do_detail> TruckBodySetData(StringBuilder strSql)
{
var headList = new List<TruckChfee_do_detail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
TruckChfee_do_detail data = new TruckChfee_do_detail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.FEEDOID = Convert.ToString(reader["GID"]);
data.FEEID = Convert.ToString(reader["FEEID"]);
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
data.DOAMOUNT = Convert.ToDecimal(reader["DOAMOUNT"]);
data.ORIGCURRENCY = Convert.ToString(reader["ORIGCURRENCY"]);
data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"]);
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToString(reader["ETD"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 发票核销费用明细金额币别合计
static public List<Chfee_do_Sum> GetBodySumList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT c.FEETYPE,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,c.ORIGCURRENCY CURRENCY,Sum(c.ORIGAMOUNT) AMOUNT ");
strSql.Append(" FROM ch_fee_do_invoice c");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
}
strSql.Append(" Group by c.FEETYPE,c.ORIGCURRENCY");
return BodySumSetData(strSql);
}
private static List<Chfee_do_Sum> BodySumSetData(StringBuilder strSql)
{
var headList = new List<Chfee_do_Sum>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Chfee_do_Sum data = new Chfee_do_Sum();
#region Set DB data to Object
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region Inquery FeeDataList
static public List<MsOpBill> GetFeeDataList(string strCondition,string isdebit, string userid, string usercode, string orgcode, string sort)
{
var rangstr = GetRangDASearchStr("index", 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 ");
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,SALECORPID");
strSql.Append(" from v_op_bill b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BsNo");
}
return SetFeeData(strSql);
}
private static List<MsOpBill> SetFeeData(StringBuilder strSql)
{
var headList = new List<MsOpBill>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpBill data = new MsOpBill();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
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;
}
static public List<BillTruckCustDetail> GetTruckFeeDataList(string strCondition, string isdebit, string userid, string usercode, string orgcode, string sort)
{
var rangstr = GetRangDASearchStr("index", 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 ");
strSql.Append("b.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE,");
strSql.Append("b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR,");
strSql.Append("b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO");
strSql.Append(" from v_op_truck_bulk b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BsNo");
}
return SetTruckFeeData(strSql);
}
private static List<BillTruckCustDetail> SetTruckFeeData(StringBuilder strSql)
{
var headList = new List<BillTruckCustDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BillTruckCustDetail data = new BillTruckCustDetail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);
if (reader["NETWEIGHT"] != DBNull.Value)
data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]);
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 添加列表
11 months ago
static public List<BillCustDetail> GetAddBillList(string strCondition, string userid, string usercode, string orgcode, string sort)
2 years ago
{
var rangstr = GetRangDASearchStr("index", 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 ");
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
strSql.Append(",b.CUSTOMERNAME");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO");
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 ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
11 months ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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) 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 ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
11 months ago
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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) 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 ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
11 months 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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
2 years ago
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
11 months ago
strSql.Append(" where F.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
2 years ago
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
strSql.Append("GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
strSql.Append(",b.CUSTOMERNAME");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,F.CUSTOMERNAME");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by b.BsNo");
}
return SetAddBillData(strSql);
}
11 months ago
public static int getAddBillTotalCount(string strCondition, string userid, string usercode, string companyid)
{
var rangstr = GetRangDASearchStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
2 years ago
11 months ago
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("GROUP BY b.BSNO,f.CUSTOMERNAME) AS T ");
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;
}
2 years ago
private static List<BillCustDetail> SetAddBillData(StringBuilder strSql)
{
var headList = new List<BillCustDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BillCustDetail data = new BillCustDetail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
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"]);
10 months ago
data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]);
2 years ago
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"]);
10 months ago
if (reader["BSSTATUS"] != DBNull.Value)
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
2 years ago
11 months ago
if (reader["RMBDR"] != DBNull.Value)
data.RMBDrAmount = Convert.ToDecimal(reader["RMBDR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.RMBDrBalAmount = Convert.ToDecimal(reader["BALRMBDR"]) - Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.RMBDrDoAmount = Convert.ToDecimal(reader["BALRMBDR"]) - Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["RMBCR"] != DBNull.Value)
data.RMBCrAmount = Convert.ToDecimal(reader["RMBCR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.RMBCrBalAmount = Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.RMBCrDoAmount = Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["USDDR"] != DBNull.Value)
data.USDDrAmount = Convert.ToDecimal(reader["USDDR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.USDDrBalAmount = Convert.ToDecimal(reader["BALUSDDR"]) - Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.USDDrDoAmount = Convert.ToDecimal(reader["BALUSDDR"]) - Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["USDCR"] != DBNull.Value)
data.USDCrAmount = Convert.ToDecimal(reader["USDCR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.USDCrBalAmount = Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.USDCrDoAmount = Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["OTDR"] != DBNull.Value)
data.OTDrAmount = Convert.ToDecimal(reader["OTDR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.OTDrBalAmount = Convert.ToDecimal(reader["BALOTDR"]) - Convert.ToDecimal(reader["BALOTCR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.OTDrDoAmount = Convert.ToDecimal(reader["BALOTDR"]) - Convert.ToDecimal(reader["BALOTCR"]);
if (reader["OTCR"] != DBNull.Value)
data.OTCrAmount = Convert.ToDecimal(reader["OTCR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.OTCrBalAmount = Convert.ToDecimal(reader["BALOTCR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.OTCrDoAmount = Convert.ToDecimal(reader["BALOTCR"]);
2 years ago
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<BillTruckCustDetail> GetAddTruckBillList(string strCondition, string isdebit, string userid, string usercode, string orgcode, string sort)
{
var rangstr = GetRangDASearchStr("index", 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 ");
strSql.Append("b.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE,");
strSql.Append("b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR,");
strSql.Append("b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO");
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 ISNULL(SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS STLRMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLRMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT-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 ISNULL(AMOUNT-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 ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS STLUSDCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT-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 ISNULL(AMOUNT-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 ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(SETTLEMENT,0) END) END)ELSE 0 END),0) AS STLOTCR,");
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-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 ISNULL(AMOUNT-SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
strSql.Append(" FROM CH_FEE F ");
strSql.Append(" INNER JOIN v_op_truck_bulk B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where F.ISINVOICE<>1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
strSql.Append("GROUP BY b.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE");
strSql.Append(",b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR");
strSql.Append(",b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO");
strSql.Append(",F.CUSTOMERNAME");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by b.BsNo");
}
return SetAddTruckBillData(strSql);
}
private static List<BillTruckCustDetail> SetAddTruckBillData(StringBuilder strSql)
{
var headList = new List<BillTruckCustDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BillTruckCustDetail data = new BillTruckCustDetail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);
if (reader["NETWEIGHT"] != DBNull.Value)
data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]);
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region feedetail DataList
1 year ago
static public List<ChFeeDetail> GetFeeDetailList(string strCondition,string sort=null)
2 years ago
{
var strSql = new StringBuilder();
1 year ago
strSql.Append("SELECT * from( ");
strSql.Append("SELECT ");
2 years ago
strSql.Append("f.BSNO,f.GID AS CH_ID,FeeType");
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-isnull(f.invoice,0)-isnull(f.ORDERINVOICE,0) as balamount,isnull(f.invoice,0)+isnull(f.ORDERINVOICE,0) as stlamount,f.currency,f.exChangerate");
strSql.Append(" from ch_fee f where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
1 year ago
strSql.Append(") as v");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("StlAmount", "balamount");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by feeName ");
}
2 years ago
return SetFeeDetailData(strSql);
}
private static List<ChFeeDetail> SetFeeDetailData(StringBuilder strSql)
{
var headList = new List<ChFeeDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
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 = Convert.ToInt16(reader["FeeType"]);
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeName = Convert.ToString(reader["feeName"]);
data.CustomerName = Convert.ToString(reader["customerName"]);
data.Amount = Convert.ToDecimal(reader["Amount"]);
if (reader["BalAmount"] != DBNull.Value)
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
if (reader["BalAmount"] != DBNull.Value)
data.StlAmount = Convert.ToDecimal(reader["BalAmount"]);
data.Currency = Convert.ToString(reader["Currency"]);
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<ChFeeExrate> GetCurrExrateData(string billno, string billcust, string billcurr, string feesql)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT DISTINCT CURRENCY,EXCHANGERATE ");
strSql.Append(" FROM ch_fee f where CURRENCY<>'" + billcurr + "' AND CUSTOMERNAME='"+billcust+"'");
if (!string.IsNullOrEmpty(feesql))
{
strSql.Append(" and " + feesql);
}
return SetCurrExrateData(strSql);
}
private static List<ChFeeExrate> SetCurrExrateData(StringBuilder strSql)
{
var headList = new List<ChFeeExrate>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChFeeExrate data = new ChFeeExrate();
#region Set DB data to Object
data.CURR = Convert.ToString(reader["CURRENCY"]);
data.EXRATE = 0;
if (reader["EXCHANGERATE"] != DBNull.Value)
data.DFEXRATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult AddDetail(string billno, List<ChFeeDetail> bodyList, string curr,string MBLNO,string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into ch_fee_do_invoice (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
values (@GID,@BILLNO,@BSNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@BSTYPE,@FEEID,@FEENAME,@CURRENCY
,@AMOUNT,@DOAMOUNT,@FEETYPE,@CATEGORY,@BILLSTATUS,@ISDELETED,@CREATETIME
,@EXCHANGERATE,@ORIGCURRENCY,@ORIGAMOUNT,@INVOICESETTLENO,@COMPANYID) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"UPDATE CH_FEE SET ORDERINVOICE=ORDERINVOICE+@ORDERINVOICE WHERE GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, MBLNO);
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String,"");
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CustomerName);
var tops = enumValue.BSNO.Substring(0, 7);
if (tops == "topseae")
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true);
else
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, curr);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.DoAmount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16,10);
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean,false);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.ExChangerate);
db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, enumValue.StlAmount);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, enumValue.StlAmount);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static Decimal GetExrate(string curr, List<ChFeeExrate> exratelist)
{
decimal exrate = 0;
if (exratelist != null)
{
foreach (var enumValue in exratelist)
{
if (enumValue.CURR==curr){
exrate=enumValue.EXRATE;
}
}
}
return exrate;
}
public static DBResult AddBill(string billno, string billcust, string billcurr, string feesql, List<ChFeeExrate> exratelist, string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
feesql = feesql + " AND CUSTOMERNAME='" + billcust + "'";
var feelist = GetFeeDetailList(feesql);
var cmdInsert =
db.GetSqlStringCommand(
@"insert into ch_fee_do_invoice (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
values (@GID,@BILLNO,@BSNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@BSTYPE,@FEEID,@FEENAME,@CURRENCY
,@AMOUNT,@DOAMOUNT,@FEETYPE,@CATEGORY,@BILLSTATUS,@ISDELETED,@CREATETIME
,@EXCHANGERATE,@ORIGCURRENCY,@ORIGAMOUNT,@INVOICESETTLENO,@COMPANYID) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"UPDATE CH_FEE SET ORDERINVOICE=ORDERINVOICE+@ORDERINVOICE WHERE GID=@GID ");
if (feelist != null)
{
foreach (var enumValue in feelist)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String,"");
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, "");
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CustomerName);
var tops = enumValue.BSNO.Substring(0, 7);
if (tops == "topseae")
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true);
else
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, billcurr);
if (billcurr == enumValue.Currency)
{
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
}
else {
var UExrate = GetExrate(enumValue.Currency, exratelist);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount * UExrate);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate);
}
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType);
db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, enumValue.StlAmount);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 10);
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
1 year ago
db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, enumValue.StlAmount);
//db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, enumValue.StlAmount);
//db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, enumValue.StlAmount);
db.ExecuteNonQuery(cmdUpdate, 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;
}
public static DBResult DelFeeDo(List<Chfee_do_detail> boday)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmddelete = db.GetSqlStringCommand("delete from ch_fee_do_invoice where GID=@FEEDOID");
var cmdupdate = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=ORDERINVOICE-@ORIGAMOUNT where GID=@GID");
foreach (var enumValue in boday)
{
cmddelete.Parameters.Clear();
db.AddInParameter(cmddelete, "@FEEDOID", DbType.String, enumValue.FEEDOID);
db.ExecuteNonQuery(cmddelete, tran);
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@ORIGAMOUNT", DbType.Decimal, enumValue.ORIGAMOUNT);
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID);
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;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static int p_update_Amount(string billno)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("p_update_Invoicehexiao");
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
db.ExecuteNonQuery(cmd);
return 0;
}
public static DBResult updateFeeTax(string billno, decimal taxrate)
{
var result = new DBResult();
var dataList = GetBodyList("BILLNO='" + billno + "'");
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"UPDATE CH_FEE SET ACCTAXRATE=@INVOICE WHERE GID=@GID ");
if (dataList != null)
{
foreach (var enumValue in dataList)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.FEEID);
db.AddInParameter(cmdUpdate, "@INVOICE", DbType.Decimal, taxrate);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
2 years ago
public static DBResult SubmitAudit(String WorkFlowName, String USERID, String bill,string companyid,string username)
2 years ago
{
var result = new DBResult();
2 years ago
T_ALL_DA T_ALL_DA = new T_ALL_DA();
Database db = DatabaseFactory.CreateDatabase();
2 years ago
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
2 years ago
var WorkFlowid = "";
if (WorkFlowid == "")
{
string lsSQL = "select * FROM workflow WHERE COMPANYID='" + companyid + "' AND ISCONDITION=1 and [TYPE]=(SELECT TYPENO FROM workflow_type WHERE [NAME]='" + WorkFlowName + "') "
+ " and GID in (select workflowID from workflow_Userpath where userid ='" + USERID + "') order by SORTNO ";
DataSet dsworkflow = T_ALL_DA.GetAllSQL(lsSQL);
if (dsworkflow != null)
{
if (dsworkflow.Tables[0].Rows.Count > 0)
{
foreach (DataRow row in dsworkflow.Tables[0].Rows)
{
var CONDITIONSQL = Convert.ToString(row["CONDITIONSQL"]);
CONDITIONSQL = CONDITIONSQL.Replace("[业务编号]", "'" + bill + "'");
var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL);
if (strCOUNT != "0")
{
WorkFlowid = Convert.ToString(row["GID"]);
break;
}
2 years ago
2 years ago
}
}
}
if (WorkFlowid == "") WorkFlowid = "no";
}
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID,bill,bill,"", WorkFlowid);
2 years ago
if (WorkResult.Success == true)
{
2 years ago
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='提交审核',SUBMITOP='" + username + "' where BILLNO=@BILLNO");
2 years ago
if (WorkResult.islast == true)
{
1 year ago
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='审核通过',SUBMITOP='"+username+ "',AUDITUSER='" + USERID + "',AUDITTIME=GETDATE() where BILLNO=@BILLNO");
2 years ago
var bodylist = GetBodyList("BILLNO='" + bill + "'");
if (bodylist != null)
{
var cmdupdatefee = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=ORDERINVOICE-@ORIGAMOUNT,INVOICE=ISNULL(INVOICE,0)+@ORDERINVOICE,INVOICENUM=@INVOICENUM where GID=@GID");
var cmdupdatefee2 = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=0 where INVOICE=AMOUNT AND GID=@GID");
foreach (var enumValuebody in bodylist)
{
cmdupdatefee.Parameters.Clear();
db.AddInParameter(cmdupdatefee, "@ORIGAMOUNT", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@ORDERINVOICE", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@INVOICENUM", DbType.String, enumValuebody.INVOICENO);
db.AddInParameter(cmdupdatefee, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee, tran);
cmdupdatefee2.Parameters.Clear();
db.AddInParameter(cmdupdatefee2, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee2, tran);
}
}
}
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "提交审核成功";
}
else {
result.Success = false;
result.Message = "提交审核错误!";
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交审核错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
2 years ago
public static DBResult SubmitAuditList(String WorkFlowName, String USERID, String bills,string companyid,string username)
2 years ago
{
var result = new DBResult();
var billList = bills.Split(',');
2 years ago
T_ALL_DA T_ALL_DA = new T_ALL_DA();
Database db = DatabaseFactory.CreateDatabase();
2 years ago
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var bill in billList)
{
2 years ago
var WorkFlowid = "";
if (WorkFlowid == "")
{
string lsSQL = "select * FROM workflow WHERE COMPANYID='" + companyid + "' AND ISCONDITION=1 and [TYPE]=(SELECT TYPENO FROM workflow_type WHERE [NAME]='" + WorkFlowName + "') "
+ " and GID in (select workflowID from workflow_Userpath where userid ='" + USERID + "') order by SORTNO ";
DataSet dsworkflow = T_ALL_DA.GetAllSQL(lsSQL);
if (dsworkflow != null)
{
if (dsworkflow.Tables[0].Rows.Count > 0)
{
foreach (DataRow row in dsworkflow.Tables[0].Rows)
{
var CONDITIONSQL = Convert.ToString(row["CONDITIONSQL"]);
CONDITIONSQL = CONDITIONSQL.Replace("[业务编号]", "'" + bill + "'");
var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL);
if (strCOUNT != "0")
{
WorkFlowid = Convert.ToString(row["GID"]);
break;
}
}
}
}
if (WorkFlowid == "") WorkFlowid = "no";
2 years ago
2 years ago
}
2 years ago
2 years ago
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID,bill,bill, "", WorkFlowid);
2 years ago
if (WorkResult.Success == true)
{
2 years ago
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='提交审核',SUBMITOP='" + username + "' where BILLNO=@BILLNO");
2 years ago
if (WorkResult.islast == true)
{
1 year ago
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='审核通过',SUBMITOP='" + username + "',AUDITUSER='"+USERID+ "',AUDITTIME=GETDATE() where BILLNO=@BILLNO");
2 years ago
var bodylist = GetBodyList("BILLNO='" + bill + "'");
if (bodylist!=null)
{
var cmdupdatefee = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=ORDERINVOICE-@ORIGAMOUNT,INVOICE=ISNULL(INVOICE,0)+@ORDERINVOICE,INVOICENUM=@INVOICENUM where GID=@GID");
var cmdupdatefee2 = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=0 where INVOICE=AMOUNT AND GID=@GID");
foreach (var enumValuebody in bodylist)
{
cmdupdatefee.Parameters.Clear();
db.AddInParameter(cmdupdatefee, "@ORIGAMOUNT", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@ORDERINVOICE", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@INVOICENUM", DbType.String, enumValuebody.INVOICENO);
db.AddInParameter(cmdupdatefee, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee, tran);
cmdupdatefee2.Parameters.Clear();
db.AddInParameter(cmdupdatefee2, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee2, tran);
}
}
}
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "提交审核成功";
}
else
{
result.Success = false;
result.Message = "提交审核错误!";
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交审核错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult SubmitAuditBack(String WorkFlowName, String USERID, String bill)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, bill, USERID);
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='新建' where BILLNO=@BILLNO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "撤销提交成功";
}
else {
result = new DBResult();
result.Success = false;
result.Message = "已部分审核此业务,不允许撤回提交!";
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销提交错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult SubmitAuditBackList(String WorkFlowName, String USERID, 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)
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, bill, USERID);
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='新建' where BILLNO=@BILLNO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "撤销提交成功";
}
else
{
result = new DBResult();
result.Success = false;
result.Message = "已部分审核此业务,不允许撤回提交!";
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销提交错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult AuditList(List<ChInvoicehexiao> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
1 year ago
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='审核通过',AUDITUSER='" + USERID + "',AUDITTIME=GETDATE() where BILLNO=@BILLNO");
2 years ago
foreach (var enumValue in boday)
{
if (enumValue.BILLSTATUS == "提交审核" || enumValue.BILLSTATUS == "驳回提交")
{
var bodylist = GetBodyList("BILLNO='" + enumValue.BILLNO + "'");
Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("PayInvAudit", enumValue.BILLNO, USERID,enumValue.BILLNO);
if (WorkResult.Success == true && WorkResult.islast == true)
{
var cmdupdatefee = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=ORDERINVOICE-@ORIGAMOUNT,INVOICE=ISNULL(INVOICE,0)+@ORDERINVOICE,INVOICENUM=@INVOICENUM where GID=@GID");
var cmdupdatefee2 = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=0 where INVOICE=AMOUNT AND GID=@GID");
foreach (var enumValuebody in bodylist)
{
cmdupdatefee.Parameters.Clear();
db.AddInParameter(cmdupdatefee, "@ORIGAMOUNT", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@ORDERINVOICE", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@INVOICENUM", DbType.String, enumValuebody.INVOICENO);
db.AddInParameter(cmdupdatefee, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee, tran);
cmdupdatefee2.Parameters.Clear();
db.AddInParameter(cmdupdatefee2, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee2, tran);
}
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO);
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;
}
}
result.Success = true;
result.Message = "审核通过";
return result;
}
public static DBResult AuditBackList(List<ChInvoicehexiao> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
1 year ago
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BILLSTATUS='驳回提交',AUDITUSER='',AUDITTIME=NULL where BILLNO=@BILLNO");
2 years ago
foreach (var enumValue in boday)
{
if (enumValue.BILLSTATUS == "提交审核" || enumValue.BILLSTATUS == "审核通过")
{
var bodylist = GetBodyList("BILLNO='" + enumValue.BILLNO + "'");
Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo("PayInvAudit", enumValue.BILLNO, USERID, "");
if (WorkResult.Success == true)
{
if (enumValue.BILLSTATUS == "审核通过")
{
foreach (var enumValuebody in bodylist)
{
var cmdupdatefee = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORIGAMOUNT,INVOICE=INVOICE-@ORDERINVOICE,INVOICENUM='' where GID=@GID");
cmdupdatefee.Parameters.Clear();
db.AddInParameter(cmdupdatefee, "@ORIGAMOUNT", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@ORDERINVOICE", DbType.Decimal, enumValuebody.ORIGAMOUNT);
db.AddInParameter(cmdupdatefee, "@GID", DbType.String, enumValuebody.FEEID);
db.ExecuteNonQuery(cmdupdatefee, tran);
}
}
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO);
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;
}
}
result.Success = true;
result.Message = "完成驳回";
return result;
}
#region 入账申请
static public List<ChBalapplication> GetBalPayList(string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
{
if (userid != "")
{
var rangstr = GetRangDAPayListStr("", 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 [GID],[BILLNO],[BILLSTATUS],[CUSTOMERNAME],[AMOUNTRMB],[RATE],[AMOUNTUSD],[APPLICANT] ");
strSql.Append(",[APPLYTIME],[ENTERTIME],[AUDITUSER],[AUDITTIME],[REMARK],[ISDELETE] ,[DELETEUSER]");
strSql.Append(",[DELETETIME],[COMPANYID] ,[CURR],");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=ch_fee_balapplication.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=ch_fee_balapplication.APPLICANT) as APPLICANTNAME");
strSql.Append(",(select ShowName from [user] where GID=ch_fee_balapplication.AUDITUSER) as AUDITUSERREF");
strSql.Append(" FROM ch_fee_balapplication where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ENTERTIME DESC");
}
return SetBalPayData(strSql);
}
static public ChBalapplication GetBalPayData(string condition)
{
var list = GetBalPayList(condition);
if (list.Count > 0)
return list[0];
return new ChBalapplication();
}
private static List<ChBalapplication> SetBalPayData(StringBuilder strSql)
{
var headList = new List<ChBalapplication>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChBalapplication data = new ChBalapplication();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BILLNO = Convert.ToString(reader["BILLNO"]);
if (reader["BILLSTATUS"] != DBNull.Value)
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["CURR"] != DBNull.Value)
data.CURR = Convert.ToString(reader["CURR"]);
if (reader["AMOUNTRMB"] != DBNull.Value)
data.AMOUNTRMB = Convert.ToDecimal(reader["AMOUNTRMB"]);
if (reader["AMOUNTUSD"] != DBNull.Value)
data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
if (reader["RATE"] != DBNull.Value)
data.RATE = Convert.ToDecimal(reader["RATE"]);
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
if (reader["APPLYTIME"] != DBNull.Value)
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]).ToString("yyyy-MM-dd");
if (reader["ENTERTIME"] != DBNull.Value)
data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]);
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]);
data.AUDITUSER = Convert.ToString(reader["AUDITUSERREF"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteBalDetail(string billno)
{
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_fee_invoicehexiao SET BALBILLNO='' WHERE BALBILLNO=@BALBILLNO ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BALBILLNO", DbType.String, billno);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult AddBalList(List<ChInvoicehexiao> boday, String billno)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BALBILLNO='"+billno+"' where BILLNO=@BILLNO AND (BALBILLNO IS NULL OR BALBILLNO='')");
if (billno=="")
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoicehexiao set BALBILLNO='" + billno + "' where BILLNO=@BILLNO ");
foreach (var enumValue in boday)
{
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO);
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;
}
}
result.Success = true;
result.Message = "审核通过";
return result;
}
public static DBResult LockBalList(String bills,bool islock)
{
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_fee_balapplication set BILLSTATUS=0 where BILLNO=@BILLNO");
if (!islock)
cmdupdate = db.GetSqlStringCommand("update ch_fee_balapplication set BILLSTATUS=1 where BILLNO=@BILLNO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", 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 int p_update_BalAmount(string billno)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("p_update_BalApp");
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
db.ExecuteNonQuery(cmd);
return 0;
}
#endregion
#region 付费申请生成发票核销
static public List<ChPayapplication> GetPayListData(string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
{
var rangstr = GetRangDAListStr("", 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 cm.GID,cm.BILLNO,cm.BILLSTATUS,cm.CUSTOMERNAME,cm.CURR,cm.CHEQUEPAYABLE,cm.SETTLETYPE,cm.PAYTYPE");
strSql.Append(" ,cm.PAYABLETIME,cm.AMOUNTRMB,cm.RATE,cm.AMOUNTUSD,cm.SETTLERMB,cm.SETTLEUSD,cm.SETTLERATE");
strSql.Append(" ,cm.APPLICANT,cm.APPLYTIME,cm.ENTERTIME,cm.SETTLEUSER,cm.SETTLETIME,cm.AUDITUSER,cm.AUDITTIME ");
strSql.Append(" ,cm.REMARK,cm.COMPANYID,cm.ISAPP,cm.PAYAPPID,cm.CHEQUENUMREMARK,cm.INVDATE,cm.INVNO, ");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
strSql.Append(",(select ShowName from [user] where GID=cm.AUDITUSER) as AUDITUSERREF");
strSql.Append(",CUSTACCOUNTGID");
strSql.Append(",(select CODENAME+'_'+bankname from info_client_bank where gid=cm.CUSTACCOUNTGID) CUSTBANKNAME");
strSql.Append(",(select ACCOUNT from info_client_bank where gid=cm.CUSTACCOUNTGID) CUSTACCOUNT");
strSql.Append(",cm.BS_CUSTOMERNAME,0 IsAudit,PREAMOUNTRMB,PREAMOUNTUSD ");
strSql.Append(",i.BALINVRMBAMOUNT,i.BALINVUSDAMOUNT");
strSql.Append(" FROM ch_fee_payapplication cm left join v_fee_do_payinvoice i on (i.BILLNO=cm.BILLNO) where (i.BALINVRMBAMOUNT!=0 or i.BALINVUSDAMOUNT!=0) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by APPLYTIME DESC");
}
return SetPayInvData(strSql);
}
private static List<ChPayapplication> SetPayInvData(StringBuilder strSql)
{
var headList = new List<ChPayapplication>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChPayapplication data = new ChPayapplication();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BILLNO = Convert.ToString(reader["BILLNO"]);
if (reader["BILLSTATUS"] != DBNull.Value)
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
data.PAYTYPE = Convert.ToString(reader["PAYTYPE"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["CURR"] != DBNull.Value)
data.CURR = Convert.ToString(reader["CURR"]);
data.CHEQUEPAYABLE = Convert.ToString(reader["CHEQUEPAYABLE"]);
if (reader["SETTLETYPE"] != DBNull.Value)
data.SETTLETYPE = Convert.ToInt32(reader["SETTLETYPE"]);
if (reader["PAYABLETIME"] != DBNull.Value)
data.PAYABLETIME = Convert.ToDateTime(reader["PAYABLETIME"]).ToString("yyyy-MM-dd");
if (reader["AMOUNTRMB"] != DBNull.Value)
data.AMOUNTRMB = Convert.ToDecimal(reader["AMOUNTRMB"]);
if (reader["AMOUNTUSD"] != DBNull.Value)
data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
if (reader["RATE"] != DBNull.Value)
data.RATE = Convert.ToDecimal(reader["RATE"]);
if (reader["BALINVRMBAMOUNT"] != DBNull.Value)
data.BALAMOUNTRMB = Convert.ToDecimal(reader["BALINVRMBAMOUNT"]);
if (reader["BALINVUSDAMOUNT"] != DBNull.Value)
data.BALAMOUNTUSD = Convert.ToDecimal(reader["BALINVUSDAMOUNT"]);
data.SETTLERMB = data.BALAMOUNTRMB;
data.SETTLEUSD = data.BALAMOUNTUSD;
if (reader["SETTLERATE"] != DBNull.Value)
data.SETTLERATE = Convert.ToDecimal(reader["SETTLERATE"]);
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
if (reader["APPLYTIME"] != DBNull.Value)
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]);
if (reader["ENTERTIME"] != DBNull.Value)
data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]);
if (reader["SETTLETIME"] != DBNull.Value)
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]);
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]);
data.SETTLEUSER = Convert.ToString(reader["SETTLEUSER"]);
data.AUDITUSER = Convert.ToString(reader["AUDITUSERREF"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
if (reader["ISAPP"] != DBNull.Value)
data.ISAPP = Convert.ToBoolean(reader["ISAPP"]);
data.PAYAPPID = Convert.ToString(reader["PAYAPPID"]);
data.CHEQUENUMREMARK = Convert.ToString(reader["CHEQUENUMREMARK"]);
data.INVNO = Convert.ToString(reader["INVNO"]);
2 years ago
if (reader["INVDATE"] != DBNull.Value && reader["INVDATE"].ToString() != "")
data.INVDATE = Convert.ToDateTime(reader["INVDATE"]).ToString("yyyy-MM-dd");
data.CUSTACCOUNTGID = Convert.ToString(reader["CUSTACCOUNTGID"]);
2 years ago
data.CUSTBANKNAME = Convert.ToString(reader["CUSTBANKNAME"]);
data.CUSTACCOUNT = Convert.ToString(reader["CUSTACCOUNT"]);
if (reader["IsAudit"] != DBNull.Value)
data.IsAudit = Convert.ToString(reader["IsAudit"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult AddPayBill(string billno, List<ChPayapplication> bodyList, string billcurr, List<ChFeeExrate> exratelist, string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into ch_fee_do_invoice (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
values (@GID,@BILLNO,@BSNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@BSTYPE,@FEEID,@FEENAME,@CURRENCY
,@AMOUNT,@DOAMOUNT,@FEETYPE,@CATEGORY,@BILLSTATUS,@ISDELETED,@CREATETIME
,@EXCHANGERATE,@ORIGCURRENCY,@ORIGAMOUNT,@INVOICESETTLENO,@COMPANYID) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"UPDATE CH_FEE SET ORDERINVOICE=ORDERINVOICE+@ORDERINVOICE WHERE GID=@GID ");
if (bodyList != null)
{
foreach (var enumPay in bodyList)
{
2 years ago
var feesql = " d.BILLNO='"+enumPay.BILLNO+"' ";
var feelist = GetAppFeeDetailList(feesql,db,tran);
2 years ago
var stlamount = enumPay.SETTLERMB;
var usdstlamount = enumPay.SETTLEUSD;
var isAll = false;
if (enumPay.BALAMOUNTRMB == enumPay.SETTLERMB && enumPay.BALAMOUNTUSD == enumPay.SETTLEUSD) isAll = true;
if (feelist != null)
{
foreach (var feedovalue in feelist)
{
decimal balamount = 0;
decimal origamount = 0;
decimal amount = 0;
decimal UExrate = 0;
if ((stlamount != 0) || (usdstlamount != 0) || isAll)
{
if (feedovalue.Currency == "RMB")
{
if ((feedovalue.BalAmount <= stlamount) || isAll)
{
origamount = feedovalue.BalAmount;
amount = feedovalue.BalAmount;
if (feedovalue.FeeType== 2)
stlamount = stlamount - amount;
else
stlamount = stlamount + amount;
}
else
{
amount = stlamount;
stlamount = 0;
origamount = stlamount;
}
}
else if (feedovalue.Currency == "USD")
{
if ((feedovalue.BalAmount) <= usdstlamount || isAll)
{
origamount = feedovalue.BalAmount;
amount = feedovalue.BalAmount;
if (feedovalue.FeeType== 2)
usdstlamount = usdstlamount - balamount;
else
usdstlamount = usdstlamount + balamount;
}
else
{
amount = usdstlamount;
origamount = usdstlamount;
usdstlamount = 0;
}
}
else
{
if ((feedovalue.BalAmount) <= usdstlamount || isAll)
{
origamount = feedovalue.BalAmount;
amount = feedovalue.BalAmount;
if (feedovalue.FeeType == 2)
usdstlamount = usdstlamount - balamount;
else
usdstlamount = usdstlamount + balamount;
}
else
{
amount = usdstlamount;
usdstlamount = 0;
origamount =usdstlamount;
}
}
if (feedovalue.Currency == billcurr)
{
balamount = amount;
UExrate = 1;
}
else
{
if (feedovalue.Currency != billcurr)
{
UExrate = GetExrate(feedovalue.Currency, exratelist);
balamount = origamount * UExrate;
}
else
{
balamount = origamount;
UExrate = 1;
}
}
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, feedovalue.BSNO);
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, "");
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, "");
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, feedovalue.CustomerName);
var tops = feedovalue.BSNO.Substring(0, 7);
if (tops == "topseae")
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true);
else
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, feedovalue.CH_ID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, feedovalue.FeeName);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, billcurr);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, balamount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate);
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, feedovalue.FeeType);
db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, feedovalue.Currency);
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 10);
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, feedovalue.CH_ID);
db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, origamount);
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;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
static public List<ChFeeDetail> GetFeeDetailList(string strCondition, Database db, DbTransaction tran)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("f.BSNO,f.GID AS CH_ID,FeeType");
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-isnull(f.invoice,0)-isnull(f.ORDERINVOICE,0) as balamount,isnull(f.invoice,0)+isnull(f.ORDERINVOICE,0) as stlamount,f.currency,f.exChangerate");
strSql.Append(" from ch_fee f where f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetFeeDetailData(strSql,db,tran);
}
2 years ago
static public List<ChFeeDetail> GetAppFeeDetailList(string strCondition, Database db, DbTransaction tran)
{
var strSql = new StringBuilder();
strSql.Append("SELECT BSNO,CH_ID,FeeType,FeeType_Ref,feeName,customerName,amount,case when amount>0 then (case when ORIGAMOUNT>balamount then balamount else ORIGAMOUNT end) else (case when ORIGAMOUNT<balamount then balamount else ORIGAMOUNT end) end balamount");
strSql.Append(",stlamount,currency,exChangerate from (");
strSql.Append("SELECT ");
strSql.Append("f.BSNO,f.GID AS CH_ID,f.FeeType");
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-isnull(f.invoice,0)-isnull(f.ORDERINVOICE,0) as balamount,isnull(f.invoice,0)+isnull(f.ORDERINVOICE,0) as stlamount,f.currency,f.exChangerate,d.ORIGAMOUNT");
strSql.Append(" from ch_fee f left join ch_fee_do d on (d.FEEID=F.GID) ");
strSql.Append(" where d.CATEGORY=4 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
2 years ago
2 years ago
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" ) AS V ");
return SetFeeDetailData(strSql, db, tran);
}
2 years ago
2 years ago
private static List<ChFeeDetail> SetFeeDetailData(StringBuilder strSql, Database db, DbTransaction tran)
2 years ago
{
var headList = new List<ChFeeDetail>();
using (IDataReader reader = db.ExecuteReader(tran, CommandType.Text, strSql.ToString()))
{
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 = Convert.ToInt16(reader["FeeType"]);
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeName = Convert.ToString(reader["feeName"]);
data.CustomerName = Convert.ToString(reader["customerName"]);
data.Amount = Convert.ToDecimal(reader["Amount"]);
if (reader["BalAmount"] != DBNull.Value)
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
if (reader["BalAmount"] != DBNull.Value)
data.StlAmount = Convert.ToDecimal(reader["BalAmount"]);
data.Currency = Convert.ToString(reader["Currency"]);
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<ChFeeExrate> GetAppCurrExrateData(List<ChPayapplication> bodyList, string billcurr)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT DISTINCT c.ORIGCURRENCY CURRENCY,f.EXCHANGERATE");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" left join ch_fee f on (f.GID=c.FEEID)");
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) AND c.AMOUNT<>c.DOAMOUNT and c.ORIGCURRENCY<>'" + billcurr + "'");
var i = 1;
if (bodyList != null)
{
strSql.Append(" and (");
foreach (var enumValue in bodyList)
{
if (i == 1)
strSql.Append(" c.BILLNO='" + enumValue.BILLNO + "' ");
else
strSql.Append(" or c.BILLNO='" + enumValue.BILLNO + "' ");
i++;
}
strSql.Append(" )");
}
return SetCurrExrateData(strSql);
}
public static DBResult UpdateApp(String bills, string type)
{
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_fee_invoicehexiao set ISAPP=" + type + " where BILLNO=@BILLNO");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BILLNO", 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 string GetRangDAListStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modPaySettleAppList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (APPLICANT='" + userid + "')";
}
else if (visiblerange == "3")
{
str = " (APPLICANT='" + userid + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "') and APPLICANT in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')";
}
else if (visiblerange == "1")
{
str = " APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "')";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
return str;
}
#endregion
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(*) AS CT from ch_fee_invoicehexiao (NOLOCK) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
1 year ago
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
2 years ago
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modChInvoicehexiaoList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
1 year ago
string VSSQL = "";
2 years ago
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"]);
1 year ago
VSSQL = Convert.ToString(reader["VSSQL"]);
2 years ago
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (OP='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (OP='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptid = rangeDa.GetDEPTGID(userid);
str = " OP in (select showname from vw_user where deptid='" + deptid + "') ";
}
else if (visiblerange == "1")
{
str = " OP in (select showname from vw_user 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 = " (OP in (select showname from vw_user where COMPANYID='" + companyid + "') ";
}
else
{
str = str + " or OP in (select showname from vw_user where COMPANYID='" + 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 ";
}
1 year ago
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
2 years ago
1 year ago
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
2 years ago
return str;
}
public static string GetAuditRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
1 year ago
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
2 years ago
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modChInvoicehexiaoList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
1 year ago
string VSSQL = "";
2 years ago
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"]);
1 year ago
VSSQL = Convert.ToString(reader["VSSQL"]);
2 years ago
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (i.OP='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (i.OP='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptid = rangeDa.GetDEPTGID(userid);
str = " i.OP in (select showname from vw_user where deptid='" + deptid + "') ";
}
else if (visiblerange == "1")
{
str = " i.OP in (select showname from vw_user where companyid='" + companyid + "') ";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
1 year ago
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
2 years ago
1 year ago
}
2 years ago
return str;
}
public static string GetRangDASearchStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
1 year ago
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
2 years ago
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modChInvoicehexiaoSearch' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
1 year ago
string VSSQL = "";
2 years ago
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"]);
1 year ago
VSSQL = Convert.ToString(reader["VSSQL"]);
2 years ago
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptid = rangeDa.GetDEPTGID(userid);
//str = " (OP in (select showname from vw_user where deptgid='" + deptid + "') OR SALE in (select showname from vw_user where deptgid='" + deptid + "') OR CUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') "
//+ " OR FRCUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') OR INPUTBY in (select showname from vw_user where deptgid='" + deptid + "'))";
str = $" exists(select 1 from vw_user where deptgid='{deptid}' and SHOWNAME in(OP,SALE,CUSTSERVICE,FRCUSTSERVICE,INPUTBY)) ";
2 years ago
}
else if (visiblerange == "1")
{
//str = " (OP in (select showname from vw_user where COMPANYID='" + companyid + "') OR SALE in (select showname from vw_user where COMPANYID='" + companyid + "') OR CUSTSERVICE in (select showname from vw_user where COMPANYID='" + companyid + "') "
//+ " OR FRCUSTSERVICE in (select showname from vw_user where COMPANYID='" + companyid + "') OR INPUTBY in (select showname from vw_user where COMPANYID='" + companyid + "'))";
str = " exists (select 1 from vw_user where COMPANYID='" + companyid + "' and showname in(OP,SALE,CUSTSERVICE,FRCUSTSERVICE,INPUTBY)) ";
2 years ago
}
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 ";
}
1 year ago
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
2 years ago
1 year ago
}
2 years ago
return str;
}
public static string GetRangDAPayListStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
1 year ago
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
2 years ago
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modPaySettleAppList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
1 year ago
string VSSQL = "";
2 years ago
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"]);
1 year ago
VSSQL = Convert.ToString(reader["VSSQL"]);
2 years ago
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (APPLICANT='" + userid + "')";
}
else if (visiblerange == "3")
{
str = " (APPLICANT='" + userid + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptid = rangeDa.GetDEPTGID(userid);
str = " APPLICANT in (select USERID from vw_user where deptid='" + deptid + "') ";
}
else if (visiblerange == "1")
{
str = " APPLICANT in (select USERID from vw_user where COMPANYID='" + companyid + "')";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
1 year ago
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
2 years ago
1 year ago
}
2 years ago
return str;
}
}
}