using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.Areas.Account.Models.Chfee_Recvapplication; 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.MsSysParamSet; using DSWeb.MvcShipping.DAL.MsBaseInfoDAL; using DSWeb.Common.DB; using System.Linq; using DSWeb.SysMng.DAL.SysRoleTaskQuery; using System.Data.Entity.Migrations; namespace DSWeb.Areas.Account.DAL.Chfee_Recvapplication { public partial class ChrecvapplicationDAL:IGetTotalCount { #region 收费申请列表 static public List GetDataList(string strCondition, string userid="", string usercode="", string orgcode="", string sort = null) { SysRoleTaskQueryDAL.SaveQuery(userid, "modChfee_recvapplicationOP", "formChRecvapplicationIndex", strCondition); 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,BILLNO,BILLSTATUS,CUSTOMERNAME,CURR,INVOICETITLE,SETTLETYPE,PRINTCOUNT "); strSql.Append(" ,RECVTIME,AMOUNTRMB,RATE,AMOUNTUSD,SETTLERMB,SETTLEUSD,SETTLERATE"); strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,SETTLEUSER,SETTLETIME,AUDITUSER,AUDITTIME "); strSql.Append(" ,REMARK,COMPANYID,INVOICENUMREMARK,PREAMOUNTRMB,PREAMOUNTUSD,ACCOUNT "); strSql.Append(",(select BANKNAME from [sys_bank] where GID=cm.ACCOUNT) as ACCOUNTREF"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME"); strSql.Append(",cm.SALECORPID,(select [NAME] from [company] where GID=cm.SALECORPID) as SALECORP"); strSql.Append(",(select top 1 description from info_client where SHORTNAME=cm.CUSTOMERNAME) as CUSTOMERFULLNAME"); strSql.Append(",ORREASON"); strSql.Append(" FROM ch_fee_recvapplication 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); } static public ChRecvapplication GetData(string condition, string userid = "", string usercode = "", string orgcode = "") { var list = GetDataList(condition,userid,usercode,orgcode); if (list.Count > 0) return list[0]; return new ChRecvapplication(); } 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()) { ChRecvapplication data = new ChRecvapplication(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BILLNO = Convert.ToString(reader["BILLNO"]); data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]); data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CUSTOMERFULLNAME = Convert.ToString(reader["CUSTOMERFULLNAME"]); if (reader["CURR"] != DBNull.Value) data.CURR = Convert.ToString(reader["CURR"]); data.INVOICETITLE = Convert.ToString(reader["INVOICETITLE"]); data.SETTLETYPE = Convert.ToInt32(reader["SETTLETYPE"]); if (reader["RECVTIME"] != DBNull.Value) data.RECVTIME = Convert.ToDateTime(reader["RECVTIME"]).ToString("yyyy-MM-dd"); if (reader["AMOUNTRMB"] != DBNull.Value) data.AMOUNTRMB = Convert.ToDecimal(reader["AMOUNTRMB"]); if (reader["AMOUNTUSD"] != DBNull.Value) data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]); if (reader["RATE"] != DBNull.Value) data.RATE = Convert.ToDecimal(reader["RATE"]); if (reader["SETTLERMB"] != DBNull.Value) data.SETTLERMB = Convert.ToDecimal(reader["SETTLERMB"]); if (reader["SETTLEUSD"] != DBNull.Value) data.SETTLEUSD = Convert.ToDecimal(reader["SETTLEUSD"]); if (reader["SETTLERATE"] != DBNull.Value) data.SETTLERATE = Convert.ToDecimal(reader["SETTLERATE"]); data.APPLICANT = Convert.ToString(reader["APPLICANT"]); data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]); if (reader["APPLYTIME"] != DBNull.Value) data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]); if (reader["ENTERTIME"] != DBNull.Value) data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]); if (reader["SETTLETIME"] != DBNull.Value) data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]); if (reader["AUDITTIME"] != DBNull.Value) data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]); data.SETTLEUSER = Convert.ToString(reader["SETTLEUSER"]); data.AUDITUSER = Convert.ToString(reader["AUDITUSER"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); data.ACCOUNT= Convert.ToString(reader["ACCOUNT"]); data.ACCOUNTREF = Convert.ToString(reader["ACCOUNTREF"]); data.INVOICENUMREMARK = Convert.ToString(reader["INVOICENUMREMARK"]); if (reader["PREAMOUNTRMB"] != DBNull.Value) data.PREAMOUNTRMB = Convert.ToDecimal(reader["PREAMOUNTRMB"]); if (reader["PREAMOUNTUSD"] != DBNull.Value) data.PREAMOUNTUSD = Convert.ToDecimal(reader["PREAMOUNTUSD"]); if (reader["PRINTCOUNT"] != DBNull.Value) data.PRINTCOUNT = Convert.ToInt32(reader["PRINTCOUNT"]); data.SALECORP = Convert.ToString(reader["SALECORP"]); data.SALECORPID = Convert.ToString(reader["SALECORPID"]); data.ORREASON = Convert.ToString(reader["ORREASON"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion public int GetTotalCount(string strCondition, string userid, string usercode, string orgcode) { var strSql = new StringBuilder(); strSql.Append(" SELECT count(*) _count"); strSql.Append(" FROM ch_fee_recvapplication cm where 1=1 "); var rangstr = GetRangDAListStr("", userid, usercode, orgcode); if (!string.IsNullOrEmpty(rangstr)) { strSql.Append(" and " + rangstr); } 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; } #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 "); strSql.Append(",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF"); strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO"); strSql.Append(",b.CUSTOMERNAME,b.ENTERP,f.ACCTAXRATE"); 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,(select name from company where GID=b.CORPID) COMPANYNAME,(select name from company where GID=b.SALECORPID) BSSALECORP"); strSql.Append(" FROM ch_fee_do c"); strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)"); strSql.Append(" left join ch_fee f on (f.gid=c.feeid) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by c.CREATETIME,b.ETD,b.MBLNO "); } return BodySetData(strSql); } private static List BodySetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { Chfee_do_detail data = new Chfee_do_detail(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.FEEDOID = Convert.ToString(reader["GID"]); data.FEEID = Convert.ToString(reader["FEEID"]); data.FEENAME = Convert.ToString(reader["FEENAME"]); data.FEEOBJNAME = Convert.ToString(reader["FEEOBJNAME"]); data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]); data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]); data.CURRENCY = Convert.ToString(reader["CURRENCY"]); data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]); data.DOAMOUNT = Convert.ToDecimal(reader["DOAMOUNT"]); data.ORIGCURRENCY = Convert.ToString(reader["ORIGCURRENCY"]); data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"]); data.ORIGSTLAMOUNT = Convert.ToDecimal(reader["ORIGSTLAMOUNT"]); data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToString(reader["ETD"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.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.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]); data.ENTERP = Convert.ToString(reader["ENTERP"]); if (reader["ACCTAXRATE"] != DBNull.Value) data.ACCTAXRATE = Convert.ToDecimal(reader["ACCTAXRATE"]); data.BSSALECORP = Convert.ToString(reader["BSSALECORP"]); #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 strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE"); strSql.Append(",b.DOC,b.SALE"); strSql.Append(",f.GID AS CH_ID,f.FeeType"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref"); strSql.Append(",f.feeName,f.customerName as FeeObjName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,f.currency,f.exChangerate,isnull(f.invoice,0) as invoice"); 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.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"]); data.Invoice = Convert.ToDecimal(reader["invoice"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 添加列表 static public List GetAddBillList(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='RECAPPFEERANGE'"); 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 strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.REMARK"); strSql.Append(",F.CUSTOMERNAME AS CUSTNAME "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,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.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,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.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,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.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR"); strSql.Append(",(select name from company where gid=b.CORPID) COMPANYNAME "); strSql.Append(" FROM CH_FEE f "); strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); strSql.Append(" where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'"); if (SeaeDefaultSort.PARAMVALUE != "2") strSql.Append(" and f.FEESTATUS IN (0,8,9) "); else strSql.Append(" and f.FEESTATUS IN (2,0,8,9) "); 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 b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.REMARK,f.CUSTOMERNAME,b.CORPID"); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by b.ETD,b.MBLNO,b.BsNo"); } return SetAddBillData(strSql); } 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.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.DOC = Convert.ToString(reader["DOC"]); data.SALE = Convert.ToString(reader["SALE"]); data.REMARK = Convert.ToString(reader["REMARK"]); if (reader["BSSTATUS"] != DBNull.Value) data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]); if (reader["RMBDR"] != DBNull.Value) data.RMBDrAmount = Convert.ToDecimal(reader["RMBDR"]); if (reader["BALRMBDR"] != DBNull.Value) data.RMBDrBalAmount = Convert.ToDecimal(reader["BALRMBDR"]); if (reader["BALRMBDR"] != DBNull.Value) data.RMBDrDoAmount = Convert.ToDecimal(reader["BALRMBDR"]); 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"]); if (reader["BALUSDDR"] != DBNull.Value) data.USDDrDoAmount = Convert.ToDecimal(reader["BALUSDDR"]); 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"]); if (reader["BALOTDR"] != DBNull.Value) data.OTDrDoAmount = Convert.ToDecimal(reader["BALOTDR"]); 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"]); data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #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='RECAPPFEERANGE'"); 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.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.remark,f.AccTaxRate,f.INPUTMODE,f.SALECORP"); strSql.Append(" from ch_fee f where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'"); if (SeaeDefaultSort.PARAMVALUE != "2") strSql.Append(" and f.FEESTATUS IN (0,8,9) "); else strSql.Append(" and f.FEESTATUS IN (2,0,8,9) "); 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)) { sortstring = sortstring.Replace("StlAmount", "balamount"); 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"]); data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]); data.Remark = Convert.ToString(reader["Remark"]); data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]); data.SALECORP = Convert.ToString(reader["SALECORP"]); if (reader["AccTaxRate"] != DBNull.Value) data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]); #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.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,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; } public static DBResult AddDetail(string billno, List bodyList, string curr, string companyid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"insert into ch_fee_do (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 ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT2)>=0) OR (AMOUNT<0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT3)<=0))"); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdUpdate, "@ORDERAMOUNT2", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdUpdate, "@ORDERAMOUNT3", DbType.Decimal, enumValue.StlAmount); var updatecount = db.ExecuteNonQuery(cmdUpdate, tran); if (updatecount == 1) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, 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); if (curr == "") { db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.DoAmount); } else { db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, curr); db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.DoAmount); } db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType); db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 5); db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now); db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.ExChangerate); db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, ""); db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid); db.ExecuteNonQuery(cmdInsert, tran); } } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } /// /// 2023-1-28 ///如果此次选择的业务中,销售人员的所属公司分属不同,返回错误 ///如果头表所属分部为空 将其设置为所选业务的销售人员所属的公司 并保存; ///如果头表所属分部不为空 判断所属分部与所选业务的销售人员所属的公司是否相同 如否则返回错误; /// /// /// /// /// /// /// /// public static DBResult SetSALECORP(string billno, List bsnoList, string billcust, string companyid, string userid, bool custgroup = false) { var result = new DBResult(); result.OK(); var cdc = new CommonDataContext(); var SaleCorpList=cdc.v_op_bill.Where(x=>bsnoList.Contains(x.BSNO)).Select(s=>s.SALECORPID).Distinct().ToList(); if (SaleCorpList == null || SaleCorpList.Count != 1) { result.SetErrorInfo("所选业务的销售公司应当相同!"); return result; } var head = cdc.ch_fee_recvapplication.FirstOrDefault(x => x.BILLNO == billno); if (head == null|| string.IsNullOrWhiteSpace(head.BILLNO)) { result.SetErrorInfo("请先保存业务!"); return result; } if (string.IsNullOrWhiteSpace(head.SALECORPID)) { head.SALECORPID = SaleCorpList[0]; cdc.ch_fee_recvapplication.AddOrUpdate(head); cdc.SaveChanges(); } else { if (head.SALECORPID != SaleCorpList[0]) { result.SetErrorInfo("所选业务的所属分部应当与申请单当前的所属分部相同!"); return result; } } return result; } public static DBResult SetSALECORP(string billno, string feesql, string billcust, string companyid, string userid, bool custgroup = false) { if (!custgroup) feesql = feesql + " AND CUSTOMERNAME='" + billcust + "'"; var feelist = GetFeeDetailList(feesql, userid, "", companyid,"");//GetFeeDetailList var bsnoList = feelist.Select(s => s.BSNO).Distinct().ToList(); return SetSALECORP(billno, bsnoList, billcust, companyid, userid, custgroup); } public static DBResult AddBill(string billno, string billcust, string billcurr, string feesql, List exratelist, string companyid,string userid, bool custgroup = false) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); 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); //2023-1-28 如果头表所属分部为空 将其设置为所选业务的销售人员所属的公司 //如果此次选择的业务中,销售人员的所属公司分属不同 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 ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT2)>=0) OR (AMOUNT<0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT3)<=0))"); if (feelist != null) { foreach (var enumValue in feelist) { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdUpdate, "@ORDERAMOUNT2", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdUpdate, "@ORDERAMOUNT3", DbType.Decimal, enumValue.StlAmount); var updatecount = db.ExecuteNonQuery(cmdUpdate, tran); if (updatecount == 1) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, 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); if (billcurr == null || billcurr == "") db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency); else db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, billcurr); if (billcurr == enumValue.Currency) { db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1); } else { if (billcurr == "") { db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1); } else { var UExrate = GetExrate(enumValue.Currency, exratelist); db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount * UExrate); db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate); } } db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType); db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, enumValue.StlAmount); db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 5); 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, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount); //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 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) { 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 set ORDERAMOUNT=isnull((select sum(Amount) from ch_fee_do where GID<>@FEEDOID and feeid=ch_fee.gid and CATEGORY in(2,5) ),0) where GID=@GID"); var cmddelete = db.GetSqlStringCommand("delete from ch_fee_do where GID=@FEEDOID"); foreach (var enumValue in boday) { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@FEEDOID", DbType.String, enumValue.FEEDOID); db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID); db.ExecuteNonQuery(cmdupdate, tran); cmddelete.Parameters.Clear(); db.AddInParameter(cmddelete, "@FEEDOID", DbType.String, enumValue.FEEDOID); db.ExecuteNonQuery(cmddelete, tran); } } result = new DBResult(); result.Success = true; result.Message = "成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功"; return result; } public static int p_update_Amount(string billno) { Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetStoredProcCommand("p_update_recvapplycation"); db.AddInParameter(cmd, "@con_no", DbType.String, billno); db.ExecuteNonQuery(cmd); return 0; } public static string GetCustNo(string masterbsno) { var strnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var billno = ""; var strnumno = ""; var strSql = new StringBuilder(); strSql.Append("select billno from ch_fee_recvapplication where billno like '" + masterbsno + "%' order by billno"); var i = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = Convert.ToString(reader["billno"]); var strnumno1 = evData.Substring(evData.Length - 1, 1); var strnumno2 = strnum.Substring(i, 1); if (strnumno1 != strnumno2) strnumno = strnumno2; i = i + 1; } reader.Close(); } if (strnumno == "") strnumno = strnum.Substring(i, 1); billno = masterbsno + strnumno; return billno; } static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT Count(GID) AS CT from ch_fee_recvapplication (NOLOCK) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var ct = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ct = Convert.ToInt16(reader["CT"]); } reader.Close(); } return ct; } #region 提交审核和撤销审核 public static DBResult SubmitAudit(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 { var cmdupdate = db.GetSqlStringCommand("update ch_fee_recvapplication set BILLSTATUS=2,APPLYTIME=getdate() where BILLNO=@BILLNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "提交审核成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交审核错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitAuditList(String bills) { var result = new DBResult(); var billList = bills.Split(','); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var bill in billList) { var cmdupdate = db.GetSqlStringCommand("update ch_fee_recvapplication set BILLSTATUS=2,APPLYTIME=getdate() where BILLNO=@BILLNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "提交审核成功"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交审核错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitAuditBack(String bill) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdupdate = db.GetSqlStringCommand("update ch_fee_recvapplication set BILLSTATUS=1 where BILLNO=@BILLNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销提交成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销提交错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitAuditBackList(String bills) { var result = new DBResult(); var billList = bills.Split(','); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var bill in billList) { var cmdupdate = db.GetSqlStringCommand("update ch_fee_recvapplication set BILLSTATUS=1 where BILLNO=@BILLNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销提交成功"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销提交错误,请重试或联系系统管理员"; return result; } } return result; } #endregion #region 驳回 public static DBResult AuditList(List boday,string SHOWNAME) { var result = new DBResult(); try { var cdc = new CommonDataContext(); var billnolist = boday.Select(s => s.BILLNO).ToList(); var recvapplicationList = cdc.ch_fee_recvapplication.Where(x => billnolist.Contains(x.BILLNO)).ToList(); if (recvapplicationList != null && recvapplicationList.Count > 0) { foreach (var item in recvapplicationList) { item.BILLSTATUS = 0; item.AUDITTIME = DateTime.Now; item.AUDITUSER = SHOWNAME; } cdc.SaveChanges(); } result.Success = true; result.Message = "审核通过"; return result; } catch (Exception e) { result.Success = false; result.Message = "审核错误【"+e.Message+"】"; return result; } //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_recvapplication set BILLSTATUS=0 where BILLNO=@BILLNO"); // foreach (var enumValue in boday) // { // cmdupdate.Parameters.Clear(); // db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO); // db.ExecuteNonQuery(cmdupdate, tran); // } // } // result = new DBResult(); // result.Success = true; // result.Message = "审核通过"; // tran.Commit(); // } // catch (Exception) // { // tran.Rollback(); // result.Success = false; // result.Message = "审核出现错误,请重试或联系系统管理员"; // return result; // } //} //result.Success = true; //result.Message = "审核通过"; //return result; } public static DBResult AuditBackList(List boday,string ORREASON,string SHOWNAME) { var result = new DBResult(); try { var cdc = new CommonDataContext(); var billnolist = boday.Select(s => s.BILLNO).ToList(); var recvapplicationList = cdc.ch_fee_recvapplication.Where(x => billnolist.Contains(x.BILLNO)).ToList(); if (recvapplicationList != null && recvapplicationList.Count > 0) { foreach (var item in recvapplicationList) { item.BILLSTATUS = 6; item.AUDITTIME = DateTime.Now; item.AUDITUSER = SHOWNAME; item.ORREASON = ORREASON; } cdc.SaveChanges(); } result.Success = true; result.Message = "审核驳回"; return result; } catch (Exception e) { result.Success = false; result.Message = "审核驳回错误【" + e.Message + "】"; return result; } //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_recvapplication set BILLSTATUS=6,ORREASON='"+ ORREASON + "' where BILLNO=@BILLNO"); // foreach (var enumValue in boday) // { // cmdupdate.Parameters.Clear(); // db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO); // db.ExecuteNonQuery(cmdupdate, tran); // } // } // result = new DBResult(); // result.Success = true; // result.Message = "完成驳回"; // tran.Commit(); // } // catch (Exception) // { // tran.Rollback(); // result.Success = false; // result.Message = "驳回出现错误,请重试或联系系统管理员"; // return result; // } //} //result.Success = true; //result.Message = "完成驳回"; //return result; } #endregion #region 收费申请列表权限范围 public static string GetRangDAListStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modRecvSettleAppList' 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 = " (APPLICANT='" + userid + "')"; } else if (visiblerange == "3") { str = " (APPLICANT='" + userid + "')"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (COMPANYID='" + companyid + "' or SALECORPID='"+ companyid + "') and APPLICANT in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')"; } else if (visiblerange == "1") { str = " (COMPANYID='" + companyid + "' or SALECORPID='" + companyid + "') "; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "' or SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "' "; } else { str = str + " or COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "' or SALECORPID='" + 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 = " (APPLICANT='" + Convert.ToString(reader["OPID"]) + "'"; } else { str = str + " or APPLICANT='" + Convert.ToString(reader["OPID"]) + "' "; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "0") { str = " 1=1 "; } 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 "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modRecvSettleAppSearch' 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 = " (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 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 CUSTSERVICE 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 + "')))"; } 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 = " (Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'"; } else { str = str + " or 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 = " (OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' OR DOC='" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { str = str + " or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' OR DOC='" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "0") { str = " 1=1 "; } return str; } public static string GetRangAddFeeDAStr(string userid, string username, string companyid) { string str = ""; string modustr = "MODRECAPPFEERANGE"; 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; } #endregion } }