Артем Гавриленко 3 éve
szülő
commit
8fd0543f1c

+ 0 - 53
Kusach/AddDriverWindow.xaml.cs

@@ -1,53 +0,0 @@
-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
-{
-    /// <summary>
-    /// Логика взаимодействия для AddDriverWindow.xaml
-    /// </summary>
-    public partial class AddDriverWindow : Window
-    {
-        public AddDriverWindow()
-        {
-            InitializeComponent();
-        }
-
-        private void BackButton_Click(object sender, RoutedEventArgs e)
-        {
-            this.Close();
-        }
-
-        private void AddDriverButton_Click(object sender, RoutedEventArgs e)
-        {
-            if (IdTransportBox.Text == "" || NameBox.Text == "" || SurnameBox.Text == "" || PatronymicBox.Text == "")
-                MessageBox.Show("Поля не могут быть пустыми.");
-            else
-            {
-                Drivers newDriver = new Drivers()
-                {
-                    IdDriver = cnt.db.Drivers.Select(p => p.IdDriver).DefaultIfEmpty(0).Max() + 1,
-                    IdTransport = Convert.ToInt32(IdTransportBox.Text),
-                    Name = NameBox.Text,
-                    Surname = SurnameBox.Text,
-                    Patronymic = PatronymicBox.Text
-                };
-                cnt.db.Drivers.Add(newDriver);
-                cnt.db.SaveChanges();
-                MessageBox.Show("Водитель успешно создан.");
-                this.Close();
-            }
-        }
-    }
-}

+ 16 - 2
Kusach/Kusach.csproj

@@ -67,9 +67,12 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
-    <Compile Include="AddDriverWindow.xaml.cs">
+    <Compile Include="Windows\AddDriverWindow.xaml.cs">
       <DependentUpon>AddDriverWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Windows\AddDriverToRouteWindow.xaml.cs">
+      <DependentUpon>AddDriverToRouteWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Windows\AddPointToRouteWindow.xaml.cs">
       <DependentUpon>AddPointToRouteWindow.xaml</DependentUpon>
     </Compile>
@@ -147,10 +150,17 @@
     <Compile Include="TestPGPage.xaml.cs">
       <DependentUpon>TestPGPage.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Windows\PointEditWindow.xaml.cs">
+      <DependentUpon>PointEditWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Windows\RouteEditWindow.xaml.cs">
       <DependentUpon>RouteEditWindow.xaml</DependentUpon>
     </Compile>
-    <Page Include="AddDriverWindow.xaml">
+    <Page Include="Windows\AddDriverWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Windows\AddDriverToRouteWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
@@ -202,6 +212,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Windows\PointEditWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Windows\RouteEditWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 68 - 0
Kusach/Windows/AddDriverToRouteWindow.xaml

@@ -0,0 +1,68 @@
+<Window x:Class="Kusach.Windows.AddDriverToRouteWindow"
+        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="AddDriverToRouteWindow" 
+        Height="300" 
+        Width="450"
+        WindowStyle="None"
+        WindowStartupLocation="CenterScreen">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="224*"/>
+            <RowDefinition Height="45*"/>
+        </Grid.RowDefinitions>
+        <DataGrid
+            Name="DriversListDataGrid" 
+            AutoGenerateColumns="False" 
+            VerticalAlignment="Stretch" 
+            HorizontalAlignment="Stretch"
+            CanUserAddRows="False"
+            Grid.Row="0">
+            <DataGrid.ItemContainerStyle>
+                <Style TargetType="DataGridRow">
+                    <EventSetter 
+                        Event="MouseDoubleClick" 
+                        Handler="PointsDataGridRow_MouseDoubleClick"/>
+                </Style>
+            </DataGrid.ItemContainerStyle>
+            <DataGrid.Columns>
+                <DataGridTextColumn 
+                    Binding="{Binding IdDriver}" 
+                    Header="Номер"  
+                    Width="50" 
+                    IsReadOnly="True"/>
+                <DataGridTextColumn 
+                    Binding="{Binding Transport.NameOfTransport}" 
+                    Header="Транспортное средство" 
+                    Width="200" 
+                    IsReadOnly="True"/>
+                <DataGridTextColumn 
+                    Binding="{Binding Surname}" 
+                    Header="Фамилия" 
+                    Width="200"
+                    IsReadOnly="True"/>
+                <DataGridTextColumn 
+                    Binding="{Binding Name}" 
+                    Header="Имя" 
+                    Width="200"
+                    IsReadOnly="True"/>
+                <DataGridTextColumn 
+                    Binding="{Binding Patronymic}" 
+                    Header="Отчество" 
+                    Width="200"
+                    IsReadOnly="True"/>
+            </DataGrid.Columns>
+        </DataGrid>
+        <Button 
+            Grid.Row="1"
+            Content="Отмена"
+            Width="90"
+            Height="35"
+            HorizontalAlignment="Center"
+            Click="BackButton_Click"/>
+    </Grid>
+</Window>

+ 39 - 0
Kusach/Windows/AddDriverToRouteWindow.xaml.cs

@@ -0,0 +1,39 @@
+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>
+    /// Логика взаимодействия для AddDriverToRouteWindow.xaml
+    /// </summary>
+    public partial class AddDriverToRouteWindow : Window
+    {
+        public int driverId = -1;
+        public AddDriverToRouteWindow(int id)
+        {
+            InitializeComponent();
+            DriversListDataGrid.ItemsSource = cnt.db.Drivers.ToList();
+        }
+        private void PointsDataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
+        {
+            driverId = ((Drivers)DriversListDataGrid.SelectedItem).IdDriver;
+            this.Close();
+        }
+
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+    }
+}

+ 5 - 1
Kusach/AddDriverWindow.xaml

@@ -80,6 +80,10 @@
             VerticalAlignment="Top" 
             Height="40" 
             Width="120" 
-            Click="BackButton_Click"/>
+            Click="BackButton_Click"
+            IsDefault="True"/>
+        <Border 
+            BorderBrush="Black" 
+            BorderThickness="2"/>
     </Grid>
 </Window>

+ 76 - 0
Kusach/Windows/AddDriverWindow.xaml.cs

@@ -0,0 +1,76 @@
+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
+{
+    /// <summary>
+    /// Логика взаимодействия для AddDriverWindow.xaml
+    /// </summary>
+    public partial class AddDriverWindow : Window
+    {
+        int routeId,driverId;
+        public AddDriverWindow(int id = -1)
+        {
+            InitializeComponent();
+            routeId = id;
+        }
+
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+
+        private void AddDriverButton_Click(object sender, RoutedEventArgs e)
+        {
+            if (IdTransportBox.Text == "" || NameBox.Text == "" || SurnameBox.Text == "" || PatronymicBox.Text == "")
+                MessageBox.Show("Поля не могут быть пустыми.");
+            else
+            {
+                try
+                {
+                    driverId = cnt.db.Drivers.Select(p => p.IdDriver).DefaultIfEmpty(0).Max() + 1;
+                    Drivers newDriver = new Drivers()
+                    {
+                        IdDriver = driverId,
+                        IdTransport = Convert.ToInt32(IdTransportBox.Text),
+                        Name = NameBox.Text,
+                        Surname = SurnameBox.Text,
+                        Patronymic = PatronymicBox.Text
+                    };
+                    cnt.db.Drivers.Add(newDriver);
+                    cnt.db.SaveChanges();
+
+                    if (routeId != -1)
+                    {
+                        DriversList newDriverRoute = new DriversList()
+                        {
+                            Id = cnt.db.DriversList.Select(p => p.Id).DefaultIfEmpty(0).Max() + 1,
+                            IdDriver = driverId,
+                            IdRoute = routeId
+                        };
+                        cnt.db.DriversList.Add(newDriverRoute);
+                    }
+                    cnt.db.SaveChanges();
+                    MessageBox.Show("Водитель успешно создан.");
+                    this.Close();
+                }
+                catch
+                {
+                    MessageBox.Show("Ошибка создания водителя.");
+                    this.Close();
+                }
+            }
+        }
+    }
+}

+ 1 - 1
Kusach/Windows/AddPointToRouteWindow.xaml.cs

@@ -19,7 +19,7 @@ namespace Kusach.Windows
     /// </summary>
     public partial class AddPointToRouteWindow : Window
     {
-        public AddPointToRouteWindow(int id)
+        public AddPointToRouteWindow()
         {
             InitializeComponent();
             PointsListDataGrid.ItemsSource = cnt.db.Points.ToList();

+ 1 - 1
Kusach/Windows/AddRouteWindow.xaml

@@ -12,7 +12,7 @@
         WindowStyle="None"
         WindowStartupLocation="CenterScreen"
         Loaded="OnLoad">
-    <Grid Background="#FFF7F7F7">
+    <Grid>
         <StackPanel
             Margin="0,10,0,0"
             HorizontalAlignment="Center"

+ 65 - 0
Kusach/Windows/PointEditWindow.xaml

@@ -0,0 +1,65 @@
+<Window x:Class="Kusach.Windows.PointEditWindow"
+        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="PointEditWindow" 
+        Height="210" 
+        Width="300"
+        ResizeMode="NoResize"
+        WindowStyle="None"
+        WindowStartupLocation="CenterScreen">
+    <Grid>
+        <StackPanel
+            Margin="0,10,0,0"
+            HorizontalAlignment="Center"
+            VerticalAlignment="Top">
+            <Label 
+            Content="Название" 
+            HorizontalAlignment="Left" 
+            VerticalAlignment="Top" 
+            Height="30" 
+            Width="190"/>
+            <TextBox 
+            x:Name="NameBox"
+            HorizontalAlignment="Left" 
+            VerticalAlignment="Top" 
+            Height="30" 
+            Width="190"/>
+            <Label 
+            Content="Локация" 
+            HorizontalAlignment="Left" 
+            VerticalAlignment="Top" 
+            Height="30" 
+            Width="190"/>
+            <TextBox 
+            x:Name="LocationBox"
+            HorizontalAlignment="Left" 
+            VerticalAlignment="Top" 
+            Height="30" 
+            Width="190"/>
+        </StackPanel>
+        <Button 
+            Content="Сохранить" 
+            HorizontalAlignment="Left"
+            Margin="170,160,0,0" 
+            VerticalAlignment="Top" 
+            Height="40" 
+            Width="120" 
+            Click="SavePointButton_Click"/>
+        <Button 
+            Content="Отмена"
+            HorizontalAlignment="Left" 
+            Margin="10,160,0,0" 
+            VerticalAlignment="Top" 
+            Height="40" 
+            Width="120" 
+            Click="BackButton_Click"
+            IsDefault="True"/>
+        <Border 
+            BorderBrush="Black" 
+            BorderThickness="2"/>
+    </Grid>
+</Window>

+ 43 - 0
Kusach/Windows/PointEditWindow.xaml.cs

@@ -0,0 +1,43 @@
+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>
+    /// Логика взаимодействия для PointEditWindow.xaml
+    /// </summary>
+    public partial class PointEditWindow : Window
+    {
+        int pointId;
+        public PointEditWindow(int id)
+        {
+            InitializeComponent();
+            pointId = id;
+            NameBox.Text = cnt.db.Points.Where(item => item.IdPoint == pointId).Select(item => item.Name).FirstOrDefault();
+            LocationBox.Text = cnt.db.Points.Where(item => item.IdPoint == pointId).Select(item => item.location).FirstOrDefault();
+        }
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+        private void SavePointButton_Click(object sender, RoutedEventArgs e)
+        {
+            Points point = cnt.db.Points.Where(item => item.IdPoint == pointId).FirstOrDefault();
+            point.Name = NameBox.Text;
+            point.location = LocationBox.Text;
+            cnt.db.SaveChanges();
+            this.Close();
+        }
+    }
+}

+ 9 - 6
Kusach/Windows/RouteEditWindow.xaml

@@ -99,7 +99,7 @@
                                 Width="90"
                                 Height="30"
                                 Margin="0,0,10,0"
-                                Click="UpdatePoints_Click">
+                                Click="Update_Click">
                             </Button>
                             <Button
                                 Content="Создать"
@@ -163,7 +163,7 @@
                                     IsReadOnly="True"/>
                                 <DataGridTextColumn 
                                     Binding="{Binding Drivers.IdTransport}" 
-                                    Header="Name" 
+                                    Header="Транспортное средство" 
                                     IsReadOnly="True"/>
                                 <DataGridTextColumn 
                                     Binding="{Binding Drivers.Surname}" 
@@ -175,7 +175,7 @@
                                     IsReadOnly="True"/>
                                 <DataGridTextColumn 
                                     Binding="{Binding Drivers.Patronymic}" 
-                                    Header="Patronymic" 
+                                    Header="Patronymic"
                                     IsReadOnly="True"/>
                             </DataGrid.Columns>
                         </DataGrid>
@@ -186,19 +186,22 @@
                                 Content="Обновить"
                                 Width="90"
                                 Height="30"
-                                Margin="0,0,10,0">
+                                Margin="0,0,10,0"
+                                Click="Update_Click">
                             </Button>
                             <Button
                                 Content="Создать"
                                 Width="90"
                                 Height="30"
-                                Margin="0,0,10,0">
+                                Margin="0,0,10,0"
+                                Click="AddDriver_Click">
                             </Button>
                             <Button
                                 Content="Добавить"
                                 Width="90"
                                 Height="30"
-                                Margin="0,0,10,0">
+                                Margin="0,0,10,0"
+                                Click="AddFromListDriver_Click">
                             </Button>
                             <Button
                                 Visibility="Hidden"

+ 46 - 9
Kusach/Windows/RouteEditWindow.xaml.cs

@@ -25,12 +25,12 @@ namespace Kusach.Windows
             InitializeComponent();
             routeId = id;
             RouteNameBox.Text = cnt.db.Routes.Where(item => item.IdRoute == routeId).Select(item => item.Name).FirstOrDefault();
-            PointsListDataGrid.ItemsSource = cnt.db.PointsList.Where(item => item.IdRoute == routeId).ToList();
-            DriversListDataGrid.ItemsSource = cnt.db.DriversList.Where(item => item.IdRoute == routeId).ToList();
+            Update();
         }
         private void PointsDataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
-            MessageBox.Show("cell: " + ((PointsList)PointsListDataGrid.SelectedItem).IdPoint);
+            PointEditWindow pew = new PointEditWindow(((PointsList)PointsListDataGrid.SelectedItem).IdPoint);
+            pew.ShowDialog();
         }
         private void DriversDataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
@@ -41,13 +41,18 @@ namespace Kusach.Windows
             AddPointWindow apw = new AddPointWindow(routeId);
             apw.ShowDialog();
         }
+        private void AddDriver_Click(object sender, RoutedEventArgs e)
+        {
+            AddDriverWindow adw = new AddDriverWindow(routeId);
+            adw.ShowDialog();
+        }
         private void RemovePoint_Click(object sender, RoutedEventArgs e)
         {
             try
             {
                 cnt.db.PointsList.Remove(cnt.db.PointsList.Where(item => item.IdRoute == routeId && item.IdPoint == ((PointsList)PointsListDataGrid.SelectedItem).IdPoint).FirstOrDefault());
                 cnt.db.SaveChanges();
-                update();
+                Update();
             }
             catch
             {
@@ -57,12 +62,15 @@ namespace Kusach.Windows
 
         private void ExitButton_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)
         {
-            AddPointToRouteWindow aptrw = new AddPointToRouteWindow(routeId);
+            AddPointToRouteWindow aptrw = new AddPointToRouteWindow();
             aptrw.ShowDialog();
             int pointId = aptrw.pointId;
             if (pointId != -1)
@@ -77,7 +85,7 @@ namespace Kusach.Windows
                     };
                     cnt.db.PointsList.Add(newAddPointToRoute);
                     cnt.db.SaveChanges();
-                    update();
+                    Update();
                     MessageBox.Show("Точка успешно добавлена");
                 }
                 catch
@@ -86,13 +94,42 @@ namespace Kusach.Windows
                 }
             }
         }
-        void update()
+
+        private void AddFromListDriver_Click(object sender, RoutedEventArgs e)
+        {
+            AddDriverToRouteWindow adtrw = new AddDriverToRouteWindow(routeId);
+            adtrw.ShowDialog();
+            int driverId = adtrw.driverId;
+            if (driverId != -1)
+            {
+                try
+                {
+                    DriversList newAddDriverToRoute = new DriversList()
+                    {
+                        Id = cnt.db.DriversList.Select(p => p.Id).DefaultIfEmpty(0).Max() + 1,
+                        IdDriver = driverId,
+                        IdRoute = routeId
+                    };
+                    cnt.db.DriversList.Add(newAddDriverToRoute);
+                    cnt.db.SaveChanges();
+                    Update();
+                    MessageBox.Show("Водитель успешно добавлен");
+                }
+                catch
+                {
+                    MessageBox.Show("Ошибка добавления записи");
+                }
+            }
+        }
+
+        void Update()
         {
             PointsListDataGrid.ItemsSource = cnt.db.PointsList.Where(item => item.IdRoute == routeId).ToList();
+            DriversListDataGrid.ItemsSource = cnt.db.DriversList.Where(item => item.IdRoute == routeId).ToList();
         }
-        private void UpdatePoints_Click(object sender, RoutedEventArgs e)
+        private void Update_Click(object sender, RoutedEventArgs e)
         {
-            update();
+            Update();
         }
     }
 }