Exemple #1
0
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(BaseDic model)
 {
     this._repoBaseDic.Delete(model);
 }
Exemple #2
0
        /// <summary>
        /// foreach数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <param name="name"></param>
        /// <param name="db"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static List <T> MapForEach <T>(List <T> data, string name, DataContext db, ConfigModel config, int i = 1) where T : class, new()
        {
            var      result  = new List <T>();
            var      param   = new List <DbParameter>();
            var      dicName = DbCache.Get(config.CacheType, string.Format("{0}.foreach.name.{1}", name.ToLower(), i));
            var      type    = DbCache.Get(config.CacheType, string.Format("{0}.foreach.type.{1}", name.ToLower(), i));
            var      field   = DbCache.Get(config.CacheType, string.Format("{0}.foreach.field.{1}", name.ToLower(), i));
            var      sql     = DbCache.Get(config.CacheType, string.Format("{0}.foreach.sql.{1}", name.ToLower(), i));
            Assembly assembly;

            if (type.IndexOf(',') > 0)
            {
                var key = string.Format("ForEach.{0}", type.Split(',')[1]);
                if (DbCache.Exists(CacheType.Web, key))
                {
                    assembly = DbCache.Get <object>(CacheType.Web, key) as Assembly;
                }
                else
                {
                    assembly = AppDomain.CurrentDomain.GetAssemblies().ToList().Find(a => a.FullName.Split(',')[0] == type.Split(',')[1]);
                }
                if (assembly == null)
                {
                    assembly = Assembly.Load(type.Split(',')[1]);
                }
                if (assembly == null)
                {
                    return(data);
                }
                else
                {
                    DbCache.Set <object>(CacheType.Web, key, assembly);
                    if (assembly.GetType(type.Split(',')[0]) == null)
                    {
                        return(data);
                    }

                    foreach (var item in data)
                    {
                        var model      = Activator.CreateInstance(assembly.GetType(type.Split(',')[0]));
                        var list       = Activator.CreateInstance(typeof(List <>).MakeGenericType(assembly.GetType(type.Split(',')[0])));
                        var infoResult = BaseDic.PropertyInfo <T>().Find(a => a.PropertyType.FullName == list.GetType().FullName);
                        var dynSet     = new DynamicSet(model);

                        //param
                        param.Clear();
                        if (field.IndexOf(',') > 0)
                        {
                            foreach (var split in field.Split(','))
                            {
                                var infoField = BaseDic.PropertyInfo <T>().Find(a => a.Name.ToLower() == split);
                                var tempParam = DbProviderFactories.GetFactory(config).CreateParameter();
                                tempParam.ParameterName = split;
                                tempParam.Value         = infoField.GetValue(item, null);
                                param.Add(tempParam);
                            }
                        }
                        else
                        {
                            var infoField = BaseDic.PropertyInfo <T>().Find(a => a.Name.ToLower() == field);
                            var tempParam = DbProviderFactories.GetFactory(config).CreateParameter();
                            tempParam.ParameterName = field;
                            tempParam.Value         = infoField.GetValue(item, null);
                            param.Add(tempParam);
                        }

                        var tempData = db.ExecuteSql(sql, param.ToArray(), false);

                        foreach (var temp in tempData.DicList)
                        {
                            foreach (var info in model.GetType().GetProperties())
                            {
                                if (temp.GetValue(info.Name).ToStr() == "" && info.PropertyType.Name == "Nullable`1")
                                {
                                    continue;
                                }

                                if (info.PropertyType.Name == "Nullable`1" && info.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                                {
                                    dynSet.SetValue(model, info.Name, Convert.ChangeType(temp.GetValue(info.Name), Nullable.GetUnderlyingType(info.PropertyType)), config.IsPropertyCache);
                                }
                                else
                                {
                                    dynSet.SetValue(model, info.Name, Convert.ChangeType(temp.GetValue(info.Name), info.PropertyType), config.IsPropertyCache);
                                }
                            }

                            var method = list.GetType().GetMethod("Add", BindingFlags.Instance | BindingFlags.Public);
                            method.Invoke(list, new object[] { model });
                        }

                        infoResult.SetValue(item, list);
                        result.Add(item);
                    }
                    return(result);
                }
            }
            else
            {
                return(data);
            }
        }
Exemple #3
0
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(BaseDic model)
 {
     this._repoBaseDic.Update(model);
 }
Exemple #4
0
 public BaseDic Insert(BaseDic model)
 {
     return(this._repoBaseDic.Insert(model));
 }
 /// <summary>
 /// 删除实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Delete(BaseDic model)
 {
     this._BaseDicBiz.Delete(model);
 }
 /// <summary>
 /// 修改实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void Update(BaseDic model)
 {
     this._BaseDicBiz.Update(model);
 }
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public BaseDic Insert(BaseDic model)
 {
     return(this._BaseDicBiz.Insert(model));
 }