浏览代码

Вывод из файла

lyudmila.archackowa 6 月之前
父节点
当前提交
2d5acfc3cc
共有 2 个文件被更改,包括 80 次插入10 次删除
  1. 10 6
      AvaloniaApplication2/MainWindow.axaml
  2. 70 4
      AvaloniaApplication2/MainWindow.axaml.cs

+ 10 - 6
AvaloniaApplication2/MainWindow.axaml

@@ -2,11 +2,11 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600"
         x:Class="AvaloniaApplication2.MainWindow"
         Title="AvaloniaApplication2" FontSize="36">
 	<Grid>
-		<StackPanel HorizontalAlignment="Center">
+		<StackPanel HorizontalAlignment="Center" Name="WritePanel">
 			<StackPanel Orientation="Horizontal" >
 				<StackPanel Margin="10">
 					<TextBlock>Введите название страны:</TextBlock>
@@ -38,7 +38,11 @@
 				<TextBlock FontSize ="36">Буддизм</TextBlock>
 			</ListBox>			
 			<Button Click="WriteFile" Margin="10">Записать в файл</Button>
-			<TextBlock Name="ShowMessage" Foreground="Red"></TextBlock>
-		</StackPanel>		
-	</Grid>
-</Window>
+			<Button Click="ShowCountriesClick">Показать содержимое файла</Button>
+		</StackPanel>
+			<StackPanel Name="ShowCountries" IsVisible="False">
+				<Button Click="Back_Click">Назад</Button>
+			</StackPanel>
+			
+	</Grid>	
+</Window>

+ 70 - 4
AvaloniaApplication2/MainWindow.axaml.cs

@@ -1,6 +1,8 @@
 using Avalonia.Controls;
 using Avalonia.Interactivity;
 using Avalonia.Markup.Xaml.MarkupExtensions;
+using Avalonia.Media;
+using System;
 using System.IO;
 
 namespace AvaloniaApplication2
@@ -61,16 +63,80 @@ namespace AvaloniaApplication2
             // ïðîáåãàåìñÿ ïî âñåìó ñïèñêó âûáðàííûõ ðåëèãèé (òàê êàê ó ñïèñêà íàñòðîåí ìíîæåñòâåííûé âûáîð ïðè óñëîâèè çàæàòèÿ Ctrl)
             foreach (TextBlock item in lbReligions.SelectedItems)
             {
-                religions += religions + item.Text + ", "; // äîáàâëÿåì ðåëèãèþ â ñòðîêó ÿåðåç çàïÿòóþ
+                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);
-                ShowMessage.Text = "Çàïèñü äîáàâëåíà";
+                 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;
+        }
     }
 }