Esempio n. 1
0
        /// <summary>
        /// 给实体赋值
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="colName">列名</param>
        /// <param name="value">值</param>
        public void SetModelValue(DataAccess.Model.Rank model, string colName, object value)
        {
            if (model == null || string.IsNullOrEmpty(colName))
            {
                return;
            }

            //返回指定条件的实体
            switch (colName)
            {
            case "Id":
                model.Id = (long)value;
                break;

            case "RankLevel":
                model.RankLevel = (string)value;
                break;

            case "RankCName":
                model.RankCName = (string)value;
                break;

            case "RankEName":
                model.RankEName = (string)value;
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 给实体赋值
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="dic">列名与值</param>
        public void SetModelValue(DataAccess.Model.Rank model, Dictionary <string, object> dic)
        {
            if (model == null || dic == null)
            {
                return;
            }

            //遍历字典,逐个给字段赋值
            foreach (var d in dic)
            {
                SetModelValue(model, d.Key, d.Value);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 将Rank记录实体由普通的实体(DataAccess.Model.Rank)转换为SubSonic插件生成的实体
        /// </summary>
        /// <param name="model">普通的实体(DataAccess.Model.Rank)</param>
        /// <returns>Rank</returns>
        public Rank Transform(DataAccess.Model.Rank model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new Rank
            {
                Id = model.Id,

                RankLevel = model.RankLevel,

                RankCName = model.RankCName,

                RankEName = model.RankEName,
            });
        }
Esempio n. 4
0
        /// <summary>
        /// 更新IIS缓存中指定Id记录
        /// </summary>
        /// <param name="model">记录实体</param>
        public void SetModelForCache(DataAccess.Model.Rank model)
        {
            if (model == null)
            {
                return;
            }

            //从缓存中删除记录
            DelCache(model.Id);

            //从缓存中读取记录列表
            var list = GetList();

            if (list == null)
            {
                list = new List <DataAccess.Model.Rank>();
            }
            //添加记录
            list.Add(model);
        }
Esempio n. 5
0
        /// <summary>
        /// 返回实体中指定字段名的值
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="colName">获取的字段名</param>
        /// <returns></returns>
        private object GetFieldValue(DataAccess.Model.Rank model, string colName)
        {
            if (model == null || string.IsNullOrEmpty(colName))
            {
                return(null);
            }
            //返回指定的列值
            switch (colName)
            {
            case "Id":
                return(model.Id);

            case "RankLevel":
                return(model.RankLevel);

            case "RankCName":
                return(model.RankCName);

            case "RankEName":
                return(model.RankEName);
            }

            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// 从IIS缓存中获取指定条件的记录
        /// </summary>
        /// <param name="conditionColName">条件列名</param>
        /// <param name="value">条件值</param>
        /// <returns>DataAccess.Model.Rank</returns>
        public DataAccess.Model.Rank GetModelForCache(string conditionColName, object value)
        {
            try
            {
                //从缓存中获取List
                var list = GetList();
                DataAccess.Model.Rank           model      = null;
                Expression <Func <Rank, bool> > expression = null;

                //返回指定条件的实体
                switch (conditionColName)
                {
                case "Id":
                    model      = list.SingleOrDefault(x => x.Id == (long)value);
                    expression = x => x.Id == (long)value;
                    break;

                case "RankLevel":
                    model      = list.SingleOrDefault(x => x.RankLevel == (string)value);
                    expression = x => x.RankLevel == (string)value;
                    break;

                case "RankCName":
                    model      = list.SingleOrDefault(x => x.RankCName == (string)value);
                    expression = x => x.RankCName == (string)value;
                    break;

                case "RankEName":
                    model      = list.SingleOrDefault(x => x.RankEName == (string)value);
                    expression = x => x.RankEName == (string)value;
                    break;


                default:
                    return(null);
                }

                if (model == null)
                {
                    //从数据库中读取
                    var tem = Rank.SingleOrDefault(expression);
                    if (tem == null)
                    {
                        return(null);
                    }
                    else
                    {
                        //对查询出来的实体进行转换
                        model = Transform(tem);
                        SetModelForCache(model);
                        return(model);
                    }
                }
                else
                {
                    return(model);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取Rank表记录时出现异常", e);

                return(null);
            }
        }