123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace Transportation
- {
- public partial class UpdateDrivers : Form
- {
- SqlCommand query = null;
- SqlDataReader reader = null;
- public UpdateDrivers()
- {
- InitializeComponent();
- }
- private void UpdateDrivers_Load(object sender, EventArgs e)
- {
- // code_executor, surname_driver, name_driver, midname_driver, number_passport_driver, place_passport_driver, date_passport_driver, code_passport_driver, number_driverlicense, telephone_driver
- query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
- reader = query.ExecuteReader();
- while (reader.Read())
- {
- ExecutorsCB.Items.Add(reader.GetString(0));
- }
- reader.Close();
- 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);
- reader = query.ExecuteReader();
- reader.Read();
- int codeExecutor = reader.GetInt32(0);
- SurnameDriverTB.Text = reader.GetString(1);
- NameDriverTB.Text = reader.GetString(2);
- MidnameDriverTB.Text = reader.GetString(3);
- NumberPassportDriverMTB.Text = reader.GetString(4);
- PlacePassportDriverRTB.Text = reader.GetString(5);
- DatePassportDriverDTP.Value = reader.GetDateTime(6);
- CodePassportDriverMTB.Text = reader.GetString(7);
- NumberDriverLicenseMTB.Text = reader.GetString(8);
- TelephoneDriverMTB.Text = reader.GetString(9);
- reader.Close();
- query = new SqlCommand($"select (surname_executor + ' ' + name_executor + ' ' + midname_executor) from Executors where code_executor like '{codeExecutor}'", dbhelper.sqlConnection);
- ExecutorsCB.SelectedItem = query.ExecuteScalar().ToString();
- }
- private void UpdateBTN_Click(object sender, EventArgs e)
- {
- query = new SqlCommand($"select code_executor from executors where (surname_executor + ' ' + name_executor + ' ' + midname_executor) like '{ExecutorsCB.SelectedItem}'", dbhelper.sqlConnection);
- string codeExecutor = query.ExecuteScalar().ToString();
- 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);
- query.Parameters.AddWithValue("code_executor", codeExecutor);
- query.Parameters.AddWithValue("surname_driver", SurnameDriverTB.Text);
- query.Parameters.AddWithValue("name_driver", NameDriverTB.Text);
- query.Parameters.AddWithValue("midname_driver", MidnameDriverTB.Text);
- query.Parameters.AddWithValue("number_passport_driver", NumberPassportDriverMTB.Text);
- query.Parameters.AddWithValue("place_passport_driver", PlacePassportDriverRTB.Text);
- query.Parameters.AddWithValue("date_passport_driver", DatePassportDriverDTP.Value);
- query.Parameters.AddWithValue("code_passport_driver", CodePassportDriverMTB.Text);
- query.Parameters.AddWithValue("number_driverlicense", NumberDriverLicenseMTB.Text);
- query.Parameters.AddWithValue("telephone_driver", TelephoneDriverMTB.Text);
- if (query.ExecuteNonQuery().ToString().Equals("1"))
- {
- MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- }
- }
-
- }
|