UpdateDrivers.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 UpdateDrivers : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public UpdateDrivers()
  18. {
  19. InitializeComponent();
  20. }
  21. private void UpdateDrivers_Load(object sender, EventArgs e)
  22. {
  23. // code_executor, surname_driver, name_driver, midname_driver, number_passport_driver, place_passport_driver, date_passport_driver, code_passport_driver, number_driverlicense, telephone_driver
  24. query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
  25. reader = query.ExecuteReader();
  26. while (reader.Read())
  27. {
  28. ExecutorsCB.Items.Add(reader.GetString(0));
  29. }
  30. reader.Close();
  31. query = new SqlCommand($"select code_executor, surname_driver, name_driver, midname_driver, number_passport_driver, place_passport_driver, date_passport_driver, code_passport_driver, number_driverlicense, telephone_driver from Drivers where code_driver like '{MainMenu.driverIndex}'", dbhelper.sqlConnection);
  32. reader = query.ExecuteReader();
  33. reader.Read();
  34. int codeExecutor = reader.GetInt32(0);
  35. SurnameDriverTB.Text = reader.GetString(1);
  36. NameDriverTB.Text = reader.GetString(2);
  37. MidnameDriverTB.Text = reader.GetString(3);
  38. NumberPassportDriverMTB.Text = reader.GetString(4);
  39. PlacePassportDriverRTB.Text = reader.GetString(5);
  40. DatePassportDriverDTP.Value = reader.GetDateTime(6);
  41. CodePassportDriverMTB.Text = reader.GetString(7);
  42. NumberDriverLicenseMTB.Text = reader.GetString(8);
  43. TelephoneDriverMTB.Text = reader.GetString(9);
  44. reader.Close();
  45. query = new SqlCommand($"select (surname_executor + ' ' + name_executor + ' ' + midname_executor) from Executors where code_executor like '{codeExecutor}'", dbhelper.sqlConnection);
  46. ExecutorsCB.SelectedItem = query.ExecuteScalar().ToString();
  47. }
  48. private void UpdateBTN_Click(object sender, EventArgs e)
  49. {
  50. query = new SqlCommand($"select code_executor from executors where (surname_executor + ' ' + name_executor + ' ' + midname_executor) like '{ExecutorsCB.SelectedItem}'", dbhelper.sqlConnection);
  51. string codeExecutor = query.ExecuteScalar().ToString();
  52. query = new SqlCommand($"update Drivers set code_executor = @code_executor, surname_driver = @surname_driver, name_driver = @name_driver, midname_driver = @midname_driver, number_passport_driver = @number_passport_driver, place_passport_driver = @place_passport_driver, date_passport_driver = @date_passport_driver, code_passport_driver = @code_passport_driver, number_driverlicense = @number_driverlicense, telephone_driver = @telephone_driver where code_driver like '{MainMenu.driverIndex}'", dbhelper.sqlConnection);
  53. query.Parameters.AddWithValue("code_executor", codeExecutor);
  54. query.Parameters.AddWithValue("surname_driver", SurnameDriverTB.Text);
  55. query.Parameters.AddWithValue("name_driver", NameDriverTB.Text);
  56. query.Parameters.AddWithValue("midname_driver", MidnameDriverTB.Text);
  57. query.Parameters.AddWithValue("number_passport_driver", NumberPassportDriverMTB.Text);
  58. query.Parameters.AddWithValue("place_passport_driver", PlacePassportDriverRTB.Text);
  59. query.Parameters.AddWithValue("date_passport_driver", DatePassportDriverDTP.Value);
  60. query.Parameters.AddWithValue("code_passport_driver", CodePassportDriverMTB.Text);
  61. query.Parameters.AddWithValue("number_driverlicense", NumberDriverLicenseMTB.Text);
  62. query.Parameters.AddWithValue("telephone_driver", TelephoneDriverMTB.Text);
  63. if (query.ExecuteNonQuery().ToString().Equals("1"))
  64. {
  65. MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  66. this.Close();
  67. }
  68. }
  69. }
  70. }