UpdateRequest.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 UpdateRequest : Form
  14. {
  15. SqlCommand query = null;
  16. SqlDataReader reader = null;
  17. public UpdateRequest()
  18. {
  19. InitializeComponent();
  20. }
  21. private void UpdateRequest_Load(object sender, EventArgs e)
  22. {
  23. query = new SqlCommand("select surname_executor + ' ' + name_executor + ' ' + midname_executor from Executors", dbhelper.sqlConnection);
  24. reader = query.ExecuteReader();
  25. while (reader.Read())
  26. {
  27. ExecutorsCB.Items.Add(reader.GetString(0));
  28. }
  29. reader.Close();
  30. query = new SqlCommand("select surname_driver + ' ' + name_driver + ' ' + midname_driver from Drivers", dbhelper.sqlConnection);
  31. reader = query.ExecuteReader();
  32. while (reader.Read())
  33. {
  34. DriversCB.Items.Add(reader.GetString(0));
  35. }
  36. reader.Close();
  37. query = new SqlCommand("select brand_vehicle + ' ' + model_vehicle + ' ' + number_vehicle from Vehicles", dbhelper.sqlConnection);
  38. reader = query.ExecuteReader();
  39. while (reader.Read())
  40. {
  41. VehiclesCB.Items.Add(reader.GetString(0));
  42. }
  43. reader.Close();
  44. query = new SqlCommand("select surname_logistician + ' ' + name_logistician + ' ' + midname_logistician from Logisticians", dbhelper.sqlConnection);
  45. reader = query.ExecuteReader();
  46. while (reader.Read())
  47. {
  48. LogisticiansCB.Items.Add(reader.GetString(0));
  49. }
  50. reader.Close();
  51. query = new SqlCommand($"select 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 from requests where code_request like '{MainMenu.requestIndex}'", dbhelper.sqlConnection);
  52. reader = query.ExecuteReader();
  53. reader.Read();
  54. int codeExecutor = reader.GetInt32(0);
  55. int codeDriver = reader.GetInt32(1);
  56. int codeVehicle = reader.GetInt32(2);
  57. DateLoadingDTP.Value = reader.GetDateTime(3);
  58. PlaceLoadingRTB.Text = reader.GetString(4);
  59. NameShipperTB.Text = reader.GetString(5);
  60. TelephoneShipperMTB.Text = reader.GetString(6);
  61. NameCargoRTB.Text = reader.GetString(7);
  62. TransportationConditionsRTB.Text = reader.GetString(8);
  63. DateUnloadingDTP.Value = reader.GetDateTime(9);
  64. PlaceUnloadingRTP.Text = reader.GetString(10);
  65. NameConsigneeTB.Text = reader.GetString(11);
  66. TelephoneConsigneeMTB.Text = reader.GetString(12);
  67. RoutePlaceTB.Text = reader.GetString(13);
  68. RouteMileageTB.Text = reader.GetString(14);
  69. TransportationFormatDTP.Text = reader.GetString(15);
  70. PaymentTB.Text = reader.GetString(16);
  71. PaymentConditionsTB.Text = reader.GetString(17);
  72. int codeLogistician = reader.GetInt32(18);
  73. reader.Close();
  74. query = new SqlCommand($"select (surname_executor + ' ' + name_executor + ' ' + midname_executor) from Executors where code_executor like '{codeExecutor}'", dbhelper.sqlConnection);
  75. ExecutorsCB.SelectedItem = query.ExecuteScalar().ToString();
  76. query = new SqlCommand($"select (surname_driver + ' ' + name_driver + ' ' + midname_driver) from drivers where code_driver like '{codeDriver}'", dbhelper.sqlConnection);
  77. DriversCB.SelectedItem = query.ExecuteScalar().ToString();
  78. query = new SqlCommand($"select (brand_vehicle + ' ' + model_vehicle + ' ' + number_vehicle) from vehicles where code_vehicle like '{codeVehicle}'", dbhelper.sqlConnection);
  79. VehiclesCB.SelectedItem = query.ExecuteScalar().ToString();
  80. query = new SqlCommand($"select (surname_logistician + ' ' + name_logistician + ' ' + midname_logistician) from logisticians where code_logistician like '{codeLogistician}'", dbhelper.sqlConnection);
  81. LogisticiansCB.SelectedItem = query.ExecuteScalar().ToString();
  82. }
  83. private void UpdateBTN_Click(object sender, EventArgs e)
  84. {
  85. query = new SqlCommand($"select code_executor from executors where (surname_executor + ' ' + name_executor + ' ' + midname_executor) like '{ExecutorsCB.SelectedItem}'", dbhelper.sqlConnection);
  86. string codeExecutor = query.ExecuteScalar().ToString();
  87. query = new SqlCommand($"select code_Driver from drivers where (surname_driver + ' ' + name_driver + ' ' + midname_driver) like '{DriversCB.SelectedItem}'", dbhelper.sqlConnection);
  88. string codeDriver = query.ExecuteScalar().ToString();
  89. query = new SqlCommand($"select code_vehicle from vehicles where (brand_vehicle + ' ' + model_vehicle + ' ' + number_vehicle) like '{VehiclesCB.SelectedItem}'", dbhelper.sqlConnection);
  90. string codeVehicle = query.ExecuteScalar().ToString();
  91. query = new SqlCommand($"select code_logistician from logisticians where (surname_logistician + ' ' + name_logistician + ' ' + midname_logistician) like '{LogisticiansCB.SelectedItem}'", dbhelper.sqlConnection);
  92. string codeLogistician = query.ExecuteScalar().ToString();
  93. query = new SqlCommand($"update requests set code_executor = @code_executor, code_driver = @code_driver, code_vehicle = @code_vehicle, date_loading = @date_loading, place_loading = @place_loading, fullname_shipper = @fullname_shipper, telephone_shipper = @telephone_shipper, name_cargo = @name_cargo, transportation_conditions = @transportation_conditions, date_unloading = @date_unloading, place_unloading = @place_unloading, fullname_consignee = @fullname_consignee, telephone_consignee = @telephone_consignee, route_town_request = @route_town_request, route_mileage_request = @route_mileage_request, transportation_format = @transportation_format, payment_request = @payment_request, payment_conditions_request = @payment_conditions_request, code_logistician = @code_logistician where code_request like '{MainMenu.requestIndex}'", dbhelper.sqlConnection);
  94. query.Parameters.AddWithValue("code_executor", codeExecutor);
  95. query.Parameters.AddWithValue("code_driver", codeDriver);
  96. query.Parameters.AddWithValue("code_vehicle", codeVehicle);
  97. query.Parameters.AddWithValue("date_loading", DateLoadingDTP.Value);
  98. query.Parameters.AddWithValue("place_loading", PlaceLoadingRTB.Text);
  99. query.Parameters.AddWithValue("fullname_shipper", NameShipperTB.Text);
  100. query.Parameters.AddWithValue("telephone_shipper", TelephoneShipperMTB.Text);
  101. query.Parameters.AddWithValue("name_cargo", NameCargoRTB.Text);
  102. query.Parameters.AddWithValue("transportation_conditions", TransportationConditionsRTB.Text);
  103. query.Parameters.AddWithValue("date_unloading", DateUnloadingDTP.Value);
  104. query.Parameters.AddWithValue("place_unloading", PlaceUnloadingRTP.Text);
  105. query.Parameters.AddWithValue("fullname_consignee", NameConsigneeTB.Text);
  106. query.Parameters.AddWithValue("telephone_consignee", TelephoneConsigneeMTB.Text);
  107. query.Parameters.AddWithValue("route_town_request", RoutePlaceTB.Text);
  108. query.Parameters.AddWithValue("route_mileage_request", RouteMileageTB.Text);
  109. query.Parameters.AddWithValue("transportation_format", TransportationFormatDTP.Text);
  110. query.Parameters.AddWithValue("payment_request", PaymentTB.Text);
  111. query.Parameters.AddWithValue("payment_conditions_request", PaymentConditionsTB.Text);
  112. query.Parameters.AddWithValue("code_logistician", codeLogistician);
  113. if (query.ExecuteNonQuery().ToString().Equals("1"))
  114. {
  115. MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  116. this.Close();
  117. }
  118. }
  119. }
  120. }