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