Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.54 KB | None | 0 0
  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.Xml;
  11. using System.Xml.Linq;
  12. using System.IO;
  13. using iTextSharp.text;
  14. using iTextSharp.text.pdf;
  15. using Excel = Microsoft.Office.Interop.Excel;
  16. using Word = Microsoft.Office.Interop.Word;
  17.  
  18. namespace Labo5NIKITA_2
  19. {
  20. public partial class Form1 : Form
  21. {
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. XDocument mydoc = new XDocument(new XElement("Labo5NIKITA"));
  26. mydoc.Save("Labo5NIKITA.xml");
  27. загрузитьДанныеИзXmlФайлаToolStripMenuItem.Enabled = false;
  28. загрузитьДанныеИзXmlФайлаToolStripMenuItem.ToolTipText = "Кнопка будет разблокирована после сохранения txt в xml!";
  29. listBox1.Focus();
  30. textBox1.ReadOnly = true;
  31. textBox2.ReadOnly = true;
  32. textBox3.ReadOnly = true;
  33. textBox4.ReadOnly = true;
  34. textBox5.Visible = false;
  35. label6.Visible = false;
  36. button1.Visible = false;
  37. }
  38.  
  39. //Сохраняет данные из txt в xml
  40. private void СохранениеДанныхИзТекстовогоФайлаВXmlФайлToolStripMenuItem_Click(object sender, EventArgs e)
  41. {
  42. XDocument mydoc = new XDocument(new XElement("Labo5NIKITA"));
  43. mydoc.Save("Labo5NIKITA.xml");
  44. XElement myelement = mydoc.Element("Labo5NIKITA");
  45. try
  46. {
  47. string text = "";
  48. string[] print = File.ReadAllLines("Sickleave.txt", Encoding.GetEncoding(1251));
  49. bool number = false;
  50. for (int i = 0; i < print.Count(); i++)
  51. {
  52. text = print[i];
  53. string[] wd = text.Split(' ');
  54. if (wd.Count() > 6)
  55. {
  56. //Проверка фамилии на содержание только букв
  57. try
  58. {
  59. foreach (char ch in wd[0])
  60. {
  61. if (ch >= '0' && ch <= '9')
  62. {
  63. number = true;
  64. }
  65. }
  66. if (number)
  67. {
  68. wd[0] = "Неверные данные";
  69. }
  70. }
  71. catch
  72. {
  73. wd[0] = "Неверные данные";
  74. }
  75. //Проверка имени на содержание только букв
  76. try
  77. {
  78. foreach (char ch in wd[1])
  79. {
  80. if (ch >= '0' && ch <= '9')
  81. {
  82. number = true;
  83. }
  84. }
  85. if (number)
  86. {
  87. wd[1] = "Неверные данные";
  88. }
  89. }
  90. catch
  91. {
  92. wd[1] = "Неверные данные";
  93. }
  94. //Проверка отчества на содержание только букв
  95. try
  96. {
  97. foreach (char ch in wd[2])
  98. {
  99. if (ch >= '0' && ch <= '9')
  100. {
  101. number = true;
  102. }
  103. }
  104. if (number)
  105. {
  106. wd[2] = "Неверные данные";
  107. }
  108. }
  109. catch
  110. {
  111. wd[2] = "Неверные данные";
  112. }
  113. //Проверка сопоставления дат(дата посещения врача не может быть ранее даты рождения)
  114. try
  115. {
  116. if (Convert.ToDateTime(wd[4]) < Convert.ToDateTime(wd[3]))
  117. {
  118. wd[3] = "Неверные данные";
  119. wd[4] = "Неверные данные";
  120. }
  121. }
  122. catch
  123. {
  124. wd[3] = "Неверные данные";
  125. wd[4] = "Неверные данные";
  126. }
  127. //Проверка диагноза на содержание только букв
  128. try
  129. {
  130. foreach (char ch in wd[5])
  131. {
  132. if (ch >= '0' && ch <= '9')
  133. {
  134. number = true;
  135. }
  136. }
  137. if (number)
  138. {
  139. wd[5] = "Неверные данные";
  140. }
  141. }
  142. catch
  143. {
  144. wd[5] = "Неверные данные";
  145. }
  146. //Проверка пола на содержание только букв
  147. try
  148. {
  149. foreach (char ch in wd[6])
  150. {
  151. if (ch >= '0' && ch <= '9')
  152. {
  153. number = true;
  154. }
  155. }
  156. if (number)
  157. {
  158. wd[6] = "Неверные данные";
  159. }
  160. }
  161. catch
  162. {
  163. wd[6] = "Неверные данные";
  164. }
  165. myelement.Add(new XElement("Больничная_запись", new XAttribute("ФИО", wd[0] + "_" + wd[1] + "_" + wd[2]), new XElement("Дата_рождения", wd[3]), new XElement("Дата_обращения_к_доктору", wd[4]), new XElement("Диагноз", wd[5]), new XElement("Пол", wd[6])));
  166. mydoc.Save("Labo5NIKITA.xml");
  167. }
  168. else
  169. {
  170. MessageBox.Show("Одна из строк документа содержит неверные данные! Эта строка не будет сохранена!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  171. }
  172. }
  173. MessageBox.Show("Сохранение прошло успешно!", "Выполнено!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  174. загрузитьДанныеИзXmlФайлаToolStripMenuItem.Enabled = true;
  175. загрузитьДанныеИзXmlФайлаToolStripMenuItem.ToolTipText = "Загружает xml на форму";
  176. }
  177.  
  178. catch (Exception error)
  179. {
  180. MessageBox.Show("Ошибка:\n" + error.Message, "Ошибка записи", MessageBoxButtons.OK, MessageBoxIcon.Error);
  181. }
  182. }
  183. //Загрузка данных из xml на форму
  184. private void ЗагрузитьДанныеИзXmlФайлаToolStripMenuItem_Click(object sender, EventArgs e)
  185. {
  186. try
  187. {
  188. XDocument mydoc = XDocument.Load("Labo5NIKITA.xml");
  189. XElement myelement = mydoc.Element("Labo5NIKITA");
  190.  
  191. foreach (XElement elements in myelement.Elements("Больничная_запись").ToList())
  192. {
  193. listBox1.Items.Add(elements.Attribute("ФИО").Value);
  194. }
  195. listBox1.SelectedIndex = 0;
  196. MessageBox.Show("Запись прошла успешно!", "Выполнено!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  197. }
  198.  
  199. catch (Exception error)
  200. {
  201. MessageBox.Show("Ошибка:\n" + error.Message, "Ошибка записи!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  202. }
  203.  
  204. }
  205. //Отображение данных из xml в textbox`ы
  206. private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
  207. {
  208. try
  209. {
  210. XDocument mydoc = XDocument.Load("Labo5NIKITA.xml");
  211. XElement myelement = mydoc.Element("Labo5NIKITA");
  212. int count = -1;
  213. foreach (XElement elements in myelement.Elements("Больничная_запись").ToList())
  214. {
  215. count++;
  216. if (count == listBox1.SelectedIndex)
  217. {
  218. textBox1.Text = elements.Element("Дата_рождения").Value;
  219. textBox2.Text = elements.Element("Дата_обращения_к_доктору").Value;
  220. textBox3.Text = elements.Element("Диагноз").Value;
  221. textBox4.Text = elements.Element("Пол").Value;
  222. textBox5.Text = elements.Attribute("ФИО").Value;
  223. break;
  224. }
  225. }
  226. }
  227.  
  228. catch (Exception error)
  229. {
  230. MessageBox.Show("Ошибка:\n" + error.Message, "Ошибка чтения файла!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  231. }
  232. }
  233. //Удаление элемента через contextmenustrip
  234. private void УдалитьToolStripMenuItem_Click(object sender, EventArgs e)
  235. {
  236. if (File.Exists("Labo5NIKITA.xml"))
  237. {
  238. XDocument mydoc = XDocument.Load("Labo5NIKITA.xml");
  239. XElement myelement = mydoc.Element("Labo5NIKITA");
  240. int count = -1;
  241. try
  242. {
  243. if (listBox1.Items.Count != 0)
  244. {
  245. foreach (XElement elements in myelement.Elements("Больничная_запись").ToList())
  246. {
  247. count++;
  248. if (count != listBox1.SelectedIndex)
  249. {
  250. elements.Remove();
  251. listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]);
  252. textBox1.Text = "";
  253. textBox2.Text = "";
  254. textBox3.Text = "";
  255. textBox4.Text = "";
  256. mydoc.Save("Labo5NIKITA.xml");
  257. MessageBox.Show("Удаление элемента прошло успешно!", "Выполнено!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  258. break;
  259. }
  260. }
  261. }
  262. else
  263. {
  264. MessageBox.Show("Нет элементов!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  265. }
  266. }
  267. catch (Exception error)
  268. {
  269. MessageBox.Show("Ошибка:" + error.Message, "Ошибка чтения файла!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  270. }
  271. }
  272. else
  273. {
  274. MessageBox.Show("Файл - Labo5NIKITA.xml - не существует!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  275. }
  276. }
  277.  
  278. //Добавление элемента через contextmenustrip
  279. private void ToolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)
  280. {
  281. bool number = false;
  282.  
  283. if (e.KeyChar == (char)Keys.Enter)
  284. {
  285. if (toolStripTextBox1.TextLength != 0)
  286. {
  287. string[] wd = toolStripTextBox1.Text.Split(' ');
  288. if (wd.Count() > 4)
  289. {
  290. try
  291. {
  292. if (wd.Count() > 6)
  293. {
  294. try
  295. {
  296. //Проверка первого слова на содержание только букв
  297. foreach (char ch in wd[0])
  298. {
  299. if (ch >= '0' && ch <= '9')
  300. {
  301. number = true;
  302. }
  303. }
  304. if (number)
  305. {
  306. wd[0] = "Неверные данные";
  307. }
  308. }
  309. catch
  310. {
  311. wd[0] = "Неверные данные";
  312. }
  313. //Проверка имени на содержание только букв
  314. try
  315. {
  316. foreach (char ch in wd[1])
  317. {
  318. if (ch >= '0' && ch <= '9')
  319. {
  320. number = true;
  321. }
  322. }
  323. if (number)
  324. {
  325. wd[1] = "Неверные данные";
  326. }
  327. }
  328. catch
  329. {
  330. wd[1] = "Неверные данные";
  331. }
  332. //Проверка отчества на содержание только букв
  333. try
  334. {
  335. foreach (char ch in wd[2])
  336. {
  337. if (ch >= '0' && ch <= '9')
  338. {
  339. number = true;
  340. }
  341. }
  342. if (number)
  343. {
  344. wd[2] = "Неверные данные";
  345. }
  346. }
  347. catch
  348. {
  349. wd[2] = "Неверные данные";
  350. }
  351. //Проверка сопоставления дат(дата посещения врача не может быть ранее даты рождения)
  352. try
  353. {
  354. if (Convert.ToDateTime(wd[4]) < Convert.ToDateTime(wd[3]))
  355. {
  356. wd[3] = "Неверные данные";
  357. wd[4] = "Неверные данные";
  358. }
  359. }
  360. catch
  361. {
  362. wd[3] = "Неверные данные";
  363. wd[4] = "Неверные данные";
  364. }
  365. //Проверка диагноза на содержание только букв
  366. try
  367. {
  368. foreach (char ch in wd[5])
  369. {
  370. if (ch >= '0' && ch <= '9')
  371. {
  372. number = true;
  373. }
  374. }
  375. if (number)
  376. {
  377. wd[5] = "Неверные данные";
  378. }
  379. }
  380. catch
  381. {
  382. wd[5] = "Неверные данные";
  383. }
  384. //Проверка пола на содержание только букв
  385. try
  386. {
  387. foreach (char ch in wd[6])
  388. {
  389. if (ch >= '0' && ch <= '9')
  390. {
  391. number = true;
  392. }
  393. }
  394. if (number)
  395. {
  396. wd[6] = "Неверные данные";
  397. }
  398. }
  399. catch
  400. {
  401. wd[6] = "Неверные данные";
  402. }
  403. if (wd[0] != "Неверные данные" && wd[1] != "Неверные данные" && wd[2] != "Неверные данные" && wd[3] != "Неверные данные" && wd[4] != "Неверные данные" && wd[5] != "Неверные данные" && wd[6] != "Неверные данные")
  404. {
  405. XDocument mydoc = XDocument.Load("Labo5NIKITA.xml");
  406. XElement myelement = mydoc.Element("Labo5NIKITA");
  407. myelement.Add(new XElement("Больничная_запись", new XAttribute("ФИО", wd[0] + "_" + wd[1] + "_" + wd[2]), new XElement("Дата_рождения", wd[3]), new XElement("Дата_обращения_к_доктору", wd[4]), new XElement("Диагноз", wd[5]), new XElement("Пол", wd[6])));
  408. mydoc.Save("Labo5NIKITA.xml");
  409. listBox1.Items.Add(wd[0] + "_" + wd[1] + "_" + wd[2]);
  410. toolStripTextBox1.Text = "";
  411. contextMenuStrip1.Hide();
  412. MessageBox.Show("Сохранение прошло успешно!", "Выполнено!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  413. }
  414. else
  415. {
  416. MessageBox.Show("Ошибка: вы ввели неверные данные!\n Проверьте правильность и повторите ввод!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  417. }
  418. }
  419. else
  420. {
  421. MessageBox.Show("Файл не содержит достаточной информации о больном! Проверьте данные и повторите попытку!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  422. }
  423. }
  424. catch (Exception error)
  425. {
  426. MessageBox.Show("Ошибка: " + error.Message, "Ошибка записи файла!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  427. }
  428. }
  429. else
  430. {
  431. MessageBox.Show("Ошибка: вы ввели неверные данные!\n Проверьте правильность и повторите ввод!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  432. }
  433. }
  434. else
  435. {
  436. MessageBox.Show("Ошибка: данные не могут быть пустыми!\n Проверьте правильность и повторите ввод!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  437. }
  438. }
  439. }
  440.  
  441. //Редактирование данных
  442. private void РедактироватьToolStripMenuItem_Click(object sender, EventArgs e)
  443. {
  444. textBox1.ReadOnly = false;
  445. textBox1.ReadOnly = false;
  446. textBox2.ReadOnly = false;
  447. textBox3.ReadOnly = false;
  448. textBox4.ReadOnly = false;
  449. textBox5.Visible = true;
  450. label6.Visible = true;
  451. button1.Visible = true;
  452. listBox1.Enabled = false;
  453. }
  454.  
  455. private void ОпределитьКоличесвтоПациентовСУказаннымДиагназомToolStripMenuItem_Click(object sender, EventArgs e)
  456. {
  457. try
  458. {
  459. if (listBox1.SelectedIndices.Count != 0)
  460. {
  461. Form2 Dialog = new Form2();
  462. String diagnosis;
  463. int counter = 0;
  464. var result = Dialog.ShowDialog();
  465.  
  466. XDocument mydoc = XDocument.Load("Labo5NIKITA.xml");
  467. XElement myelement = mydoc.Element("Labo5NIKITA");
  468. if (result == DialogResult.OK && Dialog.Text != "" && Dialog.Text != " ")
  469. {
  470. diagnosis = Dialog.Text;
  471. Dialog.Close();
  472. foreach (XElement xe in myelement.Elements("Больничная_запись").ToList())
  473. {
  474. if (xe.Element("Диагноз").Value == diagnosis)
  475. {
  476. counter++;
  477. }
  478. }
  479. MessageBox.Show("Количество людей с диагнозом " + diagnosis + " : " + counter, "Поиск осуществлен!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  480. }
  481. else
  482. {
  483. Dialog.Close();
  484. MessageBox.Show("Данные не были введены!", "Поиск не осуществлен!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  485. }
  486. }
  487. else
  488. {
  489. MessageBox.Show("Данные не были загружены на форму!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  490. }
  491. }
  492. catch (Exception error)
  493. {
  494. MessageBox.Show("Ошибка: " + error.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  495. }
  496. }
  497.  
  498. private void ВPdfToolStripMenuItem_Click(object sender, EventArgs e)
  499. {
  500. try
  501. {
  502. if (listBox1.SelectedIndices.Count != 0)
  503. {
  504. if (listBox1.SelectedIndex > -1)
  505. {
  506. var document = new Document();
  507. PdfWriter PDFWrite = PdfWriter.GetInstance(document, new FileStream(Application.StartupPath + @"\Labo5NIKITA.pdf", FileMode.Create));
  508. document.Open();
  509. try
  510. {
  511. BaseFont baseFont = BaseFont.CreateFont(@"C:\Users\nikit\Desktop\Labo5NIKITA_2\Labo5NIKITA_2\bin\Debug\arial.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
  512. iTextSharp.text.Font myfont = new iTextSharp.text.Font(baseFont, 10);
  513. PdfPTable table = new PdfPTable(5);
  514.  
  515. PdfPCell cell = new PdfPCell(new Phrase("Больничный лист", myfont));
  516. table.AddCell(new Paragraph(label1.Text, myfont));
  517. table.AddCell(new Paragraph(label2.Text, myfont));
  518. table.AddCell(new Paragraph(label3.Text, myfont));
  519. table.AddCell(new Paragraph(label4.Text, myfont));
  520. table.AddCell(new Paragraph(label5.Text, myfont));
  521. string recording = listBox1.SelectedItem.ToString();
  522. table.AddCell(new Paragraph(recording, myfont));
  523. table.AddCell(new Paragraph(textBox1.Text, myfont));
  524. table.AddCell(new Paragraph(textBox2.Text, myfont));
  525. table.AddCell(new Paragraph(textBox3.Text, myfont));
  526. table.AddCell(new Paragraph(textBox4.Text, myfont));
  527. document.Add(table);
  528. document.Close();
  529. MessageBox.Show("Формирование карточки в PDF выполнено!", "Выполнено!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  530. }
  531. catch (Exception error)
  532. {
  533. MessageBox.Show("Ошибка: " + error.Message, "Ошибка записи файла!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  534. }
  535. }
  536. else
  537. {
  538. MessageBox.Show("Ошибка: нет выделенных элементов!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  539. }
  540. }
  541. else
  542. {
  543. MessageBox.Show("Ошибка: данные не загружены!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  544. }
  545. }
  546. catch (Exception error)
  547. {
  548. MessageBox.Show("Ошибка: " + error.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  549. }
  550. }
  551.  
  552. private void ВExcelToolStripMenuItem_Click(object sender, EventArgs e)
  553. {
  554. if (listBox1.SelectedIndices.Count != 0)
  555. {
  556. if (listBox1.SelectedIndex > -1)
  557. {
  558. Excel.Application myExcel = new Excel.Application();
  559.  
  560. try
  561. {
  562. Excel.Workbook myBook;
  563. Excel.Worksheet myList;
  564.  
  565. myBook = myExcel.Workbooks.Add();//добавление книги
  566. string FIO = listBox1.SelectedItem.ToString();
  567.  
  568. myList = (Excel.Worksheet)myBook.Sheets[1];//добавление листа
  569.  
  570. myList.Cells[1, 1] = label1.Text;//1-ая строка 1-ый столбец
  571. myList.Cells[1, 2] = label2.Text;//1-ая строка 2-ой столбец
  572. myList.Cells[1, 3] = label3.Text;
  573. myList.Cells[1, 4] = label4.Text;
  574. myList.Cells[1, 5] = label5.Text;
  575.  
  576. myList.Cells[2, 1] = FIO;//2-ая строка 1-ый столбец
  577. myList.Cells[2, 2] = textBox1.Text;//2-ая строка 2-ой столбец
  578. myList.Cells[2, 3] = textBox2.Text;
  579. myList.Cells[2, 4] = textBox3.Text;
  580. myList.Cells[2, 5] = textBox4.Text;
  581.  
  582. myList.Columns[1].Autofit();
  583. myList.Columns[2].Autofit();
  584. myList.Columns[3].Autofit();
  585. myList.Columns[4].Autofit();
  586. myList.Columns[5].Autofit();
  587.  
  588. myBook.SaveAs(@"C:\Users\nikit\Desktop\Labo5NIKITA_2\Labo5NIKITA_2\bin\Debug\Labo5NIKITA.xlsx");
  589. MessageBox.Show("Формирование карточки в EXCEL выполнено!", "Выполнено!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  590. myExcel.Quit();
  591. }
  592. catch (Exception error)
  593. {
  594. MessageBox.Show("Ошибка: " + error.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  595. }
  596. }
  597. else
  598. {
  599. MessageBox.Show("Ошибка: нет выделенных элементов!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  600. }
  601. }
  602. else
  603. {
  604. MessageBox.Show("Ошибка: данные не загружены!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  605. }
  606. }
  607.  
  608. private void ВWordToolStripMenuItem_Click(object sender, EventArgs e)
  609. {
  610. if (listBox1.SelectedIndices.Count != 0)
  611. {
  612. if (listBox1.SelectedIndex > -1)
  613. {
  614. Word._Document wrdDoc;
  615. Word.Selection wrdSelection;
  616. Word.MailMerge wrdMailMerge;
  617. Word.Table wrdTable;
  618.  
  619. Word.Application wrdApp = new Word.Application();
  620.  
  621. wrdDoc = wrdApp.Documents.Add();
  622. wrdDoc.Select();
  623. wrdSelection = wrdApp.Selection;
  624. wrdMailMerge = wrdDoc.MailMerge;
  625.  
  626. string FIO = listBox1.SelectedItem.ToString();
  627.  
  628. wrdTable = wrdDoc.Tables.Add(wrdSelection.Range, 9, 5);
  629.  
  630. wrdTable.Columns[1].SetWidth(100, Word.WdRulerStyle.wdAdjustNone);
  631. wrdTable.Columns[2].SetWidth(100, Word.WdRulerStyle.wdAdjustNone);
  632. wrdTable.Columns[3].SetWidth(100, Word.WdRulerStyle.wdAdjustNone);
  633. wrdTable.Columns[4].SetWidth(100, Word.WdRulerStyle.wdAdjustNone);
  634. wrdTable.Columns[5].SetWidth(100, Word.WdRulerStyle.wdAdjustNone);
  635.  
  636. wrdTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
  637. wrdDoc.Tables[1].Cell(1, 1).Range.InsertAfter(label1.Text);
  638. wrdDoc.Tables[1].Cell(1, 2).Range.InsertAfter(label2.Text);
  639. wrdDoc.Tables[1].Cell(1, 3).Range.InsertAfter(label3.Text);
  640. wrdDoc.Tables[1].Cell(1, 4).Range.InsertAfter(label4.Text);
  641. wrdDoc.Tables[1].Cell(1, 5).Range.InsertAfter(label5.Text);
  642.  
  643. wrdDoc.Tables[1].Cell(2, 1).Range.InsertAfter(FIO);
  644. wrdDoc.Tables[1].Cell(2, 2).Range.InsertAfter(textBox1.Text);
  645. wrdDoc.Tables[1].Cell(2, 3).Range.InsertAfter(textBox2.Text);
  646. wrdDoc.Tables[1].Cell(2, 4).Range.InsertAfter(textBox3.Text);
  647. wrdDoc.Tables[1].Cell(2, 5).Range.InsertAfter(textBox4.Text);
  648.  
  649. wrdDoc.Saved = true;
  650. wrdDoc.SaveAs(@"C:\Users\nikit\Desktop\Labo5NIKITA_2\Labo5NIKITA_2\bin\Debug\Lab05NIKITA.docx");
  651. wrdDoc.Close();
  652. wrdApp.Quit();
  653.  
  654. wrdSelection = null;
  655. wrdMailMerge = null;
  656. wrdDoc = null;
  657. wrdApp = null;
  658. }
  659. else
  660. {
  661. MessageBox.Show("Ошибка: нет выделенных элементов!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  662. }
  663. }
  664. else
  665. {
  666. MessageBox.Show("Ошибка: данные не загружены!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  667. }
  668.  
  669. }
  670.  
  671. private void Button1_Click(object sender, EventArgs e)
  672. {
  673. if (listBox1.SelectedIndices.Count != 0)
  674. {
  675. if (listBox1.SelectedIndex > -1)
  676. {
  677.  
  678. bool number = false;
  679. bool check = true;
  680.  
  681. //Проверка сопоставления дат(дата посещения врача не может быть ранее даты рождения)
  682. try
  683. {
  684. if (Convert.ToDateTime(textBox2.Text) < Convert.ToDateTime(textBox1.Text))
  685. {
  686. check = false;
  687. }
  688. }
  689. catch
  690. {
  691. check = false;
  692. }
  693. //Проверка диагноза на содержание только букв
  694. try
  695. {
  696. foreach (char ch in textBox3.Text)
  697. {
  698. if (ch >= '0' && ch <= '9')
  699. {
  700. number = true;
  701. }
  702. }
  703. if (number)
  704. {
  705. check = false;
  706. }
  707. }
  708. catch
  709. {
  710. check = false;
  711. }
  712. //Проверка пола на содержание только букв
  713. try
  714. {
  715. foreach (char ch in textBox4.Text)
  716. {
  717. if (ch >= '0' && ch <= '9')
  718. {
  719. number = true;
  720. }
  721. }
  722. if (number)
  723. {
  724. check = false;
  725. }
  726. }
  727. catch
  728. {
  729. check = false;
  730. }
  731.  
  732.  
  733. if (check)
  734. {
  735. XDocument mydoc = XDocument.Load("Labo5NIKITA.xml");
  736. XElement myelement = mydoc.Element("Labo5NIKITA");
  737. int i = -1;
  738. foreach (XElement xe in myelement.Elements("Больничная_запись").ToList())
  739. {
  740. i++;
  741. if (i == listBox1.SelectedIndex)
  742. {
  743. xe.Attribute("ФИО").Value = textBox5.Text;
  744. xe.Element("Дата_рождения").Value = textBox1.Text;
  745. xe.Element("Дата_обращения_к_доктору").Value = textBox2.Text;
  746. xe.Element("Диагноз").Value = textBox3.Text;
  747. xe.Element("Пол").Value = textBox4.Text;
  748. mydoc.Save("Labo5NIKITA.xml");
  749. listBox1.Items[i] = textBox5.Text;
  750. MessageBox.Show("Изменение прошло успешно", "Выполнено", MessageBoxButtons.OK, MessageBoxIcon.Information);
  751. listBox1.Focus();
  752. textBox1.ReadOnly = true;
  753. textBox2.ReadOnly = true;
  754. textBox3.ReadOnly = true;
  755. textBox4.ReadOnly = true;
  756. textBox5.Visible = false;
  757. label6.Visible = false;
  758. button1.Visible = false;
  759. listBox1.Enabled = true;
  760. break;
  761. }
  762. }
  763. }
  764. else
  765. MessageBox.Show("Ошибка: вы ввели неверные данные!\n Проверьте правильность и повторите ввод!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  766. }
  767. else
  768. {
  769. MessageBox.Show("Ошибка: элемент не выделен!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  770. }
  771. }
  772. else
  773. MessageBox.Show("Ошибка: нет элементов для редактирования!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  774. }
  775. }
  776.  
  777.  
  778. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement