12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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 AddVehicle : Form
- {
- SqlCommand query = null;
- SqlDataReader reader = null;
- public AddVehicle()
- {
- InitializeComponent();
- }
- private void AddVehicle_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();
- }
- private void AddBtn_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("insert into vehicles (code_executor, brand_vehicle, model_vehicle, number_vehicle, code_category, volume_body, length_body, width_body, height_body) values (@code_executor, @brand_vehicle, @model_vehicle, @number_vehicle, @code_category, @volume_body, @length_body, @width_body, @height_body)", 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();
- }
- }
- }
- }
|