Esempio n. 1
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con;

            con = new SqlConnection(@"Data Source=IVAN\SQLEXPRESS;Initial Catalog=MTC;Integrated Security=True");
            try
            {
                con.Open();

                SqlCommand com = new SqlCommand("Select * from Users where login='******' and password='******'", con);
                if (com.ExecuteScalar() == null)
                {
                    System.Windows.MessageBox.Show("Пароль введен не верно");
                }
                else
                {
                    SqlCommand comRole = new SqlCommand("select Роль from Users where login='******' and password='******'", con);
                    if (((string)comRole.ExecuteScalar()).ToString().Replace(" ", "") == "Технолог")
                    {
                        AddClient win = new AddClient();
                        win.Show();
                        this.Close();
                    }
                    if (((string)comRole.ExecuteScalar()).ToString().Replace(" ", "") == "Оператор")
                    {
                        addCall win = new addCall();
                        win.Show();
                        this.Close();
                    }
                    if (((string)comRole.ExecuteScalar()).ToString().Replace(" ", "") == "Администратор")
                    {
                        AddUser win = new AddUser();
                        win.Show();
                        this.Close();
                    }
                }
            }

            catch (System.Data.SqlClient.SqlException ex) //Catch SqlException
            {
                MessageBox.Show("Отсутствует подключение к БД");
            }
            catch (Exception ex) //Catch Other Exception
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con;

            con = new SqlConnection(@"Data Source=IVAN\SQLEXPRESS;Initial Catalog=MTC;Integrated Security=True");
            try
            {
                con.Open();
                MTC.ViewModel.Authorization auth = new ViewModel.Authorization(con);
                if (!auth.Availability(tbLogin.Text, tbPassword.Password))
                {
                    System.Windows.MessageBox.Show("Пароль введен не верно");
                }
                else
                {
                    string role = auth.Role(tbLogin.Text, tbPassword.Password);
                    if (role == "Технолог")
                    {
                        AddClient win = new AddClient();
                        win.Show();
                        this.Close();
                    }
                    if (role == "Оператор")
                    {
                        addCall win = new addCall();
                        win.Show();
                        this.Close();
                    }
                    if (role == "Администратор")
                    {
                        AddUser win = new AddUser();
                        win.Show();
                        this.Close();
                    }
                }
            }

            catch (System.Data.SqlClient.SqlException ex) //Catch SqlException
            {
                MessageBox.Show("Отсутствует подключение к БД");
            }
            catch (Exception ex) //Catch Other Exception
            {
                MessageBox.Show(ex.Message);
            }
        }