AddRequest.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 AddRequest : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public AddRequest()
  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($"select code_Driver from drivers where (surname_driver + ' ' + name_driver + ' ' + midname_driver) like '{DriversCB.SelectedItem}'", dbhelper.sqlConnection);
  26. string codeDriver = query.ExecuteScalar().ToString();
  27. query = new SqlCommand($"select code_vehicle from vehicles where (brand_vehicle + ' ' + model_vehicle + ' ' + number_vehicle) like '{VehiclesCB.SelectedItem}'", dbhelper.sqlConnection);
  28. string codeVehicle = query.ExecuteScalar().ToString();
  29. query = new SqlCommand($"select code_logistician from logisticians where (surname_logistician + ' ' + name_logistician + ' ' + midname_logistician) like '{LogisticiansCB.SelectedItem}'", dbhelper.sqlConnection);
  30. string codeLogistician = query.ExecuteScalar().ToString();
  31. query = new SqlCommand("insert into requests (code_executor, code_driver, code_vehicle, date_loading, place_loading, fullname_shipper, telephone_shipper, name_cargo, transportation_conditions, date_unloading, place_unloading, fullname_consignee, telephone_consignee, route_town_request, route_mileage_request, transportation_format, payment_request, payment_conditions_request, code_logistician) values (@code_executor, @code_driver, @code_vehicle, @date_loading, @place_loading, @fullname_shipper, @telephone_shipper, @name_cargo, @transportation_conditions, @date_unloading, @place_unloading, @fullname_consignee, @telephone_consignee, @route_town_request, @route_mileage_request, @transportation_format, @payment_request, @payment_conditions_request, @code_logistician)", dbhelper.sqlConnection);
  32. query.Parameters.AddWithValue("code_executor", codeExecutor);
  33. query.Parameters.AddWithValue("code_driver", codeDriver);
  34. query.Parameters.AddWithValue("code_vehicle", codeVehicle);
  35. query.Parameters.AddWithValue("date_loading", DateLoadingDTP.Value);
  36. query.Parameters.AddWithValue("place_loading", PlaceLoadingRTB.Text);
  37. query.Parameters.AddWithValue("fullname_shipper", NameShipperTB.Text);
  38. query.Parameters.AddWithValue("telephone_shipper", TelephoneShipperMTB.Text);
  39. query.Parameters.AddWithValue("name_cargo", NameCargoRTB.Text);
  40. query.Parameters.AddWithValue("transportation_conditions", TransportationConditionsRTB.Text);
  41. query.Parameters.AddWithValue("date_unloading", DateUnloadingDTP.Value);
  42. query.Parameters.AddWithValue("place_unloading", PlaceUnloadingRTP.Text);
  43. query.Parameters.AddWithValue("fullname_consignee", NameConsigneeTB.Text);
  44. query.Parameters.AddWithValue("telephone_consignee", TelephoneConsigneeMTB.Text);
  45. query.Parameters.AddWithValue("route_town_request", RoutePlaceTB.Text);
  46. query.Parameters.AddWithValue("route_mileage_request", RouteMileageTB.Text);
  47. query.Parameters.AddWithValue("transportation_format", TransportationFormatDTP.Text);
  48. query.Parameters.AddWithValue("payment_request", PaymentTB.Text);
  49. query.Parameters.AddWithValue("payment_conditions_request", PaymentConditionsTB.Text);
  50. query.Parameters.AddWithValue("code_logistician", codeLogistician);
  51. if (query.ExecuteNonQuery().ToString().Equals("1"))
  52. {
  53. MessageBox.Show("Добавление прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  54. this.Close();
  55. }
  56. }
  57. private void AddRequest_Load(object sender, EventArgs e)
  58. {
  59. query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
  60. reader = query.ExecuteReader();
  61. while (reader.Read())
  62. {
  63. ExecutorsCB.Items.Add(reader.GetString(0));
  64. }
  65. reader.Close();
  66. query = new SqlCommand("select surname_driver + ' ' + name_driver + ' ' + midname_driver from Drivers", dbhelper.sqlConnection);
  67. reader = query.ExecuteReader();
  68. while (reader.Read())
  69. {
  70. DriversCB.Items.Add(reader.GetString(0));
  71. }
  72. reader.Close();
  73. query = new SqlCommand("select brand_vehicle + ' ' + model_vehicle + ' ' + number_vehicle from Vehicles", dbhelper.sqlConnection);
  74. reader = query.ExecuteReader();
  75. while (reader.Read())
  76. {
  77. VehiclesCB.Items.Add(reader.GetString(0));
  78. }
  79. reader.Close();
  80. query = new SqlCommand("select surname_logistician + ' ' + name_logistician + ' ' + midname_logistician from Logisticians", dbhelper.sqlConnection);
  81. reader = query.ExecuteReader();
  82. while (reader.Read())
  83. {
  84. LogisticiansCB.Items.Add(reader.GetString(0));
  85. }
  86. reader.Close();
  87. }
  88. }
  89. }