123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- 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;
- }
- }
-
- }
|