Valera 7 hónapja
szülő
commit
6fdb96c626
3 módosított fájl, 200 hozzáadás és 126 törlés
  1. BIN
      img/tea.png
  2. BIN
      img/tea2.png
  3. 200 126
      readme.md

BIN
img/tea.png


BIN
img/tea2.png


+ 200 - 126
readme.md

@@ -1,4 +1,4 @@
-**["Элементы управления"](https://github.com/kolei/OAP/blob/master/articles/exam.md)**
+**["Получение данных из внешних источников.CSV."](https://github.com/kolei/OAP/blob/master/articles/lab_wpf_data_csv.md)**
 ***
 **C#**
 ***
@@ -17,9 +17,11 @@ namespace WpfApp1.model
     {
         public string name { get; set; }
         public int year { get; set; }
-        public int price { get; set; }
-        public List<Carsprice> Carsprice { get; set; }
-        public List<Namecar> Namecar { get; set; }
+        public double price { get; set; }
+        public string color { get; set; }
+        public bool defects { get; set; }
+        public DateOnly dateOfLastSTO { get; set; }
+        public string photo { get; set; }
     }
 }
 ```
@@ -91,143 +93,80 @@ namespace WpfApp1.model
 
 ```
 ***
-**MainWindow.xaml**
+**Class4**
 ***
 ```
-<Window x:Class="WpfApp1.MainWindow"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        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"
-        xmlns:local="clr-namespace:WpfApp1"
-        mc:Ignorable="d"
-        Title="Иванов Валера И-21" Height="450" Width="908">
-    <Grid ShowGridLines="True">
-        <Grid.RowDefinitions>
-            <RowDefinition Height="auto"/>
-            <RowDefinition />
-            <RowDefinition Height="auto"/>
-        </Grid.RowDefinitions>
-        <Grid.ColumnDefinitions>
-            <ColumnDefinition Width="200"/>
-            <ColumnDefinition/>
-        </Grid.ColumnDefinitions>
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using CsvHelper;
 
-        <!-- лого -->
-        <Image 
-        Source="./img/da.jpg" 
-        Grid.RowSpan="2" HorizontalAlignment="Right"/>
-        <DataGrid
-    Grid.Row="1"
-    Grid.Column="1"
-    CanUserAddRows="False"
-    AutoGenerateColumns="False"
-    ItemsSource="{Binding CarList}">
-            <DataGrid.Columns>
-                <DataGridTextColumn
-            Header="Название"
-            Binding="{Binding name}"/>
-                <DataGridTextColumn
-            Header="Цена"
-            Binding="{Binding price}"/>
-                <DataGridTextColumn
-            Header="Год"
-            Binding="{Binding year}"/>
-            </DataGrid.Columns>
-        </DataGrid>
-        <StackPanel 
-        Orientation="Vertical"
-        Grid.RowSpan="3"
-        VerticalAlignment="Bottom">
-            <Button 
-            x:Name="ExitButton"
-            Content="Выход" 
-            Click="ExitButton_Click"
-            Height="50"/>
-        </StackPanel>
-        
 
-        <WrapPanel
-        Orientation="Horizontal"
-        Grid.Column="1"
-        MinHeight="50">
-            <Label 
-    Content="Поиск" 
-    VerticalAlignment="Center"/>
-            <TextBox
-    Width="200"
-    VerticalAlignment="Center"
-    x:Name="SearchFilterTextBox" 
-    KeyUp="SearchFilter_KeyUp"/>
-            
-            <Label 
-    Content="Название:"
-    VerticalAlignment="Center"/>
+namespace WpfApp1.model
+{
+    class Class4
+    {
+        public class CSVDataProvider : LocalDataProvider, IDataProvider
+        {
+            private IEnumerable<cars> carList;
 
-            <ComboBox
-    Name="carnameFilterComboBox"
-    SelectionChanged="carnameFilterComboBox_SelectionChanged"
-    VerticalAlignment="Center"
-    MinWidth="100"
-    SelectedIndex="0"
-    ItemsSource="{Binding CarinfoList}">
-                <ComboBox.ItemTemplate>
-                    <DataTemplate>
-                        <Label
-                Content="{Binding title}"/>
-                    </DataTemplate>
-                </ComboBox.ItemTemplate>
-            </ComboBox>
-            <Label 
-Content="Цена:"
-VerticalAlignment="Center"/>
-            
-            <ComboBox
-Name="carpriceFilterComboBox"
-SelectionChanged="carpriceFilterComboBox_SelectionChanged"
-VerticalAlignment="Center"
-MinWidth="100"
-SelectedIndex="0"
-ItemsSource="{Binding CarpriceList}">
+            public CSVDataProvider()
+            {
+                using (var reader = new StreamReader("./data.csv"))
+                {
+                    using (var csv = new CsvReader(
+                        reader,
+                        CultureInfo.InvariantCulture))
+                    {
+                        carList = csv.GetRecords<cars>().ToList();
+                    }
+                }
+            }
+            public IEnumerable<cars>getCars()
+            {
+                return carList;
+            }
+        }
+    }
+}
 
-                <ComboBox.ItemTemplate>
-                    <DataTemplate>
-                        <Label 
-            Content="{Binding title}"/>
-                    </DataTemplate>
-                </ComboBox.ItemTemplate>
-            </ComboBox>
-            <Label 
-    Content="Возраст:" 
-    VerticalAlignment="Center"/>
-            <RadioButton
-    GroupName="Age"
-    Tag="1"
-    Content="по возрастанию"
-    IsChecked="True"
-    Checked="RadioButton_Checked"
-    VerticalAlignment="Center"/>
-            <RadioButton
-    GroupName="Age"
-    Tag="2"
-    Content="по убыванию"
-    Checked="RadioButton_Checked"
-    VerticalAlignment="Center"/>
-        </WrapPanel>
-    </Grid>
-</Window>
+```
+***
+**data.csv**
+***
+```
+name,year,price,color,defects,dateOfLastSTO,photo,
+Toyota Trueno AE8,1995,15000,white,false,4/30/2024,, 
+Toyota Supra A80,1996,30000,blue,false,5/1/2024,, 
+Nissal Skyline R34,1996,25000,red,true,5/2/2024,, 
+Nissan Silvia S15,1999,20000,green,false,5/3/2024,, 
+Toyota Camry 3.5,2020,20000,black,true,5/4/2024,, 
+Audi RS 6,2016,30000,purple,false,5/5/2024,, 
+Трактор LOVOL TE354 HT,2024,66666,red,false,5/6/2024,, 
+BMW M5 F90,2019,30000,white,true,5/7/2024,, 
+BMW E36,2006,35000,green,true,5/8/2024,, 
+Daewoo Matiz,2010,20000,blue,false,5/9/2024,, 
 
 ```
 ***
 **MainWindow.xaml.cs**
 ***
 ```
+using CsvHelper;
 using System;
 using System.ComponentModel;
+using System.Globalization;
+using System.IO;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using WpfApp1.model;
+using static WpfApp1.model.Class4;
 
 namespace WpfApp1
 {
@@ -294,7 +233,7 @@ namespace WpfApp1
         {
             InitializeComponent();
             DataContext = this;
-            Globals.dataProvider = new LocalDataProvider();
+            Globals.dataProvider = new CSVDataProvider();
             CarList = Globals.dataProvider.getCars();
             CarinfoList = Globals.dataProvider.getName().ToList();
             CarinfoList.Insert(0, new Namecar { title = "Все автомобили" });
@@ -467,9 +406,144 @@ namespace WpfApp1
 }
 
 
+```
+***
+**MainWindow.xaml**
+***
+```
+<Window x:Class="WpfApp1.MainWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        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"
+        xmlns:local="clr-namespace:WpfApp1"
+        mc:Ignorable="d"
+        Title="Иванов Валера И-21" Height="450" Width="908">
+    <Grid ShowGridLines="True">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="auto"/>
+            <RowDefinition />
+            <RowDefinition Height="auto"/>
+        </Grid.RowDefinitions>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="200"/>
+            <ColumnDefinition/>
+        </Grid.ColumnDefinitions>
+
+        <!-- лого -->
+        <Image 
+        Source="./img/da.jpg" 
+        Grid.RowSpan="2" HorizontalAlignment="Right"/>
+        <DataGrid
+    Grid.Row="1"
+    Grid.Column="1"
+    CanUserAddRows="False"
+    AutoGenerateColumns="False"
+    ItemsSource="{Binding CarList}">
+            <DataGrid.Columns>
+                <DataGridTextColumn
+            Header="Название"
+            Binding="{Binding name}"/>
+                <DataGridTextColumn
+            Header="Цена"
+            Binding="{Binding price}"/>
+                <DataGridTextColumn
+            Header="Год"
+            Binding="{Binding year}"/>
+                <DataGridTextColumn
+                    Header="Дефекты"
+                    Binding="{Binding defects}"/>
+                <DataGridTextColumn
+                    Header="Дата последнего СТО"
+                    Binding="{Binding dateOfLastSTO}"/>
+            </DataGrid.Columns>
+        </DataGrid>
+        <StackPanel 
+        Orientation="Vertical"
+        Grid.RowSpan="3"
+        VerticalAlignment="Bottom">
+            <Button 
+            x:Name="ExitButton"
+            Content="Выход" 
+            Click="ExitButton_Click"
+            Height="50"/>
+        </StackPanel>
+        
+
+        <WrapPanel
+        Orientation="Horizontal"
+        Grid.Column="1"
+        MinHeight="50">
+            <Label 
+    Content="Поиск" 
+    VerticalAlignment="Center"/>
+            <TextBox
+    Width="200"
+    VerticalAlignment="Center"
+    x:Name="SearchFilterTextBox" 
+    KeyUp="SearchFilter_KeyUp"/>
+            
+            <Label 
+    Content="Название:"
+    VerticalAlignment="Center"/>
+
+            <ComboBox
+    Name="carnameFilterComboBox"
+    SelectionChanged="carnameFilterComboBox_SelectionChanged"
+    VerticalAlignment="Center"
+    MinWidth="100"
+    SelectedIndex="0"
+    ItemsSource="{Binding CarinfoList}">
+                <ComboBox.ItemTemplate>
+                    <DataTemplate>
+                        <Label
+                Content="{Binding title}"/>
+                    </DataTemplate>
+                </ComboBox.ItemTemplate>
+            </ComboBox>
+            <Label 
+Content="Цена:"
+VerticalAlignment="Center"/>
+            
+            <ComboBox
+Name="carpriceFilterComboBox"
+SelectionChanged="carpriceFilterComboBox_SelectionChanged"
+VerticalAlignment="Center"
+MinWidth="100"
+SelectedIndex="0"
+ItemsSource="{Binding CarpriceList}">
+
+                <ComboBox.ItemTemplate>
+                    <DataTemplate>
+                        <Label 
+            Content="{Binding title}"/>
+                    </DataTemplate>
+                </ComboBox.ItemTemplate>
+            </ComboBox>
+            <Label 
+    Content="Возраст:" 
+    VerticalAlignment="Center"/>
+            <RadioButton
+    GroupName="Age"
+    Tag="1"
+    Content="по возрастанию"
+    IsChecked="True"
+    Checked="RadioButton_Checked"
+    VerticalAlignment="Center"/>
+            <RadioButton
+    GroupName="Age"
+    Tag="2"
+    Content="по убыванию"
+    Checked="RadioButton_Checked"
+    VerticalAlignment="Center"/>
+        </WrapPanel>
+    </Grid>
+</Window>
+
 ```
 ***
 **Вот что получилось**
 
-![](./img/net3.png)
-![](./img/net4.png)
+![](./img/tea2.png)
+***
+![](./img/tea.png)