using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using HcUtility.Comm; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.OA.Models.WorkFlow; using DSWeb.Areas.CommMng.Models; using DSWeb.MvcShipping.Models.MsOpApply; using DSWeb.MvcShipping.Models.MsOpApplyService; using DSWeb.MvcShipping.Models.MsInfoClient; using DSWeb.MvcShipping.Models.MsCtExplan; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.TruckMng.Helper.Repository; using DSWeb.SoftMng.Models.MsInfoClass; using DSWeb.SoftMng.Models.MsInfoClientItem; namespace DSWeb.Areas.CommMng.DAL { public class TruckBasicDataRefDAL { #region 良通捷运 目的地列表 static public List GetDetiNation_LTJY(string strCondition, string strUserID) { var strSql = new StringBuilder(); strSql.Append("select DISTINCT NAME,DISTANCE from PC_LTJY_Distance where 1=1 "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetDetiNation_LTJY(strSql); } private static List SetDetiNation_LTJY(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { DICModel data = new DICModel(); #region Set DB data to Object data.KEYFIELD = (reader["NAME"] == null ? "" : Convert.ToString(reader["NAME"]));//惟一值 data.VALUEFIELD = (reader["DISTANCE"] == null ? "" : Convert.ToString(reader["DISTANCE"]));//惟一值 #endregion headList.Add(data); } #region 空白项 DICModel data2 = new DICModel(); data2.KEYFIELD = "";//惟一值 data2.VALUEFIELD = "0";//惟一值 #endregion headList.Add(data2); reader.Close(); } return headList; } #endregion #region 将带逗号的内容拆成单个,并将出现频率最高的放置在最前。参数为(表名 列名 查询条件) static public List GetCommaWord(string tablename, string columnname, string condition, string strUserID) { var strSql = new StringBuilder(); var column = " case isnull(" + columnname + ",'') when '' then '' else " + columnname + "+',' end "; strSql.Append(" WITH TB_2 AS ( "); strSql.Append(" SELECT " + column + " as " + columnname + " ,CHARINDEX(','," + column + ") STA,CHARINDEX(','," + column + ")-1 LENS FROM " + tablename + " where 1=1 "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" and " + condition); } strSql.Append(" UNION ALL "); strSql.Append(" SELECT " + columnname + " ,CHARINDEX(','," + columnname + ",STA+1) STA,CHARINDEX(','," + columnname + ",STA+1)-STA-1 LENS FROM TB_2 WHERE STA<>0) "); strSql.Append(" SELECT distinct SUBSTRING(" + columnname + ",STA-LENS,LENS) VALUE,count(SUBSTRING(" + columnname + ",STA-LENS,LENS)) count FROM TB_2 "); strSql.Append(" WHERE STA<>0 "); strSql.Append(" group by SUBSTRING(" + columnname + ",STA-LENS,LENS) "); strSql.Append(" order by count(SUBSTRING(" + columnname + ",STA-LENS,LENS)) DESC "); return SetCommaWord(strSql); } private static List SetCommaWord(StringBuilder strSql) { var headList = new List(); #region 空白项 DICModel data2 = new DICModel(); data2.KEYFIELD = "";//惟一值 data2.VALUEFIELD = "0";//惟一值 headList.Add(data2); #endregion Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { DICModel data = new DICModel(); #region Set DB data to Object data.KEYFIELD = (reader["VALUE"] == null ? "" : Convert.ToString(reader["VALUE"]));//惟一值 data.VALUEFIELD = (reader["count"] == null ? "" : Convert.ToString(reader["count"]));//惟一值 #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion } }