UpdateLogistician.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 UpdateLogistician : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public UpdateLogistician()
  18. {
  19. InitializeComponent();
  20. }
  21. private void UpdateBTN_Click(object sender, EventArgs e)
  22. {
  23. query = new SqlCommand($"update Logisticians set surname_logistician = @surname_logistician, name_logistician = @name_logistician, midname_logistician = @midname_logistician, number_passport_logistician = @number_passport_logistician, place_passport_logistician = @place_passport_logistician, date_passport_logistician = @date_passport_logistician, code_passport_logistician = @code_passport_logistician, telephone_logistician = @telephone_logistician where code_logistician like '{MainMenu.logisticianIndex}'", dbhelper.sqlConnection);
  24. query.Parameters.AddWithValue("surname_logistician", SurnameLogisticianTB.Text);
  25. query.Parameters.AddWithValue("name_logistician", NameLogisticianTB.Text);
  26. query.Parameters.AddWithValue("midname_logistician", MidnameLogisticianTB.Text);
  27. query.Parameters.AddWithValue("number_passport_logistician", NumberPassportLogisticianMTB.Text);
  28. query.Parameters.AddWithValue("place_passport_logistician", PlacePassportLogisticianRTB.Text);
  29. query.Parameters.AddWithValue("date_passport_logistician", DatePassportLogisticianDTP.Value);
  30. query.Parameters.AddWithValue("code_passport_logistician", CodePassportLogisticianMTB.Text);
  31. query.Parameters.AddWithValue("telephone_logistician", TelephoneLogisticianMTB.Text);
  32. if (query.ExecuteNonQuery().ToString().Equals("1"))
  33. {
  34. MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  35. this.Close();
  36. }
  37. }
  38. private void UpdateLogistician_Load(object sender, EventArgs e)
  39. {
  40. query = new SqlCommand($"select surname_logistician, name_logistician, midname_logistician, number_passport_logistician, place_passport_logistician, date_passport_logistician, code_passport_logistician, telephone_logistician from Logisticians where code_logistician like '{MainMenu.logisticianIndex}'", dbhelper.sqlConnection);
  41. reader = query.ExecuteReader();
  42. reader.Read();
  43. SurnameLogisticianTB.Text = reader.GetString(0);
  44. NameLogisticianTB.Text = reader.GetString(1);
  45. MidnameLogisticianTB.Text = reader.GetString(2);
  46. NumberPassportLogisticianMTB.Text = reader.GetString(3);
  47. PlacePassportLogisticianRTB.Text = reader.GetString(4);
  48. DatePassportLogisticianDTP.Value = reader.GetDateTime(5);
  49. CodePassportLogisticianMTB.Text = reader.GetString(6);
  50. TelephoneLogisticianMTB.Text = reader.GetString(7);
  51. reader.Close();
  52. }
  53. }
  54. }