MainWindow.axaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Media;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. namespace praktika3_graph_interface
  10. {
  11. public struct users
  12. {
  13. public string surname;
  14. public string name;
  15. public string patronymic;
  16. public string phone;
  17. public int birthday;
  18. public int birthmonth;
  19. public int birthyear;
  20. public string gender;
  21. public int den_nedeli;
  22. public string goroskop;
  23. public users(string surname, string name, string patronymic, string phone, int birthday,
  24. int birthmonth, int birthyear, string gender, int den_nedeli, string goroskop)
  25. {
  26. this.surname = surname;
  27. this.name = name;
  28. this.patronymic = patronymic;
  29. this.phone = phone;
  30. this.birthday = birthday;
  31. this.birthmonth = birthmonth;
  32. this.birthyear = birthyear;
  33. this.gender = gender;
  34. this.den_nedeli = den_nedeli;
  35. this.goroskop = goroskop;
  36. }
  37. public void writeToFile(users obj)
  38. {
  39. using (StreamWriter sw = new StreamWriter("users.csv", true, System.Text.Encoding.UTF8))
  40. {
  41. sw.WriteLine(obj.surname + ";" + obj.name + ";" + obj.patronymic + ";" + obj.phone +
  42. ";" + obj.birthday + ";" + obj.birthmonth + ";" + obj.birthyear + ";" + obj.gender + ";" + obj.den_nedeli + ";" + obj.goroskop);
  43. }
  44. }
  45. }
  46. public partial class MainWindow : Window
  47. {
  48. public MainWindow()
  49. {
  50. InitializeComponent();
  51. }
  52. private void getUser(object sender, RoutedEventArgs e)
  53. {
  54. users user = new();
  55. Regex forFIO = new Regex("^[À-ß]{1}[à-ÿ]{2,}$");
  56. Regex forPhone = new Regex("^8{1}[0-9]{10}$");
  57. if (forFIO.IsMatch(tbSurname.Text))
  58. {
  59. user.surname = changeColorIncorrectFormat(tbSurname, true);
  60. if (forFIO.IsMatch(tbName.Text))
  61. {
  62. user.name = changeColorIncorrectFormat(tbName, true);
  63. if (forFIO.IsMatch(tbPatronymic.Text))
  64. {
  65. user.patronymic = changeColorIncorrectFormat(tbPatronymic, true);
  66. if (forPhone.IsMatch(tbPhone.Text))
  67. {
  68. user.phone = changeColorIncorrectFormat(tbPhone, true);
  69. user.birthday = int.Parse(tbBirthday.Text);
  70. user.birthmonth = cbMonth.SelectedIndex;
  71. user.birthyear = int.Parse(tbBirthyear.Text);
  72. if (rbF.IsChecked == true) user.gender = "Æåíñêèé";
  73. if (rbM.IsChecked == true) user.gender = "Ìóæñêîé";
  74. DateOnly date = new DateOnly(user.birthyear, user.birthmonth, user.birthday);
  75. user.den_nedeli = (int)date.DayOfWeek;
  76. user.goroskop = drevneslavyanskiiGoroskop(date);
  77. user.writeToFile(user);
  78. showSuccess();
  79. }
  80. else user.phone = changeColorIncorrectFormat(tbPhone, false);
  81. }
  82. else user.patronymic = changeColorIncorrectFormat(tbPatronymic, false);
  83. }
  84. else user.name = changeColorIncorrectFormat(tbName, false);
  85. }
  86. else user.surname = changeColorIncorrectFormat(tbSurname, false);
  87. Console.WriteLine();
  88. }
  89. private string changeColorIncorrectFormat(TextBox tb, bool correct)
  90. {
  91. if (correct)
  92. {
  93. tb.Foreground = Brushes.Black;
  94. tb.BorderBrush = new SolidColorBrush(Color.FromArgb(100, 0, 0, 0));
  95. }
  96. else
  97. {
  98. tb.BorderBrush = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0));
  99. tb.Foreground = Brushes.Red;
  100. }
  101. return tb.Text;
  102. }
  103. private string drevneslavyanskiiGoroskop(DateOnly birth)
  104. {
  105. string god = "";
  106. int year = birth.Year;
  107. if ((new DateOnly(year, 1, 31) <= birth) && (new DateOnly(year, 2, 28) >= birth)) god = "Âåëåñ";
  108. else if ((new DateOnly(year, 3, 1) <= birth) && (new DateOnly(year, 4, 1) > birth)) god = "Ìàêîøü";
  109. else if ((new DateOnly(year, 4, 1) <= birth) && (new DateOnly(year, 5, 1) > birth)) god = "Æèâà";
  110. else if ((new DateOnly(year, 5, 1) <= birth) && (new DateOnly(year, 5, 15) > birth)) god = "ßðèëî";
  111. else if ((new DateOnly(year, 5, 15) <= birth) && (new DateOnly(year, 6, 3) > birth)) god = "Ëåëÿ";
  112. else if ((new DateOnly(year, 6, 2) <= birth) && (new DateOnly(year, 6, 13) > birth)) god = "Êîñòðîìà";
  113. else if ((new DateOnly(year, 6, 24) == birth)) god = "Èâàí Êóïàëà";
  114. else if ((new DateOnly(year, 6, 13) <= birth) && (new DateOnly(year, 7, 7) > birth)) god = "Äîäîëà";
  115. else if ((new DateOnly(year, 7, 7) <= birth) && (new DateOnly(year, 7, 31) >= birth)) god = "Ëàäà";
  116. else if ((new DateOnly(year, 8, 1) <= birth) && (new DateOnly(year, 8, 29) > birth)) god = "Ïåðóí";
  117. else if ((new DateOnly(year, 8, 29) <= birth) && (new DateOnly(year, 9, 14) > birth)) god = "Ñåâà";
  118. else if ((new DateOnly(year, 9, 14) <= birth) && (new DateOnly(year, 9, 28) > birth)) god = "Ðîæàíèöà";
  119. else if ((new DateOnly(year, 9, 28) <= birth) && (new DateOnly(year, 10, 16) > birth)) god = "Ñâàðîæè÷è";
  120. else if ((new DateOnly(year, 10, 16) <= birth) && (new DateOnly(year, 11, 9) > birth)) god = "Ìîðåíà";
  121. else if ((new DateOnly(year, 11, 9) <= birth) && (new DateOnly(year, 11, 29) > birth)) god = "Çèìà";
  122. else if ((new DateOnly(year, 11, 29) <= birth) && (new DateOnly(year, 12, 24) > birth)) god = "Êàðà÷óí";
  123. else if ((new DateOnly(year, 12, 24) <= birth) && (new DateOnly(year, 1, 31) > birth)) god = "Ðîæàíèöà";
  124. return god;
  125. }
  126. private void showSuccess()
  127. {
  128. bSuccess.IsVisible = true;
  129. }
  130. private void hideSuccess(object sender, RoutedEventArgs e)
  131. {
  132. bSuccess.IsVisible = false;
  133. }
  134. private void showUsers(object sender, RoutedEventArgs e)
  135. {
  136. form.IsVisible = false;
  137. userlist.IsVisible = true;
  138. buttonReturn.IsVisible = true;
  139. List<users> listOfUsers = new();
  140. using (StreamReader sr = new StreamReader("users.csv"))
  141. {
  142. string text = "";
  143. while (!sr.EndOfStream)
  144. {
  145. text = sr.ReadLine();
  146. if (text == "") continue;
  147. string[] buf = text.Split(';');
  148. users user = new();
  149. user.surname = buf[0];
  150. user.name = buf[1];
  151. user.patronymic = buf[2];
  152. user.phone = buf[3];
  153. user.birthday = int.Parse(buf[4]);
  154. user.birthmonth = int.Parse(buf[5]);
  155. user.birthyear = int.Parse(buf[6]);
  156. user.gender = buf[7];
  157. user.den_nedeli = int.Parse(buf[8]);
  158. user.goroskop = buf[9];
  159. listOfUsers.Add(user);
  160. }
  161. listOfUsers.Sort((p1, p2) => p1.surname.CompareTo(p2.surname));
  162. for (int i = 0; i < listOfUsers.Count; i++)
  163. {
  164. TextBlock tbFIO = new TextBlock()
  165. {
  166. Text = listOfUsers[i].surname + " " + listOfUsers[i].name + " " + listOfUsers[i].patronymic,
  167. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
  168. };
  169. TextBlock tbBirth = new TextBlock()
  170. {
  171. Text = listOfUsers[i].birthday + "." + listOfUsers[i].birthmonth + "." + listOfUsers[i].birthyear,
  172. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
  173. };
  174. TextBlock tbPhoneS = new TextBlock()
  175. {
  176. Text = listOfUsers[i].phone,
  177. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
  178. };
  179. TextBlock tbGenderS = new TextBlock()
  180. {
  181. Text = listOfUsers[i].gender,
  182. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
  183. };
  184. TextBlock tbDen = new TextBlock()
  185. {
  186. Text = listOfUsers[i].den_nedeli.ToString(),
  187. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
  188. };
  189. TextBlock tbGoroskopS = new TextBlock()
  190. {
  191. Text = listOfUsers[i].goroskop,
  192. HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
  193. };
  194. StackPanel spUser = new StackPanel();
  195. spUser.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
  196. spUser.Width = 500;
  197. if (tbGenderS.Text == "Æåíñêèé") spUser.Background = new SolidColorBrush(Color.FromArgb(100, 222, 211, 166));
  198. else spUser.Background = new SolidColorBrush(Color.FromArgb(100, 117, 146, 4));
  199. spUser.Children.Add(tbFIO);
  200. spUser.Children.Add(tbBirth);
  201. spUser.Children.Add(tbPhoneS);
  202. spUser.Children.Add(tbGenderS);
  203. spUser.Children.Add(tbDen);
  204. spUser.Children.Add(tbGoroskopS);
  205. Border border = new Border();
  206. border.BorderBrush = new SolidColorBrush(Color.FromArgb(100, 0, 0, 0));
  207. border.Width = spUser.Width;
  208. border.Height = spUser.Height;
  209. border.BorderThickness = new Avalonia.Thickness(5);
  210. border.Margin = new Avalonia.Thickness(10);
  211. border.Child = spUser;
  212. userlist.Children.Add(border);
  213. }
  214. }
  215. }
  216. private void bReturn(object sender, RoutedEventArgs e)
  217. {
  218. form.IsVisible = true;
  219. userlist.IsVisible = false;
  220. }
  221. }
  222. }