123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- using Avalonia.Controls;
- using Avalonia.Controls.Shapes;
- using Avalonia.Interactivity;
- using Avalonia.Markup.Xaml.MarkupExtensions;
- using Avalonia.Media;
- using System;
- using System.Collections;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Xml.Linq;
- using Tmds.DBus.Protocol;
- using static System.Net.Mime.MediaTypeNames;
- namespace AvaloniaApplication2
- {
- // ñòðóêòóðà ïîëüçîâàòåëåé
- public struct Users
- {
- public string lastname;
- public string firstname;
- public string patronymic;
- public string phoneNumber;
- public string birthday;
- public string gender;
- public string birthmonth;
- public string birthyear;
- public string weekday;
- public string horoscope;
- public void GetUser(string[] splittedLine)
- {
- lastname = splittedLine[0];
- firstname = splittedLine[1];
- patronymic = splittedLine[2];
- phoneNumber = splittedLine[3];
- gender = splittedLine[4];
- birthday = splittedLine[5];
- birthmonth = splittedLine[6];
- birthyear = splittedLine[7];
- weekday = splittedLine[8];
- horoscope = splittedLine[9];
- }
- }
- public partial class MainWindow : Window
- {
- private string[] months = {"ßíâàðü", "Ôåâðàëü", "Ìàðò", "Àïðåëü", "Ìàé", "Èþíü", "Èþëü", "Àâãóñò", "Ñåíòÿáðü", "Îêòÿáðü", "Íîÿáðü", "Äåêàáðü"};
- private string[] weekdays = { "Âîñêðåñåíüå", "Ïîíåäåëüíèê", "Âòîðíèê", "Ñðåäà", "×åòâåðã", "Ïÿòíèöà", "Ñóááîòà" };
- private string basepath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
- public MainWindow()
- {
- InitializeComponent();
- }
- private void WriteFile(object sender, RoutedEventArgs e)
- {
-
-
- bool flag = true; // Ïîêàçûâàåò, åñòü ëè íåñîîòâåòñòâèÿ ïàòòåðíàì ñðåäè ââåäåííûõ äàííûõ
- string errmessage = ""; // Ïåðåìåííàÿ, êîòîðàÿ õðàíèò íåñîîòâåòñòâèÿ ðåãóëÿðíûì âûðàæåíèÿì
- tErrMsg.Text = " ";
- Regex[] patterns = { new Regex(@"^[À-ß][à-ÿ]+$"), // Ïàòòåðí äëÿ ïðîâåðêè ôàìèëèè
- new Regex(@"^(2|1)\d{3}$"), // Ïàòòåðí äëÿ ïðîâåðêè ãîäà ðîæäåíèÿ
- new Regex(@"^\d{1,2}$"), // Ïàòòåðí äëÿ ïðîâåðêè äíÿ ðîæäåíèÿ
- new Regex(@"^(7|8)\d{10}$"), // Ïàòòåðí äëÿ ïðîâåðêè òåëåôîíà áåç ôîðìàòèðîâàíèÿ (íàïð., 79000000000)
- new Regex(@"(7|8)\(\d{3}\)\d{3}-\d{2}-\d{2}$"), // ñ ôîðìàòèðîâàíèåì (íàïð., 8(900)000-00-00))
- new Regex(@"^[À-ß][à-ÿ]*$") // Ïàòòåðí äëÿ ïðîâåðêè èìåíè
- };
- Users user = new Users();
- foreach(TextBox item in new TextBox[]{tbLastName, tbFirstName, tbPatronymic, tbPhone, tbBirthDay, tbBirthYear }) // Èçìåíÿåò çíà÷åíèÿ íåââåäåííûõ ïîëåé ñ Null íà " "
- {
- if (item.Text is not string)
- item.Text = " ";
- }
- // çàïîëíåíèå ïîëåé ñòðóêòóðû
- user.birthmonth = months[cbBirthMonth.SelectedIndex];
- if (GenderM.IsChecked == true)
- user.gender = "Ìóæñêîé";
- else
- user.gender = "Æåíñêèé";
- if (patterns[0].IsMatch(tbLastName.Text))
- user.lastname = tbLastName.Text;
- else
- {
- errmessage += "Ôàìèëèÿ, ";
- flag = false;
- }
- if (patterns[5].IsMatch(tbFirstName.Text))
- user.firstname = tbFirstName.Text;
- else
- {
- errmessage += "Èìÿ, ";
- flag = false;
- }
- if (patterns[0].IsMatch(tbPatronymic.Text))
- user.patronymic = tbPatronymic.Text;
- else
- {
- errmessage += "Îò÷åñòâî, ";
- flag = false;
- }
- if (patterns[3].IsMatch(tbPhone.Text))
- user.phoneNumber = $"8({tbPhone.Text.Substring(1,3)}){tbPhone.Text.Substring(4, 3)}-{tbPhone.Text.Substring(7, 2)}-{tbPhone.Text.Substring(9, 2)}";
- else if (patterns[4].IsMatch(tbPhone.Text))
- user.phoneNumber = $"8{tbPhone.Text.Substring(1, tbPhone.Text.Length-1)}";
- else
- {
- errmessage += "Òåëåôîí, ";
- flag = false;
- }
- if (patterns[1].IsMatch(tbBirthYear.Text))
- user.birthyear = tbBirthYear.Text;
- else
- {
- errmessage += "Ãîä, ";
- flag = false;
- }
- if (patterns[2].IsMatch(tbBirthDay.Text))
- user.birthday = tbBirthDay.Text;
- else
- {
- errmessage += "Äåíü, ";
- flag = false;
- }
- if (!flag)
- {
- tErrMsg.Text = $"{errmessage.Substring(0,errmessage.Length-2)} íå ñîîòâåòñòâóþò ôîðìàòó";
- }
- else
- {
- DateOnly birthdate = new DateOnly(Convert.ToInt32(user.birthyear), cbBirthMonth.SelectedIndex+1, Convert.ToInt32(user.birthday));
- user.weekday = weekdays[Convert.ToInt32(birthdate.DayOfWeek)];
- DateOnly[,] hrsRanges = { {new DateOnly(Convert.ToInt32(user.birthyear), 12, 24), new DateOnly(Convert.ToInt32(user.birthyear), 1, 30) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 1, 31), new DateOnly(Convert.ToInt32(user.birthyear), 2, 28) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 3, 1), new DateOnly(Convert.ToInt32(user.birthyear), 3, 31) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 4, 1), new DateOnly(Convert.ToInt32(user.birthyear), 4, 30) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 5, 1), new DateOnly(Convert.ToInt32(user.birthyear), 5, 14) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 5, 15), new DateOnly(Convert.ToInt32(user.birthyear), 6, 1) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 6, 2), new DateOnly(Convert.ToInt32(user.birthyear), 6, 12) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 6, 13), new DateOnly(Convert.ToInt32(user.birthyear), 7, 6) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 6, 24), new DateOnly(Convert.ToInt32(user.birthyear), 6, 24) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 7, 7), new DateOnly(Convert.ToInt32(user.birthyear), 7, 31) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 8, 1), new DateOnly(Convert.ToInt32(user.birthyear), 8, 28) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 8, 29), new DateOnly(Convert.ToInt32(user.birthyear), 9, 13) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 9, 14), new DateOnly(Convert.ToInt32(user.birthyear), 9, 27) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 9, 28), new DateOnly(Convert.ToInt32(user.birthyear), 10, 15) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 10, 16), new DateOnly(Convert.ToInt32(user.birthyear), 11, 8) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 11, 9), new DateOnly(Convert.ToInt32(user.birthyear), 11, 28) },
- {new DateOnly(Convert.ToInt32(user.birthyear), 11, 29), new DateOnly(Convert.ToInt32(user.birthyear), 12, 23) },};
- if (birthdate >= hrsRanges[0, 0] & birthdate <= hrsRanges[0, 1])
- user.horoscope = "Ìîðîç";
- else if (birthdate >= hrsRanges[1, 0] & birthdate <= hrsRanges[1, 1])
- user.horoscope = "Âåëåñ";
- else if (birthdate >= hrsRanges[2, 0] & birthdate <= hrsRanges[2, 1])
- user.horoscope = "Ìàêîøü";
- else if (birthdate >= hrsRanges[3, 0] & birthdate <= hrsRanges[3, 1])
- user.horoscope = "Æèâà";
- else if (birthdate >= hrsRanges[4, 0] & birthdate <= hrsRanges[4, 1])
- user.horoscope = "ßðèëî";
- else if (birthdate >= hrsRanges[5, 0] & birthdate <= hrsRanges[5, 1])
- user.horoscope = "Ëåëÿ";
- else if (birthdate >= hrsRanges[6, 0] & birthdate <= hrsRanges[6, 1])
- user.horoscope = "Êîñòðîìà";
- else if (birthdate >= hrsRanges[8, 0] & birthdate <= hrsRanges[8, 1])
- user.horoscope = "Èâàí Êóïàëà";
- else if (birthdate >= hrsRanges[7, 0] & birthdate <= hrsRanges[7, 1])
- user.horoscope = "Äîäîëà";
- else if (birthdate >= hrsRanges[9, 0] & birthdate <= hrsRanges[9, 1])
- user.horoscope = "Ëàäà";
- else if (birthdate >= hrsRanges[10, 0] & birthdate <= hrsRanges[10, 1])
- user.horoscope = "Ïåðóí";
- else if (birthdate >= hrsRanges[11, 0] & birthdate <= hrsRanges[11, 1])
- user.horoscope = "Ñåâà";
- else if (birthdate >= hrsRanges[12, 0] & birthdate <= hrsRanges[12, 1])
- user.horoscope = "Ðîæàíèöà";
- else if (birthdate >= hrsRanges[13, 0] & birthdate <= hrsRanges[13, 1])
- user.horoscope = "Ñâàðîæè÷è";
- else if (birthdate >= hrsRanges[14, 0] & birthdate <= hrsRanges[14, 1])
- user.horoscope = "Ìîðåíà";
- else if (birthdate >= hrsRanges[15, 0] & birthdate <= hrsRanges[15, 1])
- user.horoscope = "Çèìà";
- else if (birthdate >= hrsRanges[16, 0] & birthdate <= hrsRanges[16, 1])
- user.horoscope = "Êàðà÷óí";
- else
- user.horoscope = "Íèêòî";
- try
- {
- using (StreamWriter writer = new StreamWriter(basepath + @"\users.csv", true, System.Text.Encoding.UTF8))
- {
- writer.WriteLine($"{user.lastname};{user.firstname};{user.patronymic};{user.phoneNumber};{user.gender};{user.birthday};{user.birthmonth};{user.birthyear};{user.weekday};{user.horoscope}");
- tErrMsg.Text = "Çàïèñü äîáàâëåíà";
- }
- }
- catch (Exception)
- {
- tErrMsg.Text = "Âîçíèêëà îøèáêà ïðè äîáàâëåíèè çàïèñè";
- }
-
- }
-
- }
-
- private void ShowUsers(object sender, RoutedEventArgs e)
- {
- UsersPanel.IsVisible = true;
- WritePanel.IsVisible = false;
- ArrayList allUsers = new ArrayList();
- using (StreamReader reader = new StreamReader(basepath + @"\users.csv"))
- {
- reader.ReadLine();
- string line;
- string[] splittedLine;
- Users user = new Users();
- while ((line = reader.ReadLine()) != null)
- {
- splittedLine = line.Split(";");
- user.GetUser(splittedLine);
- allUsers.Add(user);
- }
- }
- Users[] users = (Users[])allUsers.ToArray(typeof(Users)); // Ïðåîáðàçîâàíèå ArrayList â ìàññèâ ñòðóêòóð
- users = users.OrderBy(a => a.lastname).ThenBy(b => b.firstname).ToArray(); // Ñîðòèðîâêà ïîëüçîâàòåëåé ïî èìåíè è ôàìèëèè
- foreach(Users user in users)
- {
- TextBlock FIO = new TextBlock()
- {
- Text = $"ÔÈÎ: {user.lastname} {user.firstname} {user.patronymic}",
- };
- TextBlock Phone = new TextBlock()
- {
- Text = $"Íîìåð òåëåôîíà: {user.phoneNumber}",
- };
- string textbirthday;
- string textbirthmonth;
- if (Convert.ToInt32(user.birthday) < 10)
- textbirthday = $"0{user.birthday}";
- else
- textbirthday = user.birthday;
- if (Array.IndexOf(months, user.birthmonth) + 1 < 10)
- textbirthmonth = $"0{Array.IndexOf(months, user.birthmonth) + 1}";
- else
- textbirthmonth = $"{Array.IndexOf(months, user.birthmonth) + 1}";
- TextBlock Birth = new TextBlock()
- {
- Text = $"Äåíü ðîæäåíèÿ: {textbirthday}.{textbirthmonth}.{user.birthyear}",
- };
- TextBlock WeekDay = new TextBlock()
- {
- Text = $"Äåíü íåäåëè ðîæäåíèÿ: {user.weekday}",
- };
- TextBlock Male = new TextBlock()
- {
- Text = "Ïîë: Ìóæñêîé",
- Foreground = new SolidColorBrush(Color.FromRgb(145, 210, 255)),
- };
- TextBlock Female = new TextBlock()
- {
- Text = "Ïîë: Æåíñêèé",
- Foreground = new SolidColorBrush(Color.FromRgb(229, 128, 255)),
- };
- TextBlock HoroScope = new TextBlock()
- {
- Text = $"Ãîðîñêîï: {user.horoscope}",
- };
- StackPanel spUser = new StackPanel();
- spUser.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
- spUser.Children.Add(FIO);
- spUser.Children.Add(Phone);
- spUser.Children.Add(Birth);
- spUser.Children.Add(WeekDay);
- if (user.gender == "Ìóæñêîé")
- spUser.Children.Add(Male);
- else
- spUser.Children.Add(Female);
- spUser.Children.Add(HoroScope);
- Border border = new Border();
- border.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
- border.BorderBrush = Brushes.BlueViolet;
- 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;
- UsersPanel.Children.Add(border);
- }
-
- }
- private void ClickBack(object sender, RoutedEventArgs e)
- {
- UsersPanel.IsVisible = false;
- WritePanel.IsVisible = true;
- for (int i = UsersPanel.Children.Count - 1; i > 0; i--) // Óáèðàåò áëîêè ñ ïîëüçîâàòåëÿìè
- {
- UsersPanel.Children.Remove(UsersPanel.Children[i]);
- }
- }
- }
- }
|