/// <summary> /// Заполнение стартовой информации (не по достижениям) /// </summary> void FillingNP() { using (AchievmentsEntities ach = new AchievmentsEntities()) { Password p = ach.Passwords.Where(x => x.ID == App.curPnID).FirstOrDefault(); TBlInfo.Text += "Пользователь: " + p.Name+"\n"; } }
public Edit() { InitializeComponent(); using (AchievmentsEntities ach=new AchievmentsEntities()) { user = ach.Passwords.Find(App.curPnID); TBLog.Text = user.Name.Clone().ToString(); } }
void UpdateLVSubTh(Theme th) { using (AchievmentsEntities ach=new AchievmentsEntities()) { List<Subtheme> sTh = new List<Subtheme>(); var sThR=ach.SubThemeRels.Where(p => p.ThemeID == th.ID).ToList(); sTh.AddRange(sThR.Select(p => p.Subtheme)); LVSubTh.ItemsSource = sTh; } }
/// <summary> /// Обновление ComboBox - подтем /// </summary> /// <param name="ach">Соединение с бд</param> void RefrefsSubTh(AchievmentsEntities ach) { ComboBoxSubtheme.Items.Clear(); Theme th = ach.Themes.Where(t => t.Name == ComboBoxTheme.SelectedValue.ToString()).FirstOrDefault(); foreach (var item in ach.SubThemeRels) { if (item.Theme == th) { ComboBoxSubtheme.Items.Add(item.Subtheme.Name); } } if (ComboBoxSubtheme.Items.Count > 0) ComboBoxSubtheme.SelectedIndex = 0; }
/// <summary> /// Обновление ComboBox - тем и подтем /// </summary> void ComboBoxFill() { ComboBoxTheme.Items.Clear(); using (AchievmentsEntities ach = new AchievmentsEntities()) { foreach (var item in ach.Themes) { ComboBoxTheme.Items.Add(item.Name); } ComboBoxTheme.SelectedIndex = 0; } }
void GetThemeList() { using (AchievmentsEntities ach=new AchievmentsEntities()) { ach.Themes.Load(); var themes = ach.Themes.Local; LVTheme.ItemsSource=themes.AsEnumerable(); } if (LVTheme.Items.Count!=0) { LVTheme.SelectedIndex = 0; ChangeViews(); } }
private void ButtonOK_Click(object sender, RoutedEventArgs e) { if (TextBoxName.Text == "") { MessageBox.Show("Имя не может быть пустым"); return; } using (AchievmentsEntities ach = new AchievmentsEntities()) { if (theme) CreateNewTheme(ach); else CreateNewSubTheme(ach); } if(DelegatesData.HandlerAchAddDelCBRefresf!=null) DelegatesData.HandlerAchAddDelCBRefresf(); this.Close(); }
void CreateNewPass() { if (PBNP.Password!=PBRNP.Password) { MessageBox.Show("Пароли не совпадают"); return; } using (AchievmentsEntities ach=new AchievmentsEntities()) { user = ach.Passwords.Find(App.curPnID); if (user.Name != TBLog.Text) user.Name = TBLog.Text; MD5 md = new MD5CryptoServiceProvider(); byte[] bt = Encoding.UTF8.GetBytes(PBNP.Password); user.Password1 = bt; ach.SaveChanges(); } }
void CreateCategoryList() { using (AchievmentsEntities ach = new AchievmentsEntities()) { if (th) { ach.Themes.Load(); var themes = ach.Themes.Local; LVCat.ItemsSource = themes.AsEnumerable(); } else { ach.Subthemes.Load(); var subThemes = ach.Subthemes.Local; LVCat.ItemsSource = subThemes.AsEnumerable(); } LVCat.SelectedIndex = 0; } }
void CheckOldPass() { MD5 md = new MD5CryptoServiceProvider(); byte[] bt = Encoding.UTF8.GetBytes(PBOld.Password); using (AchievmentsEntities ach = new AchievmentsEntities()) { if (bt.SequenceEqual(user.Password1)) { PBOld.IsEnabled = false; TBLog.IsEnabled = true; PBNP.IsEnabled = true; PBRNP.IsEnabled = true; MessageBox.Show("Правильный пароль"); } else MessageBox.Show("Неправильный пароль"); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (th) { using (AchievmentsEntities ach = new AchievmentsEntities()) { Theme thm = ach.Themes.Find((LVCat.SelectedItem as Theme).ID); thm.Name = TBName.Text; ach.SaveChanges(); } } else { using (AchievmentsEntities ach = new AchievmentsEntities()) { Subtheme sthm = ach.Subthemes.Find((LVCat.SelectedItem as Subtheme).ID); List<string> sl=new List<string>(); foreach (var item in ach.Themes) { sl.Add(item.Name); } if (sl.Contains(sthm.Name)) { MessageBox.Show("Изменение основной подтемы невозможно!"); return; } sthm.Name = TBName.Text; ach.SaveChanges(); } } CreateCategoryList(); }
bool IsEmpty(int ID) { using(AchievmentsEntities ach=new AchievmentsEntities()) { if (theme) { if (ach.AchieveInfoes.Where(p => p.ThemeID == ID && p.PersonID == App.curPnID).Count() > 0) { return false; } } else if (ach.AchieveInfoes.Where(p => p.SubthemeID == ID && p.PersonID == App.curPnID).Count() > 0) { return false; } return true; } }
void CreateAchList(Subtheme sTh) { AchievmentsEntities ach = new AchievmentsEntities(); achI.AddRange(ach.AchieveInfoes.Where(p => p.SubthemeID == sTh.ID && p.PersonID == App.curPnID).AsEnumerable()); }
/// <summary> /// Получить все достижения для текущего пользователя /// </summary> /// <returns></returns> IQueryable<AchieveInfo> GetFullAchList() { AchievmentsEntities ach = new AchievmentsEntities(); var aa = ach.AchieveInfoes.Where(p => p.Password.ID == App.curPnID); return aa; }
/// <summary> /// Полная операция создания новой темы /// </summary> void CreateNewTheme(AchievmentsEntities ach) { if(ach.Themes.Select(x=>x.Name==TextBoxName.Text).FirstOrDefault()) { MessageBox.Show("Тема уже существует"); return; } ach.Themes.Add(new Theme() { Name = TextBoxName.Text }); ComboBoxTheme.Items.Add(TextBoxName.Text); ComboBoxTheme.SelectedIndex=0; CreateNewSubTheme(ach); ach.SaveChanges(); }
/// <summary> /// Добавление подтемы и создание связи - многие ко многим /// </summary> /// <param name="ach"></param> void CreateManyToManyRel(AchievmentsEntities ach) { //выбор темы из бд Theme th = ach.Themes.Where(x => x.Name == ComboBoxTheme.SelectedValue.ToString()).FirstOrDefault(); Subtheme st; //Если подтема есть, связать её еще одной темой if (ach.Subthemes.Select(t => t.Name.ToUpper().Equals(TextBoxName.Text.ToUpper())).FirstOrDefault()) st = ach.Subthemes.Where(t => t.Name == TextBoxName.Text).FirstOrDefault(); //если нет - создать новую else { st = new Subtheme() { Name = TextBoxName.Text }; ach.Subthemes.Add(st); } //добавление связи к теме ach.SubThemeRels.Add( new SubThemeRel() { Theme=th, Subtheme=st } ); ach.SaveChanges(); }
/// <summary> /// Полная операция создания новой подтемы /// </summary> void CreateNewSubTheme(AchievmentsEntities ach) { if (ach.SubThemeRels.Select(x => x.Theme.Name == ComboBoxTheme.SelectedValue.ToString() && x.Subtheme.Name == TextBoxName.Text).FirstOrDefault()) { MessageBox.Show("Подтема уже существует в этой теме"); return; } CreateManyToManyRel(ach); }
private void ComboBoxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ComboBoxTheme.SelectedIndex != -1) using (AchievmentsEntities ach = new AchievmentsEntities()) { RefrefsSubTh(ach); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { ai.Date = achI.aDate; ai.Name = achI.aName; ai.Points = achI.aPoints; ai.Subscribe = achI.aSubscribe; using (AchievmentsEntities ach=new AchievmentsEntities()) { ai.Theme = ach.Themes.Where(p => p.Name == ComboBoxTheme.SelectedValue).FirstOrDefault(); ai.Subtheme = ach.Subthemes.Where(p => p.Name == ComboBoxSubtheme.SelectedValue).FirstOrDefault(); AchieveInfo temp= ach.AchieveInfoes.Find(ai.ID); temp.Date = ai.Date; temp.Name = ai.Name; temp.Points = ai.Points; temp.Subscribe = ai.Subscribe; temp.Subtheme = ai.Subtheme; temp.Theme = ai.Theme; ach.SaveChanges(); } Button_Click_2(this, new RoutedEventArgs()); }