using System; using System.Data; using System.Collections.Generic; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using DSWeb.MvcShipping.Models.MsCodeFeeSetList; namespace DSWeb.MvcShipping.DAL.MsCodeFeeSetList { public class MsCodeFeeSetListDAL { static public List GetDataList (string strCondition,int start,int limit,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 A.CREATETIME DESC,A.GID"); } strSql.Append(@") as num , "); strSql.Append(@"A.GID, A.FEECODE, A.NAME, A.DEFAULTCURR, A.DESCRIPTION, ISSEA, ISAIR, ISTRUCKING, ISTRUCKINGFIXED, ISWMS, ISADVANCEDPAY, DEFAULTUNIT,ISNULL((case A.DEFAULTUNIT when 1 then '单票' when 2 then '重量' when 3 then '尺码' when 4 then '计费吨' when 5 then 'TEU' when 6 then '净重' when 7 then '总价' when 8 then '计价重量' when 9 then '箱型' when 10 then 'CBM' when 11 then 'BILL' end),'') DEFAULTUNITREF, DEFAULTDEBIT,ISNULL((case A.DEFAULTDEBIT when 1 then '船公司' when 2 then '订舱代理' when 3 then '场站' when 4 then '车队' when 5 then '委托单位' when 6 then '报关行' when 7 then '代理' when 8 then '航空公司' when 9 then '发货人' when 10 then '收货人' when 11 then '通知人' when 0 then '其他' end),'') DEFAULTDEBITREF, DEFAULTCREDIT,ISNULL((case A.DEFAULTCREDIT when 1 then '船公司' when 2 then '订舱代理' when 3 then '场站' when 4 then '车队' when 5 then '委托单位' when 6 then '报关行' when 7 then '代理' when 8 then '航空公司' when 9 then '发货人' when 10 then '收货人' when 11 then '通知人' when 12 then '船代' when 13 then '码头' when 0 then '其他' end),'') DEFAULTCREDITREF,A.CREATEUSER, B.SHOWNAME as CREATEUSERREF, A.CREATETIME , A.FEEGROUP,A.FEEFRT,A.TAXRATE,A.DUITYPE,A.GOODNAME "); strSql.Append(@"FROM code_fee as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where 1=1 and " + strCondition); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>={0} and t.num<={1} ",start,start+limit)); return SetData(strSql); } static public string GetDataListStr(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append(@"SELECT A.GID, A.FEECODE, A.NAME, A.DEFAULTCURR, A.DESCRIPTION, ISSEA, ISAIR, ISTRUCKING, ISTRUCKINGFIXED, ISWMS, ISADVANCEDPAY, DEFAULTUNIT,ISNULL((case A.DEFAULTUNIT when 1 then '单票' when 2 then '重量' when 3 then '尺码' when 4 then '计费吨' when 5 then 'TEU' when 6 then '净重' when 7 then '总价' when 8 then '计价重量' when 9 then '箱型' when 10 then 'CBM' when 11 then 'BILL' end),'') DEFAULTUNITREF, DEFAULTDEBIT,ISNULL((case A.DEFAULTDEBIT when 1 then '船公司' when 2 then '订舱代理' when 3 then '场站' when 4 then '车队' when 5 then '委托单位' when 6 then '报关行' when 7 then '代理' when 8 then '航空公司' when 9 then '发货人' when 10 then '收货人' when 11 then '通知人' when 0 then '其他' end),'') DEFAULTDEBITREF, DEFAULTCREDIT,ISNULL((case A.DEFAULTCREDIT when 1 then '船公司' when 2 then '订舱代理' when 3 then '场站' when 4 then '车队' when 5 then '委托单位' when 6 then '报关行' when 7 then '代理' when 8 then '航空公司' when 9 then '发货人' when 10 then '收货人' when 11 then '通知人' when 12 then '船代' when 13 then '码头' when 0 then '其他' end),'') DEFAULTCREDITREF,A.CREATEUSER, B.SHOWNAME as CREATEUSERREF, A.CREATETIME , A.FEEGROUP,A.FEEFRT,A.TAXRATE,A.DUITYPE,A.GOODNAME "); strSql.Append(@"FROM code_fee as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where 1=1 and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by A.CREATETIME DESC,A.GID"); } return strSql.ToString(); } static public int getTotalCount ( string strCondition ) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) from code_fee as A inner join [user] as B on A.createuser=B.gid "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where 1=1 and " + strCondition); } int cnt=0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } static public CodeFeeSetList GetData(string condition) { CodeFeeSetList data = null; var list = GetDataList(condition,0,1); if (list.Count > 0) data = list[0]; if (data == null) { data = new CodeFeeSetList(); } 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()) { CodeFeeSetList data = new CodeFeeSetList(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.FEECODE = Convert.ToString(reader["FEECODE"]); data.NAME = Convert.ToString(reader["NAME"]); data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]); data.DEFAULTCURR = Convert.ToString(reader["DEFAULTCURR"]); if (reader["ISSEA"] != DBNull.Value) data.ISSEA = Convert.ToBoolean(reader["ISSEA"]);//状态 if (reader["ISAIR"] != DBNull.Value) data.ISAIR = Convert.ToBoolean(reader["ISAIR"]);//状态 if (reader["ISTRUCKING"] != DBNull.Value) data.ISTRUCKING = Convert.ToBoolean(reader["ISTRUCKING"]);//状态 if (reader["ISTRUCKINGFIXED"] != DBNull.Value) data.ISTRUCKINGFIXED = Convert.ToBoolean(reader["ISTRUCKINGFIXED"]);//状态 if (reader["ISWMS"] != DBNull.Value) data.ISWMS = Convert.ToBoolean(reader["ISWMS"]);//状态 if (reader["ISADVANCEDPAY"] != DBNull.Value) data.ISADVANCEDPAY = Convert.ToBoolean(reader["ISADVANCEDPAY"]);//状态 data.DEFAULTUNIT = Convert.ToString(reader["DEFAULTUNIT"]); data.DEFAULTDEBIT = Convert.ToString(reader["DEFAULTDEBIT"]); data.DEFAULTCREDIT = Convert.ToString(reader["DEFAULTCREDIT"]); data.DEFAULTUNITREF = Convert.ToString(reader["DEFAULTUNITREF"]); data.DEFAULTDEBITREF = Convert.ToString(reader["DEFAULTDEBITREF"]); data.DEFAULTCREDITREF = Convert.ToString(reader["DEFAULTCREDITREF"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.FEEGROUP = Convert.ToString(reader["FEEGROUP"]); data.FEEFRT = Convert.ToString(reader["FEEFRT"]); data.TAXRATE = Convert.ToString(reader["TAXRATE"]); data.DUITYPE = Convert.ToString(reader["DUITYPE"]); data.GOODNAME = Convert.ToString(reader["GOODNAME"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static bool GetFeeCount(string FEENAME) { var isfee = false; var strSql = new StringBuilder(); strSql.Append("Select count(*) as count "); strSql.Append(" from ch_fee "); strSql.Append(" where FEENAME='" + FEENAME + "'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } public static bool GetCodeFeeCount(string strCondition) { var isfee = false; var strSql = new StringBuilder(); strSql.Append("Select count(*) as count "); strSql.Append(" from code_fee "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } } }