mainMenu.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. using System.Drawing.Printing;
  12. namespace hospital
  13. {
  14. public partial class mainMenu : Form
  15. {
  16. SqlConnection sqlConnection = null;
  17. string query = null;
  18. SqlDataAdapter dataAdapter = null;
  19. DataSet dataSet = null;
  20. public static string index;
  21. public mainMenu()
  22. {
  23. InitializeComponent();
  24. }
  25. private void mainMenu_FormClosed(object sender, FormClosedEventArgs e)
  26. {
  27. Application.Exit();
  28. }
  29. private void mainMenu_Load(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. query = $"select id_card as 'ID', Surname_Patient as 'Фамилия', Name_Patient as 'Имя', Midname_Patient as 'Отчество', Date_Birthday_Patient as 'Дата рождения', Telephone_Patient as 'Телефон', IIAN_Patient as 'СНИЛС', Passport_Number_Patient as 'Серия, номер паспорта', Passport_Date_Patient as 'Дата выдачи', Passport_Place_Patient as 'Кем выдан', Passport_Code_Patient as 'Код подразделения', Number_Policy_Patient as 'Номер полиса', Disability_Patient as 'Инвалидность', Name_Blood as 'Группа крови', Name_Factor as 'Резус-фактор' from Medical_Cards join Blood_Type on Blood_Type.ID_Blood = Medical_Cards.ID_Blood join Rh_Factor on Rh_Factor.ID_Factor = Medical_Cards.ID_Factor";
  34. FormCreating.openConnection(ref sqlConnection);
  35. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  36. dataSet = new DataSet();
  37. dataAdapter.Fill(dataSet);
  38. dataGridView1.DataSource = dataSet.Tables[0];
  39. SqlCommand a = new SqlCommand($"select name_post from posts join employees on employees.id_post = posts.id_post where id_employee like {auth.userID}", sqlConnection);
  40. if (a.ExecuteScalar().ToString().Equals("Мед-сестра"))
  41. {
  42. tabControl1.TabPages.Remove(tabPage2);
  43. delete_medicalCard.Visible = false;
  44. }
  45. }
  46. catch
  47. {
  48. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  49. debugAndTrace.writeInFile("ERROR");
  50. }
  51. }
  52. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. passwordFounded = false;
  57. switch (tabControl1.SelectedIndex)
  58. {
  59. case 0:
  60. query = $"select id_card as 'ID', Surname_Patient as 'Фамилия', Name_Patient as 'Имя', Midname_Patient as 'Отчество', Date_Birthday_Patient as 'Дата рождения', Telephone_Patient as 'Телефон', IIAN_Patient as 'СНИЛС', Passport_Number_Patient as 'Серия, номер паспорта', Passport_Date_Patient as 'Дата выдачи', Passport_Place_Patient as 'Кем выдан', Passport_Code_Patient as 'Код подразделения', Number_Policy_Patient as 'Номер полиса', Disability_Patient as 'Инвалидность', Name_Blood as 'Группа крови', Name_Factor as 'Резус-фактор' from Medical_Cards join Blood_Type on Blood_Type.ID_Blood = Medical_Cards.ID_Blood join Rh_Factor on Rh_Factor.ID_Factor = Medical_Cards.ID_Factor";
  61. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  62. dataSet = new DataSet();
  63. dataAdapter.Fill(dataSet);
  64. dataGridView1.DataSource = dataSet.Tables[0];
  65. debugAndTrace.writeInFile("Включена вкладка \"Медицинские карты\"");
  66. break;
  67. case 1:
  68. query = $"select id_patientcard as 'ID', surname_patient + ' ' + Name_Patient + ' ' + Midname_Patient as 'ФИО пациента', Surname_Employee + ' ' + Name_Employee + ' ' + Midname_Employee as 'ФИО лечащего врача', Name_Disease as 'Заболевание', Name_Severity as 'Тяжесть', Number_Ward as 'Номер палаты' from patientcards join medical_cards on medical_cards.id_card = patientcards.id_card join Employees on Employees.ID_Employee = PatientCards.ID_Employee join Diseases on Diseases.ID_Disease = PatientCards.ID_Disease join Disease_Severity on Disease_Severity.ID_Severity = PatientCards.ID_Severity join Wards on Wards.ID_Ward = PatientCards.ID_Ward";
  69. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  70. dataSet = new DataSet();
  71. dataAdapter.Fill(dataSet);
  72. dataGridView2.DataSource = dataSet.Tables[0];
  73. debugAndTrace.writeInFile("Включена вкладка \"Карты пациентов\"");
  74. break;
  75. case 2:
  76. costL.Text = "Общая стоимость: 0";
  77. query = $"select id_drugs as 'ID', name_drugs as 'Лекарство', price_drugs as 'Цена' from drugs";
  78. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  79. dataSet = new DataSet();
  80. dataAdapter.Fill(dataSet);
  81. dataGridView3.DataSource = dataSet.Tables[0];
  82. debugAndTrace.writeInFile("Включена вкладка \"Лекарства\"");
  83. break;
  84. case 3:
  85. if (!passwordFounded)
  86. {
  87. checkPasswordTB.Text = "";
  88. panel1.Visible = true;
  89. }
  90. debugAndTrace.writeInFile("Включена вкладка \"Профиль\"");
  91. SqlCommand a = new SqlCommand($"select surname_employee from employees where id_employee like '{auth.userID}'", sqlConnection);
  92. newSuraname_employeeTB.Text = a.ExecuteScalar().ToString();
  93. a = new SqlCommand($"select name_employee from employees where id_employee like '{auth.userID}'", sqlConnection);
  94. newName_employeeTB.Text = a.ExecuteScalar().ToString();
  95. a = new SqlCommand($"select midname_employee from employees where id_employee like N'{auth.userID}'", sqlConnection);
  96. newMidname_employeeTB.Text = a.ExecuteScalar().ToString();
  97. a = new SqlCommand($"select name_gender from gender join employees on employees.id_gender = gender.id_gender where id_employee like {auth.userID}", sqlConnection);
  98. genderTB.Text = a.ExecuteScalar().ToString();
  99. a = new SqlCommand($"select date_birthday_employee from employees where id_employee like '{auth.userID}'", sqlConnection);
  100. DateTime date = DateTime.Parse(a.ExecuteScalar().ToString());
  101. birthdateDTP.Text = $"{date.Day}.{date.Month}.{date.Year}";
  102. a = new SqlCommand($"select telephone_employee from employees where id_employee like '{auth.userID}'", sqlConnection);
  103. newTelephone_employeeMTB.Text = a.ExecuteScalar().ToString();
  104. a = new SqlCommand($"select passport_number_employee from employees where id_employee like {auth.userID}", sqlConnection);
  105. passportNumberMTB.Text = a.ExecuteScalar().ToString();
  106. a = new SqlCommand($"select passport_place_employee from employees where id_employee like {auth.userID}", sqlConnection);
  107. newPassport_place_employeeTB.Text = a.ExecuteScalar().ToString();
  108. a = new SqlCommand($"select passport_code_employee from employees where id_employee like {auth.userID}", sqlConnection);
  109. passportCodeMTB.Text = a.ExecuteScalar().ToString();
  110. a = new SqlCommand($"select passport_date_employee from employees where id_employee like {auth.userID}", sqlConnection);
  111. passportDateDTP.Text = a.ExecuteScalar().ToString();
  112. break;
  113. }
  114. }
  115. catch
  116. {
  117. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  118. debugAndTrace.writeInFile("ERROR");
  119. }
  120. }
  121. private void button3_Click(object sender, EventArgs e)
  122. {
  123. try
  124. {
  125. var res = MessageBox.Show("Вы уверены, что хотите удалить данные?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  126. if(res == DialogResult.Yes)
  127. {
  128. string row = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
  129. SqlCommand a = new SqlCommand($"delete from medical_cards where id_card = {row}", sqlConnection);
  130. a.ExecuteNonQuery();
  131. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  132. dataSet = new DataSet();
  133. dataAdapter.Fill(dataSet);
  134. dataGridView1.DataSource = dataSet.Tables[0];
  135. debugAndTrace.writeInFile($"Удалена медицинская карта {row}");
  136. }
  137. else
  138. {
  139. MessageBox.Show("Действие отменено", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  140. }
  141. }
  142. catch
  143. {
  144. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  145. debugAndTrace.writeInFile("ERROR");
  146. }
  147. }
  148. private void button2_Click(object sender, EventArgs e)
  149. {
  150. try
  151. {
  152. index = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
  153. updateMedCard update = new updateMedCard();
  154. update.Show();
  155. debugAndTrace.writeInFile($"Переход на форму изменения медицинской карты {index}");
  156. update.FormClosing += (obj, args) =>
  157. {
  158. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  159. dataSet = new DataSet();
  160. dataAdapter.Fill(dataSet);
  161. dataGridView1.DataSource = dataSet.Tables[0];
  162. };
  163. }
  164. catch
  165. {
  166. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  167. debugAndTrace.writeInFile("ERROR");
  168. }
  169. }
  170. private void button1_Click(object sender, EventArgs e)
  171. {
  172. try
  173. {
  174. insertMedCard insert = new insertMedCard();
  175. insert.Show();
  176. debugAndTrace.writeInFile("Переход на форму добавления медицинской карты");
  177. insert.FormClosing += (obj, args) =>
  178. {
  179. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  180. dataSet = new DataSet();
  181. dataAdapter.Fill(dataSet);
  182. dataGridView1.DataSource = dataSet.Tables[0];
  183. };
  184. }
  185. catch
  186. {
  187. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  188. debugAndTrace.writeInFile("ERROR");
  189. }
  190. }
  191. private void add_patientCard_Click(object sender, EventArgs e)
  192. {
  193. try
  194. {
  195. insertPatientCard insert = new insertPatientCard();
  196. insert.Show();
  197. debugAndTrace.writeInFile($"Переход на форму записи пациента в палату");
  198. insert.FormClosing += (obj, args) =>
  199. {
  200. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  201. dataSet = new DataSet();
  202. dataAdapter.Fill(dataSet);
  203. dataGridView2.DataSource = dataSet.Tables[0];
  204. };
  205. }
  206. catch
  207. {
  208. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  209. debugAndTrace.writeInFile("ERROR");
  210. }
  211. }
  212. private void delete_patientCard_Click(object sender, EventArgs e)
  213. {
  214. try
  215. {
  216. string row = dataGridView2.Rows[dataGridView2.CurrentCell.RowIndex].Cells[0].Value.ToString();
  217. SqlCommand a = new SqlCommand($"update wards set isfree = 1 where id_ward like (select id_ward from patientcards where id_patientcard like {row})", sqlConnection);
  218. a.ExecuteNonQuery();
  219. a = new SqlCommand($"update medical_cards set isill = 0 where id_card like (select id_card from patientcards where id_patientcard like {row})", sqlConnection);
  220. a.ExecuteNonQuery();
  221. a = new SqlCommand($"delete from patientcards where id_patientcard like {row}", sqlConnection);
  222. a.ExecuteNonQuery();
  223. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  224. dataSet = new DataSet();
  225. dataAdapter.Fill(dataSet);
  226. dataGridView2.DataSource = dataSet.Tables[0];
  227. a = new SqlCommand($"select id_card from patientcards where id_patientcard like {row}", sqlConnection);
  228. debugAndTrace.writeInFile($"Пациент {row} выписан из палаты {a.ExecuteScalar()}");
  229. }
  230. catch
  231. {
  232. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  233. debugAndTrace.writeInFile("ERROR");
  234. }
  235. }
  236. bool passwordFounded = false;
  237. private void button1_Click_1(object sender, EventArgs e)
  238. {
  239. try
  240. {
  241. SqlCommand a = new SqlCommand($"select password from employees where id_employee like '{auth.userID}'", sqlConnection);
  242. Array.Resize(ref auth.data, 1);
  243. auth.data[0] = "Пароль: " + checkPasswordTB.Text.GetHashCode();
  244. if (checkPasswordTB.Text.GetHashCode().ToString().Equals(a.ExecuteScalar()))
  245. {
  246. panel1.Visible = false;
  247. passwordFounded = true;
  248. debugAndTrace.writeInFile($"Удачный вход на панель редактирования пользователя {auth.userID}", auth.data);
  249. }
  250. else
  251. {
  252. MessageBox.Show("Пароли не совпадают!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  253. debugAndTrace.writeInFile($"Неудачный вход на панель редактирования пользователя {auth.userID}", auth.data);
  254. }
  255. }
  256. catch
  257. {
  258. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  259. debugAndTrace.writeInFile("ERROR");
  260. }
  261. }
  262. private void button2_Click_1(object sender, EventArgs e)//изменение данных пользователя
  263. {
  264. try
  265. {
  266. SqlCommand a = null;
  267. if (!String.IsNullOrEmpty(newLoginTB.Text))
  268. {
  269. a = new SqlCommand($"select count(*) from employees where login like N'{newLoginTB.Text.GetHashCode()}'", sqlConnection);
  270. MessageBox.Show(a.ExecuteScalar().ToString());
  271. if (a.ExecuteScalar().ToString().Equals("0"))
  272. {
  273. Array.Resize(ref auth.data, auth.data.Length + 1);
  274. auth.data[auth.data.Length - 1] = "Логин: " + newLoginTB.Text.GetHashCode().ToString();
  275. a = new SqlCommand($"update employees set login = @login where id_employee like '{auth.userID}'", sqlConnection);
  276. a.Parameters.AddWithValue("login", newLoginTB.Text.GetHashCode());
  277. a.ExecuteNonQuery();
  278. }
  279. }
  280. if (!String.IsNullOrEmpty(newPasswordTB.Text))
  281. {
  282. Array.Resize(ref auth.data, auth.data.Length + 1);
  283. auth.data[auth.data.Length - 1] = "Пароль: " + newPasswordTB.Text.GetHashCode().ToString();
  284. a = new SqlCommand($"update employees set password = @password where id_employee like {auth.userID}", sqlConnection);
  285. a.Parameters.AddWithValue("password", newPasswordTB.Text.GetHashCode());
  286. a.ExecuteNonQuery();
  287. }
  288. DateTime date1 = DateTime.Parse(birthdateDTP.Text);
  289. DateTime date2 = DateTime.Parse(passportDateDTP.Text);
  290. a = new SqlCommand($"update employees set surname_employee = @surname_employee, name_employee = @name_employee, midname_employee = @midname_employee, date_birthday_employee = @date_birthday_employee, telephone_employee = @telephone_employee, passport_number_employee = @passport_number_employee, passport_date_employee = @passport_date_employee, passport_place_employee = @passport_place_employee, passport_code_employee = @passport_code_employee where id_employee like '{auth.userID}'", sqlConnection);
  291. a.Parameters.AddWithValue("surname_employee", newSuraname_employeeTB.Text);
  292. a.Parameters.AddWithValue("name_employee", newName_employeeTB.Text);
  293. a.Parameters.AddWithValue("midname_employee", newMidname_employeeTB.Text);
  294. a.Parameters.AddWithValue("date_birthday_employee", $"{date1.Day}/{date1.Month}/{date1.Year}");
  295. a.Parameters.AddWithValue("telephone_employee", newTelephone_employeeMTB.Text);
  296. a.Parameters.AddWithValue("passport_number_employee", passportNumberMTB.Text);
  297. a.Parameters.AddWithValue("passport_date_employee", $"{date2.Day}/{date2.Month}/{date2.Year}");
  298. a.Parameters.AddWithValue("passport_place_employee", newPassport_place_employeeTB.Text);
  299. a.Parameters.AddWithValue("passport_code_employee", passportCodeMTB.Text);
  300. Array.Resize(ref auth.data, 9);
  301. auth.data[0] = $"Фамилия: " + newSuraname_employeeTB.Text;
  302. auth.data[1] = $"Имя: " + newName_employeeTB.Text;
  303. auth.data[2] = $"Отчетсво: " + newMidname_employeeTB.Text;
  304. auth.data[3] = $"Дата рождения: " + $"{date1.Month}/{date1.Day}/{date1.Year}";
  305. auth.data[4] = $"Телефон: " + newTelephone_employeeMTB.Text;
  306. auth.data[5] = $"Серия и номер паспорта: " + passportNumberMTB.Text;
  307. auth.data[6] = $"Дата выдачи паспорта: " + $"{date2.Month}/{date2.Day}/{date2.Year}";
  308. auth.data[7] = $"Кем выдан: " + newPassport_place_employeeTB.Text;
  309. auth.data[8] = $"Код подразделения: " + passportCodeMTB.Text;
  310. if(a.ExecuteNonQuery() == 1)
  311. {
  312. MessageBox.Show($"Данные успешно изменены", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  313. debugAndTrace.writeInFile($"Редактирование данных пользователя {auth.userID}", auth.data);
  314. }
  315. else
  316. {
  317. MessageBox.Show("Произошла ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  318. debugAndTrace.writeInFile("Ошибка добавления данных", auth.data);
  319. }
  320. }
  321. catch
  322. {
  323. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  324. debugAndTrace.writeInFile("ERROR");
  325. }
  326. }
  327. string[][] recipe = new string[0][];
  328. private void updateRecipe()
  329. {
  330. try
  331. {
  332. dataGridView4.Columns.Clear();
  333. dataGridView4.Columns.Add("first", "Название");
  334. dataGridView4.Columns.Add("second", "Количество");
  335. dataGridView4.Columns.Add("third", "Сумма");
  336. dataGridView4.Rows.Clear();
  337. for (int l = 0; l < recipe.Length; l++)
  338. {
  339. dataGridView4.Rows.Add();
  340. for (int i = 0; i < recipe[l].Length; i++)
  341. {
  342. dataGridView4.Rows[l].Cells[i].Value = recipe[l][i];
  343. }
  344. }
  345. }
  346. catch
  347. {
  348. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  349. debugAndTrace.writeInFile("ERROR");
  350. }
  351. }
  352. int sum = 0;
  353. private void addDrugBTN_Click(object sender, EventArgs e)
  354. {
  355. try
  356. {
  357. Array.Resize(ref auth.data, 4);
  358. Array.Resize(ref recipe, recipe.Length + 1);
  359. recipe[recipe.Length - 1] = new string[3];
  360. string drugRow = dataGridView3.Rows[dataGridView3.CurrentCell.RowIndex].Cells[0].Value.ToString();
  361. SqlCommand a = new SqlCommand($"select name_drugs, price_drugs from drugs where id_drugs like '{drugRow}'", sqlConnection);
  362. SqlDataReader reader = a.ExecuteReader();
  363. reader.Read();
  364. recipe[recipe.Length - 1][0] = reader.GetString(0);
  365. recipe[recipe.Length - 1][1] = amountDrug.Value.ToString();
  366. recipe[recipe.Length - 1][2] = (reader.GetInt32(1) * (int)amountDrug.Value).ToString();
  367. sum += reader.GetInt32(1) * (int)amountDrug.Value;
  368. auth.data[0] = $"Название добавленного лекарства: {reader.GetString(0)}";
  369. auth.data[1] = $"Количество добавленного лекарства: {amountDrug.Value}";
  370. auth.data[2] = $"Цена добавленного лекарства: {(reader.GetInt32(1) * (int)amountDrug.Value).ToString()}";
  371. auth.data[3] = $"Общая стоимость: {sum}";
  372. reader.Close();
  373. updateRecipe();
  374. costL.Text = $"Общая стоимость: {sum}";
  375. debugAndTrace.writeInFile($"Добавление лекарства {drugRow} в рецепт", auth.data);
  376. }
  377. catch
  378. {
  379. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  380. debugAndTrace.writeInFile("ERROR");
  381. }
  382. }
  383. private void clearBTN_Click(object sender, EventArgs e)
  384. {
  385. try
  386. {
  387. Array.Resize(ref recipe, 0);
  388. updateRecipe();
  389. debugAndTrace.writeInFile("Очистка рецепта");
  390. }
  391. catch
  392. {
  393. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  394. debugAndTrace.writeInFile("ERROR");
  395. }
  396. }
  397. private void button3_Click_1(object sender, EventArgs e)
  398. {
  399. try
  400. {
  401. insertDrug insert = new insertDrug();
  402. insert.Show();
  403. debugAndTrace.writeInFile("Переход на форму добавления лекарства");
  404. insert.FormClosing += (obj, args) =>
  405. {
  406. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  407. dataSet = new DataSet();
  408. dataAdapter.Fill(dataSet);
  409. dataGridView3.DataSource = dataSet.Tables[0];
  410. };
  411. }
  412. catch
  413. {
  414. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  415. debugAndTrace.writeInFile("ERROR");
  416. }
  417. }
  418. private void button3_Click_2(object sender, EventArgs e)
  419. {
  420. try
  421. {
  422. index = dataGridView3.Rows[dataGridView3.CurrentCell.RowIndex].Cells[0].Value.ToString();
  423. updateDrug update = new updateDrug();
  424. update.Show();
  425. debugAndTrace.writeInFile("Переход на форму изменения лекарства");
  426. update.FormClosing += (obj, args) =>
  427. {
  428. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  429. dataSet = new DataSet();
  430. dataAdapter.Fill(dataSet);
  431. dataGridView3.DataSource = dataSet.Tables[0];
  432. };
  433. }
  434. catch
  435. {
  436. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  437. debugAndTrace.writeInFile("ERROR");
  438. }
  439. }
  440. private void deleteDrugsBTN_Click(object sender, EventArgs e)
  441. {
  442. try
  443. {
  444. var res = MessageBox.Show("Вы уверены, что хотите удалить данные?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  445. if (res == DialogResult.Yes)
  446. {
  447. string row = dataGridView3.Rows[dataGridView3.CurrentCell.RowIndex].Cells[0].Value.ToString();
  448. SqlCommand a = new SqlCommand($"delete from drugs where id_drugs = {row}", sqlConnection);
  449. a.ExecuteNonQuery();
  450. dataAdapter = new SqlDataAdapter(query, sqlConnection);
  451. dataSet = new DataSet();
  452. dataAdapter.Fill(dataSet);
  453. dataGridView3.DataSource = dataSet.Tables[0];
  454. debugAndTrace.writeInFile($"Удалено лекарство {row}");
  455. }
  456. else
  457. {
  458. MessageBox.Show("Действие отменено", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  459. }
  460. }
  461. catch
  462. {
  463. MessageBox.Show("Произошла непредваиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  464. debugAndTrace.writeInFile("ERROR");
  465. }
  466. }
  467. private void label9_Click(object sender, EventArgs e)
  468. {
  469. }
  470. string header = "Рецепт", text = "";
  471. private void print_Click(object sender, EventArgs e)
  472. {
  473. for (int i = 0; i < recipe.Length; i++)
  474. {
  475. for (int j = 0; j < recipe[i].Length; j++)
  476. {
  477. if(j == recipe[i].Length - 1)
  478. {
  479. text += $"{recipe[i][j]}.";
  480. }
  481. else
  482. {
  483. text += $"{recipe[i][j]},";
  484. }
  485. }
  486. text += "\n";
  487. }
  488. PrintDocument doc = new PrintDocument();
  489. doc.PrintPage += PrintPageHandler;
  490. PrintDialog dial = new PrintDialog();
  491. dial.Document = doc;
  492. if (dial.ShowDialog() == DialogResult.OK)
  493. {
  494. dial.Document.Print();
  495. }
  496. }
  497. void PrintPageHandler(object sender, PrintPageEventArgs e)
  498. {
  499. e.Graphics.DrawString(header, new Font("Times New Roman", 18), Brushes.Black, 240, 30);
  500. e.Graphics.DrawString(text, new Font("Times New Roman", 14), Brushes.Black, 10, 100);
  501. }
  502. }
  503. }