UpdateVehicle.cs 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 UpdateVehicle : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public UpdateVehicle()
  18. {
  19. InitializeComponent();
  20. }
  21. private void UpdateBtn_Click(object sender, EventArgs e)
  22. {
  23. query = new SqlCommand($"select code_executor from executors where (surname_executor + ' ' + name_executor + ' ' + midname_executor) like '{ExecutorsCB.SelectedItem}'", dbhelper.sqlConnection);
  24. string codeExecutor = query.ExecuteScalar().ToString();
  25. query = new SqlCommand($"select code_category from category_trailer where name_category like '{CategoryCB.SelectedItem}'", dbhelper.sqlConnection);
  26. string codeCategory = query.ExecuteScalar().ToString();
  27. 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);
  28. query.Parameters.AddWithValue("code_executor", codeExecutor);
  29. query.Parameters.AddWithValue("brand_vehicle", BrandTB.Text);
  30. query.Parameters.AddWithValue("model_vehicle", ModelTB.Text);
  31. query.Parameters.AddWithValue("number_vehicle", NumberMTB.Text);
  32. query.Parameters.AddWithValue("code_category", codeCategory);
  33. query.Parameters.AddWithValue("volume_body", VolumeNUD.Value);
  34. query.Parameters.AddWithValue("length_body", LengthNUD.Value);
  35. query.Parameters.AddWithValue("width_body", WidthNUD.Value);
  36. query.Parameters.AddWithValue("height_body", HeightNUD.Value);
  37. if (query.ExecuteNonQuery().ToString().Equals("1"))
  38. {
  39. MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  40. this.Close();
  41. }
  42. }
  43. private void UpdateVehicle_Load(object sender, EventArgs e)
  44. {
  45. query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
  46. reader = query.ExecuteReader();
  47. while (reader.Read())
  48. {
  49. ExecutorsCB.Items.Add(reader.GetString(0));
  50. }
  51. reader.Close();
  52. query = new SqlCommand("select name_category from Category_Trailer", dbhelper.sqlConnection);
  53. reader = query.ExecuteReader();
  54. while (reader.Read())
  55. {
  56. CategoryCB.Items.Add(reader.GetString(0));
  57. }
  58. reader.Close();
  59. 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);
  60. reader = query.ExecuteReader();
  61. reader.Read();
  62. int codeExecutor = reader.GetInt32(0);
  63. BrandTB.Text = reader.GetString(1);
  64. ModelTB.Text = reader.GetString(2);
  65. NumberMTB.Text = reader.GetString(3);
  66. int codeCategory = reader.GetInt32(4);
  67. VolumeNUD.Value = Convert.ToDecimal(reader.GetDouble(5));
  68. LengthNUD.Value = Convert.ToDecimal(reader.GetDouble(6));
  69. WidthNUD.Value = Convert.ToDecimal(reader.GetDouble(7));
  70. HeightNUD.Value = Convert.ToDecimal(reader.GetDouble(8));
  71. reader.Close();
  72. query = new SqlCommand($"select (surname_executor + ' ' + name_executor + ' ' + midname_executor) from Executors where code_executor like '{codeExecutor}'", dbhelper.sqlConnection);
  73. ExecutorsCB.SelectedItem = query.ExecuteScalar().ToString();
  74. query = new SqlCommand($"select name_category from category_trailer where code_category like '{codeCategory}'", dbhelper.sqlConnection);
  75. CategoryCB.SelectedItem = query.ExecuteScalar().ToString();
  76. }
  77. }
  78. }