123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using Avalonia.Controls;
- using Avalonia.Controls.Shapes;
- using Avalonia.Interactivity;
- using Avalonia.Media;
- using HarfBuzzSharp;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace AvaloniaApplication1
- {
- public struct InfoUser
- {
- public string surname;
- public string name;
- public string patronymic;
- public string gender;
- public string phone;
- public int dayBirth;
- public int monthBirth;
- public int yearBirth;
- public string weekDay;
- public string sign;
- public string Concat()
- {
- return surname + ";" + name + ";" + patronymic + ";" + gender + ";" + phone + ";" + dayBirth + ";" + monthBirth + ";" + yearBirth + ";" + weekDay + ";" + sign;
- }
- }
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void WriteFile(object sender, RoutedEventArgs e)
- {
- List<InfoUser> listUser = new List<InfoUser>();
- bool flag = true;
- try
- {
- Regex rSurname = new Regex("[À-ß][à-ÿ]{1,}");
- bool fSurname = rSurname.IsMatch(tbSurname.Text);
- if (fSurname == false)
- flag = false;
- Regex rName = new Regex("[À-ß][à-ÿ]{0,}");
- bool fName = rName.IsMatch(tbName.Text);
- if (fName == false)
- flag = false;
- Regex rPatr = new Regex("[À-ß][à-ÿ]{0,}");
- bool fPatr = rPatr.IsMatch(tbPatr.Text);
- if (fPatr == false)
- flag = false;
- Regex rPhone = new Regex(@"^8(\d{3})\d{3}(\d{2}){2}$");
- bool fPhone = rPhone.IsMatch(tbPhone.Text);
- if (fPhone == false)
- flag = false;
- }
- catch
- {
- flag = false;
- }
-
- if (flag == true)
- {
- string gender = "";
- if (rbPzh.IsChecked == true) gender = "Æåíñêèé";
- if (rbPm.IsChecked == true) gender = "Ìóæñêîé";
- int year = Convert.ToInt32(tbYear.Text);
- int month = Convert.ToInt32(cbMonth.SelectedIndex);
- int day = Convert.ToInt32(tbDay.Text);
- DateTime date = new DateTime(year, month, day);
- string dayWeek = date.DayOfWeek.ToString();
- string sign = "";
- if ((day >= 24 && day <= 30 && month == 12) || (day <= 30 && month == 1)) sign = "Ìîðîç";
- if ((day == 31 && month == 1) || (day >= 1 && day <= 28 && month == 2)) sign = "Âåëåñ";
- if ((day >= 1 && day <= 31 && month == 3)) sign = "Ìàêîøü";
- if ((day >= 1 && day <= 30 && month == 4)) sign = "Æèâà";
- if ((day >= 1 && day <= 14 && month == 5)) sign = "ßðèëà";
- if ((day >= 15 && day <= 31 && month == 5) || (day <= 2 && month == 6)) sign = "Ëåëÿ";
- if ((day >= 2 && day <= 12 && month == 6)) sign = "Êîñòðîìà";
- if (((day >= 13 && day <= 30 && month == 6) || (day <= 6 && month == 7)) && (day != 24 && month == 6)) sign = "Äîäîëà";
- if (day == 24 && month == 6) sign = "Èâàí Êóïàëà";
- if ((day >= 7 && day <= 31 && month == 7)) sign = "Ëàäà";
- if ((day >= 1 && day <= 28 && month == 8)) sign = "Ïåðóí";
- if ((day >= 29 && day <= 31 && month == 8) || (day <= 13 && month == 9)) sign = "Ñåâà";
- if ((day >= 14 && day <= 27 && month == 9)) sign = "Ðîæåíèöà";
- if ((day >= 28 && day <= 30 && month == 9) || (day <= 15 && month == 10)) sign = "Ñâàðîæè÷è";
- if ((day >= 16 && day <= 31 && month == 10) || (day <= 8 && month == 11)) sign = "Ìîðåíà";
- if ((day >= 9 && day <= 28 && month == 11)) sign = "Çèìà";
- if ((day >= 29 && day <= 30 && month == 11) || (day <= 23 && month == 12)) sign = "Êàðà÷óí";
- listUser.Add(new InfoUser
- {
- surname = tbSurname.Text,
- name = tbName.Text,
- patronymic = tbPatr.Text,
- gender = gender,
- phone = tbPhone.Text,
- dayBirth = day,
- monthBirth = month,
- yearBirth = year,
- weekDay = dayWeek,
- sign = sign
- });
- using (StreamWriter streamWriter = new StreamWriter("User.csv", true))
- {
- foreach(InfoUser u in listUser)
- {
- streamWriter.WriteLine(u.Concat());
- }
- }
- MessageWriteFile.IsVisible = true;
- MessageProblem.IsVisible = false;
- }
- else
- {
- MessageProblem.IsVisible = true;
- MessageWriteFile.IsVisible = false;
- }
- }
- public SolidColorBrush color(string gender)
- {
- switch (gender)
- {
- case "Ìóæñêîé":
- return new SolidColorBrush(Color.FromArgb(65, 176, 209, 249));
- case "Æåíñêèé":
- return new SolidColorBrush(Color.FromArgb(65, 253, 196, 251));
- default:
- return new SolidColorBrush(Color.FromRgb(0, 0, 0));
- }
- }
- private void ReadFile(object sender, RoutedEventArgs e)
- {
- MainPanel.IsVisible = false;
- ShowUsers.IsVisible = true;
- List<InfoUser> sortUser = new List<InfoUser>();
- using (StreamReader sr = new StreamReader("User.csv"))
- {
- string line = "";
- List<InfoUser> listUser = new List<InfoUser>();
- while (!sr.EndOfStream)
- {
- line = sr.ReadLine();
- string[] lineArray = line.Split(";");
- listUser.Add(new InfoUser
- {
- surname = lineArray[0],
- name = lineArray[1],
- patronymic = lineArray[2],
- gender = lineArray[3],
- phone = lineArray[4],
- dayBirth = Convert.ToInt32(lineArray[5]),
- monthBirth = Convert.ToInt32(lineArray[6]),
- yearBirth = Convert.ToInt32(lineArray[7]),
- weekDay = lineArray[8],
- sign = lineArray[9]
- });
- }
- sortUser = listUser.OrderBy(x => x.surname).ToList();
- }
- File.Create("User.csv").Close();
- using (StreamWriter streamWriter = new StreamWriter("User.csv", true))
- {
- foreach (InfoUser u in sortUser)
- {
- streamWriter.WriteLine(u.Concat());
- }
- }
- using (StreamReader sr = new StreamReader("User.csv"))
- {
- string line = "";
- while (!sr.EndOfStream)
- {
- line = sr.ReadLine();
- string[] lineArray = line.Split(";");
- TextBlock tbFIO = new TextBlock()
- {
- Text = "ÔÈÎ: " + lineArray[0] + " " + lineArray[1] + " " + lineArray[2],
- };
- TextBlock tbGender = new TextBlock()
- {
- Text = "Ïîë: " + lineArray[3],
- };
- TextBlock tbPhone = new TextBlock()
- {
- Text = "Òåëåôîí: " + lineArray[4],
- };
- TextBlock tbDataBirth = new TextBlock()
- {
- Text = "Äàòà ðîæäåíèÿ: " + lineArray[5] + "." + lineArray[6] + "." + lineArray[7],
- };
- TextBlock tbDayWeek = new TextBlock()
- {
- Text = "Äåíü ðîæäåíèÿ íà íåäåëå: " + lineArray[8],
- };
- TextBlock tbSing = new TextBlock()
- {
- Text = "Çíàê ïî äðåâíåñëàâÿíñêîìó ãîðîñêîïó: " + lineArray[9],
- };
- StackPanel spUser = new StackPanel();
- spUser.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
- spUser.Children.Add(tbFIO);
- spUser.Children.Add(tbGender);
- spUser.Children.Add(tbPhone);
- spUser.Children.Add(tbDataBirth);
- spUser.Children.Add(tbDayWeek);
- spUser.Children.Add(tbSing);
- Border border = new Border();
- border.Background = color(lineArray[3]);
- border.BorderBrush = Brushes.Indigo;
- 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 = spUser;
- ShowUsers.Children.Add(border);
- }
- }
- }
- private void BackClick(object sender, RoutedEventArgs e)
- {
- ShowUsers.IsVisible = false;
- MainPanel.IsVisible = true;
- }
- }
- }
|