1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace Transportation
- {
- public partial class UpdateVehicle : Form
- {
- SqlCommand query = null;
- SqlDataReader reader = null;
- public UpdateVehicle()
- {
- InitializeComponent();
- }
- private void UpdateBtn_Click(object sender, EventArgs e)
- {
- query = new SqlCommand($"select code_executor from executors where (surname_executor + ' ' + name_executor + ' ' + midname_executor) like '{ExecutorsCB.SelectedItem}'", dbhelper.sqlConnection);
- string codeExecutor = query.ExecuteScalar().ToString();
- query = new SqlCommand($"select code_category from category_trailer where name_category like '{CategoryCB.SelectedItem}'", dbhelper.sqlConnection);
- string codeCategory = query.ExecuteScalar().ToString();
- query = new SqlCommand($"update Vehicles set code_executor = @code_executor, brand_vehicle = @brand_vehicle, model_vehicle = @model_vehicle, number_vehicle = @number_vehicle, code_category = @code_category, volume_body = @volume_body, length_body = @length_body, width_body = @width_body, height_body = @height_body where code_vehicle like '{MainMenu.vehicleIndex}'", dbhelper.sqlConnection);
- query.Parameters.AddWithValue("code_executor", codeExecutor);
- query.Parameters.AddWithValue("brand_vehicle", BrandTB.Text);
- query.Parameters.AddWithValue("model_vehicle", ModelTB.Text);
- query.Parameters.AddWithValue("number_vehicle", NumberMTB.Text);
- query.Parameters.AddWithValue("code_category", codeCategory);
- query.Parameters.AddWithValue("volume_body", VolumeNUD.Value);
- query.Parameters.AddWithValue("length_body", LengthNUD.Value);
- query.Parameters.AddWithValue("width_body", WidthNUD.Value);
- query.Parameters.AddWithValue("height_body", HeightNUD.Value);
- if (query.ExecuteNonQuery().ToString().Equals("1"))
- {
- MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- }
- private void UpdateVehicle_Load(object sender, EventArgs e)
- {
-
- query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
- reader = query.ExecuteReader();
- while (reader.Read())
- {
- ExecutorsCB.Items.Add(reader.GetString(0));
- }
- reader.Close();
- query = new SqlCommand("select name_category from Category_Trailer", dbhelper.sqlConnection);
- reader = query.ExecuteReader();
- while (reader.Read())
- {
- CategoryCB.Items.Add(reader.GetString(0));
- }
- reader.Close();
- query = new SqlCommand($"select code_executor, brand_vehicle, model_vehicle, number_vehicle, code_category, volume_body, length_body, width_body, height_body from Vehicles where code_vehicle like '{MainMenu.vehicleIndex}'", dbhelper.sqlConnection);
- reader = query.ExecuteReader();
- reader.Read();
- int codeExecutor = reader.GetInt32(0);
- BrandTB.Text = reader.GetString(1);
- ModelTB.Text = reader.GetString(2);
- NumberMTB.Text = reader.GetString(3);
- int codeCategory = reader.GetInt32(4);
- VolumeNUD.Value = Convert.ToDecimal(reader.GetDouble(5));
- LengthNUD.Value = Convert.ToDecimal(reader.GetDouble(6));
- WidthNUD.Value = Convert.ToDecimal(reader.GetDouble(7));
- HeightNUD.Value = Convert.ToDecimal(reader.GetDouble(8));
- reader.Close();
- query = new SqlCommand($"select (surname_executor + ' ' + name_executor + ' ' + midname_executor) from Executors where code_executor like '{codeExecutor}'", dbhelper.sqlConnection);
- ExecutorsCB.SelectedItem = query.ExecuteScalar().ToString();
- query = new SqlCommand($"select name_category from category_trailer where code_category like '{codeCategory}'", dbhelper.sqlConnection);
- CategoryCB.SelectedItem = query.ExecuteScalar().ToString();
- }
- }
- }
|