using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; using MySql.Data.MySqlClient; namespace demMalyhin { public partial class AdmEditOrder : Form { private string productId; public AdmEditOrder(string productId) { InitializeComponent(); LoadProductData(productId); LoadPickup(); LoadStatus(); } private void LoadProductData(string productId) { try { DB db = new DB(); using (MySqlConnection connection = db.getConnection()) { connection.Open(); string query = "SELECT order_date, delivery_date, pickup_point_id, user_initials_id, code, orderstatus_id FROM Orders WHERE id_Orders = @id"; using (MySqlCommand command = new MySqlCommand(query, connection)) { command.Parameters.AddWithValue("@id", productId); using (MySqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { textBoxId.Text = productId; textBoxDate.Text = reader["order_date"].ToString(); textBoxDelivery.Text = reader["delivery_date"].ToString(); comboBoxPoint.Text = reader["pickup_point_id"].ToString(); textBoxCode.Text = reader["code"].ToString(); comboBoxStatus.Text = reader["orderstatus_id"].ToString(); } else { MessageBox.Show("Продукт с указанным ID не найден."); this.DialogResult = DialogResult.Cancel; this.Close(); } } } } } catch (MySqlException ex) { MessageBox.Show("Ошибка при загрузке данных продукта: " + ex.Message); } } private void LoadPickup() { try { DB db = new DB(); using (MySqlConnection connection = db.getConnection()) { connection.Open(); string query = "SELECT idpickup_points, pickup_points.index FROM pickup_points"; using (MySqlCommand command = new MySqlCommand(query, connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { DataTable categoryTable = new DataTable(); categoryTable.Load(reader); comboBoxPoint.DataSource = categoryTable; comboBoxPoint.DisplayMember = "index"; comboBoxPoint.ValueMember = "idpickup_points"; } } } } catch (MySqlException ex) { MessageBox.Show("Ошибка при загрузке категорий: " + ex.Message); } } private void LoadStatus() { try { DB db = new DB(); using (MySqlConnection connection = db.getConnection()) { connection.Open(); string query = "SELECT id_OrderStatus, status_name FROM OrderStatus"; using (MySqlCommand command = new MySqlCommand(query, connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { DataTable statusTable = new DataTable(); statusTable.Load(reader); comboBoxStatus.DataSource = statusTable; comboBoxStatus.DisplayMember = "status_name"; comboBoxStatus.ValueMember = "id_OrderStatus"; } } } } catch (MySqlException ex) { MessageBox.Show("Ошибка при загрузке категорий: " + ex.Message); } } private void button3_Click(object sender, EventArgs e) { try { object supplierId = comboBoxStatus.SelectedValue; object manufacturerId = comboBoxPoint.SelectedValue; DB db = new DB(); using (MySqlConnection connection = db.getConnection()) { connection.Open(); string query = "UPDATE Orders SET order_date = @od, delivery_date = @dd, pickup_point_id = @point, orderstatus_id = @status, Orders.code = @code WHERE id_Orders = @id"; using (MySqlCommand command = new MySqlCommand(query, connection)) { command.Parameters.AddWithValue("@id", textBoxId.Text); command.Parameters.AddWithValue("@od", textBoxDate.Text); command.Parameters.AddWithValue("@dd", textBoxDelivery.Text); command.Parameters.AddWithValue("@code", textBoxCode.Text); command.Parameters.AddWithValue("@status", supplierId); command.Parameters.AddWithValue("@point", manufacturerId); int rowsAffected = command.ExecuteNonQuery(); if (rowsAffected > 0) { MessageBox.Show("Данные продукта успешно обновлены."); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("Не удалось обновить данные продукта."); } } } } catch (MySqlException ex) { MessageBox.Show("Ошибка при сохранении данных продукта: " + ex.Message); } } } }