using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.Metrics; using System.IO; using System.Linq; using System.Text.RegularExpressions; namespace AvaloniaApplication1 { public partial class MainWindow : Window { struct MyStruct { public string name; public string surname; public string patronimic; public string phone; public string month; public int day; public int year; public string pol; public string horoscope; public string DayOfWeek; } public MainWindow() { InitializeComponent(); } public void WriteFile(object setter, RoutedEventArgs e) { int m = 0; MyStruct myStruct = new MyStruct(); Regex r = new Regex("^[А-ЯЁ][а-яё]{1,}$"); if (tbName.Text != null) { bool a = r.IsMatch(tbName.Text); if (a == true) { myStruct.name = tbName.Text; } else { Error.IsVisible = true; return; } } Regex g = new Regex("^[А-ЯЁ][а-яё]{2,}$"); if (tbLastname.Text != null) { bool a = g.IsMatch(tbLastname.Text); if (a == true) { myStruct.surname = tbLastname.Text; } else { Error.IsVisible = true; return; } } Regex i = new Regex("^8\\d{10}$"); if (tbtelephone.Text != null) { bool a = i.IsMatch(tbtelephone.Text); if (a == true) { myStruct.phone = tbtelephone.Text; } else { Error.IsVisible = true; return; } } if(tbOtchestvo.Text != null) { myStruct.patronimic = tbOtchestvo.Text; } else { Error.IsVisible = true; return; } switch (cbMonth.SelectedIndex) { case 0: myStruct.month = "Декабрь"; m = 12; break; case 1: myStruct.month = "Январь"; m = 1; break; case 2: myStruct.month = "Февраль"; m = 2; break; case 3: myStruct.month = "Март"; m = 3; break; case 4: myStruct.month = "Апрель"; m = 4; break; case 5: myStruct.month = "Май"; m = 5; break; case 6: myStruct.month = "Июнь"; m = 6; break; case 7: myStruct.month = "Июль"; m = 7; break; case 8: myStruct.month = "Август"; m = 8; break; case 9: myStruct.month = "Сентябрь"; m = 9; break; case 10: myStruct.month = "Октябрь"; m = 10; break; case 11: myStruct.month = "Ноябрь"; m = 11; break; } if (tbday.Text != null && Convert.ToInt32(tbday.Text) < 32) { myStruct.day = Convert.ToInt32(tbday.Text); } else { Error.IsVisible = true; return; } if(tbyear.Text != null && Convert.ToInt32(tbyear.Text) > 0) { myStruct.year = Convert.ToInt32(tbyear.Text); } else { Error.IsVisible = true; return; } if(Female.IsChecked == true) { myStruct.pol = "Женский"; } if (Male.IsChecked == true) { myStruct.pol = "Мужской"; } if(Female.IsChecked == false && Male.IsChecked == false) { Error.IsVisible = true; return; } if(myStruct.month == "Декабрь" && myStruct.day >= 24 || myStruct.month == "Январь" && myStruct.day <= 30) { myStruct.horoscope = "Мороз"; } if (myStruct.month == "Март") { myStruct.horoscope = "Макошь"; } if (myStruct.month == "Апрель") { myStruct.horoscope = "Жива"; } if (myStruct.month == "Май" && myStruct.day <= 14) { myStruct.horoscope = "Ярила"; } if (myStruct.month == "Май" && myStruct.day >= 15 || myStruct.month == "Июнь" && myStruct.day == 1) { myStruct.horoscope = "Леля"; } if (myStruct.month == "Июнь" && myStruct.day <= 12 && myStruct.day >= 2) { myStruct.horoscope = "Кострома"; } if (myStruct.month == "Июнь" && myStruct.day >= 13 || myStruct.month == "Июль" && myStruct.day <= 6) { myStruct.horoscope = "Додола"; } if (myStruct.month == "Июль" && myStruct.day >= 7) { myStruct.horoscope = "Лада"; } if (myStruct.month == "Август" && myStruct.day >= 1 && myStruct.day <= 28) { myStruct.horoscope = "Перун"; } if (myStruct.month == "Август" && myStruct.day >= 29 || myStruct.month == "Сентябрь" && myStruct.day <= 13) { myStruct.horoscope = "Сева"; } if (myStruct.month == "Сентябрь" && myStruct.day >= 14 && myStruct.day <= 27) { myStruct.horoscope = "Рожаница"; } if (myStruct.month == "Сентябрь" && myStruct.day >= 28 || myStruct.month == "Октябрь" && myStruct.day <= 15) { myStruct.horoscope = "Сварожичи"; } if (myStruct.month == "Октябрь" && myStruct.day >= 16 || myStruct.month == "Ноябрь" && myStruct.day <= 8) { myStruct.horoscope = "Морена"; } if (myStruct.month == "Ноябрь" && myStruct.day >= 9 && myStruct.day <= 28) { myStruct.horoscope = "Зима"; } if (myStruct.month == "Ноября" && myStruct.day >= 29 || myStruct.month == "Декабрь" && myStruct.day <= 23) { myStruct.horoscope = "Карачун"; } DateOnly date = new DateOnly(myStruct.year, m, myStruct.day); myStruct.DayOfWeek = date.DayOfWeek.ToString(); tbGoroskop.Text = myStruct.horoscope; tbWeek.Text = myStruct.DayOfWeek; using (StreamWriter sw = new StreamWriter("path.csv", true, System.Text.Encoding.UTF8)) { Error.IsVisible = false; Succes.IsVisible = true; sw.WriteLine(myStruct.name + ";" + myStruct.surname + ";" + myStruct.patronimic + ";" + myStruct.phone + ";" + myStruct.year + ";" + m + ";" + myStruct.day + ";" + myStruct.horoscope + ";" + myStruct.DayOfWeek + ";" + myStruct.pol); } } private void ReadFile(object sender, RoutedEventArgs e) { Show.IsVisible = true; WritePanel.IsVisible = false; using (StreamReader sr = new StreamReader("path.csv")) { string line = ""; while (!sr.EndOfStream) { line = sr.ReadLine(); string[] lineArray = line.Split(';'); TextBlock FIO = new TextBlock() { Text = "ФИО: " + lineArray[1] + " " + lineArray[0] + " " + lineArray[2] }; TextBlock tbDate = new TextBlock() { Text = "Дата: " + lineArray[6] + "." + lineArray[5] + "." + lineArray[4] + " " + lineArray[8] }; TextBlock tbphone = new TextBlock() { Text = "Номер телефона: " + lineArray[3] }; TextBlock tbhoroscope = new TextBlock() { Text = "Знак славянского гороскопа: " + lineArray[7] }; TextBlock tbpol = new TextBlock() { Text = "Пол: " + lineArray[9] }; StackPanel sp = new StackPanel(); sp.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center; sp.Children.Add(FIO); sp.Children.Add(tbDate); sp.Children.Add(tbphone); sp.Children.Add(tbhoroscope); sp.Children.Add(tbpol); Border border = new Border(); if (lineArray[9] == "Женский") { border.BorderBrush = Brushes.Pink; } if (lineArray[9] == "Мужской") { border.BorderBrush = Brushes.Blue; } border.BorderThickness = new Avalonia.Thickness(2); border.CornerRadius = new Avalonia.CornerRadius(50); border.Margin = new Avalonia.Thickness(10); border.Padding = new Avalonia.Thickness(20); border.Child = sp; Show.Children.Add(border); } } } private void Back(object sender, RoutedEventArgs e) { Show.IsVisible = false; WritePanel.IsVisible = true; } } }