123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using Avalonia.Controls;
- using Avalonia.Interactivity;
- using Avalonia.Media;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace praktika3_graph_interface
- {
- public struct users
- {
- public string surname;
- public string name;
- public string patronymic;
- public string phone;
- public int birthday;
- public int birthmonth;
- public int birthyear;
- public string gender;
- public int den_nedeli;
- public string goroskop;
- public users(string surname, string name, string patronymic, string phone, int birthday,
- int birthmonth, int birthyear, string gender, int den_nedeli, string goroskop)
- {
- this.surname = surname;
- this.name = name;
- this.patronymic = patronymic;
- this.phone = phone;
- this.birthday = birthday;
- this.birthmonth = birthmonth;
- this.birthyear = birthyear;
- this.gender = gender;
- this.den_nedeli = den_nedeli;
- this.goroskop = goroskop;
- }
- public void writeToFile(users obj)
- {
- using (StreamWriter sw = new StreamWriter("users.csv", true, System.Text.Encoding.UTF8))
- {
- sw.WriteLine(obj.surname + ";" + obj.name + ";" + obj.patronymic + ";" + obj.phone +
- ";" + obj.birthday + ";" + obj.birthmonth + ";" + obj.birthyear + ";" + obj.gender + ";" + obj.den_nedeli + ";" + obj.goroskop);
- }
- }
- }
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void getUser(object sender, RoutedEventArgs e)
- {
- users user = new();
- Regex forFIO = new Regex("^[À-ß]{1}[à-ÿ]{2,}$");
- Regex forPhone = new Regex("^8{1}[0-9]{10}$");
- if (forFIO.IsMatch(tbSurname.Text))
- {
- user.surname = changeColorIncorrectFormat(tbSurname, true);
- if (forFIO.IsMatch(tbName.Text))
- {
- user.name = changeColorIncorrectFormat(tbName, true);
- if (forFIO.IsMatch(tbPatronymic.Text))
- {
- user.patronymic = changeColorIncorrectFormat(tbPatronymic, true);
- if (forPhone.IsMatch(tbPhone.Text))
- {
- user.phone = changeColorIncorrectFormat(tbPhone, true);
- user.birthday = int.Parse(tbBirthday.Text);
- user.birthmonth = cbMonth.SelectedIndex;
- user.birthyear = int.Parse(tbBirthyear.Text);
- if (rbF.IsChecked == true) user.gender = "Æåíñêèé";
- if (rbM.IsChecked == true) user.gender = "Ìóæñêîé";
- DateOnly date = new DateOnly(user.birthyear, user.birthmonth, user.birthday);
- user.den_nedeli = (int)date.DayOfWeek;
- user.goroskop = drevneslavyanskiiGoroskop(date);
- user.writeToFile(user);
- showSuccess();
- }
- else user.phone = changeColorIncorrectFormat(tbPhone, false);
- }
- else user.patronymic = changeColorIncorrectFormat(tbPatronymic, false);
- }
- else user.name = changeColorIncorrectFormat(tbName, false);
- }
- else user.surname = changeColorIncorrectFormat(tbSurname, false);
- Console.WriteLine();
- }
- private string changeColorIncorrectFormat(TextBox tb, bool correct)
- {
- if (correct)
- {
- tb.Foreground = Brushes.Black;
- tb.BorderBrush = new SolidColorBrush(Color.FromArgb(100, 0, 0, 0));
- }
- else
- {
- tb.BorderBrush = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0));
- tb.Foreground = Brushes.Red;
- }
- return tb.Text;
- }
- private string drevneslavyanskiiGoroskop(DateOnly birth)
- {
- string god = "";
- int year = birth.Year;
- if ((new DateOnly(year, 1, 31) <= birth) && (new DateOnly(year, 2, 28) >= birth)) god = "Âåëåñ";
- else if ((new DateOnly(year, 3, 1) <= birth) && (new DateOnly(year, 4, 1) > birth)) god = "Ìàêîøü";
- else if ((new DateOnly(year, 4, 1) <= birth) && (new DateOnly(year, 5, 1) > birth)) god = "Æèâà";
- else if ((new DateOnly(year, 5, 1) <= birth) && (new DateOnly(year, 5, 15) > birth)) god = "ßðèëî";
- else if ((new DateOnly(year, 5, 15) <= birth) && (new DateOnly(year, 6, 3) > birth)) god = "Ëåëÿ";
- else if ((new DateOnly(year, 6, 2) <= birth) && (new DateOnly(year, 6, 13) > birth)) god = "Êîñòðîìà";
- else if ((new DateOnly(year, 6, 24) == birth)) god = "Èâàí Êóïàëà";
- else if ((new DateOnly(year, 6, 13) <= birth) && (new DateOnly(year, 7, 7) > birth)) god = "Äîäîëà";
- else if ((new DateOnly(year, 7, 7) <= birth) && (new DateOnly(year, 7, 31) >= birth)) god = "Ëàäà";
- else if ((new DateOnly(year, 8, 1) <= birth) && (new DateOnly(year, 8, 29) > birth)) god = "Ïåðóí";
- else if ((new DateOnly(year, 8, 29) <= birth) && (new DateOnly(year, 9, 14) > birth)) god = "Ñåâà";
- else if ((new DateOnly(year, 9, 14) <= birth) && (new DateOnly(year, 9, 28) > birth)) god = "Ðîæàíèöà";
- else if ((new DateOnly(year, 9, 28) <= birth) && (new DateOnly(year, 10, 16) > birth)) god = "Ñâàðîæè÷è";
- else if ((new DateOnly(year, 10, 16) <= birth) && (new DateOnly(year, 11, 9) > birth)) god = "Ìîðåíà";
- else if ((new DateOnly(year, 11, 9) <= birth) && (new DateOnly(year, 11, 29) > birth)) god = "Çèìà";
- else if ((new DateOnly(year, 11, 29) <= birth) && (new DateOnly(year, 12, 24) > birth)) god = "Êàðà÷óí";
- else if ((new DateOnly(year, 12, 24) <= birth) && (new DateOnly(year, 1, 31) > birth)) god = "Ðîæàíèöà";
- return god;
- }
- private void showSuccess()
- {
- bSuccess.IsVisible = true;
- }
- private void hideSuccess(object sender, RoutedEventArgs e)
- {
- bSuccess.IsVisible = false;
- }
- private void showUsers(object sender, RoutedEventArgs e)
- {
- form.IsVisible = false;
- userlist.IsVisible = true;
- buttonReturn.IsVisible = true;
- List<users> listOfUsers = new();
- using (StreamReader sr = new StreamReader("users.csv"))
- {
- string text = "";
- while (!sr.EndOfStream)
- {
- text = sr.ReadLine();
- if (text == "") continue;
- string[] buf = text.Split(';');
- users user = new();
- user.surname = buf[0];
- user.name = buf[1];
- user.patronymic = buf[2];
- user.phone = buf[3];
- user.birthday = int.Parse(buf[4]);
- user.birthmonth = int.Parse(buf[5]);
- user.birthyear = int.Parse(buf[6]);
- user.gender = buf[7];
- user.den_nedeli = int.Parse(buf[8]);
- user.goroskop = buf[9];
- listOfUsers.Add(user);
-
- }
- listOfUsers.Sort((p1, p2) => p1.surname.CompareTo(p2.surname));
- for (int i = 0; i < listOfUsers.Count; i++)
- {
- TextBlock tbFIO = new TextBlock()
- {
- Text = listOfUsers[i].surname + " " + listOfUsers[i].name + " " + listOfUsers[i].patronymic,
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
- };
- TextBlock tbBirth = new TextBlock()
- {
- Text = listOfUsers[i].birthday + "." + listOfUsers[i].birthmonth + "." + listOfUsers[i].birthyear,
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
- };
- TextBlock tbPhoneS = new TextBlock()
- {
- Text = listOfUsers[i].phone,
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
- };
- TextBlock tbGenderS = new TextBlock()
- {
- Text = listOfUsers[i].gender,
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
- };
- TextBlock tbDen = new TextBlock()
- {
- Text = listOfUsers[i].den_nedeli.ToString(),
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
- };
- TextBlock tbGoroskopS = new TextBlock()
- {
- Text = listOfUsers[i].goroskop,
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
- };
- StackPanel spUser = new StackPanel();
- spUser.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
- spUser.Width = 500;
- if (tbGenderS.Text == "Æåíñêèé") spUser.Background = new SolidColorBrush(Color.FromArgb(100, 222, 211, 166));
- else spUser.Background = new SolidColorBrush(Color.FromArgb(100, 117, 146, 4));
- spUser.Children.Add(tbFIO);
- spUser.Children.Add(tbBirth);
- spUser.Children.Add(tbPhoneS);
- spUser.Children.Add(tbGenderS);
- spUser.Children.Add(tbDen);
- spUser.Children.Add(tbGoroskopS);
- Border border = new Border();
- border.BorderBrush = new SolidColorBrush(Color.FromArgb(100, 0, 0, 0));
- border.Width = spUser.Width;
- border.Height = spUser.Height;
- border.BorderThickness = new Avalonia.Thickness(5);
- border.Margin = new Avalonia.Thickness(10);
- border.Child = spUser;
- userlist.Children.Add(border);
- }
- }
- }
-
- private void bReturn(object sender, RoutedEventArgs e)
- {
- form.IsVisible = true;
- userlist.IsVisible = false;
- }
- }
- }
|