using System; using System.Data; 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.ChfeeDetail; using DSWeb.MvcShipping.DAL.MsCodeGoodInv; using DSWeb.Areas.MvcShipping.DAL; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.MvcShipping.DAL.MsBaseInfoDAL; using DSWeb.Areas.Account.Models.TruckChfee_do_detail; using System.Data.SqlClient; namespace DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication { public partial class ChinvoiceapplicationDAL { #region 发票申请列表 static public List GetDataList(int start, int limit, string strCondition, out int totel, 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 *,dbo.GetFeeNoStlByInvNo(BILLNO) as NOSTL from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("APPLICANTNAME", "(select ShowName from [user] where GID=cm.APPLICANT)"); sortstring = sortstring.Replace("INVOICECATEGORYREF", "(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY)"); sortstring = sortstring.Replace("BILLSTATUSREF", "(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS)"); sortstring = sortstring.Replace("INVOICENOREF", "(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO)"); sortstring = sortstring.Replace("INVDATE", "(select top 1 INVOICEMAKETIME from ch_fee_invoice where BILLNO=cm.INVBILLNO)"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by APPLYTIME DESC"); } strSql.Append(@") as num , "); strSql.Append(" GID,BILLNO,BILLSTATUS,CUSTOMERNAME,ACTUALCUSTOMERNAME,CURRENCY,INVOICECUSTNAME,INVOICECATEGORY "); strSql.Append(" ,BSNO,MBLNO,VESSELVOYAGE,POL,POD,ETD,APPLYAMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT"); strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,OPERATOR,OPERATETIME,INVBILLNO "); strSql.Append(" ,REMARK,SHENREMARK,COMPANYID,ISAPPLY,CUSTRATENO,CUSTADDRTEL,CUSTBANK,RATE,INVOICENO,RECVCURR,FEEAMOUNT "); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF"); strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME"); strSql.Append(",(select DEPTNAME from [VW_user] where userid=cm.APPLICANT) as APPLICANTDEPT"); strSql.Append(",(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVOICENOREF "); strSql.Append(",(select top 1 INVOICEMAKETIME from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVDATE "); strSql.Append(",PAYCOMPANYID,(select name from company where gid=cm.PAYCOMPANYID) PAYCOMPANYREF,0 IsAudit,REASON,cm.ISPRINT,cm.PRINTCOUNT "); strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,cm.PUSHMODE) as PUSHMODEREF"); strSql.Append(" FROM ch_fee_invoiceapplication 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)); // totel = getTotalCount(strCondition); return SetData(strSql); } static public List GetDataListAll(string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null) { var rangstr = ""; if (!string.IsNullOrEmpty(userid)) 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,BILLNO,BILLSTATUS,CUSTOMERNAME,ACTUALCUSTOMERNAME,CURRENCY,INVOICECUSTNAME,INVOICECATEGORY "); strSql.Append(" ,BSNO,MBLNO,VESSELVOYAGE,POL,POD,ETD,APPLYAMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT"); strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,OPERATOR,OPERATETIME,INVBILLNO "); strSql.Append(" ,REMARK,SHENREMARK,COMPANYID,ISAPPLY,CUSTRATENO,CUSTADDRTEL,CUSTBANK,RATE,INVOICENO,RECVCURR,FEEAMOUNT "); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF"); strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME"); strSql.Append(",(select DEPTNAME from [VW_user] where userid=cm.APPLICANT) as APPLICANTDEPT"); strSql.Append(",(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVOICENOREF "); strSql.Append(",(select top 1 INVOICEMAKETIME from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVDATE "); strSql.Append(",PAYCOMPANYID,(select name from company where gid=cm.PAYCOMPANYID) PAYCOMPANYREF,0 IsAudit,REASON,cm.ISPRINT,cm.PRINTCOUNT "); strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,cm.PUSHMODE) as PUSHMODEREF,'' as NOSTL"); strSql.Append(" FROM ch_fee_invoiceapplication 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 APPLYTIME DESC"); } return SetData(strSql); } public static int getTotalCount(string strCondition) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) "); strSql.Append(" FROM ch_fee_invoiceapplication 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 List GetDataInvList(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,cm.BILLNO,BILLSTATUS,CUSTOMERNAME,ACTUALCUSTOMERNAME,CURRENCY,INVOICECUSTNAME,INVOICECATEGORY "); strSql.Append(" ,BSNO,MBLNO,VESSELVOYAGE,POL,POD,ETD,APPLYAMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT"); strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,OPERATOR,OPERATETIME,INVBILLNO "); strSql.Append(" ,REMARK,SHENREMARK,COMPANYID,ISAPPLY,CUSTRATENO,CUSTADDRTEL,CUSTBANK,RATE,INVOICENO,RECVCURR,FEEAMOUNT "); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF"); strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME"); strSql.Append(",(select DEPTNAME from [VW_user] where userid=cm.APPLICANT) as APPLICANTDEPT"); strSql.Append(",(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVOICENOREF,null INVDATE "); strSql.Append(",PAYCOMPANYID,(select name from company where gid=cm.PAYCOMPANYID) PAYCOMPANYREF,0 IsAudit,REASON,cm.ISPRINT,cm.PRINTCOUNT "); strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,cm.PUSHMODE) as PUSHMODEREF,'' as NOSTL"); strSql.Append(" FROM ch_fee_invoiceapplication cm "); strSql.Append(" left join v_fee_do_payinvoiceNoInv NV ON (NV.BILLNO=cm.BILLNO) where ISNULL(NV.BILLNO,'')<>'' "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by APPLYTIME DESC"); } return SetData(strSql); } static public ChInvoiceapplication GetData(string condition, string userid = "", string usercode = "", string orgcode = "") { var list = GetDataListAll(condition,userid,usercode,orgcode); if (list.Count > 0) return list[0]; return new ChInvoiceapplication(); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ChInvoiceapplication data = new ChInvoiceapplication(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BILLNO = Convert.ToString(reader["BILLNO"]); if (reader["BILLSTATUS"] != DBNull.Value) data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]); data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.ACTUALCUSTOMERNAME = Convert.ToString(reader["ACTUALCUSTOMERNAME"]); if (reader["CURRENCY"] != DBNull.Value) data.CURRENCY = Convert.ToString(reader["CURRENCY"]); data.INVOICENO = Convert.ToString(reader["INVOICENO"]); data.INVOICENOREF = Convert.ToString(reader["INVOICENOREF"]); data.INVOICECUSTNAME = Convert.ToString(reader["INVOICECUSTNAME"]); data.INVOICECATEGORY = Convert.ToString(reader["INVOICECATEGORY"]); data.INVOICECATEGORYREF = Convert.ToString(reader["INVOICECATEGORYREF"]); 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["APPLYAMOUNT"] != DBNull.Value) data.APPLYAMOUNT = Convert.ToDecimal(reader["APPLYAMOUNT"]); 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["RATE"] != DBNull.Value) data.RATE = Convert.ToDecimal(reader["RATE"]); else data.RATE =0; data.APPLICANT = Convert.ToString(reader["APPLICANT"]); data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]); data.APPLICANTDEPT = Convert.ToString(reader["APPLICANTDEPT"]); if (reader["APPLYTIME"] != DBNull.Value) data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]).ToString("yyyy-MM-dd"); if (reader["ENTERTIME"] != DBNull.Value) data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]); data.OPERATOR = Convert.ToString(reader["OPERATOR"]); if (reader["OPERATETIME"] != DBNull.Value) data.OPERATETIME = Convert.ToDateTime(reader["OPERATETIME"]); data.SHENREMARK = Convert.ToString(reader["SHENREMARK"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); if (reader["ISAPPLY"] != DBNull.Value) data.ISAPPLY = Convert.ToBoolean(reader["ISAPPLY"]); data.CUSTRATENO = Convert.ToString(reader["CUSTRATENO"]); data.CUSTADDRTEL = Convert.ToString(reader["CUSTADDRTEL"]); data.CUSTBANK = Convert.ToString(reader["CUSTBANK"]); data.PAYCOMPANYID = Convert.ToString(reader["PAYCOMPANYID"]); data.PAYCOMPANYREF = Convert.ToString(reader["PAYCOMPANYREF"]); data.RECVCURR = Convert.ToString(reader["RECVCURR"]); data.FEEAMOUNT = Convert.ToString(reader["FEEAMOUNT"]); data.IsAudit = Convert.ToString(reader["IsAudit"]); data.REASON = Convert.ToString(reader["REASON"]); data.PUSHMODE = Convert.ToString(reader["PUSHMODE"]); data.PUSHMOBILE = Convert.ToString(reader["PUSHMOBILE"]); data.PUSHEMAIL = Convert.ToString(reader["PUSHEMAIL"]); data.PUSHMODEREF = Convert.ToString(reader["PUSHMODEREF"]); data.NOSTL = Convert.ToString(reader["NOSTL"]); if (reader["INVDATE"] != DBNull.Value) data.INVDATE = Convert.ToDateTime(reader["INVDATE"]).ToString("yyyy-MM-dd"); data.ISPRINT = Convert.ToString(reader["ISPRINT"]); if (reader["PRINTCOUNT"] != DBNull.Value) data.PRINTCOUNT = Convert.ToInt32(reader["PRINTCOUNT"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 发票申请明细 static public List GetDetailList(string strCondition,string sort=null) { 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); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by SerialNo"); } return DetailSetData(strSql); } private static List DetailSetData(StringBuilder strSql) { var headList = new List(); 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; } #endregion #region 发票申请费用明细 static public List GetBodyList(string strCondition,string sort=null) { 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,f.ACCTAXRATE "); 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.INPUTBY,b.OP,b.CUSTSERVICE"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP"); strSql.Append(",f.Remark Remark,f.INPUTMODE,f.AUDITDATE,f.SALECORP "); 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 b.MBLNO"); } return BodySetData(strSql); } private static List BodySetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSql.ToString(); cmd.CommandTimeout = 1200000; //要加这一句 using (IDataReader reader = db.ExecuteReader(cmd)) { 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.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["ORIGEXCHANGERATE"] != DBNull.Value) data.ORIGEXCHANGERATE = Convert.ToDecimal(reader["ORIGEXCHANGERATE"]); if (reader["BSSTATUS"] != DBNull.Value) data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); data.Remark = Convert.ToString(reader["Remark"]); data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]); if (reader["AUDITDATE"] != DBNull.Value) data.AUDITDATE = Convert.ToString(reader["AUDITDATE"]); data.SALECORP = Convert.ToString(reader["SALECORP"]); data.COMPANYNAME = Convert.ToString(reader["BSSALECORP"]); data.ENTERP = Convert.ToString(reader["ENTERP"]); if (reader["ACCTAXRATE"] != DBNull.Value) data.ACCTAXRATE = Convert.ToDecimal(reader["ACCTAXRATE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetTruckBodyList(string strCondition, string sort = null) { 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,B.MBLNO,B.CNTRTOTAL,"); strSql.Append("B.ETD,B.ETA,B.OP,B.SALE,B.CUSTSERVICE,B.CUSTATTN,B.CUSTTEL,B.CONSIGNEENAME,B.CONSIGNEEATTN,B.CONSIGNEETEL,B.CONSIGNEEADDR,"); strSql.Append("B.PORTLOAD,B.PORTDISCHARGE,B.GOODSNAME,B.KGS,B.NETWEIGHT,B.CBM,B.PKGS,B.KINDPKGS,B.TRUCKER,B.TRUCKNO"); strSql.Append(",f.Remark Remark,f.INPUTMODE "); 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 b.MBLNO"); } return TruckBodySetData(strSql); } private static List TruckBodySetData(StringBuilder strSql) { var headList = new List(); 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"]); if (reader["NETWEIGHT"] != DBNull.Value) data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 明细金额币别合计 static public List 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 BodySumSetData(StringBuilder strSql) { var headList = new List(); 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 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,b.CUSTOMNO"); 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 SetFeeData(StringBuilder strSql) { var headList = new List(); 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.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.DOC = Convert.ToString(reader["DOC"]); data.SALE = Convert.ToString(reader["SALE"]); data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); 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"]); 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 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='INVAPPFEERANGE'"); 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").Replace("COMPANYID", "b.SALECORPID").Replace("COMPANYNAME", "b.SALECORPID"); // strSql.Append(" order by " + sortstring); //} //else //{ // strSql.Append(" order by f.BsNo"); //} //strSql.Append(@") as num , "); strSql.Append("SELECT f.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,b.INVNO"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,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 (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) 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) "); } var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); if (isopen == false) { strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) "); } strSql.Append("GROUP BY f.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,b.INVNO"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.SALECORPID,f.CUSTOMERNAME"); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME").Replace("COMPANYID", "b.SALECORPID").Replace("COMPANYNAME", "b.SALECORPID"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by f.BsNo"); } //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='INVAPPFEERANGE'"); 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 f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) 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 SetAddBillData(StringBuilder strSql) { var headList = new List(); 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"]); if (reader["BSSTATUS"] != DBNull.Value) data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]); data.COMPANYID = Convert.ToString(reader["SALECORPID"]); data.COMPANYNAME = Convert.ToString(reader["SALECORP"]); data.INVNO = Convert.ToString(reader["INVNO"]); 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 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").Replace("COMPANYID", "b.SALECORPID").Replace("COMPANYNAME", "b.SALECORPID"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by f.BsNo"); } strSql.Append(@") as num , "); strSql.Append("f.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 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var INVISNOTSTL = MsSysParamSetDAL.GetData("PARAMNAME='INVISNOTSTL'"); if (INVISNOTSTL.PARAMVALUE == "1") { strSql.Append(" and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) "); } var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); if (isopen == false) { strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) "); } strSql.Append("GROUP BY f.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 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append("GROUP BY b.BSNO,f.CUSTOMERNAME) AS T "); int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } private static List SetAddTruckBillData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { BillTruckCustDetail data = new BillTruckCustDetail(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd"); if (reader["ETA"] != DBNull.Value) data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd"); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]); data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.SALE = Convert.ToString(reader["SALE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.TRUCKER = Convert.ToString(reader["TRUCKER"]); data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.SALE = Convert.ToString(reader["SALE"]); data.FEEOBJNAME= Convert.ToString(reader["CUSTNAME"]); 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"]); if (reader["NETWEIGHT"] != DBNull.Value) data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); 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 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 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 SetCurrExrateData(StringBuilder strSql) { var headList = new List(); 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 GetFeeDetailList(string strCondition,string userid, string usercode, string orgcode,string sort=null) { var strSql = new StringBuilder(); var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPFEERANGE'"); 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(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName"); strSql.Append(",f.INPUTMODE,f.UNIT,f.UNITPRICE,f.QUANTITY from ch_fee f "); strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) 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) "); } var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); if (isopen == false) { strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) "); } strSql.Append(" ) AS VF "); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by feeName"); } return SetFeeDetailData(strSql); } private static List SetFeeDetailData(StringBuilder strSql) { var headList = new List(); 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"]); if (reader["exChangerate"] != DBNull.Value) data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]); if (reader["AccTaxRate"] != DBNull.Value) data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]); data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]); data.UNIT = Convert.ToString(reader["UNIT"]); if (reader["UNITPRICE"] != DBNull.Value) data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]); if (reader["QUANTITY"] != DBNull.Value) data.QUANTITY = Convert.ToDecimal(reader["QUANTITY"]); data.Remark= Convert.ToString(reader["remark"]); data.INPUTBY = Convert.ToString(reader["OpName"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 发票明细保存,删除 public static DBResult SaveInvDetail(string BsNo, List 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 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 bodyList, string curr, string companyid,bool isList,string GID,ChInvoiceapplication headdata) { var result = new DBResult(); decimal ttlamount = headdata.APPLYAMOUNT; bool INVAPPMAX = false; var INVAPPMAXPARAM = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPMAX'"); if (INVAPPMAXPARAM.PARAMVALUE == "1") { INVAPPMAX = true; } if (ttlamount >= 99999 && INVAPPMAX) { result.Success = false; result.Message = "单张发票申请不能超过100000"; 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 ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORDERINVOICE 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; decimal doamount = 0; decimal StlAmount = 0; if (bodyList != null) { foreach (var enumValue in bodyList) { if (ttlamount >= 99999 && INVAPPMAX) break; if ((ttlamount + Math.Round(enumValue.DoAmount, 2, MidpointRounding.AwayFromZero)) >= 99999 && INVAPPMAX) { StlAmount = 0; doamount = 0; ischaoe = true; //doamount = 99999-ttlamount; //StlAmount = Math.Round(enumValue.StlAmount*((99999 - ttlamount)/doamount),2, MidpointRounding.AwayFromZero); } else { doamount = Math.Round(enumValue.DoAmount, 2, MidpointRounding.AwayFromZero); StlAmount = enumValue.StlAmount; } ttlamount = ttlamount + doamount; 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, doamount); db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType); db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 6); 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, StlAmount); db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, ""); db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid); db.ExecuteNonQuery(cmdInsert, tran); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, StlAmount); db.ExecuteNonQuery(cmdUpdate, tran); if (isList&& doamount!=0) { 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, doamount); db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, headdata.RATE); if (headdata.RATE == 0) { db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, doamount); db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, doamount); db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0); } else { var tax = Math.Round(doamount / (1 + headdata.RATE / 100) * (headdata.RATE / 100), 2, MidpointRounding.AwayFromZero); var amount = doamount - tax; // var amount = Math.Round(enumValue.DoAmount / (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); } if (enumValue.FeeType == 2) amtttl = amtttl - doamount; else amtttl = amtttl + doamount; } } acctaxrate = headdata.RATE; if (!isList&& ttlamount!=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, 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, Math.Round(amount, 2, MidpointRounding.AwayFromZero)); db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amount, 2, MidpointRounding.AwayFromZero)); 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(string billno, string billcust, string billcurr, string feesql, List exratelist, string companyid, bool isList, string GID,ChInvoiceapplication headdata,bool custgroup = false,string userid="") { var result = new DBResult(); bool INVAPPMAX = false; decimal ttlamount = headdata.APPLYAMOUNT; var INVAPPMAXPARAM = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPMAX'"); if (INVAPPMAXPARAM.PARAMVALUE == "1") { INVAPPMAX = true; } if (ttlamount >= 99999 && INVAPPMAX) { result.Success = false; result.Message = "单张发票申请不能超过100000"; return result; } Database db = DatabaseFactory.CreateDatabase(); decimal amtttl = 0; decimal acctaxrate = 0; bool adddo = true; bool ischaoe = false; var FEENOAUDITCANTSHENINV = MsSysParamSetDAL.GetData("PARAMNAME='FEENOAUDITCANTSHENINV'"); List billnoinvlist = null; var defGOOD = MsCodeGoodInvDAL.GetData(" ISDEF='1' and (DEFCURR='' or DEFCURR='" + headdata.RECVCURR + "')"); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (!custgroup) feesql = feesql + " AND CUSTOMERNAME='" + billcust + "'"; var feelist = GetFeeDetailList(feesql,userid,"", companyid); if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1") { billnoinvlist = MsOpBillDAL.GetDataList(" BSNO IN (select DISTINCT BSNO from ch_fee (NOLOCK) where FEETYPE=1 and (FEESTATUS=1 OR FEESTATUS=2 ) AND BSNO IN (SELECT DISTINCT BSNO FROM CH_FEE f WHERE f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) AND " + feesql + " ))", "", "", ""); } 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 ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORDERINVOICE WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-ISNULL(ORDERINVOICE,0))-@ORDERINVOICE)>=0) OR (AMOUNT<0 AND ((AMOUNT-ISNULL(ORDERINVOICE,0))-@ORDERINVOICE)<=0))"); 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 doamount = 0; decimal StlAmount = 0; decimal ORIGAMOUNT = 0; decimal UExrate = 0; if (feelist != null) { foreach (var enumValue in feelist) { //if (ttlamount >= 99999&& INVAPPMAX) break; if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1") { if (billnoinvlist != null) { foreach (var billnoinv in billnoinvlist) { if (enumValue.BSNO == billnoinv.BSNO) adddo = false; } } } if (adddo) { decimal feettl = 0; decimal otamount = 0; if (billcurr == 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; doamount = 0; ischaoe = true; } else { doamount = feettl; if (enumValue.FeeType == 2) amtttl = amtttl - enumValue.StlAmount; else amtttl = amtttl + enumValue.StlAmount; ttlamount = ttlamount + otamount; } } else { UExrate = GetExrate(enumValue.Currency, exratelist); if (enumValue.FeeType == 2) otamount = - enumValue.StlAmount * UExrate; else otamount = enumValue.StlAmount * UExrate; feettl = enumValue.StlAmount * UExrate; feettl = Math.Round(feettl, 2, MidpointRounding.AwayFromZero); if ((ttlamount + Math.Round(otamount, 2, MidpointRounding.AwayFromZero)) >= 100000 && INVAPPMAX) { feettl = 0; doamount = 0; ischaoe = true; //feettl = 99999 - ttlamount; //doamount = enumValue.StlAmount * (feettl /(enumValue.StlAmount * UExrate)); //amtttl = amtttl + feettl; //ttlamount = ttlamount + feettl; } else { doamount = enumValue.StlAmount; if (enumValue.FeeType == 2) amtttl = amtttl - feettl; else amtttl = amtttl + feettl; ttlamount = ttlamount + otamount; } } if (feettl != 0) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CustomerName); //var tops = enumValue.BSNO.Substring(0, 7); //if (tops == "topseae") // db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true); //else db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false); db.AddInParameter(cmdInsert, "@FEEID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName); db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, billcurr); if (billcurr == enumValue.Currency) { db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero)); db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1); } else { db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero)); db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate); } db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType); db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, doamount); db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 6); 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, "@ORDERINVOICE", DbType.Decimal, doamount); db.ExecuteNonQuery(cmdUpdate, tran); if (isList) { var defGOODFEELIST = MsCodeGoodInvDAL.GetData(" GOODNAME='代理" + enumValue.FeeName + "'"); var quantity = enumValue.QUANTITY; if (quantity == 0) quantity = 1; 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 (defGOODFEELIST.GOODNAME == "") { db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费"); db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票"); } else { db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOODFEELIST.GID); db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOODFEELIST.UNIT); } db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOODFEELIST.SPEC); db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, quantity); db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(feettl / quantity, 3, MidpointRounding.AwayFromZero)); // db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal,defGOODFEELIST.TAXRATE); db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, headdata.RATE); if (headdata.RATE == 0) { db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(feettl / quantity, 3, MidpointRounding.AwayFromZero)); db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero)); db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0); } else { // var tax = Math.Round(feettl / (1 + defGOODFEELIST.TAXRATE / 100) * (defGOODFEELIST.TAXRATE / 100), 2); var tax = Math.Round(feettl / (1 + headdata.RATE / 100) * (headdata.RATE / 100), 2, MidpointRounding.AwayFromZero); var amount = feettl - tax; db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amount / quantity, 3, MidpointRounding.AwayFromZero)); 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, defGOODFEELIST.GOODCODE); db.ExecuteNonQuery(cmdInsertInv, tran); } } } } } acctaxrate = headdata.RATE; if (!isList&& amtttl!=0) { // acctaxrate = defGOOD.TAXRATE; 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)); db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS,2)); db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS,2)); 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); //db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, invlist.AMOUNT + amount); //db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, ((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 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); } 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); } } var MBLNOSTR = ""; if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1") { if (billnoinvlist != null) { foreach (var billnoinv in billnoinvlist) { MBLNOSTR = MBLNOSTR + billnoinv.MBLNO + ","; } } } if (MBLNOSTR != "") MBLNOSTR = "主提单号:" + MBLNOSTR + " 业务应收费用中存在未审核的费用,不能添加发票申请!"; else MBLNOSTR = "添加成功"; if (ischaoe) { result.Success = false; result.Message ="单张发票不能超过十万元"; } else { result = new DBResult(); result.Success = true; result.Message = MBLNOSTR; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } //result.Success = true; //result.Message = "保存成功"; return result; } public static Decimal GetExrate(string curr, List 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 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 ORDERINVOICE=ORDERINVOICE-@ORIGAMOUNT where GID=@GID"); foreach (var enumValue in boday) { cmddelete.Parameters.Clear(); db.AddInParameter(cmddelete, "@FEEDOID", DbType.String, enumValue.FEEDOID); db.ExecuteNonQuery(cmddelete, tran); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@ORIGAMOUNT", DbType.Decimal, enumValue.ORIGAMOUNT); db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID); db.ExecuteNonQuery(cmdupdate, tran); 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_invapplycation"); 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 SubmitAudit(String WorkFlowName, String USERID, String bill,string companyid) { var result = new DBResult(); T_ALL_DA T_ALL_DA = new T_ALL_DA(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var WorkFlowid = ""; if (WorkFlowid == "") { string lsSQL = "select * FROM workflow WHERE COMPANYID='" + companyid + "' AND ISCONDITION=1 and [TYPE]=(SELECT TYPENO FROM workflow_type WHERE [NAME]='" + WorkFlowName + "') " + " and GID in (select workflowID from workflow_Userpath where userid ='" + USERID + "') order by SORTNO "; DataSet dsworkflow = T_ALL_DA.GetAllSQL(lsSQL); if (dsworkflow != null) { if (dsworkflow.Tables[0].Rows.Count > 0) { foreach (DataRow row in dsworkflow.Tables[0].Rows) { var CONDITIONSQL = Convert.ToString(row["CONDITIONSQL"]); CONDITIONSQL = CONDITIONSQL.Replace("[业务编号]", "'" + bill + "'"); var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL); if (strCOUNT != "0") { WorkFlowid = Convert.ToString(row["GID"]); break; } } } } if (WorkFlowid == "") WorkFlowid = "no"; } Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName,bill, USERID,bill,bill,"", WorkFlowid); if (WorkResult.Success == true) { var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO"); if (WorkResult.islast == true) { cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0,OPERATETIME=GETDATE() where BILLNO=@BILLNO"); } else { cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=2 where BILLNO=@BILLNO"); } cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "提交审核成功"; } else { result.Success = false; result.Message = "提交审核错误!"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交审核错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitAuditList(String WorkFlowName, String USERID, String bills) { var result = new DBResult(); var billList = bills.Split(','); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var bill in billList) { Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID,bill,bill,""); if (WorkResult.Success == true) { var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO"); if (WorkResult.islast == true) { cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0 where BILLNO=@BILLNO"); } else { cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=2 where BILLNO=@BILLNO"); } cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "提交审核成功"; } else { result.Success = false; result.Message = "提交审核错误!"; } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交审核错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitAuditBack(String WorkFlowName, String USERID, String bill) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, bill, USERID); if (WorkResult.Success == true) { var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=1 where BILLNO=@BILLNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销提交成功"; } else { result = new DBResult(); result.Success = false; result.Message = "已部分审核此业务,不允许撤回提交!"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销提交错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitAuditBackList(String WorkFlowName, String USERID, String bills) { var result = new DBResult(); var billList = bills.Split(','); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var bill in billList) { Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, bill, USERID); if (WorkResult.Success == true) { var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=1 where BILLNO=@BILLNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销提交成功"; } else { result = new DBResult(); result.Success = false; result.Message = "已部分审核此业务,不允许撤回提交!"; } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销提交错误,请重试或联系系统管理员"; return result; } } return result; } #endregion #region 审核或驳回 public static DBResult AuditList(List boday,string PAYCOMPANYID, String USERID) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (boday != null) { var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0 where BILLNO=@BILLNO"); var cmdupdate2 = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0,PAYCOMPANYID=@PAYCOMPANYID where BILLNO=@BILLNO"); foreach (var enumValue in boday) { if (enumValue.BILLSTATUS == 2 || enumValue.BILLSTATUS ==4) { Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("InvAudit", enumValue.BILLNO, USERID, tran, enumValue.BILLNO); if (WorkResult.Success == true&&WorkResult.islast==true) { if (boday.Count == 1) { cmdupdate2.Parameters.Clear(); db.AddInParameter(cmdupdate2, "@PAYCOMPANYID", DbType.String, PAYCOMPANYID); db.AddInParameter(cmdupdate2, "@BILLNO", DbType.String, enumValue.BILLNO); db.ExecuteNonQuery(cmdupdate2, tran); } else { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO); db.ExecuteNonQuery(cmdupdate, tran); } } } } } result = new DBResult(); result.Success = true; result.Message = "审核通过"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "审核出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "审核通过"; return result; } public static DBResult AuditBackList(List boday, String USERID, string reason) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (boday != null) { var cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=4,REASON='" + reason + "' where BILLNO=@BILLNO"); foreach (var enumValue in boday) { if (enumValue.BILLSTATUS == 2 || enumValue.BILLSTATUS == 0) { Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo("InvAudit", enumValue.BILLNO, USERID, ""); if (WorkResult.Success == true) { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO); db.ExecuteNonQuery(cmdupdate, tran); } } } } result = new DBResult(); result.Success = true; result.Message = "完成驳回"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "驳回出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "完成驳回"; return result; } #endregion static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT Count(GID) AS CT from ch_fee_invoiceapplication (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 发票审核列表 static public List GetAuditDataList(string strCondition, string userid, string isaudit,string companyid,string sort = null) { var strSql = new StringBuilder(); strSql.Append(" SELECT i.GID,i.BILLNO,i.BILLSTATUS,i.CUSTOMERNAME,i.ACTUALCUSTOMERNAME,i.CURRENCY,i.INVOICENO,i.INVOICECUSTNAME,i.INVOICECATEGORY "); strSql.Append(" ,i.BSNO,i.MBLNO,i.VESSELVOYAGE,i.POL,i.POD,i.ETD,i.APPLYAMOUNT,i.INVAMOUNT,i.AMOUNTCAPITAL,i.OTCURRAMOUNT"); strSql.Append(" ,i.APPLICANT,i.APPLYTIME,i.ENTERTIME,i.OPERATOR,i.OPERATETIME,i.RECVCURR,i.FEEAMOUNT "); strSql.Append(" ,i.REMARK,i.SHENREMARK,i.COMPANYID,i.ISAPPLY,i.CUSTRATENO,i.CUSTADDRTEL,i.CUSTBANK,i.RATE,'' INVOICENOREF,null INVDATE "); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=i.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=i.INVOICECATEGORY) as INVOICECATEGORYREF"); strSql.Append(",(select ShowName from [user] where GID=i.APPLICANT) as APPLICANTNAME"); strSql.Append(",(select DEPTNAME from [VW_user] where userid=i.APPLICANT) as APPLICANTDEPT"); strSql.Append(",i.PAYCOMPANYID,(select name from company where gid=i.PAYCOMPANYID) PAYCOMPANYREF,dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno) as IsAudit,i.REASON,i.ISPRINT,i.PRINTCOUNT "); strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,i.PUSHMODE) as PUSHMODEREF,'' as NOSTL"); strSql.Append(" FROM ch_fee_invoiceapplication i left join workflow_using wu on wu.bsno=i.billno where 1=1 "); if (isaudit=="1") strSql.Append(" and i.BILLSTATUS=2 and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 "); else if (isaudit == "2") // strSql.Append(" and i.BILLSTATUS=0 AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) "); strSql.Append(" and i.BILLSTATUS=0 "); else if (isaudit == "") { var rangstr = GetRangDAListStr("", userid,"", companyid); if (!string.IsNullOrEmpty(rangstr)) { strSql.Append(" and " + rangstr); } //strSql.Append(" and (dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 "); //strSql.Append(" or (I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ))) "); } if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by APPLYTIME desc "); } return SetData(strSql); } #endregion public static DBResult GetPrint(string bsno, string userid = "", string usercode = "", string orgcode = "") { var AuditPrint = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPPRINTAFTERAUDIT'"); var PrintOne = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPONLYPRINTONE'"); var result = new DBResult(); if (AuditPrint.PARAMVALUE != "1" && PrintOne.PARAMVALUE != "1") { result = new DBResult(); result.Success = true; result.Message = "成功"; } var PAYBILL = GetData(" cm.BILLNO='" + bsno + "'", userid, usercode, orgcode); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { //var cmdupdatePrt = db.GetSqlStringCommand("update ch_fee_payapplication set ISPRINT='1' where BILLNO=@BILLNO"); //cmdupdatePrt.Parameters.Clear(); //db.AddInParameter(cmdupdatePrt, "@BILLNO", DbType.String, bsno); //db.ExecuteNonQuery(cmdupdatePrt, tran); if (AuditPrint.PARAMVALUE == "1") { if (PAYBILL.BILLSTATUS != 0 && PAYBILL.BILLSTATUS != 4 && PAYBILL.BILLSTATUS != 5) { result.Success = false; result.Message = "此票发票申请未审核,请审核通过后再打印"; } else { if (PrintOne.PARAMVALUE == "1") { if (PAYBILL.ISPRINT == "1") { result.Success = false; result.Message = "此票发票申请已打印过,不允许重复打印"; } else { result = new DBResult(); result.Success = true; result.Message = "成功"; } } else { result = new DBResult(); result.Success = true; result.Message = "成功"; } } } else { if (PrintOne.PARAMVALUE == "1") { if (PAYBILL.ISPRINT == "1") { result.Success = false; result.Message = "此票发票申请已打印过,不允许重复打印"; } else { result = new DBResult(); result.Success = true; result.Message = "成功"; } } else { result = new DBResult(); result.Success = true; result.Message = "成功"; } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "发生错误"; } } return result; } #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]='modInvoiceAppList' 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 = " (APPLICANT='" + userid + "')"; } else if (visiblerange == "3") { str = " (APPLICANT='" + userid + "')"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "') and APPLICANT in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')"; } else if (visiblerange == "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 = " (APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "') "; } else { str = str + " or APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "')"; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "6") { var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (APPLICANT='" + Convert.ToString(reader["OPID"]) + "' "; } else { str = str + " or APPLICANT='" + Convert.ToString(reader["OPID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "1") { str = " COMPANYID='" + companyid + "' "; } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } #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]='modInvoiceAppSearch' 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 + "' OR DOC='" + username + "')"; } else if (visiblerange == "3") { str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "' OR DOC='" + username + "')"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))"; } else if (visiblerange == "1") { str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')))"; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (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 = "MODINVAPPFEERANGE"; 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 deptname = rangeDa.GetDEPTNAME(userid); str = " f.ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') and f.ENTEROPERATOR in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')"; } else if (visiblerange == "1") { str = " f.ENTEROPERATOR in (select USERID from user_company 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; } public static DBResult PASSAUDITWithGID(string ch_fee_invoiceapplicationGID) { var result = new DBResult(); string sql = "update ch_fee_invoiceapplication set BILLSTATUS = 0 where GID = '" + ch_fee_invoiceapplicationGID + "'"; Database db = DatabaseFactory.CreateDatabase(); try { int rst = db.ExecuteNonQuery(CommandType.Text, sql); result.Success = rst > 0; result.Message = "操作成功!"; return result; } catch (Exception e) { result.Success = false; result.Message = e.Message; return result; throw; } } #endregion } }