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(); } }
/// <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(); }
/// <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(); } }
/// <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(); } }
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(); }