MainWindow.axaml.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Shapes;
  3. using Avalonia.Interactivity;
  4. using Avalonia.Media;
  5. using HarfBuzzSharp;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. namespace AvaloniaApplication1
  12. {
  13. public struct InfoUser
  14. {
  15. public string surname;
  16. public string name;
  17. public string patronymic;
  18. public string gender;
  19. public string phone;
  20. public int dayBirth;
  21. public int monthBirth;
  22. public int yearBirth;
  23. public string weekDay;
  24. public string sign;
  25. public string Concat()
  26. {
  27. return surname + ";" + name + ";" + patronymic + ";" + gender + ";" + phone + ";" + dayBirth + ";" + monthBirth + ";" + yearBirth + ";" + weekDay + ";" + sign;
  28. }
  29. }
  30. public partial class MainWindow : Window
  31. {
  32. public MainWindow()
  33. {
  34. InitializeComponent();
  35. }
  36. private void WriteFile(object sender, RoutedEventArgs e)
  37. {
  38. List<InfoUser> listUser = new List<InfoUser>();
  39. bool flag = true;
  40. try
  41. {
  42. Regex rSurname = new Regex("[À-ß][à-ÿ]{1,}");
  43. bool fSurname = rSurname.IsMatch(tbSurname.Text);
  44. if (fSurname == false)
  45. flag = false;
  46. Regex rName = new Regex("[À-ß][à-ÿ]{0,}");
  47. bool fName = rName.IsMatch(tbName.Text);
  48. if (fName == false)
  49. flag = false;
  50. Regex rPatr = new Regex("[À-ß][à-ÿ]{0,}");
  51. bool fPatr = rPatr.IsMatch(tbPatr.Text);
  52. if (fPatr == false)
  53. flag = false;
  54. Regex rPhone = new Regex(@"^8(\d{3})\d{3}(\d{2}){2}$");
  55. bool fPhone = rPhone.IsMatch(tbPhone.Text);
  56. if (fPhone == false)
  57. flag = false;
  58. }
  59. catch
  60. {
  61. flag = false;
  62. }
  63. if (flag == true)
  64. {
  65. string gender = "";
  66. if (rbPzh.IsChecked == true) gender = "Æåíñêèé";
  67. if (rbPm.IsChecked == true) gender = "Ìóæñêîé";
  68. int year = Convert.ToInt32(tbYear.Text);
  69. int month = Convert.ToInt32(cbMonth.SelectedIndex);
  70. int day = Convert.ToInt32(tbDay.Text);
  71. DateTime date = new DateTime(year, month, day);
  72. string dayWeek = date.DayOfWeek.ToString();
  73. string sign = "";
  74. if ((day >= 24 && day <= 30 && month == 12) || (day <= 30 && month == 1)) sign = "Ìîðîç";
  75. if ((day == 31 && month == 1) || (day >= 1 && day <= 28 && month == 2)) sign = "Âåëåñ";
  76. if ((day >= 1 && day <= 31 && month == 3)) sign = "Ìàêîøü";
  77. if ((day >= 1 && day <= 30 && month == 4)) sign = "Æèâà";
  78. if ((day >= 1 && day <= 14 && month == 5)) sign = "ßðèëà";
  79. if ((day >= 15 && day <= 31 && month == 5) || (day <= 2 && month == 6)) sign = "Ëåëÿ";
  80. if ((day >= 2 && day <= 12 && month == 6)) sign = "Êîñòðîìà";
  81. if (((day >= 13 && day <= 30 && month == 6) || (day <= 6 && month == 7)) && (day != 24 && month == 6)) sign = "Äîäîëà";
  82. if (day == 24 && month == 6) sign = "Èâàí Êóïàëà";
  83. if ((day >= 7 && day <= 31 && month == 7)) sign = "Ëàäà";
  84. if ((day >= 1 && day <= 28 && month == 8)) sign = "Ïåðóí";
  85. if ((day >= 29 && day <= 31 && month == 8) || (day <= 13 && month == 9)) sign = "Ñåâà";
  86. if ((day >= 14 && day <= 27 && month == 9)) sign = "Ðîæåíèöà";
  87. if ((day >= 28 && day <= 30 && month == 9) || (day <= 15 && month == 10)) sign = "Ñâàðîæè÷è";
  88. if ((day >= 16 && day <= 31 && month == 10) || (day <= 8 && month == 11)) sign = "Ìîðåíà";
  89. if ((day >= 9 && day <= 28 && month == 11)) sign = "Çèìà";
  90. if ((day >= 29 && day <= 30 && month == 11) || (day <= 23 && month == 12)) sign = "Êàðà÷óí";
  91. listUser.Add(new InfoUser
  92. {
  93. surname = tbSurname.Text,
  94. name = tbName.Text,
  95. patronymic = tbPatr.Text,
  96. gender = gender,
  97. phone = tbPhone.Text,
  98. dayBirth = day,
  99. monthBirth = month,
  100. yearBirth = year,
  101. weekDay = dayWeek,
  102. sign = sign
  103. });
  104. using (StreamWriter streamWriter = new StreamWriter("User.csv", true))
  105. {
  106. foreach(InfoUser u in listUser)
  107. {
  108. streamWriter.WriteLine(u.Concat());
  109. }
  110. }
  111. MessageWriteFile.IsVisible = true;
  112. MessageProblem.IsVisible = false;
  113. }
  114. else
  115. {
  116. MessageProblem.IsVisible = true;
  117. MessageWriteFile.IsVisible = false;
  118. }
  119. }
  120. public SolidColorBrush color(string gender)
  121. {
  122. switch (gender)
  123. {
  124. case "Ìóæñêîé":
  125. return new SolidColorBrush(Color.FromArgb(65, 176, 209, 249));
  126. case "Æåíñêèé":
  127. return new SolidColorBrush(Color.FromArgb(65, 253, 196, 251));
  128. default:
  129. return new SolidColorBrush(Color.FromRgb(0, 0, 0));
  130. }
  131. }
  132. private void ReadFile(object sender, RoutedEventArgs e)
  133. {
  134. MainPanel.IsVisible = false;
  135. ShowUsers.IsVisible = true;
  136. List<InfoUser> sortUser = new List<InfoUser>();
  137. using (StreamReader sr = new StreamReader("User.csv"))
  138. {
  139. string line = "";
  140. List<InfoUser> listUser = new List<InfoUser>();
  141. while (!sr.EndOfStream)
  142. {
  143. line = sr.ReadLine();
  144. string[] lineArray = line.Split(";");
  145. listUser.Add(new InfoUser
  146. {
  147. surname = lineArray[0],
  148. name = lineArray[1],
  149. patronymic = lineArray[2],
  150. gender = lineArray[3],
  151. phone = lineArray[4],
  152. dayBirth = Convert.ToInt32(lineArray[5]),
  153. monthBirth = Convert.ToInt32(lineArray[6]),
  154. yearBirth = Convert.ToInt32(lineArray[7]),
  155. weekDay = lineArray[8],
  156. sign = lineArray[9]
  157. });
  158. }
  159. sortUser = listUser.OrderBy(x => x.surname).ToList();
  160. }
  161. File.Create("User.csv").Close();
  162. using (StreamWriter streamWriter = new StreamWriter("User.csv", true))
  163. {
  164. foreach (InfoUser u in sortUser)
  165. {
  166. streamWriter.WriteLine(u.Concat());
  167. }
  168. }
  169. using (StreamReader sr = new StreamReader("User.csv"))
  170. {
  171. string line = "";
  172. while (!sr.EndOfStream)
  173. {
  174. line = sr.ReadLine();
  175. string[] lineArray = line.Split(";");
  176. TextBlock tbFIO = new TextBlock()
  177. {
  178. Text = "ÔÈÎ: " + lineArray[0] + " " + lineArray[1] + " " + lineArray[2],
  179. };
  180. TextBlock tbGender = new TextBlock()
  181. {
  182. Text = "Ïîë: " + lineArray[3],
  183. };
  184. TextBlock tbPhone = new TextBlock()
  185. {
  186. Text = "Òåëåôîí: " + lineArray[4],
  187. };
  188. TextBlock tbDataBirth = new TextBlock()
  189. {
  190. Text = "Äàòà ðîæäåíèÿ: " + lineArray[5] + "." + lineArray[6] + "." + lineArray[7],
  191. };
  192. TextBlock tbDayWeek = new TextBlock()
  193. {
  194. Text = "Äåíü ðîæäåíèÿ íà íåäåëå: " + lineArray[8],
  195. };
  196. TextBlock tbSing = new TextBlock()
  197. {
  198. Text = "Çíàê ïî äðåâíåñëàâÿíñêîìó ãîðîñêîïó: " + lineArray[9],
  199. };
  200. StackPanel spUser = new StackPanel();
  201. spUser.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
  202. spUser.Children.Add(tbFIO);
  203. spUser.Children.Add(tbGender);
  204. spUser.Children.Add(tbPhone);
  205. spUser.Children.Add(tbDataBirth);
  206. spUser.Children.Add(tbDayWeek);
  207. spUser.Children.Add(tbSing);
  208. Border border = new Border();
  209. border.Background = color(lineArray[3]);
  210. border.BorderBrush = Brushes.Indigo;
  211. border.BorderThickness = new Avalonia.Thickness(2);
  212. border.CornerRadius = new Avalonia.CornerRadius(50);
  213. border.Margin = new Avalonia.Thickness(10);
  214. border.Padding = new Avalonia.Thickness(20);
  215. border.Child = spUser;
  216. ShowUsers.Children.Add(border);
  217. }
  218. }
  219. }
  220. private void BackClick(object sender, RoutedEventArgs e)
  221. {
  222. ShowUsers.IsVisible = false;
  223. MainPanel.IsVisible = true;
  224. }
  225. }
  226. }