addSotrudnic.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 addSotrudnic : Form
  14. {
  15. SqlCommand query = null;
  16. public addSotrudnic()
  17. {
  18. InitializeComponent();
  19. }
  20. private void addSotrudnic_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. }
  32. catch
  33. {
  34. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  35. }
  36. }
  37. private void bt_add_Click(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. query = new SqlCommand($"insert into experience (kol_vo_smen, num_sertificat, work_place, student_otryad, status_otryad) values (@kol_vo_smen, @num_sertificat, @work_place, @student_otryad, @status_otryad)", db_helper.sqlConnection);
  42. query.Parameters.AddWithValue($"kol_vo_smen", nud_kolSmen.Value);
  43. query.Parameters.AddWithValue($"num_sertificat", mtb_numSertificat.Text);
  44. query.Parameters.AddWithValue($"work_place", tb_workPlace.Text);
  45. query.Parameters.AddWithValue($"student_otryad", tb_studentOtryad.Text);
  46. query.Parameters.AddWithValue($"status_otryad", tb_statusOtryad.Text);
  47. query.ExecuteNonQuery();
  48. DateTime date1 = DateTime.Parse(dtp_dateVudach.Text);
  49. query = new SqlCommand($"insert into passport (kem_vudan, date_vudach, seria, nomer) values (@kem_vudan, @date_vudach, @seria, @nomer)", db_helper.sqlConnection);
  50. query.Parameters.AddWithValue($"kem_vudan", tb_kemVudan.Text);
  51. query.Parameters.AddWithValue($"date_vudach", $"{date1.Day}.{date1.Month}.{date1.Year}");
  52. query.Parameters.AddWithValue($"seria", mtb_seria.Text);
  53. query.Parameters.AddWithValue($"nomer", mtb_nomer.Text);
  54. query.ExecuteNonQuery();
  55. query = new SqlCommand($"select kod_passport from passport where kem_vudan like '{tb_kemVudan.Text}' and date_vudach like '{date1.Day}.{date1.Month}.{date1.Year}' and seria like '{mtb_seria.Text}' and nomer like '{mtb_nomer.Text}'", db_helper.sqlConnection);
  56. string kodPassport = query.ExecuteScalar().ToString();
  57. query = new SqlCommand($"select kod_experince from experience where kol_vo_smen like '{nud_kolSmen.Value}' and num_sertificat like '{mtb_numSertificat.Text}' and work_place like '{tb_workPlace.Text}' and student_otryad like '{tb_studentOtryad.Text}' and status_otryad like '{tb_statusOtryad.Text}'", db_helper.sqlConnection);
  58. string kodExp = query.ExecuteScalar().ToString();
  59. query = new SqlCommand($"select kod_dolgnost from dolgnost where dolgnost like '{cb_dolgnost.SelectedItem}'", db_helper.sqlConnection);
  60. string kodDolgnost = query.ExecuteScalar().ToString();
  61. date1 = DateTime.Parse(dtp_dateBirth.Text);
  62. query = new SqlCommand($"insert into sotrudnic (surname, [name], patronymic, telephone, date_birth, adress, family_status, obrazovanie, kod_passport, inn, snils, num_med_book, kod_dolgnost, salary, kod_experience) values (@surname, @name, @patronymic, @telephone, @date_birth, @adress, @family_status, @obrazovanie, @kod_passport, @inn, @snils, @num_med_book, @kod_dolgnost, @salary, @kod_experience)", db_helper.sqlConnection);
  63. query.Parameters.AddWithValue($"surname", tb_surname.Text);
  64. query.Parameters.AddWithValue($"name", tb_name.Text);
  65. query.Parameters.AddWithValue($"patronymic", tb_patronymic.Text);
  66. query.Parameters.AddWithValue($"telephone", mtb_telephone.Text);
  67. query.Parameters.AddWithValue($"date_birth", $"{date1.Day}.{date1.Month}.{date1.Year}");
  68. query.Parameters.AddWithValue($"adress", tb_adress.Text);
  69. query.Parameters.AddWithValue($"family_status", cb_familyStatus.SelectedItem);
  70. query.Parameters.AddWithValue($"obrazovanie", cb_obrazovanie.SelectedItem);
  71. query.Parameters.AddWithValue($"kod_passport", kodPassport);
  72. query.Parameters.AddWithValue($"inn", mtb_INN.Text);
  73. query.Parameters.AddWithValue($"snils", mtb_snils.Text);
  74. query.Parameters.AddWithValue($"num_med_book", nud_numMedBook.Value);
  75. query.Parameters.AddWithValue($"kod_dolgnost", kodDolgnost);
  76. query.Parameters.AddWithValue($"salary", nud_salary.Value);
  77. query.Parameters.AddWithValue($"kod_experience", kodExp);
  78. if (query.ExecuteNonQuery().ToString().Equals("1"))
  79. {
  80. MessageBox.Show("Данные успешно добавлены!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  81. this.Close();
  82. }
  83. }
  84. catch
  85. {
  86. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  87. }
  88. }
  89. }
  90. }