AddDriver.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 AddDriver : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public AddDriver()
  18. {
  19. InitializeComponent();
  20. }
  21. private void AddBTN_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("insert into drivers (code_executor, surname_driver, name_driver, midname_driver, number_passport_driver, place_passport_driver, date_passport_driver, code_passport_driver, number_driverlicense, telephone_driver) values (@code_executor, @surname_driver, @name_driver, @midname_driver, @number_passport_driver, @place_passport_driver, @date_passport_driver, @code_passport_driver, @number_driverlicense, @telephone_driver)", dbhelper.sqlConnection);
  26. query.Parameters.AddWithValue("code_executor", codeExecutor);
  27. query.Parameters.AddWithValue("surname_driver", SurnameDriverTB.Text);
  28. query.Parameters.AddWithValue("name_driver", NameDriverTB.Text);
  29. query.Parameters.AddWithValue("midname_driver", MidnameDriverTB.Text);
  30. query.Parameters.AddWithValue("number_passport_driver", NumberPassportDriverMTB.Text);
  31. query.Parameters.AddWithValue("place_passport_driver", PlacePassportDriverRTB.Text);
  32. query.Parameters.AddWithValue("date_passport_driver", DatePassportDriverDTP.Value);
  33. query.Parameters.AddWithValue("code_passport_driver", CodePassportDriverMTB.Text);
  34. query.Parameters.AddWithValue("number_driverlicense", NumberDriverLicenseMTB.Text);
  35. query.Parameters.AddWithValue("telephone_driver", TelephoneDriverMTB.Text);
  36. if (query.ExecuteNonQuery().ToString().Equals("1"))
  37. {
  38. MessageBox.Show("Добавление прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  39. this.Close();
  40. }
  41. }
  42. private void AddDriver_Load(object sender, EventArgs e)
  43. {
  44. query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
  45. reader = query.ExecuteReader();
  46. while (reader.Read())
  47. {
  48. ExecutorsCB.Items.Add(reader.GetString(0));
  49. }
  50. reader.Close();
  51. }
  52. }
  53. }