Ver código fonte

Добавлено поле поиска в XAML

Вадим Королёв 1 ano atrás
pai
commit
79206f3da9

+ 1 - 1
InvestTracker/MainWindow.xaml

@@ -6,7 +6,7 @@
         xmlns:local="clr-namespace:InvestTracker"
         xmlns:commands="clr-namespace:InvestTracker.Commands"
         mc:Ignorable="d"
-        Title="ИнвестУчёт" Height="600" Width="900">
+        Title="ИнвестУчёт" Height="720" Width="1280">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="32px"/>

+ 17 - 2
InvestTracker/VM/EmployeeBrowseVM.cs

@@ -53,6 +53,21 @@ namespace InvestTracker.VM
         /// </summary>
         public Employee? SelectedEmployee { get; set; }
 
+        /// <summary>
+        /// Видимо ли на данный момент поле поиска
+        /// </summary>
+        public bool SearchVisible { get; set; }
+
+        /// <summary>
+        /// По какой фамилии фильтровать поиск
+        /// </summary>
+        public string FilterSurname { get; set; }
+
+        /// <summary>
+        /// По какой должности фильтровать поиск
+        /// </summary>
+        public Entities.Title FilterTitle { get; set; }
+
         public EmployeeBrowseVM()
         {
             UndoCommand     = new DelegateCommand(Undo_Executed,    WhenDirty);
@@ -194,8 +209,8 @@ namespace InvestTracker.VM
         /// </summary>
         private void Find_Executed()
         {
-            MessageBox.Show("Searching...");
-            ReEvaluateCommands();
+            SearchVisible = true;
+            RaisePropertyChanged(nameof(SearchVisible));
         }
         
         /// <summary>

+ 155 - 77
InvestTracker/Views/EmployeeBrowseView.xaml

@@ -6,7 +6,7 @@
       xmlns:vm="clr-namespace:InvestTracker.VM"
       xmlns:local="clr-namespace:InvestTracker.Views"
       xmlns:model="clr-namespace:InvestTracker.Entities"
-      xmlns:validation="clr-namespace:InvestTracker.Validation"
+      xmlns:validation="clr-namespace:InvestTracker.Validation" d:DataContext="{d:DesignInstance Type=vm:EmployeeBrowseVM}"
       mc:Ignorable="d" 
       d:DesignHeight="450" d:DesignWidth="800"
       x:Name="EPage"
@@ -46,100 +46,178 @@
 
         <ToolBar>
             <Button Name="Undo" Command="{Binding UndoCommand}" ToolTip="Отменить редактирование/создание">
-                <Image Width="16" Height="16" Source="/Images/undo.png" />
+                <Image Width="32" Height="32" Source="/Images/undo.png" />
             </Button>
             <Button Name="Add" Command="{Binding NewCommand}" ToolTip="Добавить">
-                <Image Width="16" Height="16"  Source="/Images/add.png" />
+                <Image Width="32" Height="32"  Source="/Images/add.png" />
             </Button>
             <Button Name="Edit" Command="{Binding EditCommand}" ToolTip="Редактировать">
-                <Image Width="16" Height="16"  Source="/Images/edit.png" />
+                <Image Width="32" Height="32"  Source="/Images/edit.png" />
             </Button>
             <Button Name="Search" Command="{Binding FindCommand}" ToolTip="Поиск">
-                <Image Width="16" Height="16"  Source="/Images/search.png" />
+                <Image Width="32" Height="32"  Source="/Images/search.png" />
             </Button>
             <Button Name="Save" Command="{Binding SaveCommand}"  ToolTip="Сохранить">
-                <Image Width="16" Height="16"  Source="/Images/save.png" />
+                <Image Width="32" Height="32"  Source="/Images/save.png" />
             </Button>
             <Button Name="Delete" Command="{Binding DeleteCommand}" ToolTip="Удалить">
-                <Image Width="16" Height="16"  Source="/Images/delete.png" />
+                <Image Width="32" Height="32"  Source="/Images/delete.png" />
             </Button>
         </ToolBar>
 
         <Label>Список сотрудников</Label>
 
-        <DataGrid
-            AutoGenerateColumns="False"
-            ItemsSource="{Binding Employees}"
-            RowBackground="#ddd"
-            AlternatingRowBackground="#eee"
-            CanUserAddRows="False"
-            CanUserDeleteRows="False"
-            IsReadOnly="{Binding GridBlocked}"
-            SelectedItem="{Binding SelectedEmployee}">
+        <!--Main-->
+        <Grid>
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="*"/>
+            </Grid.ColumnDefinitions>
+            
+            <!--Сетка редактирования-->
+            <DataGrid
+                Margin="4,0"
+                Grid.Column="0"
+                AutoGenerateColumns="False"
+                ItemsSource="{Binding Employees}"
+                RowBackground="#ddd"
+                AlternatingRowBackground="#eee"
+                CanUserAddRows="False"
+                CanUserDeleteRows="False"
+                IsReadOnly="{Binding GridBlocked}"
+                SelectedItem="{Binding SelectedEmployee}">
 
-            <!--Рисуем восклицательный знак если в строке ошибка-->
-            <DataGrid.RowValidationErrorTemplate>
-                <ControlTemplate>
-                    <Grid
-                        Margin="0,-2,0,-2"
-                        ToolTip="{Binding
-                            RelativeSource={RelativeSource FindAncestor,
-                            AncestorType={x:Type DataGridRow}},
-                            Path=(Validation.Errors)[0].ErrorContent}">
-                        <Ellipse
-                            StrokeThickness="0"
-                            Fill="Red"
-                            Width="{TemplateBinding FontSize}"
-                            Height="{TemplateBinding FontSize}" />
-                        <TextBlock
-                            Text="!"
-                            FontSize="{TemplateBinding FontSize}"
-                            FontWeight="Bold"
-                            Foreground="White"
-                            HorizontalAlignment="Center" />
-                    </Grid>
-                </ControlTemplate>
-            </DataGrid.RowValidationErrorTemplate>
+                <!--Рисуем восклицательный знак если в строке ошибка-->
+                <DataGrid.RowValidationErrorTemplate>
+                    <ControlTemplate>
+                        <Grid
+                            Margin="0,-2,0,-2"
+                            ToolTip="{Binding
+                                RelativeSource={RelativeSource FindAncestor,
+                                AncestorType={x:Type DataGridRow}},
+                                Path=(Validation.Errors)[0].ErrorContent}">
+                            <Ellipse
+                                StrokeThickness="0"
+                                Fill="Red"
+                                Width="{TemplateBinding FontSize}"
+                                Height="{TemplateBinding FontSize}" />
+                            <TextBlock
+                                Text="!"
+                                FontSize="{TemplateBinding FontSize}"
+                                FontWeight="Bold"
+                                Foreground="White"
+                                HorizontalAlignment="Center" />
+                        </Grid>
+                    </ControlTemplate>
+                </DataGrid.RowValidationErrorTemplate>
 
-            <DataGrid.Columns>
-                <DataGridTextColumn
-                    Binding="{Binding Path=Surname,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
-                    Header="Фамилия"/>
-                <DataGridTextColumn
-                    Binding="{Binding Path=Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
-                    Header="Имя"/>
-                <DataGridTextColumn
-                    Binding="{Binding Path=Patronymic,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
-                    Header="Отчество"/>
-                <DataGridComboBoxColumn
+                <DataGrid.Columns>
+                    <DataGridTextColumn
+                        Binding="{Binding Path=Surname,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
+                        Header="Фамилия"/>
+                    <DataGridTextColumn
+                        Binding="{Binding Path=Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
+                        Header="Имя"/>
+                    <DataGridTextColumn
+                        Binding="{Binding Path=Patronymic,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
+                        Header="Отчество"/>
+                    <DataGridComboBoxColumn
+                        ItemsSource="{Binding DataContext.AllTitles,Source={x:Reference ProxyElement}}"
+                        DisplayMemberPath="Name"
+                        SelectedValueBinding="{Binding Path=TitleId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                        SelectedValuePath="Id"
+                        Header="Должность"/>
+                    <DataGridTemplateColumn
+                        CellTemplate="{StaticResource RegularDateTemplate}"
+                        CellEditingTemplate="{StaticResource EditingDateTemplate}"
+                        Header="Дата рождения" />
+                    <DataGridTextColumn
+                        Binding="{Binding Path=Phone,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
+                        Header="Телефон" />
+                    <DataGridTextColumn
+                        EditingElementStyle="{StaticResource ValidationFail}"
+                        Header="Электронная почта">
+                        <DataGridTextColumn.Binding>
+                            <Binding 
+                                Path="Email" 
+                                Mode="TwoWay" 
+                                UpdateSourceTrigger="PropertyChanged"
+                                ValidatesOnExceptions="True">
+                                <Binding.ValidationRules>
+                                    <validation:Email/>
+                                </Binding.ValidationRules>
+                            </Binding>
+                        </DataGridTextColumn.Binding>
+                    </DataGridTextColumn>
+                </DataGrid.Columns>
+            </DataGrid>
+            <!--/Сетка редактирования-->
+            
+            <!--Поле поиска-->
+            <Grid Grid.Column="1" Background="#ddd" Margin="4,0">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="64"/>
+                    <ColumnDefinition Width="*"/>
+                    <ColumnDefinition Width="32"/>
+                </Grid.ColumnDefinitions>
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="16"/>
+                    <RowDefinition Height="32"/>
+                    <RowDefinition Height="32"/>
+                </Grid.RowDefinitions>
+
+                <Label
+                    Content="Поиск"
+                    HorizontalAlignment="Center"
+                    Grid.Column="0"
+                    Grid.ColumnSpan="3"
+                    Grid.Row="0"/>
+
+                <Label
+                    Content="Фамилия"
+                    HorizontalAlignment="Right"
+                    VerticalAlignment="Center"
+                    Grid.Column="0"
+                    Grid.Row="1"/>
+                <TextBox
+                    VerticalContentAlignment="Center"
+                    Grid.Column="1"
+                    Margin="4"
+                    Grid.Row="1"
+                    Text="{Binding FilterSurname,UpdateSourceTrigger=PropertyChanged}"/>
+                <Button
+                    Grid.Column="2"
+                    Grid.Row="1"
+                    Margin="4"
+                    ToolTip="Поиск по фамилии">
+                    <Image Source="/Images/search.png" />
+                </Button>
+
+                <Label
+                    Content="Должность"
+                    HorizontalAlignment="Right"
+                    VerticalAlignment="Center"
+                    Grid.Column="0"
+                    Grid.Row="2"/>
+                <ComboBox
+                    VerticalContentAlignment="Center"
+                    Margin="4"
+                    Grid.Column="1"
+                    Grid.Row="2"
                     ItemsSource="{Binding DataContext.AllTitles,Source={x:Reference ProxyElement}}"
                     DisplayMemberPath="Name"
-                    SelectedValueBinding="{Binding Path=TitleId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                    SelectedValuePath="Id"
-                    Header="Должность"/>
-                <DataGridTemplateColumn
-                    CellTemplate="{StaticResource RegularDateTemplate}"
-                    CellEditingTemplate="{StaticResource EditingDateTemplate}"
-                    Header="Дата рождения" />
-                <DataGridTextColumn
-                    Binding="{Binding Path=Phone,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
-                    Header="Телефон" />
-                <DataGridTextColumn
-                    EditingElementStyle="{StaticResource ValidationFail}"
-                    Header="Электронная почта">
-                    <DataGridTextColumn.Binding>
-                        <Binding 
-                            Path="Email" 
-                            Mode="TwoWay" 
-                            UpdateSourceTrigger="PropertyChanged"
-                            ValidatesOnExceptions="True">
-                            <Binding.ValidationRules>
-                                <validation:Email/>
-                            </Binding.ValidationRules>
-                        </Binding>
-                    </DataGridTextColumn.Binding>
-                </DataGridTextColumn>
-            </DataGrid.Columns>
-        </DataGrid>
+                    SelectedItem="{Binding FilterTitle, UpdateSourceTrigger=PropertyChanged}"/>
+                <Button
+                    Margin="4"
+                    Grid.Column="2"
+                    Grid.Row="2"
+                    ToolTip="Поиск по должности">
+                    <Image Source="/Images/search.png" />
+                </Button>
+
+            </Grid>
+            <!--/Поле поиска-->
+        </Grid>
+        <!--/Main-->
     </StackPanel>
 </Page>