using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsOpOther; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using HcUtility.Core; using System.Data.SqlClient; using DSWeb.DataAccess; using DSWeb.MvcShipping.Models.MsCodeServiceFeeTemplate; using DSWeb.MvcShipping.DAL.MsCodeServiceFeeTemplateDAL; using System.Web; using DSWeb.MvcShipping.Models.MsSysBillNoSet; using DSWeb.MvcShipping.DAL.MsSysBillNoSet; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using DSWeb.MvcShipping.Models.MsChFee; using DSWeb.MvcShipping.DAL.MsSysParamSet; namespace DSWeb.MvcShipping.DAL.MsOpOtherDAL { public class MsOpOtherDAL { #region Inquery DataList static public List GetDataList(int start, int limit, string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); 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 { var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='OpOtherDefaultSort'"); if (SeaeDefaultSort.PARAMVALUE != "") strSql.Append(" order by " + SeaeDefaultSort.PARAMVALUE); else strSql.Append(" order by BSDATE desc"); } strSql.Append(@") as num , "); // strSql.Append("op_other.BSNO, OPLB, OPLBNAME, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,"); strSql.Append(" CUSTNO, MBLNO, HBLNO, CONTRACTNO, CUSTOMERNAME, CONVERT(char(10), BSDATE, 20) as BSDATE, ACCDATE, BSSOURCE, BSSOURCEDETAIL, OP, CUSTSERVICE, SALE, FRCUSTSERVICE,CORPID, TRANSTYPE, VESSEL, VOYNO,"); strSql.Append(" CONVERT(char(10), ETD, 20) as ETD, PORTLOAD, PORTDISCHARGE, TRADETYPE, GOODSNAME, KGS, NETWEIGHT, PKGS, KINDPKGS, CBM,CTNALL,CTNNUM,ISVOU, VOUNO, REMARK,"); strSql.Append(" (select top 1 showname from [user] where GID=op_other.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_other.MODIFIEDUSER) as MODIFIEDUSER, "); strSql.Append(" MODIFIEDTIME, ORDERNO,OPERATOR,STLNAME,STLDATE,ENTERP,BOOKNO,dbo.F_GetBillDrFeeStatus(op_other.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_other.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLDUIDR,I.TTLCR,I.TTLINVCR,I.TTLDUICR "); strSql.Append(",SALECORPID,(select [NAME] from [company] where GID=op_other.SALECORPID) as SALECORP,CLOSINGDATE,CLOSEDOCDATE,SALEDEPT,CUSTOMSER,WAREHOUSE,COUNTRYOFORIGIN"); strSql.Append(",(SELECT COUNT(*) FROM OP_AMEND WHERE PARENTID = op_other.BSNO) as AMENDCOUNT"); strSql.Append(",IsService1,IsService2,IsService3,IsService4,IsService5,IsService6,IsService7,IsService8,IsService9,IsService10,IsService11,IsService12,IsService13,IsService14,IsService15,IsService16,op_other.BillFeeStatus FROM op_other"); strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_other.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num", start, start + limit)); // return SetData(strSql.ToString()); } static public List GetDataAllList(int start, int limit, string strCondition) { var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); strSql.Append(" order by BSDATE desc"); strSql.Append(@") as num , "); // strSql.Append("op_other.BSNO, OPLB, OPLBNAME, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,"); strSql.Append(" CUSTNO, MBLNO, HBLNO, CONTRACTNO, CUSTOMERNAME, CONVERT(char(10), BSDATE, 20) as BSDATE, ACCDATE, BSSOURCE, BSSOURCEDETAIL, OP, CUSTSERVICE, SALE, FRCUSTSERVICE,CORPID, TRANSTYPE, VESSEL, VOYNO,"); strSql.Append(" CONVERT(char(10), ETD, 20) as ETD, PORTLOAD, PORTDISCHARGE, TRADETYPE, GOODSNAME, KGS, NETWEIGHT, PKGS, KINDPKGS, CBM,CTNALL,CTNNUM,ISVOU, VOUNO, REMARK,"); strSql.Append(" (select top 1 showname from [user] where GID=op_other.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_other.MODIFIEDUSER) as MODIFIEDUSER, "); strSql.Append(" MODIFIEDTIME, ORDERNO,OPERATOR,STLNAME,STLDATE,ENTERP,BOOKNO,dbo.F_GetBillDrFeeStatus(op_other.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_other.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLDUIDR,I.TTLCR,I.TTLINVCR,I.TTLDUICR "); strSql.Append(",SALECORPID,(select [NAME] from [company] where GID=op_other.SALECORPID) as SALECORP,CLOSINGDATE,CLOSEDOCDATE,SALEDEPT,CUSTOMSER,WAREHOUSE,COUNTRYOFORIGIN"); strSql.Append(",(SELECT COUNT(*) FROM OP_AMEND WHERE PARENTID = op_other.BSNO) as AMENDCOUNT"); strSql.Append(",IsService1,IsService2,IsService3,IsService4,IsService5,IsService6,IsService7,IsService8,IsService9,IsService10,IsService11,IsService12,IsService13,IsService14,IsService15,IsService16,op_other.BillFeeStatus FROM op_other"); strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_other.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num", start, start + limit)); // return SetData(strSql.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 op_other "); strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_other.BSNO) "); 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 string GetDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } // String strSql = "SELECT BSNO, OPLB, OPLBNAME, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF, CUSTNO, MBLNO, HBLNO, CONTRACTNO, CUSTOMERNAME, CONVERT(char(10), BSDATE, 20) as BSDATE,"; strSql = strSql +"ACCDATE, BSSOURCE, BSSOURCEDETAIL, OP, CUSTSERVICE, SALE,FRCUSTSERVICE, CORPID, TRANSTYPE, VESSEL, VOYNO, CONVERT(char(10), ETD, 20) as ETD, PORTLOAD, PORTDISCHARGE, TRADETYPE, GOODSNAME, KGS, NETWEIGHT, PKGS, KINDPKGS, CBM,CTNALL,CTNNUM,ISVOU, VOUNO, REMARK, (select top 1 showname from [user] where GID=op_other.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_other.MODIFIEDUSER) as MODIFIEDUSER, MODIFIEDTIME, ORDERNO,OPERATOR,STLNAME,STLDATE,ENTERP,BOOKNO "; strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=SALECORPID) as SALECORP,CLOSINGDATE,CLOSEDOCDATE,SALEDEPT,CUSTOMSER,WAREHOUSE,COUNTRYOFORIGIN"; strSql = strSql + ",(SELECT COUNT(*) FROM OP_AMEND WHERE PARENTID = op_other.BSNO) as AMENDCOUNT"; strSql = strSql + ",IsService1,IsService2,IsService3,IsService4,IsService5,IsService6,IsService7,IsService8,IsService9,IsService10,IsService11,IsService12,IsService13,IsService14,IsService15,IsService16,dbo.F_GetBillDrFeeStatus(op_other.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_other.BSNO) CRFEESTATUS,ISPRINTPR FROM op_other"; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by BSDATE desc"; } return strSql.ToString(); } static public MsOpOtherEntity GetData(string condition) { String strSql = "SELECT BSNO, OPLB, OPLBNAME, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF, CUSTNO, MBLNO, HBLNO, CONTRACTNO, CUSTOMERNAME, CONVERT(char(10), BSDATE, 20) as BSDATE"; strSql = strSql + ", ACCDATE, BSSOURCE, BSSOURCEDETAIL, OP, CUSTSERVICE,FRCUSTSERVICE, SALE, CORPID, TRANSTYPE, VESSEL, VOYNO, CONVERT(char(10), ETD, 20) as ETD, PORTLOAD, PORTDISCHARGE, TRADETYPE, GOODSNAME, KGS, NETWEIGHT, PKGS, KINDPKGS, CBM,CTNALL,CTNNUM, ISVOU, VOUNO, REMARK, (select top 1 showname from [user] where GID=op_other.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_other.MODIFIEDUSER) as MODIFIEDUSER, MODIFIEDTIME, ORDERNO,OPERATOR,STLNAME,STLDATE,ENTERP,BOOKNO "; strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=SALECORPID) as SALECORP,CLOSINGDATE,CLOSEDOCDATE,SALEDEPT,CUSTOMSER,WAREHOUSE,COUNTRYOFORIGIN"; strSql = strSql + ",(SELECT COUNT(*) FROM OP_AMEND WHERE PARENTID = op_other.BSNO) as AMENDCOUNT"; strSql = strSql + ",IsService1,IsService2,IsService3,IsService4,IsService5,IsService6,IsService7,IsService8,IsService9,IsService10,IsService11,IsService12,IsService13,IsService14,IsService15,IsService16,'' DRFEESTATUS,'' CRFEESTATUS,ISPRINTPR,0 TTLDR,0 TTLINVDR,0 TTLDUIDR,0 TTLCR,0 TTLINVCR,0 TTLDUICR,BillFeeStatus FROM op_other"; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } var list=SetData(strSql); if (list.Count > 0) { return list[0]; } return new MsOpOtherEntity(); } private static List SetData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpOtherEntity data = new MsOpOtherEntity(); #region Set DB data to Object data.BillFeeStatus = Convert.ToString(reader["BillFeeStatus"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.OPLB = Convert.ToString(reader["OPLB"]); data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]); data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); data.FEESTATUS = Convert.ToBoolean(reader["FEESTATUS"]); data.BSSTATUSREF = Convert.ToString(reader["BSSTATUSREF"]); data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]); data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"])); data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"])); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.BSDATE = Convert.ToString(reader["BSDATE"]); //if (reader["BSDATE"] != DBNull.Value) // data.BSDATE = Convert.ToDateTime(reader["BSDATE"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]); data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]); data.OP = Convert.ToString(reader["OP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.FRCUSTSERVICE = Convert.ToString(reader["FRCUSTSERVICE"]); data.SALE = Convert.ToString(reader["SALE"]); data.SALEDEPT = Convert.ToString(reader["SALEDEPT"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.TRANSTYPE = Convert.ToString(reader["TRANSTYPE"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToString(reader["ETD"]); //if (reader["ETD"] != DBNull.Value) // data.ETD = Convert.ToDateTime(reader["ETD"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.TRADETYPE = Convert.ToString(reader["TRADETYPE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); if (reader["KGS"] != DBNull.Value) data.KGS = Convert.ToDecimal(reader["KGS"]); if (reader["NETWEIGHT"] != DBNull.Value) data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); if (reader["PKGS"] != DBNull.Value) data.PKGS = Convert.ToInt32(reader["PKGS"]); data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]); if (reader["CBM"] != DBNull.Value) data.CBM = Convert.ToDecimal(reader["CBM"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); if (reader["CTNNUM"] != DBNull.Value) data.CTNNUM = Convert.ToInt32(reader["CTNNUM"]); try { data.ISVOU = Convert.ToBoolean(reader["ISVOU"]); } catch (Exception e) { data.ISVOU = false; } data.VOUNO = Convert.ToString(reader["VOUNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]); data.ENTERP = Convert.ToString(reader["ENTERP"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.OPERATOR = Convert.ToString(reader["OPERATOR"]); data.STLNAME = Convert.ToString(reader["STLNAME"]); data.STLDATE = Convert.ToString(reader["STLDATE"]); data.BOOKNO = Convert.ToString(reader["BOOKNO"]); if (reader["AMENDCOUNT"] != DBNull.Value) data.AMEND = Convert.ToString(reader["AMENDCOUNT"]);//是否有更改单 data.IsSERVICE1 = Convert.ToString(reader["IsService1"]); data.IsSERVICE2 = Convert.ToString(reader["IsService2"]); data.IsSERVICE3 = Convert.ToString(reader["IsService3"]); data.IsSERVICE4 = Convert.ToString(reader["IsService4"]); data.IsSERVICE5 = Convert.ToString(reader["IsService5"]); data.IsSERVICE6 = Convert.ToString(reader["IsService6"]); data.IsSERVICE7 = Convert.ToString(reader["IsService7"]); data.IsSERVICE8 = Convert.ToString(reader["IsService8"]); data.IsSERVICE9 = Convert.ToString(reader["IsService9"]); data.IsSERVICE10 = Convert.ToString(reader["IsService10"]); data.IsSERVICE11 = Convert.ToString(reader["IsService11"]); data.IsSERVICE12 = Convert.ToString(reader["IsService12"]); data.IsSERVICE13 = Convert.ToString(reader["IsService13"]); data.IsSERVICE14 = Convert.ToString(reader["IsService14"]); data.IsSERVICE15 = Convert.ToString(reader["IsService15"]); data.IsSERVICE16 = Convert.ToString(reader["IsService16"]); data.ISPRINTPR = Convert.ToString(reader["ISPRINTPR"]); decimal ttldr = 0; if (reader["TTLDR"] != DBNull.Value) ttldr = Convert.ToDecimal(reader["TTLDR"]); decimal ttlinvdr = 0; if (reader["TTLDR"] != DBNull.Value) ttlinvdr = Convert.ToDecimal(reader["TTLINVDR"]); if (ttlinvdr == 0) data.DRINVSTATUS = "未开票"; else if (ttlinvdr == ttldr) data.DRINVSTATUS = "已开票"; else if (ttlinvdr != ttldr) data.DRINVSTATUS = "部分开票"; decimal ttlduidr = 0; if (reader["TTLDUIDR"] != DBNull.Value) ttlduidr = Convert.ToDecimal(reader["TTLDUIDR"]); if (ttlduidr == 0) data.DRDUISTATUS = "未对账"; else if (ttlduidr == ttldr) data.DRDUISTATUS = "已对账"; else if (ttlduidr != ttldr) data.DRDUISTATUS = "部分对账"; decimal ttlcr = 0; decimal ttlduicr = 0; if (reader["TTLCR"] != DBNull.Value) ttldr = Convert.ToDecimal(reader["TTLCR"]); decimal ttlinvcr = 0; if (reader["TTLINVCR"] != DBNull.Value) ttlinvcr = Convert.ToDecimal(reader["TTLINVCR"]); if (reader["TTLDUICR"] != DBNull.Value) ttlduicr = Convert.ToDecimal(reader["TTLDUICR"]); if (ttlinvcr == 0) data.CRINVSTATUS = "未开票"; else if (ttlinvcr == ttlcr) data.CRINVSTATUS = "已开票"; else if (ttlinvcr != ttlcr) data.CRINVSTATUS = "部分开票"; if (ttlduicr == 0) data.CRDUISTATUS = "未对账"; else if (ttlduicr == ttldr) data.CRDUISTATUS = "已对账"; else if (ttlduicr != ttldr) data.CRDUISTATUS = "部分对账"; data.SALECORPID = Convert.ToString(reader["SALECORPID"]);//分公司代码 data.SALECORP = Convert.ToString(reader["SALECORP"]);//分公司代码 if (reader["CLOSINGDATE"] != DBNull.Value) data.CLOSINGDATE = Convert.ToDateTime(reader["CLOSINGDATE"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 if (reader["CLOSEDOCDATE"] != DBNull.Value) data.CLOSEDOCDATE = Convert.ToDateTime(reader["CLOSEDOCDATE"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 data.CUSTOMSER = Convert.ToString(reader["CUSTOMSER"]);//分公司代码 data.WAREHOUSE = Convert.ToString(reader["WAREHOUSE"]);//分公司代码 data.COUNTRYOFORIGIN = Convert.ToString(reader["COUNTRYOFORIGIN"]);//分公司代码 #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 "部分提交"; } else if (feestatusint.IndexOf("6:") > -1) { return "驳回提交"; } else if (feestatusint.IndexOf("7:") > -1) { return "驳回申请"; } return result; } static public List GetDataListSum(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } // var strSql = new StringBuilder(); strSql.Append("SELECT Count(BSNO) as NOBILL,SUM(CASE LEFT(CTNALL,2) WHEN '40' THEN CTNNUM*2 ELSE CTNNUM END) TEU"); strSql.Append(",sum(CASE IsService1 WHEN '1' THEN 1 ELSE 0 END) as SERVICE1,sum(CASE IsService2 WHEN '1' THEN 1 ELSE 0 END) as SERVICE2"); strSql.Append(",sum(CASE IsService3 WHEN '1' THEN 1 ELSE 0 END) as SERVICE3,sum(CASE IsService4 WHEN '1' THEN 1 ELSE 0 END) as SERVICE4"); strSql.Append(",sum(CASE IsService5 WHEN '1' THEN 1 ELSE 0 END) as SERVICE5,sum(CASE IsService6 WHEN '1' THEN 1 ELSE 0 END) as SERVICE6"); strSql.Append(",sum(CASE IsService7 WHEN '1' THEN 1 ELSE 0 END) as SERVICE7,sum(CASE IsService8 WHEN '1' THEN 1 ELSE 0 END) as SERVICE8"); strSql.Append(",sum(CASE IsService9 WHEN '1' THEN 1 ELSE 0 END) as SERVICE9,sum(CASE IsService10 WHEN '1' THEN 1 ELSE 0 END) as SERVICE10"); strSql.Append(",sum(CASE IsService11 WHEN '1' THEN 1 ELSE 0 END) as SERVICE11,sum(CASE IsService12 WHEN '1' THEN 1 ELSE 0 END) as SERVICE12"); strSql.Append(",sum(CASE IsService13 WHEN '1' THEN 1 ELSE 0 END) as SERVICE13,sum(CASE IsService14 WHEN '1' THEN 1 ELSE 0 END) as SERVICE14"); strSql.Append(",sum(CASE IsService15 WHEN '1' THEN 1 ELSE 0 END) as SERVICE15,sum(CASE IsService16 WHEN '1' THEN 1 ELSE 0 END) as SERVICE16"); strSql.Append(" from op_other "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetDataSum(strSql); } private static List SetDataSum(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpApplySum data = new MsOpApplySum(); #region Set DB data to Object if (reader["NOBILL"] != DBNull.Value) data.NOBILL = Convert.ToInt32(reader["NOBILL"]);//票数 if (reader["TEU"] != DBNull.Value) data.TEU = Convert.ToInt32(reader["TEU"]);//TEU if (reader["SERVICE1"] != DBNull.Value) data.SERVICE1 = Convert.ToInt32(reader["SERVICE1"]);//箱型1 if (reader["SERVICE2"] != DBNull.Value) data.SERVICE2 = Convert.ToInt32(reader["SERVICE2"]);//箱型2 if (reader["SERVICE3"] != DBNull.Value) data.SERVICE3 = Convert.ToInt32(reader["SERVICE3"]);//箱型3 if (reader["SERVICE4"] != DBNull.Value) data.SERVICE4 = Convert.ToInt32(reader["SERVICE4"]);//箱型4 if (reader["SERVICE5"] != DBNull.Value) data.SERVICE5 = Convert.ToInt32(reader["SERVICE5"]);//箱型5 if (reader["SERVICE6"] != DBNull.Value) data.SERVICE6 = Convert.ToInt32(reader["SERVICE6"]);//箱型6 if (reader["SERVICE7"] != DBNull.Value) data.SERVICE7 = Convert.ToInt32(reader["SERVICE7"]);//箱型7 if (reader["SERVICE8"] != DBNull.Value) data.SERVICE8 = Convert.ToInt32(reader["SERVICE8"]);//箱型8 if (reader["SERVICE9"] != DBNull.Value) data.SERVICE9 = Convert.ToInt32(reader["SERVICE9"]);//箱型9 if (reader["SERVICE10"] != DBNull.Value) data.SERVICE10 = Convert.ToInt32(reader["SERVICE10"]);//箱型10 if (reader["SERVICE11"] != DBNull.Value) data.SERVICE11 = Convert.ToInt32(reader["SERVICE11"]);//箱型1 if (reader["SERVICE12"] != DBNull.Value) data.SERVICE12 = Convert.ToInt32(reader["SERVICE12"]);//箱型2 if (reader["SERVICE13"] != DBNull.Value) data.SERVICE13 = Convert.ToInt32(reader["SERVICE13"]);//箱型3 if (reader["SERVICE14"] != DBNull.Value) data.SERVICE14 = Convert.ToInt32(reader["SERVICE14"]);//箱型4 if (reader["SERVICE15"] != DBNull.Value) data.SERVICE15 = Convert.ToInt32(reader["SERVICE15"]);//箱型5 if (reader["SERVICE16"] != DBNull.Value) data.SERVICE16 = Convert.ToInt32(reader["SERVICE16"]);//箱型6 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 明细表 public static DBResult DeleteDetail(MsOpOtherEntity headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdDelete = db.GetSqlStringCommand("delete from op_other_detail where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDelete, tran); cmdDelete = db.GetSqlStringCommand("delete from op_other_service where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDelete, tran); cmdDelete = db.GetSqlStringCommand("delete from op_other_service_detail where BSNO='" + headData.BSNO + "'"); db.ExecuteNonQuery(cmdDelete, tran); 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 getCodeRule(string strRULENAME, int strRULETYPE, string strfield, string strETD, string strACCDATE, string strUserID, string strCompanyID) { //调用编码规则 if (strETD.Trim().IndexOf("0001") > -1) { strETD = ""; } string strRULEYEAR = ""; string strRULECONTENT = ""; string strCODENAME = ""; string strDEPTNO = ""; string strRULENOLENGTH = ""; int iRULENOLENGTH = 0; int inum = 0; string strCONTENT = ""; T_ALL_DA T_ALL_DA = new T_ALL_DA(); // DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=" + strRULETYPE); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True")) { if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期")) { if (strETD.Trim() == "") { return ""; } DateTime dETD = System.Convert.ToDateTime(strETD.Trim()); if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True")) { if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4") { strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM"); } else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2") { strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM"); } } else { if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4") { strRULEYEAR = dETD.ToString("yyyy"); } else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2") { strRULEYEAR = dETD.ToString("yy"); } } } else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("会计期间")) { if (strACCDATE.Trim() == "") { return ""; } DateTime dACCDATE = System.Convert.ToDateTime(strACCDATE.Trim() + "-01"); if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True")) { if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4") { strRULEYEAR = dACCDATE.ToString("yyyy") + dACCDATE.ToString("MM"); } else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2") { strRULEYEAR = dACCDATE.ToString("yy") + dACCDATE.ToString("MM"); } } else { if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4") { strRULEYEAR = dACCDATE.ToString("yyyy"); } else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2") { strRULEYEAR = dACCDATE.ToString("yy"); } } } else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份")) { DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()")); if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True")) { if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4") { strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM"); } else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2") { strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM"); } } else { if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4") { strRULEYEAR = fwqdate.ToString("yyyy"); } else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2") { strRULEYEAR = fwqdate.ToString("yy"); } } } // if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True")) { strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID.Trim() + "')"); } if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True")) { strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID.Trim() + "')"); } strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim(); strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME); strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO); // iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim()); strCONTENT = strRULECONTENT + strRULEYEAR; //获取分公司的票号头字符 string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'"); strCONTENT = tempBANKSHEAD + strCONTENT; // strRULENOLENGTH = T_ALL_DA.GetStrSQL(strfield, "select top 1 " + strfield + " from [op_other] where " + strfield + " like '" + strCONTENT.Trim() + "%' order by " + strfield + " DESC"); if (strRULENOLENGTH == "") { strRULENOLENGTH = "1"; } else { strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), ""); inum = int.Parse(strRULENOLENGTH.Trim()); inum = inum + 1; strRULENOLENGTH = inum.ToString(); } int j = iRULENOLENGTH - strRULENOLENGTH.Length; for (int i = 1; i <= j; i++) { strRULENOLENGTH = "0" + strRULENOLENGTH; } // strCONTENT = strCONTENT + strRULENOLENGTH; return strCONTENT; } } } return ""; } #endregion #region 判断编码是否有重复 static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" Count(BSNO) AS CT "); strSql.Append(" from op_other "); 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; } #endregion #region 判断是否有FEE public static bool GetFeeCount(string BSNO) { var isfee = false; String strSql = "Select count(*) as count from ch_fee where BSNO='" + BSNO + "'"; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } #endregion #region 委托业务费用加锁 /// /// 委托业务费用加锁 /// /// 委托业务编号 /// 值等于1表示加锁成功 值不等于1表示加锁失败 public static int LockFeeStatus(string tempBSNO) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@BSNO",SqlDbType.VarChar,100) }; parms[0].Value = tempBSNO; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "UPDATE op_other SET FEESTATUS = 1 WHERE BSNO = @BSNO", parms); sqlTran.Commit(); iResult = 1;//状态为1表示更新成功 } catch (Exception execError) { iResult = -1;//有异常,更新失败 sqlTran.Rollback(); iResult = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } #endregion #region 委托业务费用解锁 /// /// 委托业务费用解锁 /// /// 委托业务编号 /// 值等于1表示解锁成功 值不等于1表示解锁失败 public static int UnLockFeeStatus(string tempBSNO) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@BSNO",SqlDbType.VarChar,100) }; parms[0].Value = tempBSNO; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "UPDATE op_other SET FEESTATUS =0 WHERE BSNO = @BSNO", parms); sqlTran.Commit(); iResult = 1;//状态为1表示更新成功 } catch (Exception execError) { iResult = -1;//有异常,更新失败 sqlTran.Rollback(); iResult = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } #endregion #region 服务费用生成 static public MsOpFeeService GetFeeService(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("IsServiceFee1,IsServiceFee2,IsServiceFee3,IsServiceFee4,IsServiceFee5,IsServiceFee6,IsServiceFee7,IsServiceFee8"); strSql.Append(",IsServiceFee9,IsServiceFee10,IsServiceFee11,IsServiceFee12,IsServiceFee13,IsServiceFee14,IsServiceFee15,IsServiceFee16"); strSql.Append(",IsSERVICE1,IsSERVICE2,IsSERVICE3,IsSERVICE4,IsSERVICE5,IsSERVICE6,IsSERVICE7,IsSERVICE8"); strSql.Append(",IsSERVICE9,IsSERVICE10,IsSERVICE11,IsSERVICE12,IsSERVICE13,IsSERVICE14,IsSERVICE15,IsSERVICE16"); strSql.Append(" from OP_OTHER "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpFeeService data = new MsOpFeeService(); #region Set DB data to Object if (reader["IsSERVICEFEE1"] != DBNull.Value) data.IsSERVICEFEE1 = Convert.ToString(reader["IsServiceFee1"]); if (reader["IsSERVICEFEE2"] != DBNull.Value) data.IsSERVICEFEE2 = Convert.ToString(reader["IsServiceFee2"]); if (reader["IsSERVICEFEE3"] != DBNull.Value) data.IsSERVICEFEE3 = Convert.ToString(reader["IsServiceFee3"]); if (reader["IsSERVICEFEE4"] != DBNull.Value) data.IsSERVICEFEE4 = Convert.ToString(reader["IsServiceFee4"]); if (reader["IsSERVICEFEE5"] != DBNull.Value) data.IsSERVICEFEE5 = Convert.ToString(reader["IsServiceFee5"]); if (reader["IsSERVICEFEE6"] != DBNull.Value) data.IsSERVICEFEE6 = Convert.ToString(reader["IsServiceFee6"]); if (reader["IsSERVICEFEE7"] != DBNull.Value) data.IsSERVICEFEE7 = Convert.ToString(reader["IsServiceFee7"]); if (reader["IsSERVICEFEE8"] != DBNull.Value) data.IsSERVICEFEE8 = Convert.ToString(reader["IsServiceFee8"]); if (reader["IsSERVICEFEE9"] != DBNull.Value) data.IsSERVICEFEE9 = Convert.ToString(reader["IsServiceFee9"]); if (reader["IsSERVICEFEE10"] != DBNull.Value) data.IsSERVICEFEE10 = Convert.ToString(reader["IsServiceFee10"]); if (reader["IsSERVICEFEE11"] != DBNull.Value) data.IsSERVICEFEE11 = Convert.ToString(reader["IsServiceFee11"]); if (reader["IsSERVICEFEE12"] != DBNull.Value) data.IsSERVICEFEE12 = Convert.ToString(reader["IsServiceFee12"]); if (reader["IsSERVICEFEE13"] != DBNull.Value) data.IsSERVICEFEE13 = Convert.ToString(reader["IsServiceFee13"]); if (reader["IsSERVICEFEE14"] != DBNull.Value) data.IsSERVICEFEE14 = Convert.ToString(reader["IsServiceFee14"]); if (reader["IsSERVICEFEE15"] != DBNull.Value) data.IsSERVICEFEE15 = Convert.ToString(reader["IsServiceFee15"]); if (reader["IsSERVICEFEE16"] != DBNull.Value) data.IsSERVICEFEE16 = Convert.ToString(reader["IsServiceFee16"]); if (reader["IsSERVICE1"] != DBNull.Value) data.IsSERVICE1 = Convert.ToString(reader["IsSERVICE1"]); if (reader["IsSERVICE2"] != DBNull.Value) data.IsSERVICE2 = Convert.ToString(reader["IsSERVICE2"]); if (reader["IsSERVICE3"] != DBNull.Value) data.IsSERVICE3 = Convert.ToString(reader["IsSERVICE3"]); if (reader["IsSERVICE4"] != DBNull.Value) data.IsSERVICE4 = Convert.ToString(reader["IsSERVICE4"]); if (reader["IsSERVICE5"] != DBNull.Value) data.IsSERVICE5 = Convert.ToString(reader["IsSERVICE5"]); if (reader["IsSERVICE6"] != DBNull.Value) data.IsSERVICE6 = Convert.ToString(reader["IsSERVICE6"]); if (reader["IsSERVICE7"] != DBNull.Value) data.IsSERVICE7 = Convert.ToString(reader["IsSERVICE7"]); if (reader["IsSERVICE8"] != DBNull.Value) data.IsSERVICE8 = Convert.ToString(reader["IsSERVICE8"]); if (reader["IsSERVICE9"] != DBNull.Value) data.IsSERVICE9 = Convert.ToString(reader["IsSERVICE9"]); if (reader["IsSERVICE10"] != DBNull.Value) data.IsSERVICE10 = Convert.ToString(reader["IsSERVICE10"]); if (reader["IsSERVICE11"] != DBNull.Value) data.IsSERVICE11 = Convert.ToString(reader["IsSERVICE11"]); if (reader["IsSERVICE12"] != DBNull.Value) data.IsSERVICE12 = Convert.ToString(reader["IsSERVICE12"]); if (reader["IsSERVICE13"] != DBNull.Value) data.IsSERVICE13 = Convert.ToString(reader["IsSERVICE13"]); if (reader["IsSERVICE14"] != DBNull.Value) data.IsSERVICE14 = Convert.ToString(reader["IsSERVICE14"]); if (reader["IsSERVICE15"] != DBNull.Value) data.IsSERVICE15 = Convert.ToString(reader["IsSERVICE15"]); if (reader["IsSERVICE16"] != DBNull.Value) data.IsSERVICE16 = Convert.ToString(reader["IsSERVICE16"]); #endregion bodyList.Add(data); } reader.Close(); } if (bodyList.Count > 0) return bodyList[0]; return new MsOpFeeService(); } public static List GetENTERPLIST() { var strSql = new StringBuilder(); strSql.Append("SELECT distinct ENTERP,'' ENTERPID from op_other WHERE ENTERP<>'' ORDER BY ENTERP"); Database db = DatabaseFactory.CreateDatabase(); var evList = new List(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ENTERP Data = new ENTERP(); Data.ENTERPID = Convert.ToString(reader["ENTERPID"]); Data.CUSTOMER = Convert.ToString(reader["ENTERP"]); evList.Add(Data); } reader.Close(); } return evList; } #region 服务费用生成 public static DBResult PiliangServiceFee(List billList, List feeList, string userid) { 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(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO) "); var cmdInsertFeeDo = db.GetSqlStringCommand( @"insert into ch_fee_do_service (GID, TEMPLATEID,TEMPLATEFEEID,BSNO,FEEID) values (@GID,@TEMPLATEID,@TEMPLATEFEEID,@BSNO,@FEEID) "); var TEMPLATEID = ""; if (feeList != null) { foreach (var enumFee in feeList) { TEMPLATEID = enumFee.TemplateID; } } if (billList != null) { foreach (var enumValue in billList) { var applyfee = GetFeeService("BSNO='" + enumValue.BSNO + "'"); var feedostr = ""; if (applyfee.IsSERVICE1 == "1") if (feedostr == "") feedostr = " OPField='SERVICE1' "; else feedostr = feedostr + " or OPField='SERVICE1' "; if (applyfee.IsSERVICE2 == "1") if (feedostr == "") feedostr = " OPField='SERVICE2' "; else feedostr = feedostr + " or OPField='SERVICE2' "; if (applyfee.IsSERVICE3 == "1") if (feedostr == "") feedostr = " OPField='SERVICE3' "; else feedostr = feedostr + " or OPField='SERVICE3' "; if (applyfee.IsSERVICE4 == "1") if (feedostr == "") feedostr = " OPField='SERVICE4' "; else feedostr = feedostr + " or OPField='SERVICE4' "; if (applyfee.IsSERVICE5 == "1") if (feedostr == "") feedostr = " OPField='SERVICE5' "; else feedostr = feedostr + " or OPField='SERVICE5' "; if (applyfee.IsSERVICE6 == "1") if (feedostr == "") feedostr = " OPField='SERVICE6' "; else feedostr = feedostr + " or OPField='SERVICE6' "; if (applyfee.IsSERVICE7 == "1") if (feedostr == "") feedostr = " OPField='SERVICE7' "; else feedostr = feedostr + " or OPField='SERVICE7' "; if (applyfee.IsSERVICE8 == "1") if (feedostr == "") feedostr = " OPField='SERVICE8' "; else feedostr = feedostr + " or OPField='SERVICE8' "; if (applyfee.IsSERVICE9 == "1") if (feedostr == "") feedostr = " OPField='SERVICE9' "; else feedostr = feedostr + " or OPField='SERVICE9' "; if (applyfee.IsSERVICE10 == "1") if (feedostr == "") feedostr = " OPField='SERVICE10' "; else feedostr = feedostr + " or OPField='SERVICE10' "; if (applyfee.IsSERVICE11 == "1") if (feedostr == "") feedostr = " OPField='SERVICE11' "; else feedostr = feedostr + " or OPField='SERVICE11' "; if (applyfee.IsSERVICE12 == "1") if (feedostr == "") feedostr = " OPField='SERVICE12' "; else feedostr = feedostr + " or OPField='SERVICE12' "; if (applyfee.IsSERVICE13 == "1") if (feedostr == "") feedostr = " OPField='SERVICE13' "; else feedostr = feedostr + " or OPField='SERVICE13' "; if (applyfee.IsSERVICE14 == "1") if (feedostr == "") feedostr = " OPField='SERVICE14' "; else feedostr = feedostr + " or OPField='SERVICE14' "; if (applyfee.IsSERVICE15 == "1") if (feedostr == "") feedostr = " OPField='SERVICE15' "; else feedostr = feedostr + " or OPField='SERVICE15' "; if (applyfee.IsSERVICE16 == "1") if (feedostr == "") feedostr = " OPField='SERVICE16' "; else feedostr = feedostr + " or OPField='SERVICE16' "; if (feedostr != "") feedostr = "(" + feedostr + ")"; if (feedostr != "") { feedostr=feedostr+" and TEMPLATEID='"+TEMPLATEID+"' and GID not in (select TEMPLATEFEEID from ch_fee_do_service where BSNO='"+enumValue.BSNO+"')"; var feelist2 = MsCodeServiceFeeTemplateDAL.MsCodeServiceFeeTemplateDAL.GetBodyListtran(feedostr,db,tran); if (feelist2 != null) { foreach (var enumFee in feelist2) { var taxamount = Math.Round(enumFee.UnitPrice * (1 + (enumFee.TAXRATE / 100)), 2); var FEEID= Guid.NewGuid().ToString(); cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, FEEID); db.AddInParameter(cmdInsert, "@bsno", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsert, "@fee_type", DbType.String, enumFee.FeeType); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, enumFee.FeeName); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, ""); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, enumFee.CustomerType); if (enumFee.CustomerName != "") db.AddInParameter(cmdInsert, "@customer_name", DbType.String, enumFee.CustomerName); else if (enumFee.CustomerType == "委托单位") { db.AddInParameter(cmdInsert, "@customer_name", DbType.String, enumValue.CUSTOMERNAME); } else db.AddInParameter(cmdInsert, "@customer_name", DbType.String, ""); db.AddInParameter(cmdInsert, "@unit", DbType.String, enumFee.Unit); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, enumFee.UnitPrice); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, taxamount); db.AddInParameter(cmdInsert, "@currency", DbType.String, enumFee.Currency); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, enumFee.ExchangeRate); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); db.AddInParameter(cmdInsert, "@remark", DbType.String, ""); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.DateTime, DateTime.Now); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 2); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, enumFee.TAXRATE); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, enumFee.UnitPrice); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 2); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, taxamount); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, ""); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.DateTime, null); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.ExecuteNonQuery(cmdInsert, tran); cmdInsertFeeDo.Parameters.Clear(); db.AddInParameter(cmdInsertFeeDo, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsertFeeDo, "@TEMPLATEID", DbType.String, TEMPLATEID); db.AddInParameter(cmdInsertFeeDo, "@TEMPLATEFEEID", DbType.String, enumFee.GID); db.AddInParameter(cmdInsertFeeDo, "@BSNO", DbType.String,enumValue.BSNO); db.AddInParameter(cmdInsertFeeDo, "@FEEID", DbType.String,FEEID); db.ExecuteNonQuery(cmdInsertFeeDo, tran); } } } } } tran.Commit(); result.Success = true; result.Message = "保存成功" + result.Message; return result; } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } #endregion #endregion #region EXCEL导入 public static bool ImportBldata(HttpRequestBase request, DataTable table, string userid, string companyid, out string msg, string username) { var isSucess = false; msg = ""; if (table == null) throw new ArgumentNullException("table"); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); Database db = DatabaseFactory.CreateDatabase(); using (DbConnection connection = db.CreateConnection()) { connection.Open(); DbTransaction idbTran = connection.BeginTransaction(); try { foreach (DataRow row in table.Rows) { var BSNO = ""; var CUSTCODE = Convert.ToString(row["パートナー"]); var HBLNO = Convert.ToString(row["H B/L NO"]); var MBLNO = Convert.ToString(row["M BL NO"]); var ETD = Convert.ToString(row["ETD"]); var CUSTNAME = T_ALL_DA.GetStrSQL("SHORTNAME", "select top 1 SHORTNAME from info_client where CODENAME='" + CUSTCODE + "'"); if (MBLNO != "") { var YEAR = DateTime.Now.ToString("yyyy"); var MONTHDAY = ETD; var MONTH = MONTHDAY.Substring(0, MONTHDAY.IndexOf(".")); var DAY = MONTHDAY.Substring(MONTHDAY.IndexOf(".") + 1, MONTHDAY.Length - MONTHDAY.IndexOf(".") - 1); if (MONTH.Length == 1) MONTH = "0" + MONTH; if (DAY.Length == 1) DAY = "0" + DAY; var BSETD = YEAR + "-" + MONTH + "-" + DAY; #region 托单数据生成 var headData = new MsOpOtherEntity(); headData.CORPID = companyid; BSNO = "topother" + Guid.NewGuid().ToString().Replace("-", ""); headData.BSNO = BSNO; headData.CUSTOMERNAME = CUSTNAME; headData.MBLNO = MBLNO; headData.HBLNO = HBLNO; headData.VESSEL = Convert.ToString(row["VESSEL&VOYAGE"]); headData.PORTDISCHARGE = Convert.ToString(row["港"]); headData.PKGS = Convert.ToInt32(row["PACKAGE"]); headData.KGS = Convert.ToDecimal(row["WEIGHT"]); headData.CBM = Convert.ToDecimal(row["MEASURE"]); headData.REMARK = Convert.ToString(row["担当者"]); headData.ETD = BSETD; headData.BSDATE = DateTime.Now.ToString("yyyy-MM-dd"); headData.ACCDATE = DateTime.Now.ToString("yyyy-MM"); var iResult = 0; var isuse = false; var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='综合业务'", companyid); if (billnoset.BILLTYPE != "") isuse = true; if (headData.CUSTNO == "") { if (isuse) { if (billnoset.BILLTYPE != "") { headData.CUSTNO = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.ETD.ToString().Trim(), headData.ACCDATE.ToString().Trim(), "", headData.OP); } else headData.CUSTNO = MsOpOtherDAL.getCodeRule("委托编号", 6, "CUSTNO", headData.BSDATE.ToString().Trim(), headData.ACCDATE.ToString().Trim(),userid,companyid); } } string rq = T_ALL_DA.GetStrSQL("rq", "select getdate() as rq"); headData.DbOperationType = DbOperationType.DbotIns; // headData.OPLB = "op_other";//业务类型 headData.OPLBNAME = "散杂运输";//业务类型名称 headData.BSSTATUS = false;//业务状态 headData.FEESTATUS = false;//费用状态 headData.ISVOU = false;//是否生成凭证 headData.VOUNO = "";//凭证号 headData.CREATEUSER =userid;//创建人 headData.CREATETIME = DateTime.Parse(rq);//创建时间 headData.MODIFIEDUSER =userid;//最后一次操作人 headData.MODIFIEDTIME = DateTime.Parse(rq);//最后一次操作时间 headData.OP = username; var modb = new ModelObjectDB(); DBResult result = modb.Save(headData); var headList = new List(); var THYF = Convert.ToString(row["ドル支払い"]); if (THYF != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "退海运费"; data.CustomerType = "委托单位"; data.CustomerName = CUSTNAME; data.Unit ="票"; data.UnitPrice = Convert.ToDecimal(THYF); data.Quantity = 1; data.Amount = Convert.ToDecimal(THYF); data.Currency = "USD"; data.ExChangerate = MsChFeeDAL.MsChFeeDAL.GetFeeNowCurr(companyid,"USD",BSETD,"2"); data.EnteroPerator =userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 1; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(THYF); data.TaxUnitPrice = Convert.ToDecimal(THYF); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "JPY"; data.Remark = ""; headList.Add(data); } var THYFJPY = Convert.ToString(row["円支払い"]); if (THYFJPY != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "退海运费"; data.CustomerType = "委托单位"; data.CustomerName = CUSTNAME; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(THYFJPY); data.Quantity = 1; data.Amount = Convert.ToDecimal(THYFJPY); data.Currency = "JPY"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 1; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(THYFJPY); data.TaxUnitPrice = Convert.ToDecimal(THYFJPY); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "JPY"; data.Remark = ""; headList.Add(data); } var HAN = Convert.ToString(row["H A/N請求"]); if (HAN != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 1; data.FeeName = "收日本客户费用"; data.CustomerType = ""; data.CustomerName = "日本目的港换单应收"; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(HAN); data.Quantity = 1; data.Amount = Convert.ToDecimal(HAN); data.Currency = "JPY"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 1; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(HAN); data.TaxUnitPrice = Convert.ToDecimal(HAN); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "JPY"; data.Remark = ""; headList.Add(data); } var XFS = Convert.ToString(row["消費税"]); if (XFS != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "消费税"; data.CustomerType = ""; data.CustomerName = "日本政府"; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(XFS); data.Quantity = 1; data.Amount = Convert.ToDecimal(XFS); data.Currency = "JPY"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 1; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(XFS); data.TaxUnitPrice = Convert.ToDecimal(XFS); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "JPY"; data.Remark = ""; headList.Add(data); } var MAN = Convert.ToString(row["M A/N支払い"]); if (MAN != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "付日本船公司费用"; data.CustomerType = ""; data.CustomerName = "日本船公司"; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(MAN); data.Quantity = 1; data.Amount = Convert.ToDecimal(MAN); data.Currency = "JPY"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 1; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(MAN); data.TaxUnitPrice = Convert.ToDecimal(MAN); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "JPY"; data.Remark = ""; headList.Add(data); } if (headList != null) { iResult = MsChFeeDAL.MsChFeeDAL.SaveUpdateFee(headList, BSNO, userid); } #endregion } } idbTran.Commit(); isSucess = true; } catch (Exception exception) { idbTran.Rollback(); isSucess = false; msg = exception.Message; } } return isSucess; } public static bool ImportBlZhdata(HttpRequestBase request, DataTable table, string userid, string companyid, out string msg, string username) { var isSucess = false; msg = ""; if (table == null) throw new ArgumentNullException("table"); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); Database db = DatabaseFactory.CreateDatabase(); using (DbConnection connection = db.CreateConnection()) { connection.Open(); DbTransaction idbTran = connection.BeginTransaction(); var MBLNO = ""; try { foreach (DataRow row in table.Rows) { var BSNO = ""; var VESSEL = Convert.ToString(row["船名航次"]); MBLNO = Convert.ToString(row["提单号"]); var CNTRNO = Convert.ToString(row["箱号"]); var CNTRSIZE = Convert.ToString(row["箱型"]); var AMOUNT = Convert.ToString(row["收"]); var CUSTNAME = Convert.ToString(row["客户名称"]); var BSDATE = Convert.ToString(row["操作日期"]); if (MBLNO != "") { var head = GetData("MBLNO='"+MBLNO+"'"); decimal ttlamount = 0; if (head.MBLNO == "") { var BSETD = Convert.ToDateTime(BSDATE).ToString("yyyy-MM-dd"); #region 托单数据生成 var headData = new MsOpOtherEntity(); headData.CORPID = companyid; BSNO = "topother" + Guid.NewGuid().ToString().Replace("-", ""); headData.BSNO = BSNO; headData.CUSTOMERNAME = CUSTNAME; headData.MBLNO = MBLNO; headData.VESSEL = VESSEL; headData.REMARK = CNTRNO; headData.ETD = BSETD; headData.BSDATE = DateTime.Now.ToString("yyyy-MM-dd"); headData.ACCDATE = DateTime.Now.ToString("yyyy-MM"); var iResult = 0; var isuse = false; var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='综合业务'", companyid); if (billnoset.BILLTYPE != "") isuse = true; if (headData.CUSTNO == "") { if (isuse) { if (billnoset.BILLTYPE != "") { headData.CUSTNO = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.ETD.ToString().Trim(), headData.ACCDATE.ToString().Trim(), "", headData.OP); } else headData.CUSTNO = MsOpOtherDAL.getCodeRule("委托编号", 6, "CUSTNO", headData.BSDATE.ToString().Trim(), headData.ACCDATE.ToString().Trim(), userid, companyid); } } string rq = T_ALL_DA.GetStrSQL("rq", "select getdate() as rq"); headData.DbOperationType = DbOperationType.DbotIns; // headData.OPLB = "op_other";//业务类型 headData.OPLBNAME = "散杂运输";//业务类型名称 headData.BSSTATUS = false;//业务状态 headData.FEESTATUS = false;//费用状态 headData.ISVOU = false;//是否生成凭证 headData.VOUNO = "";//凭证号 headData.CREATEUSER = userid;//创建人 headData.CREATETIME = DateTime.Parse(rq);//创建时间 headData.MODIFIEDUSER = userid;//最后一次操作人 headData.MODIFIEDTIME = DateTime.Parse(rq);//最后一次操作时间 headData.OP = username; var modb = new ModelObjectDB(); DBResult result = modb.Save(headData); } else { BSNO = head.BSNO; head.REMARK = head.REMARK +" " +CNTRNO; head.DbOperationType = DbOperationType.DbotUpd; var modb = new ModelObjectDB(); DBResult result = modb.Save(head); } var headList = new List(); if (AMOUNT!= "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 1; data.FeeName = Convert.ToString(row["费用名称"]); data.CustomerType = "委托单位"; data.CustomerName = CUSTNAME; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(AMOUNT); data.Quantity = 1; data.Amount = Convert.ToDecimal(AMOUNT); data.Currency = "RMB"; data.ExChangerate =1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 0; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(AMOUNT); data.TaxUnitPrice = Convert.ToDecimal(AMOUNT); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "RMB"; data.Remark = ""; headList.Add(data); ttlamount = Convert.ToDecimal(AMOUNT); } var THYFJPY = Convert.ToString(row["付装卸队装卸费"]); if (THYFJPY != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "装卸费"; data.CustomerType = "委托单位"; data.CustomerName = Convert.ToString(row["装卸队名称"]); data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(THYFJPY); data.Quantity = 1; data.Amount = Convert.ToDecimal(THYFJPY); data.Currency = "RMB"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 0; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(THYFJPY); data.TaxUnitPrice = Convert.ToDecimal(THYFJPY); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "RMB"; data.Remark = ""; headList.Add(data); ttlamount = ttlamount - Convert.ToDecimal(THYFJPY); } var HAN = Convert.ToString(row["付YCY"]); if (HAN != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType =2; data.FeeName = "代理费"; data.CustomerType = ""; data.CustomerName = "宇畅洋"; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(HAN); data.Quantity = 1; data.Amount = Convert.ToDecimal(HAN); data.Currency = "RMB"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 0; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(HAN); data.TaxUnitPrice = Convert.ToDecimal(HAN); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "RMB"; data.Remark = ""; headList.Add(data); ttlamount = ttlamount - Convert.ToDecimal(HAN); } var XFS = Convert.ToString(row["付联华机械费"]); if (XFS != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "机械费"; data.CustomerType = ""; data.CustomerName = "联华"; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(XFS); data.Quantity = 1; data.Amount = Convert.ToDecimal(XFS); data.Currency = "RMB"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 0; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(XFS); data.TaxUnitPrice = Convert.ToDecimal(XFS); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "RMB"; data.Remark = ""; headList.Add(data); ttlamount = ttlamount - Convert.ToDecimal(XFS); } var MAN = Convert.ToString(row["付代理场站费"]); if (MAN != "0") { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "场站费"; data.CustomerType = ""; data.CustomerName =CUSTNAME; data.Unit = "票"; data.UnitPrice = Convert.ToDecimal(MAN); data.Quantity = 1; data.Amount = Convert.ToDecimal(MAN); data.Currency = "RMB"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 0; data.TaxRate = 0; data.NoTaxAmount = Convert.ToDecimal(MAN); data.TaxUnitPrice = Convert.ToDecimal(MAN); data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "RMB"; data.Remark = ""; headList.Add(data); ttlamount = ttlamount - Convert.ToDecimal(MAN); } if (ttlamount != 0) { MsChFee data = new MsChFee(); data.BsNo = "*"; data.GId = Guid.NewGuid().ToString(); data.FeeType = 2; data.FeeName = "装卸费"; data.CustomerType = ""; data.CustomerName = "振华"; data.Unit = "票"; data.UnitPrice = ttlamount; data.Quantity = 1; data.Amount = ttlamount; data.Currency = "RMB"; data.ExChangerate = 1; data.EnteroPerator = userid; data.IsOpen = "0"; data.IsAdvancedpay = "0"; data.FeeStatus = 0; data.TaxRate = 0; data.NoTaxAmount = ttlamount; data.TaxUnitPrice = ttlamount; data.AccTaxRate = 0; data.IsInvoice = "0"; data.LOCALCURR = "RMB"; data.Remark = ""; headList.Add(data); } if (headList != null) { MsChFeeDAL.MsChFeeDAL.SaveUpdateFee(headList, BSNO, userid); } #endregion } } idbTran.Commit(); isSucess = true; } catch (Exception exception) { idbTran.Rollback(); isSucess = false; msg = MBLNO+"---"+exception.Message; } } return isSucess; } #endregion #region Rang权限范围 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]='modOpOtherList' 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 CREATEUSER='" + userid + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')"; } else if (visiblerange == "3") { str = " (OP='" + username + "' OR CREATEUSER='" + userid + "' OR SALE='" + username + "' OR CUSTSERVICE='" + 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 CREATEUSER in (select GID 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 = " (UPPER(op_other.Corpid)='" + companyid + "' or op_other.SALECORPID='" + 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 = " (op_other.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or op_other.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "' "; } else { str = str + " or op_other.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' or op_other.SALECORPID='" + Convert.ToString(reader["COMPANYID"]) + "'"; }; } str = str + ")"; reader.Close(); } } else { str = " (UPPER(op_other.Corpid)='" + companyid + "') "; } } else if (visiblerange == "6") { if (tb == "index") { var opstr = ""; 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())) { while (reader.Read()) { if (opstr == "") { opstr = " ('" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { opstr = opstr + ",'" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; } if (opstr != "") opstr = opstr + ")"; reader.Close(); } if (opstr == "") opstr = "('" + username + "')"; str = " (OP in " + opstr + " or CREATEUSER in " + opstr + " or CUSTSERVICE IN " + opstr + " or SALE IN " + opstr + " )"; } else { str = " (UPPER(op_other.Corpid)='" + companyid + "') "; } } else if (visiblerange == "0") { str = " 1=1 "; } VSSQL = VSSQL.Trim(); if (!string.IsNullOrEmpty(VSSQL)) { if (!string.IsNullOrEmpty(str)) { str = str + " and (" + VSSQL + ") "; } else { str = " (" + VSSQL + ") "; } } return str; } #endregion #region 添加日志 public static DBResult setLog(MsOpOtherEntity modeldata, string strUserID) { DBResult result = new DBResult(); if (modeldata == null) { result.Success = false; result.Message = "没有输入任何需要修改的数据"; return result; } string OPLBNAME = modeldata.OPLBNAME.ToString(); string MBLNO = modeldata.MBLNO.ToString(); // Database db = DatabaseFactory.CreateDatabase(); using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { #region 把【仓储结算关联表wms_settlement_date】中数据【ISDELETE】设为【1】 string strSql = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除信息','删除操作','" + OPLBNAME + "主提单号:" + MBLNO + "','" + strUserID + "')"; int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null); #endregion sqlTran.Commit(); } catch (Exception) { sqlTran.Rollback(); result.Success = false; result.Message = "操作出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "操作数据成功"; return result; } #endregion } }