private void btnDelete_Click(object sender, RoutedEventArgs e) { App.Id = classDataGrid.Selecter(); if (App.Id != null) { MessageBoxResult message = MessageBox.Show("Вы уверены, что хотите удалить?", "Уведмоление", MessageBoxButton.YesNo, MessageBoxImage.Question); switch (message) { case MessageBoxResult.Yes: try { connection.Open(); cmd = new SqlCommand("DELETE FROM [Fabric] " + $"WHERE [IdFabric] = '{App.Id}'", connection); cmd.ExecuteNonQuery(); } catch (Exception ex) { ClassMessageBox.MessageBoxError(ex.Message); } finally { connection.Close(); } break; } } else { ClassMessageBox.MessageBoxInfo("Выберите данные для удаления"); } }
private void btnEdit_Click(object sender, RoutedEventArgs e) { App.Id = classDataGrid.Selecter(); if (App.Id != null) { WinFabricEdit winFabricEdit = new WinFabricEdit(); winFabricEdit.ShowDialog(); } else { ClassMessageBox.MessageBoxInfo("Выберите данные для редактирования"); } }
private void btnReg_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 if (string.IsNullOrEmpty(pbPasswordSecond.Password)) { ClassMessageBox.MessageBoxInfo("Введите пароль"); pbPassword.Focus(); } else if (pbPassword.Password != pbPasswordSecond.Password) { ClassMessageBox.MessageBoxInfo("Введенные пароли не совпадают"); pbPassword.Focus(); } else { try { connection.Open(); cmd = new SqlCommand("INSERT INTO [User]" + "VALUES (@Login, @Password, @RoleId)", connection); cmd.Parameters.AddWithValue("Login", tbLogin.Text); cmd.Parameters.AddWithValue("Password", pbPassword.Password); cmd.Parameters.AddWithValue("RoleId", 1); cmd.ExecuteNonQuery(); ClassMessageBox.MessageBoxInfo("Вы успешно зарегистрировались"); } catch (Exception ex) { ClassMessageBox.MessageBoxError(ex.Message); } finally { connection.Close(); } } }
private void btnEdit_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbArticle.Text)) { ClassMessageBox.MessageBoxError("Введите артикул"); tbArticle.Focus(); } else if (string.IsNullOrEmpty(tbColor.Text)) { ClassMessageBox.MessageBoxError("Введите цвет"); tbColor.Focus(); } else if (string.IsNullOrEmpty(tbComposition.Text)) { ClassMessageBox.MessageBoxError("Введите композицию"); tbComposition.Focus(); } else if (string.IsNullOrEmpty(tbDrawing.Text)) { ClassMessageBox.MessageBoxError("Введите узор"); tbDrawing.Focus(); } else if (string.IsNullOrEmpty(tbLength.Text)) { ClassMessageBox.MessageBoxError("Введите длину"); tbLength.Focus(); } else if (string.IsNullOrEmpty(tbName.Text)) { ClassMessageBox.MessageBoxError("Введите наименование"); tbName.Focus(); } else if (string.IsNullOrEmpty(tbPrice.Text)) { ClassMessageBox.MessageBoxError("Введите цену"); tbPrice.Focus(); } else if (string.IsNullOrEmpty(tbWidth.Text)) { ClassMessageBox.MessageBoxError("Введите ширину"); tbWidth.Focus(); } else { try { connection.Open(); cmd = new SqlCommand("UPDATE [Fabric] " + "SET ArticleNumber = @ArticleNumber, " + "Name = @Name," + "Color = @Color," + "Drawing = @Drawing," + "Composition = @Composition, " + "Width = @Width," + "Length = @Length," + "Price = @Price " + $"WHERE [IdFabric] = {App.Id}", connection); cmd.Parameters.AddWithValue("ArticleNumber", tbArticle.Text); cmd.Parameters.AddWithValue("Name", tbName.Text); cmd.Parameters.AddWithValue("Color", tbColor.Text); cmd.Parameters.AddWithValue("Drawing", tbDrawing.Text); cmd.Parameters.AddWithValue("Composition", tbComposition.Text); cmd.Parameters.AddWithValue("Width", tbWidth.Text); cmd.Parameters.AddWithValue("Length", tbLength.Text); cmd.Parameters.AddWithValue("Price", double.Parse(tbPrice.Text)); cmd.ExecuteNonQuery(); ClassMessageBox.MessageBoxInfo("Вы успешно добавили товар"); } catch (Exception ex) { ClassMessageBox.MessageBoxError(ex.Message); } finally { connection.Close(); } } }
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(); } } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbArticle.Text)) { ClassMessageBox.MessageBoxError("Введите артикул"); tbArticle.Focus(); } else if (string.IsNullOrEmpty(tbColor.Text)) { ClassMessageBox.MessageBoxError("Введите цвет"); tbColor.Focus(); } else if (string.IsNullOrEmpty(tbComposition.Text)) { ClassMessageBox.MessageBoxError("Введите композицию"); tbComposition.Focus(); } else if (string.IsNullOrEmpty(tbDrawing.Text)) { ClassMessageBox.MessageBoxError("Введите узор"); tbDrawing.Focus(); } else if (string.IsNullOrEmpty(tbLength.Text)) { ClassMessageBox.MessageBoxError("Введите длину"); tbLength.Focus(); } else if (string.IsNullOrEmpty(tbName.Text)) { ClassMessageBox.MessageBoxError("Введите наименование"); tbName.Focus(); } else if (string.IsNullOrEmpty(tbPrice.Text)) { ClassMessageBox.MessageBoxError("Введите цену"); tbPrice.Focus(); } else if (string.IsNullOrEmpty(tbWidth.Text)) { ClassMessageBox.MessageBoxError("Введите ширину"); tbWidth.Focus(); } else { try { connection.Open(); cmd = new SqlCommand("INSERT INTO [Fabric] " + "(ArticleNumber, Name, Color, Drawing, " + "Composition, Width, Length, Price)" + "VALUES (@ArticleNumber, @Name," + " @Color, @Drawing, @Composition, " + "@Width, @Length, @Price)", connection); cmd.Parameters.AddWithValue("ArticleNumber", tbArticle.Text); cmd.Parameters.AddWithValue("Name", tbName.Text); cmd.Parameters.AddWithValue("Color", tbColor.Text); cmd.Parameters.AddWithValue("Drawing", tbDrawing.Text); cmd.Parameters.AddWithValue("Composition", tbComposition.Text); cmd.Parameters.AddWithValue("Width", tbWidth.Text); cmd.Parameters.AddWithValue("Length", tbLength.Text); cmd.Parameters.AddWithValue("Price", tbPrice.Text); cmd.ExecuteNonQuery(); ClassMessageBox.MessageBoxInfo("Вы успешно добавили товар"); } catch (Exception ex) { ClassMessageBox.MessageBoxError(ex.Message); } finally { connection.Close(); } } }