MainWindow.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.IO;
  16. using static System.Net.Mime.MediaTypeNames;
  17. namespace WpfApp1
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для MainWindow.xaml
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. string pant = "1.txt";
  25. public MainWindow()
  26. {
  27. InitializeComponent();
  28. }
  29. struct people
  30. {
  31. public string name;
  32. public string dateB;
  33. public string pol;
  34. public string di;
  35. }
  36. List<people> peopleList = new List<people>();
  37. int n = 1;
  38. bool flag = false;
  39. int count = 0;
  40. string zapis()
  41. {
  42. string text = "";
  43. text += tb_name + " ";
  44. text += dp_date + " ";
  45. if (lb_pol.SelectedItem is per person)
  46. {
  47. text += person.pol + " ";
  48. //MessageBox.Show(person.pol);
  49. }
  50. if(cb_1.IsChecked == true)
  51. {
  52. text += cb_1.Content;
  53. }
  54. if(cb_2.IsChecked == true)
  55. {
  56. text += cb_2.Content;
  57. }
  58. if(cb_3.IsChecked == true)
  59. {
  60. text += cb_3.Content;
  61. }
  62. return text;
  63. }
  64. void initialDate(int n)
  65. {
  66. using (StreamReader sr = new StreamReader(pant))
  67. {
  68. try
  69. {
  70. if (flag == true)
  71. {
  72. for (int i = 0; i < count; i++)
  73. {
  74. sr.ReadLine();
  75. }
  76. }
  77. string[] pl = sr.ReadLine().Split(' ');
  78. people peoples = new people();
  79. peoples.name = (pl[n]);
  80. peoples.dateB = pl[n + 1];
  81. peoples.pol = pl[n + 3];
  82. peoples.di = pl[n + 4];
  83. peopleList.Add(peoples);
  84. }
  85. catch
  86. {
  87. MessageBox.Show("больше данных нет");
  88. }
  89. }
  90. }
  91. void show()
  92. {
  93. initialDate(n);
  94. foreach (people people in peopleList)
  95. {
  96. nameV.Content = Convert.ToString(people.name);
  97. datenV.Content = Convert.ToString(people.dateB);
  98. polV.Content = Convert.ToString(people.pol);
  99. diV.Content = Convert.ToString(people.di);
  100. }
  101. }
  102. private void Button_Click(object sender, RoutedEventArgs e)
  103. {
  104. File.AppendAllText(pant, zapis() + Environment.NewLine);
  105. }
  106. private void Button_Click_1(object sender, RoutedEventArgs e)
  107. {
  108. show();
  109. flag = true;
  110. }
  111. private void Button_Click_2(object sender, RoutedEventArgs e)
  112. {
  113. if (flag==true)
  114. {
  115. count++;
  116. show();
  117. }
  118. }
  119. }
  120. }