|
@@ -1,30 +1,416 @@
|
|
-**[Привязка](https://github.com/kolei/OAP/blob/master/articles/t8_binding.md#привязка-binding-интерфейс-inotifypropertychanged-форматирование-значений-привязки-и-конвертеры-значений)**
|
|
|
|
|
|
+**["Элементы управления"](https://github.com/kolei/OAP/blob/master/articles/exam.md)**
|
|
***
|
|
***
|
|
-**Python**
|
|
|
|
|
|
+**C#**
|
|
***
|
|
***
|
|
-```angular2html
|
|
|
|
-import tkinter as tk #импортирую библиотеку и даю другое название
|
|
|
|
|
|
+**Class1**
|
|
|
|
+***
|
|
|
|
+```
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Security.Cryptography.X509Certificates;
|
|
|
|
+using System.Text;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+
|
|
|
|
+namespace WpfApp1.model
|
|
|
|
+{
|
|
|
|
+ public class cars
|
|
|
|
+ {
|
|
|
|
+ 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; }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+```
|
|
|
|
+***
|
|
|
|
+**Class2**
|
|
|
|
+***
|
|
|
|
+```
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Text;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+
|
|
|
|
+namespace WpfApp1.model
|
|
|
|
+{
|
|
|
|
+ class Globals
|
|
|
|
+ {
|
|
|
|
+ public static IDataProvider dataProvider;
|
|
|
|
+ IEnumerable<Namecar> getNamecar()
|
|
|
|
+ {
|
|
|
|
+ return new Namecar[] {
|
|
|
|
+ new Namecar { title = "Toyota Trueno AE8"},
|
|
|
|
+ new Namecar { title = "Toyota Supra A80"},
|
|
|
|
+ new Namecar { title = "Nissal Skyline R34" },
|
|
|
|
+ new Namecar { title = "Nissan Silvia S15"},
|
|
|
|
+ new Namecar { title = "Toyota Camry 3.5"},
|
|
|
|
+ new Namecar { title = "Audi RS 6" },
|
|
|
|
+ new Namecar { title = "Трактор LOVOL TE354 HT"},
|
|
|
|
+ new Namecar { title = "BMW M5 F90"},
|
|
|
|
+ new Namecar { title = "BMW E36" },
|
|
|
|
+ new Namecar { title = "Daewoo Matiz" }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ IEnumerable<Carsprice> getCarsprice()
|
|
|
|
+ {
|
|
|
|
+ return new Carsprice[] {
|
|
|
|
+ new Carsprice{title="Малая цена", priceFrom=0, priceTo=15001},
|
|
|
|
+ new Carsprice{title="Средняя цена", priceFrom = 20000, priceTo=35000},
|
|
|
|
+ new Carsprice{title="Высокая цена", priceFrom = 35001, priceTo=70000},
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+```
|
|
|
|
+***
|
|
|
|
+**Class3**
|
|
|
|
+***
|
|
|
|
+```
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Text;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+
|
|
|
|
+namespace WpfApp1.model
|
|
|
|
+{
|
|
|
|
+ public class Carsprice
|
|
|
|
+ {
|
|
|
|
+ public string title { get; set; }
|
|
|
|
+ public int priceFrom { get; set; }
|
|
|
|
+ public int priceTo { get; set; }
|
|
|
|
+ }
|
|
|
|
+ public class Namecar
|
|
|
|
+ {
|
|
|
|
+ public string title { get; set; }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
-class MainWindow(tk.Tk): #создаю главное окно приложения
|
|
|
|
- def __init__(self):
|
|
|
|
- super().__init__()
|
|
|
|
|
|
+```
|
|
|
|
+***
|
|
|
|
+**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>
|
|
|
|
|
|
- self.title("Иванов Валера И-21")
|
|
|
|
- self.geometry("300x250")
|
|
|
|
|
|
+ <!-- лого -->
|
|
|
|
+ <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>
|
|
|
|
|
|
- self.text_box = tk.Entry(self) #создаю текстовое поле
|
|
|
|
- self.text_box.pack() #размещаю текстовое поле
|
|
|
|
|
|
+ <WrapPanel
|
|
|
|
+ Orientation="Horizontal"
|
|
|
|
+ Grid.Column="1"
|
|
|
|
+ MinHeight="50">
|
|
|
|
+ <Label
|
|
|
|
+ Content="Название:"
|
|
|
|
+ VerticalAlignment="Center"/>
|
|
|
|
|
|
- self.text_block = tk.Label(self, textvariable=tk.StringVar(value=self.text_box.get()), height=30)
|
|
|
|
- self.text_block.pack()
|
|
|
|
|
|
+ <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}">
|
|
|
|
|
|
- # Привязываю значение текстового поля к переменной textvariable
|
|
|
|
- self.text_box.configure(textvariable=self.text_block.cget("textvariable"))
|
|
|
|
|
|
+ <ComboBox.ItemTemplate>
|
|
|
|
+ <DataTemplate>
|
|
|
|
+ <Label
|
|
|
|
+ Content="{Binding title}"/>
|
|
|
|
+ </DataTemplate>
|
|
|
|
+ </ComboBox.ItemTemplate>
|
|
|
|
+ </ComboBox>
|
|
|
|
+ </WrapPanel>
|
|
|
|
+ </Grid>
|
|
|
|
+</Window>
|
|
|
|
+```
|
|
|
|
+***
|
|
|
|
+**MainWindow.xaml.cs**
|
|
|
|
+***
|
|
|
|
+```
|
|
|
|
+using System;
|
|
|
|
+using System.ComponentModel;
|
|
|
|
+using System.Windows;
|
|
|
|
+using WpfApp1.model;
|
|
|
|
|
|
-if __name__ == "__main__":
|
|
|
|
- window = MainWindow()
|
|
|
|
- window.mainloop()
|
|
|
|
|
|
+namespace WpfApp1
|
|
|
|
+{
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Interaction logic for MainWindow.xaml
|
|
|
|
+ /// </summary>
|
|
|
|
|
|
|
|
+ public partial class MainWindow : Window, INotifyPropertyChanged
|
|
|
|
+ {
|
|
|
|
+ public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
+ private void Invalidate()
|
|
|
|
+ {
|
|
|
|
+ if (PropertyChanged != null)
|
|
|
|
+ PropertyChanged(this, new PropertyChangedEventArgs("CarList"));
|
|
|
|
+ }
|
|
|
|
+ public string selectedname = "Все автомобили";
|
|
|
|
+ public Carsprice? selectedprice = null;
|
|
|
|
+
|
|
|
|
+ private IEnumerable<cars> _CarList;
|
|
|
|
+ public IEnumerable<cars> CarList
|
|
|
|
+ {
|
|
|
|
+ get
|
|
|
|
+ {
|
|
|
|
+ return _CarList
|
|
|
|
+ .Where(c => (c.name == selectedname || selectedname == "Все автомобили"))
|
|
|
|
+ .Where(c => (selectedprice == null || (c.price >= selectedprice.priceFrom && c.price < selectedprice.priceTo)));
|
|
|
|
+ }
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ _CarList = value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public List<cars> Cars { get; set; }
|
|
|
|
+ public List<Namecar> CarinfoList { get; set; }
|
|
|
|
+ public List<Carsprice> CarpriceList { get; set; }
|
|
|
|
+ public MainWindow()
|
|
|
|
+ {
|
|
|
|
+ InitializeComponent();
|
|
|
|
+ DataContext = this;
|
|
|
|
+ Globals.dataProvider = new LocalDataProvider();
|
|
|
|
+ CarList = Globals.dataProvider.getCars();
|
|
|
|
+ CarinfoList = Globals.dataProvider.getName().ToList();
|
|
|
|
+ CarinfoList.Insert(0, new Namecar { title = "Все автомобили" });
|
|
|
|
+ CarpriceList = Globals.dataProvider.getPrice().ToList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void ExitButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Application.Current.Shutdown();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void carnameFilterComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ selectedname = (carnameFilterComboBox.SelectedItem as Namecar).title;
|
|
|
|
+ Invalidate();
|
|
|
|
+ }
|
|
|
|
+ private void carpriceFilterComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ selectedprice = carpriceFilterComboBox.SelectedItem as Carsprice;
|
|
|
|
+ Invalidate();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ interface IDataProvider
|
|
|
|
+ {
|
|
|
|
+ IEnumerable<cars> getCars();
|
|
|
|
+ IEnumerable<Namecar> getName();
|
|
|
|
+ IEnumerable<Carsprice> getPrice();
|
|
|
|
+ }
|
|
|
|
+ public class LocalDataProvider : IDataProvider
|
|
|
|
+ {
|
|
|
|
+ public IEnumerable<Namecar> getName()
|
|
|
|
+ {
|
|
|
|
+ return new Namecar[]
|
|
|
|
+ {
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Toyota Trueno AE86"
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Toyota Supra A80"
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Nissal Skyline R34"
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Nissan Silvia S15"
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Toyota Camry 3.5"
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Audi RS 6"
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Трактор LOVOL TE354 HT"
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="BMW M5 F90"
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="BMW E36"
|
|
|
|
+ },
|
|
|
|
+ new Namecar()
|
|
|
|
+ {
|
|
|
|
+ title="Daewoo Matiz"
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ public IEnumerable<Carsprice> getPrice()
|
|
|
|
+ {
|
|
|
|
+ return new Carsprice[]
|
|
|
|
+ {
|
|
|
|
+ new Carsprice()
|
|
|
|
+ {
|
|
|
|
+ title="Все цены",
|
|
|
|
+ priceFrom=0,
|
|
|
|
+ priceTo=70000
|
|
|
|
+ },
|
|
|
|
+ new Carsprice()
|
|
|
|
+ {
|
|
|
|
+ title="Малая цена",
|
|
|
|
+ priceFrom=0,
|
|
|
|
+ priceTo=15001
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ new Carsprice()
|
|
|
|
+ {
|
|
|
|
+ title="Средняя цена",
|
|
|
|
+ priceFrom=20000,
|
|
|
|
+ priceTo=35000
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ new Carsprice()
|
|
|
|
+ {
|
|
|
|
+ title="Высокая цена",
|
|
|
|
+ priceFrom=35001,
|
|
|
|
+ priceTo=70000
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ public IEnumerable<cars> getCars()
|
|
|
|
+ {
|
|
|
|
+ return new cars[] {
|
|
|
|
+ new cars {
|
|
|
|
+ price = 15000,
|
|
|
|
+ name = "Toyota Trueno AE86",
|
|
|
|
+ year = 1995,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 30000,
|
|
|
|
+ name = "Toyota Supra A80",
|
|
|
|
+ year = 1996,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 25000,
|
|
|
|
+ name = "Nissal Skyline R34",
|
|
|
|
+ year = 1996
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 20000,
|
|
|
|
+ name = "Nissan Silvia S15",
|
|
|
|
+ year = 1999,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 20000,
|
|
|
|
+ name = "Toyota Camry 3.5",
|
|
|
|
+ year = 2020,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 30000,
|
|
|
|
+ name = "Audi RS 6",
|
|
|
|
+ year = 2016,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 66666,
|
|
|
|
+ name = "Трактор LOVOL TE354 HT",
|
|
|
|
+ year = 2024,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 30000,
|
|
|
|
+ name = "BMW M5 F90",
|
|
|
|
+ year = 2019,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 35000,
|
|
|
|
+ name = "BMW E36",
|
|
|
|
+ year = 2006,
|
|
|
|
+ },
|
|
|
|
+ new cars {
|
|
|
|
+ price = 20000,
|
|
|
|
+ name = "Daewoo Matiz",
|
|
|
|
+ year = 2010,
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+```
|
|
|
|
+***
|
|
**Вот что получилось**
|
|
**Вот что получилось**
|
|
|
|
|
|
-![](./img/scr.png)
|
|
|
|
|
|
+![](./img/net.png)
|
|
|
|
+![](./img/net1.png)
|
|
|
|
+![](./img/net2.png)
|