Imagara 3 vuotta sitten
vanhempi
commit
09cf5a5f31

+ 34 - 34
Kusach/EDM.edmx

@@ -148,18 +148,6 @@
             </Dependent>
           </ReferentialConstraint>
         </Association>
-        <Association Name="FK__RouteList__IdRou__6383C8BA">
-          <End Role="Dispatcher" Type="Self.Dispatcher" Multiplicity="1" />
-          <End Role="RouteList" Type="Self.RouteList" Multiplicity="*" />
-          <ReferentialConstraint>
-            <Principal Role="Dispatcher">
-              <PropertyRef Name="IdDispatcher" />
-            </Principal>
-            <Dependent Role="RouteList">
-              <PropertyRef Name="IdRoute" />
-            </Dependent>
-          </ReferentialConstraint>
-        </Association>
         <Association Name="FK_Drivers_Transport">
           <End Role="Transport" Type="Self.Transport" Multiplicity="1" />
           <End Role="Drivers" Type="Self.Drivers" Multiplicity="*" />
@@ -172,6 +160,18 @@
             </Dependent>
           </ReferentialConstraint>
         </Association>
+        <Association Name="FK_RouteList_Dispatcher">
+          <End Role="Dispatcher" Type="Self.Dispatcher" Multiplicity="1" />
+          <End Role="RouteList" Type="Self.RouteList" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Dispatcher">
+              <PropertyRef Name="IdDispatcher" />
+            </Principal>
+            <Dependent Role="RouteList">
+              <PropertyRef Name="IdDispatcher" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
         <EntityContainer Name="Хранилище EDMModelContainer">
           <EntitySet Name="Dispatcher" EntityType="Self.Dispatcher" Schema="dbo" store:Type="Tables" />
           <EntitySet Name="Drivers" EntityType="Self.Drivers" Schema="dbo" store:Type="Tables" />
@@ -202,14 +202,14 @@
             <End Role="Routes" EntitySet="Routes" />
             <End Role="RouteList" EntitySet="RouteList" />
           </AssociationSet>
-          <AssociationSet Name="FK__RouteList__IdRou__6383C8BA" Association="Self.FK__RouteList__IdRou__6383C8BA">
-            <End Role="Dispatcher" EntitySet="Dispatcher" />
-            <End Role="RouteList" EntitySet="RouteList" />
-          </AssociationSet>
           <AssociationSet Name="FK_Drivers_Transport" Association="Self.FK_Drivers_Transport">
             <End Role="Transport" EntitySet="Transport" />
             <End Role="Drivers" EntitySet="Drivers" />
           </AssociationSet>
+          <AssociationSet Name="FK_RouteList_Dispatcher" Association="Self.FK_RouteList_Dispatcher">
+            <End Role="Dispatcher" EntitySet="Dispatcher" />
+            <End Role="RouteList" EntitySet="RouteList" />
+          </AssociationSet>
         </EntityContainer>
       </Schema></edmx:StorageModels>
     <!-- CSDL content -->
@@ -229,8 +229,8 @@
           <Property Name="PhoneNumber" Type="String" MaxLength="10" FixedLength="false" Unicode="true" Nullable="false" />
           <Property Name="Email" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
           <Property Name="Permission" Type="Int32" Nullable="false" />
-          <NavigationProperty Name="RouteList" Relationship="Self.FK__RouteList__IdRou__6383C8BA" FromRole="Dispatcher" ToRole="RouteList" />
           <Property Name="ProfileImgSource" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <NavigationProperty Name="RouteList" Relationship="EDMModel.FK_RouteList_Dispatcher" FromRole="Dispatcher" ToRole="RouteList" />
         </EntityType>
         <EntityType Name="Drivers">
           <Key>
@@ -280,8 +280,8 @@
           <Property Name="Id" Type="Int32" Nullable="false" />
           <Property Name="IdRoute" Type="Int32" Nullable="false" />
           <Property Name="IdDispatcher" Type="Int32" Nullable="false" />
-          <NavigationProperty Name="Dispatcher" Relationship="Self.FK__RouteList__IdRou__6383C8BA" FromRole="RouteList" ToRole="Dispatcher" />
           <NavigationProperty Name="Routes" Relationship="Self.FK__RouteList__IdRou__628FA481" FromRole="RouteList" ToRole="Routes" />
+          <NavigationProperty Name="Dispatcher" Relationship="EDMModel.FK_RouteList_Dispatcher" FromRole="RouteList" ToRole="Dispatcher" />
         </EntityType>
         <EntityType Name="Routes">
           <Key>
@@ -312,18 +312,6 @@
           <Property Name="NumberPlate" Type="String" MaxLength="10" FixedLength="false" Unicode="true" Nullable="false" />
           <NavigationProperty Name="Drivers" Relationship="Self.FK_Drivers_Transport" FromRole="Transport" ToRole="Drivers" />
         </EntityType>
-        <Association Name="FK__RouteList__IdRou__6383C8BA">
-          <End Role="Dispatcher" Type="Self.Dispatcher" Multiplicity="1" />
-          <End Role="RouteList" Type="Self.RouteList" Multiplicity="*" />
-          <ReferentialConstraint>
-            <Principal Role="Dispatcher">
-              <PropertyRef Name="IdDispatcher" />
-            </Principal>
-            <Dependent Role="RouteList">
-              <PropertyRef Name="IdRoute" />
-            </Dependent>
-          </ReferentialConstraint>
-        </Association>
         <Association Name="FK__DriversLi__IdDri__0C85DE4D">
           <End Role="Drivers" Type="Self.Drivers" Multiplicity="1" />
           <End Role="DriversList" Type="Self.DriversList" Multiplicity="*" />
@@ -406,10 +394,6 @@
           <EntitySet Name="Routes" EntityType="Self.Routes" />
           <EntitySet Name="sysdiagrams" EntityType="Self.sysdiagrams" />
           <EntitySet Name="Transport" EntityType="Self.Transport" />
-          <AssociationSet Name="FK__RouteList__IdRou__6383C8BA" Association="Self.FK__RouteList__IdRou__6383C8BA">
-            <End Role="Dispatcher" EntitySet="Dispatcher" />
-            <End Role="RouteList" EntitySet="RouteList" />
-          </AssociationSet>
           <AssociationSet Name="FK__DriversLi__IdDri__0C85DE4D" Association="Self.FK__DriversLi__IdDri__0C85DE4D">
             <End Role="Drivers" EntitySet="Drivers" />
             <End Role="DriversList" EntitySet="DriversList" />
@@ -434,7 +418,23 @@
             <End Role="Routes" EntitySet="Routes" />
             <End Role="RouteList" EntitySet="RouteList" />
           </AssociationSet>
+          <AssociationSet Name="FK_RouteList_Dispatcher" Association="EDMModel.FK_RouteList_Dispatcher">
+            <End Role="Dispatcher" EntitySet="Dispatcher" />
+            <End Role="RouteList" EntitySet="RouteList" />
+          </AssociationSet>
         </EntityContainer>
+        <Association Name="FK_RouteList_Dispatcher">
+          <End Type="EDMModel.Dispatcher" Role="Dispatcher" Multiplicity="1" />
+          <End Type="EDMModel.RouteList" Role="RouteList" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Dispatcher">
+              <PropertyRef Name="IdDispatcher" />
+            </Principal>
+            <Dependent Role="RouteList">
+              <PropertyRef Name="IdDispatcher" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
       </Schema>
     </edmx:ConceptualModels>
     <!-- C-S mapping content -->

+ 3 - 3
Kusach/EDM.edmx.diagram

@@ -5,22 +5,22 @@
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
       <Diagram DiagramId="82fb6c82068d472697811e1a8b69e0b5" Name="Diagram1">
-        <EntityTypeShape EntityType="EDMModel.Dispatcher" Width="1.5" PointX="0.75" PointY="13.375" IsExpanded="true" />
+        <EntityTypeShape EntityType="EDMModel.Dispatcher" Width="1.5" PointX="7.375" PointY="6" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.Drivers" Width="1.5" PointX="0.75" PointY="6.75" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.DriversList" Width="1.5" PointX="3" PointY="3.875" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.Points" Width="1.5" PointX="7" PointY="1.125" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.PointsList" Width="1.5" PointX="3" PointY="0.875" IsExpanded="true" />
-        <EntityTypeShape EntityType="EDMModel.RouteList" Width="1.5" PointX="3" PointY="6.875" IsExpanded="true" />
+        <EntityTypeShape EntityType="EDMModel.RouteList" Width="1.5" PointX="4.75" PointY="5.875" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.Routes" Width="1.5" PointX="0.75" PointY="3.875" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.sysdiagrams" Width="1.5" PointX="12.625" PointY="1.625" IsExpanded="true" />
         <EntityTypeShape EntityType="EDMModel.Transport" Width="1.5" PointX="1.5" PointY="10" IsExpanded="true" />
-        <AssociationConnector Association="EDMModel.FK__RouteList__IdRou__6383C8BA" ManuallyRouted="false" />
         <AssociationConnector Association="EDMModel.FK__DriversLi__IdDri__0C85DE4D" ManuallyRouted="false" />
         <AssociationConnector Association="EDMModel.FK_Drivers_Transport" ManuallyRouted="false" />
         <AssociationConnector Association="EDMModel.FK__DriversLi__IdRou__68487DD7" ManuallyRouted="false" />
         <AssociationConnector Association="EDMModel.FK__PointsLis__IdPoi__6477ECF3" ManuallyRouted="false" />
         <AssociationConnector Association="EDMModel.FK__PointsLis__IdRou__66603565" ManuallyRouted="false" />
         <AssociationConnector Association="EDMModel.FK__RouteList__IdRou__628FA481" ManuallyRouted="false" />
+        <AssociationConnector Association="EDMModel.FK_RouteList_Dispatcher" />
       </Diagram>
     </edmx:Diagrams>
   </edmx:Designer>

+ 12 - 2
Kusach/Functions.cs

@@ -39,10 +39,20 @@ namespace Kusach
         // Валидация логина и пароля
         public static bool IsValidLogAndPass(string login, string password)
         {
-            if (login != "" && password != "")
-                return true;
+            if (login == "" || password == "")
+                return false;
             else
+                return true;
+        }
+        // Валидация логина и пароля
+        public static bool IsValidLogAndPassRegister(string login, string password)
+        {
+            if (login.Length < 5 || password.Length < 5)
+                return false;
+            if (login == password)
                 return false;
+            else
+                return true;
         }
         // Получение названия маршрута по его id
         public static string GetRouteName(int routeId)

+ 7 - 0
Kusach/Kusach.csproj

@@ -138,6 +138,9 @@
     <Compile Include="Windows\AddPointWindow.xaml.cs">
       <DependentUpon>AddPointWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Windows\AddRouteToDispatcherWindow.xaml.cs">
+      <DependentUpon>AddRouteToDispatcherWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Windows\AddRouteWindow.xaml.cs">
       <DependentUpon>AddRouteWindow.xaml</DependentUpon>
     </Compile>
@@ -209,6 +212,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Windows\AddRouteToDispatcherWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Windows\AddRouteWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 3 - 3
Kusach/Pages/RoutesListPage.xaml

@@ -28,7 +28,7 @@
             <Button
                 Name="CreateButton"
                 Width="120"
-                Content="Создать"
+                Content="Добавить"
                 Click="AddRouteButton_Click"/>
             <Button
                 Width="120"
@@ -52,12 +52,12 @@
             </DataGrid.ItemContainerStyle>
             <DataGrid.Columns>
                 <DataGridTextColumn 
-                    Binding="{Binding IdRoute}" 
+                    Binding="{Binding Routes.IdRoute}" 
                     Header="Номер"  
                     Width="70"
                     IsReadOnly="True"/>
                 <DataGridTextColumn 
-                    Binding="{Binding Name}" 
+                    Binding="{Binding Routes.Name}" 
                     Header="Название"
                     IsReadOnly="True"/>
             </DataGrid.Columns>

+ 30 - 8
Kusach/Pages/RoutesListPage.xaml.cs

@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -13,13 +14,13 @@ namespace Kusach.Pages
         public RoutesListPage()
         {
             InitializeComponent();
-            RoutesList.ItemsSource = cnt.db.Routes.ToList();
+            RoutesList.ItemsSource = cnt.db.RouteList.Where(item => item.IdDispatcher == profile.DispatcherId).ToList();
             if (profile.Permission != 0)
                 CreateButton.Visibility = Visibility.Collapsed;
         }
         private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
-            Windows.RouteEditWindow rew = new Windows.RouteEditWindow(((Routes)RoutesList.SelectedItem).IdRoute);
+            Windows.RouteEditWindow rew = new Windows.RouteEditWindow(((RouteList)RoutesList.SelectedItem).IdRoute);
                 rew.Show();
         }
 
@@ -37,19 +38,40 @@ namespace Kusach.Pages
         private void SearchTextChanged(object sender, TextChangedEventArgs e)
         {
             if (SearchBox.Text != "" && SearchBox.Text != "Поиск...")
-                RoutesList.ItemsSource = cnt.db.Routes.Where(item => (item.IdRoute + " " + item.Name).Contains(SearchBox.Text)).ToList();
+                RoutesList.ItemsSource = cnt.db.RouteList.Where(item => (item.Routes.IdRoute + " " + item.Routes.Name).Contains(SearchBox.Text) && item.IdDispatcher == profile.DispatcherId).ToList();
             else
-                cnt.db.Routes.ToList();
+                cnt.db.RouteList.Where(item => item.IdDispatcher == profile.DispatcherId).ToList();
         }
         #endregion
         private void AddRouteButton_Click(object sender, RoutedEventArgs e)
         {
-            AddRouteWindow arw = new AddRouteWindow();
-            arw.Show();
+            Windows.AddRouteToDispatcherWindow artdw = new Windows.AddRouteToDispatcherWindow();
+            artdw.ShowDialog();
+            int routeId = artdw.routeId;
+            if (routeId != -1)
+            {
+                try
+                {
+                    RouteList newAddRouteToDispatcher = new RouteList()
+                    {
+                        Id = cnt.db.RouteList.Select(p => p.Id).DefaultIfEmpty(0).Max() + 1,
+                        IdRoute = routeId,
+                        IdDispatcher = profile.DispatcherId
+                    };
+                    cnt.db.RouteList.Add(newAddRouteToDispatcher);
+                    cnt.db.SaveChanges();
+                    MessageBox.Show("Маршрут успешно добавлена");
+                }
+                catch (Exception exc)
+                {
+                    MessageBox.Show("Ошибка добавления записи" + exc);
+                }
+            }
+
         }
         private void UpdateRoutesButton_Click(object sender, RoutedEventArgs e)
         {
-            RoutesList.ItemsSource = cnt.db.Routes.ToList();
+            RoutesList.ItemsSource = cnt.db.RouteList.Where(item => item.IdDispatcher == profile.DispatcherId).ToList();
         }
     }
 }

+ 1 - 1
Kusach/RouteList.cs

@@ -18,7 +18,7 @@ namespace Kusach
         public int IdRoute { get; set; }
         public int IdDispatcher { get; set; }
     
-        public virtual Dispatcher Dispatcher { get; set; }
         public virtual Routes Routes { get; set; }
+        public virtual Dispatcher Dispatcher { get; set; }
     }
 }

+ 0 - 5
Kusach/Windows/AddDriverToRouteWindow.xaml

@@ -31,11 +31,6 @@
             </DataGrid.ItemContainerStyle>
             <DataGrid.Columns>
                 <DataGridTextColumn 
-                    Binding="{Binding IdDriver}" 
-                    Header="Номер"  
-                    Width="50" 
-                    IsReadOnly="True"/>
-                <DataGridTextColumn 
                     Binding="{Binding Transport.NameOfTransport}" 
                     Header="Транспортное средство" 
                     Width="200" 

+ 2 - 2
Kusach/Windows/AddDriverWindow.xaml

@@ -17,13 +17,13 @@
             HorizontalAlignment="Center"
             VerticalAlignment="Top">
             <Label 
-            Content="IdTransport" 
+            Content="Номерной знак" 
             HorizontalAlignment="Left" 
             VerticalAlignment="Top" 
             Height="30" 
             Width="190"/>
             <TextBox 
-            x:Name="IdTransportBox"
+            x:Name="NumberPlateBox"
             HorizontalAlignment="Left" 
             VerticalAlignment="Top" 
             Height="30" 

+ 4 - 2
Kusach/Windows/AddDriverWindow.xaml.cs

@@ -23,8 +23,10 @@ namespace Kusach
 
         private void AddDriverButton_Click(object sender, RoutedEventArgs e)
         {
-            if (IdTransportBox.Text == "" || NameBox.Text == "" || SurnameBox.Text == "" || PatronymicBox.Text == "")
+            if (NumberPlateBox.Text == "" || NameBox.Text == "" || SurnameBox.Text == "" || PatronymicBox.Text == "")
                 MessageBox.Show("Поля не могут быть пустыми.");
+           // if(cnt.db.Transport.Select(item => item.NumberPlate).Contains(NumberPlateBox.Text))
+           //     MessageBox.Show("Неверно введен номерной знак");
             else
             {
                 try
@@ -33,7 +35,7 @@ namespace Kusach
                     Drivers newDriver = new Drivers()
                     {
                         IdDriver = driverId,
-                        IdTransport = Convert.ToInt32(IdTransportBox.Text),
+                        IdTransport = Convert.ToInt32(cnt.db.Transport.Where(item => item.NumberPlate == NumberPlateBox.Text).Select(item => item.IdTransport).FirstOrDefault()),
                         Name = NameBox.Text,
                         Surname = SurnameBox.Text,
                         Patronymic = PatronymicBox.Text

+ 0 - 5
Kusach/Windows/AddPointToRouteWindow.xaml

@@ -31,11 +31,6 @@
             </DataGrid.ItemContainerStyle>
             <DataGrid.Columns>
                 <DataGridTextColumn 
-                    Binding="{Binding IdPoint}" 
-                    Header="Номер"  
-                    Width="50" 
-                    IsReadOnly="True"/>
-                <DataGridTextColumn 
                     Binding="{Binding Name}" 
                     Header="Название" 
                     Width="200" 

+ 69 - 0
Kusach/Windows/AddRouteToDispatcherWindow.xaml

@@ -0,0 +1,69 @@
+<Window x:Class="Kusach.Windows.AddRouteToDispatcherWindow"
+        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:Kusach.Windows"
+        mc:Ignorable="d"
+        Title="AddRouteToDispatcherWindow"
+        Height="300" 
+        Width="450"
+        WindowStyle="None"
+        WindowStartupLocation="CenterScreen">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="224*"/>
+            <RowDefinition Height="45*"/>
+        </Grid.RowDefinitions>
+        <DataGrid
+            Name="RoutesListDataGrid" 
+            AutoGenerateColumns="False" 
+            VerticalAlignment="Stretch" 
+            HorizontalAlignment="Stretch"
+            CanUserAddRows="False"
+            Grid.Row="0">
+            <DataGrid.ItemContainerStyle>
+                <Style TargetType="DataGridRow">
+                    <EventSetter 
+                        Event="MouseDoubleClick" 
+                        Handler="RouteDataGridRow_MouseDoubleClick"/>
+                </Style>
+            </DataGrid.ItemContainerStyle>
+            <DataGrid.Columns>
+                <DataGridTextColumn 
+                    Binding="{Binding IdRoute}" 
+                    Header="Номер"  
+                    Width="50" 
+                    IsReadOnly="True"/>
+                <DataGridTextColumn 
+                    Binding="{Binding Name}" 
+                    Header="Название" 
+                    IsReadOnly="True"/>
+            </DataGrid.Columns>
+        </DataGrid>
+        <StackPanel 
+            Grid.Row="1"
+            Orientation="Horizontal"
+            HorizontalAlignment="Center"
+            VerticalAlignment="Center">
+            <Button 
+            Content="Отмена"
+            Width="90"
+            Height="35"
+            HorizontalAlignment="Center"
+            Click="BackButton_Click"
+            Margin="0,0,10,0"/>
+            <Button 
+            Name="CreateButton"
+            Content="Создать"
+            Width="90"
+            Height="35"
+            HorizontalAlignment="Center"
+            Click="CreateButton_Click"/>
+        </StackPanel>
+        <Border 
+            Grid.RowSpan="2"
+            BorderBrush="Black" 
+            BorderThickness="2"/>
+    </Grid>
+</Window>

+ 44 - 0
Kusach/Windows/AddRouteToDispatcherWindow.xaml.cs

@@ -0,0 +1,44 @@
+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.Shapes;
+
+namespace Kusach.Windows
+{
+    /// <summary>
+    /// Логика взаимодействия для AddRouteToDispatcherWindow.xaml
+    /// </summary>
+    public partial class AddRouteToDispatcherWindow : Window
+    {
+        public int routeId = -1;
+        public AddRouteToDispatcherWindow()
+        {
+            InitializeComponent();
+            RoutesListDataGrid.ItemsSource = cnt.db.Routes.ToList();
+        }
+        private void RouteDataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
+        {
+            routeId = ((Routes)RoutesListDataGrid.SelectedItem).IdRoute;
+            this.Close();
+        }
+        private void CreateButton_Click(object sender, RoutedEventArgs e)
+        {
+            AddRouteWindow arw = new AddRouteWindow();
+            arw.Show();
+        }
+
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+    }
+}

+ 11 - 1
Kusach/Windows/AddRouteWindow.xaml.cs

@@ -31,13 +31,23 @@ namespace Kusach
             {
                 try
                 {
+                    int newRouteId = cnt.db.Routes.Select(p => p.IdRoute).DefaultIfEmpty(0).Max() + 1;
                     Routes newRoute = new Routes()
                     {
-                        IdRoute = cnt.db.Routes.Select(p => p.IdRoute).DefaultIfEmpty(0).Max() + 1,
+                        IdRoute = newRouteId,
                         Name = RouteNameBox.Text
                     };
                     cnt.db.Routes.Add(newRoute);
                     cnt.db.SaveChanges();
+
+                    RouteList newRouteList = new RouteList()
+                    {
+                        Id = cnt.db.RouteList.Select(p => p.Id).DefaultIfEmpty(0).Max() + 1,
+                        IdRoute = newRouteId,
+                        IdDispatcher = profile.DispatcherId
+                    };
+                    cnt.db.RouteList.Add(newRouteList);
+                    cnt.db.SaveChanges();
                     this.Close();
                 }
                 catch

+ 2 - 2
Kusach/Windows/DriverEditWindow.xaml

@@ -17,13 +17,13 @@
             HorizontalAlignment="Center"
             VerticalAlignment="Top">
             <Label 
-            Content="IdTransport" 
+            Content="Номерной знак" 
             HorizontalAlignment="Left" 
             VerticalAlignment="Top" 
             Height="30" 
             Width="190"/>
             <TextBox 
-            x:Name="IdTransportBox"
+            x:Name="NumberPlate"
             HorizontalAlignment="Left" 
             VerticalAlignment="Top" 
             Height="30" 

+ 2 - 2
Kusach/Windows/DriverEditWindow.xaml.cs

@@ -13,7 +13,7 @@ namespace Kusach.Windows
         {
             InitializeComponent();
             driverId = id;
-            IdTransportBox.Text = cnt.db.Drivers.Where(item => item.IdDriver == driverId).Select(item => item.IdTransport).FirstOrDefault().ToString();
+            NumberPlate.Text = cnt.db.Drivers.Where(item => item.IdDriver == driverId).Select(item => item.Transport.NumberPlate).FirstOrDefault().ToString();
             SurnameBox.Text = cnt.db.Drivers.Where(item => item.IdDriver == driverId).Select(item => item.Surname).FirstOrDefault();
             NameBox.Text = cnt.db.Drivers.Where(item => item.IdDriver == driverId).Select(item => item.Name).FirstOrDefault();
             PatronymicBox.Text = cnt.db.Drivers.Where(item => item.IdDriver == driverId).Select(item => item.Patronymic).FirstOrDefault();
@@ -26,7 +26,7 @@ namespace Kusach.Windows
         {
             Drivers driver = cnt.db.Drivers.Where(item => item.IdDriver == driverId).FirstOrDefault();
             driver.Name = NameBox.Text;
-            driver.IdTransport = Convert.ToInt32(IdTransportBox.Text);
+            driver.IdTransport = Convert.ToInt32(cnt.db.Transport.Where(item => item.NumberPlate == NumberPlate.Text).Select(item => item.IdTransport).FirstOrDefault());
             driver.Surname = SurnameBox.Text;
             driver.Name = NameBox.Text;
             driver.Patronymic = PatronymicBox.Text;

+ 3 - 1
Kusach/Windows/RegWindow.xaml.cs

@@ -18,8 +18,10 @@ namespace Kusach
         {
             try
             {
-                if (logbox.Text == "" || passbox.Text == "")
+                if (!Functions.IsValidLogAndPass(logbox.Text, passbox.Text))
                     MessageBox.Show("Поля не могут быть пустыми.");
+                if (!Functions.IsValidLogAndPassRegister(logbox.Text, passbox.Text))
+                    MessageBox.Show("Поля «Логин» и «Пароль» должны содержать не менее 5 символов. Поля «Логин» и «Пароль» не должны быть равны");
                 else if (Functions.IsLoginAlreadyTaken(logbox.Text))
                     MessageBox.Show("Данный логин уже занят");
                 else if (!Functions.IsValidPhoneNumber(PhoneBox.Text))

+ 11 - 2
Kusach/Windows/RouteEditWindow.xaml

@@ -15,12 +15,13 @@
             <RowDefinition Height="354*"/>
         </Grid.RowDefinitions>
         <Button
-            Content="Сохранить&#xD;&#xA; и выйти" 
+            Content="Выйти" 
             HorizontalAlignment="Left" 
             VerticalAlignment="Top" 
             Margin="10,10,0,0" 
             Width="90" 
-            Height="50" 
+            Height="50"
+            FontSize="16"
             Click="ExitButton_Click"/>
         <TextBox
             Name="RouteNameBox"
@@ -77,6 +78,14 @@
                             Orientation="Horizontal"
                             Grid.Row="1">
                             <Button
+                                Name="SaveButton"
+                                Content="Сохранить"
+                                Width="90"
+                                Height="30"
+                                Margin="0,0,10,0"
+                                Click="SaveButton_Click">
+                            </Button>
+                            <Button
                                 Content="Обновить"
                                 Width="90"
                                 Height="30"

+ 6 - 1
Kusach/Windows/RouteEditWindow.xaml.cs

@@ -18,6 +18,7 @@ namespace Kusach.Windows
             if (profile.Permission != 0)
             {
                 RouteNameBox.IsEnabled = false;
+                SaveButton.Visibility = Visibility.Collapsed;
                 AddButton.Visibility = Visibility.Collapsed;
                 RemoveButton.Visibility = Visibility.Collapsed;
                 AddButtonDrivers.Visibility = Visibility.Collapsed;
@@ -63,10 +64,14 @@ namespace Kusach.Windows
 
         private void ExitButton_Click(object sender, RoutedEventArgs e)
         {
+            this.Close();
+        }
+
+        private void SaveButton_Click(object sender, RoutedEventArgs e)
+        {
             Routes route = cnt.db.Routes.Where(item => item.IdRoute == routeId).FirstOrDefault();
             route.Name = RouteNameBox.Text;
             cnt.db.SaveChanges();
-            this.Close();
         }
 
         private void AddFromListPoint_Click(object sender, RoutedEventArgs e)

+ 16 - 6
UnitTests/UnitTest1.cs

@@ -35,13 +35,14 @@ namespace UnitTests
         [TestMethod]
         public void LoginTest()
         {
-            string login = "qq";
-            string password = "qq";
+            string login = "kovalev30";
+            string password = "kovalev333";
             Assert.IsTrue(Functions.LoginCheck(login, password));
         }
         [TestMethod]
         public void IsValidLoginAndPassword()
         {
+            Assert.IsTrue(Functions.IsValidLogAndPass("login3", "password33"));
             Assert.IsTrue(Functions.IsValidLogAndPass("qq", "ww"));
             Assert.IsTrue(Functions.IsValidLogAndPass("laq", "wwadsw"));
             Assert.IsFalse(Functions.IsValidLogAndPass("", ""));
@@ -49,9 +50,18 @@ namespace UnitTests
             Assert.IsFalse(Functions.IsValidLogAndPass("SimpleLogin", ""));
         }
         [TestMethod]
+        public void IsValidLoginAndPasswordRegister()
+        {
+            Assert.IsTrue(Functions.IsValidLogAndPassRegister("login3", "password33"));
+            Assert.IsFalse(Functions.IsValidLogAndPassRegister("login3", "login3"));
+            Assert.IsFalse(Functions.IsValidLogAndPassRegister("qq", "ww"));
+            Assert.IsFalse(Functions.IsValidLogAndPassRegister("qqvxfc", "ww"));
+            
+        }
+        [TestMethod]
         public void IsLoginAlreadyTaken()
         {
-            Assert.IsTrue(Functions.IsLoginAlreadyTaken("qq"));
+            Assert.IsTrue(Functions.IsLoginAlreadyTaken("kovalev30"));
             Assert.IsFalse(Functions.IsLoginAlreadyTaken("user23"));
             Assert.IsFalse(Functions.IsLoginAlreadyTaken("F"));
             Assert.IsFalse(Functions.IsLoginAlreadyTaken(""));
@@ -67,7 +77,7 @@ namespace UnitTests
         public void GetNumberPlateUsingId()
         {
             int transportId = 1;
-            string expected = "AA333AA78";
+            string expected = "а333аа78";
             Assert.AreEqual(Functions.GetNumberPlate(transportId), expected);
         }
         [TestMethod]
@@ -124,7 +134,7 @@ namespace UnitTests
         [TestMethod]
         public void IsPhoneNumberAlreadyTaken()
         {
-            Assert.IsTrue(Functions.IsPhoneNumberAlreadyTaken("7776006060"));
+            Assert.IsTrue(Functions.IsPhoneNumberAlreadyTaken("9996963350"));
             Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006061"));
             Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006062"));
             Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006063"));
@@ -134,7 +144,7 @@ namespace UnitTests
         [TestMethod]
         public void IsEmailAlreadyTaken()
         {
-            Assert.IsTrue(Functions.IsEmailAlreadyTaken("filaks@gmail.com"));
+            Assert.IsTrue(Functions.IsEmailAlreadyTaken("rud.kovalev@gmail.com"));
             Assert.IsFalse(Functions.IsEmailAlreadyTaken("filaks@mail.ru"));
             Assert.IsFalse(Functions.IsEmailAlreadyTaken("cute@gmail.com"));
             Assert.IsFalse(Functions.IsEmailAlreadyTaken("user@gmail.com"));