Bläddra i källkod

Merge branch 'add-transport-list' of 21IS12/SAS into master

Королёв Вадим Сергеевич 6 månader sedan
förälder
incheckning
816b8be88c

+ 27 - 1
src/SASDesktop/Models/SASExt.cs

@@ -29,7 +29,7 @@ namespace SASDesktop.Models
         {
             get
             {
-                return GetHumanName + "placeholder";
+                return GetHumanName + DateOfBirth.ToString();
             }
         }
         public string GetHumanPass
@@ -52,6 +52,7 @@ namespace SASDesktop.Models
             }
         }
     }
+
     partial class File
     {
         public ImageSource ImageSource
@@ -83,4 +84,29 @@ namespace SASDesktop.Models
             }
         }
     }
+
+    partial class Transport
+    {
+        public string ListGeneral
+        {
+            get
+            {
+                return Model1.Brand1.Name + " " + Model1.Name + " " + RelaseYear.ToString();
+            }
+        }
+
+        public string CurrentOwnerText
+        {
+            get
+            {
+                if (TransportOwnerships.Count == 0)
+                {
+                    return "<Нет владельцев>";
+                }
+                
+                var currentOwner = TransportOwnerships.OrderByDescending(to => to.CreatedAt).FirstOrDefault();
+                return currentOwner.Citizen1.GetHumanName;
+            }
+        }
+    }
 }

+ 22 - 1
src/SASDesktop/Navigation.cs

@@ -16,8 +16,14 @@ namespace SASDesktop
         #region Команды
         public static DelegateCommand ToDriverCreate    { get; set; }   = new DelegateCommand(ToDriverCreateExecuted);
         public static DelegateCommand ToDriverList      { get; set; }   = new DelegateCommand(ToDriverListExecuted);
+
         public static DelegateCommand ToTransportCreate { get; set; }   = new DelegateCommand(ToTransportCreateExecuted);
         public static DelegateCommand ToTransportList   { get; set; }   = new DelegateCommand(ToTransportListExecuted);
+
+        public static DelegateCommand ToLicenseCreate   { get; set; }   = new DelegateCommand(ToLicenseCreateExecuted);
+        public static DelegateCommand ToLicenseRemove   { get; set; }   = new DelegateCommand(ToLicenseRemoveExecuted);
+        public static DelegateCommand ToLicenseList     { get; set; }   = new DelegateCommand(ToLicenseListExecuted);
+
         public static DelegateCommand Logout            { get; set; }   = new DelegateCommand(LogoutExecuted);//shotup
         #endregion
 
@@ -82,7 +88,7 @@ namespace SASDesktop
         /// </summary>
         public static void ToTransportListExecuted()
         {
-            throw new NotImplementedException();
+            GetMainFrame().Navigate(new Views.Transport.List());
         }
 
         /// <summary>
@@ -95,5 +101,20 @@ namespace SASDesktop
             HideLogoutButton();
             GetMainFrame().Navigate(new Views.Auth());
         }
+        
+        public static void ToLicenseCreateExecuted()
+        {
+            Popups.NotImplementedSorry();
+        }
+        
+        public static void ToLicenseRemoveExecuted()
+        {
+            Popups.NotImplementedSorry();
+        }
+        
+        public static void ToLicenseListExecuted()
+        {
+            Popups.NotImplementedSorry();
+        }
     }
 }

+ 10 - 0
src/SASDesktop/Popups.cs

@@ -46,5 +46,15 @@ namespace SASDesktop
             );
             return response == MessageBoxResult.Yes;
         }
+
+        public static void NotImplementedSorry()
+        {
+            MessageBox.Show(
+                "Эта функция ещё не реализована",
+                "Функция не реализована",
+                MessageBoxButton.OK,
+                MessageBoxImage.Information
+            );
+        }
     }
 }

+ 17 - 1
src/SASDesktop/SASDesktop.csproj

@@ -198,6 +198,7 @@
     <Compile Include="ViewModels\Drivers\ListOutput.cs" />
     <Compile Include="ViewModels\Portal.cs" />
     <Compile Include="ViewModels\Transport\Create.cs" />
+    <Compile Include="ViewModels\Transport\List.cs" />
     <Compile Include="Views\Auth.xaml.cs">
       <DependentUpon>Auth.xaml</DependentUpon>
     </Compile>
@@ -207,10 +208,15 @@
     <Compile Include="Views\Drivers\DriverListOutput.xaml.cs">
       <DependentUpon>DriverListOutput.xaml</DependentUpon>
     </Compile>
-    <Compile Include="Views\Portal.cs" />
+    <Compile Include="Views\Portal.cs">
+      <DependentUpon>Portal.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\Transport\Create.xaml.cs">
       <DependentUpon>Create.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\Transport\List.xaml.cs">
+      <DependentUpon>List.xaml</DependentUpon>
+    </Compile>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -255,6 +261,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\Transport\List.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs">
@@ -310,5 +320,11 @@
   <ItemGroup>
     <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\VINlib\VINlib.csproj">
+      <Project>{e38515da-3ce4-4b1c-a9f5-40c506bf29eb}</Project>
+      <Name>VINlib</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 34 - 2
src/SASDesktop/ViewModels/Transport/Create.cs

@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using VINlib;
 
 namespace SASDesktop.ViewModels.Transport
 {
@@ -15,7 +16,23 @@ namespace SASDesktop.ViewModels.Transport
         public string VIN
         {
             get { return _vin; }
-            set { _vin = value; RaisePropertyChanged(nameof(VIN)); }
+            set
+            {
+                _vin = value;
+
+                if (VINlib.VinInfo.CheckVIN(value))
+                {
+                    // Если VIN-номер - правильный, то подставляем год
+                    int year = VINlib.VinInfo.GetTransportYear(value);
+                    if (year != 0)
+                    {
+                        // Библиотека смогла вернуть год
+                        ReleaseYear = year.ToString();
+                    }
+                }
+
+                RaisePropertyChanged(nameof(VIN));
+            }
         }
         #endregion
 
@@ -514,7 +531,22 @@ namespace SASDesktop.ViewModels.Transport
 
         private void SubmitExecuted()
         {
-            // TODO: валидации и проверки
+            // TODO: больше валидаций и проверок
+
+            // 0. Проверки
+            List<string> errors = new List<string>();
+
+            bool vinIsCorrect = VINlib.VinInfo.CheckVIN(VIN);
+            if (!vinIsCorrect)
+            {
+                errors.Add("Неверный VIN-номер");
+            }
+
+            if (errors.Count > 0)
+            {
+                Popups.ShowErrors(errors);
+                return;
+            }
 
             var db = new Models.SASEntities();
 

+ 38 - 0
src/SASDesktop/ViewModels/Transport/List.cs

@@ -0,0 +1,38 @@
+using Prism.Commands;
+using Prism.Mvvm;
+using SASDesktop.Models;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace SASDesktop.ViewModels.Transport
+{
+    class List : BindableBase
+    {
+        public ObservableCollection<Models.Transport> TransportList { get; set; }
+        public DelegateCommand EditCmd { get; set; }
+        public DelegateCommand DeleteCmd { get; set; }
+
+        public List()
+        {
+            var db = new Models.SASEntities();
+            TransportList = new ObservableCollection<Models.Transport>(db.Transports.ToList());
+            EditCmd = new DelegateCommand(EditExecuted);
+            DeleteCmd = new DelegateCommand(DeleteExecuted);
+        }
+
+        public void EditExecuted()
+        {
+            Popups.NotImplementedSorry();
+        }
+
+        public void DeleteExecuted()
+        {
+            Popups.NotImplementedSorry();
+        }
+    }
+}

+ 21 - 0
src/SASDesktop/Views/Portal.xaml

@@ -56,6 +56,27 @@
                                 Margin="0,4"/>
                     </StackPanel>
                 </Border>
+                
+                <!--Управление водительскими правами-->
+                <Border Style="{StaticResource Card}">
+                    <StackPanel Style="{StaticResource CardInner}">
+                        <TextBlock
+                            Style="{StaticResource H3}"
+                            Text="Управление водительскими правами"/>
+                        <Button
+                            Content="Создать"
+                            Command="{Binding Source={x:Static root:Navigation.ToLicenseCreate}}"
+                            Margin="0,4"/>
+                        <Button
+                            Content="Снять права с водителя"
+                            Command="{Binding Source={x:Static root:Navigation.ToLicenseRemove}}"
+                            Margin="0,4"/>
+                        <Button
+                            Content="Просмотр списка"
+                            Command="{Binding Source={x:Static root:Navigation.ToLicenseList}}"
+                            Margin="0,4"/>
+                    </StackPanel>
+                </Border>
             </WrapPanel>
         </StackPanel>
     </ScrollViewer>

+ 95 - 0
src/SASDesktop/Views/Transport/List.xaml

@@ -0,0 +1,95 @@
+<Page x:Class="SASDesktop.Views.Transport.List"
+      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+      xmlns:local="clr-namespace:SASDesktop.Views.Transport" xmlns:transport="clr-namespace:SASDesktop.ViewModels.Transport" d:DataContext="{d:DesignInstance Type=transport:List}"
+      mc:Ignorable="d"
+      xmlns:root="clr-namespace:SASDesktop"
+      d:DesignHeight="600" d:DesignWidth="800"
+      Title="Список ТС">
+    <!--Страница просмотра всех транспортных средств-->
+    <ScrollViewer>
+        <StackPanel
+            CanVerticallyScroll="True"
+            Style="{StaticResource FormContainer}">
+
+            <!--Заголовок страницы-->
+            <TextBlock 
+                HorizontalAlignment="Center"
+                Style="{StaticResource H2}"
+                Text="Список транспортных средств"/>
+
+            <!--Сам список-->
+            <ListView
+                ItemsSource="{Binding TransportList}"
+                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
+                Height="400">
+                <ListView.ItemsPanel>
+                    <ItemsPanelTemplate>
+                        <WrapPanel Orientation="Horizontal"/>
+                    </ItemsPanelTemplate>
+                </ListView.ItemsPanel>
+
+                <ListView.ItemTemplate>
+                    <DataTemplate>
+                        <Grid Width="310">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="80"/>
+                                <ColumnDefinition Width="*"/>
+                            </Grid.ColumnDefinitions>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="20"/>
+                                <RowDefinition Height="20"/>
+                                <RowDefinition Height="20"/>
+                            </Grid.RowDefinitions>
+
+                            <TextBlock
+                                Text="VIN:"
+                                Grid.Column="0"
+                                Grid.Row="0"/>
+                            <TextBlock
+                                Text="{Binding VIN}"
+                                Grid.Column="1"
+                                Grid.Row="0"/>
+
+                            <TextBlock
+                                Text="Основное:"
+                                Grid.Column="0"
+                                Grid.Row="1"/>
+                            <TextBlock
+                                Text="{Binding ListGeneral}"
+                                Grid.Column="1"
+                                Grid.Row="1"/>
+                            
+                            <TextBlock
+                                Text="Владелец:"
+                                Grid.Column="0"
+                                Grid.Row="2"/>
+                            <TextBlock
+                                Text="{Binding CurrentOwnerText}"
+                                Grid.Column="1"
+                                Grid.Row="2"/>
+                        </Grid>
+                    </DataTemplate>
+                </ListView.ItemTemplate>
+            </ListView>
+
+            <!--Кнопки управления-->
+            <StackPanel Orientation="Horizontal">
+                <Button
+                    Content="Добавить"
+                    Style="{StaticResource StandartButton}"
+                    Command="{Binding Source={x:Static root:Navigation.ToTransportCreate}}"/>
+                <Button
+                    Content="Редактировать"
+                    Style="{StaticResource StandartButton}"
+                    Command="{Binding EditCmd}"/>
+                <Button
+                    Content="Удалить"
+                    Style="{StaticResource StandartButton}"
+                    Command="{Binding DeleteCmd}"/>
+            </StackPanel>
+        </StackPanel>
+    </ScrollViewer>
+</Page>

+ 29 - 0
src/SASDesktop/Views/Transport/List.xaml.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace SASDesktop.Views.Transport
+{
+    /// <summary>
+    /// Логика взаимодействия для Create.xaml
+    /// </summary>
+    public partial class List : Page
+    {
+        public List()
+        {
+            InitializeComponent();
+            DataContext = new ViewModels.Transport.List();
+        }
+    }
+}