AddVehicle.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace Transportation
  12. {
  13. public partial class AddVehicle : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public AddVehicle()
  18. {
  19. InitializeComponent();
  20. }
  21. private void AddVehicle_Load(object sender, EventArgs e)
  22. {
  23. query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
  24. reader = query.ExecuteReader();
  25. while(reader.Read())
  26. {
  27. ExecutorsCB.Items.Add(reader.GetString(0));
  28. }
  29. reader.Close();
  30. query = new SqlCommand("select name_category from Category_Trailer", dbhelper.sqlConnection);
  31. reader = query.ExecuteReader();
  32. while (reader.Read())
  33. {
  34. CategoryCB.Items.Add(reader.GetString(0));
  35. }
  36. reader.Close();
  37. }
  38. private void AddBtn_Click(object sender, EventArgs e)
  39. {
  40. query = new SqlCommand($"select code_executor from executors where (surname_executor + ' ' + name_executor + ' ' + midname_executor) like '{ExecutorsCB.SelectedItem}'", dbhelper.sqlConnection);
  41. string codeExecutor = query.ExecuteScalar().ToString();
  42. query = new SqlCommand($"select code_category from category_trailer where name_category like '{CategoryCB.SelectedItem}'", dbhelper.sqlConnection);
  43. string codeCategory = query.ExecuteScalar().ToString();
  44. 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);
  45. query.Parameters.AddWithValue("code_executor", codeExecutor);
  46. query.Parameters.AddWithValue("brand_vehicle", BrandTB.Text);
  47. query.Parameters.AddWithValue("model_vehicle", ModelTB.Text);
  48. query.Parameters.AddWithValue("number_vehicle", NumberMTB.Text);
  49. query.Parameters.AddWithValue("code_category", codeCategory);
  50. query.Parameters.AddWithValue("volume_body", VolumeNUD.Value);
  51. query.Parameters.AddWithValue("length_body", LengthNUD.Value);
  52. query.Parameters.AddWithValue("width_body", WidthNUD.Value);
  53. query.Parameters.AddWithValue("height_body", HeightNUD.Value);
  54. if(query.ExecuteNonQuery().ToString().Equals("1"))
  55. {
  56. MessageBox.Show("Добавление прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  57. this.Close();
  58. }
  59. }
  60. }
  61. }