private async void AddEvent_Click(object sender, RoutedEventArgs e) { try { string emptyRichTxtBox = new TextRange(EventText.Document.ContentStart, EventText.Document.ContentEnd).Text; if (emptyRichTxtBox.Length - 2 == 0) { MessageBox.Show("Текстовое поле пусто!"); return; } using (Models.OrganizerDB dc = new Models.OrganizerDB()) { Models.Event Work = new Models.Event(); Work.DateEvent = DateEvent.SelectedDate.ToString().Remove(10, 8); Work.Text_Event = new TextRange(EventText.Document.ContentStart, EventText.Document.ContentEnd).Text; Work.User = Classes.SelectUser.SelectUserID; dc.Event.Add(Work); await dc.SaveChangesAsync(); FillTable(); DeleteEvent.IsEnabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BusinessRecord(object sender, MouseButtonEventArgs e) { try { DataGrid dg = sender as DataGrid; Models.Business row = (Models.Business)dg.SelectedItems[0]; ind = Convert.ToInt32(row.ID_Business.ToString()); using (Models.OrganizerDB context = new Models.OrganizerDB()) { var busin = context.Business.FirstOrDefault(s => s.ID_Business == ind && s.User == Classes.SelectUser.SelectUserID); if (busin != null) { StateBox.Text = busin.State; BusinessDatePicker.SelectedDate = DateTime.Parse(busin.Date); BusinessPerson.Text = busin.Person; FlowDocument flow = new FlowDocument(new Paragraph(new Run(busin.TextWork))); BusinessTextWork.Document = flow; DeleteBusiness.IsEnabled = true; ChangeBusiness.IsEnabled = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void notebookDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) // получение индекса выделенной строки и запись инф-и в окно { try { DataGrid dg = sender as DataGrid; Models.Notebook row = (Models.Notebook)dg.SelectedItems[0]; index = Convert.ToInt32(row.ID_NB.ToString()); using (Models.OrganizerDB context = new Models.OrganizerDB()) { var notebook = context.Notebook.FirstOrDefault(s => s.ID_NB == index && s.User == Classes.SelectUser.SelectUserID); if (notebook != null) { NoteTitle.Text = notebook.HeaderNB; FlowDocument flow = new FlowDocument(new Paragraph(new Run(notebook.TextNotebook))); NoteText.Document = flow; ChangeNote.IsEnabled = true; DeleteNote.IsEnabled = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void LoadElements() { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Person pers = context.Person.Find(Classes.SelectContact.SelectContactID); var brush = new ImageBrush(); brush.ImageSource = ImageFunc.ConvertImageFromBinary(pers.PersonPhoto); PersonPhoto.Background = brush; Name.Text = pers.Name; LastName.Text = pers.Lastname; Patronymic.Text = pers.Patronymic; if (pers.Gender == "М") { Gender.SelectedIndex = 0; } else { Gender.SelectedIndex = 1; } DOB.Text = pers.DOB; NickName.Text = pers.NickName; PhoneNumber.Text = pers.Phone_number; Position.Text = pers.Position; Email.Text = pers.Email; Adress.Text = pers.AdressPerson; } }
private void BtnUserAdd(object sender, RoutedEventArgs e) { int CheckingLoginExistance = 0; try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { if (!Regex.IsMatch(Username.Text, Classes.ValidationRegex.Login)) { MessageBox.Show("Логин не соответствует формату"); return; } if (!Regex.IsMatch(UserAddPassword.Text, Classes.ValidationRegex.Password)) { MessageBox.Show("Пароль не соответствует формату"); return; } var user = context.User.FirstOrDefault(s => s.UserName == Username.Text.Replace(" ", "")); if (user != null) //проверка на существование пользователя { CheckingLoginExistance = 1; // пользователь существует } if (CheckingLoginExistance == 0) { Models.User Newuser = new Models.User(); Newuser.UserName = Username.Text; // Считываем логин Newuser.Password = (Crypter.Encrypt(UserAddPassword.Text)).ToString(); // считываем и зашифровываем пароль if (ImgPath != "") { Newuser.UserPhoto = ImageFunc.ConvertImageToBinary(ImgPath); } else { string fileName = "user3.png"; string fullPath; fullPath = System.IO.Path.GetFullPath(fileName); Newuser.UserPhoto = ImageFunc.ConvertImageToBinary(fullPath); } context.User.Add(Newuser); context.SaveChanges(); MessageBox.Show("Новый пользователь " + Username.Text + " добавлен"); Username.Clear(); UserAddPassword.Clear(); } else { MessageBox.Show("Пользователь " + Username.Text + " существует. Пожалуйста, придумайте другой логин.", "Повтор логина", MessageBoxButton.OK); } } } catch (Exception ex) { MessageBox.Show("Новый пользователь " + Username.Text + "не добавлен!!!б, ошибка: " + ex.Message); } }
private async void EnterApp() { try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { var user = await context.User.FirstOrDefaultAsync(s => s.UserName == Username.Text.Replace(" ", "")); if (user != null) { if (Crypter.Decrypt(user.Password) == UserPassword.Password.ToString().Replace(" ", "")) { Classes.SelectUser.SelectUserID = user.UserID; MainWindow MainWnd = new MainWindow(); MainWnd.Show(); this.Close(); } else { MessageBox.Show("Неправильный пароль"); } } else { MessageBox.Show("Такого пользователя не существует"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SearchNote_Click(object sender, RoutedEventArgs e) { using (Models.OrganizerDB context = new Models.OrganizerDB()) { context.Notebook.Load(); notebookDataGrid.ItemsSource = context.Notebook.Local.ToBindingList().Where(p => p.User == Classes.SelectUser.SelectUserID).Where(p => p.HeaderNB.Contains(NoteSearch.Text)); } }
public void FillTable() { using (Models.OrganizerDB dc = new Models.OrganizerDB()) { dc.Event.Load(); eventDataGrid.ItemsSource = dc.Event.Local.ToBindingList().Where(p => p.User == Classes.SelectUser.SelectUserID); } }
public void FillTable() { using (Models.OrganizerDB context = new Models.OrganizerDB()) { context.Notebook.Load(); notebookDataGrid.ItemsSource = context.Notebook.Local.ToBindingList().Where(p => p.User == Classes.SelectUser.SelectUserID); } }
private void btnSearchPerson_Click(object sender, RoutedEventArgs e) { using (Models.OrganizerDB context = new Models.OrganizerDB()) { context.Person.Load(); personDataGrid.ItemsSource = context.Person.Local.ToBindingList() .Where(p => p.User == Classes.SelectUser.SelectUserID && p.Lastname.Contains(PersonSearch.Text) || p.Name.Contains(PersonSearch.Text)); } }
private void DeletePerson_Click(object sender, RoutedEventArgs e) { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Person pers = context.Person.Find(Classes.SelectContact.SelectContactID); context.Person.Remove(pers); context.SaveChanges(); MessageBox.Show("Контакт удален"); this.Close(); } }
private void WindowLoaded(object sender, RoutedEventArgs e) { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.User user = context.User.Find(Classes.SelectUser.SelectUserID); var brush = new ImageBrush(); brush.ImageSource = ImageFunc.ConvertImageFromBinary(user.UserPhoto); UserPhoto.Background = brush; Username.Text = user.UserName; } }
static public void Check() { Models.OrganizerDB context = new Models.OrganizerDB(); DateTime thisDay = DateTime.Today; foreach (var ev in context.Event.Where(p => p.User == Classes.SelectUser.SelectUserID)) { if (ev.DateEvent == thisDay.ToString().Remove(10)) { Notification(ev.Text_Event); } } thisDay.ToString(); }
private void BtnUserChangeInf(object sender, RoutedEventArgs e) { try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { if (!Regex.IsMatch(Username.Text, Classes.ValidationRegex.Login)) { MessageBox.Show("Логин не соответствует формату"); return; } if (!Regex.IsMatch(userNewPassword.Text, Classes.ValidationRegex.Password)) { MessageBox.Show("Пароль не соответствует формату"); return; } Models.User user = context.User.Find(Classes.SelectUser.SelectUserID); if (Crypter.Decrypt(user.Password) == userOldPassword.Text.Replace(" ", "")) { user.UserName = Username.Text; // Считываем логин user.Password = (Crypter.Encrypt(userNewPassword.Text)).ToString(); // считываем и зашифровываем пароль if (ImgPath != "") { user.UserPhoto = ImageFunc.ConvertImageToBinary(ImgPath); } context.SaveChanges(); MessageBox.Show("Информация успешно изменена"); } else { MessageBox.Show("Введен неверный пароль.", "Проверьте правильность ввода", MessageBoxButton.OK, MessageBoxImage.Warning); } } } catch (Exception ex) { MessageBox.Show("Изменить данные " + Username.Text + " не удалось, ошибка: " + ex.Message); } }
private void DeleteEvent_Click(object sender, RoutedEventArgs e) { try { using (Models.OrganizerDB dc = new Models.OrganizerDB()) { Models.Event work = dc.Event.Find(index); dc.Event.Remove(work); dc.SaveChanges(); FillTable(); DeleteEvent.IsEnabled = false; FlowDocument flow = new FlowDocument(new Paragraph(new Run(""))); EventText.Document = flow; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ChangeRecord_Click(object sender, RoutedEventArgs e) { try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Notebook notebook = context.Notebook.Find(index); notebook.HeaderNB = NoteTitle.Text; notebook.TextNotebook = new TextRange(NoteText.Document.ContentStart, NoteText.Document.ContentEnd).Text; notebook.DateTime = DateTime.Today.ToString().Remove(10, 8); context.SaveChanges(); } FillTable(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void DeleteRecord_Click(object sender, RoutedEventArgs e) { try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Notebook notebook = context.Notebook.Find(index); context.Notebook.Remove(notebook); context.SaveChanges(); } FillTable(); ChangeNote.IsEnabled = false; DeleteNote.IsEnabled = false; NoteTitle.Text = ""; FlowDocument flow = new FlowDocument(new Paragraph(new Run(""))); NoteText.Document = flow; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddRecord_Click(object sender, RoutedEventArgs e) { try { string emptyRichTxtBox = new TextRange(NoteText.Document.ContentStart, NoteText.Document.ContentEnd).Text; if (NoteTitle.Text == "") { MessageBox.Show("Заголовок пуст!"); return; } if (emptyRichTxtBox.Length - 2 == 0) { MessageBox.Show("Текстовое поле пусто!"); return; } using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Notebook NewNote = new Models.Notebook(); NewNote.HeaderNB = NoteTitle.Text; NewNote.TextNotebook = new TextRange(NoteText.Document.ContentStart, NoteText.Document.ContentEnd).Text; NewNote.DateTime = DateTime.Today.ToString().Remove(10, 8); NewNote.User = Classes.SelectUser.SelectUserID; context.Notebook.Add(NewNote); context.SaveChanges(); } FillTable(); ChangeNote.IsEnabled = false; DeleteNote.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ChangePersonInfo_Click(object sender, RoutedEventArgs e) { try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Person pers = context.Person.Find(Classes.SelectContact.SelectContactID); if (ImgPath != "") { pers.PersonPhoto = ImageFunc.ConvertImageToBinary(ImgPath); } if (Name.Text != "") { if (Regex.IsMatch(Name.Text, Classes.ValidationRegex.NameRegex)) { pers.Name = Name.Text; } else { MessageBox.Show("Неверный формат имени"); return; } } else { MessageBox.Show("Поле Имя должно быть заполнено"); return; } if (LastName.Text != "") { if (Regex.IsMatch(LastName.Text, Classes.ValidationRegex.NameRegex)) { pers.Lastname = LastName.Text; } else { MessageBox.Show("Неверный формат фамилии"); return; } } else { MessageBox.Show("Поле Фамилия должно быть заполнено"); return; } if (Patronymic.Text != "") { pers.Patronymic = Patronymic.Text; } else { pers.Patronymic = ""; } pers.Gender = Gender.Text.Remove(1); pers.DOB = DOB.SelectedDate.ToString().Remove(10, 8); if (NickName.Text != "") { pers.NickName = NickName.Text; } else { pers.NickName = ""; } if (PhoneNumber.Text != "") { if (Regex.IsMatch(PhoneNumber.Text, Classes.ValidationRegex.PhoneRegex)) { pers.Phone_number = PhoneNumber.Text; } else { MessageBox.Show("Неверный формат номера телефона"); return; } } else { pers.Phone_number = ""; } if (Position.Text != "") { pers.Position = Position.Text; } else { pers.Position = ""; } if (Email.Text != "") { if (Regex.IsMatch(Email.Text, Classes.ValidationRegex.EmailRegex)) { pers.Email = Email.Text; } else { MessageBox.Show("Неверный формат Email"); return; } } else { pers.Email = ""; } if (Adress.Text != "") { pers.AdressPerson = Adress.Text; } else { pers.AdressPerson = ""; } context.SaveChanges(); MessageBox.Show("Информация обновлена"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnContactAdd(object sender, RoutedEventArgs e) { try { using (Models.OrganizerDB context = new Models.OrganizerDB()) { Models.Person pers = new Models.Person(); if (ImgPath != "") { pers.PersonPhoto = ImageFunc.ConvertImageToBinary(ImgPath); } else { string fileName = "user3.png"; string fullPath; fullPath = System.IO.Path.GetFullPath(fileName); pers.PersonPhoto = ImageFunc.ConvertImageToBinary(fullPath); } if (Name.Text != "") { if (Regex.IsMatch(Name.Text, Classes.ValidationRegex.NameRegex)) { pers.Name = Name.Text; } else { MessageBox.Show("Неверный формат имени"); return; } } else { MessageBox.Show("Поле Имя должно быть заполнено"); return; } if (LastName.Text != "") { if (Regex.IsMatch(LastName.Text, Classes.ValidationRegex.NameRegex)) { pers.Lastname = LastName.Text; } else { MessageBox.Show("Неверный формат фамилии"); return; } } else { MessageBox.Show("Поле Фамилия должно быть заполнено"); return; } if (Patronymic.Text != "") { pers.Patronymic = Patronymic.Text; } else { pers.Patronymic = ""; } pers.Gender = Gender.Text.Remove(1); pers.DOB = DOB.SelectedDate.ToString().Remove(10, 8); if (NickName.Text != "") { pers.NickName = NickName.Text; } else { pers.NickName = ""; } if (PhoneNumber.Text != "") { if (Regex.IsMatch(PhoneNumber.Text, Classes.ValidationRegex.PhoneRegex)) { pers.Phone_number = PhoneNumber.Text; } else { MessageBox.Show("Неверный формат номера телефона"); return; } } else { pers.Phone_number = ""; } if (Position.Text != "") { pers.Position = Position.Text; } else { pers.Position = ""; } if (Email.Text != "") { if (Regex.IsMatch(Email.Text, Classes.ValidationRegex.EmailRegex)) { pers.Email = Email.Text; } else { MessageBox.Show("Неверный формат Email"); return; } } else { pers.Email = ""; } if (Adress.Text != "") { pers.AdressPerson = Adress.Text; } else { pers.AdressPerson = ""; } pers.User = Classes.SelectUser.SelectUserID; context.Person.Add(pers); context.SaveChanges(); MessageBox.Show("Контакт " + Name.Text + " " + LastName.Text + " добавлен"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }