MainWindow.axaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Media;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Diagnostics.Metrics;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. namespace AvaloniaApplication1
  12. {
  13. public partial class MainWindow : Window
  14. {
  15. struct MyStruct
  16. {
  17. public string name;
  18. public string surname;
  19. public string patronimic;
  20. public string phone;
  21. public string month;
  22. public int day;
  23. public int year;
  24. public string pol;
  25. public string horoscope;
  26. public string DayOfWeek;
  27. }
  28. public MainWindow()
  29. {
  30. InitializeComponent();
  31. }
  32. public void WriteFile(object setter, RoutedEventArgs e)
  33. {
  34. int m = 0;
  35. MyStruct myStruct = new MyStruct();
  36. Regex r = new Regex("^[À-ߨ][à-ÿ¸]{1,}$");
  37. if (tbName.Text != null)
  38. {
  39. bool a = r.IsMatch(tbName.Text);
  40. if (a == true)
  41. {
  42. myStruct.name = tbName.Text;
  43. }
  44. else
  45. {
  46. Error.IsVisible = true;
  47. return;
  48. }
  49. }
  50. Regex g = new Regex("^[À-ߨ][à-ÿ¸]{2,}$");
  51. if (tbLastname.Text != null)
  52. {
  53. bool a = g.IsMatch(tbLastname.Text);
  54. if (a == true)
  55. {
  56. myStruct.surname = tbLastname.Text;
  57. }
  58. else
  59. {
  60. Error.IsVisible = true;
  61. return;
  62. }
  63. }
  64. Regex i = new Regex("^8\\d{10}$");
  65. if (tbtelephone.Text != null)
  66. {
  67. bool a = i.IsMatch(tbtelephone.Text);
  68. if (a == true)
  69. {
  70. myStruct.phone = tbtelephone.Text;
  71. }
  72. else
  73. {
  74. Error.IsVisible = true;
  75. return;
  76. }
  77. }
  78. if(tbOtchestvo.Text != null)
  79. {
  80. myStruct.patronimic = tbOtchestvo.Text;
  81. }
  82. else
  83. {
  84. Error.IsVisible = true;
  85. return;
  86. }
  87. switch (cbMonth.SelectedIndex)
  88. {
  89. case 0:
  90. myStruct.month = "Äåêàáðü";
  91. m = 12;
  92. break;
  93. case 1:
  94. myStruct.month = "ßíâàðü";
  95. m = 1;
  96. break;
  97. case 2:
  98. myStruct.month = "Ôåâðàëü";
  99. m = 2;
  100. break;
  101. case 3:
  102. myStruct.month = "Ìàðò";
  103. m = 3;
  104. break;
  105. case 4:
  106. myStruct.month = "Àïðåëü";
  107. m = 4;
  108. break;
  109. case 5:
  110. myStruct.month = "Ìàé";
  111. m = 5;
  112. break;
  113. case 6:
  114. myStruct.month = "Èþíü";
  115. m = 6;
  116. break;
  117. case 7:
  118. myStruct.month = "Èþëü";
  119. m = 7;
  120. break;
  121. case 8:
  122. myStruct.month = "Àâãóñò";
  123. m = 8;
  124. break;
  125. case 9:
  126. myStruct.month = "Ñåíòÿáðü";
  127. m = 9;
  128. break;
  129. case 10:
  130. myStruct.month = "Îêòÿáðü";
  131. m = 10;
  132. break;
  133. case 11:
  134. myStruct.month = "Íîÿáðü";
  135. m = 11;
  136. break;
  137. }
  138. if (tbday.Text != null && Convert.ToInt32(tbday.Text) < 32)
  139. {
  140. myStruct.day = Convert.ToInt32(tbday.Text);
  141. }
  142. else
  143. {
  144. Error.IsVisible = true;
  145. return;
  146. }
  147. if(tbyear.Text != null && Convert.ToInt32(tbyear.Text) > 0)
  148. {
  149. myStruct.year = Convert.ToInt32(tbyear.Text);
  150. }
  151. else
  152. {
  153. Error.IsVisible = true;
  154. return;
  155. }
  156. if(Female.IsChecked == true)
  157. {
  158. myStruct.pol = "Æåíñêèé";
  159. }
  160. if (Male.IsChecked == true)
  161. {
  162. myStruct.pol = "Ìóæñêîé";
  163. }
  164. if(Female.IsChecked == false && Male.IsChecked == false)
  165. {
  166. Error.IsVisible = true;
  167. return;
  168. }
  169. if(myStruct.month == "Äåêàáðü" && myStruct.day >= 24 || myStruct.month == "ßíâàðü" && myStruct.day <= 30)
  170. {
  171. myStruct.horoscope = "Ìîðîç";
  172. }
  173. if (myStruct.month == "Ìàðò")
  174. {
  175. myStruct.horoscope = "Ìàêîøü";
  176. }
  177. if (myStruct.month == "Àïðåëü")
  178. {
  179. myStruct.horoscope = "Æèâà";
  180. }
  181. if (myStruct.month == "Ìàé" && myStruct.day <= 14)
  182. {
  183. myStruct.horoscope = "ßðèëà";
  184. }
  185. if (myStruct.month == "Ìàé" && myStruct.day >= 15 || myStruct.month == "Èþíü" && myStruct.day == 1)
  186. {
  187. myStruct.horoscope = "Ëåëÿ";
  188. }
  189. if (myStruct.month == "Èþíü" && myStruct.day <= 12 && myStruct.day >= 2)
  190. {
  191. myStruct.horoscope = "Êîñòðîìà";
  192. }
  193. if (myStruct.month == "Èþíü" && myStruct.day >= 13 || myStruct.month == "Èþëü" && myStruct.day <= 6)
  194. {
  195. myStruct.horoscope = "Äîäîëà";
  196. }
  197. if (myStruct.month == "Èþëü" && myStruct.day >= 7)
  198. {
  199. myStruct.horoscope = "Ëàäà";
  200. }
  201. if (myStruct.month == "Àâãóñò" && myStruct.day >= 1 && myStruct.day <= 28)
  202. {
  203. myStruct.horoscope = "Ïåðóí";
  204. }
  205. if (myStruct.month == "Àâãóñò" && myStruct.day >= 29 || myStruct.month == "Ñåíòÿáðü" && myStruct.day <= 13)
  206. {
  207. myStruct.horoscope = "Ñåâà";
  208. }
  209. if (myStruct.month == "Ñåíòÿáðü" && myStruct.day >= 14 && myStruct.day <= 27)
  210. {
  211. myStruct.horoscope = "Ðîæàíèöà";
  212. }
  213. if (myStruct.month == "Ñåíòÿáðü" && myStruct.day >= 28 || myStruct.month == "Îêòÿáðü" && myStruct.day <= 15)
  214. {
  215. myStruct.horoscope = "Ñâàðîæè÷è";
  216. }
  217. if (myStruct.month == "Îêòÿáðü" && myStruct.day >= 16 || myStruct.month == "Íîÿáðü" && myStruct.day <= 8)
  218. {
  219. myStruct.horoscope = "Ìîðåíà";
  220. }
  221. if (myStruct.month == "Íîÿáðü" && myStruct.day >= 9 && myStruct.day <= 28)
  222. {
  223. myStruct.horoscope = "Çèìà";
  224. }
  225. if (myStruct.month == "Íîÿáðÿ" && myStruct.day >= 29 || myStruct.month == "Äåêàáðü" && myStruct.day <= 23)
  226. {
  227. myStruct.horoscope = "Êàðà÷óí";
  228. }
  229. DateOnly date = new DateOnly(myStruct.year, m, myStruct.day);
  230. myStruct.DayOfWeek = date.DayOfWeek.ToString();
  231. tbGoroskop.Text = myStruct.horoscope;
  232. tbWeek.Text = myStruct.DayOfWeek;
  233. using (StreamWriter sw = new StreamWriter("path.csv", true, System.Text.Encoding.UTF8))
  234. {
  235. Error.IsVisible = false;
  236. Succes.IsVisible = true;
  237. sw.WriteLine(myStruct.name + ";" + myStruct.surname + ";" + myStruct.patronimic + ";" + myStruct.phone + ";" + myStruct.year + ";" + m + ";" + myStruct.day + ";" + myStruct.horoscope + ";" + myStruct.DayOfWeek + ";" + myStruct.pol);
  238. }
  239. }
  240. private void ReadFile(object sender, RoutedEventArgs e)
  241. {
  242. Show.IsVisible = true;
  243. WritePanel.IsVisible = false;
  244. using (StreamReader sr = new StreamReader("path.csv"))
  245. {
  246. string line = "";
  247. while (!sr.EndOfStream)
  248. {
  249. line = sr.ReadLine();
  250. string[] lineArray = line.Split(';');
  251. TextBlock FIO = new TextBlock()
  252. {
  253. Text = "ÔÈÎ: " + lineArray[1] + " " + lineArray[0] + " " + lineArray[2]
  254. };
  255. TextBlock tbDate = new TextBlock()
  256. {
  257. Text = "Äàòà: " + lineArray[6] + "." + lineArray[5] + "." + lineArray[4] + " " + lineArray[8]
  258. };
  259. TextBlock tbphone = new TextBlock()
  260. {
  261. Text = "Íîìåð òåëåôîíà: " + lineArray[3]
  262. };
  263. TextBlock tbhoroscope = new TextBlock()
  264. {
  265. Text = "Çíàê ñëàâÿíñêîãî ãîðîñêîïà: " + lineArray[7]
  266. };
  267. TextBlock tbpol = new TextBlock()
  268. {
  269. Text = "Ïîë: " + lineArray[9]
  270. };
  271. StackPanel sp = new StackPanel();
  272. sp.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
  273. sp.Children.Add(FIO);
  274. sp.Children.Add(tbDate);
  275. sp.Children.Add(tbphone);
  276. sp.Children.Add(tbhoroscope);
  277. sp.Children.Add(tbpol);
  278. Border border = new Border();
  279. if (lineArray[9] == "Æåíñêèé")
  280. {
  281. border.BorderBrush = Brushes.Pink;
  282. }
  283. if (lineArray[9] == "Ìóæñêîé")
  284. {
  285. border.BorderBrush = Brushes.Blue;
  286. }
  287. border.BorderThickness = new Avalonia.Thickness(2);
  288. border.CornerRadius = new Avalonia.CornerRadius(50);
  289. border.Margin = new Avalonia.Thickness(10);
  290. border.Padding = new Avalonia.Thickness(20);
  291. border.Child = sp;
  292. Show.Children.Add(border);
  293. }
  294. }
  295. }
  296. private void Back(object sender, RoutedEventArgs e)
  297. {
  298. Show.IsVisible = false;
  299. WritePanel.IsVisible = true;
  300. }
  301. }
  302. }