using System ;
using System.Data ;
using System.Data.Common ;
using System.Collections.Generic ;
using System.Text ;
using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication ;
using DSWeb.Areas.Account.Models.Chfee_do_detail ;
using DSWeb.Areas.Account.Models.MsOpBill ;
using DSWeb.Areas.Account.Models.BillChfeeDetail ;
using Microsoft.Practices.EnterpriseLibrary.Data ;
using DSWeb.Areas.Account.Models.Chfee_Exrate ;
using DSWeb.Areas.Account.Models.Chfee_do_Sum ;
using DSWeb.Areas.CommMng.Models ;
using DSWeb.EntityDA ;
using HcUtility.Comm ;
using DSWeb.Areas.CommMng.DAL ;
using DSWeb.Areas.Account.Models.Chfee_Invoice ;
using DSWeb.Areas.Account.Models.ChfeeDetail ;
using System.IO ;
using DSWeb.MvcShipping.DAL.MsCodeGoodInv ;
using DSWeb.MvcShipping.DAL.MsSysParamSet ;
using DSWeb.Areas.Account.Models.TruckChfee_do_detail ;
using DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication ;
using DSWeb.Areas.Account.Models.RytInvoice ;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL ;
using System.Xml ;
using System.Xml.Serialization ;
using System.Configuration ;
using System.Security.Cryptography ;
using DSWeb.MvcShipping.DAL.MsCompanysDAL ;
using DSWeb.MvcShipping.DAL.MsChFeeDAL ;
namespace DSWeb.Areas.Account.DAL.Chfee_Invoice
{
public partial class ChinvoiceDAL
{
#region 发票列表
static public List < ChInvoice > GetDataList ( int start , int limit , 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 * from (SELECT row_number() over (" ) ;
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
sortstring = sortstring . Replace ( "NOSTL" , "dbo.GetFeeNoStlByInvNo(cm.BILLNO)" ) ;
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by CURRENCY,OPERATETIME DESC" ) ;
}
strSql . Append ( @") as num , " ) ;
strSql . Append ( " GID,INVOICENO,BILLNO,CUSTOMERNAME,ACTUALCUSTOMERNAME,INVOICECUSTNAME,INVOICEMAKETIME,BANK,ACCOUNT,BSNO,VESSELVOYAGE,ETD,POL,POD" ) ;
strSql . Append ( " ,FEEITEM,AMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,CURRENCY,REMARK,APPLYTIME,OPERATOR,LICENSECODE,TAXCODE,INVOICETYPE,BILLSTATUS" ) ;
strSql . Append ( " ,ISNEEDPRINT,ISNEEDFEE,OPERATETIME,MBLNO,EXCHANGERATE,PRINTCAPITAL,PRINTAMOUNT,PRINTTITLE,COMPANYID,VOUCHERNO " ) ;
strSql . Append ( " ,CUSTRATENO,CUSTADDRTEL,CUSTBANK,INVOICECATEGORY,ISDELETE,DELETEOPERATOR,DELETETIME,RECVCURR " ) ;
strSql . Append ( ",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF" ) ;
strSql . Append ( ",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97009 and EnumValueID=cm.INVOICETYPE) as INVOICETYPEREF" ) ;
strSql . Append ( ",(case cm.billstatus when 1 then '已锁定' else '未锁定' end) as BILLSTATUSREF" ) ;
strSql . Append ( ",CREATEUSER,(select ShowName from [user] where GID=cm.CREATEUSER) as CREATEUSERREF,CREATETIME" ) ;
strSql . Append ( ",(select ShowName from [user] where GID=cm.OPERATOR) as OPERATORNAME" ) ;
strSql . Append ( ",(select ShowName from [user] where GID=cm.DELETEOPERATOR) as DELOPERATORNAME" ) ;
strSql . Append ( ",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT,VOUNO,DZSTATUS" ) ;
strSql . Append ( ", INVSHENNO=stuff ((SELECT distinct BILLNO+',' FROM ch_fee_invoiceapplication p WHERE p.INVBILLNO=cm.BILLNO FOR xml path('')), 1, 0, '')" ) ;
//strSql.Append(",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT,VOUNO,DZSTATUS");
// SELECT SUM(isnull(F.amount,0)-isnull(F.SETTLEMENT, 0)) FROM CH_FEE F LEFT JOIN CH_FEE_DO D ON(D.FEEID= F.GID) WHERE F.CURRENCY = 'RMB' AND D.BILLNO = 'IN2018012500002'
strSql . Append ( ",(select top 1 (select ShowName from [user] where GID=ap.applicant) APPLICANT from ch_fee_invoiceapplication ap where invbillno=cm.BILLNO) APPLICANT" ) ;
strSql . Append ( ",(select top 1 (select DEPTNAME from [VW_user] where userid=ap.applicant) APPLICANTDEPT from ch_fee_invoiceapplication ap where invbillno=cm.BILLNO) APPLICANTDEPT" ) ;
strSql . Append ( ",SALECORPID,(select [NAME] from [company] where GID=cm.SALECORPID) as SALECORP" ) ;
strSql . Append ( ",(select sum(TAX) from ch_fee_invoicedetail where PID=cm.GID) as TAX" ) ;
strSql . Append ( ",PTORRED,SETRED" ) ;
strSql . Append ( " FROM ch_fee_invoice cm 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 = GetRangDAListStr ( "" , 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_invoice cm 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 string GetDataListStr ( 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 GID,INVOICENO,BILLNO,CUSTOMERNAME,ACTUALCUSTOMERNAME,INVOICECUSTNAME,INVOICEMAKETIME,BANK,ACCOUNT,BSNO,VESSELVOYAGE,ETD,POL,POD" ) ;
strSql . Append ( " ,FEEITEM,AMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,CURRENCY,REMARK,APPLYTIME,OPERATOR,LICENSECODE,TAXCODE,INVOICETYPE,BILLSTATUS" ) ;
strSql . Append ( " ,ISNEEDPRINT,ISNEEDFEE,OPERATETIME,MBLNO,EXCHANGERATE,PRINTCAPITAL,PRINTAMOUNT,PRINTTITLE,COMPANYID,VOUCHERNO " ) ;
strSql . Append ( " ,CUSTRATENO,CUSTADDRTEL,CUSTBANK,INVOICECATEGORY,ISDELETE,DELETEOPERATOR,DELETETIME,RECVCURR " ) ;
strSql . Append ( ",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF" ) ;
strSql . Append ( ",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97009 and EnumValueID=cm.INVOICETYPE) as INVOICETYPEREF" ) ;
strSql . Append ( ",(case cm.billstatus when 1 then '已锁定' else '未锁定' end) as BILLSTATUSREF" ) ;
strSql . Append ( ",(select ShowName from [user] where GID=cm.OPERATOR) as OPERATORNAME" ) ;
strSql . Append ( ",CREATEUSER,(select ShowName from [user] where GID=cm.CREATEUSER) as CREATEUSERREF,CREATETIME" ) ;
strSql . Append ( ",(select ShowName from [user] where GID=cm.DELETEOPERATOR) as DELOPERATORNAME" ) ;
strSql . Append ( ",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT,VOUNO,DZSTATUS" ) ;
strSql . Append ( ", INVSHENNO=stuff ((SELECT distinct BILLNO+',' FROM ch_fee_invoiceapplication p WHERE p.INVBILLNO=cm.BILLNO FOR xml path('')), 1, 0, '')" ) ;
//strSql.Append(",dbo.GetFeeNoStlByInvNo(cm.BILLNO) as NOSTL,FEEAMOUNT,VOUNO,DZSTATUS");
// SELECT SUM(isnull(F.amount,0)-isnull(F.SETTLEMENT, 0)) FROM CH_FEE F LEFT JOIN CH_FEE_DO D ON(D.FEEID= F.GID) WHERE F.CURRENCY = 'RMB' AND D.BILLNO = 'IN2018012500002'
strSql . Append ( ",(select top 1 (select ShowName from [user] where GID=ap.applicant) APPLICANT from ch_fee_invoiceapplication ap where invbillno=cm.BILLNO) APPLICANT" ) ;
strSql . Append ( ",(select top 1 (select DEPTNAME from [VW_user] where userid=ap.applicant) APPLICANTDEPT from ch_fee_invoiceapplication ap where invbillno=cm.BILLNO) APPLICANTDEPT" ) ;
strSql . Append ( ",SALECORPID,(select [NAME] from [company] where GID=cm.SALECORPID) as SALECORP" ) ;
strSql . Append ( ",(select sum(TAX) from ch_fee_invoicedetail where PID=cm.GID) as TAX" ) ;
strSql . Append ( ",PTORRED,SETRED,INVAMOUNT-(select sum(TAX) from ch_fee_invoicedetail where PID=cm.GID) NOTAXAMOUNT" ) ;
strSql . Append ( " FROM ch_fee_invoice cm 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 CURRENCY,OPERATETIME DESC" ) ;
}
return strSql . ToString ( ) ;
}
static public ChInvoice GetData ( string condition , string userid = "" , string usercode = "" , string orgcode = "" )
{
var list = GetDataList ( 0 , 1 , condition , userid , usercode , orgcode , "" ) ;
if ( list . Count > 0 )
return list [ 0 ] ;
return new ChInvoice ( ) ;
}
private static List < ChInvoice > SetData ( StringBuilder strSql )
{
var headList = new List < ChInvoice > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
ChInvoice data = new ChInvoice ( ) ;
#region Set DB data to Object
data . GID = Convert . ToString ( reader [ "GID" ] ) ;
data . BILLNO = Convert . ToString ( reader [ "BILLNO" ] ) ;
data . CUSTOMERNAME = Convert . ToString ( reader [ "CUSTOMERNAME" ] ) ;
data . ACTUALCUSTOMERNAME = Convert . ToString ( reader [ "ACTUALCUSTOMERNAME" ] ) ;
if ( reader [ "CURRENCY" ] ! = DBNull . Value )
data . CURRENCY = Convert . ToString ( reader [ "CURRENCY" ] ) ;
data . INVOICENO = Convert . ToString ( reader [ "INVOICENO" ] ) ;
data . INVOICECUSTNAME = Convert . ToString ( reader [ "INVOICECUSTNAME" ] ) ;
data . INVOICECATEGORY = Convert . ToString ( reader [ "INVOICECATEGORY" ] ) ;
data . INVOICECATEGORYREF = Convert . ToString ( reader [ "INVOICECATEGORYREF" ] ) ;
if ( reader [ "INVOICETYPE" ] ! = DBNull . Value )
data . INVOICETYPE = Convert . ToInt32 ( reader [ "INVOICETYPE" ] ) ;
data . INVOICETYPEREF = Convert . ToString ( reader [ "INVOICETYPEREF" ] ) ;
if ( reader [ "BILLSTATUS" ] ! = DBNull . Value )
data . BILLSTATUS = Convert . ToInt32 ( reader [ "BILLSTATUS" ] ) ;
data . BILLSTATUSREF = Convert . ToString ( reader [ "BILLSTATUSREF" ] ) ;
data . BSNO = Convert . ToString ( reader [ "BSNO" ] ) ;
data . MBLNO = Convert . ToString ( reader [ "MBLNO" ] ) ;
data . VESSELVOYAGE = Convert . ToString ( reader [ "VESSELVOYAGE" ] ) ;
data . ETD = Convert . ToString ( reader [ "ETD" ] ) ;
data . POL = Convert . ToString ( reader [ "POL" ] ) ;
data . POD = Convert . ToString ( reader [ "POD" ] ) ;
if ( reader [ "AMOUNT" ] ! = DBNull . Value )
data . AMOUNT = Convert . ToDecimal ( reader [ "AMOUNT" ] ) ;
if ( reader [ "INVAMOUNT" ] ! = DBNull . Value )
data . INVAMOUNT = Convert . ToDecimal ( reader [ "INVAMOUNT" ] ) ;
data . AMOUNTCAPITAL = Convert . ToString ( reader [ "AMOUNTCAPITAL" ] ) ;
if ( reader [ "OTCURRAMOUNT" ] ! = DBNull . Value )
data . OTCURRAMOUNT = Convert . ToDecimal ( reader [ "OTCURRAMOUNT" ] ) ;
if ( reader [ "EXCHANGERATE" ] ! = DBNull . Value )
data . EXCHANGERATE = Convert . ToDecimal ( reader [ "EXCHANGERATE" ] ) ;
else
data . EXCHANGERATE = 0 ;
data . APPLICANT = Convert . ToString ( reader [ "APPLICANT" ] ) ;
data . APPLICANTDEPT = Convert . ToString ( reader [ "APPLICANTDEPT" ] ) ;
// data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
if ( reader [ "APPLYTIME" ] ! = DBNull . Value )
data . APPLYTIME = Convert . ToDateTime ( reader [ "APPLYTIME" ] ) ;
if ( reader [ "INVOICEMAKETIME" ] ! = DBNull . Value )
data . INVOICEMAKETIME = Convert . ToDateTime ( reader [ "INVOICEMAKETIME" ] ) . ToString ( "yyyy-MM-dd" ) ;
data . OPERATOR = Convert . ToString ( reader [ "OPERATOR" ] ) ;
data . OPERATORNAME = Convert . ToString ( reader [ "OPERATORNAME" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
data . COMPANYID = Convert . ToString ( reader [ "COMPANYID" ] ) ;
data . CUSTRATENO = Convert . ToString ( reader [ "CUSTRATENO" ] ) ;
data . CUSTADDRTEL = Convert . ToString ( reader [ "CUSTADDRTEL" ] ) ;
data . CUSTBANK = Convert . ToString ( reader [ "CUSTBANK" ] ) ;
if ( reader [ "ISNEEDPRINT" ] ! = DBNull . Value )
data . ISNEEDPRINT = Convert . ToString ( reader [ "ISNEEDPRINT" ] ) ;
if ( reader [ "ISNEEDFEE" ] ! = DBNull . Value )
data . ISNEEDFEE = Convert . ToString ( reader [ "ISNEEDFEE" ] ) ;
if ( reader [ "ISDELETE" ] ! = DBNull . Value )
data . ISDELETE = Convert . ToString ( reader [ "ISDELETE" ] ) ;
data . DELETEOPERATOR = Convert . ToString ( reader [ "DELETEOPERATOR" ] ) ;
data . DELOPERATORNAME = Convert . ToString ( reader [ "DELOPERATORNAME" ] ) ;
if ( reader [ "DELETETIME" ] ! = DBNull . Value )
data . DELETETIME = Convert . ToDateTime ( reader [ "DELETETIME" ] ) ;
data . NOSTL = Convert . ToString ( reader [ "NOSTL" ] ) ;
data . FEEAMOUNT = Convert . ToString ( reader [ "FEEAMOUNT" ] ) ;
data . VOUCHERNO = Convert . ToString ( reader [ "VOUCHERNO" ] ) ;
data . VOUNO = Convert . ToString ( reader [ "VOUNO" ] ) ;
data . RECVCURR = Convert . ToString ( reader [ "RECVCURR" ] ) ;
data . SALECORPID = Convert . ToString ( reader [ "SALECORPID" ] ) ; //分公司代码
data . SALECORP = Convert . ToString ( reader [ "SALECORP" ] ) ; //分公司代码
data . ACCOUNT = Convert . ToString ( reader [ "ACCOUNT" ] ) ; //分公司代码
data . BANK = Convert . ToString ( reader [ "BANK" ] ) ; //分公司代码
data . DZSTATUS = Convert . ToString ( reader [ "DZSTATUS" ] ) ;
data . PTORRED = Convert . ToString ( reader [ "PTORRED" ] ) ;
data . SETRED = Convert . ToString ( reader [ "SETRED" ] ) ;
data . INVSHENNO = Convert . ToString ( reader [ "INVSHENNO" ] ) ;
if ( reader [ "TAX" ] ! = DBNull . Value )
data . TAX = Convert . ToDecimal ( reader [ "TAX" ] ) ;
data . CREATEUSER = Convert . ToString ( reader [ "CREATEUSER" ] ) ;
data . CREATEUSERREF = Convert . ToString ( reader [ "CREATEUSERREF" ] ) ;
if ( reader [ "CREATETIME" ] ! = DBNull . Value )
data . CREATETIME = Convert . ToDateTime ( reader [ "CREATETIME" ] ) . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
# endregion
#region 发票明细
static public List < ChInvoiceDetail > GetDetailList ( string strCondition )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT GID,PID,SerialNo,GOODSNAME,SPEC,UNIT " ) ;
strSql . Append ( ",PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE" ) ;
strSql . Append ( ",(Select GOODNAME from code_goods_inv where GID=ch_fee_invoicedetail.GOODSNAME) AS GOODSNAMEREF" ) ;
strSql . Append ( " FROM ch_fee_invoicedetail " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition ) ;
}
return DetailSetData ( strSql ) ;
}
static public List < ChInvoiceDetail > GetDetailList ( string strCondition , Database db , DbTransaction tran )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT GID,PID,SerialNo,GOODSNAME,SPEC,UNIT " ) ;
strSql . Append ( ",PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE" ) ;
strSql . Append ( ",(Select GOODNAME from code_goods_inv where GID=ch_fee_invoicedetail.GOODSNAME) AS GOODSNAMEREF" ) ;
strSql . Append ( " FROM ch_fee_invoicedetail " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition ) ;
}
return DetailSetData ( strSql , db , tran ) ;
}
static public ChInvoiceDetail GetDetailData ( string condition )
{
var list = GetDetailList ( condition ) ;
if ( list . Count > 0 )
return list [ 0 ] ;
return new ChInvoiceDetail ( ) ;
}
private static List < ChInvoiceDetail > DetailSetData ( StringBuilder strSql )
{
var headList = new List < ChInvoiceDetail > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
ChInvoiceDetail data = new ChInvoiceDetail ( ) ;
#region Set DB data to Object
data . GID = Convert . ToString ( reader [ "GID" ] ) ;
data . PID = Convert . ToString ( reader [ "PID" ] ) ;
data . SERIALNO = Convert . ToInt16 ( reader [ "SerialNo" ] ) ;
data . GOODSNAME = Convert . ToString ( reader [ "GOODSNAME" ] ) ;
data . GOODSNAMEREF = Convert . ToString ( reader [ "GOODSNAMEREF" ] ) ;
if ( data . GOODSNAMEREF = = "" | | data . GOODSNAMEREF = = null ) data . GOODSNAMEREF = data . GOODSNAME ;
data . SPEC = Convert . ToString ( reader [ "SPEC" ] ) ;
data . UNIT = Convert . ToString ( reader [ "UNIT" ] ) ;
data . PKGS = Convert . ToDecimal ( reader [ "PKGS" ] ) ;
data . TAXPRICE = Convert . ToDecimal ( reader [ "TAXPRICE" ] ) ;
data . PRICE = Convert . ToDecimal ( reader [ "PRICE" ] ) ;
data . AMOUNT = Convert . ToDecimal ( reader [ "AMOUNT" ] ) ;
data . TAXRATE = Convert . ToDecimal ( reader [ "TAXRATE" ] ) ;
data . TAX = Convert . ToDecimal ( reader [ "TAX" ] ) ;
data . REMARK = Convert . ToString ( reader [ "Remark" ] ) ;
data . GOODCODE = Convert . ToString ( reader [ "GOODCODE" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
private static List < ChInvoiceDetail > DetailSetData ( StringBuilder strSql , Database db , DbTransaction tran )
{
var headList = new List < ChInvoiceDetail > ( ) ;
using ( IDataReader reader = db . ExecuteReader ( tran , CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
ChInvoiceDetail data = new ChInvoiceDetail ( ) ;
#region Set DB data to Object
data . GID = Convert . ToString ( reader [ "GID" ] ) ;
data . PID = Convert . ToString ( reader [ "PID" ] ) ;
data . SERIALNO = Convert . ToInt16 ( reader [ "SerialNo" ] ) ;
data . GOODSNAME = Convert . ToString ( reader [ "GOODSNAME" ] ) ;
data . GOODSNAMEREF = Convert . ToString ( reader [ "GOODSNAMEREF" ] ) ;
if ( data . GOODSNAMEREF = = "" | | data . GOODSNAMEREF = = null ) data . GOODSNAMEREF = data . GOODSNAME ;
data . SPEC = Convert . ToString ( reader [ "SPEC" ] ) ;
data . UNIT = Convert . ToString ( reader [ "UNIT" ] ) ;
data . PKGS = Convert . ToDecimal ( reader [ "PKGS" ] ) ;
data . TAXPRICE = Convert . ToDecimal ( reader [ "TAXPRICE" ] ) ;
data . PRICE = Convert . ToDecimal ( reader [ "PRICE" ] ) ;
data . AMOUNT = Convert . ToDecimal ( reader [ "AMOUNT" ] ) ;
data . TAXRATE = Convert . ToDecimal ( reader [ "TAXRATE" ] ) ;
data . TAX = Convert . ToDecimal ( reader [ "TAX" ] ) ;
data . REMARK = Convert . ToString ( reader [ "Remark" ] ) ;
data . GOODCODE = Convert . ToString ( reader [ "GOODCODE" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
public static List < ChInvoiceNo > GetInvoiceNo ( string companyid , string userid )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "select b.INVOICECODE+i.INVOICENUM INVOICENUM from ch_fee_invoiceitems i left join ch_fee_invoicebooks b on (i.BOOKID=b.GID)" ) ;
strSql . Append ( " where b.COMPANYID='" + companyid + "' and (b.DEFUSER='" + userid + "' or isnull(DEFUSER,'')='' ) and (i.isdelete=0 or i.isdelete is null) and i.ismakeout=0 AND ISNULL(i.ISLOCK,0)=0 AND ISNULL(B.ISLOCK,0)=0 and (b.isdelete=0 or b.isdelete is null)" ) ;
strSql . Append ( " order by b.MODIFIEDTIME desc,i.INVOICENUM " ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
var evList = new List < ChInvoiceNo > ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
var evData = new ChInvoiceNo ( ) ;
evData . INVNO = Convert . ToString ( reader [ "INVOICENUM" ] ) ;
evList . Add ( evData ) ;
}
reader . Close ( ) ;
}
return evList ;
}
# endregion
#region 发票费用明细
static public List < Chfee_do_detail > GetBodyList ( string strCondition , string sort = "" )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE " ) ;
strSql . Append ( ",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE" ) ;
strSql . Append ( " ,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.DESTINATION,b.INPUTBY,b.OP,b.CUSTSERVICE" ) ;
strSql . Append ( ",b.DOC,b.SALE,b.CNTRTOTAL" ) ;
strSql . Append ( ",f.Remark Remark,f.INPUTMODE " ) ;
strSql . Append ( " FROM ch_fee_do c" ) ;
strSql . Append ( " left join v_op_bill b on (b.bsno=c.bsno)" ) ;
strSql . Append ( " left join ch_fee f on (f.gid=c.feeid) " ) ;
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 ) ;
}
static public List < Chfee_do_detail > GetBsList ( string strCondition )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT '' GID,'' BSNO,'' FEEID,'' FEENAME,'' CURRENCY,sum(ISNULL((case when c.ORIGCURRENCY='RMB' THEN case when c.FEETYPE=1 THEN ORIGAMOUNT ELSE -ORIGAMOUNT END ELSE 0 END),0)) AMOUNT,0 DOAMOUNT" ) ;
strSql . Append ( ",'' ORIGCURRENCY,sum(ISNULL((case when c.ORIGCURRENCY!='RMB' THEN case when c.FEETYPE=1 THEN ORIGAMOUNT ELSE -ORIGAMOUNT END ELSE 0 END),0)) ORIGAMOUNT,0 ORIGSTLAMOUNT,0 EXCHANGERATE,0 ORIGEXCHANGERATE " ) ;
strSql . Append ( ",1 FEETYPE,'' FEEOBJNAME,'收' AS FEETYPEREF" ) ;
strSql . Append ( " ,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.DESTINATION,b.INPUTBY,b.OP,b.CUSTSERVICE" ) ;
strSql . Append ( ",b.DOC,b.SALE,b.CNTRTOTAL" ) ;
strSql . Append ( ",'' Remark,'' INPUTMODE " ) ;
strSql . Append ( " FROM ch_fee_do c" ) ;
strSql . Append ( " left join v_op_bill b on (b.bsno=c.bsno)" ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition ) ;
}
strSql . Append ( " GROUP BY 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.DESTINATION,b.INPUTBY,b.OP,b.CUSTSERVICE" ) ;
strSql . Append ( ",b.DOC,b.SALE,b.CNTRTOTAL" ) ;
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 . FEENAME = Convert . ToString ( reader [ "FEENAME" ] ) ;
data . FEEOBJNAME = Convert . ToString ( reader [ "FEEOBJNAME" ] ) ;
data . FEETYPE = Convert . ToInt16 ( reader [ "FEETYPE" ] ) ;
data . FEETYPEREF = Convert . ToString ( reader [ "FEETYPEREF" ] ) ;
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 . ORIGSTLAMOUNT = Convert . ToDecimal ( reader [ "ORIGSTLAMOUNT" ] ) ;
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" ] ) ;
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 . DESTINATION = Convert . ToString ( reader [ "DESTINATION" ] ) ;
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 . CNTRTOTAL = Convert . ToString ( reader [ "CNTRTOTAL" ] ) ;
if ( reader [ "BSSTATUS" ] ! = DBNull . Value )
data . BSSTATUS = Convert . ToBoolean ( reader [ "BSSTATUS" ] ) ;
if ( reader [ "ORIGEXCHANGERATE" ] ! = DBNull . Value )
data . ORIGEXCHANGERATE = Convert . ToDecimal ( reader [ "ORIGEXCHANGERATE" ] ) ;
data . Remark = Convert . ToString ( reader [ "Remark" ] ) ;
data . INPUTMODE = Convert . ToString ( reader [ "INPUTMODE" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
static public List < TruckChfee_do_detail > GetTruckBodyList ( string strCondition , string sort = "" )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE " ) ;
strSql . Append ( ",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,(SELECT EXCHANGERATE from ch_fee where GID=c.FEEID) ORIGEXCHANGERATE" ) ;
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" ) ;
strSql . Append ( ",f.Remark Remark,f.INPUTMODE,C.CREATETIME " ) ;
strSql . Append ( " FROM ch_fee_do c" ) ;
strSql . Append ( " left join v_op_truck_bulk b on (b.bsno=c.bsno)" ) ;
strSql . Append ( " left join ch_fee f on (f.gid=c.feeid) " ) ;
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 BodyTruckSetData ( strSql ) ;
}
private static List < TruckChfee_do_detail > BodyTruckSetData ( 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 . FEENAME = Convert . ToString ( reader [ "FEENAME" ] ) ;
data . FEEOBJNAME = Convert . ToString ( reader [ "FEEOBJNAME" ] ) ;
data . FEETYPE = Convert . ToInt16 ( reader [ "FEETYPE" ] ) ;
data . FEETYPEREF = Convert . ToString ( reader [ "FEETYPEREF" ] ) ;
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 . ORIGSTLAMOUNT = Convert . ToDecimal ( reader [ "ORIGSTLAMOUNT" ] ) ;
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" ] ) ;
if ( reader [ "ORIGEXCHANGERATE" ] ! = DBNull . Value )
data . ORIGEXCHANGERATE = Convert . ToDecimal ( reader [ "ORIGEXCHANGERATE" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
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 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 < BillChfeeDetail > GetFeeDataList ( string strCondition , string userid , string usercode , string orgcode , string sort )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , orgcode ) ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstr ;
}
else
{
strCondition = rangstr ;
}
}
var INVISNOTSTL = MsSysParamSetDAL . GetData ( "PARAMNAME='INVISNOTSTL'" ) ;
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" ) ;
strSql . Append ( ",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 as FeeObjName,f.amount,f.currency,f.exChangerate,f.AccTaxRate" ) ;
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( ",f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount" ) ;
}
else
{
strSql . Append ( ",f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount" ) ;
}
strSql . Append ( " from ch_fee f " ) ;
strSql . Append ( " left join v_op_bill b on (b.bsno=f.bsno)" ) ;
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 b.BsNo" ) ;
}
return SetFeeData ( strSql ) ;
}
private static List < BillChfeeDetail > SetFeeData ( StringBuilder strSql )
{
var headList = new List < BillChfeeDetail > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
BillChfeeDetail data = new BillChfeeDetail ( ) ;
#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" ] ) ;
if ( reader [ "BSSTATUS" ] ! = DBNull . Value )
data . BSSTATUS = Convert . ToBoolean ( reader [ "BSSTATUS" ] ) ;
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 . FeeObjName = Convert . ToString ( reader [ "FeeObjName" ] ) ;
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" ] ) ;
if ( reader [ "exChangerate" ] ! = DBNull . Value )
data . ExChangerate = Convert . ToDecimal ( reader [ "exChangerate" ] ) ;
if ( reader [ "AccTaxRate" ] ! = DBNull . Value )
data . AccTaxRate = Convert . ToDecimal ( reader [ "AccTaxRate" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
# endregion
#region 添加列表
static public List < BillCustDetail > GetAddBillList ( int start , int limit , string strCondition , string userid , string usercode , string orgcode , string sort )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , orgcode ) ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstr ;
}
else
{
strCondition = rangstr ;
}
}
var PAYUSEFEERANGE = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFEERANGE'" ) ;
if ( PAYUSEFEERANGE . PARAMVALUE = = "1" )
{
var rangstrfee = GetRangAddFeeDAStr ( userid , usercode , orgcode ) ;
if ( ! string . IsNullOrEmpty ( rangstrfee ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstrfee ;
}
else
{
strCondition = rangstrfee ;
}
}
}
var INVISNOTSTL = MsSysParamSetDAL . GetData ( "PARAMNAME='INVISNOTSTL'" ) ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( @"SELECT * from (SELECT row_number() over (" ) ;
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
sortstring = sortstring . Replace ( "FEEOBJNAME" , "F.CUSTOMERNAME" ) ;
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by b.BsNo" ) ;
}
strSql . Append ( @") as num , " ) ;
strSql . Append ( "b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO" ) ;
strSql . Append ( ",b.CUSTOMERNAME" ) ;
strSql . Append ( ",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD" ) ;
strSql . Append ( ",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE" ) ;
strSql . Append ( ",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.REMARK,b.SALECORPID,(SELECT [NAME] from [COMPANY] WHERE GID=b.SALECORPID) SALECORP" ) ;
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," ) ;
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.SETTLEMENT,0)-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.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR," ) ;
}
else
{
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," ) ;
}
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," ) ;
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.SETTLEMENT,0)-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.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR," ) ;
}
else
{
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," ) ;
}
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," ) ;
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.amount-isnull(f.SETTLEMENT,0)-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.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR" ) ;
}
else
{
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" ) ;
}
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 ISNULL(f.INVLINKGID,'')='' " ) ;
var InvAppFeeStatus = MsSysParamSetDAL . GetData ( "PARAMNAME='InvAppFeeStatus'" ) ;
if ( InvAppFeeStatus . PARAMVALUE ! = "2" )
strSql . Append ( " and f.FEESTATUS IN (0,8,9) " ) ;
else
strSql . Append ( " and f.FEESTATUS IN (2,0,8,9) " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " AND " + strCondition ) ;
}
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( " and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) " ) ;
}
strSql . Append ( "GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO" ) ;
strSql . Append ( ",b.CUSTOMERNAME" ) ;
strSql . Append ( ",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD" ) ;
strSql . Append ( ",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE" ) ;
strSql . Append ( ",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.REMARK,b.SALECORPID,f.CUSTOMERNAME" ) ;
strSql . Append ( @")as t " ) ;
strSql . Append ( string . Format ( "where t.num>{0} and t.num<={1} " , start , start + limit ) ) ; / /
return SetAddBillData ( strSql ) ;
}
public static int getAddBillTotalCount ( string strCondition , string userid , string usercode , string companyid )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstr ;
}
else
{
strCondition = rangstr ;
}
}
var PAYUSEFEERANGE = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFEERANGE'" ) ;
if ( PAYUSEFEERANGE . PARAMVALUE = = "1" )
{
var rangstrfee = GetRangAddFeeDAStr ( userid , usercode , companyid ) ;
if ( ! string . IsNullOrEmpty ( rangstrfee ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstrfee ;
}
else
{
strCondition = rangstrfee ;
}
}
}
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 ISNULL(f.INVLINKGID,'')='' " ) ;
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 ;
}
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 . ORDERNO = Convert . ToString ( reader [ "ORDERNO" ] ) ;
data . CUSTOMERNAME = Convert . ToString ( reader [ "CUSTOMERNAME" ] ) ;
data . VESSEL = Convert . ToString ( reader [ "VESSEL" ] ) ;
data . VOYNO = Convert . ToString ( reader [ "VOYNO" ] ) ;
data . PORTLOAD = Convert . ToString ( reader [ "PORTLOAD" ] ) ;
data . PORTDISCHARGE = Convert . ToString ( reader [ "PORTDISCHARGE" ] ) ;
data . 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 . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
data . SALECORPID = Convert . ToString ( reader [ "SALECORPID" ] ) ;
data . SALECORP = Convert . ToString ( reader [ "SALECORP" ] ) ;
if ( reader [ "BSSTATUS" ] ! = DBNull . Value )
data . BSSTATUS = Convert . ToBoolean ( reader [ "BSSTATUS" ] ) ;
data . FEEOBJNAME = Convert . ToString ( reader [ "CUSTNAME" ] ) ;
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" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
static public List < BillTruckCustDetail > GetAddTruckBillList ( int start , int limit , string strCondition , string userid , string usercode , string orgcode , string sort )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , orgcode ) ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstr ;
}
else
{
strCondition = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( @"SELECT * from (SELECT row_number() over (" ) ;
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
sortstring = sortstring . Replace ( "FEEOBJNAME" , "F.CUSTOMERNAME" ) ;
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by b.BsNo" ) ;
}
strSql . Append ( @") as num , " ) ;
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 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," ) ;
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR," ) ;
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR," ) ;
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.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," ) ;
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR," ) ;
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR," ) ;
strSql . Append ( "isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.amount-isnull(f.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" ) ;
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 ) ;
}
var INVISNOTSTL = MsSysParamSetDAL . GetData ( "PARAMNAME='INVISNOTSTL'" ) ;
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( " and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) " ) ;
}
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,f.CUSTOMERNAME" ) ;
strSql . Append ( @")as t " ) ;
strSql . Append ( string . Format ( "where t.num>{0} and t.num<={1} " , start , start + limit ) ) ; / /
return SetAddTruckBillData ( strSql ) ;
}
public static int getAddTruckBillTotalCount ( string strCondition , string userid , string usercode , string companyid )
{
var rangstr = GetRangDAStr ( "index" , userid , usercode , companyid ) ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstr ;
}
else
{
strCondition = rangstr ;
}
}
StringBuilder strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME " ) ;
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,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 ;
}
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 . 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 . 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 . OP = Convert . ToString ( reader [ "OP" ] ) ;
data . CUSTSERVICE = Convert . ToString ( reader [ "CUSTSERVICE" ] ) ;
data . FEEOBJNAME = Convert . ToString ( reader [ "CUSTNAME" ] ) ;
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" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
# endregion
static public List < Chfee_do_Sum > GetAddSum ( string strCondition , string userid , string usercode , string orgcode )
{
var rangstr = GetRangDAStr ( "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 f.FEETYPE,(CASE f.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.CURRENCY,Sum(f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0)) AMOUNT " ) ;
strSql . Append ( " from ch_fee f " ) ;
strSql . Append ( " left join v_op_bill b on (b.bsno=f.bsno)" ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition ) ;
}
strSql . Append ( " Group by f.FEETYPE,f.CURRENCY" ) ;
return BodySumSetData ( strSql ) ;
}
static public List < ChFeeExrate > GetCurrExrateData ( string billcust , string billcurr , string feesql , bool custgroup = false )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT DISTINCT CURRENCY,EXCHANGERATE " ) ;
if ( ! custgroup )
strSql . Append ( " FROM ch_fee f where CURRENCY<>'" + billcurr + "' AND CUSTOMERNAME='" + billcust + "'" ) ;
else
strSql . Append ( " FROM ch_fee f where CURRENCY<>'" + billcurr + "'" ) ;
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 ;
}
#region 费用列表明细
static public List < ChFeeDetail > GetFeeDetailList ( string strCondition , string userid , string usercode , string orgcode , string sort = null )
{
var strSql = new StringBuilder ( ) ;
var PAYUSEFEERANGE = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFEERANGE'" ) ;
if ( PAYUSEFEERANGE . PARAMVALUE = = "1" )
{
var rangstrfee = GetRangAddFeeDAStr ( userid , usercode , orgcode ) ;
if ( ! string . IsNullOrEmpty ( rangstrfee ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstrfee ;
}
else
{
strCondition = rangstrfee ;
}
}
}
strSql . Append ( "SELECT * from (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)+isnull(f.ORDERINVSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.AccTaxRate,f.REMARK" ) ;
strSql . Append ( ",f.INPUTMODE from ch_fee f " ) ;
strSql . Append ( " where f.ISINVOICE<>1 and ISNULL(f.INVLINKGID,'')='' " ) ;
var InvAppFeeStatus = MsSysParamSetDAL . GetData ( "PARAMNAME='InvAppFeeStatus'" ) ;
if ( InvAppFeeStatus . PARAMVALUE ! = "2" )
strSql . Append ( " and f.FEESTATUS IN (0,8,9) " ) ;
else
strSql . Append ( " and f.FEESTATUS IN (2,0,8,9) " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " AND " + strCondition ) ;
}
var INVISNOTSTL = MsSysParamSetDAL . GetData ( "PARAMNAME='INVISNOTSTL'" ) ;
if ( INVISNOTSTL . PARAMVALUE = = "1" )
{
strSql . Append ( " and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) " ) ;
}
strSql . Append ( " ) AS VF " ) ;
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" ) ;
}
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" ] ) ;
if ( reader [ "AccTaxRate" ] ! = DBNull . Value )
data . AccTaxRate = Convert . ToDecimal ( reader [ "AccTaxRate" ] ) ;
data . INPUTMODE = Convert . ToString ( reader [ "INPUTMODE" ] ) ;
data . Remark = Convert . ToString ( reader [ "REMARK" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
# endregion
#region 发票明细保存,删除
public static DBResult SaveInvDetail ( string BsNo , List < ChInvoiceDetail > bodyList )
{
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_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values ( @GID , @PID , @SerialNo , @GOODSNAME , @SPEC , @UNIT , @PKGS , @TAXPRICE , @PRICE , @AMOUNT , @TAXRATE , @TAX , @Remark , @GOODCODE ) ");
var cmdUpdate =
db . GetSqlStringCommand (
@ "update ch_fee_invoicedetail set SerialNo=@SerialNo,GOODSNAME=@GOODSNAME,SPEC=@SPEC,UNIT=@UNIT,PKGS=@PKGS,TAXPRICE=@TAXPRICE
, PRICE = @PRICE , AMOUNT = @AMOUNT , TAXRATE = @TAXRATE , Remark = @Remark , TAX = @TAX , GOODCODE = @GOODCODE where GID = @GID ");
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
if ( enumValue . PID = = "*" | | enumValue . GID = = "" )
{
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@PID" , DbType . String , BsNo ) ;
db . AddInParameter ( cmdInsert , "@SerialNo" , DbType . Int32 , enumValue . SERIALNO ) ;
db . AddInParameter ( cmdInsert , "@GOODSNAME" , DbType . String , enumValue . GOODSNAME ) ;
db . AddInParameter ( cmdInsert , "@SPEC" , DbType . String , enumValue . SPEC ) ;
db . AddInParameter ( cmdInsert , "@UNIT" , DbType . String , enumValue . UNIT ) ;
db . AddInParameter ( cmdInsert , "@PKGS" , DbType . Decimal , enumValue . PKGS ) ;
db . AddInParameter ( cmdInsert , "@TAXPRICE" , DbType . Decimal , enumValue . TAXPRICE ) ;
db . AddInParameter ( cmdInsert , "@PRICE" , DbType . Decimal , enumValue . PRICE ) ;
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , enumValue . AMOUNT ) ;
db . AddInParameter ( cmdInsert , "@TAXRATE" , DbType . Decimal , enumValue . TAXRATE ) ;
db . AddInParameter ( cmdInsert , "@TAX" , DbType . Decimal , enumValue . TAX ) ;
db . AddInParameter ( cmdInsert , "@Remark" , DbType . String , enumValue . REMARK ) ;
db . AddInParameter ( cmdInsert , "@GOODCODE" , DbType . String , enumValue . GOODCODE ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
}
else
{
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@GID" , DbType . String , enumValue . GID ) ;
db . AddInParameter ( cmdUpdate , "@SerialNo" , DbType . Int32 , enumValue . SERIALNO ) ;
db . AddInParameter ( cmdUpdate , "@GOODSNAME" , DbType . String , enumValue . GOODSNAME ) ;
db . AddInParameter ( cmdUpdate , "@SPEC" , DbType . String , enumValue . SPEC ) ;
db . AddInParameter ( cmdUpdate , "@UNIT" , DbType . String , enumValue . UNIT ) ;
db . AddInParameter ( cmdUpdate , "@PKGS" , DbType . Decimal , enumValue . PKGS ) ;
db . AddInParameter ( cmdUpdate , "@TAXPRICE" , DbType . Decimal , enumValue . TAXPRICE ) ;
db . AddInParameter ( cmdUpdate , "@PRICE" , DbType . Decimal , enumValue . PRICE ) ;
db . AddInParameter ( cmdUpdate , "@AMOUNT" , DbType . Decimal , enumValue . AMOUNT ) ;
db . AddInParameter ( cmdUpdate , "@TAXRATE" , DbType . Decimal , enumValue . TAXRATE ) ;
db . AddInParameter ( cmdUpdate , "@TAX" , DbType . Decimal , enumValue . TAX ) ;
db . AddInParameter ( cmdUpdate , "@Remark" , DbType . String , enumValue . REMARK ) ;
db . AddInParameter ( cmdUpdate , "@GOODCODE" , DbType . String , enumValue . GOODCODE ) ;
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 DelInvDetail ( List < ChInvoiceDetail > bodyList )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdInsert =
db . GetSqlStringCommand (
@"delete from ch_fee_invoicedetail where GID=@GID " ) ;
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , enumValue . GID ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
}
}
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "删除出现错误,请重试或联系系统管理员" ;
return result ;
}
}
result . Success = true ;
result . Message = "删除成功" + result . Message ;
return result ;
}
# endregion
public static DBResult AddDetail ( string billno , List < BillChfeeDetail > bodyList , string curr , string companyid , bool isList , string GID , ChInvoice headData )
{
var result = new DBResult ( ) ;
bool INVAPPMAX = false ;
decimal ttlamount = headData . INVAMOUNT ;
var INVAPPMAXPARAM = MsSysParamSetDAL . GetData ( "PARAMNAME='INVAPPMAX'" ) ;
if ( INVAPPMAXPARAM . PARAMVALUE = = "1" )
{
INVAPPMAX = true ;
}
if ( ttlamount > = 99999 & & INVAPPMAX )
{
result . Success = false ;
result . Message = "单张发票申请不能超过十万元" ;
return result ;
}
bool ischaoe = false ;
var defGOOD = MsCodeGoodInvDAL . GetData ( " ISDEF='1' and (DEFCURR='' or DEFCURR='" + headData . RECVCURR + "')" ) ;
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 (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 INVOICE=ISNULL(INVOICE,0)+@INVOICE,INVOICENUM=@INVOICENUM WHERE GID=@GID " ) ;
var cmdInsertInv =
db . GetSqlStringCommand (
@ "insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values ( @GID , @PID , @SerialNo , @GOODSNAME , @SPEC , @UNIT , @PKGS , @TAXPRICE , @PRICE , @AMOUNT , @TAXRATE , @TAX , @Remark , @GOODCODE ) ");
var cmdUpdateInv =
db . GetSqlStringCommand (
@ "update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
, PRICE = @PRICE , AMOUNT = @AMOUNT , TAX = @TAX where GID = @GID ");
decimal amtttl = 0 ;
decimal acctaxrate = 0 ;
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
if ( ( ttlamount + Math . Round ( enumValue . DoAmount , 2 , MidpointRounding . AwayFromZero ) ) > = 99999 & & INVAPPMAX )
{
ischaoe = true ;
//doamount = 99999-ttlamount;
//StlAmount = Math.Round(enumValue.StlAmount*((99999 - ttlamount)/doamount),2, MidpointRounding.AwayFromZero);
}
else
{
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 , enumValue . MBLNO ) ;
db . AddInParameter ( cmdInsert , "@HBLNO" , DbType . String , enumValue . HBLNO ) ;
db . AddInParameter ( cmdInsert , "@CUSTOMERNAME" , DbType . String , enumValue . FeeObjName ) ;
//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 , Math . Round ( enumValue . DoAmount , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@FEETYPE" , DbType . Int16 , enumValue . FeeType ) ;
db . AddInParameter ( cmdInsert , "@CATEGORY" , DbType . Int16 , 7 ) ;
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 , "@INVOICE" , DbType . Decimal , enumValue . StlAmount ) ;
db . AddInParameter ( cmdUpdate , "@INVOICENUM" , DbType . String , headData . INVOICENO ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
if ( isList )
{
cmdInsertInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInv , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsertInv , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInv , "@SerialNo" , DbType . Int32 , 1 ) ;
db . AddInParameter ( cmdInsertInv , "@GOODSNAME" , DbType . String , enumValue . FeeName ) ;
db . AddInParameter ( cmdInsertInv , "@SPEC" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInv , "@UNIT" , DbType . String , "票" ) ;
db . AddInParameter ( cmdInsertInv , "@PKGS" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( enumValue . DoAmount , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@TAXRATE" , DbType . Decimal , headData . EXCHANGERATE ) ;
if ( headData . EXCHANGERATE = = 0 )
{
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , Math . Round ( enumValue . DoAmount , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , Math . Round ( enumValue . DoAmount , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( enumValue . DoAmount / ( 1 + headData . EXCHANGERATE / 100 ) * ( headData . EXCHANGERATE / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = enumValue . DoAmount - tax ;
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , tax ) ;
}
db . AddInParameter ( cmdInsertInv , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInv , "@GOODCODE" , DbType . String , "" ) ;
db . ExecuteNonQuery ( cmdInsertInv , tran ) ;
}
if ( enumValue . FeeType = = 2 )
amtttl = amtttl - enumValue . DoAmount ;
else
amtttl = amtttl + enumValue . DoAmount ;
ttlamount = ttlamount + amtttl ;
}
}
}
acctaxrate = headData . EXCHANGERATE ;
if ( ! isList & & amtttl ! = 0 ) {
var dataList = GetDetailList ( " PID='" + GID + "'" ) ;
if ( dataList . Count ! = 0 )
{
var invlist = dataList [ 0 ] ;
cmdUpdateInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInv , "@GID" , DbType . String , invlist . GID ) ;
if ( acctaxrate = = 0 )
{
db . AddInParameter ( cmdUpdateInv , "@AMOUNT" , DbType . Decimal , Math . Round ( invlist . AMOUNT + amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( ( invlist . AMOUNT + amtttl ) / invlist . PKGS , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@PRICE" , DbType . Decimal , Math . Round ( ( invlist . AMOUNT + amtttl ) / invlist . PKGS , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXRATE" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdUpdateInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else {
amtttl = amtttl + ( invlist . TAXPRICE * invlist . PKGS ) ;
var tax = Math . Round ( amtttl / ( 1 + acctaxrate / 100 ) * ( acctaxrate / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
db . AddInParameter ( cmdUpdateInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdUpdateInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdUpdateInv , "@TAX" , DbType . Decimal , tax ) ;
//var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2);
//var amount = amtttl - tax;
//db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, invlist.AMOUNT + amount);
//db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal,Math.Round(((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 100),2));
//db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amount) / invlist.PKGS,2));
//db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal,invlist.TAX+tax);
}
db . ExecuteNonQuery ( cmdUpdateInv , tran ) ;
}
else {
cmdInsertInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInv , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsertInv , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInv , "@SerialNo" , DbType . Int32 , 1 ) ;
if ( defGOOD . GOODNAME = = "" )
{
db . AddInParameter ( cmdInsertInv , "@GOODSNAME" , DbType . String , "代理运杂费" ) ;
db . AddInParameter ( cmdInsertInv , "@UNIT" , DbType . String , "票" ) ;
}
else
{
db . AddInParameter ( cmdInsertInv , "@GOODSNAME" , DbType . String , defGOOD . GID ) ;
db . AddInParameter ( cmdInsertInv , "@UNIT" , DbType . String , defGOOD . UNIT ) ;
}
db . AddInParameter ( cmdInsertInv , "@SPEC" , DbType . String , defGOOD . SPEC ) ;
db . AddInParameter ( cmdInsertInv , "@PKGS" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@TAXRATE" , DbType . Decimal , acctaxrate ) ;
if ( acctaxrate = = 0 )
{
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , Math . Round ( amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , Math . Round ( amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( amtttl / ( 1 + acctaxrate / 100 ) * ( acctaxrate / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , tax ) ;
}
db . AddInParameter ( cmdInsertInv , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInv , "@GOODCODE" , DbType . String , defGOOD . GOODCODE ) ;
db . ExecuteNonQuery ( cmdInsertInv , tran ) ;
}
}
if ( ischaoe )
{
result . Success = false ;
result . Message = "单张发票不能超过十万元" ;
}
else
{
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 = "保存成功" + result.Message;
return result ;
}
public static DBResult AddBill ( ChInvoice headData , string feesql , List < ChFeeExrate > exratelist , string companyid , bool isList , string GID , string userid , bool custgroup = false )
{
var result = new DBResult ( ) ;
var defGOOD = MsCodeGoodInvDAL . GetData ( " ISDEF='1' and (DEFCURR='' or DEFCURR='" + headData . RECVCURR + "') " ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
decimal amtttl = 0 ;
decimal acctaxrate = 0 ;
bool INVAPPMAX = false ;
decimal ttlamount = headData . INVAMOUNT ;
var INVAPPMAXPARAM = MsSysParamSetDAL . GetData ( "PARAMNAME='INVAPPMAX'" ) ;
if ( INVAPPMAXPARAM . PARAMVALUE = = "1" )
{
INVAPPMAX = true ;
}
if ( ttlamount > = 99999 & & INVAPPMAX )
{
result . Success = false ;
result . Message = "单张发票申请不能超过十万元" ;
return result ;
}
bool ischaoe = false ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
if ( ! custgroup )
feesql = feesql + " AND CUSTOMERNAME='" + headData . CUSTOMERNAME + "'" ;
var feelist = GetFeeDetailList ( feesql , userid , "" , companyid ) ;
var cmdInsert =
db . GetSqlStringCommand (
@ "insert into ch_fee_do (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 INVOICE=ISNULL(INVOICE,0)+@INVOICE,INVOICENUM=@INVOICENUM WHERE GID=@GID " ) ;
var cmdInsertInv =
db . GetSqlStringCommand (
@ "insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values ( @GID , @PID , @SerialNo , @GOODSNAME , @SPEC , @UNIT , @PKGS , @TAXPRICE , @PRICE , @AMOUNT , @TAXRATE , @TAX , @Remark , @GOODCODE ) ");
var cmdUpdateInv =
db . GetSqlStringCommand (
@ "update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
, PRICE = @PRICE , AMOUNT = @AMOUNT , TAX = @TAX where GID = @GID ");
if ( feelist ! = null )
{
foreach ( var enumValue in feelist )
{
decimal feettl = 0 ;
decimal otamount = 0 ;
ischaoe = false ;
if ( headData . CURRENCY = = enumValue . Currency )
{
feettl = enumValue . StlAmount ;
if ( enumValue . FeeType = = 2 )
otamount = - enumValue . StlAmount ;
else
otamount = enumValue . StlAmount ;
if ( ( ttlamount + Math . Round ( otamount , 2 , MidpointRounding . AwayFromZero ) ) > = 100000 & & INVAPPMAX )
{
feettl = 0 ;
ischaoe = true ;
}
}
else
{
var UExrate = GetExrate ( enumValue . Currency , exratelist ) ;
if ( enumValue . FeeType = = 2 )
otamount = - enumValue . StlAmount * UExrate ;
else
otamount = enumValue . StlAmount * UExrate ;
if ( ( ttlamount + Math . Round ( otamount , 2 , MidpointRounding . AwayFromZero ) ) > = 100000 & & INVAPPMAX )
{
feettl = 0 ;
ischaoe = true ;
}
}
if ( ! ischaoe )
{
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@BILLNO" , DbType . String , headData . 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 , headData . CURRENCY ) ;
if ( headData . CURRENCY = = enumValue . Currency )
{
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , enumValue . StlAmount ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@EXCHANGERATE" , DbType . Decimal , 1 ) ;
if ( enumValue . FeeType = = 2 )
amtttl = amtttl - enumValue . StlAmount ;
else
amtttl = amtttl + enumValue . StlAmount ;
}
else
{
var UExrate = GetExrate ( enumValue . Currency , exratelist ) ;
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , Math . Round ( enumValue . StlAmount * UExrate , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@EXCHANGERATE" , DbType . Decimal , UExrate ) ;
if ( enumValue . FeeType = = 2 )
amtttl = amtttl - Math . Round ( enumValue . StlAmount * UExrate , 2 , MidpointRounding . AwayFromZero ) ;
else
amtttl = amtttl + Math . Round ( enumValue . StlAmount * UExrate , 2 , MidpointRounding . AwayFromZero ) ;
}
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 , 7 ) ;
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 ) ;
db . AddInParameter ( cmdUpdate , "@INVOICE" , DbType . Decimal , enumValue . StlAmount ) ;
db . AddInParameter ( cmdUpdate , "@INVOICENUM" , DbType . String , headData . INVOICENO ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
ttlamount = ttlamount + amtttl ;
if ( isList )
{
cmdInsertInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInv , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsertInv , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInv , "@SerialNo" , DbType . Int32 , 1 ) ;
db . AddInParameter ( cmdInsertInv , "@GOODSNAME" , DbType . String , enumValue . FeeName ) ;
db . AddInParameter ( cmdInsertInv , "@SPEC" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInv , "@UNIT" , DbType . String , "票" ) ;
db . AddInParameter ( cmdInsertInv , "@PKGS" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInv , "@TAXRATE" , DbType . Decimal , enumValue . AccTaxRate ) ;
if ( headData . CURRENCY = = enumValue . Currency )
{
db . AddInParameter ( cmdInsertInv , "@TAXPRICE" , DbType . Decimal , enumValue . StlAmount ) ;
if ( headData . EXCHANGERATE = = 0 )
{
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , enumValue . StlAmount ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , enumValue . StlAmount ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( enumValue . StlAmount / ( 1 + headData . EXCHANGERATE / 100 ) * ( headData . EXCHANGERATE / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , tax ) ;
}
}
else
{
var UExrate = GetExrate ( enumValue . Currency , exratelist ) ;
db . AddInParameter ( cmdInsertInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( enumValue . StlAmount * UExrate , 2 , MidpointRounding . AwayFromZero ) ) ;
if ( headData . EXCHANGERATE = = 0 )
{
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , Math . Round ( enumValue . StlAmount * UExrate , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , Math . Round ( enumValue . StlAmount * UExrate , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( ( enumValue . StlAmount * UExrate ) / ( 1 + headData . EXCHANGERATE / 100 ) * ( headData . EXCHANGERATE / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = Math . Round ( ( enumValue . StlAmount * UExrate ) - tax , 2 , MidpointRounding . AwayFromZero ) ;
// var amount =Math.Round((enumValue.StlAmount * UExrate) / (1 + enumValue.AccTaxRate / 100),2);
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , tax ) ;
}
}
db . AddInParameter ( cmdInsertInv , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInv , "@GOODCODE" , DbType . String , "" ) ;
db . ExecuteNonQuery ( cmdInsertInv , tran ) ;
}
}
}
}
acctaxrate = headData . EXCHANGERATE ;
if ( ! isList & & amtttl ! = 0 )
{
var dataList = GetDetailList ( " PID='" + GID + "'" ) ;
if ( dataList . Count ! = 0 )
{
var invlist = dataList [ 0 ] ;
cmdUpdateInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInv , "@GID" , DbType . String , invlist . GID ) ;
if ( acctaxrate = = 0 )
{
db . AddInParameter ( cmdUpdateInv , "@AMOUNT" , DbType . Decimal , Math . Round ( invlist . AMOUNT + amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( ( invlist . AMOUNT + amtttl ) / invlist . PKGS , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@PRICE" , DbType . Decimal , Math . Round ( ( invlist . AMOUNT + amtttl ) / invlist . PKGS , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXRATE" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdUpdateInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
amtttl = amtttl + ( invlist . TAXPRICE * invlist . PKGS ) ;
var tax = Math . Round ( amtttl / ( 1 + acctaxrate / 100 ) * ( acctaxrate / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
db . AddInParameter ( cmdUpdateInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( amtttl , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdUpdateInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdUpdateInv , "@TAX" , DbType . Decimal , tax ) ;
//var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2);
//var amount =amtttl- tax;
//db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT + amount,2));
//db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 100),2));
//db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal,Math.Round((invlist.AMOUNT + amount) / invlist.PKGS,2));
//db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, invlist.TAX+tax);
}
db . ExecuteNonQuery ( cmdUpdateInv , tran ) ;
}
else
{
cmdInsertInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInv , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsertInv , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInv , "@SerialNo" , DbType . Int32 , 1 ) ;
if ( defGOOD . GOODNAME = = "" )
{
db . AddInParameter ( cmdInsertInv , "@GOODSNAME" , DbType . String , "代理运杂费" ) ;
db . AddInParameter ( cmdInsertInv , "@UNIT" , DbType . String , "票" ) ;
}
else
{
db . AddInParameter ( cmdInsertInv , "@GOODSNAME" , DbType . String , defGOOD . GID ) ;
db . AddInParameter ( cmdInsertInv , "@UNIT" , DbType . String , defGOOD . UNIT ) ;
}
db . AddInParameter ( cmdInsertInv , "@SPEC" , DbType . String , defGOOD . SPEC ) ;
db . AddInParameter ( cmdInsertInv , "@PKGS" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInv , "@TAXPRICE" , DbType . Decimal , amtttl ) ;
db . AddInParameter ( cmdInsertInv , "@TAXRATE" , DbType . Decimal , acctaxrate ) ;
if ( acctaxrate = = 0 )
{
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , amtttl ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , amtttl ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( amtttl / ( 1 + acctaxrate / 100 ) * ( acctaxrate / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = amtttl - tax ;
// var amount = Math.Round(amtttl / (1 + acctaxrate / 100),2);
db . AddInParameter ( cmdInsertInv , "@PRICE" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@AMOUNT" , DbType . Decimal , amount ) ;
db . AddInParameter ( cmdInsertInv , "@TAX" , DbType . Decimal , tax ) ;
}
db . AddInParameter ( cmdInsertInv , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInv , "@GOODCODE" , DbType . String , defGOOD . GOODCODE ) ;
db . ExecuteNonQuery ( cmdInsertInv , tran ) ;
}
}
if ( ischaoe )
{
result . Success = false ;
result . Message = "单张发票不能超过十万元" ;
}
else
{
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 updateFeeTax ( string billno , decimal taxrate )
{
var result = new DBResult ( ) ;
var dataList = ChinvoiceDAL . 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 ;
}
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 DelFeeDo ( List < Chfee_do_detail > boday , string GID )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
decimal AMOUNT = 0 ;
if ( boday ! = null )
{
var cmddelete = db . GetSqlStringCommand ( "delete from ch_fee_do where GID=@FEEDOID" ) ;
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee set INVOICE=ISNULL(INVOICE,0)-@ORIGAMOUNT,INVOICENUM='' 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 ) ;
if ( enumValue . FEETYPE = = 1 )
AMOUNT = AMOUNT + enumValue . AMOUNT ;
else AMOUNT = AMOUNT - enumValue . AMOUNT ;
}
var dataList = GetDetailList ( " PID='" + GID + "'" ) ;
if ( dataList . Count ! = 0 )
{
var cmdUpdateInv =
db . GetSqlStringCommand (
@ "update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
, PRICE = @PRICE , AMOUNT = @AMOUNT , TAX = @TAX where GID = @GID ");
var invlist = dataList [ 0 ] ;
cmdUpdateInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInv , "@GID" , DbType . String , invlist . GID ) ;
if ( invlist . TAXRATE = = 0 )
{
db . AddInParameter ( cmdUpdateInv , "@AMOUNT" , DbType . Decimal , Math . Round ( invlist . AMOUNT - AMOUNT , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXPRICE" , DbType . Decimal , Math . Round ( ( invlist . AMOUNT - AMOUNT ) / invlist . PKGS , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@PRICE" , DbType . Decimal , Math . Round ( ( invlist . AMOUNT - AMOUNT ) / invlist . PKGS , 2 , MidpointRounding . AwayFromZero ) ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXRATE" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdUpdateInv , "@TAX" , DbType . Decimal , 0 ) ;
}
else
{
var tax = Math . Round ( AMOUNT / ( 1 + invlist . TAXRATE / 100 ) * ( invlist . TAXRATE / 100 ) , 2 , MidpointRounding . AwayFromZero ) ;
var amount = AMOUNT - tax ;
db . AddInParameter ( cmdUpdateInv , "@AMOUNT" , DbType . Decimal , invlist . AMOUNT - amount ) ;
db . AddInParameter ( cmdUpdateInv , "@TAXPRICE" , DbType . Decimal , ( ( invlist . AMOUNT - amount ) / invlist . PKGS ) * ( 1 + invlist . TAXRATE / 100 ) ) ;
db . AddInParameter ( cmdUpdateInv , "@PRICE" , DbType . Decimal , ( invlist . AMOUNT - amount ) / invlist . PKGS ) ;
db . AddInParameter ( cmdUpdateInv , "@TAX" , DbType . Decimal , invlist . TAX - tax ) ;
}
db . ExecuteNonQuery ( cmdUpdateInv , 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 , string GID )
{
Database db = DatabaseFactory . CreateDatabase ( ) ;
var cmd = db . GetStoredProcCommand ( "p_update_invoice" ) ;
db . AddInParameter ( cmd , "@con_no" , DbType . String , billno ) ;
db . AddInParameter ( cmd , "@con_gid" , DbType . String , GID ) ;
db . ExecuteNonQuery ( cmd ) ;
return 0 ;
}
#region 发票申请开票和取消
public static DBResult AddAppDetail ( string billno , List < ChInvoiceapplication > bodyList , string invoiceno , string companyid , string GID )
{
var result = new DBResult ( ) ;
var invdetailDataList = GetDetailList ( "PID='" + GID + "'" ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdUpdateInv =
db . GetSqlStringCommand (
@ "update ch_fee_invoice set REMARK=REMARK+' '+@REMARK
WHERE BILLNO = @BILLNO ");
var cmdInsert =
db . GetSqlStringCommand (
@ "insert ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
, AMOUNT , DOAMOUNT , FEETYPE , CATEGORY , BILLSTATUS , ISDELETED , CREATETIME
, EXCHANGERATE , ORIGCURRENCY , ORIGAMOUNT , INVOICESETTLENO , COMPANYID )
SELECT NEWID ( ) , @BILLNO , BSNO , MBLNO , HBLNO , CUSTOMERNAME , BSTYPE , FEEID , FEENAME , CURRENCY
, AMOUNT , DOAMOUNT , FEETYPE , 7 , BILLSTATUS , ISDELETED , GETDATE ( ) , EXCHANGERATE , ORIGCURRENCY
, ORIGAMOUNT , INVOICESETTLENO , COMPANYID from ch_fee_do WHERE BILLNO = @AppBILLNO ");
var cmdUpdate =
db . GetSqlStringCommand (
@ "declare @FEEID varchar(100)
declare @ORDERINVOICE numeric ( 19 , 4 )
declare CurBill cursor for
select FEEID , ORIGAMOUNT ORDERINVOICE
from ch_fee_do where BILLNO = @AppBILLNO
open CurBill
fetch next from CurBill into @FEEID , @ORDERINVOICE
while @ @Fetch_Status = 0
begin
UPDATE CH_FEE SET INVOICE = ISNULL ( INVOICE , 0 ) + @ORDERINVOICE , ORDERINVSETTLEMENT = ISNULL ( ORDERINVSETTLEMENT , 0 ) + @ORDERINVOICE , INVOICENUM = @INVOICENUM WHERE GID = @FEEID
fetch next from CurBill into @FEEID , @ORDERINVOICE
end ;
close CurBill
dealLocate CurBill
");
var cmdUpdateApp =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoiceapplication set BILLSTATUS=3,INVBILLNO=@INVBILLNO,INVOICENO=@INVOICENO where BILLNO=@BILLNO" ) ;
var cmdInsertInvDetail =
db . GetSqlStringCommand (
@ "insert ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values ( NEWID ( ) , @PID , @SerialNo , @GOODSNAME , @SPEC , @UNIT , @PKGS , @TAXPRICE , @PRICE , @AMOUNT , @TAXRATE , @TAX , @Remark , @GOODCODE ) ");
var currency = "" ;
decimal rate = 0 ;
var custrateno = "" ;
var custaddrtel = "" ;
var custbank = "" ;
var INVOICECATEGORY = "" ;
var ACTUALCUSTOMERNAME = "" ;
var INVOICECUSTNAME = "" ;
var REMARK = "" ;
var invdetailid = "" ;
if ( bodyList ! = null )
{
cmdUpdateInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInv , "@BILLNO" , DbType . String , billno ) ;
foreach ( var enumValue in bodyList )
{
currency = enumValue . CURRENCY ;
rate = enumValue . RATE ;
custrateno = enumValue . CUSTRATENO ;
custaddrtel = enumValue . CUSTADDRTEL ;
custbank = enumValue . CUSTBANK ;
INVOICECATEGORY = enumValue . INVOICECATEGORY ;
ACTUALCUSTOMERNAME = enumValue . ACTUALCUSTOMERNAME ;
INVOICECUSTNAME = enumValue . INVOICECUSTNAME ;
REMARK = REMARK + ' ' + enumValue . REMARK ;
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@BILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdInsert , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . AddInParameter ( cmdUpdate , "@INVOICENUM" , DbType . String , invoiceno ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
var invdetaillist = GetDetailList ( "PID='" + enumValue . GID + "'" , db , tran ) ;
if ( invdetaillist ! = null )
{
foreach ( var enumInvDetail in invdetaillist )
{
bool ishave = false ;
if ( invdetailDataList ! = null ) {
foreach ( var invdetailData in invdetailDataList )
{
if ( invdetailData . GOODSNAME = = enumInvDetail . GOODSNAME ) {
invdetailData . TAXPRICE = invdetailData . TAXPRICE + enumInvDetail . TAXPRICE ;
invdetailData . PRICE = invdetailData . PRICE + enumInvDetail . PRICE ;
invdetailData . AMOUNT = invdetailData . AMOUNT + enumInvDetail . AMOUNT ;
invdetailData . TAX = invdetailData . TAX + enumInvDetail . TAX ;
ishave = true ;
}
}
}
if ( ! ishave ) {
var invdetailtmp = enumInvDetail ;
invdetailtmp . GID = "*" ;
invdetailtmp . PID = GID ;
invdetailDataList . Add ( invdetailtmp ) ;
}
//if (invdetailData.AMOUNT == 0)
//{
// invdetailData.GOODCODE = enumInvDetail.GOODCODE;
// invdetailData.GOODSNAME = enumInvDetail.GOODSNAME;
// invdetailData.GOODSNAMEREF = enumInvDetail.GOODSNAMEREF;
// invdetailData.SPEC = enumInvDetail.SPEC;
// invdetailData.UNIT = enumInvDetail.UNIT;
// invdetailData.PKGS = enumInvDetail.PKGS;
// invdetailData.TAXPRICE = enumInvDetail.TAXPRICE;
// invdetailData.PRICE = enumInvDetail.PRICE;
// invdetailData.TAXRATE = enumInvDetail.TAXRATE;
// invdetailData.AMOUNT = enumInvDetail.AMOUNT;
// invdetailData.TAX = enumInvDetail.TAX;
// invdetailData.REMARK = enumInvDetail.REMARK;
//}
//else
//{
// invdetailData.TAXPRICE = invdetailData.TAXPRICE + enumInvDetail.TAXPRICE;
// invdetailData.PRICE = invdetailData.PRICE + enumInvDetail.PRICE;
// invdetailData.AMOUNT = invdetailData.AMOUNT + enumInvDetail.AMOUNT;
// invdetailData.TAX = invdetailData.TAX + enumInvDetail.TAX;
// invdetailid = invdetailData.GID;
//}
}
}
cmdUpdateApp . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateApp , "@INVBILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdUpdateApp , "@INVOICENO" , DbType . String , invoiceno ) ;
db . AddInParameter ( cmdUpdateApp , "@BILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdUpdateApp , tran ) ;
}
if ( invdetailDataList ! = null ) {
foreach ( var invdetailData in invdetailDataList )
{
if ( invdetailData . GID = = "*" )
{
cmdInsertInvDetail . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInvDetail , "@SerialNo" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInvDetail , "@GOODSNAME" , DbType . String , invdetailData . GOODSNAME ) ;
db . AddInParameter ( cmdInsertInvDetail , "@SPEC" , DbType . String , invdetailData . SPEC ) ;
db . AddInParameter ( cmdInsertInvDetail , "@UNIT" , DbType . String , invdetailData . UNIT ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PKGS" , DbType . Decimal , invdetailData . PKGS ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAXPRICE" , DbType . Decimal , invdetailData . TAXPRICE ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PRICE" , DbType . Decimal , invdetailData . PRICE ) ;
db . AddInParameter ( cmdInsertInvDetail , "@AMOUNT" , DbType . Decimal , invdetailData . AMOUNT ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAX" , DbType . Decimal , invdetailData . TAX ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAXRATE" , DbType . Decimal , invdetailData . TAXRATE ) ;
db . AddInParameter ( cmdInsertInvDetail , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInvDetail , "@GOODCODE" , DbType . String , invdetailData . GOODCODE ) ;
db . ExecuteNonQuery ( cmdInsertInvDetail , tran ) ;
}
else {
var cmdUpdateInvDetail =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoicedetail set TAXPRICE=@TAXPRICE,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID" ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@GID" , DbType . String , invdetailData . GID ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@TAXPRICE" , DbType . Decimal , invdetailData . TAXPRICE ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@PRICE" , DbType . Decimal , invdetailData . PRICE ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@AMOUNT" , DbType . Decimal , invdetailData . AMOUNT ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@TAX" , DbType . Decimal , invdetailData . TAX ) ;
db . ExecuteNonQuery ( cmdUpdateInvDetail , tran ) ;
}
}
}
//if (invdetailid == string.Empty)
//{
// cmdInsertInvDetail.Parameters.Clear();
// db.AddInParameter(cmdInsertInvDetail, "@PID", DbType.String, GID);
// db.AddInParameter(cmdInsertInvDetail, "@SerialNo", DbType.Decimal, 1);
// db.AddInParameter(cmdInsertInvDetail, "@GOODSNAME", DbType.String, invdetailData.GOODSNAME);
// db.AddInParameter(cmdInsertInvDetail, "@SPEC", DbType.String, invdetailData.SPEC);
// db.AddInParameter(cmdInsertInvDetail, "@UNIT", DbType.String, invdetailData.UNIT);
// db.AddInParameter(cmdInsertInvDetail, "@PKGS", DbType.Decimal, invdetailData.PKGS);
// db.AddInParameter(cmdInsertInvDetail, "@TAXPRICE", DbType.Decimal, invdetailData.TAXPRICE);
// db.AddInParameter(cmdInsertInvDetail, "@PRICE", DbType.Decimal, invdetailData.PRICE);
// db.AddInParameter(cmdInsertInvDetail, "@AMOUNT", DbType.Decimal, invdetailData.AMOUNT);
// db.AddInParameter(cmdInsertInvDetail, "@TAX", DbType.Decimal, invdetailData.TAX);
// db.AddInParameter(cmdInsertInvDetail, "@TAXRATE", DbType.Decimal, invdetailData.TAXRATE);
// db.AddInParameter(cmdInsertInvDetail, "@Remark", DbType.String, "");
// db.AddInParameter(cmdInsertInvDetail, "@GOODCODE", DbType.String, invdetailData.GOODCODE);
// db.ExecuteNonQuery(cmdInsertInvDetail, tran);
//}
//else {
// var cmdUpdateInvDetail =
// db.GetSqlStringCommand(
// @"UPDATE ch_fee_invoicedetail set TAXPRICE=@TAXPRICE,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID");
// db.AddInParameter(cmdUpdateInvDetail, "@PID", DbType.String, invdetailid);
// db.AddInParameter(cmdUpdateInvDetail, "@TAXPRICE", DbType.Decimal, invdetailData.TAXPRICE);
// db.AddInParameter(cmdUpdateInvDetail, "@PRICE", DbType.Decimal, invdetailData.PRICE);
// db.AddInParameter(cmdUpdateInvDetail, "@AMOUNT", DbType.Decimal, invdetailData.AMOUNT);
// db.AddInParameter(cmdUpdateInvDetail, "@TAX", DbType.Decimal, invdetailData.TAX);
// db.ExecuteNonQuery(cmdUpdateInvDetail, tran);
//}
db . AddInParameter ( cmdUpdateInv , "@REMARK" , DbType . String , REMARK ) ;
db . ExecuteNonQuery ( cmdUpdateInv , 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 AddAppDetailNew ( string billno , List < ChInvoiceapplication > bodyList , string invoiceno , string companyid , string GID )
{
var result = new DBResult ( ) ;
var invdetailDataList = GetDetailList ( "PID='" + GID + "'" ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdUpdatefeedo =
db . GetSqlStringCommand (
@" update ch_fee_do set doamount=ISNULL(doamount,0)+@stlamount,origstlamount=ISNULL(origstlamount,0)+@origstlamount where gid=@gid" ) ;
var cmdUpdateFEE =
db . GetSqlStringCommand (
@"UPDATE CH_FEE SET INVOICE=ISNULL(INVOICE,0)+@INVOICE,ORDERINVSETTLEMENT=ISNULL(ORDERINVSETTLEMENT,0)+@INVOICE2 WHERE GID=@GID " ) ;
var cmdUpdateInv =
db . GetSqlStringCommand (
@ "update ch_fee_invoice set REMARK=REMARK+' '+@REMARK
WHERE BILLNO = @BILLNO ");
var cmdInsert =
db . GetSqlStringCommand (
@ "insert ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
, AMOUNT , DOAMOUNT , FEETYPE , CATEGORY , BILLSTATUS , ISDELETED , CREATETIME
, EXCHANGERATE , ORIGCURRENCY , ORIGAMOUNT , INVOICESETTLENO , COMPANYID )
SELECT NEWID ( ) , @BILLNO , BSNO , MBLNO , HBLNO , CUSTOMERNAME , BSTYPE , FEEID , FEENAME , CURRENCY
, AMOUNT , DOAMOUNT , FEETYPE , 7 , BILLSTATUS , ISDELETED , GETDATE ( ) , EXCHANGERATE , ORIGCURRENCY
, ORIGAMOUNT , INVOICESETTLENO , COMPANYID from ch_fee_do WHERE BILLNO = @AppBILLNO ");
var cmdUpdateApp =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoiceapplication set BILLSTATUS=3,INVBILLNO=@INVBILLNO,INVOICENO=@INVOICENO,DOINVAMOUNT=ISNULL(DOINVAMOUNT,0)+@DOINVAMOUNT where BILLNO=@BILLNO" ) ;
var cmdInsertInvDetail =
db . GetSqlStringCommand (
@ "insert ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values ( NEWID ( ) , @PID , @SerialNo , @GOODSNAME , @SPEC , @UNIT , @PKGS , @TAXPRICE , @PRICE , @AMOUNT , @TAXRATE , @TAX , @Remark , @GOODCODE ) ");
var currency = "" ;
decimal rate = 0 ;
var custrateno = "" ;
var custaddrtel = "" ;
var custbank = "" ;
var INVOICECATEGORY = "" ;
var ACTUALCUSTOMERNAME = "" ;
var INVOICECUSTNAME = "" ;
var REMARK = "" ;
var invdetailid = "" ;
if ( bodyList ! = null )
{
cmdUpdateInv . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateInv , "@BILLNO" , DbType . String , billno ) ;
foreach ( var enumValue in bodyList )
{
var stlamount = enumValue . STLAMOUNT ;
var invappdetail = ChinvoiceapplicationDAL . GetBodyList ( "c.BILLNO='" + enumValue . BILLNO + "'" ) ;
if ( invappdetail ! = null )
{
foreach ( var feedovalue in invappdetail )
{
decimal balamount = 0 ;
decimal origamount = 0 ;
if ( stlamount ! = 0 )
{
if ( ( feedovalue . AMOUNT - feedovalue . DOAMOUNT ) < = stlamount )
{
balamount = feedovalue . AMOUNT - feedovalue . DOAMOUNT ;
if ( feedovalue . FEETYPE = = 1 )
stlamount = stlamount - balamount ;
else
stlamount = stlamount + balamount ;
origamount = feedovalue . ORIGAMOUNT - feedovalue . ORIGSTLAMOUNT ;
}
else
{
balamount = stlamount ;
stlamount = stlamount - balamount ;
origamount = balamount / feedovalue . EXCHANGERATE ;
}
cmdUpdatefeedo . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdatefeedo , "@stlamount" , DbType . Decimal , balamount ) ;
db . AddInParameter ( cmdUpdatefeedo , "@origstlamount" , DbType . Decimal , origamount ) ;
db . AddInParameter ( cmdUpdatefeedo , "@gid" , DbType . String , feedovalue . FEEDOID ) ;
db . ExecuteNonQuery ( cmdUpdatefeedo , tran ) ;
var feedoid = Guid . NewGuid ( ) . ToString ( ) ;
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , feedoid ) ;
db . AddInParameter ( cmdInsert , "@BILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdInsert , "@BSNO" , DbType . String , feedovalue . BSNO ) ;
db . AddInParameter ( cmdInsert , "@MBLNO" , DbType . String , feedovalue . MBLNO ) ;
db . AddInParameter ( cmdInsert , "@HBLNO" , DbType . String , feedovalue . HBLNO ) ;
db . AddInParameter ( cmdInsert , "@CUSTOMERNAME" , DbType . String , feedovalue . FEEOBJNAME ) ;
db . AddInParameter ( cmdInsert , "@BSTYPE" , DbType . Boolean , false ) ;
db . AddInParameter ( cmdInsert , "@FEEID" , DbType . String , feedovalue . FEEID ) ;
db . AddInParameter ( cmdInsert , "@FEENAME" , DbType . String , feedovalue . FEENAME ) ;
db . AddInParameter ( cmdInsert , "@CURRENCY" , DbType . String , feedovalue . CURRENCY ) ;
db . AddInParameter ( cmdInsert , "@AMOUNT" , DbType . Decimal , balamount ) ;
db . AddInParameter ( cmdInsert , "@DOAMOUNT" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@FEETYPE" , DbType . Int16 , feedovalue . FEETYPE ) ;
db . AddInParameter ( cmdInsert , "@CATEGORY" , DbType . Int16 , 7 ) ;
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 , feedovalue . EXCHANGERATE ) ;
db . AddInParameter ( cmdInsert , "@ORIGCURRENCY" , DbType . String , feedovalue . ORIGCURRENCY ) ;
db . AddInParameter ( cmdInsert , "@ORIGAMOUNT" , DbType . Decimal , origamount ) ;
db . AddInParameter ( cmdInsert , "@INVOICESETTLENO" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsert , "@COMPANYID" , DbType . String , companyid ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
cmdUpdateFEE . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateFEE , "@GID" , DbType . String , feedovalue . FEEID ) ;
db . AddInParameter ( cmdUpdateFEE , "@INVOICE" , DbType . Decimal , origamount ) ;
db . AddInParameter ( cmdUpdateFEE , "@INVOICE2" , DbType . Decimal , origamount ) ;
db . ExecuteNonQuery ( cmdUpdateFEE , tran ) ;
}
}
}
currency = enumValue . CURRENCY ;
rate = enumValue . RATE ;
custrateno = enumValue . CUSTRATENO ;
custaddrtel = enumValue . CUSTADDRTEL ;
custbank = enumValue . CUSTBANK ;
INVOICECATEGORY = enumValue . INVOICECATEGORY ;
ACTUALCUSTOMERNAME = enumValue . ACTUALCUSTOMERNAME ;
INVOICECUSTNAME = enumValue . INVOICECUSTNAME ;
REMARK = REMARK + ' ' + enumValue . REMARK ;
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@BILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdInsert , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
//cmdUpdate.Parameters.Clear();
//db.AddInParameter(cmdUpdate, "@AppBILLNO", DbType.String, enumValue.BILLNO);
//db.AddInParameter(cmdUpdate, "@INVOICENUM", DbType.String, invoiceno);
//db.ExecuteNonQuery(cmdUpdate, tran);
var invdetaillist = GetDetailList ( "PID='" + enumValue . GID + "'" , db , tran ) ;
var stlinvaount = enumValue . STLINVAMOUNT ;
if ( invdetaillist ! = null )
{
foreach ( var enumInvDetail in invdetaillist )
{
if ( stlinvaount ! = 0 )
{
bool ishave = false ;
if ( enumInvDetail . AMOUNT < = stlinvaount )
{
stlinvaount = stlinvaount - enumInvDetail . AMOUNT ;
if ( invdetailDataList ! = null )
{
foreach ( var invdetailData in invdetailDataList )
{
if ( invdetailData . GOODSNAME = = enumInvDetail . GOODSNAME )
{
invdetailData . TAXPRICE = invdetailData . TAXPRICE + enumInvDetail . TAXPRICE ;
invdetailData . PRICE = invdetailData . PRICE + enumInvDetail . PRICE ;
invdetailData . AMOUNT = invdetailData . AMOUNT + enumInvDetail . AMOUNT ;
invdetailData . TAX = invdetailData . TAX + enumInvDetail . TAX ;
ishave = true ;
}
}
}
if ( ! ishave )
{
var invdetailtmp = enumInvDetail ;
invdetailtmp . GID = "*" ;
invdetailtmp . PID = GID ;
invdetailDataList . Add ( invdetailtmp ) ;
}
}
else
{
if ( invdetailDataList ! = null )
{
foreach ( var invdetailData in invdetailDataList )
{
if ( invdetailData . GOODSNAME = = enumInvDetail . GOODSNAME )
{
invdetailData . TAXPRICE = invdetailData . TAXPRICE + enumInvDetail . TAXPRICE * ( stlinvaount / enumInvDetail . AMOUNT ) ;
invdetailData . PRICE = invdetailData . PRICE + enumInvDetail . PRICE * ( stlinvaount / enumInvDetail . AMOUNT ) ;
invdetailData . AMOUNT = invdetailData . AMOUNT + stlinvaount ;
invdetailData . TAX = invdetailData . TAX + enumInvDetail . TAX * ( stlinvaount / enumInvDetail . AMOUNT ) ;
ishave = true ;
}
}
}
if ( ! ishave )
{
var invdetailtmp = enumInvDetail ;
invdetailtmp . GID = "*" ;
invdetailtmp . PID = GID ;
invdetailtmp . TAXPRICE = enumInvDetail . TAXPRICE * ( stlinvaount / enumInvDetail . AMOUNT ) ;
invdetailtmp . PRICE = enumInvDetail . PRICE * ( stlinvaount / enumInvDetail . AMOUNT ) ;
invdetailtmp . AMOUNT = stlinvaount ;
invdetailtmp . TAX = enumInvDetail . TAX * ( stlinvaount / enumInvDetail . AMOUNT ) ;
invdetailDataList . Add ( invdetailtmp ) ;
}
stlinvaount = 0 ;
}
}
}
}
cmdUpdateApp . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateApp , "@INVBILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdUpdateApp , "@INVOICENO" , DbType . String , invoiceno ) ;
db . AddInParameter ( cmdUpdateApp , "@DOINVAMOUNT" , DbType . Decimal , enumValue . DOINVAMOUNT ) ;
db . AddInParameter ( cmdUpdateApp , "@BILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdUpdateApp , tran ) ;
}
if ( invdetailDataList ! = null )
{
foreach ( var invdetailData in invdetailDataList )
{
if ( invdetailData . GID = = "*" )
{
cmdInsertInvDetail . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertInvDetail , "@SerialNo" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertInvDetail , "@GOODSNAME" , DbType . String , invdetailData . GOODSNAME ) ;
db . AddInParameter ( cmdInsertInvDetail , "@SPEC" , DbType . String , invdetailData . SPEC ) ;
db . AddInParameter ( cmdInsertInvDetail , "@UNIT" , DbType . String , invdetailData . UNIT ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PKGS" , DbType . Decimal , invdetailData . PKGS ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAXPRICE" , DbType . Decimal , invdetailData . TAXPRICE ) ;
db . AddInParameter ( cmdInsertInvDetail , "@PRICE" , DbType . Decimal , invdetailData . PRICE ) ;
db . AddInParameter ( cmdInsertInvDetail , "@AMOUNT" , DbType . Decimal , invdetailData . AMOUNT ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAX" , DbType . Decimal , invdetailData . TAX ) ;
db . AddInParameter ( cmdInsertInvDetail , "@TAXRATE" , DbType . Decimal , invdetailData . TAXRATE ) ;
db . AddInParameter ( cmdInsertInvDetail , "@Remark" , DbType . String , "" ) ;
db . AddInParameter ( cmdInsertInvDetail , "@GOODCODE" , DbType . String , invdetailData . GOODCODE ) ;
db . ExecuteNonQuery ( cmdInsertInvDetail , tran ) ;
}
else
{
var cmdUpdateInvDetail =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoicedetail set TAXPRICE=@TAXPRICE,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID" ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@GID" , DbType . String , invdetailData . GID ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@TAXPRICE" , DbType . Decimal , invdetailData . TAXPRICE ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@PRICE" , DbType . Decimal , invdetailData . PRICE ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@AMOUNT" , DbType . Decimal , invdetailData . AMOUNT ) ;
db . AddInParameter ( cmdUpdateInvDetail , "@TAX" , DbType . Decimal , invdetailData . TAX ) ;
db . ExecuteNonQuery ( cmdUpdateInvDetail , tran ) ;
}
}
}
//if (invdetailid == string.Empty)
//{
// cmdInsertInvDetail.Parameters.Clear();
// db.AddInParameter(cmdInsertInvDetail, "@PID", DbType.String, GID);
// db.AddInParameter(cmdInsertInvDetail, "@SerialNo", DbType.Decimal, 1);
// db.AddInParameter(cmdInsertInvDetail, "@GOODSNAME", DbType.String, invdetailData.GOODSNAME);
// db.AddInParameter(cmdInsertInvDetail, "@SPEC", DbType.String, invdetailData.SPEC);
// db.AddInParameter(cmdInsertInvDetail, "@UNIT", DbType.String, invdetailData.UNIT);
// db.AddInParameter(cmdInsertInvDetail, "@PKGS", DbType.Decimal, invdetailData.PKGS);
// db.AddInParameter(cmdInsertInvDetail, "@TAXPRICE", DbType.Decimal, invdetailData.TAXPRICE);
// db.AddInParameter(cmdInsertInvDetail, "@PRICE", DbType.Decimal, invdetailData.PRICE);
// db.AddInParameter(cmdInsertInvDetail, "@AMOUNT", DbType.Decimal, invdetailData.AMOUNT);
// db.AddInParameter(cmdInsertInvDetail, "@TAX", DbType.Decimal, invdetailData.TAX);
// db.AddInParameter(cmdInsertInvDetail, "@TAXRATE", DbType.Decimal, invdetailData.TAXRATE);
// db.AddInParameter(cmdInsertInvDetail, "@Remark", DbType.String, "");
// db.AddInParameter(cmdInsertInvDetail, "@GOODCODE", DbType.String, invdetailData.GOODCODE);
// db.ExecuteNonQuery(cmdInsertInvDetail, tran);
//}
//else {
// var cmdUpdateInvDetail =
// db.GetSqlStringCommand(
// @"UPDATE ch_fee_invoicedetail set TAXPRICE=@TAXPRICE,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID");
// db.AddInParameter(cmdUpdateInvDetail, "@PID", DbType.String, invdetailid);
// db.AddInParameter(cmdUpdateInvDetail, "@TAXPRICE", DbType.Decimal, invdetailData.TAXPRICE);
// db.AddInParameter(cmdUpdateInvDetail, "@PRICE", DbType.Decimal, invdetailData.PRICE);
// db.AddInParameter(cmdUpdateInvDetail, "@AMOUNT", DbType.Decimal, invdetailData.AMOUNT);
// db.AddInParameter(cmdUpdateInvDetail, "@TAX", DbType.Decimal, invdetailData.TAX);
// db.ExecuteNonQuery(cmdUpdateInvDetail, tran);
//}
db . AddInParameter ( cmdUpdateInv , "@REMARK" , DbType . String , REMARK ) ;
db . ExecuteNonQuery ( cmdUpdateInv , 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 DelAppList ( List < ChInvoiceapplication > 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 cmddelete = db . GetSqlStringCommand ( "delete from ch_fee_do where BILLNO=@BILLNO AND FEEID IN (SELECT FEEID FROM CH_FEE_DO WHERE BILLNO=@AppBILLNO)" ) ;
var cmdUpdate = db . GetSqlStringCommand (
@ "declare @FEEID varchar(100)
declare @ORDERINVOICE numeric ( 19 , 4 )
declare CurBill cursor for
select FEEID , ORIGAMOUNT
from ch_fee_do where BILLNO = @AppBILLNO
open CurBill
fetch next from CurBill into @FEEID , @ORDERINVOICE
while @ @Fetch_Status = 0
begin
UPDATE CH_FEE SET INVOICE = ISNULL ( INVOICE , 0 ) - @ORDERINVOICE , ORDERINVSETTLEMENT = ISNULL ( ORDERINVSETTLEMENT , 0 ) - @ORDERINVOICE , INVOICENUM = ' ' WHERE GID = @FEEID
fetch next from CurBill into @FEEID , @ORDERINVOICE
end ;
close CurBill
dealLocate CurBill
");
var cmdUpdateApp =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoiceapplication set BILLSTATUS=0,INVBILLNO='',INVOICENO='' where BILLNO=@AppBILLNO" ) ;
foreach ( var enumValue in boday )
{
cmddelete . Parameters . Clear ( ) ;
db . AddInParameter ( cmddelete , "@BILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmddelete , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmddelete , tran ) ;
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
cmdUpdateApp . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateApp , "@AppBILLNO" , DbType . String , enumValue . BILLNO ) ;
db . ExecuteNonQuery ( cmdUpdateApp , 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 ;
}
# endregion
public static DBResult UpdateInvNoDelete ( string billno , string userid , bool isdelete = true )
{
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_invoiceitems set ISDELETE=1,DELETEUSER=@DELETEUSER,DELETETIME=@DELETETIME where INVOICENUM=@BILLNO" ) ;
var cmdUpdate2 =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoiceitems set ISDELETE=0 where INVOICENUM=@BILLNO" ) ;
if ( billno . Length > 8 ) {
cmdUpdate =
db . GetSqlStringCommand (
@ "UPDATE ch_fee_invoiceitems set ISDELETE=1,DELETEUSER=@DELETEUSER,DELETETIME=@DELETETIME where FROM ch_fee_invoiceitems I
LEFT JOIN ch_fee_invoicebooks B ON ( B . GID = I . BOOKID ) where B . INVOICECODE + I . INVOICENUM = @BILLNO ");
cmdUpdate2 =
db . GetSqlStringCommand (
@ "UPDATE ch_fee_invoiceitems set ISDELETE=0 where FROM ch_fee_invoiceitems I
LEFT JOIN ch_fee_invoicebooks B ON ( B . GID = I . BOOKID ) where B . INVOICECODE + I . INVOICENUM = @BILLNO ");
}
if ( isdelete )
{
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@BILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdUpdate , "@DELETEUSER" , DbType . String , billno ) ;
db . AddInParameter ( cmdUpdate , "@DELETETIME" , DbType . String , DateTime . Now ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
}
else {
cmdUpdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate2 , "@BILLNO" , DbType . String , billno ) ;
db . ExecuteNonQuery ( cmdUpdate2 , 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 UpdateInvNoUse ( string billno , string userid , string invbillno )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
if ( invbillno ! = "" )
{
var cmdUpdate2 =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoiceitems set ISMAKEOUT=0,MAKEOUTUSER='',MAKEOUTTIME=null,BILLNO='' where BILLNO=@BILLNO" ) ;
cmdUpdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate2 , "@BILLNO" , DbType . String , invbillno ) ;
db . ExecuteNonQuery ( cmdUpdate2 , tran ) ;
}
//var cmdUpdate =
// db.GetSqlStringCommand(
// @"UPDATE ch_fee_invoiceitems set ISMAKEOUT=1,MAKEOUTUSER=@DELETEUSER,MAKEOUTTIME=@DELETETIME,BILLNO=@INVBILLNO where INVOICENUM=@BILLNO");
//if (billno.Length > 8) {
var cmdUpdate =
db . GetSqlStringCommand (
@ "UPDATE ch_fee_invoiceitems set ISMAKEOUT=1,MAKEOUTUSER=@DELETEUSER,MAKEOUTTIME=@DELETETIME,BILLNO=@INVBILLNO FROM ch_fee_invoiceitems I
LEFT JOIN ch_fee_invoicebooks B ON ( B . GID = I . BOOKID ) where B . INVOICECODE + I . INVOICENUM = @BILLNO ");
//}
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@BILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdUpdate , "@INVBILLNO" , DbType . String , invbillno ) ;
db . AddInParameter ( cmdUpdate , "@DELETEUSER" , DbType . String , billno ) ;
db . AddInParameter ( cmdUpdate , "@DELETETIME" , DbType . String , DateTime . Now ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
var cmdUpdate3 =
db . GetSqlStringCommand (
@ "UPDATE ch_fee_invoicebooks set MODIFIEDTIME=GETDATE() FROM ch_fee_invoiceitems I
LEFT JOIN ch_fee_invoicebooks B ON ( B . GID = I . BOOKID ) where B . INVOICECODE + I . INVOICENUM = @BILLNO ");
//}
cmdUpdate3 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate3 , "@BILLNO" , DbType . String , billno ) ;
db . ExecuteNonQuery ( cmdUpdate3 , 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 UpdateInvNoCancelUse ( 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_invoiceitems set ISMAKEOUT=0,MAKEOUTUSER='',MAKEOUTTIME=null,BILLNO='' where INVOICENUM=@BILLNO");
//if (billno.Length > 8) {
var cmdUpdate =
db . GetSqlStringCommand (
@ "UPDATE ch_fee_invoiceitems set ISMAKEOUT=0,MAKEOUTUSER='',MAKEOUTTIME=null,BILLNO='' FROM ch_fee_invoiceitems I
LEFT JOIN ch_fee_invoicebooks B ON ( B . GID = I . BOOKID ) where B . INVOICECODE + I . INVOICENUM = @BILLNO ");
//}
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@BILLNO" , DbType . String , 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 UpdatePrint ( 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_invoice set ISNEEDPRINT=1 where BILLNO=@BILLNO" ) ;
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@BILLNO" , DbType . String , 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 UpdateDelete ( string billno , string userid , bool isdelete = true )
{
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_invoice set ISDELETE=1,DELETEOPERATOR=@DELETEOPERATOR,DELETETIME=@DELETETIME where BILLNO=@BILLNO" ) ;
var cmdUpdate2 =
db . GetSqlStringCommand (
@"UPDATE ch_fee_invoice set ISDELETE=0 where BILLNO=@BILLNO" ) ;
if ( isdelete )
{
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@DELETEOPERATOR" , DbType . String , userid ) ;
db . AddInParameter ( cmdUpdate , "@DELETETIME" , DbType . DateTime , DateTime . Now ) ;
db . AddInParameter ( cmdUpdate , "@BILLNO" , DbType . String , billno ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
}
else {
cmdUpdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate2 , "@BILLNO" , DbType . String , billno ) ;
db . ExecuteNonQuery ( cmdUpdate2 , 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 int GetRdCount ( string strCondition )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT Count(GID) AS CT from ch_fee_invoice (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 ;
}
static public int GetStCount ( string strCondition )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT Count(*) AS CT from v_fee_do_payapplication (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 ;
}
#region 提交审核和撤销审核
public static DBResult Lock ( String bill )
{
var result = new DBResult ( ) ;
var INVLOCKFEEAUTOAUDIT = MsSysParamSetDAL . GetData ( "PARAMNAME='INVLOCKFEEAUTOAUDIT'" ) . PARAMVALUE ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_invoice set BILLSTATUS=1 where BILLNO=@BILLNO" ) ;
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate , tran ) ;
if ( INVLOCKFEEAUTOAUDIT = = "1" ) {
var cmdupdate2 = db . GetSqlStringCommand ( "update ch_fee set FEESTATUS=0 where FEESTATUS IN (1,2) AND GID IN (SELECT FEEID FROM CH_FEE_DO WHERE BILLNO=@BILLNO) " ) ;
cmdupdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate2 , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate2 , tran ) ;
}
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "锁定成功" ;
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "锁定错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
public static DBResult LockList ( String bills )
{
var result = new DBResult ( ) ;
var billList = bills . Split ( ',' ) ;
var INVLOCKFEEAUTOAUDIT = MsSysParamSetDAL . GetData ( "PARAMNAME='INVLOCKFEEAUTOAUDIT'" ) . PARAMVALUE ;
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_invoice set BILLSTATUS=1 where BILLNO=@BILLNO" ) ;
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate , tran ) ;
if ( INVLOCKFEEAUTOAUDIT = = "1" )
{
var cmdupdate2 = db . GetSqlStringCommand ( "update ch_fee set FEESTATUS=0 where FEESTATUS IN (1,2) AND GID IN (SELECT FEEID FROM CH_FEE_DO WHERE BILLNO=@BILLNO) " ) ;
cmdupdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate2 , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate2 , tran ) ;
}
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "锁定成功" ;
}
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "锁定错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
public static DBResult UnLock ( String bill , string userid )
{
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_invoice set BILLSTATUS=0 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 = "撤销锁定成功" ;
var cmdupdate2 = db . GetSqlStringCommand ( "insert into sys_log(GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER) select NEWID(),'" + bill + "','撤销发票锁定',getdate(),INVOICENO+'('+CUSTOMERNAME+')','" + userid + "' from ch_fee_invoice where BILLNO=@BILLNO" ) ;
cmdupdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate2 , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate2 , tran ) ;
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "撤销锁定错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
public static DBResult UnLockList ( String bills , string userid )
{
var result = new DBResult ( ) ;
var billList = bills . Split ( ',' ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
try
{
foreach ( var bill in billList )
{
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_invoice set BILLSTATUS=0 where BILLNO=@BILLNO" ) ;
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate , tran ) ;
var cmdupdate2 = db . GetSqlStringCommand ( "insert into sys_log(GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER) select NEWID(),'" + bill + "','撤销发票锁定',getdate(),INVOICENO+'('+CUSTOMERNAME+')','" + userid + "' from ch_fee_invoice where BILLNO=@BILLNO" ) ;
cmdupdate2 . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate2 , "@BILLNO" , DbType . String , bill ) ;
db . ExecuteNonQuery ( cmdupdate2 , tran ) ;
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "撤销锁定成功" ;
}
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "撤销锁定错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
public static DBResult UpInvListDZStauts ( List < ChInvoice > invlist , string dzstatus )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
try
{
foreach ( var bill in invlist )
{
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_invoice set DZSTATUS='" + dzstatus + "' where BILLNO=@BILLNO" ) ;
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@BILLNO" , DbType . String , bill . BILLNO ) ;
db . ExecuteNonQuery ( cmdupdate , tran ) ;
result . Success = true ;
result . Message = "撤销锁定成功" ;
}
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "撤销锁定错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
# endregion
#region 发票模板
public static DBResult GetRemarksTemplate ( string companyid , string templatename = "" )
{
var result = new DBResult ( ) ;
if ( templatename = = "" | | templatename = = null ) { templatename = "发票备注" ; } ;
string str = "" ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( " TEMPLATE " ) ;
strSql . Append ( " from sys_template " ) ;
strSql . Append ( " where TEMPLATETYPE='" + templatename + "' and COMPANYID='" + companyid + "'" ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
result . Success = true ;
result . Data = Convert . ToString ( reader [ "TEMPLATE" ] ) ;
break ;
}
reader . Close ( ) ;
}
return result ;
}
public static DBResult SaveRemarksTemplate ( string Template , string companyid , string templatename = "" )
{
var result = new DBResult ( ) ;
if ( templatename = = "" | | templatename = = null ) { templatename = "发票备注" ; } ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdDelete =
db . GetSqlStringCommand (
@"delete from sys_template where TEMPLATETYPE='" + templatename + "' and COMPANYID='" + companyid + "'" ) ;
db . ExecuteNonQuery ( cmdDelete , tran ) ;
var cmdInsert =
db . GetSqlStringCommand (
@ "insert into sys_template (GID,TEMPLATE,TEMPLATETYPE,COMPANYID)
values ( @GID , @TEMPLATE , @TEMPLATETYPE , @COMPANYID ) ");
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@TEMPLATE" , DbType . String , Template ) ;
db . AddInParameter ( cmdInsert , "@TEMPLATETYPE" , DbType . String , templatename ) ;
db . AddInParameter ( cmdInsert , "@COMPANYID" , DbType . String , companyid ) ;
db . ExecuteNonQuery ( cmdInsert , 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 GetRemarksData ( List < Chfee_do_detail > bodyList , string companyid , string billno , string templatename = "" , string invdate = "" )
{
var result = new DBResult ( ) ;
if ( templatename = = "" | | templatename = = null ) { templatename = "发票备注" ; } ;
string templatestr = "" ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( " TEMPLATE " ) ;
strSql . Append ( " from sys_template " ) ;
strSql . Append ( " where TEMPLATETYPE='" + templatename + "' and COMPANYID='" + companyid + "'" ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
templatestr = Convert . ToString ( reader [ "TEMPLATE" ] ) ;
break ;
}
reader . Close ( ) ;
}
if ( templatestr = = "" )
{
result . Success = false ;
result . Message = "请先设置发票提取模板!" ;
return result ;
}
var exrate = "" ;
var INVGETNOWEXCHANGE = MsSysParamSetDAL . GetData ( "PARAMNAME='INVGETNOWEXCHANGE'" ) . PARAMVALUE ;
if ( INVGETNOWEXCHANGE = = "1" )
{
var invratelist = MsChFeeDAL . GetFeeNowInvCurrList ( invdate ) ;
if ( invratelist ! = null )
{
foreach ( var invrate in invratelist )
{
exrate = invrate . DEFRATE . ToString ( ) ;
}
}
}
else
{
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
DataSet dsUserOp = T_ALL_DA . GetAllSQL ( "select top 1 CONVERT(DECIMAL(18,4),EXCHANGERATE) as EXCHANGERATE from ch_fee_do where ORIGCURRENCY<>'RMB' AND BILLNO='" + billno + "'" ) ;
if ( dsUserOp ! = null )
exrate = dsUserOp . Tables [ 0 ] . Rows [ 0 ] [ "EXCHANGERATE" ] . ToString ( ) . Trim ( ) ;
}
decimal rmbttl = 0 ;
decimal usdttl = 0 ;
decimal Allrmbttl = 0 ;
decimal Allusdttl = 0 ;
var str = templatestr ;
var strl = "" ;
str = str . Replace ( "\r\n" , "\\" ) ;
str = str . Replace ( "\n" , "\\" ) ;
str = str . Replace ( "\r" , " " ) ;
string [ ] StrList = str . Split ( '\\' ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
usdttl = 0 ;
rmbttl = 0 ;
rmbttl = enumValue . AMOUNT ;
if ( enumValue . ORIGCURRENCY ! = "RMB" )
{
usdttl = enumValue . ORIGAMOUNT ;
Allusdttl = Allusdttl + usdttl ;
}
Allrmbttl = Allrmbttl + rmbttl ;
for ( var i = 0 ; i < = StrList . Length - 1 ; i + + )
{
str = StrList [ i ] ;
if ( str . IndexOf ( "[外币金额(总计)]" ) < 0 & & str . IndexOf ( "[人民币金额(总计)]" ) < 0 & & str . IndexOf ( "[折算汇率(总计)]" ) < 0 )
{
str = str . Replace ( "[委托编号]" , enumValue . CUSTNO ) ;
str = str . Replace ( "[主提单号]" , enumValue . MBLNO ) ;
str = str . Replace ( "[分提单号]" , enumValue . HBLNO ) ;
str = str . Replace ( "[委托单位]" , enumValue . CUSTOMERNAME ) ;
str = str . Replace ( "[开船日期]" , enumValue . ETD ) ;
str = str . Replace ( "[揽货人]" , enumValue . SALE ) ;
str = str . Replace ( "[船名]" , enumValue . VESSEL ) ;
str = str . Replace ( "[航次]" , enumValue . VOYNO ) ;
str = str . Replace ( "[装货港]" , enumValue . PORTLOAD ) ;
str = str . Replace ( "[卸货港]" , enumValue . PORTDISCHARGE ) ;
str = str . Replace ( "[目的港]" , enumValue . DESTINATION ) ;
str = str . Replace ( "[集装箱]" , enumValue . CNTRTOTAL ) ;
str = str . Replace ( "[订舱编号]" , enumValue . ORDERNO ) ;
str = str . Replace ( "[外币金额]" , usdttl . ToString ( "#0.00" ) ) ;
str = str . Replace ( "[人民币金额]" , rmbttl . ToString ( "#0.00" ) ) ;
//if (dsUserOp != null)
str = str . Replace ( "[折算汇率]" , exrate ) ;
//else
// str = str.Replace("[折算汇率]", "");
str = str . Replace ( "[外币金额(总计)]" , "" ) ;
str = str . Replace ( "[人民币金额(总计)]" , "" ) ;
str = str . Replace ( "[折算汇率(总计)]" , "" ) ;
//if (strl == "") strl = str + Environment.NewLine;
//else strl = strl + str + Environment.NewLine;
if ( strl = = "" ) strl = str + " " ;
else strl = strl + str + " " ;
}
}
//rmbttl = rmbttl + enumValue.AMOUNT;
//if (enumValue.ORIGCURRENCY != "RMB")
// usdttl = usdttl + enumValue.ORIGAMOUNT;
}
}
for ( var i = 0 ; i < = StrList . Length - 1 ; i + + )
{
str = StrList [ i ] ;
if ( str . IndexOf ( "[外币金额(总计)]" ) > = 0 | | str . IndexOf ( "[人民币金额(总计)]" ) > = 0 & & str . IndexOf ( "[折算汇率(总计)]" ) > = 0 )
{
str = str . Replace ( "[委托编号]" , "" ) ;
str = str . Replace ( "[主提单号]" , "" ) ;
str = str . Replace ( "[委托单位]" , "" ) ;
str = str . Replace ( "[开船日期]" , "" ) ;
str = str . Replace ( "[揽货人]" , "" ) ;
str = str . Replace ( "[船名]" , "" ) ;
str = str . Replace ( "[航次]" , "" ) ;
str = str . Replace ( "[装货港]" , "" ) ;
str = str . Replace ( "[卸货港]" , "" ) ;
str = str . Replace ( "[目的港]" , "" ) ;
str = str . Replace ( "[外币金额]" , "" ) ;
str = str . Replace ( "[人民币金额]" , "" ) ;
str = str . Replace ( "[折算汇率]" , "" ) ;
str = str . Replace ( "[外币金额(总计)]" , Allusdttl . ToString ( "#0.00" ) ) ;
str = str . Replace ( "[人民币金额(总计)]" , Allrmbttl . ToString ( "#0.00" ) ) ;
//if (dsUserOp != null)
// str = str.Replace("[折算汇率(总计)]", dsUserOp.Tables[0].Rows[0]["EXCHANGERATE"].ToString().Trim());
//else
// str = str.Replace("[折算汇率(总计)]", "");
str = str . Replace ( "[折算汇率(总计)]" , exrate ) ;
if ( str . Trim ( ) ! = "" )
strl = strl + str + " " ;
}
}
result . Data = result . Data + strl ;
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "保存出现错误,请重试或联系系统管理员" ;
return result ;
}
}
result . Success = true ;
result . Message = "保存成功" + result . Message ;
return result ;
}
# endregion
#region 导出发票
public static string CreateInvList ( List < ChInvoice > headList , string path )
{
var opBill = headList [ 0 ] ;
string filename = path + "\\" + headList [ 0 ] . INVOICENO . ToString ( ) + "-" + DateTime . Now . ToString ( "yyyyMMddHHmmssfff" ) + ".xml" ;
if ( System . IO . File . Exists ( filename ) )
{
System . IO . File . Delete ( filename ) ;
}
FileStream f = new FileStream ( filename , FileMode . Create ) ;
StreamWriter r = new StreamWriter ( f , Encoding . Default ) ;
var goodcode = "" ;
var skr = "" ;
var INVSKR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVSKR'" ) ;
if ( INVSKR . PARAMVALUE ! = "" ) skr = INVSKR . PARAMVALUE ;
var fhr = "" ;
var INVFHR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFHR'" ) ;
if ( INVFHR . PARAMVALUE ! = "" ) fhr = INVFHR . PARAMVALUE ;
var INVEXPLOCK = MsSysParamSetDAL . GetData ( "PARAMNAME='INVEXPLOCK'" ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
r . WriteLine ( "<?xml version=\"1.0\" encoding=\"GBK\" ?>" ) ;
r . WriteLine ( "<Kp>" ) ;
r . WriteLine ( "<Version>2.0</Version>" ) ;
r . WriteLine ( "<Fpxx>" ) ;
r . WriteLine ( "<Zsl>" + headList . Count + "</Zsl>" ) ;
r . WriteLine ( "<Fpsj>" ) ;
foreach ( var bill in headList )
{
r . WriteLine ( "<Fp>" ) ;
r . WriteLine ( "<Djh>" + bill . BILLNO + "</Djh>" ) ;
r . WriteLine ( "<Gfmc>" + bill . INVOICECUSTNAME + "</Gfmc>" ) ;
r . WriteLine ( "<Gfsh>" + bill . CUSTRATENO + "</Gfsh>" ) ;
r . WriteLine ( "<Gfyhzh>" + bill . CUSTBANK + "</Gfyhzh>" ) ;
r . WriteLine ( "<Gfdzdh>" + bill . CUSTADDRTEL + "</Gfdzdh>" ) ;
r . WriteLine ( "<Bz>" + bill . REMARK + "</Bz>" ) ;
r . WriteLine ( "<Kpr>" + bill . OPERATORNAME + "</Kpr>" ) ;
r . WriteLine ( "<Fhr>" + fhr + "</Fhr>" ) ;
r . WriteLine ( "<Skr>" + skr + "</Skr>" ) ;
r . WriteLine ( "<Spbmbbh>12.0</Spbmbbh>" ) ;
if ( bill . EXCHANGERATE = = 0 )
r . WriteLine ( "<Hsbz>0</Hsbz>" ) ;
else
r . WriteLine ( "<Hsbz>1</Hsbz>" ) ;
r . WriteLine ( "<Spxx>" ) ;
var invdetaillist = GetDetailList ( "PID='" + bill . GID + "'" ) ;
var invno = 1 ;
foreach ( var invdetail in invdetaillist )
{
r . WriteLine ( "<Sph>" ) ;
r . WriteLine ( "<Xh>" + invno . ToString ( ) + "</Xh>" ) ;
r . WriteLine ( "<Spmc>" + invdetail . GOODSNAMEREF + "</Spmc>" ) ;
r . WriteLine ( "<Ggxh>" + invdetail . SPEC + "</Ggxh>" ) ;
r . WriteLine ( "<Jldw>" + invdetail . UNIT + "</Jldw>" ) ;
var defGOOD = MsCodeGoodInvDAL . GetData ( " GID='" + invdetail . GOODSNAME + "' " ) ;
r . WriteLine ( "<Spbm>" + defGOOD . GOODCODE + "</Spbm>" ) ;
r . WriteLine ( "<Qyspbm>" + defGOOD . TAXCLASS + "</Qyspbm>" ) ;
r . WriteLine ( "<Syyhzcbz>" + defGOOD . ISUSEPREF + "</Syyhzcbz>" ) ;
r . WriteLine ( "<Lslbz>" + defGOOD . ZTAXTYPE + "</Lslbz>" ) ;
r . WriteLine ( "<Yhzcsm>" + defGOOD . DEFREMARK + "</Yhzcsm>" ) ;
r . WriteLine ( "<Dj>" + Math . Round ( invdetail . PRICE , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</Dj>" ) ;
r . WriteLine ( "<Sl>" + Math . Round ( invdetail . PKGS , 6 ) . ToString ( ) + "</Sl>" ) ;
r . WriteLine ( "<Je>" + Math . Round ( invdetail . AMOUNT , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</Je>" ) ;
r . WriteLine ( "<Slv>" + Math . Round ( ( invdetail . TAXRATE / 100 ) , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</Slv>" ) ;
r . WriteLine ( "<Kce>0</Kce>" ) ;
r . WriteLine ( "</Sph>" ) ;
invno + + ;
}
r . WriteLine ( "</Spxx>" ) ;
r . WriteLine ( "</Fp>" ) ;
if ( INVEXPLOCK . PARAMVALUE = = "1" ) {
var blUpSQL = "update ch_fee_invoice set BILLSTATUS=1 where BILLNO='" + bill . BILLNO + "' " ;
bool bl = T_ALL_DA . GetExecuteSqlCommand ( blUpSQL ) ;
}
}
r . WriteLine ( "</Fpsj>" ) ;
r . WriteLine ( "</Fpxx>" ) ;
r . WriteLine ( "</Kp>" ) ;
r . Close ( ) ;
f . Close ( ) ;
return filename ;
}
public static string CreateDZInvList ( List < ChInvoice > headList , string path , string companyid )
{
var opBill = headList [ 0 ] ;
string filename = path + "\\" + headList [ 0 ] . INVOICENO . ToString ( ) + "-" + DateTime . Now . ToString ( "yyyyMMddHHmmssfff" ) + ".xml" ;
if ( System . IO . File . Exists ( filename ) )
{
System . IO . File . Delete ( filename ) ;
}
FileStream f = new FileStream ( filename , FileMode . Create ) ;
StreamWriter r = new StreamWriter ( f , Encoding . Default ) ;
var goodcode = "" ;
var skr = "" ;
var INVSKR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVSKR'" ) ;
if ( INVSKR . PARAMVALUE ! = "" ) skr = INVSKR . PARAMVALUE ;
var fhr = "" ;
var INVFHR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFHR'" ) ;
if ( INVFHR . PARAMVALUE ! = "" ) fhr = INVFHR . PARAMVALUE ;
var INVEXPLOCK = MsSysParamSetDAL . GetData ( "PARAMNAME='INVEXPLOCK'" ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
decimal hjse = 0 ;
decimal hjje = 0 ;
r . WriteLine ( "<?xml version=\"1.0\" encoding=\"GBK\" ?>" ) ;
r . WriteLine ( "<business id=\"FPKJ\" comment=\"发票开具\">" ) ;
foreach ( var bill in headList )
{
r . WriteLine ( "<REQUEST_COMMON_FPKJ class=\"REQUEST_COMMON_FPKJ\">" ) ;
var invdetaillist = GetDetailList ( "PID='" + bill . GID + "'" ) ;
foreach ( var invdetail1 in invdetaillist )
{
hjse = hjse + invdetail1 . TAX ;
}
hjje = bill . INVAMOUNT - hjse ;
r . WriteLine ( "<COMMON_FPKJ_FPT class=\"COMMON_FPKJ_FPT\">" ) ;
r . WriteLine ( "<FPQQLSH>" + bill . BILLNO + "</FPQQLSH>" ) ;
r . WriteLine ( "<KPLX>0</KPLX>" ) ;
r . WriteLine ( "<BMB_BBH>33.0</BMB_BBH>" ) ;
var company = MsCompanysDAL . GetNoPicData ( "GID='" + companyid + "'" ) ;
r . WriteLine ( "<XSF_NSRSBH>" + company . TAXCODE + "</XSF_NSRSBH>" ) ;
r . WriteLine ( "<XSF_MC>" + company . BILLRISES + "</XSF_MC>" ) ;
r . WriteLine ( "<XSF_DZDH>" + company . ADDRESS + "</XSF_DZDH>" ) ;
r . WriteLine ( "<XSF_YHZH></XSF_YHZH>" ) ;
r . WriteLine ( "<GMF_NSRSBH>" + bill . CUSTRATENO + "</GMF_NSRSBH>" ) ;
r . WriteLine ( "<GMF_MC>" + bill . INVOICECUSTNAME + "</GMF_MC>" ) ;
r . WriteLine ( "<GMF_DZDH>" + bill . CUSTADDRTEL + "</GMF_DZDH>" ) ;
r . WriteLine ( "<GMF_YHZH>" + bill . CUSTBANK + "</GMF_YHZH>" ) ;
r . WriteLine ( "<KPR>" + bill . OPERATORNAME + "</KPR>" ) ;
r . WriteLine ( "<SKR>" + fhr + "</SKR>" ) ;
r . WriteLine ( "<FHR>" + skr + "</FHR>" ) ;
r . WriteLine ( "<YFP_DM></YFP_DM>" ) ;
r . WriteLine ( "<YFP_HM></YFP_HM>" ) ;
r . WriteLine ( "<JSHJ>" + bill . INVAMOUNT + "</JSHJ>" ) ;
r . WriteLine ( "<HJJE>" + hjje + "</HJJE>" ) ;
r . WriteLine ( "<HJSE>" + hjse + "</HJSE>" ) ;
if ( hjse = = 0 )
r . WriteLine ( "<HSBZ>0</HSBZ>" ) ;
else
r . WriteLine ( "<HSBZ>1</HSBZ>" ) ;
r . WriteLine ( "<BZ>" + bill . REMARK + "</BZ>" ) ;
r . WriteLine ( "</COMMON_FPKJ_FPT>" ) ;
r . WriteLine ( "<COMMON_FPKJ_XMXXS class='COMMON_FPKJ_XMXX' size='1'>" ) ;
var invno = 1 ;
foreach ( var invdetail in invdetaillist )
{
var defGOOD = MsCodeGoodInvDAL . GetData ( " GID='" + invdetail . GOODSNAME + "' " ) ;
r . WriteLine ( "<COMMON_FPKJ_XMXX>" ) ;
r . WriteLine ( "<FPHXZ>0</FPHXZ>" ) ;
r . WriteLine ( "<SPBM>" + defGOOD . GOODCODE + "</SPBM>" ) ;
r . WriteLine ( "<ZXBM>" + defGOOD . GOODCODE + "</ZXBM>" ) ;
if ( defGOOD . ISUSEPREF = = "1" )
r . WriteLine ( "<YHZCBS>1</YHZCBS>" ) ;
else r . WriteLine ( "<YHZCBS>0</YHZCBS>" ) ;
r . WriteLine ( "<LSLBS>1</LSLBS>" ) ;
r . WriteLine ( "<ZZSTSGL></ZZSTSGL>" ) ;
r . WriteLine ( "<XMMC>" + invdetail . GOODSNAMEREF + "</XMMC>" ) ;
r . WriteLine ( "<GGXH>" + invdetail . SPEC + "</GGXH>" ) ;
r . WriteLine ( "<DW>" + invdetail . UNIT + "</DW>" ) ;
r . WriteLine ( "<XMSL>" + Math . Round ( invdetail . PKGS , 6 ) . ToString ( ) + "</XMSL>" ) ;
r . WriteLine ( "<XMDJ>" + Math . Round ( invdetail . PRICE , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</XMDJ>" ) ;
r . WriteLine ( "<XMJE>" + Math . Round ( invdetail . AMOUNT , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</XMJE>" ) ;
r . WriteLine ( "<SL>" + Math . Round ( ( invdetail . TAXRATE / 100 ) , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</SL>" ) ;
r . WriteLine ( "<SE>" + Math . Round ( invdetail . TAX , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) + "</SE>" ) ;
r . WriteLine ( "<KCE>0</KCE>" ) ;
r . WriteLine ( "</COMMON_FPKJ_XMXX>" ) ;
invno + + ;
}
r . WriteLine ( "</COMMON_FPKJ_XMXXS>" ) ;
if ( INVEXPLOCK . PARAMVALUE = = "1" )
{
var blUpSQL = "update ch_fee_invoice set BILLSTATUS=1 where BILLNO='" + bill . BILLNO + "' " ;
bool bl = T_ALL_DA . GetExecuteSqlCommand ( blUpSQL ) ;
}
r . WriteLine ( "</REQUEST_COMMON_FPKJ>" ) ;
}
r . WriteLine ( "</business>" ) ;
r . Close ( ) ;
f . Close ( ) ;
return filename ;
}
public static string CreateInvRYORDERTList ( List < ChInvoice > headList , string path , string optype , string invaccount , string invpsw )
{
var opBill = headList [ 0 ] ;
string filename = path + "\\FPORDER" + headList [ 0 ] . INVOICENO . ToString ( ) + "-" + DateTime . Now . ToString ( "yyyyMMddHHmmssfff" ) + ".xml" ;
if ( System . IO . File . Exists ( filename ) )
{
System . IO . File . Delete ( filename ) ;
}
//FileStream f = new FileStream(filename, FileMode.Create);
//StreamWriter r = new StreamWriter(f, Encoding.Default);
var goodcode = "" ;
var ReCode = "OP01" ;
if ( optype = = "M" ) ReCode = "OP02" ;
if ( optype = = "D" ) ReCode = "OP03" ;
Request order = new Request ( ) ;
XmlHead Head = new XmlHead ( ) ;
Head . PbAccount = invaccount ;
Head . PbPassWord = invpsw ;
Head . ReCode = ReCode ;
Head . SerialNo = Guid . NewGuid ( ) . ToString ( ) ;
Head . PostTime = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
order . Head = Head ;
foreach ( var bill in headList )
{
var bslist = GetBsList ( "c.BILLNO='" + bill . BILLNO + "'" ) ;
var bs = new Chfee_do_detail ( ) ;
if ( bslist . Count > 0 ) bs = bslist [ 0 ] ;
else {
bs . ETD = DateTime . Now . ToString ( "yyyy-MM-dd" ) ;
bs . PORTLOAD = "QINGDAO" ;
bs . PORTDISCHARGE = "KOBE,JAPAN" ;
bs . VESSEL = "CMA CGM TUTICORIN" ;
bs . VOYNO = "0GE17W" ;
bs . MBLNO = "APLU719273300" ;
}
XmlOrderBody orderBody = new XmlOrderBody ( ) ;
XmlOrderDetail orderdetail = new XmlOrderDetail ( ) ;
orderdetail . order_type = "整箱" ;
orderdetail . order_date = bs . ETD ;
orderdetail . customer_fullname = bill . INVOICECUSTNAME ;
orderdetail . start_port = bs . PORTLOAD . Replace ( "," , " " ) ;
orderdetail . end_port = bs . PORTDISCHARGE . Replace ( "," , " " ) ;
orderdetail . sail_date = bs . ETD ;
orderdetail . shipname = bs . VESSEL ;
orderdetail . voyage_no = bs . VOYNO ;
orderdetail . bill_lading_no = bs . MBLNO ;
var ctnList = new List < XmlCtn > ( ) ;
var bsctnlist = MsOpSeaeDAL . GetBodyListSum ( "BSNO='" + bs . BSNO + "'" ) ;
foreach ( var enumCtn in bsctnlist ) {
XmlCtn ctn = new XmlCtn ( ) ;
ctn . ctn_type = enumCtn . CTNALL ;
ctn . ctn_quantity = enumCtn . CTNNUM . ToString ( ) ;
ctnList . Add ( ctn ) ;
}
//ctn.ctn_type=bs.CNTRTOTAL
orderBody . OrderDetail = orderdetail ;
XmlCtns Ctns = new XmlCtns ( ) ;
Ctns . Ctns = ctnList ;
orderBody . Ctns = Ctns ;
var feelist = new List < Xmlexpense > ( ) ;
var invdetaillist = GetDetailList ( "PID='" + bill . GID + "'" ) ;
var invno = 1 ;
foreach ( var invdetail in invdetaillist )
{
Xmlexpense fee = new Xmlexpense ( ) ;
fee . expense_id = invdetail . GID ;
fee . expense_name = invdetail . GOODSNAMEREF ;
fee . currency = bill . CURRENCY ;
fee . price = Math . Round ( invdetail . TAXPRICE , 2 , MidpointRounding . AwayFromZero ) . ToString ( ) ;
fee . unit = invdetail . UNIT ;
if ( fee . unit = = "" ) fee . unit = "票" ;
fee . quantity = Math . Round ( invdetail . PKGS , 0 ) . ToString ( ) ;
if ( fee . quantity = = "" | | fee . quantity = = "0" ) fee . quantity = "1" ;
feelist . Add ( fee ) ;
}
Xmlexpenses expenses = new Xmlexpenses ( ) ;
expenses . expenses = feelist ;
orderBody . expenses = expenses ;
order . OrderBody = orderBody ;
// order.OrderBody=ord
}
using ( StreamWriter sw = new StreamWriter ( filename ) )
{
XmlSerializer xs = new XmlSerializer ( order . GetType ( ) ) ;
xs . Serialize ( sw , order ) ;
}
XmlDocument xobj = new XmlDocument ( ) ;
xobj . Load ( filename ) ;
//if (File.Exists(filename))
//{
// File.Delete(filename);
//}
return Xml2String ( xobj ) ;
}
public static string CreateInvRYTList ( List < ChInvoice > headList , string path , string optype , List < Xmlexpense > expenses , string invaccount , string invpsw , string email )
{
var opBill = headList [ 0 ] ;
string filename = path + "\\FP" + headList [ 0 ] . INVOICENO . ToString ( ) + "-" + DateTime . Now . ToString ( "yyyyMMddHHmmssfff" ) + ".xml" ;
if ( System . IO . File . Exists ( filename ) )
{
System . IO . File . Delete ( filename ) ;
}
var goodcode = "" ;
var skr = "" ;
var INVSKR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVSKR'" ) ;
if ( INVSKR . PARAMVALUE ! = "" ) skr = INVSKR . PARAMVALUE ;
var fhr = "" ;
var INVFHR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFHR'" ) ;
if ( INVFHR . PARAMVALUE ! = "" ) fhr = INVFHR . PARAMVALUE ;
var INVEXPLOCK = MsSysParamSetDAL . GetData ( "PARAMNAME='INVEXPLOCK'" ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
var ReCode = "OP05" ;
//if (optype == "M") ReCode = "OP02";
//if (optype == "D") ReCode = "OP03";
Xmlinvoice order = new Xmlinvoice ( ) ;
XmlHead Head = new XmlHead ( ) ;
Head . PbAccount = invaccount ;
Head . PbPassWord = invpsw ;
Head . ReCode = ReCode ;
Head . SerialNo = Guid . NewGuid ( ) . ToString ( ) ;
Head . PostTime = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
order . Head = Head ;
List < XmlInvoicel > invoicelist = new List < XmlInvoicel > ( ) ;
foreach ( var bill in headList )
{
XmlInvoicel invoice = new XmlInvoicel ( ) ;
invoice . customer_name = bill . INVOICECUSTNAME ;
invoice . customer_code = bill . CUSTRATENO ;
invoice . customer_address = bill . CUSTADDRTEL ;
// invoice.customer_bank_name=bill.b
var banklist = bill . CUSTBANK . Split ( ' ' ) ;
if ( banklist . Length = = 2 )
{
invoice . customer_bank_name = banklist [ 0 ] ;
invoice . customer_bank_account = banklist [ 1 ] ;
}
else {
invoice . customer_bank_name = bill . CUSTBANK ;
invoice . customer_bank_account = bill . CUSTBANK ;
}
var banklist2 = bill . ACCOUNT . Split ( '-' ) ;
invoice . partner_bank_name = banklist2 [ 0 ] ;
invoice . partner_bank_account = banklist2 [ 1 ] ;
invoice . drawer = bill . OPERATORNAME ;
invoice . payee = skr ;
invoice . reviewer = fhr ;
invoice . total_amount = "0" ;
invoice . currency = bill . CURRENCY ;
invoice . remark_type = "1" ;
invoice . remark = bill . REMARK ;
invoice . email = email ;
// order.OrderBody.Ctns.Ctns = ctnList;
var XmlInvDetail = new List < XmlInvDetail > ( ) ;
var invno = 1 ;
foreach ( var invdetail in expenses )
{
XmlInvDetail fee = new XmlInvDetail ( ) ;
fee . expense_id = invdetail . expense_id ;
fee . expense_name = invdetail . expense_name ;
fee . expense_amount = invdetail . amount ;
XmlInvDetail . Add ( fee ) ;
}
XmlInvDetails invDetails = new XmlInvDetails ( ) ;
invDetails . InvDetail = XmlInvDetail ;
invoice . invDetails = invDetails ;
invoicelist . Add ( invoice ) ;
XmlInvoiceBodys invoiceBodys = new XmlInvoiceBodys ( ) ;
invoiceBodys . InvDetail = invoicelist ;
XmlInvoiceBody invoiceBody = new XmlInvoiceBody ( ) ;
invoiceBody . InvoiceBodys = invoiceBodys ;
order . InvoiceBody = invoiceBody ;
// order.OrderBody.expenses.expenses = feelist;
}
using ( StreamWriter sw = new StreamWriter ( filename ) )
{
XmlSerializer xs = new XmlSerializer ( order . GetType ( ) ) ;
xs . Serialize ( sw , order ) ;
}
XmlDocument xobj = new XmlDocument ( ) ;
xobj . Load ( filename ) ;
//if (File.Exists(filename))
//{
// File.Delete(filename);
//}
return Xml2String ( xobj ) ;
}
public static string Xml2String ( XmlDocument XDoc )
{
MemoryStream Stream = new MemoryStream ( ) ;
XmlTextWriter Writer = new XmlTextWriter ( Stream , null ) ;
Writer . Formatting = Formatting . Indented ;
XDoc . Save ( Writer ) ;
StreamReader sr = new StreamReader ( Stream , System . Text . Encoding . UTF8 ) ;
Stream . Position = 0 ;
string XmlString = sr . ReadToEnd ( ) ;
sr . Close ( ) ;
Stream . Close ( ) ;
return XmlString ;
}
# endregion
#region 发票列表权限范围
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,AUTHORITYID,VSSQL " ) ;
strSql . Append ( " from VW_User_Authority " ) ;
strSql . Append ( " where [NAME]='modInvoiceManagement' and USERID='" + userid + "' and ISDELETE=0" ) ;
string visiblerange = "4" ;
string operaterange = "4" ;
string AUTHORITYID = "" ;
string VSSQL = "" ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
visiblerange = Convert . ToString ( reader [ "VISIBLERANGE" ] ) ;
operaterange = Convert . ToString ( reader [ "OPERATERANGE" ] ) ;
AUTHORITYID = Convert . ToString ( reader [ "AUTHORITYID" ] ) ;
VSSQL = Convert . ToString ( reader [ "VSSQL" ] ) ;
break ;
}
reader . Close ( ) ;
}
if ( visiblerange = = "4" )
{
str = " (CREATEUSER='" + userid + "')" ;
}
else if ( visiblerange = = "3" )
{
str = " (CREATEUSER='" + userid + "')" ;
}
else if ( visiblerange = = "2" )
{
var rangeDa = new RangeDA ( ) ;
var deptid = rangeDa . GetDEPTGID ( userid ) ;
str = " CREATEUSER in (select USERID from vw_user where deptid='" + deptid + "') " ;
}
else if ( visiblerange = = "1" )
{
str = " COMPANYID='" + companyid + "' " ;
}
else if ( visiblerange = = "5" )
{
var userstr = new StringBuilder ( ) ;
userstr . Append ( " select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1" ) ;
Database userdb = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = userdb . ExecuteReader ( CommandType . Text , userstr . ToString ( ) ) )
{
str = "" ;
while ( reader . Read ( ) )
{
if ( str = = "" )
{
str = " COMPANYID='" + companyid + "' " ;
}
else
{
str = str + " or 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 = " (CREATEUSER='" + Convert . ToString ( reader [ "OPID" ] ) + "' " ;
}
else
{
str = str + " or CREATEUSER='" + Convert . ToString ( reader [ "OPID" ] ) + "'" ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else if ( visiblerange = = "0" )
{
str = " 1=1 " ;
}
VSSQL = VSSQL . Trim ( ) ;
if ( ! string . IsNullOrEmpty ( VSSQL ) )
{
if ( ! string . IsNullOrEmpty ( str ) )
{
str = str + " and (" + VSSQL + ") " ;
}
else
{
str = " (" + VSSQL + ") " ;
}
}
return str ;
}
# endregion
#region 发票费用查询范围
public static string GetRangDAStr ( string tb , string userid , string username , string companyid )
{
string str = "" ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( " VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL " ) ;
strSql . Append ( " from VW_User_Authority " ) ;
strSql . Append ( " where [NAME]='modInvoiceImport' and USERID='" + userid + "' and ISDELETE=0" ) ;
string visiblerange = "4" ;
string operaterange = "4" ;
string AUTHORITYID = "" ;
string VSSQL = "" ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
visiblerange = Convert . ToString ( reader [ "VISIBLERANGE" ] ) ;
operaterange = Convert . ToString ( reader [ "OPERATERANGE" ] ) ;
AUTHORITYID = Convert . ToString ( reader [ "AUTHORITYID" ] ) ;
VSSQL = Convert . ToString ( reader [ "VSSQL" ] ) ;
break ;
}
reader . Close ( ) ;
}
if ( visiblerange = = "4" )
{
str = " (OP='" + username + "' OR INPUTBY='" + username + "' 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 + "'))" ;
}
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 + "'))" ;
}
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 = " (b.Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "'" ;
}
else
{
str = str + " or b.Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "'" ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else if ( visiblerange = = "6" )
{
var userstr = new StringBuilder ( ) ;
userstr . Append ( " select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1" ) ;
Database userdb = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = userdb . ExecuteReader ( CommandType . Text , userstr . ToString ( ) ) )
{
str = "" ;
while ( reader . Read ( ) )
{
if ( str = = "" )
{
str = " (b.OP='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR b.SALE='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR b.CUSTSERVICE='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR b.INPUTBY='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' " ;
}
else
{
str = str + " or b.OP='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR b.SALE='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR b.CUSTSERVICE='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR b.INPUTBY='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' " ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else if ( visiblerange = = "0" )
{
str = " 1=1 " ;
}
VSSQL = VSSQL . Trim ( ) ;
if ( ! string . IsNullOrEmpty ( VSSQL ) )
{
if ( ! string . IsNullOrEmpty ( str ) )
{
str = str + " and (" + VSSQL + ") " ;
}
else
{
str = " (" + VSSQL + ") " ;
}
}
return str ;
}
public static string GetRangAddFeeDAStr ( string userid , string username , string companyid )
{
string str = "" ;
string modustr = "MODINVFEERANGE" ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( " VISIBLERANGE,OPERATERANGE,AUTHORITYID " ) ;
strSql . Append ( " from VW_User_Authority " ) ;
strSql . Append ( " where [NAME]='" + modustr + "' and USERID='" + userid + "' and ISDELETE=0" ) ;
string visiblerange = "4" ;
string operaterange = "4" ;
string AUTHORITYID = "" ;
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" ] ) ;
break ;
}
reader . Close ( ) ;
}
if ( visiblerange = = "4" )
{
str = " f.ENTEROPERATOR='" + userid + "'" ;
}
else if ( visiblerange = = "3" )
{
str = " f.ENTEROPERATOR='" + userid + "'" ;
}
else if ( visiblerange = = "2" )
{
var rangeDa = new RangeDA ( ) ;
var deptid = rangeDa . GetDEPTGID ( userid ) ;
str = " f.ENTEROPERATOR in (select USERID from vw_user where deptid='" + deptid + "') " ;
}
else if ( visiblerange = = "1" )
{
str = " f.ENTEROPERATOR in (select USERID from vw_user where COMPANYID='" + companyid + "') " ;
}
else if ( visiblerange = = "5" )
{
var userstr = new StringBuilder ( ) ;
userstr . Append ( " select USERID FROM user_company WHERE COMPANYID IN (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 = " (f.ENTEROPERATOR='" + Convert . ToString ( reader [ "USERID" ] ) + "'" ;
}
else
{
str = str + " or f.ENTEROPERATOR='" + Convert . ToString ( reader [ "USERID" ] ) + "'" ;
} ;
}
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 = " (f.ENTEROPERATOR='" + Convert . ToString ( reader [ "OPID" ] ) + "' " ;
}
else
{
str = str + " or f.ENTEROPERATOR='" + Convert . ToString ( reader [ "OPID" ] ) + "' " ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else if ( visiblerange = = "0" )
{
str = " 1=1 " ;
}
return str ;
}
# endregion
}
public static class AES
{
public static string key = ConfigurationManager . AppSettings [ "AESkey" ] ;
#region AesEncrypt aes加密
/// <summary>
/// AES 加密
/// </summary>
/// <param name="str">明文(待加密)</param>
/// <returns></returns>
public static string AesEncrypt ( string str )
{
if ( string . IsNullOrEmpty ( str ) ) return null ;
Byte [ ] toEncryptArray = Encoding . UTF8 . GetBytes ( str ) ;
if ( key = = null | | key = = "" ) key = "12345678876543211234567887654abc" ;
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding . UTF8 . GetBytes ( key ) ,
Mode = CipherMode . ECB ,
Padding = PaddingMode . PKCS7
} ;
ICryptoTransform cTransform = rm . CreateEncryptor ( ) ;
Byte [ ] resultArray = cTransform . TransformFinalBlock ( toEncryptArray , 0 , toEncryptArray . Length ) ;
return Convert . ToBase64String ( resultArray , 0 , resultArray . Length ) ;
}
# endregion
#region AesDecrypt aes解密
/// <summary>
/// AES 解密
/// </summary>
/// <param name="str">明文(待解密)</param>
/// <returns></returns>
public static string AesDecrypt ( string str )
{
if ( string . IsNullOrEmpty ( str ) ) return null ;
Byte [ ] toEncryptArray = Convert . FromBase64String ( str ) ;
if ( key = = null | | key = = "" ) key = "12345678876543211234567887654abc" ;
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding . UTF8 . GetBytes ( key ) ,
Mode = CipherMode . ECB ,
Padding = PaddingMode . PKCS7
} ;
ICryptoTransform cTransform = rm . CreateDecryptor ( ) ;
Byte [ ] resultArray = cTransform . TransformFinalBlock ( toEncryptArray , 0 , toEncryptArray . Length ) ;
return Encoding . UTF8 . GetString ( resultArray ) ;
}
# endregion
}
}