Exemple #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DataContext db = new DataContext(Properties.Settings.Default.AtelieConnectionString))

                {
                    Table <avtoriz> uslugis   = db.GetTable <avtoriz>();
                    var             userLogin = (from u in uslugis
                                                 where u.login == Логин.Text
                                                 select u).ToArray();
                    var userPass = (from u in uslugis
                                    where u.Password == Пароль.Text
                                    select u).ToArray();
                    if (Логин.Text == userLogin[0].login)
                    {
                        if (Пароль.Text == userPass[0].Password)
                        {
                            Ателье w1 = new Ателье(); w1.Show(); this.Close();
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("Введите корректные данные");
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            {
                try
                {
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand("select *  from [avtoriz] where [avtoriz].[login] = '"
                                                            + Логин.Text + "'and [avtoriz].[Password] = '" + Пароль.Text + "'", connection);
                        SqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows)       //если естьданные
                        {
                            while (reader.Read()) // построчно считываем данные
                            {
                                string rol = reader.GetValue(3).ToString();
                                MessageBox.Show("Добро пожаловать! " + rol + " " + reader.GetValue(4).ToString());

                                switch (rol)
                                {
                                case "Директор":
                                    Ателье w1 = new Ателье(); w1.Show(); this.Close();
                                    break;

                                case "Администратор":
                                    Ателье w2 = new Ателье(); w2.Show(); this.Close();
                                    break;

                                default:
                                    MessageBox.Show("Неизветсная роль");
                                    break;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Такого пользователя нет");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Введите корректные данные");
                }
            }
        }