updateMedCard.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 hospital
  12. {
  13. public partial class updateMedCard : Form
  14. {
  15. SqlConnection sqlConnection = null;
  16. SqlDataReader reader = null;
  17. SqlCommand a = null;
  18. public updateMedCard()
  19. {
  20. InitializeComponent();
  21. }
  22. private void updateMedCard_Load(object sender, EventArgs e)
  23. {
  24. try
  25. {
  26. FormCreating.openConnection(ref sqlConnection);
  27. disabilityCB.Items.Add("Да");
  28. disabilityCB.Items.Add("Нет");
  29. a = new SqlCommand("select name_blood from blood_type", sqlConnection);
  30. reader = a.ExecuteReader();
  31. while (reader.Read())
  32. {
  33. bloodCB.Items.Add(reader.GetString(0));
  34. }
  35. reader.Close();
  36. a = new SqlCommand($"select name_factor from rh_factor", sqlConnection);
  37. reader = a.ExecuteReader();
  38. while (reader.Read())
  39. {
  40. rhFactorCB.Items.Add(reader.GetString(0));
  41. }
  42. reader.Close();
  43. a = new SqlCommand($"select surname_patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  44. surnameTB.Text = a.ExecuteScalar().ToString();
  45. a = new SqlCommand($"select name_patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  46. nameTB.Text = a.ExecuteScalar().ToString();
  47. a = new SqlCommand($"select midname_patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  48. midnameTB.Text = a.ExecuteScalar().ToString();
  49. a = new SqlCommand($"select date_birthday_patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  50. birthDateDTP.Text = a.ExecuteScalar().ToString();
  51. a = new SqlCommand($"select telephone_patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  52. telephoneMTB.Text = a.ExecuteScalar().ToString();
  53. a = new SqlCommand($"select iian_patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  54. iianMTB.Text = a.ExecuteScalar().ToString();
  55. a = new SqlCommand($"select Passport_Number_Patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  56. passportNumberMTB.Text = a.ExecuteScalar().ToString();
  57. a = new SqlCommand($"select Passport_Date_Patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  58. passportDateDTP.Text = a.ExecuteScalar().ToString();
  59. a = new SqlCommand($"select Passport_Place_Patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  60. passpordPlaceTB.Text = a.ExecuteScalar().ToString();
  61. a = new SqlCommand($"select Passport_Code_Patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  62. passportCodeMTB.Text = a.ExecuteScalar().ToString();
  63. a = new SqlCommand($"select Number_Policy_Patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  64. policyNumberMTB.Text = a.ExecuteScalar().ToString();
  65. a = new SqlCommand($"select Disability_Patient from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  66. disabilityCB.SelectedItem = a.ExecuteScalar().ToString();
  67. if (disabilityCB.SelectedItem.Equals("Нет"))
  68. {
  69. descriptionDisabilityRTB.Visible = false;
  70. }
  71. else
  72. {
  73. descriptionDisabilityRTB.Visible = true;
  74. }
  75. a = new SqlCommand($"select Description_Disability from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  76. descriptionDisabilityRTB.Text = a.ExecuteScalar().ToString();
  77. a = new SqlCommand($"select name_blood from medical_cards join blood_type on medical_cards.id_blood = blood_type.id_blood where id_card like {mainMenu.index}", sqlConnection);
  78. bloodCB.SelectedItem = a.ExecuteScalar().ToString();
  79. a = new SqlCommand($"select name_factor from medical_cards join rh_factor on rh_factor.id_factor = medical_cards.id_factor where id_card like {mainMenu.index}", sqlConnection);
  80. rhFactorCB.SelectedItem = a.ExecuteScalar().ToString();
  81. a = new SqlCommand($"select WorkStudy_Place from medical_cards where id_card like {mainMenu.index}", sqlConnection);
  82. workStudyPlaceRTB.Text = a.ExecuteScalar().ToString();
  83. }
  84. catch
  85. {
  86. MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  87. debugAndTrace.writeInFile("ERROR");
  88. }
  89. }
  90. private void update_Click(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. var res = MessageBox.Show("Уверены, что хотите изменить данные?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  95. if (res == DialogResult.Yes)
  96. {
  97. DateTime date1 = DateTime.Parse(birthDateDTP.Text);
  98. DateTime date2 = DateTime.Parse(passportDateDTP.Text);
  99. SqlCommand bloodIndex = new SqlCommand($"select id_blood from blood_type where name_blood like N'{bloodCB.SelectedItem}'", sqlConnection);
  100. SqlCommand factorIndex = new SqlCommand($"select id_factor from rh_factor where name_factor like N'{rhFactorCB.SelectedItem}'", sqlConnection);
  101. a = new SqlCommand($"update medical_cards set Surname_Patient = @Surname_Patient, Name_Patient = @Name_Patient, Midname_Patient = @Midname_Patient, Date_Birthday_Patient = @Date_Birthday_Patient, Telephone_Patient = @Telephone_Patient, IIAN_Patient = @IIAN_Patient, Passport_Number_Patient = @Passport_Number_Patient, Passport_Date_Patient = @Passport_Date_Patient, Passport_Place_Patient = @Passport_Place_Patient, Passport_Code_Patient = @Passport_Code_Patient, Number_Policy_Patient = @Number_Policy_Patient, Disability_Patient = @Disability_Patient, Description_Disability = @Description_Disability, ID_Blood = @ID_Blood, ID_Factor = @ID_Factor, WorkStudy_Place = @WorkStudy_Place where id_card like {mainMenu.index}", sqlConnection);
  102. a.Parameters.AddWithValue("Surname_Patient", surnameTB.Text);
  103. a.Parameters.AddWithValue("Name_Patient", nameTB.Text);
  104. a.Parameters.AddWithValue("Midname_Patient", midnameTB.Text);
  105. a.Parameters.AddWithValue("Date_Birthday_Patient", $"{date1.Day}/{date1.Month}/{date1.Year}");
  106. a.Parameters.AddWithValue("Telephone_Patient", telephoneMTB.Text);
  107. a.Parameters.AddWithValue("IIAN_Patient", iianMTB.Text);
  108. a.Parameters.AddWithValue("Passport_Number_Patient", passportNumberMTB.Text);
  109. a.Parameters.AddWithValue("Passport_Date_Patient", $"{date2.Day}/{date2.Month}/{date2.Year}");
  110. a.Parameters.AddWithValue("Passport_Place_Patient", passpordPlaceTB.Text);
  111. a.Parameters.AddWithValue("Passport_Code_Patient", passportCodeMTB.Text);
  112. a.Parameters.AddWithValue("Number_Policy_Patient", policyNumberMTB.Text);
  113. a.Parameters.AddWithValue("Disability_Patient", disabilityCB.SelectedItem);
  114. a.Parameters.AddWithValue("Description_Disability", descriptionDisabilityRTB.Text);
  115. a.Parameters.AddWithValue("ID_Blood", bloodIndex.ExecuteScalar().ToString());
  116. a.Parameters.AddWithValue("ID_Factor", factorIndex.ExecuteScalar().ToString());
  117. a.Parameters.AddWithValue("WorkStudy_Place", workStudyPlaceRTB.Text);
  118. a.ExecuteNonQuery();
  119. Array.Resize(ref auth.data, 16);
  120. auth.data[0] = $"Фамилия: {surnameTB.Text}";
  121. auth.data[1] = $"Имя: {nameTB.Text}";
  122. auth.data[2] = $"Отчество: {midnameTB.Text}";
  123. auth.data[3] = $"Дата рождения: {date1.Day}/{date1.Month}/{date1.Year}";
  124. auth.data[4] = $"Телефон: {telephoneMTB.Text}";
  125. auth.data[5] = $"СНИЛС: {iianMTB.Text}";
  126. auth.data[6] = $"Серия и номер паспорта: {passportNumberMTB.Text}";
  127. auth.data[7] = $"Дата выдачи паспорта: {date2.Day}/{date2.Month}/{date2.Year}";
  128. auth.data[8] = $"Кем выдан: {passpordPlaceTB.Text}";
  129. auth.data[9] = $"Код подразделения: {passportCodeMTB.Text}";
  130. auth.data[10] = $"Номер страхового полиса: {policyNumberMTB.Text}";
  131. auth.data[11] = $"Инвалидность: {disabilityCB.SelectedIndex}";
  132. auth.data[12] = $"Описание инвалидности(если есть): {descriptionDisabilityRTB.Text}";
  133. auth.data[13] = $"Группа крови: {bloodCB.SelectedItem}";
  134. auth.data[14] = $"Резус фактор: {rhFactorCB.SelectedItem}";
  135. auth.data[15] = $"Описание трудовой деятельности: {workStudyPlaceRTB.Text}";
  136. debugAndTrace.writeInFile($"Изменение медицинской карты {mainMenu.index}", auth.data);
  137. if (a.ExecuteNonQuery() == 1)
  138. {
  139. MessageBox.Show("Изменение данных произошло успешно", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  140. debugAndTrace.writeInFile($"Изменение медицинской карты {mainMenu.index}", auth.data);
  141. debugAndTrace.writeInFile("Переход на главную форму");
  142. this.Close();
  143. }
  144. else
  145. {
  146. MessageBox.Show("Произошла ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  147. debugAndTrace.writeInFile("Ошибка добавления данных", auth.data);
  148. }
  149. }
  150. else
  151. {
  152. MessageBox.Show("Действие отменено", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  153. }
  154. }
  155. catch
  156. {
  157. MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  158. debugAndTrace.writeInFile("ERROR");
  159. }
  160. }
  161. private void disabilityCB_SelectedIndexChanged(object sender, EventArgs e)
  162. {
  163. if (disabilityCB.SelectedItem.Equals("Нет"))
  164. {
  165. descriptionDisabilityRTB.Visible = false;
  166. }
  167. else
  168. {
  169. descriptionDisabilityRTB.Visible = true;
  170. }
  171. }
  172. private void backBTN_Click(object sender, EventArgs e)
  173. {
  174. try
  175. {
  176. var res = MessageBox.Show("Уверены, что хотите отменить изменение медицинской карты?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  177. if (res == DialogResult.Yes)
  178. {
  179. debugAndTrace.writeInFile("Отмена изменения медицинской карты");
  180. this.Close();
  181. }
  182. else
  183. {
  184. MessageBox.Show("Действие отменено", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  185. }
  186. }
  187. catch
  188. {
  189. MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  190. debugAndTrace.writeInFile("ERROR");
  191. }
  192. }
  193. }
  194. }