UpdateExecutor.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 UpdateExecutor : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public UpdateExecutor()
  18. {
  19. InitializeComponent();
  20. }
  21. private void UpdateExecutor_Load(object sender, EventArgs e)
  22. {
  23. query = new SqlCommand($"select surname_executor as 'Фамилия исполнителя', name_executor as 'Имя исполнителя', midname_executor as 'Отчество исполнителя' from Executors where code_executor like '{MainMenu.executorIndex}'", dbhelper.sqlConnection);
  24. reader = query.ExecuteReader();
  25. reader.Read();
  26. SurnameExecutorTB.Text = reader.GetString(0);
  27. NameExecutorTB.Text = reader.GetString(1);
  28. MidnameExecutorTB.Text = reader.GetString(2);
  29. reader.Close();
  30. }
  31. private void UpdateBTN_Click(object sender, EventArgs e)
  32. {
  33. query = new SqlCommand($"update executors set surname_executor = @surname_executor, name_executor = @name_executor, midname_executor = @midname_executor where code_executor like '{MainMenu.executorIndex}'", dbhelper.sqlConnection);
  34. query.Parameters.AddWithValue("surname_executor", SurnameExecutorTB.Text);
  35. query.Parameters.AddWithValue("name_executor", NameExecutorTB.Text);
  36. query.Parameters.AddWithValue("midname_executor", MidnameExecutorTB.Text);
  37. if (query.ExecuteNonQuery().ToString().Equals("1"))
  38. {
  39. MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  40. this.Close();
  41. }
  42. }
  43. }
  44. }