mainMenu.cs 29 KB

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