Пример #1
0
 public void DeleteDataRep()
 {
     using (EnumDBContext ec = new EnumDBContext())
     {
         var dataAll = ec.Set <ButtonDate>();
         if (dataAll.Count() < 1)
         {
             return;
         }
         List <ButtonDate> btnList    = dataAll.ToList();
         List <string>     btnListTwo = new List <string>();
         foreach (ButtonDate item in btnList)
         {
             if (string.IsNullOrEmpty(item.Name) || string.IsNullOrEmpty(item.Url))
             {
                 dataAll.Remove(item);
             }
             if (btnListTwo.Contains(item.Name))
             {
                 dataAll.Remove(item);
             }
             else
             {
                 btnListTwo.Add(item.Name);
             }
         }
         ec.SaveChanges();
     }
 }
Пример #2
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="a"></param>
 public static void Delete <T>(Dictionary <string, object> param) where T : class
 {
     if (param.Keys.Count < 1)
     {
         return;
     }
     using (EnumDBContext ec = new EnumDBContext())
     {
         var      dataAll = ec.Set <T>();
         var      ps      = typeof(T).GetProperties();
         List <T> lt      = new List <T>();
         foreach (string item in param.Keys)
         {
             PropertyInfo pi = ps.FirstOrDefault(c => c.Name == item);
             if (pi != null)
             {
                 Type ty = pi.PropertyType;
                 lt.AddRange(dataAll.Where(c => Convert.ChangeType(pi.GetValue(c), ty) == Convert.ChangeType(param[item], ty)).ToList());
             }
         }
         if (lt.Count < 1)
         {
             return;
         }
         dataAll.RemoveRange(lt);
         ec.SaveChanges();
     }
 }
Пример #3
0
        /// <summary>
        /// 保存数据到数据库
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        public static void saveDataToSql <T>(List <T> a) where T : class
        {
            if (a.Count < 1)
            {
                return;
            }
            EnumDBContext db = new EnumDBContext();
            var           lt = db.Set <T>();
            var           ps = typeof(T).GetProperties();
            PropertyInfo  pi = ps.FirstOrDefault(c => c.Name == "ID");

            foreach (T item in a)
            {
                T m = lt.FirstOrDefault(c => (Int32)pi.GetValue(item) == (Int32)pi.GetValue(c));
                if (m == null)
                {
                    lt.Add(item);
                }
                else
                {
                    cltocl <T>(item, ref m, new List <string>()
                    {
                        "ID"
                    });
                }
            }
            db.SaveChanges();
            db.Dispose();
        }
Пример #4
0
 /// <summary>
 /// 修改按钮状态
 /// </summary>
 /// <param name="id"></param>
 /// <param name="State"></param>
 public static void ModifyPWDToSQL(DictionaryPassword PWD)
 {
     using (EnumDBContext ec = new EnumDBContext())
     {
         var dataAll = ec.Set <DictionaryPassword>();
         var model   = dataAll.FirstOrDefault(c => c.Plaintext == PWD.Plaintext && c.Password == PWD.Password);
         if (model == null)
         {
             dataAll.Add(PWD);
         }
         ec.SaveChanges();
     }
 }
Пример #5
0
        /// <summary>
        /// 获取数据集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static List <T> getListFromSQL <T>() where T : class
        {
            EnumDBContext ec         = new EnumDBContext();
            var           Sourcelist = ec.Set <T>().ToList();

            ec.Dispose();
            string className = typeof(T).Name;

            if (!PubulicData.sourceData.Keys.Contains(className))
            {
                PubulicData.sourceData.Add(className, Sourcelist);
            }
            else
            {
                PubulicData.sourceData[className] = Sourcelist;
            }
            return(Sourcelist);
        }
Пример #6
0
        public void reSetIndex()
        {
            EnumDBContext dbc     = new EnumDBContext();
            var           btndate = dbc.Set <ButtonDate>();
            var           btnWeb  = btndate.Where(c => c.Type == BtnType.网站.ToString()).OrderBy(c => c.Index);
            var           btnApp  = btndate.Where(c => c.Type == BtnType.链接.ToString()).OrderBy(c => c.Index);
            int           index   = 1;

            foreach (ButtonDate item in btnWeb)
            {
                item.Index = index;
                index++;
            }
            index = 1;
            foreach (ButtonDate item in btnApp)
            {
                item.Index = index;
                index++;
            }
            dbc.SaveChanges();
            dbc.Dispose();
        }