123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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 AddDriver : Form
- {
- SqlCommand query = null;
- SqlDataReader reader = null;
- public AddDriver()
- {
- InitializeComponent();
- }
- private void AddBTN_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("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);
- 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();
- }
- }
- private void AddDriver_Load(object sender, EventArgs e)
- {
- 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();
- }
- }
- }
|