示例#1
0
 private void btnAddUser_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(tbLogin.Text))
     {
         sB.Info("Введите логин");
     }
     else if (string.IsNullOrEmpty(tbPassword.Text))
     {
         sB.Info("Введите пароль");
     }
     else if (string.IsNullOrEmpty(cbRole.Text))
     {
         sB.Info("Введите роль");
     }
     else
     {
         dataBaseQuery.SqlQuery("INSERT INTO dbo.[User] (Login, Password, IdRole) " +
                                $"VALUES ('{tbLogin.Text}', '{tbPassword.Text}', (SELECT Id FROM dbo.[Role] " +
                                $"WHERE NameRole = '{cbRole.Text}'))", "Данные успешно добавлены",
                                "Пользователь с таким логином уже есть");
         tbLogin.Clear();
         tbPassword.Clear();
         cbRole.SelectedItem = null;
         dG.Loader("SELECT * FROM dbo.[UserRole]");
     }
 }
示例#2
0
        public void Loader(string table, string column)
        {
            try
            {
                connection.Open();

                string sqlCommand = $"SELECT {column} FROM dbo.[{table}]";
                cmd    = new SqlCommand(sqlCommand, connection);
                reader = cmd.ExecuteReader();

                comboBox.Items.Clear();

                while (reader.Read())
                {
                    comboBox.Items.Add(reader[0].ToString());
                }
            }
            catch (SqlException sqlEx)
            {
                sB.Info(sqlEx.Message);
            }
            finally
            {
                connection.Close();
            }
        }
示例#3
0
 public void SqlQuery(string sqlCommand, string infoSuccess, string exceptionMessage)
 {
     try
     {
         connection.Open();
         cmd = new SqlCommand(sqlCommand, connection);
         cmd.ExecuteNonQuery();
         sB.Info(infoSuccess);
     }
     catch (Exception ex)
     {
         sB.Info(exceptionMessage);
         sB.Info(ex.Message);
     }
     finally
     {
         connection.Close();
     }
 }
示例#4
0
 public void Loader(string sqlCommand)
 {
     try
     {
         adapter   = new SqlDataAdapter(sqlCommand, connection);
         dataTable = new DataTable();
         adapter.Fill(dataTable);
         dataGrid.ItemsSource = dataTable.DefaultView;
     }
     catch (SqlException sqlEx)
     {
         sB.Info(sqlEx.Message);
     }
 }
示例#5
0
 private void dgRecipient_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (dgRecipient.SelectedItem != null)
     {
         id = dG.FirstColumn;
     }
     try
     {
         connection.Open();
         cmd = new SqlCommand($"SELECT FirstName, LastName, PhoneNumber, Email, Address FROM dbo.[Recipient]" +
                              $"WHERE[Id] = {id}", connection);
         reader = cmd.ExecuteReader();
         reader.Read();
         if (reader.HasRows)
         {
             tbEditFirstName.Text   = reader[0].ToString();
             tbEditLastName.Text    = reader[1].ToString();
             tbEditPhoneNumber.Text = reader[2].ToString();
             tbEditEmail.Text       = reader[3].ToString();
             tbEditAddress.Text     = reader[4].ToString();
         }
     }
     catch (SqlException sqlExc)
     {
         sB.Info(sqlExc.Message);
     }
     finally
     {
         connection.Close();
     }
 }
 private void dgOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (dgOrder.SelectedItem != null)
     {
         id = dG.FirstColumn;
     }
     try
     {
         connection.Open();
         cmd = new SqlCommand($"SELECT * FROM dbo.[OrderView]" +
                              $"WHERE [Id] = {id} " +
                              $"and [IdUser] = '{App.IdUser}'", connection);
         reader = cmd.ExecuteReader();
         reader.Read();
         if (reader.HasRows)
         {
             tbEditEmployee.Text         = reader[1].ToString();
             cbEditClient.Text           = reader[2].ToString();
             cbEditRecipient.Text        = reader[3].ToString();
             cbEditSupplier.Text         = reader[4].ToString();
             cbEditArticle.Text          = reader[5].ToString();
             tbEditShippingAddress.Text  = reader[6].ToString();
             cbEditSortingCenter.Text    = reader[7].ToString();
             tbEditRecipientAddress.Text = reader[8].ToString();
             cbEditNameOrderTiming.Text  = reader[9].ToString();
             tbEditPrice.Text            = reader[10].ToString();
         }
     }
     catch (SqlException sqlExc)
     {
         sB.Info(sqlExc.Message);
     }
     finally
     {
         connection.Close();
     }
 }
 private void btnAddEmployee_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(cbLogin.Text))
     {
         sB.Info("Введите логин");
     }
     else if (string.IsNullOrEmpty(tbFirstName.Text))
     {
         sB.Info("Введите имя");
     }
     else if (string.IsNullOrEmpty(tbLastName.Text))
     {
         sB.Info("Введите фамилию");
     }
     else if (string.IsNullOrEmpty(tbPhoneNumber.Text))
     {
         sB.Info("Введите номер телефона");
     }
     else if (string.IsNullOrEmpty(tbEmail.Text))
     {
         sB.Info("Введите email");
     }
     else
     {
         dataBaseQuery.SqlQuery("INSERT INTO dbo.[Employee] " +
                                $"VALUES ((SELECT Id FROM dbo.[User] WHERE [Login] = '{cbLogin.Text}'), '{tbFirstName.Text}', '{tbLastName.Text}'," +
                                $"'{tbPhoneNumber.Text}', '{tbEmail.Text}')",
                                "Данные успешно добавлены", "Пользователь с данным логином уже есть");
         cbLogin.Text = null;
         tbFirstName.Clear();
         tbLastName.Clear();
         tbEmail.Clear();
         tbPhoneNumber.Clear();
         dG.Loader("SELECT * FROM dbo.[EmployeeUser]");
     }
 }
示例#8
0
        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();
            }
        }
示例#9
0
 private void dgProduct_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (dgProduct.SelectedItem != null)
     {
         id = dG.FirstColumn;
     }
     try
     {
         connection.Open();
         cmd = new SqlCommand($"SELECT * FROM dbo.[ProductStrength]" +
                              $"WHERE[Id] = {id}", connection);
         reader = cmd.ExecuteReader();
         reader.Read();
         if (reader.HasRows)
         {
             tbEditArticle.Text    = reader[1].ToString();
             tbEditName.Text       = reader[2].ToString();
             tbEditDimensions.Text = reader[3].ToString();
             tbEditWeight.Text     = reader[4].ToString();
             cbEditStrength.Text   = reader[5].ToString();
             tbEditFeatures.Text   = reader[6].ToString();
         }
     }
     catch (SqlException sqlExc)
     {
         sB.Info(sqlExc.Message);
     }
     finally
     {
         connection.Close();
     }
 }