MainWindow.axaml.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Media;
  4. using System;
  5. using System.Diagnostics.Metrics;
  6. using System.IO;
  7. using System.Text.RegularExpressions;
  8. namespace AvaloniaApplication1
  9. {
  10. public partial class MainWindow : Window
  11. {
  12. public struct Users
  13. {
  14. public string name;
  15. public string surname;
  16. public string forename;
  17. public string phone;
  18. public string gener;
  19. public int dayBirth;
  20. public string monthBirth;
  21. public int yearBirth;
  22. }
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. }
  27. private void WriteFile(object sender, RoutedEventArgs e)
  28. {
  29. Users user = new Users();
  30. user.name = tbName.Text;
  31. user.surname = tbSurename.Text;
  32. user.forename = tbForename.Text;
  33. user.phone = tbPhone.Text;
  34. if (rbF.IsChecked == true)
  35. {
  36. user.gener = "Æåíñêèé";
  37. }
  38. if (rbM.IsChecked == true)
  39. {
  40. user.gener = "Ìóæñêîé";
  41. }
  42. user.dayBirth = Int32.Parse(tbDay.Text);
  43. var monthNum = cbMonth.SelectedIndex;
  44. switch (cbMonth.SelectedIndex)
  45. {
  46. case 1: user.monthBirth = "ßíâàðü";
  47. break;
  48. case 2:
  49. user.monthBirth = "Ôåâðàëü";
  50. break;
  51. case 3:
  52. user.monthBirth = "Ìàðò";
  53. break;
  54. case 4:
  55. user.monthBirth = "Àïðåëü";
  56. break;
  57. case 5:
  58. user.monthBirth = "Ìàé";
  59. break;
  60. case 6:
  61. user.monthBirth = "Èþíü";
  62. break;
  63. case 7:
  64. user.monthBirth = "Èþëü";
  65. break;
  66. case 8:
  67. user.monthBirth = "Àâãóñò";
  68. break;
  69. case 9:
  70. user.monthBirth = "Ñåíòÿáðü";
  71. break;
  72. case 10:
  73. user.monthBirth = "Îêòÿáðü";
  74. break;
  75. case 11:
  76. user.monthBirth = "Íîÿáðü";
  77. break;
  78. case 12:
  79. user.monthBirth = "Äåêàáðü";
  80. break;
  81. }
  82. user.yearBirth = Int32.Parse(tbYear.Text);
  83. var d = new DateTime(user.yearBirth, cbMonth.SelectedIndex, user.dayBirth);
  84. var whatAncientRusAreYou = "";
  85. if (d.DayOfYear <= 30 || d.DayOfYear >= 359) { whatAncientRusAreYou = "Ìîðîç"; }
  86. if (d.DayOfYear <= 60 && d.DayOfYear >= 31) { whatAncientRusAreYou = "Âåëåñ"; }
  87. if (d.DayOfYear <= 91 && d.DayOfYear >= 61) { whatAncientRusAreYou = "Ìàêîøü"; }
  88. if (d.DayOfYear <= 121 && d.DayOfYear >= 92) { whatAncientRusAreYou = "Æèâà"; }
  89. if (d.DayOfYear <= 135 && d.DayOfYear >= 122) { whatAncientRusAreYou = "ßðèëî"; }
  90. if (d.DayOfYear <= 154 && d.DayOfYear >= 136) { whatAncientRusAreYou = "Ëåëÿ"; }
  91. if (d.DayOfYear <= 164 && d.DayOfYear >= 155) { whatAncientRusAreYou = "Êîñòðîìà"; }
  92. if (d.DayOfYear <= 188 && d.DayOfYear >= 165) { whatAncientRusAreYou = "Äîäîëà"; }
  93. if (d.DayOfYear <= 213 && d.DayOfYear >= 189) { whatAncientRusAreYou = "Ëàäà"; }
  94. if (d.DayOfYear <= 241 && d.DayOfYear >= 214) { whatAncientRusAreYou = "Ïåðóí"; }
  95. if (d.DayOfYear <= 257 && d.DayOfYear >= 242) { whatAncientRusAreYou = "Ñåâà"; }
  96. if (d.DayOfYear <= 271 && d.DayOfYear >= 258) { whatAncientRusAreYou = "Ðîæàíèöà"; }
  97. if (d.DayOfYear <= 289 && d.DayOfYear >= 272) { whatAncientRusAreYou = "Ñâàðîæè÷è"; }
  98. if (d.DayOfYear <= 313 && d.DayOfYear >= 290) { whatAncientRusAreYou = "Ìîðåíà"; }
  99. if (d.DayOfYear <= 333 && d.DayOfYear >= 314) { whatAncientRusAreYou = "Çèìà"; }
  100. if (d.DayOfYear <= 358 && d.DayOfYear >= 334) { whatAncientRusAreYou = "Êàðà÷óí"; }
  101. Regex NameCheck = new Regex("^[À-ß]");
  102. Regex SurenameCheck = new Regex("^[A-ß]+");
  103. Regex PhoneNumber = new Regex("^8\\(\\d{3}\\)\\d{7}");
  104. if (NameCheck.IsMatch(user.name) && SurenameCheck.IsMatch(user.surname) && PhoneNumber.IsMatch(user.phone) && user.gener != null)
  105. {
  106. using (StreamWriter sw = new StreamWriter("users.csv", true, System.Text.Encoding.UTF8))
  107. {
  108. sw.WriteLine(user.name + ";" + user.surname + ";" + user.forename + ";" + user.phone + ";" + user.gener + ";" + user.dayBirth + ";" + user.monthBirth + ";" + user.yearBirth + ";" + d.DayOfYear + ";" + whatAncientRusAreYou);
  109. ShowMessage.Text = "Çàïèñü äîáàâëåíà";
  110. }
  111. } else { ShowMessage.Text = "Çàïèñü íå äîáàâëåíà, îøèáêà â âîäèìûõ äàííûõ"; }
  112. }
  113. public SolidColorBrush color(string continent)
  114. {
  115. switch (continent)
  116. {
  117. case "Ìóæñêîé":
  118. return new SolidColorBrush(Color.FromArgb(35,0,0,255));
  119. case "Æåíñêèé":
  120. return new SolidColorBrush(Color.FromArgb(35, 255, 128, 255));
  121. default:
  122. return new SolidColorBrush(Color.FromRgb(0, 0, 0));
  123. }
  124. }
  125. private void ShowUsersClick(object sender, RoutedEventArgs e)
  126. {
  127. ShowUsers.IsVisible = true;
  128. WritePanel.IsVisible = false;
  129. ShowUsers1.IsVisible = true;
  130. using (StreamReader sr = new StreamReader("users.csv"))
  131. {
  132. var flag = true;
  133. if (flag)
  134. {
  135. string line = "";
  136. while (!sr.EndOfStream)
  137. {
  138. line = sr.ReadLine();
  139. string[] lineArray = line.Split(';');
  140. TextBlock tbName = new TextBlock()
  141. {
  142. Text = "Èìÿ Ôàìèëèÿ" + lineArray[0] + lineArray[1],
  143. };
  144. TextBlock tbForename = new TextBlock()
  145. {
  146. Text = "Îò÷åñòâî:" + lineArray[2]
  147. };
  148. TextBlock tbPhone = new TextBlock()
  149. {
  150. Text = "Òåëåôîí:" + lineArray[3]
  151. };
  152. TextBlock tbGender = new TextBlock()
  153. {
  154. Text = "Ïîë:" + lineArray[4]
  155. };
  156. var monthNum = "";
  157. if (lineArray[5] == "ßíâàðü") { monthNum = "01"; }
  158. else if (lineArray[5] == "Ôåâðàëü") { monthNum = "02"; }
  159. else if (lineArray[5] == "Ìàðò") { monthNum = "03"; }
  160. else if (lineArray[5] == "Àïðåëü") { monthNum = "04"; }
  161. else if (lineArray[5] == "Ìàé") { monthNum = "05"; }
  162. else if (lineArray[5] == "Èþíü") { monthNum = "06"; }
  163. else if (lineArray[5] == "Èþëü") { monthNum = "07"; }
  164. else if (lineArray[5] == "Àâãóñò") { monthNum = "08"; }
  165. else if (lineArray[5] == "Ñåíòÿáðü") { monthNum = "09"; }
  166. else if (lineArray[5] == "Îêòÿáðü") { monthNum = "10"; }
  167. else if (lineArray[5] == "Íîÿáðü") { monthNum = "11"; }
  168. else if (lineArray[5] == "Äåêàáðü") { monthNum = "12"; }
  169. TextBlock tbDate = new TextBlock()
  170. {
  171. Text = "Äàòà ðîæäåíèÿ:" + lineArray[5] + monthNum + lineArray[7],
  172. };
  173. TextBlock tbDateCount = new TextBlock()
  174. {
  175. Text = "Äàòà ðîæäåíèÿ ïî ñ÷¸òó:" + lineArray[8],
  176. };
  177. TextBlock tbAncientRus = new TextBlock()
  178. {
  179. Text = "Äðåâíèé ðóñ ïî ãîðîñêîïó:" + lineArray[9],
  180. };
  181. StackPanel spCountry = new StackPanel();
  182. spCountry.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
  183. spCountry.Children.Add(tbName);
  184. spCountry.Children.Add(tbForename);
  185. spCountry.Children.Add(tbPhone);
  186. spCountry.Children.Add(tbGender);
  187. spCountry.Children.Add(tbDate);
  188. spCountry.Children.Add(tbDateCount);
  189. spCountry.Children.Add(tbAncientRus);
  190. Border border = new Border();
  191. border.Background = color(lineArray[4]);
  192. border.BorderBrush = color(lineArray[4]);
  193. border.BorderThickness = new Avalonia.Thickness(2);
  194. border.CornerRadius = new Avalonia.CornerRadius(50);
  195. border.Margin = new Avalonia.Thickness(10);
  196. border.Padding = new Avalonia.Thickness(20);
  197. border.Child = spCountry;
  198. ShowUsers.Children.Add(border);
  199. }
  200. flag = false;
  201. }
  202. }
  203. }
  204. private void Back_Click(object sender, RoutedEventArgs e)
  205. {
  206. ShowUsers.IsVisible = false;
  207. WritePanel.IsVisible = true;
  208. ShowUsers1.IsVisible = false;
  209. }
  210. }
  211. }