123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using Avalonia.Controls;
- using Avalonia.Interactivity;
- using Avalonia.Media;
- using System;
- using System.Diagnostics.Metrics;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace AvaloniaApplication1
- {
- public partial class MainWindow : Window
- {
- public struct Users
- {
- public string name;
- public string surname;
- public string forename;
- public string phone;
- public string gener;
- public int dayBirth;
- public string monthBirth;
- public int yearBirth;
- }
-
- public MainWindow()
- {
- InitializeComponent();
- }
- private void WriteFile(object sender, RoutedEventArgs e)
- {
- Users user = new Users();
- user.name = tbName.Text;
- user.surname = tbSurename.Text;
- user.forename = tbForename.Text;
- user.phone = tbPhone.Text;
- if (rbF.IsChecked == true)
- {
- user.gener = "Æåíñêèé";
- }
- if (rbM.IsChecked == true)
- {
- user.gener = "Ìóæñêîé";
- }
- user.dayBirth = Int32.Parse(tbDay.Text);
- var monthNum = cbMonth.SelectedIndex;
- switch (cbMonth.SelectedIndex)
- {
- case 1: user.monthBirth = "ßíâàðü";
- break;
- case 2:
- user.monthBirth = "Ôåâðàëü";
- break;
- case 3:
- user.monthBirth = "Ìàðò";
- break;
- case 4:
- user.monthBirth = "Àïðåëü";
- break;
- case 5:
- user.monthBirth = "Ìàé";
- break;
- case 6:
- user.monthBirth = "Èþíü";
- break;
- case 7:
- user.monthBirth = "Èþëü";
- break;
- case 8:
- user.monthBirth = "Àâãóñò";
- break;
- case 9:
- user.monthBirth = "Ñåíòÿáðü";
- break;
- case 10:
- user.monthBirth = "Îêòÿáðü";
- break;
- case 11:
- user.monthBirth = "Íîÿáðü";
- break;
- case 12:
- user.monthBirth = "Äåêàáðü";
- break;
- }
- user.yearBirth = Int32.Parse(tbYear.Text);
- var d = new DateTime(user.yearBirth, cbMonth.SelectedIndex, user.dayBirth);
- var whatAncientRusAreYou = "";
- if (d.DayOfYear <= 30 || d.DayOfYear >= 359) { whatAncientRusAreYou = "Ìîðîç"; }
- if (d.DayOfYear <= 60 && d.DayOfYear >= 31) { whatAncientRusAreYou = "Âåëåñ"; }
- if (d.DayOfYear <= 91 && d.DayOfYear >= 61) { whatAncientRusAreYou = "Ìàêîøü"; }
- if (d.DayOfYear <= 121 && d.DayOfYear >= 92) { whatAncientRusAreYou = "Æèâà"; }
- if (d.DayOfYear <= 135 && d.DayOfYear >= 122) { whatAncientRusAreYou = "ßðèëî"; }
- if (d.DayOfYear <= 154 && d.DayOfYear >= 136) { whatAncientRusAreYou = "Ëåëÿ"; }
- if (d.DayOfYear <= 164 && d.DayOfYear >= 155) { whatAncientRusAreYou = "Êîñòðîìà"; }
- if (d.DayOfYear <= 188 && d.DayOfYear >= 165) { whatAncientRusAreYou = "Äîäîëà"; }
- if (d.DayOfYear <= 213 && d.DayOfYear >= 189) { whatAncientRusAreYou = "Ëàäà"; }
- if (d.DayOfYear <= 241 && d.DayOfYear >= 214) { whatAncientRusAreYou = "Ïåðóí"; }
- if (d.DayOfYear <= 257 && d.DayOfYear >= 242) { whatAncientRusAreYou = "Ñåâà"; }
- if (d.DayOfYear <= 271 && d.DayOfYear >= 258) { whatAncientRusAreYou = "Ðîæàíèöà"; }
- if (d.DayOfYear <= 289 && d.DayOfYear >= 272) { whatAncientRusAreYou = "Ñâàðîæè÷è"; }
- if (d.DayOfYear <= 313 && d.DayOfYear >= 290) { whatAncientRusAreYou = "Ìîðåíà"; }
- if (d.DayOfYear <= 333 && d.DayOfYear >= 314) { whatAncientRusAreYou = "Çèìà"; }
- if (d.DayOfYear <= 358 && d.DayOfYear >= 334) { whatAncientRusAreYou = "Êàðà÷óí"; }
- Regex NameCheck = new Regex("^[À-ß]");
- Regex SurenameCheck = new Regex("^[A-ß]+");
- Regex PhoneNumber = new Regex("^8\\(\\d{3}\\)\\d{7}");
- if (NameCheck.IsMatch(user.name) && SurenameCheck.IsMatch(user.surname) && PhoneNumber.IsMatch(user.phone) && user.gener != null)
- {
- using (StreamWriter sw = new StreamWriter("users.csv", true, System.Text.Encoding.UTF8))
- {
- sw.WriteLine(user.name + ";" + user.surname + ";" + user.forename + ";" + user.phone + ";" + user.gener + ";" + user.dayBirth + ";" + user.monthBirth + ";" + user.yearBirth + ";" + d.DayOfYear + ";" + whatAncientRusAreYou);
- ShowMessage.Text = "Çàïèñü äîáàâëåíà";
- }
- } else { ShowMessage.Text = "Çàïèñü íå äîáàâëåíà, îøèáêà â âîäèìûõ äàííûõ"; }
-
- }
-
- public SolidColorBrush color(string continent)
- {
- switch (continent)
- {
- case "Ìóæñêîé":
- return new SolidColorBrush(Color.FromArgb(35,0,0,255));
- case "Æåíñêèé":
- return new SolidColorBrush(Color.FromArgb(35, 255, 128, 255));
- default:
- return new SolidColorBrush(Color.FromRgb(0, 0, 0));
- }
- }
-
- private void ShowUsersClick(object sender, RoutedEventArgs e)
- {
- ShowUsers.IsVisible = true;
- WritePanel.IsVisible = false;
- ShowUsers1.IsVisible = true;
- using (StreamReader sr = new StreamReader("users.csv"))
- {
- var flag = true;
- if (flag)
- {
- string line = "";
- while (!sr.EndOfStream)
- {
- line = sr.ReadLine();
- string[] lineArray = line.Split(';');
- TextBlock tbName = new TextBlock()
- {
- Text = "Èìÿ Ôàìèëèÿ" + lineArray[0] + lineArray[1],
- };
- TextBlock tbForename = new TextBlock()
- {
- Text = "Îò÷åñòâî:" + lineArray[2]
- };
- TextBlock tbPhone = new TextBlock()
- {
- Text = "Òåëåôîí:" + lineArray[3]
- };
- TextBlock tbGender = new TextBlock()
- {
- Text = "Ïîë:" + lineArray[4]
- };
- var monthNum = "";
- if (lineArray[5] == "ßíâàðü") { monthNum = "01"; }
- else if (lineArray[5] == "Ôåâðàëü") { monthNum = "02"; }
- else if (lineArray[5] == "Ìàðò") { monthNum = "03"; }
- else if (lineArray[5] == "Àïðåëü") { monthNum = "04"; }
- else if (lineArray[5] == "Ìàé") { monthNum = "05"; }
- else if (lineArray[5] == "Èþíü") { monthNum = "06"; }
- else if (lineArray[5] == "Èþëü") { monthNum = "07"; }
- else if (lineArray[5] == "Àâãóñò") { monthNum = "08"; }
- else if (lineArray[5] == "Ñåíòÿáðü") { monthNum = "09"; }
- else if (lineArray[5] == "Îêòÿáðü") { monthNum = "10"; }
- else if (lineArray[5] == "Íîÿáðü") { monthNum = "11"; }
- else if (lineArray[5] == "Äåêàáðü") { monthNum = "12"; }
- TextBlock tbDate = new TextBlock()
- {
- Text = "Äàòà ðîæäåíèÿ:" + lineArray[5] + monthNum + lineArray[7],
- };
- TextBlock tbDateCount = new TextBlock()
- {
- Text = "Äàòà ðîæäåíèÿ ïî ñ÷¸òó:" + lineArray[8],
- };
- TextBlock tbAncientRus = new TextBlock()
- {
- Text = "Äðåâíèé ðóñ ïî ãîðîñêîïó:" + lineArray[9],
- };
- StackPanel spCountry = new StackPanel();
- spCountry.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
- spCountry.Children.Add(tbName);
- spCountry.Children.Add(tbForename);
- spCountry.Children.Add(tbPhone);
- spCountry.Children.Add(tbGender);
- spCountry.Children.Add(tbDate);
- spCountry.Children.Add(tbDateCount);
- spCountry.Children.Add(tbAncientRus);
- Border border = new Border();
- border.Background = color(lineArray[4]);
- border.BorderBrush = color(lineArray[4]);
- 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 = spCountry;
- ShowUsers.Children.Add(border);
- }
- flag = false;
- }
- }
- }
- private void Back_Click(object sender, RoutedEventArgs e)
- {
- ShowUsers.IsVisible = false;
- WritePanel.IsVisible = true;
- ShowUsers1.IsVisible = false;
- }
- }
- }
|