123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using Avalonia.Controls;
- using Avalonia.Interactivity;
- using Avalonia.Markup.Xaml.MarkupExtensions;
- using Avalonia.Media;
- using System;
- using System.IO;
- namespace AvaloniaApplication2
- {
- // ñòðóêòóðà
- public struct Countries
- {
- public string name; // íàçâàíèå ñòðàíû
- public string capital; // ñòîëèöà
- public string form; // ôîðìà ïðàâëåíèÿ
- public string continent; // ìàòåðèê
- public string religions; // ðåëèãèè
- public bool isNATO; // ÿâëÿåòñÿ ëè ÷ëåíîì ÍÀÒÎ
- }
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- // cbContinent.SelectedIndex = 0;
- }
- // îáðàáîò÷èê ñîáûòèÿ Click äëÿ çàïèñè â ôàéë
- private void WriteFile(object sender, RoutedEventArgs e)
- {
- Countries country = new Countries(); // ñîçäàíèå îáúåêòà ñòðóêòóðû
- // çàïîëíåíèå ïîëåé ñòðóêòóðû
- country.name = tbName.Text; // çàïîëíåíèå íàçâàíèÿ ñòðàíû èç òåêñòîâîãî ïîëÿ
- country.capital = tbCapital.Text; // çàïîëíåíèå ñòîëèöû èç òåêñòîâîãî ïîëÿ
- // â çàâèñèìîñòè îò òîãî, êàêàÿ ðàäèîêíîïêà àêòèâíà, ïðîèñõîäèò çàïèñü ôîðìû ïðàâëåíèÿ
- if (rbM.IsChecked == true) country.form = "Ìîíàðõèÿ";
- if (rbK.IsChecked == true) country.form = "Êîíñòèòóöèÿ";
- if (rbD.IsChecked == true) country.form = "Äåìîêðàòèÿ";
- // åñëè ôëàæîê âûáðàí, òî çàïèñûâàåì ïðèíàäëåæíîñòü ñòðàíû ê ÍÀÒÎ
- if (cbNATO.IsChecked == true) country.isNATO = true;
- else country.isNATO = false;
- // çàïèñûâàåì êîíòèíåíò â çàâèñèìîñòè îò âûáðàííîãî çíà÷åíèÿ â ñïèñêå, îðèåíòèðóÿñü íà èíäåêñ âûáðàííîãî çíà÷åíèÿ (çíà÷åíèÿ íà÷èíàþòñÿ ñ èíäåêñà 0)
- switch (cbContinent.SelectedIndex)
- {
- case 1:
- country.continent = "Åâðàçèÿ";
- break;
- case 2:
- country.continent = "Àìåðèêà";
- break;
- case 3:
- country.continent = "Àôðèêà";
- break;
- }
-
- string religions = ""; // ñòðîêà äëÿ ôîðìèðîâàíèÿ ñâåäåíèé î ðåãèëèÿõ â ñòðàíå
- // ïðîáåãàåìñÿ ïî âñåìó ñïèñêó âûáðàííûõ ðåëèãèé (òàê êàê ó ñïèñêà íàñòðîåí ìíîæåñòâåííûé âûáîð ïðè óñëîâèè çàæàòèÿ Ctrl)
- foreach (TextBlock item in lbReligions.SelectedItems)
- {
- religions += item.Text + ", "; // äîáàâëÿåì ðåëèãèþ â ñòðîêó ÿåðåç çàïÿòóþ
- }
- country.religions = religions;
- // çàïèñü à ôàéë
- using (StreamWriter sw = new StreamWriter("users.csv",true,System.Text.Encoding.UTF8))
- {
- sw.WriteLine(country.name + ";" + country.capital + ";" + country.continent + ";" + country.form + ";" + country.religions + ";" + country.isNATO);
- }
- }
- public SolidColorBrush color(string continent)
- {
- switch (continent)
- {
- case "Åâðàçèÿ":
- return new SolidColorBrush(Color.FromArgb(50,255, 0, 0));
- case "Àìåðèêà":
- return new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
- case "Àôðèêà":
- return new SolidColorBrush(Color.FromArgb(50, 0, 0, 255));
- default:
- return new SolidColorBrush(Color.FromRgb(0, 0, 0));
- }
- }
- private void ShowCountriesClick(object sender, RoutedEventArgs e)
- {
- ShowCountries.IsVisible = true;
- WritePanel.IsVisible = false;
- using (StreamReader sr = new StreamReader("users.csv"))
- {
- string line ="";
- while (!sr.EndOfStream)
- {
- line = sr.ReadLine();
- string[] lineArray = line.Split(';');
- TextBlock tbName = new TextBlock()
- {
- Text = "Íàçâàíèå ñòðàíû: " + lineArray[0],
- };
- TextBlock tbCapital = new TextBlock()
- {
- Text = "Ñòîëèöà: "+lineArray[1]
- };
- TextBlock tbIsNATO = new TextBlock();
- if (Convert.ToBoolean(lineArray[5])) tbIsNATO.Text = "Âõîäèò ñ ÍÀÒÎ";
- else tbIsNATO.Text = "Íå âõîäèò â ñîñòàâ ÍÀÒÎ";
- StackPanel spCountry = new StackPanel();
- spCountry.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
- spCountry.Children.Add(tbName);
- spCountry.Children.Add(tbCapital);
- spCountry.Children.Add(tbIsNATO);
-
- Border border = new Border();
- border.Background = color(lineArray[2]);
- border.BorderBrush = Brushes.Indigo;
- 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;
- ShowCountries.Children.Add(border);
- }
- }
- }
- private void Back_Click(object sender, RoutedEventArgs e)
- {
- ShowCountries.IsVisible = false;
- WritePanel.IsVisible = true;
- }
- }
- }
|