changeSotrudnic.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 Дол_Восток
  12. {
  13. public partial class changeSotrudnic : Form
  14. {
  15. SqlCommand query = null;
  16. public changeSotrudnic()
  17. {
  18. InitializeComponent();
  19. }
  20. private void changeSotrudnic_Load(object sender, EventArgs e)
  21. {
  22. try
  23. {
  24. query = new SqlCommand($"select dolgnost from dolgnost", db_helper.sqlConnection);
  25. SqlDataReader reader = query.ExecuteReader();
  26. while (reader.Read())
  27. {
  28. cb_dolgnost.Items.Add(reader.GetString(0));
  29. }
  30. reader.Close();
  31. query = new SqlCommand($"select surname from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  32. tb_surname.Text = query.ExecuteScalar().ToString();
  33. query = new SqlCommand($"select [name] from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  34. tb_name.Text = query.ExecuteScalar().ToString();
  35. query = new SqlCommand($"select patronymic from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  36. tb_patronymic.Text = query.ExecuteScalar().ToString();
  37. query = new SqlCommand($"select telephone from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  38. mtb_telephone.Text = query.ExecuteScalar().ToString();
  39. query = new SqlCommand($"select date_birth from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  40. dtp_dateBirth.Text = query.ExecuteScalar().ToString();
  41. query = new SqlCommand($"select adress from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  42. tb_adress.Text = query.ExecuteScalar().ToString();
  43. query = new SqlCommand($"select family_status from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  44. cb_familyStatus.SelectedItem = query.ExecuteScalar().ToString();
  45. query = new SqlCommand($"select obrazovanie from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  46. cb_obrazovanie.SelectedItem = query.ExecuteScalar().ToString();
  47. query = new SqlCommand($"select kem_vudan from sotrudnic join passport on passport.kod_passport = sotrudnic.kod_passport where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  48. tb_kemVudan.Text = query.ExecuteScalar().ToString();
  49. query = new SqlCommand($"select date_vudach from sotrudnic join passport on passport.kod_passport = sotrudnic.kod_passport where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  50. dtp_dateVudach.Text = query.ExecuteScalar().ToString();
  51. query = new SqlCommand($"select seria from sotrudnic join passport on passport.kod_passport = sotrudnic.kod_passport where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  52. mtb_seria.Text = query.ExecuteScalar().ToString();
  53. query = new SqlCommand($"select nomer from sotrudnic join passport on passport.kod_passport = sotrudnic.kod_passport where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  54. mtb_nomer.Text = query.ExecuteScalar().ToString();
  55. query = new SqlCommand($"select inn from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  56. mtb_INN.Text = query.ExecuteScalar().ToString();
  57. query = new SqlCommand($"select snils from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  58. mtb_snils.Text = query.ExecuteScalar().ToString();
  59. query = new SqlCommand($"select num_med_book from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  60. nud_numMedBook.Value = Convert.ToInt32(query.ExecuteScalar());
  61. query = new SqlCommand($"select dolgnost from sotrudnic join dolgnost on dolgnost.kod_dolgnost = sotrudnic.kod_dolgnost where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  62. cb_dolgnost.SelectedItem = query.ExecuteScalar().ToString();
  63. query = new SqlCommand($"select salary from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  64. nud_salary.Value = Convert.ToInt32(query.ExecuteScalar());
  65. query = new SqlCommand($"select kol_vo_smen from sotrudnic join experience on experience.kod_experince = sotrudnic.kod_experience where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  66. nud_kolSmen.Value = Convert.ToInt32(query.ExecuteScalar());
  67. query = new SqlCommand($"select num_sertificat from sotrudnic join experience on experience.kod_experince = sotrudnic.kod_experience where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  68. mtb_numSertificat.Text = query.ExecuteScalar().ToString();
  69. query = new SqlCommand($"select work_place from sotrudnic join experience on experience.kod_experince = sotrudnic.kod_experience where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  70. tb_workPlace.Text = query.ExecuteScalar().ToString();
  71. query = new SqlCommand($"select student_otryad from sotrudnic join experience on experience.kod_experince = sotrudnic.kod_experience where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  72. tb_studentOtryad.Text = query.ExecuteScalar().ToString();
  73. query = new SqlCommand($"select status_otryad from sotrudnic join experience on experience.kod_experince = sotrudnic.kod_experience where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  74. tb_statusOtryad.Text = query.ExecuteScalar().ToString();
  75. }
  76. catch
  77. {
  78. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  79. }
  80. }
  81. private void bt_change_Click(object sender, EventArgs e)
  82. {
  83. try
  84. {
  85. query = new SqlCommand($"select kod_passport from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  86. string kodPassport = query.ExecuteScalar().ToString();
  87. query = new SqlCommand($"select kod_experience from sotrudnic where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  88. string kodExperience = query.ExecuteScalar().ToString();
  89. DateTime date1 = DateTime.Parse(dtp_dateVudach.Text);
  90. query = new SqlCommand($"update passport set kem_vudan = @kem_vudan, date_vudach = @date_vudach, seria = @seria, nomer = @nomer where kod_passport like '{kodPassport}'", db_helper.sqlConnection);
  91. query.Parameters.AddWithValue($"kem_vudan", tb_kemVudan.Text);
  92. query.Parameters.AddWithValue($"date_vudach", $"{date1.Day}.{date1.Month}.{date1.Year}");
  93. query.Parameters.AddWithValue($"seria", mtb_seria.Text);
  94. query.Parameters.AddWithValue($"nomer", mtb_nomer.Text);
  95. query.ExecuteNonQuery();
  96. query = new SqlCommand($"update experience set kol_vo_smen = @kol_vo_smen, num_sertificat = @num_sertificat, work_place = @work_place, student_otryad = @student_otryad, status_otryad = @status_otryad where kod_experince like '{kodExperience}'", db_helper.sqlConnection);
  97. query.Parameters.AddWithValue($"kol_vo_smen", nud_kolSmen.Value);
  98. query.Parameters.AddWithValue($"num_sertificat", mtb_numSertificat.Text);
  99. query.Parameters.AddWithValue($"work_place", tb_workPlace.Text);
  100. query.Parameters.AddWithValue($"student_otryad", tb_studentOtryad.Text);
  101. query.Parameters.AddWithValue($"status_otryad", tb_statusOtryad.Text);
  102. query.ExecuteNonQuery();
  103. query = new SqlCommand($"select kod_dolgnost from dolgnost where dolgnost like '{cb_dolgnost.SelectedItem}'", db_helper.sqlConnection);
  104. string kodDolgnost = query.ExecuteScalar().ToString();
  105. date1 = DateTime.Parse(dtp_dateBirth.Text);
  106. query = new SqlCommand($"update sotrudnic set surname = @surname, [name] = @name, patronymic = @patronymic, telephone = @telephone, date_birth = @date_birth, adress = @adress, family_status = @family_status, obrazovanie = @obrazovanie, inn = @inn, snils = @snils, num_med_book = @num_med_book, kod_dolgnost = @kod_dolgnost, salary = @salary where kod_sotrudnic like '{GLavn.row}'", db_helper.sqlConnection);
  107. query.Parameters.AddWithValue($"surname", tb_surname.Text);
  108. query.Parameters.AddWithValue($"name", tb_name.Text);
  109. query.Parameters.AddWithValue($"patronymic", tb_patronymic.Text);
  110. query.Parameters.AddWithValue($"telephone", mtb_telephone.Text);
  111. query.Parameters.AddWithValue($"date_birth", $"{date1.Day}.{date1.Month}.{date1.Year}");
  112. query.Parameters.AddWithValue($"adress", tb_adress.Text);
  113. query.Parameters.AddWithValue($"family_status", cb_familyStatus.SelectedItem);
  114. query.Parameters.AddWithValue($"obrazovanie", cb_obrazovanie.SelectedItem);
  115. query.Parameters.AddWithValue($"inn", mtb_INN.Text);
  116. query.Parameters.AddWithValue($"snils", mtb_snils.Text);
  117. query.Parameters.AddWithValue($"num_med_book", nud_numMedBook.Value);
  118. query.Parameters.AddWithValue($"kod_dolgnost", kodDolgnost);
  119. query.Parameters.AddWithValue($"salary", nud_salary.Value);
  120. if (query.ExecuteNonQuery().ToString().Equals("1"))
  121. {
  122. MessageBox.Show("Данные успешно изменены!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  123. this.Close();
  124. }
  125. else
  126. {
  127. MessageBox.Show("", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  128. }
  129. }
  130. catch
  131. {
  132. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  133. }
  134. }
  135. }
  136. }