private void Login_Click(object sender, RoutedEventArgs e) { string login = loginBox.Text.ToLower(); string password = passwordBox.Password; string hashedPassword = PasswordInteraction.GetPasswordHash(password); User user = mainWindow.unitOfWork.Users.GetUserByLoginAndPassword(login, hashedPassword); if (user == null) { MessageBox.Show("Неверный логин или пароль!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBox.Show("Вы успешно авторизовались!", "Информация"); mainWindow.user = user; if (TeachersInteraction.IsTeacher(user)) { mainWindow.Navigation.Navigate(new TeacherPage(mainWindow, TeachersInteraction.GetTeacherModel(user))); } else if (AdminsInteraction.IsAdmin(user)) { mainWindow.Navigation.Navigate(new AdminPage(mainWindow)); } else { mainWindow.Navigation.Navigate(new UserPage(mainWindow, user)); } }
private void AddCol(string name, int combo_idx) { string combo_name = "K" + combo_idx.ToString(); var col = new DataGridTemplateColumn { Header = name }; var dt = new DataTemplate(); var stkpnl = new FrameworkElementFactory(typeof(StackPanel)); var comboBox = new FrameworkElementFactory(typeof(ComboBox)); comboBox.SetValue(ComboBox.ItemsSourceProperty, new Binding("Mark_list")); comboBox.SetValue(ComboBox.NameProperty, combo_name); comboBox.SetValue(ComboBox.SelectedIndexProperty, 0); if (TeachersInteraction.IsTeacher(mainWindow.user) == false || (TeachersInteraction.IsTeacher(mainWindow.user) == true && TeachersInteraction.GetTeacherModel(mainWindow.user).Id != curTimeTable.TeacherId)) { comboBox.SetValue(ComboBox.IsEnabledProperty, false); } comboBox.AddHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(ComboBox_Selected)); stkpnl.AppendChild(comboBox); dt.VisualTree = stkpnl; col.CellTemplate = dt; MarksGrid.Columns.Add(col); }
private void Registration_Click(object sender, RoutedEventArgs e) { string login = LoginBox.Text.ToLower(); string password = PasswordBox.Password; string first_name = First_NameBox.Text; string middle_name = Middle_NameBox.Text; string last_name = Last_NameBox.Text; string phone = PhoneBox.Text; int the_class = Int32.Parse(The_class_name.SelectedItem.ToString()); string letter = The_class_letter.SelectedValue.ToString(); if (Position_name.SelectedIndex == -1) { MessageBox.Show("Выберите роль!"); return; } if (login.Length == 0 || password.Length == 0 || first_name.Length == 0 || middle_name.Length == 0 || last_name.Length == 0) { MessageBox.Show("Пожалуйста, заполните все поля!", "Ошибка"); return; } User user = new User { FirstName = first_name, MiddleName = middle_name, LastName = last_name, Login = login, Password = PasswordInteraction.GetPasswordHash(password), Phone = phone, TheClassesId = unitOfWork.TheClasses.GetTheClassByNumber(the_class, letter) }; if (UsersInteraction.RegisterRequestStatus(user) == false) { MessageBox.Show("Пользователь с таким логином уже зарегистрирован!", "Error"); return; } if (Position_name.SelectedValue.ToString() == "Учитель") { int subject_id = Specialisation.SelectedIndex + 1; TeachersInteraction.Insert_Teacher(user, subject_id); } MessageBox.Show("Вы успешно зарегистрировались!", "Info"); user = unitOfWork.Users.GetUserByName(first_name, last_name, middle_name); mainWindow.user = user; if (TeachersInteraction.IsTeacher(user)) { mainWindow.Navigation.Navigate(new TeacherPage(mainWindow, TeachersInteraction.GetTeacherModel(user))); } else { mainWindow.Navigation.Navigate(new UserPage(mainWindow, user)); } }