private void Button_accept_Click(object sender, RoutedEventArgs e) { int dot_count1 = TextBox_product_amount.Text.Split('.').Length - 1; int dot_count2 = TextBox_average_purchase_price.Text.Split('.').Length - 1; if (ComboBox_product_name.Text != "" && TextBox_product_amount.Text != "" && ComboBox_supplier.Text != "" && TextBox_average_purchase_price.Text != "" && dot_count1 <= 1 && dot_count2 <= 1) { string count = Shortcuts.get_one_string_data_from($"SELECT count(*) FROM " + $"`storage` WHERE `product_name` = '{ComboBox_product_name.Text}' AND " + $"`supplier` = '{ComboBox_supplier.Text}';", connection); if (int.Parse(count) >= 1 && mode == QueryMode.add) { MessageBox.Show("Уже существует запись с такой краской и поставщиком!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } bool success = true; string measurement = Shortcuts.get_one_string_data_from($"SELECT `measurement` FROM `products` where `name` = '{ComboBox_product_name.Text}';", connection); switch (mode) { case QueryMode.add: success = Shortcuts.execute_command($"INSERT INTO `storage` (`id`, `product_name`, `product_amount`, `measurement`, `supplier`, `average_purchase_price`) " + $"VALUES (DEFAULT, '{ComboBox_product_name.Text}', {TextBox_product_amount.Text}, '{measurement}', " + $"'{ComboBox_supplier.Text}', {TextBox_average_purchase_price.Text});", connection); break; case QueryMode.change: success = Shortcuts.change("storage", new string[] { "id", "product_name", "product_amount", "measurement", "supplier", "average_purchase_price" }, new string[] { primary_key_value, ComboBox_product_name.Text, TextBox_product_amount.Text, measurement, ComboBox_supplier.Text, TextBox_average_purchase_price.Text }, primary_key_value, connection); break; } if (success) { parent.Focus(); if (parent is MainWindow) { ((MainWindow)parent).fill_table(); } if (parent is SupplyManagerWindow) { ((SupplyManagerWindow)parent).fill_table(); } Close(); } } else { MessageBox.Show("Заполните корректно все числовые поля и поля с выбором!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
//Удаление выбранной записи private void Button_delete_Click(object sender, RoutedEventArgs e) { object item = DataGrid.SelectedItem; if (item != null) { switch (current_table) { case Tables.requests: if (((Request)item).request_status == "Обработано") { MessageBox.Show("Нельзя удалить обработанную заявку!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (confirm_action("Вы хотите удалить текущий объект?", "Удаление")) { Shortcuts.execute_command($@"DELETE FROM `requests` where `id` = '{((Request)item).id}';", connection); fill_table(); } break; case Tables.cars: if (confirm_action("Вы хотите удалить текущий объект?", "Удаление")) { Shortcuts.execute_command($@"DELETE FROM `cars` where `vin` = '{((Car)item).vin}';", connection); fill_table(); } break; case Tables.clients: if (confirm_action("Вы хотите удалить текущий объект?", "Удаление")) { Shortcuts.execute_command($@"DELETE FROM `clients` where `mail` = '{((Client)item).mail}';", connection); fill_table(); } break; } TextBox_search.Text = ""; fill_table(); } else { MessageBox.Show("Выберите мышью запись перед удалением."); } }
//Удаление выбранной записи private void Button_delete_Click(object sender, RoutedEventArgs e) { object item = DataGrid.SelectedItem; if (item != null) { string item_name = ""; switch (current_table) { case Tables.suppliers: item_name = ((Supplier)item).name; break; case Tables.supplies: if (((Supply)item).user_mail != current_user.mail) { MessageBox.Show("Вы не можете удалять чужие поставки!", "Запрещено", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (((Supply)item).delivery_date != "") { MessageBox.Show("Нельзя удалить зачисленную поставку!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } item_name = ((Supply)item).id.ToString(); break; } if (confirm_action("Вы хотите удалить текущий объект?", "Удаление")) { Shortcuts.execute_command($@"DELETE FROM `{tables[(int)current_table]}` where `{current_primary_key_name}` = '{item_name}';", connection); TextBox_search.Text = ""; fill_table(); } } else { MessageBox.Show("Выберите мышью запись перед удалением."); } }
//Удаление выбранной записи private void Button_delete_Click(object sender, RoutedEventArgs e) { object item = DataGrid.SelectedItem; if (item != null) { string item_name = primary_key_values[DataGrid.Items.IndexOf(item)]; if (current_table == Tables.users && item_name == current_user.mail) { MessageBox.Show("Вы не можете удалить свой аккаунт."); return; } if (current_table == Tables.measurements) { switch (((Measurement)item).measurement) { case "литр": case "рулон": MessageBox.Show("Вы не можете удалять записи, используемые в системе."); return; } } if (current_table == Tables.request_statuses) { switch (((Request_status)item).request_status) { case "Обработано": case "Ожидает обработки": MessageBox.Show("Вы не можете удалять записи, используемые в системе."); return; } } if (current_table == Tables.roles) { switch (((Role)item).role) { case "администратор": case "менеджер по заявкам": case "менеджер по поставкам": MessageBox.Show("Вы не можете удалять записи, используемые в системе."); return; } } if (current_table == Tables.service_types) { switch (((Service_type)item).service_type) { case "Аэрография": case "Детальная": case "Оклейка плёнкой": case "Полная": MessageBox.Show("Вы не можете удалять записи, используемые в системе."); return; } } if (confirm_action("Вы хотите удалить текущий объект?", "Удаление")) { string primary_key_value = DataGrid.SelectedItem.ToString().Split(' ')[0]; switch (current_table) { case Tables.cars: primary_key_value = ((Car)item).vin; break; case Tables.cities: primary_key_value = ((City)item).city; break; case Tables.clients: primary_key_value = ((Client)item).mail; break; case Tables.colors: primary_key_value = ((Color)item).color_code; break; case Tables.genders: primary_key_value = ((Gender)item).gender; break; case Tables.measurements: primary_key_value = ((Measurement)item).measurement; break; case Tables.paint_types: primary_key_value = ((Paint_type)item).paint_type; break; case Tables.pictures: primary_key_value = ((Picture)item).name; break; case Tables.products: primary_key_value = ((Product)item).name; break; case Tables.requests: primary_key_value = ((Request)item).id.ToString(); break; case Tables.request_statuses: primary_key_value = ((Request_status)item).request_status; break; case Tables.roles: primary_key_value = ((Role)item).role; break; case Tables.service_types: primary_key_value = ((Service_type)item).service_type; break; case Tables.storage: primary_key_value = ((Storage)item).id.ToString(); break; case Tables.suppliers: primary_key_value = ((Supplier)item).name; break; case Tables.supplies: primary_key_value = ((Supply)item).id.ToString(); break; case Tables.users: primary_key_value = ((User)item).mail; break; } Shortcuts.execute_command($@"DELETE FROM `{tables[(int)current_table]}` where `{current_primary_key_name}` = '{primary_key_value}';", connection); TextBox_search.Text = ""; fill_table(); } } else { MessageBox.Show("Выберите мышью запись перед удалением."); } }
private void button_accept_request_Click(object sender, RoutedEventArgs e) { bool success = true; if (DataGrid.SelectedItem != null) { Request req = (Request)DataGrid.SelectedItem; if (req.request_status == "Обработано") { MessageBox.Show("Данная заявка уже обработана!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } else if (req.service_type == "Аэрография") { success = Shortcuts.execute_command("UPDATE `requests` " + "SET `request_status` = 'Обработано', " + $"`paint_date` = '{DateTime.Now:yyyy-MM-dd HH:mm:ss}' " + $"WHERE `id` = {req.id};", connection); fill_table(); if (success) { MessageBox.Show("Заявка успешно обработана!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information); } } else { int parts = req.parts_to_paint; string measurement = Shortcuts.get_one_string_data_from($"SELECT `measurement`" + $"FROM `storage` WHERE `product_name` = '{req.product_name}'", connection); decimal paint_amount; if (req.service_type == "Детальная") { paint_amount = decimal.Parse(Shortcuts.get_one_string_data_from($"SELECT SUM(`surface_size`) FROM `car_parts` " + $"WHERE `id` & {parts};", connection)) / 1000; } else { paint_amount = decimal.Parse(Shortcuts.get_one_string_data_from($"SELECT SUM(`surface_size`) FROM `car_parts`;", connection)) / 1000; } int prod_available = int.Parse(Shortcuts.get_one_string_data_from($"SELECT count(*) FROM `storage` " + $"WHERE `product_name` = '{req.product_name}' AND `supplier` = '{req.supplier}';", connection)); decimal paint_cost; switch (prod_available) { case 1: paint_cost = paint_amount * decimal.Parse(Shortcuts.get_one_string_data_from("SELECT `average_purchase_price` " + $"FROM `storage` WHERE `product_name` = '{req.product_name}';", connection)); //Всё норм success = Shortcuts.execute_command("UPDATE `storage` " + $"SET `product_amount` = (`product_amount` - {paint_amount.ToString().Replace(',','.')}) " + $"WHERE `product_name` = '{req.product_name}' AND `supplier` = '{req.supplier}';", connection); success = Shortcuts.execute_command("UPDATE `requests` " + $"SET `request_status` = 'Обработано', " + $"`paint_amount` = {paint_amount.ToString().Replace(',','.')}, " + $"`measurement` = '{measurement}', " + $"`paint_cost` = {paint_cost.ToString().Replace(',', '.')}, " + $"`paint_date` = '{DateTime.Now:yyyy-MM-dd HH:mm:ss}' " + $"WHERE `id` = {req.id};", connection); fill_table(); if (success) { MessageBox.Show("Заявка успешно обработана!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information); } break; case 0: MessageBox.Show("На складе отсутствует краска соответствующего поставщика!", "Нет краски", MessageBoxButton.OK, MessageBoxImage.Exclamation); break; default: MessageBox.Show("Произошла ошибка в базе!\nПовторяющиеся записи продукта на одного поставщика. " + "Обратитесь к администратору", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); break; } } } else { MessageBox.Show("Выберите мышью запись перед изменением."); } }
private void Button_accept_Click(object sender, RoutedEventArgs e) { //Количество точек в введённых числах int dot_count1 = TextBox_product_amount.Text.Split('.').Length - 1; int dot_count2 = TextBox_price.Text.Split('.').Length - 1; if (ComboBox_supplier.Text != "" && (string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag != "" && TextBox_product_amount.Text != "" && TextBox_price.Text != "" && DatePicker_order.SelectedDate.HasValue && dot_count1 <= 1 && dot_count2 <= 1) { string mail = ""; if (parent is MainWindow) { mail = ((MainWindow)parent).current_user.mail; } else if (parent is SupplyManagerWindow) { mail = ((SupplyManagerWindow)parent).current_user.mail; } string measurement = Shortcuts.get_one_string_data_from($"SELECT `measurement` FROM `products` where `name` = '{(string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag}';", connection); bool success = true; switch (mode) { case QueryMode.add: success = Shortcuts.execute_command($"INSERT INTO `supplies` (`id`, `user_mail`, `supplier`, " + $"`product_name`, `product_amount`, `measurement`, `price`, " + $"`order_date`, `delivery_date`) " + $"VALUES (DEFAULT, '{mail}', '{ComboBox_supplier.Text}', " + $"'{(string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag}', {TextBox_product_amount.Text}, '{measurement}', {TextBox_price.Text}, " + $"'{DatePicker_order.SelectedDate.Value:yyyy-MM-dd}', " + $"NULL);", connection); break; case QueryMode.change: success = Shortcuts.execute_command($"UPDATE `supplies` " + $"SET " + $"`user_mail` = '{mail}', " + $"`supplier` = '{ComboBox_supplier.Text}', " + $"`product_name` = '{(string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag}', " + $"`product_amount` = '{TextBox_product_amount.Text}'," + $"`measurement` = '{measurement}', " + $"`price` = '{TextBox_price.Text}', " + $"`order_date` = '{DatePicker_order.SelectedDate.Value:yyyy-MM-dd}' " + $"WHERE `id` = {primary_key_value}", connection); break; } if (success) { parent.Focus(); if (parent is MainWindow) { ((MainWindow)parent).fill_table(); } if (parent is SupplyManagerWindow) { ((SupplyManagerWindow)parent).fill_table(); } Close(); } } else { MessageBox.Show("Заполните корректно все числовые поля, поля с выбором и даты!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void button_delivery_supply_Click(object sender, RoutedEventArgs e) { if (DataGrid.SelectedItem == null) { MessageBox.Show("Выберите мышью запись перед совершением поставки."); } else { bool success = true; Supply sup = (Supply)DataGrid.SelectedItem; if (sup.delivery_date != "") { MessageBox.Show("Данная поставка уже зачислена!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } int product_storage_count = int.Parse(Shortcuts.get_one_string_data_from($"SELECT count(*) FROM " + $"`storage` WHERE `product_name` = '{sup.product_name}' AND " + $"`supplier` = '{sup.supplier}';", connection)); if (product_storage_count == 1) { //Записать в существующего поставщика Storage st = new Storage(); try { connection.Open(); MySqlCommand comm = new MySqlCommand("SELECT * FROM " + $"`storage` WHERE `product_name` = '{sup.product_name}' AND " + $"`supplier` = '{sup.supplier}';", connection); MySqlDataReader data = comm.ExecuteReader(); data.Read(); string[] values = new string[data.FieldCount]; for (int i = 0; i < data.FieldCount; i++) { values[i] = data[i].ToString(); } st = (Storage)Container_controller.Create_struct(Tables.storage, values); } catch (Exception ex) { success = false; MessageBox.Show(ex.Message); } finally { connection.Close(); } decimal new_prod_amount = st.product_amount + sup.product_amount; decimal new_price = ((st.average_purchase_price * st.product_amount) + sup.price * sup.product_amount) / (new_prod_amount); success = Shortcuts.execute_command("UPDATE `storage` SET " + $"`average_purchase_price` = {new_price.ToString().Replace(',', '.')}, " + $"`product_amount` = {new_prod_amount.ToString().Replace(',', '.')} " + $"WHERE `product_name` = '{sup.product_name.ToString().Replace(',', '.')}' AND " + $"`supplier` = '{sup.supplier}';", connection); success = Shortcuts.execute_command("UPDATE `supplies` SET " + $"`delivery_date` = '{DateTime.Now:yyyy-MM-dd}' " + $"WHERE `id` = {sup.id};", connection); if (success) { MessageBox.Show("Поставка на склад произведена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Поставка не произведена!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (product_storage_count == 0) { success = Shortcuts.execute_command("INSERT INTO `storage` " + "(`product_name`, `product_amount`, " + "`measurement`, `supplier`, `average_purchase_price`) VALUES " + $"('{sup.product_name}', {sup.product_amount.ToString().Replace(',','.')}, " + $"'{sup.measurement}', '{sup.supplier}', {(sup.price).ToString().Replace(',', '.')});", connection); success = Shortcuts.execute_command("UPDATE `supplies` SET " + $"`delivery_date` = '{DateTime.Now:yyyy-MM-dd}' " + $"WHERE `id` = {sup.id};", connection); if (success) { MessageBox.Show("Поставка на склад произведена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Поставка не произведена!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Произошла ошибка в базе!\nПовторяющиеся записи продукта на одного поставщика. " + "Обратитесь к администратору", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } fill_table(); } }