using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsChDui; using DSWeb.MvcShipping.Models.MsChDuiView; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using DSWeb.EntityDA; using HcUtility.Comm; using DSWeb.Areas.Account.Models.BillChfeeDetail; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.MvcShipping.Models.MsChFee; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using System.Data.SqlClient; using DSWeb.MvcShipping.DAL.MsInfoClient; using DSWeb.Areas.Account.Models.BSNOLB; using DSWeb.Areas.MvcShipping.DAL; namespace DSWeb.MvcShipping.DAL.MsChDui { public class MsChDuiDAL { #region Inquery DataList static public List GetDataList(int start, int limit, string strCondition, string userid, string usercode, string orgcode, string sort = null) { var rangstr = GetRangDAStr("", userid, usercode, orgcode); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by DUIDATE DESC"); } strSql.Append(@") as num , * from (select "); // strSql.Append("SELECT "); strSql.Append("DUINO,CUSTNAME"); strSql.Append(",DUIDATE"); strSql.Append(",OP,DUINAME,CUSTTYPE"); strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,ISNOTAX,BILLSTATUS"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",SUM(f.RMBDR) AS RMBDR,SUM(f.RMBCR) RMBCR,SUM(f.RMBDR-f.STLRMBDR) AS BALRMBDR,SUM(f.RMBCR-f.STLRMBCR) AS BALRMBCR,"); strSql.Append("SUM(f.USDDR) AS USDDR,SUM(f.USDCR) USDCR"); strSql.Append(",SUM(f.USDDR-f.STLUSDDR) AS BALUSDDR,SUM(f.USDCR-f.STLUSDCR) AS BALUSDCR,SUM(f.OTDR) OTDR,SUM(f.OTCR) OTCR,"); strSql.Append("SUM(f.OTDR-f.STLOTDR) AS BALOTDR,SUM(f.OTCR-f.STLOTCR) as BALOTCR"); strSql.Append(",SUM(f.TTLDR) AS TTLDR,SUM(f.TTLCR) AS TTLCR,SUM(f.TTLDR-f.STLTTLDR) AS BALTTLDR,SUM(f.TTLCR-f.STLTTLCR) as BALTTLCR,SUM(f.NOINVOICE) as NOINVOICE"); strSql.Append(" from ch_dui "); strSql.Append(" left join v_dui_allfee_sum f on (f.DEBITNO=ch_dui.DUINO)"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append("GROUP BY DUINO,CUSTNAME"); strSql.Append(",DUIDATE"); strSql.Append(",OP,DUINAME,CUSTTYPE"); strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,BILLSTATUS,ISNOTAX) as v "); strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} ORDER BY NUM ", start, start + limit)); return SetData(strSql); } static public string GetDataListStr(string strCondition, string userid, string usercode, string orgcode, string sort = null) { var rangstr = GetRangDAStr("", userid, usercode, orgcode); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT DUINO,CUSTNAME"); strSql.Append(",DUIDATE"); strSql.Append(",OP,DUINAME,CUSTTYPE"); strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,ISNOTAX,BILLSTATUS"); strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97006 and EnumValueID=ch_dui.BILLSTATUS) as BILLSTATUSREF"); strSql.Append(",SUM(f.RMBDR) AS RMBDR,SUM(f.RMBCR) RMBCR,SUM(f.RMBDR-f.STLRMBDR) AS BALRMBDR,SUM(f.RMBCR-f.STLRMBCR) AS BALRMBCR,"); strSql.Append("SUM(f.USDDR) AS USDDR,SUM(f.USDCR) USDCR"); strSql.Append(",SUM(f.USDDR-f.STLUSDDR) AS BALUSDDR,SUM(f.USDCR-f.STLUSDCR) AS BALUSDCR,SUM(f.OTDR) OTDR,SUM(f.OTCR) OTCR,"); strSql.Append("SUM(f.OTDR-f.STLOTDR) AS BALOTDR,SUM(f.OTCR-f.STLOTCR) as BALOTCR"); strSql.Append(",SUM(f.TTLDR) AS TTLDR,SUM(f.TTLCR) AS TTLCR,SUM(f.TTLDR-f.STLTTLDR) AS BALTTLDR,SUM(f.TTLCR-f.STLTTLCR) as BALTTLCR,SUM(f.NOINVOICE) as NOINVOICE"); strSql.Append(" from ch_dui "); strSql.Append(" left join v_dui_allfee_sum f on (f.DEBITNO=ch_dui.DUINO)"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append("GROUP BY DUINO,CUSTNAME"); strSql.Append(",DUIDATE"); strSql.Append(",OP,DUINAME,CUSTTYPE"); strSql.Append(",DM_ID,REMARKS,DC,ISNOSTL,BILLSTATUS,ISNOTAX"); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by DUIDATE DESC"); } return strSql.ToString(); } public static int getTotalCount(string strCondition, string userid, string usercode, string companyid) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT COUNT(*) "); strSql.Append(" from ch_dui "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } static public ChDui GetData(string condition, string userid, string usercode, string orgcode) { ChDui data = null; var list = GetDataList(0,1,condition,userid,usercode,orgcode); if (list.Count > 0) data = list[0]; if (data == null) { data = new ChDui(); } return data; } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ChDui data = new ChDui(); #region Set DB data to Object data.DUINO = Convert.ToString(reader["DUINO"]); data.CUSTNAME = Convert.ToString(reader["CUSTNAME"]); data.OP = Convert.ToString(reader["OP"]); data.DUINAME = Convert.ToString(reader["DUINAME"]); if (reader["BILLSTATUS"] != DBNull.Value) data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]); data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]); data.DM_ID = Convert.ToString(reader["DM_ID"]); data.DC = Convert.ToString(reader["DC"]); data.ISNOSTL = Convert.ToString(reader["ISNOSTL"]); data.ISNOTAX = Convert.ToString(reader["ISNOTAX"]); data.CUSTTYPE = Convert.ToString(reader["CUSTTYPE"]); if (reader["DUIDATE"] != DBNull.Value) data.DUIDATE = Convert.ToString(reader["DUIDATE"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); if (reader["RMBDR"] != DBNull.Value) data.RMBDR = Convert.ToDecimal(reader["RMBDR"]); if (reader["RMBCR"] != DBNull.Value) data.RMBCR = Convert.ToDecimal(reader["RMBCR"]); if (reader["BALRMBDR"] != DBNull.Value) data.BALRMBDR = Convert.ToDecimal(reader["BALRMBDR"]); if (reader["BALRMBCR"] != DBNull.Value) data.BALRMBCR = Convert.ToDecimal(reader["BALRMBCR"]); if (reader["USDDR"] != DBNull.Value) data.USDDR = Convert.ToDecimal(reader["USDDR"]); if (reader["USDCR"] != DBNull.Value) data.USDCR = Convert.ToDecimal(reader["USDCR"]); if (reader["BALUSDDR"] != DBNull.Value) data.BALUSDDR = Convert.ToDecimal(reader["BALUSDDR"]); if (reader["BALUSDCR"] != DBNull.Value) data.BALUSDCR = Convert.ToDecimal(reader["BALUSDCR"]); if (reader["OTDR"] != DBNull.Value) data.OTDR = Convert.ToDecimal(reader["OTDR"]); if (reader["OTCR"] != DBNull.Value) data.OTCR = Convert.ToDecimal(reader["OTCR"]); if (reader["BALOTDR"] != DBNull.Value) data.BALOTDR = Convert.ToDecimal(reader["BALOTDR"]); if (reader["BALOTCR"] != DBNull.Value) data.BALOTCR = Convert.ToDecimal(reader["BALOTCR"]); if (reader["TTLDR"] != DBNull.Value) data.TTLDR = Convert.ToDecimal(reader["TTLDR"]); if (reader["TTLCR"] != DBNull.Value) data.TTLCR = Convert.ToDecimal(reader["TTLCR"]); if (reader["BALTTLDR"] != DBNull.Value) data.BALTTLDR = Convert.ToDecimal(reader["BALTTLDR"]); if (reader["BALTTLCR"] != DBNull.Value) data.BALTTLCR = Convert.ToDecimal(reader["BALTTLCR"]); if (reader["NOINVOICE"] != DBNull.Value && Convert.ToDecimal(reader["NOINVOICE"]) == 0) data.ISINVOICE = "是"; #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region Bill DataList static public List GetBillList(int start, int limit, string strCondition,string sort=null) { var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by ETD,MBLNO "); } strSql.Append(@") as num ,v.* from ("); // strSql.Append(" "); strSql.Append(" select d.BSNO,d.DUINO,dbo.F_GetDuiFeeStatus(d.BSNO,d.DUINO) DUIFEESTATUS"); strSql.Append(",b.OPLB,b.OPLBNAME,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMERNAME,b.VESSEL,b.VOYNO,b.ETD,b.CUSTOMNO,b.ORDERNO,b.PORTDISCHARGE"); strSql.Append(",b.ACCDATE,b.SALE,b.OP,b.CNTRTOTAL,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP"); strSql.Append(",f.RMBDR,f.RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.USDDR,f.USDCR"); strSql.Append(",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.OTDR,f.OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR"); strSql.Append(",f.TTLDR,f.TTLCR,f.TTLDR-f.STLTTLDR AS BALTTLDR,f.TTLCR-f.STLTTLCR as BALTTLCR,f.RMBORDERINVOICEDR,f.USDORDERINVOICEDR,f.RMBORDERAMOUNTCR,f.USDORDERAMOUNTCR"); strSql.Append(",f.DUIRMBDR,f.DUIRMBCR,f.DUIUSDDR,f.DUIUSDCR,f.DUIOTDR,f.DUIOTCR,f.DUITTLDR,f.DUITTLCR"); strSql.Append(" from ch_dui_bill d "); strSql.Append(" left join v_op_bill b on (b.BSNO=d.BSNO)"); strSql.Append(" left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO)"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" ) as V "); strSql.Append( @")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); // return SetBillData(strSql); } public static int getDetailTotalCount(string strCondition) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(d.BSNO) "); strSql.Append(" from ch_dui_bill d "); strSql.Append(" left join v_op_bill b on (b.BSNO=d.BSNO)"); strSql.Append(" left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO)"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } private static List SetBillData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ChDuiBillView data = new ChDuiBillView(); #region Set DB data to Object data.DUINO = Convert.ToString(reader["DUINO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.DUIFEESTATUS = getfeestatus(Convert.ToString(reader["DUIFEESTATUS"])); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]); data.OPLB = Convert.ToString(reader["OPLB"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.ETD = Convert.ToString(reader["ETD"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.ETD = Convert.ToString(reader["ETD"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.SALE = Convert.ToString(reader["SALE"]); data.OP = Convert.ToString(reader["OP"]); data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]); data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); if (reader["RMBDR"] != DBNull.Value) data.RMBDR = Convert.ToDecimal(reader["RMBDR"]); if (reader["RMBCR"] != DBNull.Value) data.RMBCR = Convert.ToDecimal(reader["RMBCR"]); if (reader["BALRMBDR"] != DBNull.Value) data.BALRMBDR = Convert.ToDecimal(reader["BALRMBDR"]); if (reader["BALRMBCR"] != DBNull.Value) data.BALRMBCR = Convert.ToDecimal(reader["BALRMBCR"]); if (reader["USDDR"] != DBNull.Value) data.USDDR = Convert.ToDecimal(reader["USDDR"]); if (reader["USDCR"] != DBNull.Value) data.USDCR = Convert.ToDecimal(reader["USDCR"]); if (reader["BALUSDDR"] != DBNull.Value) data.BALUSDDR = Convert.ToDecimal(reader["BALUSDDR"]); if (reader["BALUSDCR"] != DBNull.Value) data.BALUSDCR = Convert.ToDecimal(reader["BALUSDCR"]); if (reader["OTDR"] != DBNull.Value) data.OTDR = Convert.ToDecimal(reader["OTDR"]); if (reader["OTCR"] != DBNull.Value) data.OTCR = Convert.ToDecimal(reader["OTCR"]); if (reader["BALOTDR"] != DBNull.Value) data.BALOTDR = Convert.ToDecimal(reader["BALOTDR"]); if (reader["BALOTCR"] != DBNull.Value) data.BALOTCR = Convert.ToDecimal(reader["BALOTCR"]); if (reader["TTLDR"] != DBNull.Value) data.TTLDR = Convert.ToDecimal(reader["TTLDR"]); if (reader["TTLCR"] != DBNull.Value) data.TTLCR = Convert.ToDecimal(reader["TTLCR"]); if (reader["BALTTLDR"] != DBNull.Value) data.BALTTLDR = Convert.ToDecimal(reader["BALTTLDR"]); if (reader["BALTTLCR"] != DBNull.Value) data.BALTTLCR = Convert.ToDecimal(reader["BALTTLCR"]); if (reader["RMBORDERINVOICEDR"] != DBNull.Value) data.RMBORDERINVOICEDR = Convert.ToDecimal(reader["RMBORDERINVOICEDR"]); if (reader["USDORDERINVOICEDR"] != DBNull.Value) data.USDORDERINVOICEDR = Convert.ToDecimal(reader["USDORDERINVOICEDR"]); if (reader["RMBORDERAMOUNTCR"] != DBNull.Value) data.RMBORDERAMOUNTCR = Convert.ToDecimal(reader["RMBORDERAMOUNTCR"]); if (reader["USDORDERAMOUNTCR"] != DBNull.Value) data.USDORDERAMOUNTCR = Convert.ToDecimal(reader["USDORDERAMOUNTCR"]); data.SALECORP = Convert.ToString(reader["SALECORP"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static string getfeestatus(string feestatusint) { var result = ""; if (feestatusint == "0:") { return "审核通过"; } else if (feestatusint == "1:") { return "录入状态"; } else if (feestatusint == "2:") { return "提交审核"; } else if (feestatusint == "8:") { return "部分结算"; } else if (feestatusint == "9:") { return "结算完毕"; } else if (feestatusint == "") { return "未录入"; } else if (feestatusint == "3:") { return "申请修改"; } else if (feestatusint == "4:") { return "申请删除"; } else if (feestatusint == "6:") { return "驳回提交"; } else if (feestatusint == "7:") { return "驳回申请"; } else if (feestatusint.IndexOf("9:") > -1) { return "部分结算"; } else if (feestatusint.IndexOf("8:") > -1) { return "部分结算"; } else if (feestatusint.IndexOf("0:") > -1) { return "部分审核"; } else if (feestatusint.IndexOf("2:") > -1) { return "部分提交"; } return result; } #endregion #region detail DataList static public List GetDetailList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("f.DUINO,f.DO_ID,f.BSNO,f.GID AS CH_ID,f.ISDEBIT"); 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.DEBITAMOUNT,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.NoTaxAmount,f.Remark"); strSql.Append(" from v_dui_fee f"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetDetailData(strSql); } static public ChDuiDetailView GetDetailData(string condition) { ChDuiDetailView data = null; var list = GetDetailList(condition); if (list.Count > 0) data = list[0]; if (data == null) { data = new ChDuiDetailView(); } return data; } private static List SetDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ChDuiDetailView data = new ChDuiDetailView(); #region Set DB data to Object data.DO_ID = Convert.ToString(reader["DO_ID"]); data.ISDEBIT = Convert.ToString(reader["ISDEBIT"]); data.DUINO = Convert.ToString(reader["DUINO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CH_ID = Convert.ToString(reader["CH_ID"]); data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]); data.FeeName = Convert.ToString(reader["feeName"]); data.CustomerName = Convert.ToString(reader["customerName"]); if (reader["Amount"] != DBNull.Value) data.Amount = Convert.ToDecimal(reader["Amount"]); if (reader["DEBITAMOUNT"] != DBNull.Value) data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]); if (reader["BalAmount"] != DBNull.Value) data.BalAmount = Convert.ToDecimal(reader["BalAmount"]); data.Currency = Convert.ToString(reader["Currency"]); if (reader["exChangerate"] != DBNull.Value) data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]); if (reader["NoTaxAmount"] != DBNull.Value) data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]); data.Remark = Convert.ToString(reader["Remark"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region Inquery FeeDataList static public List GetFeeDataList(string strCondition, string strduiCondition, string isdebit, string userid, string usercode, string orgcode,string sort) { /* var rangstr = GetRangDAStr("index", userid, usercode, orgcode); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; strduiCondition = strduiCondition + " and " + rangstr; } else { strCondition = rangstr; strduiCondition = rangstr; } } */ var strSql = new StringBuilder(); strSql.Append("SELECT '' AS DUINO,'否' as ISDEBIT,"); strSql.Append("BSNO,OPLB,OPLBNAME,BSSTATUS,ACCDATE,MBLNO,HBLNO,CUSTNO"); strSql.Append(",CUSTOMERNAME"); strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD"); strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE"); strSql.Append(",DOC,SALE"); strSql.Append(" from v_op_bill B "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (isdebit == "1") { strSql.Append(" UNION "); strSql.Append("SELECT DUINO,'是' as ISDEBIT,"); strSql.Append("BSNO,OPLB,OPLBNAME,BSSTATUS,ACCDATE,MBLNO,HBLNO,CUSTNO"); strSql.Append(",CUSTOMERNAME"); strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD"); strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE"); strSql.Append(",DOC,SALE"); strSql.Append(" from v_dui_opbill B"); if (!string.IsNullOrEmpty(strduiCondition)) { strSql.Append(" where " + strduiCondition); } } if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by BsNo"); } return SetFeeData(strSql); } private static List SetFeeData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpDuiBill data = new MsOpDuiBill(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.DUINO = Convert.ToString(reader["DUINO"]); data.ISDEBIT = Convert.ToString(reader["ISDEBIT"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToString(reader["ETD"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.OPLB = Convert.ToString(reader["OPLB"]); data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.DOC = Convert.ToString(reader["DOC"]); data.SALE = Convert.ToString(reader["SALE"]); data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 添加列表 static public List GetAddBillList(string strCondition, string strduiCondition, string isdebit, string userid, string usercode, string orgcode, string sort) { var rangstr = ""; rangstr = GetBillRangDAStr("index", userid, usercode, orgcode); var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND (f.ISOPEN=0 OR f.ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(rangstr)) rangstr = rangstr + " and " + isopenstr; else rangstr = isopenstr; } if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var DUIFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='DUIFEESTATUS'"); if (DUIFEESTATUS.PARAMVALUE != "" && DUIFEESTATUS.PARAMVALUE != "1") { var feestatusstr = " 1=1 "; if (DUIFEESTATUS.PARAMVALUE == "2") feestatusstr = " f.FEESTATUS<>1 "; else if (DUIFEESTATUS.PARAMVALUE == "0") feestatusstr = " f.FEESTATUS IN (0,8,9) "; if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + feestatusstr; } else { strCondition = feestatusstr; } } var modPSFEE = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid); if (!modPSFEE) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' "; } else { strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' "; } } var strSql = new StringBuilder(); strSql.Append("SELECT '' AS DUINO,'否' as ISDEBIT,"); strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP"); strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF "); strSql.Append(",F.CUSTOMERNAME AS CUSTNAME "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS DUIRMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS DUIRMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIUSDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIUSDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0)-ISNULL(DEBITAMOUNT,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)-ISNULL(DEBITAMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN CURRENCY<>'USD' AND CURRENCY<>'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIOTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN CURRENCY<>'USD' AND CURRENCY<>'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIOTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR"); strSql.Append(" FROM CH_FEE f "); strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL,B.SALECORPID,b.FEESTATUS"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,f.CUSTOMERNAME"); var sortstring = DatasetSort.Getsortstring(sort); if (isdebit == "1") { strSql.Append(" UNION "); strSql.Append("SELECT F.DUINO,'是' as ISDEBIT,"); strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,(select [NAME] from [company] where GID=B.SALECORPID) as SALECORP"); strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF "); strSql.Append(",F.CUSTOMERNAME AS CUSTNAME "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS DUIRMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS DUIRMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIUSDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIUSDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE WHEN CURRENCY<>'USD' AND CURRENCY<>'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIOTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE WHEN CURRENCY<>'USD' AND CURRENCY<>'RMB' THEN ISNULL(DEBITAMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS DUIOTCR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,"); strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR"); strSql.Append(" FROM v_dui_fee F "); strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(strduiCondition)) { strSql.Append(" where 1=1 AND " + strduiCondition); } else { strSql.Append(" where 1=1 "); } strSql.Append(" GROUP BY F.DUINO,b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO"); strSql.Append(",b.CUSTOMERNAME"); strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.ATD,b.PORTLOAD"); strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.CNTRTOTAL,B.SALECORPID,b.FEESTATUS"); strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,f.CUSTOMERNAME"); } if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by b.ETD,b.MBLNO,b.BsNo"); } return SetAddBillData(strSql); } private static List SetAddBillData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSql.ToString(); cmd.CommandTimeout = 120000; //要加这一句 using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { ChDuiBillView data = new ChDuiBillView(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.DUINO = Convert.ToString(reader["DUINO"]); data.ISDEBIT = Convert.ToString(reader["ISDEBIT"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToString(reader["ETD"]); if (reader["ATD"] != DBNull.Value) data.ATD = Convert.ToString(reader["ATD"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.OPLB = Convert.ToString(reader["OPLB"]); data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.DOC = Convert.ToString(reader["DOC"]); data.SALE = Convert.ToString(reader["SALE"]); data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]); data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]); data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]); if (reader["RMBDR"] != DBNull.Value) data.RMBDR = Convert.ToDecimal(reader["RMBDR"]); if (reader["BALRMBDR"] != DBNull.Value) data.BALRMBDR = Convert.ToDecimal(reader["BALRMBDR"]); if (reader["RMBCR"] != DBNull.Value) data.RMBCR = Convert.ToDecimal(reader["RMBCR"]); if (reader["BALRMBCR"] != DBNull.Value) data.BALRMBCR = Convert.ToDecimal(reader["BALRMBCR"]); if (reader["USDDR"] != DBNull.Value) data.USDDR = Convert.ToDecimal(reader["USDDR"]); if (reader["BALUSDDR"] != DBNull.Value) data.BALUSDDR = Convert.ToDecimal(reader["BALUSDDR"]); if (reader["USDCR"] != DBNull.Value) data.USDCR = Convert.ToDecimal(reader["USDCR"]); if (reader["BALUSDCR"] != DBNull.Value) data.BALUSDCR = Convert.ToDecimal(reader["BALUSDCR"]); if (reader["OTDR"] != DBNull.Value) data.OTDR = Convert.ToDecimal(reader["OTDR"]); if (reader["BALOTDR"] != DBNull.Value) data.BALOTDR = Convert.ToDecimal(reader["BALOTDR"]); if (reader["OTCR"] != DBNull.Value) data.OTCR = Convert.ToDecimal(reader["OTCR"]); if (reader["BALOTCR"] != DBNull.Value) data.BALOTCR = Convert.ToDecimal(reader["BALOTCR"]); if (reader["DUIRMBDR"] != DBNull.Value) data.DUIRMBDR = Convert.ToDecimal(reader["DUIRMBDR"]); if (reader["DUIRMBCR"] != DBNull.Value) data.DUIRMBCR = Convert.ToDecimal(reader["DUIRMBCR"]); data.BALDUIRMBDR = data.RMBDR - data.DUIRMBDR; data.BALDUIRMBCR = data.RMBCR - data.DUIRMBCR; data.STLDUIRMBDR = data.BALDUIRMBDR; data.STLDUIRMBCR = data.BALDUIRMBCR; if (reader["DUIUSDDR"] != DBNull.Value) data.DUIUSDDR = Convert.ToDecimal(reader["DUIUSDDR"]); if (reader["DUIUSDCR"] != DBNull.Value) data.DUIUSDCR = Convert.ToDecimal(reader["DUIUSDCR"]); data.BALDUIUSDDR = data.USDDR - data.DUIUSDDR; data.BALDUIUSDCR = data.USDCR - data.DUIUSDCR; data.STLDUIUSDDR = data.BALDUIUSDDR; data.STLDUIUSDCR = data.BALDUIUSDCR; if (reader["DUIOTDR"] != DBNull.Value) data.DUIOTDR = Convert.ToDecimal(reader["DUIOTDR"]); if (reader["DUIOTCR"] != DBNull.Value) data.DUIOTCR = Convert.ToDecimal(reader["DUIOTCR"]); data.BALDUIOTDR = data.OTDR - data.DUIOTDR; data.BALDUIOTCR = data.OTCR - data.DUIOTCR; data.STLDUIOTDR = data.BALDUIOTDR; data.STLDUIOTCR = data.BALDUIOTCR; data.SALECORP = Convert.ToString(reader["SALECORP"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region SELECT SUM public static List GetSelectSum(string feesql, string duisql, string duino) { var evList = new List(); Database db = DatabaseFactory.CreateDatabase(); if (feesql != "") { var strSql = new StringBuilder(); strSql.Append("SELECT A.CURRENCY,SUM(A.DR) DR,SUM(A.CR) CR,SUM(A.NODR) NODR,SUM(A.NOCR) NOCR FROM "); strSql.Append("(SELECT CURRENCY,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NODR "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NOCR from ch_fee F WHERE " + feesql + " AND (ISDEBIT=0 or ISDEBIT IS NULL) "); strSql.Append(" GROUP BY CURRENCY"); strSql.Append(" UNION "); strSql.Append("SELECT CURRENCY,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS DR "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) ELSE 0 END),0) AS CR "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NODR "); strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0)-ISNULL(SETTLEMENT,0) ELSE 0 END),0) AS NOCR from v_dui_fee F WHERE " + duisql + "and GID NOT IN (SELECT GID from v_dui_fee where duino='" + duino + "')"); strSql.Append(" GROUP BY CURRENCY) AS A "); strSql.Append(" GROUP BY A.CURRENCY "); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { SelectSum Data = new SelectSum(); Data.CURRENCY = Convert.ToString(reader["CURRENCY"]); Data.DR = Convert.ToDecimal(reader["DR"]); Data.NODR = Convert.ToDecimal(reader["NODR"]); Data.CR = Convert.ToDecimal(reader["CR"]); Data.NOCR = Convert.ToDecimal(reader["NOCR"]); evList.Add(Data); } reader.Close(); } } return evList; } #endregion #region feedetail DataList static public List GetFeeDetailList(string strCondition,string isdebit,string userid) { var DUIFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='DUIFEESTATUS'"); if (DUIFEESTATUS.PARAMVALUE != "" && DUIFEESTATUS.PARAMVALUE != "1") { var feestatusstr = " 1=1 "; if (DUIFEESTATUS.PARAMVALUE == "2") feestatusstr = " f.FEESTATUS<>1 "; else if (DUIFEESTATUS.PARAMVALUE == "0") feestatusstr = " f.FEESTATUS IN (0,8,9) "; if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + feestatusstr; } else { strCondition = feestatusstr; } } var modPSFEE = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid); if (!modPSFEE) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' "; } else { strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' "; } } var strSql = new StringBuilder(); if (isdebit == "是") { strSql.Append("SELECT "); strSql.Append("f.BSNO,f.GID AS CH_ID,DUINO"); 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.DEBITAMOUNT,f.balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE"); strSql.Append(" from v_dui_fee f "); } else { var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND (f.ISOPEN=0 OR f.ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(strCondition)) strCondition = strCondition + " and " + isopenstr; else strCondition = isopenstr; } strSql.Append("SELECT "); strSql.Append("f.BSNO,f.GID AS CH_ID,'' DUINO"); 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.DEBITAMOUNT,f.amount-f.Settlement as balamount,f.currency,f.exChangerate,f.notaxamount,f.Remark,f.UNITPRICE"); strSql.Append(" from ch_fee f "); } if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetFeeDetailData(strSql); } private static List SetFeeDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSql.ToString(); cmd.CommandTimeout = 120000; //要加这一句 using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { ChFeeDetail data = new ChFeeDetail(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.CH_ID = Convert.ToString(reader["CH_ID"]); data.DUINO = Convert.ToString(reader["DUINO"]); data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]); data.FeeName = Convert.ToString(reader["feeName"]); data.CustomerName = Convert.ToString(reader["customerName"]); if (reader["Amount"] != DBNull.Value) data.Amount = Convert.ToDecimal(reader["Amount"]); if (reader["DEBITAMOUNT"] != DBNull.Value) data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]); data.DuiAmount = data.Amount-data.DEBITAMOUNT; if (reader["BalAmount"] != DBNull.Value) data.BalAmount = Convert.ToDecimal(reader["BalAmount"]); data.Currency = Convert.ToString(reader["Currency"]); if (reader["exChangerate"] != DBNull.Value) data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]); if (reader["NoTaxAmount"] != DBNull.Value) data.NoTaxAmount = Convert.ToDecimal(reader["NoTaxAmount"]); data.Remark = Convert.ToString(reader["Remark"]); if (reader["UNITPRICE"] != DBNull.Value) data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion public static DBResult AddDetail(string duino,List bodyList,string isdebit) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var bsno = ""; //if (isdebit == "是") { var cmdinsertdetail = db.GetSqlStringCommand("insert into ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT,ISDEBIT) values (@DUINO,@BSNO,@CH_ID,@DEBITAMOUNT,@ISDEBIT)"); var cmdupdatechfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)+@DEBITAMOUNT where GID=@CH_ID"); if (bodyList != null) { foreach (var enumValue in bodyList) { bsno = enumValue.BSNO; cmdinsertdetail.Parameters.Clear(); db.AddInParameter(cmdinsertdetail, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail, "@CH_ID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdinsertdetail, "@DEBITAMOUNT", DbType.Decimal, enumValue.DuiAmount); if (isdebit != "是") db.AddInParameter(cmdinsertdetail, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail, tran); if (isdebit != "是") { cmdupdatechfee.Parameters.Clear(); db.AddInParameter(cmdupdatechfee, "@CH_ID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdupdatechfee, "@DEBITAMOUNT", DbType.Decimal, enumValue.DuiAmount); db.ExecuteNonQuery(cmdupdatechfee, tran); } } } //} //else //{ // var cmdUpdate = // db.GetSqlStringCommand( // @" update ch_fee set ISDEBIT=1,DEBITNO=@DUINO WHERE Gid=@CH_ID"); // if (bodyList != null) // { // foreach (var enumValue in bodyList) // { // bsno = enumValue.BSNO; // cmdUpdate.Parameters.Clear(); // db.AddInParameter(cmdUpdate, "@CH_ID", DbType.String, enumValue.CH_ID); // db.AddInParameter(cmdUpdate, "@DUINO", DbType.String, duino); // db.ExecuteNonQuery(cmdUpdate, tran); // } // } //} var cmdinsertbill = db.GetSqlStringCommand("insert into ch_dui_bill(BSNO,DUINO) SELECT distinct BSNO, DUINO FROM v_dui_fee where DUINO = '" + duino + "' " + " AND NOT EXISTS (SELECT 1 from ch_dui_bill where DUINO='" + duino + "' AND BSNO=v_dui_fee.BSNO )"); //var cmd = db.GetStoredProcCommand("sMsAddChDuiBill"); //db.AddInParameter(cmd, "@ps_BsNo", DbType.String, bsno); //db.AddInParameter(cmd, "@ps_DuiNo", DbType.String, duino); //db.AddOutParameter(cmd, "@pi_Result", DbType.Int32, 20); //db.AddOutParameter(cmd, "@ps_Message", DbType.String, 2000); db.ExecuteNonQuery(cmdinsertbill, tran); result.Success =true; result.Message = "对账成功!"; tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"+e.Message; return result; } } result.Success = true; result.Message = "保存成功"; return result; } public static DBResult DelDetail (List bodyList ) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdinsertdetail = db.GetSqlStringCommand("delete from ch_dui_detail where DO_ID=@DO_ID"); var cmdupdatechfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)-@DEBITAMOUNT where GID=@CH_ID"); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdinsertdetail.Parameters.Clear(); db.AddInParameter(cmdinsertdetail, "@DO_ID", DbType.String, enumValue.DO_ID); db.ExecuteNonQuery(cmdinsertdetail, tran); if (enumValue.ISDEBIT != "1") { cmdupdatechfee.Parameters.Clear(); db.AddInParameter(cmdupdatechfee, "@CH_ID", DbType.String, enumValue.CH_ID); db.AddInParameter(cmdupdatechfee, "@DEBITAMOUNT", DbType.Decimal, enumValue.DEBITAMOUNT); db.ExecuteNonQuery(cmdupdatechfee, tran); } } } result = new DBResult(); result.Success = true; result.Message = "成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功"; return result; } public static DBResult AddBill(string duino, string duicust, List workList, string feesql,string feedetailsql,string userid) { var result = new DBResult(); var custgroup = MsInfoClientDAL.GetClientGroupData("SHORTNAME='"+ duicust + "'").PCORPNAME; Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var custstr = ""; if (feesql != "") { //while (feesql.Contains("F.")){ // feesql = feesql.Replace("F.", " "); //} var isopen = MsBaseInfoDAL.MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid); var isopenstr = ""; if (isopen == false) { isopenstr = " ( ENTEROPERATOR='" + userid + "' OR ( ENTEROPERATOR<>'" + userid + "' AND (ISOPEN=0 OR ISOPEN IS NULL))) "; if (!string.IsNullOrEmpty(feesql)) feesql = feesql + " and " + isopenstr; else feesql = isopenstr; } var DUIFEESTATUS = MsSysParamSetDAL.GetData("PARAMNAME='DUIFEESTATUS'"); if (DUIFEESTATUS.PARAMVALUE != "" && DUIFEESTATUS.PARAMVALUE != "1") { var feestatusstr = " 1=1 "; if (DUIFEESTATUS.PARAMVALUE == "2") feestatusstr = " FEESTATUS<>1 "; else if (DUIFEESTATUS.PARAMVALUE == "0") feestatusstr = " FEESTATUS IN (0,8,9) "; feesql = feesql + " and " + feestatusstr; } custstr= " AND CUSTOMERNAME='" + duicust + "'"; if (custgroup != "") { custstr = " AND (CUSTOMERNAME='" + duicust + "' or exists (select 1 from info_client where f.CUSTOMERNAME=info_client.SHORTNAME AND PCORPNAME='" + custgroup + "'))"; } } if (workList != null) { //var cmd = db.GetStoredProcCommand("sMsAddChDuiBill"); var cmdinsertdetail2 = db.GetSqlStringCommand("insert ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT,ISDEBIT) SELECT @DUINO,@BSNO,GID,DEBITAMOUNT,'1' from v_dui_fee " + " where DUINO=@DUINO2 AND BSNO=@BSNO2"); var cmdinsertdetail3 = db.GetSqlStringCommand("insert into ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT,ISDEBIT) values (@DUINO,@BSNO,@CH_ID,@DEBITAMOUNT,@ISDEBIT)"); var cmdupdatechfee3 = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)+@DEBITAMOUNT where GID=@CH_ID"); foreach (var enumValue in workList) { if (enumValue.BALDUIRMBDR != enumValue.STLDUIRMBDR || enumValue.BALDUIRMBCR != enumValue.STLDUIRMBCR || enumValue.BALDUIUSDDR != enumValue.STLDUIUSDDR || enumValue.BALDUIUSDCR != enumValue.STLDUIUSDCR || enumValue.BALDUIOTDR != enumValue.STLDUIOTDR || enumValue.BALDUIOTCR != enumValue.STLDUIOTCR) { var sql = ""; if (enumValue.ISDEBIT == "是") { sql = " CUSTOMERNAME='" + enumValue.FEEOBJNAME + "' AND DUINO='" + duino + "' AND BSNO='" + enumValue.BSNO+ "' and GID NOT IN (SELECT GID from v_dui_fee where duino='" + duino + "') "; } else { sql = " (ISNULL(F.DEBITAMOUNT,0)<>F.AMOUNT) AND BSNO='" + enumValue.BSNO+ "' AND CUSTOMERNAME='" + enumValue.FEEOBJNAME + "'"; }; if (!string.IsNullOrEmpty(feedetailsql)) sql = sql + " AND " + feedetailsql; decimal stlduirmbdr = 0; decimal stlduirmbcr = 0; decimal stlduiusddr = 0; decimal stlduiusdcr = 0; decimal stlduiotdr = 0; decimal stlduiotcr = 0; var feelist = GetFeeDetailList(sql, enumValue.ISDEBIT,userid); if (feelist != null&& feelist.Count!=0) { stlduirmbdr = enumValue.STLDUIRMBDR; stlduirmbcr = enumValue.STLDUIRMBCR; stlduiusddr = enumValue.STLDUIUSDDR; stlduiusdcr = enumValue.STLDUIUSDCR; stlduiotdr = enumValue.STLDUIOTDR; stlduiotcr = enumValue.STLDUIOTCR; foreach (var fee in feelist) { if (enumValue.BALDUIRMBDR != enumValue.STLDUIRMBDR && fee.Currency == "RMB" && fee.FeeType_Ref == "应收") { decimal duiamount = 0; if (stlduirmbdr != 0) { if (fee.DuiAmount <= stlduirmbdr) { duiamount = fee.DuiAmount; stlduirmbdr = stlduirmbdr - fee.DuiAmount; } else { duiamount = stlduirmbdr; stlduirmbdr = 0; } cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, duiamount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, duiamount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } else if (enumValue.BALDUIRMBCR != enumValue.STLDUIRMBCR && fee.Currency == "RMB" && fee.FeeType_Ref == "应付") { decimal duiamount = 0; if (stlduirmbcr != 0) { if (fee.DuiAmount <= stlduirmbcr) { duiamount = fee.DuiAmount; stlduirmbcr = stlduirmbcr - fee.DuiAmount; } else { duiamount = stlduirmbcr; stlduirmbcr = 0; } cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, duiamount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, duiamount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } else if (enumValue.BALDUIUSDDR != enumValue.STLDUIUSDDR && fee.Currency == "USD" && fee.FeeType_Ref == "应收") { decimal duiamount = 0; if (stlduiusddr != 0) { if (fee.DuiAmount <= stlduiusddr) { duiamount = fee.DuiAmount; stlduiusddr = stlduiusddr - fee.DuiAmount; } else { duiamount = stlduiusddr; stlduiusddr = 0; } cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, duiamount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, duiamount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } else if (enumValue.BALDUIUSDCR != enumValue.STLDUIUSDCR && fee.Currency == "USD" && fee.FeeType_Ref == "应付") { decimal duiamount = 0; if (stlduiusdcr != 0) { if (fee.DuiAmount <= stlduiusdcr) { duiamount = fee.DuiAmount; stlduiusdcr = stlduiusdcr - fee.DuiAmount; } else { duiamount = stlduiusdcr; stlduiusdcr = 0; } cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, duiamount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, duiamount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } else if (enumValue.BALDUIOTDR != enumValue.STLDUIOTDR && fee.Currency != "USD" && fee.Currency != "RMB" && fee.FeeType_Ref == "应收") { decimal duiamount = 0; if (stlduiotdr != 0) { if (fee.DuiAmount <= stlduiotdr) { duiamount = fee.DuiAmount; stlduiotdr = stlduiotdr - fee.DuiAmount; } else { duiamount = stlduiotdr; stlduiotdr = 0; } cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, duiamount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, duiamount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } else if (enumValue.BALDUIOTCR != enumValue.STLDUIOTCR && fee.Currency != "USD" && fee.Currency != "RMB" && fee.FeeType_Ref == "应付") { decimal duiamount = 0; if (stlduiotcr != 0) { if (fee.DuiAmount <= stlduiotcr) { duiamount = fee.DuiAmount; stlduiotcr = stlduiotcr - fee.DuiAmount; } else { duiamount = stlduiotcr; stlduiotcr = 0; } cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, duiamount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, duiamount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } else { cmdinsertdetail3.Parameters.Clear(); db.AddInParameter(cmdinsertdetail3, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail3, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdinsertdetail3, "@DEBITAMOUNT", DbType.Decimal, fee.DuiAmount); if (enumValue.ISDEBIT != "是") db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "0"); else db.AddInParameter(cmdinsertdetail3, "@ISDEBIT", DbType.String, "1"); db.ExecuteNonQuery(cmdinsertdetail3, tran); if (enumValue.ISDEBIT != "是") { cmdupdatechfee3.Parameters.Clear(); db.AddInParameter(cmdupdatechfee3, "@CH_ID", DbType.String, fee.CH_ID); db.AddInParameter(cmdupdatechfee3, "@DEBITAMOUNT", DbType.Decimal, fee.DuiAmount); db.ExecuteNonQuery(cmdupdatechfee3, tran); } } } } } else { if (enumValue.ISDEBIT == "是") { cmdinsertdetail2.Parameters.Clear(); db.AddInParameter(cmdinsertdetail2, "@DUINO", DbType.String, duino); db.AddInParameter(cmdinsertdetail2, "@DUINO2", DbType.String, enumValue.DUINO); db.AddInParameter(cmdinsertdetail2, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdinsertdetail2, "@BSNO2", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdinsertdetail2, tran); } else { var cmdinsertdetail = db.GetSqlStringCommand("insert ch_dui_detail(DUINO,BSNO,CH_ID,DEBITAMOUNT) SELECT @DUINO,BSNO,GID,AMOUNT-ISNULL(DEBITAMOUNT,0) from ch_fee F " + " where BSNO='" + enumValue.BSNO + "' AND " + feesql + custstr); cmdinsertdetail.Parameters.Clear(); db.AddInParameter(cmdinsertdetail, "@DUINO", DbType.String, duino); db.ExecuteNonQuery(cmdinsertdetail, tran); //feesql = feesql.Replace("", custstr); var cmdfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=AMOUNT from ch_fee f WHERE BSNO='" + enumValue.BSNO + "' AND " + feesql + custstr); db.AddInParameter(cmdfee, "@DUINO", DbType.String, duino); cmdfee.CommandTimeout = 120000; //要加这一句 db.ExecuteNonQuery(cmdfee, tran); } } } } var cmdinsertbill = db.GetSqlStringCommand("insert into ch_dui_bill(BSNO,DUINO) SELECT distinct BSNO, DUINO FROM v_dui_fee where DUINO = '" + duino + "' " + " AND NOT EXISTS (SELECT 1 from ch_dui_bill where DUINO='" + duino + "' AND BSNO=v_dui_fee.BSNO )"); db.ExecuteNonQuery(cmdinsertbill, tran); result = new DBResult(); result.Success =true; result.Message ="成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功"; return result; } public static DBResult UpdateBill(string duino) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdbill = db.GetSqlStringCommand("insert ch_dui_bill(DUINO,BSNO) SELECT DUINO DEBITNO,BSNO from ch_dui_detail WHERE DUINO='"+duino+"'"); db.ExecuteNonQuery(cmdbill, tran); result = new DBResult(); result.Success = true; result.Message = "成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功"; return result; } public static DBResult DelBill ( string duino, string feesql) { var result = new DBResult(); var feeduilist=GetDetailList(feesql+ " and DUINO='"+ duino + "'"); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (feeduilist != null) { foreach (var feedui in feeduilist) { var cmdbillfee = db.GetSqlStringCommand("delete from ch_dui_detail WHERE DO_ID=" + feedui.DO_ID); db.ExecuteNonQuery(cmdbillfee, tran); if (feedui.ISDEBIT != "1") { var cmdfee = db.GetSqlStringCommand("update ch_fee set DEBITAMOUNT=isnull(DEBITAMOUNT,0)-" + feedui.DEBITAMOUNT + " where GID='" + feedui.CH_ID+"'"); db.ExecuteNonQuery(cmdfee, tran); } } } var cmdbill = db.GetSqlStringCommand("delete from ch_dui_bill WHERE DUINO='"+duino+"' and " + feesql); db.ExecuteNonQuery(cmdbill, tran); var cmdautodui = db.GetSqlStringCommand("update ch_fee_autoDui set DUINO='' where DUINO='" + duino + "'"); db.ExecuteNonQuery(cmdautodui, tran); result = new DBResult(); result.Success = true; result.Message = "成功"; tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误<"+e.Message+">,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功"; return result; } static public List GetDuiPayBodyList(string duino) { //var strSql = new StringBuilder(); //strSql.Append("select distinct BSNO,MBLNO FROM v_op_bill WHERE BSNO IN ("); //strSql.Append("SELECT BSNO FROM v_dui_fee WHERE DUINO='"+ duino + "'"); //strSql.Append(" AND ((AMOUNT >= 0 AND((BALAMOUNT < DEBITAMOUNT) OR(DEBITAMOUNT > (AMOUNT - ORDERAMOUNT))))"); //strSql.Append(" OR(AMOUNT < 0 AND((DEBITAMOUNT < BALAMOUNT) OR(DEBITAMOUNT < (AMOUNT - ORDERAMOUNT))))))"); //return SetDuiPayBodyData(strSql); var bodyList = new List(); var FeedoList = MsOpBillDAL.GetAllFeeDoList("c.FEEID IN (SELECT GID FROM v_dui_fee WHERE DUINO='" + duino + "') AND C.CATEGORY in (1,2,3,8,9,4) "); if (FeedoList != null && FeedoList.Count != 0) { foreach (var feedo in FeedoList) { var finddata = bodyList.Find(X => X.BSNO == feedo.BILLNO); if (finddata == null) { BSNOLB data = new BSNOLB(); #region Set DB data to Object data.OPLB = feedo.BILLTYPE; data.BSNO = feedo.BILLNO; data.CUSTNO =feedo.BILLUSER; #endregion bodyList.Add(data); } } } return bodyList; } //private static List SetDuiPayBodyData(StringBuilder strSql) //{ // var bodyList = new List(); // Database db = DatabaseFactory.CreateDatabase(); // using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) // { // while (reader.Read()) // { // BSNOLB data = new BSNOLB(); // #region Set DB data to Object // data.BSNO = Convert.ToString(reader["BSNO"]); // data.CUSTNO = Convert.ToString(reader["MBLNO"]); // #endregion // bodyList.Add(data); // } // reader.Close(); // } // return bodyList; //} public static string IsDuiPayStr(string duino = "") { var error = ""; var duipanylist = GetDuiPayBodyList(duino); if (duipanylist != null && duipanylist.Count!=0) { foreach (var duipay in duipanylist) { { error = error + "
已做"+duipay.OPLB+" 单号:"+duipay.BSNO+" 操作人:"+ duipay.CUSTNO; } } } return error; } #region 参照部分 public static String GetPrintStr(ChDui headData) { var sqlstr = " SELECT d.DB_ID,d.DUINO,b.*,dbo.GetOtherFee(b.bsno,d.DUINO,u.DM_ID,1,'" + headData.ISNOSTL + "') as OTHERDRFEESTR,dbo.GetOtherFee(b.bsno,d.DUINO,u.DM_ID,2,'" + headData.ISNOSTL + "') as OTHERCRFEESTR" +",f.RMBDR,f.RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.USDDR,f.USDCR" +",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.OTDR,f.OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR" + ",O.OTHERUSDDR,O.OTHERUSDCR,O.OTHEROTDR,O.OTHEROTCR,O.OTHERRMBDR,O.OTHERRMBCR,O.OTHERTTLDR,O.OTHERTTLCR"; var fieldnamestr = ""; var fieldnamesumstr = "SELECT BSNO "; var strSql = new StringBuilder(); strSql.Append("Select FEETYPE,FEENAME,CURRENCY "); strSql.Append(" from code_dui_format_fee "); strSql.Append(" where DM_ID='"+headData.DM_ID+"'"); strSql.Append(" order by FEENAME"); Database db = DatabaseFactory.CreateDatabase(); if (headData.ISNOSTL == "B") { using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]); fieldnamestr = fieldnamestr + "," + fieldname; fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN " + "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname; } reader.Close(); } sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) " + "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr + " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join (" + " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) " + " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END)" + " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END) " + " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(BALAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR," + " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(BALAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR" + " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)" + " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'"; } else { using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]); fieldnamestr = fieldnamestr + "," + fieldname; fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN " + "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname; } reader.Close(); } sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) " + "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr + " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join (" + " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END) " + " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)" + " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END) " + " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(AMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR," + " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(AMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR" + " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)" + " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'"; } var sortSql = new StringBuilder(); sortSql.Append("Select FIELDNAME,SORTTYPE "); sortSql.Append(" from code_dui_format_sort "); sortSql.Append(" where DM_ID='" + headData.DM_ID + "'"); sortSql.Append(" order by SORTNUM"); var sortstr = ""; using (IDataReader reader = db.ExecuteReader(CommandType.Text, sortSql.ToString())) { while (reader.Read()) { var fieldname ="b."+ Convert.ToString(reader["FIELDNAME"]); if (Convert.ToInt16(reader["SORTTYPE"]) == 2) { fieldname = fieldname + " DESC "; }; if (sortstr == "") { sortstr = fieldname; } else { sortstr =sortstr+","+fieldname; } } reader.Close(); } sqlstr = sqlstr +" order by "+sortstr; return sqlstr; } public static String GetNoTaxPrintStr(ChDui headData) { var sqlstr = " SELECT d.DB_ID,d.DUINO,b.*,dbo.GetNoTaxOtherFee(b.bsno,d.DUINO,u.DM_ID,1,'" + headData.ISNOSTL + "') as OTHERDRFEESTR,dbo.GetNoTaxOtherFee(b.bsno,d.DUINO,u.DM_ID,2,'" + headData.ISNOSTL + "') as OTHERCRFEESTR" + ",f.NOTAXRMBDR RMBDR,f.NOTAXRMBCR RMBCR,f.RMBDR-f.STLRMBDR AS BALRMBDR,f.RMBCR-f.STLRMBCR AS BALRMBCR,f.NOTAXUSDDR USDDR,f.NOTAXUSDCR USDCR" + ",f.USDDR-f.STLUSDDR AS BALUSDDR,f.USDCR-f.STLUSDCR AS BALUSDCR,f.NOTAXOTDR OTDR,f.NOTAXOTCR OTCR,f.OTDR-f.STLOTDR AS BALOTDR,f.OTCR-f.STLOTCR as BALOTCR" + ",O.OTHERUSDDR,O.OTHERUSDCR,O.OTHEROTDR,O.OTHEROTCR,O.OTHERRMBDR,O.OTHERRMBCR,O.OTHERTTLDR,O.OTHERTTLCR"; var fieldnamestr = ""; var fieldnamesumstr = "SELECT BSNO "; var strSql = new StringBuilder(); strSql.Append("Select FEETYPE,FEENAME,CURRENCY "); strSql.Append(" from code_dui_format_fee "); strSql.Append(" where DM_ID='" + headData.DM_ID + "'"); strSql.Append(" order by FEENAME"); Database db = DatabaseFactory.CreateDatabase(); if (headData.ISNOSTL == "B") { using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]); fieldnamestr = fieldnamestr + "," + fieldname; fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN " + "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname; } reader.Close(); } sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) " + "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr + " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join (" + " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END) " + " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END)" + " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(BALAMOUNT,0) END) END) " + " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(BALAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(BALAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR," + " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(BALAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR" + " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)" + " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'"; } else { using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var fieldname = Convert.ToString(reader["FEENAME"]) + Convert.ToString(reader["FEETYPE"]) + Convert.ToString(reader["CURRENCY"]); fieldnamestr = fieldnamestr + "," + fieldname; fieldnamesumstr = fieldnamesumstr + ",isnull(SUM(CASE FEENAME WHEN '" + Convert.ToString(reader["FEENAME"]) + "' THEN (CASE FEETYPE WHEN " + Convert.ToString(reader["FEETYPE"]) + " THEN " + "(CASE CURRENCY WHEN '" + Convert.ToString(reader["CURRENCY"]) + "' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) ELSE 0 END) ELSE 0 END),0) AS " + fieldname; } reader.Close(); } sqlstr = sqlstr + fieldnamestr + " from ch_dui_bill d left join v_op_bill b on (b.BSNO=d.BSNO) left join ch_dui u on (u.DUINO=d.DUINO) " + "left join v_dui_allfee_sum f on (f.BSNO=d.BSNO and f.DEBITNO=d.DUINO) left join (" + fieldnamesumstr + " from v_dui_fee where DUINO='" + headData.DUINO + "'group by bsno) as m on (m.BSNO=d.bsno) left join (" + " SELECT BSNO,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END) " + " ELSE 0 END),0) AS OTHERUSDDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERUSDCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END)" + " ELSE 0 END),0) AS OTHEROTDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(NOTAXAMOUNT,0) END) END) " + " ELSE 0 END),0) AS OTHEROTCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBDR,isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(NOTAXAMOUNT,0) ELSE 0 END)" + " ELSE 0 END),0) AS OTHERRMBCR,isnull(SUM(CASE FEETYPE WHEN 1 THEN ISNULL(NOTAXAMOUNT,0) * ISNULL(EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLDR," + " isnull(SUM(CASE FEETYPE WHEN 2 THEN ISNULL(NOTAXAMOUNT,0) *ISNULL( EXCHANGERATE,0) ELSE 0 END),0) AS OTHERTTLCR" + " from v_dui_fee f where f.DUINO='" + headData.DUINO + "' AND NOT EXISTS ( SELECT 1 from code_dui_format_fee m where m.DM_ID='" + headData.DM_ID + "' and m.CURRENCY=f.CURRENCY and m.FEETYPE=f.FEETYPE and m.FEENAME=f.FEENAME)" + " group by bsno) as O on (O.BSNO=d.BSNO) where d.DUINO='" + headData.DUINO + "'"; } var sortSql = new StringBuilder(); sortSql.Append("Select FIELDNAME,SORTTYPE "); sortSql.Append(" from code_dui_format_sort "); sortSql.Append(" where DM_ID='" + headData.DM_ID + "'"); sortSql.Append(" order by SORTNUM"); var sortstr = ""; using (IDataReader reader = db.ExecuteReader(CommandType.Text, sortSql.ToString())) { while (reader.Read()) { var fieldname = "b." + Convert.ToString(reader["FIELDNAME"]); if (Convert.ToInt16(reader["SORTTYPE"]) == 2) { fieldname = fieldname + " DESC "; }; if (sortstr == "") { sortstr = fieldname; } else { sortstr = sortstr + "," + fieldname; } } reader.Close(); } sqlstr = sqlstr + " order by " + sortstr; return sqlstr; } #region 提交审核和撤销审核 public static DBResult Lock(string bill) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=1 where DUINO=@DUINO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "锁定成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "锁定错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult LockList(String bills) { var result = new DBResult(); var billList = bills.Split(','); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var bill in billList) { var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=1 where DUINO=@DUINO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "锁定成功"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "锁定错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult UnLock(String bill) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=2 where DUINO=@DUINO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销锁定成功"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销锁定错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult UnLockList(String bills) { var result = new DBResult(); var billList = bills.Split(','); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { foreach (var bill in billList) { var cmdupdate = db.GetSqlStringCommand("update ch_dui set BILLSTATUS=2 where DUINO=@DUINO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@DUINO", DbType.String, bill); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销锁定成功"; } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销锁定错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult SubmitFee(string bill,string userid,string companyid) { var result = new DBResult(); var billList = MsChDuiDAL.GetBillList(0, 1,"DUINO='"+bill+"'",""); var optype = "op_seae"; if (billList != null && billList.Count != 0) { optype = billList[0].OPLB; } try { foreach (var headdata in billList) { var dataList = DSWeb.MvcShipping.DAL.MsChFeeDAL.MsChFeeDAL.GetAllDataList("DEBITNO='" + bill + "' AND FEESTATUS=1 AND BSNO='"+headdata.BSNO+"' "); if (dataList != null && dataList.Count != 0) { optype = headdata.OPLB; result = Chfee_AuditDAL.Chfee_AuditDAL.SubmitAuditNew(optype, userid, dataList, false, "", "0", companyid); } else { result = new DBResult(); result.Success = true; result.Message = "提交成功(没有数据要提交)"; } } } catch (Exception) { result.Success = false; result.Message = "提交错误,请重试或联系系统管理员"; return result; } return result; } public static DBResult SubmitFeeList(String bills, string userid, string companyid) { var result = new DBResult(); var billList = bills.Split(','); try { foreach (var bill in billList) { var bsList = MsChDuiDAL.GetBillList(0, 1, "DUINO='" + bill + "'", ""); var optype = "op_seae"; //if (bsList != null && bsList.Count != 0) //{ // optype = bsList[0].OPLB; //} foreach (var bs in bsList) { var dataList = DSWeb.MvcShipping.DAL.MsChFeeDAL.MsChFeeDAL.GetAllDataList("DEBITNO='" + bill + "' AND FEESTATUS=1 and BSNO='"+bs.BSNO+"'"); if (dataList != null && dataList.Count != 0) { optype = bs.OPLB; result = Chfee_AuditDAL.Chfee_AuditDAL.SubmitAuditNew(optype, userid, dataList, false, "", "0", companyid); } else { result = new DBResult(); result.Success = true; result.Message = "提交成功(没有数据要提交)"; } } } } catch (Exception) { result.Success = false; result.Message = "提交错误,请重试或联系系统管理员"; return result; } return result; } #endregion public static string GetBillRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modChDuiAddBillList' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " (b.OP='" + username + "' OR b.SALE='" + username + "' OR b.DOC='" + username + "' OR b.CUSTSERVICE='" + username + "')"; } else if (visiblerange == "3") { str = " (b.OP='" + username + "' OR b.SALE='" + username + "' OR b.DOC='" + username + "' OR b.CUSTSERVICE='" + username + "' )"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (b.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR b.SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR b.DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " OR b.CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))" + " )"; } else if (visiblerange == "1") { str = " (b.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR b.SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR b.DOC in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR b.CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " )"; } else if (visiblerange == "5") { if (tb == "index") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (B.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or B.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "' "; } else { str = str + " or B.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or B.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else { str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') "; } } else if (visiblerange == "6") { if (tb == "index") { str = " EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where (B.OP=U.SHOWNAME OR B.SALE=U.SHOWNAME OR B.CUSTSERVICE=U.SHOWNAME OR B.DOC=U.SHOWNAME OR B.FRCUSTSERVICE=U.SHOWNAME OR B.INPUTBY=U.SHOWNAME) AND P.userid='" + userid + "' and P.AUTHORITYID='" + AUTHORITYID + "' and P.VISIBLERANGE=1) "; } else { str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') "; } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } public static string GetRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='modChDuiFeeList' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { visiblerange = Convert.ToString(reader["VISIBLERANGE"]); operaterange = Convert.ToString(reader["OPERATERANGE"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " (OP='" + username /*+ "' OR INPUTBY='" + username*/ + "')"; } else if (visiblerange == "3") { str = " (OP='" + username /*+ "' OR INPUTBY='" + username*/ + "')"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID=(select GID from [company] where codename='" + companyid + "')) and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))"; //+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))"; } else if (visiblerange == "1") { str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID=(select GID from [company] where codename='" + companyid + "'))))"; //+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')))"; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "'"; } else { str = str + " or COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "6") { var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (OP='" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { str = str + " or OP='" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } #endregion } }