private void btnEnter_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbLogin.Text)) { ClassMessageBox.MessageBoxInfo("Введите логин"); tbLogin.Focus(); } else if (string.IsNullOrEmpty(pbPassword.Password)) { ClassMessageBox.MessageBoxInfo("Введите пароль"); pbPassword.Focus(); } else { try { connection.Open(); cmd = new SqlCommand("SELECT [RoleId], " + "[Password] FROM [User] " + $"WHERE [Login] = '{tbLogin.Text}'", connection); reader = cmd.ExecuteReader(); reader.Read(); if (reader[1].ToString() != pbPassword.Password) { ClassMessageBox.MessageBoxError("Не верный " + "логин или пароль"); tbLogin.Focus(); } else { App.Login = tbLogin.Text; App.Password = reader[1].ToString(); App.Role = reader[0].ToString(); switch (App.Role) { case "1": WinCustomer winCustomer = new WinCustomer(); winCustomer.Show(); this.Close(); break; case "2": WinManager winManager = new WinManager(); winManager.Show(); this.Close(); break; case "3": WinStorekeeper winStorekeeper = new WinStorekeeper(); winStorekeeper.Show(); this.Close(); break; case "4": WinDirectorate winDirectorate = new WinDirectorate(); winDirectorate.Show(); this.Close(); break; } } } catch (Exception ex) { ClassMessageBox.MessageBoxError(ex.Message); } finally { connection.Close(); } } }
public void Enter(string login) { try { if (string.IsNullOrEmpty(textBox.Text)) { sB.Info("Введите логин"); } else if (string.IsNullOrEmpty(passwordBox.Password)) { sB.Info("Введите пароль"); } else { connection.Open(); cmd = new SqlCommand("SELECT [Id], [Password], [IdRole] FROM dbo.[User] " + $"WHERE [Login] = '{login}'", connection); reader = cmd.ExecuteReader(); reader.Read(); App.IdUser = reader[0].ToString(); string password = reader[1].ToString(); string role = reader[2].ToString(); if (passwordBox.Password != password) { sB.Info("Неверный логин или пароль"); } else { switch (role) { case "4": WinDirector winDirector = new WinDirector(); winDirector.Show(); window.Close(); break; case "3": WinManager winManager = new WinManager(); winManager.Show(); window.Close(); break; case "2": WinEmployee winEmployee = new WinEmployee(); winEmployee.Show(); window.Close(); break; case "1": WinAdmin winAdmin = new WinAdmin(); winAdmin.Show(); window.Close(); break; } } } } catch { sB.Info("Неверный логин или пароль"); } finally { connection.Close(); } }