Imagara 2 年之前
父節點
當前提交
74afa3f9ec

+ 0 - 4
Kusach/Functions.cs

@@ -1,10 +1,6 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using System.Windows;
 
 namespace Kusach
 {

+ 1 - 7
Kusach/MainWindow.xaml.cs

@@ -2,23 +2,17 @@
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для MainWindow.xaml
-    /// </summary>
     public partial class MainWindow : Window
     {
         public MainWindow()
         {
             InitializeComponent();
             if (profile.Permission != 0)
-            {
                 DispatchersButton.Visibility = Visibility.Collapsed;
-            }
         }
         private void BackButton_Click(object sender, RoutedEventArgs e)
         {
-            LogWindow lw = new LogWindow();
-            lw.Show();
+            new LogWindow().Show();
             this.Close();
         }
         private void OnLoad(object sender, RoutedEventArgs e)

+ 1 - 14
Kusach/Pages/DispatcherListPage.xaml.cs

@@ -1,23 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
 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 Kusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для DispatcherListPage.xaml
-    /// </summary>
     public partial class DispatcherListPage : Page
     {
         public DispatcherListPage()

+ 2 - 9
Kusach/Pages/DriversListPage.xaml.cs

@@ -5,9 +5,6 @@ using System.Windows.Input;
 
 namespace Kusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для DriversListPage.xaml
-    /// </summary>
     public partial class DriversListPage : Page
     {
         public DriversListPage()
@@ -20,10 +17,7 @@ namespace Kusach.Pages
         private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
             if (profile.Permission == 0)
-            {
-                Windows.DriverEditWindow dew = new Windows.DriverEditWindow(((Drivers)DriversList.SelectedItem).IdDriver);
-                dew.Show();
-            }
+                new Windows.DriverEditWindow(((Drivers)DriversList.SelectedItem).IdDriver).Show();
         }
 
         #region Поиск
@@ -47,8 +41,7 @@ namespace Kusach.Pages
         #endregion
         private void AddDriverButton_Click(object sender, RoutedEventArgs e)
         {
-            AddDriverWindow adw = new AddDriverWindow();
-            adw.Show();
+            new AddDriverWindow().Show();
         }
 
         private void UpdateDriversButton_Click(object sender, RoutedEventArgs e)

+ 2 - 18
Kusach/Pages/PointsListPage.xaml.cs

@@ -1,23 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
 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 Kusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для PointsListPage.xaml
-    /// </summary>
     public partial class PointsListPage : Page
     {
         public PointsListPage()
@@ -30,10 +17,7 @@ namespace Kusach.Pages
         private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
             if (profile.Permission == 0)
-            {
-                Windows.PointEditWindow dew = new Windows.PointEditWindow(((Points)PointsList.SelectedItem).IdPoint);
-                dew.Show();
-            }
+                new Windows.PointEditWindow(((Points)PointsList.SelectedItem).IdPoint).Show();
         }
 
         #region Поиск

+ 8 - 12
Kusach/Pages/ProfilePage.xaml.cs

@@ -7,22 +7,19 @@ using System.Windows.Media.Imaging;
 
 namespace Kusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для ProfilePage.xaml
-    /// </summary>
     public partial class ProfilePage : Page
     {
+        Dispatcher dispatcher;
         public ProfilePage()
         {
             InitializeComponent();
-            if(cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.ProfileImgSource).FirstOrDefault() != null)
-            ProfileImg.Source = new BitmapImage(new Uri(cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.ProfileImgSource).FirstOrDefault()));
-            NameSurnameBox.Content = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.Name + " " + item.Surname).FirstOrDefault();
-            DateTime Birthday = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.Birthday).FirstOrDefault();
-            BirthdayBox.Content = Birthday.ToLongDateString();
-            string phone = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.PhoneNumber).FirstOrDefault();
-            PhoneNumBox.Content = "+7(" + phone.Substring(0, 3) + ")" + phone.Substring(3, 3) + "-" + phone.Substring(6, 2) + "-" + phone.Substring(8, 2);
-            EmailBox.Content = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.Email).FirstOrDefault();
+            dispatcher = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).FirstOrDefault();
+            if (cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.ProfileImgSource).FirstOrDefault() != null)
+                ProfileImg.Source = new BitmapImage(new Uri(dispatcher.ProfileImgSource));
+            NameSurnameBox.Content = dispatcher.Name + " " + dispatcher.Surname;
+            BirthdayBox.Content = dispatcher.Birthday.ToLongDateString();
+            PhoneNumBox.Content = "+7(" + dispatcher.PhoneNumber.Substring(0, 3) + ")" + dispatcher.PhoneNumber.Substring(3, 3) + "-" + dispatcher.PhoneNumber.Substring(6, 2) + "-" + dispatcher.PhoneNumber.Substring(8, 2);
+            EmailBox.Content = dispatcher.Email;
         }
         private void EditImageButton_Click(object sender, RoutedEventArgs e)
         {
@@ -34,7 +31,6 @@ namespace Kusach.Pages
             {
                 string filename = ofd.FileName;
                 ProfileImg.Source = new BitmapImage(new Uri(filename));
-                Dispatcher dispatcher = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).FirstOrDefault();
                 dispatcher.ProfileImgSource = filename;
                 cnt.db.SaveChanges();
             }

+ 1 - 5
Kusach/Pages/RoutesListPage.xaml.cs

@@ -6,9 +6,6 @@ using System.Windows.Input;
 
 namespace Kusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для RoutesListPage.xaml
-    /// </summary>
     public partial class RoutesListPage : Page
     {
         public RoutesListPage()
@@ -20,8 +17,7 @@ namespace Kusach.Pages
         }
         private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
-            Windows.RouteEditWindow rew = new Windows.RouteEditWindow(((RouteList)RoutesList.SelectedItem).IdRoute);
-                rew.Show();
+            new Windows.RouteEditWindow(((RouteList)RoutesList.SelectedItem).IdRoute).Show();
         }
 
         #region Поиск

+ 2 - 9
Kusach/Pages/TransportListPage.xaml.cs

@@ -5,9 +5,6 @@ using System.Windows.Input;
 
 namespace Kusach.Pages
 {
-    /// <summary>
-    /// Логика взаимодействия для TransportListPage.xaml
-    /// </summary>
     public partial class TransportListPage : Page
     {
         public TransportListPage()
@@ -20,10 +17,7 @@ namespace Kusach.Pages
         private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
             if (profile.Permission == 0)
-            {
-                Windows.TransportEditWindow tew = new Windows.TransportEditWindow(((Transport)TransportList.SelectedItem).IdTransport);
-                tew.Show();
-            }
+                new Windows.TransportEditWindow(((Transport)TransportList.SelectedItem).IdTransport).Show();
         }
 
             #region Поиск
@@ -47,8 +41,7 @@ namespace Kusach.Pages
         #endregion
         private void AddTransportButton_Click(object sender, RoutedEventArgs e)
         {
-            AddTransportWindow atw = new AddTransportWindow();
-            atw.Show();
+            new AddTransportWindow().Show();
         }
         private void UpdateTransportButton_Click(object sender, RoutedEventArgs e)
         {

+ 1 - 5
Kusach/Windows/AddDriverToRouteWindow.xaml.cs

@@ -4,9 +4,6 @@ using System.Windows.Input;
 
 namespace Kusach.Windows
 {
-    /// <summary>
-    /// Логика взаимодействия для AddDriverToRouteWindow.xaml
-    /// </summary>
     public partial class AddDriverToRouteWindow : Window
     {
         public int driverId = -1; int routeId;
@@ -28,8 +25,7 @@ namespace Kusach.Windows
         }
         private void CreateButton_Click(object sender, RoutedEventArgs e)
         {
-            AddDriverWindow adw = new AddDriverWindow(routeId);
-            adw.ShowDialog();
+            new AddDriverWindow(routeId).ShowDialog();
             this.Close();
         }
     }

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

@@ -4,9 +4,6 @@ using System.Windows;
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для AddDriverWindow.xaml
-    /// </summary>
     public partial class AddDriverWindow : Window
     {
         int routeId,driverId;

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

@@ -4,9 +4,6 @@ using System.Windows.Input;
 
 namespace Kusach.Windows
 {
-    /// <summary>
-    /// Логика взаимодействия для AddPointToRouteWindow.xaml
-    /// </summary>
     public partial class AddPointToRouteWindow : Window
     {
         int routeId;
@@ -24,8 +21,7 @@ namespace Kusach.Windows
         }
         private void CreateButton_Click(object sender, RoutedEventArgs e)
         {
-            AddPointWindow apw = new AddPointWindow(routeId);
-            apw.ShowDialog();
+            new AddPointWindow(routeId).ShowDialog();
             this.Close();
         }
 

+ 0 - 3
Kusach/Windows/AddPointWindow.xaml.cs

@@ -3,9 +3,6 @@ using System.Windows;
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для AddPointWindow.xaml
-    /// </summary>
     public partial class AddPointWindow : Window
     {
         int routeId, pointId;

+ 2 - 16
Kusach/Windows/AddRouteToDispatcherWindow.xaml.cs

@@ -1,22 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
 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;
@@ -32,8 +19,7 @@ namespace Kusach.Windows
         }
         private void CreateButton_Click(object sender, RoutedEventArgs e)
         {
-            AddRouteWindow arw = new AddRouteWindow();
-            arw.Show();
+            new AddRouteWindow().Show();
         }
 
         private void BackButton_Click(object sender, RoutedEventArgs e)

+ 0 - 3
Kusach/Windows/AddRouteWindow.xaml.cs

@@ -3,9 +3,6 @@ using System.Windows;
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для AddRouteWindow.xaml
-    /// </summary>
     public partial class AddRouteWindow : Window
     {
         public AddRouteWindow()

+ 0 - 3
Kusach/Windows/AddTransportWindow.xaml.cs

@@ -3,9 +3,6 @@ using System.Windows;
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для AddTransportWindow.xaml
-    /// </summary>
     public partial class AddTransportWindow : Window
     {
         public AddTransportWindow()

+ 4 - 18
Kusach/Windows/DispatcherEditWindow.xaml.cs

@@ -1,30 +1,17 @@
 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>
-    /// Логика взаимодействия для DispatcherEditWindow.xaml
-    /// </summary>
     public partial class DispatcherEditWindow : Window
     {
-        int dispatcherId;
+        Dispatcher dispatcher;
         public DispatcherEditWindow(int id)
         {
             InitializeComponent();
-            dispatcherId = id;
-            PermissionBox.Text = cnt.db.Dispatcher.Where(item => item.IdDispatcher == id).Select(item => item.Permission).FirstOrDefault().ToString();
+            dispatcher = cnt.db.Dispatcher.Where(item => item.IdDispatcher == id).FirstOrDefault();
+            PermissionBox.Text = dispatcher.Permission.ToString();
         }
         private void BackButton_Click(object sender, RoutedEventArgs e)
         {
@@ -34,10 +21,9 @@ namespace Kusach.Windows
         {
             if (Functions.IsOnlyDigits(PermissionBox.Text))
             {
-                Dispatcher dispatcher = cnt.db.Dispatcher.Where(item => item.IdDispatcher == dispatcherId).FirstOrDefault();
                 dispatcher.Permission = Convert.ToInt32(PermissionBox.Text);
                 cnt.db.SaveChanges();
-                if (profile.DispatcherId == dispatcherId)
+                if (profile.DispatcherId == dispatcher.IdDispatcher)
                     profile.Permission = Convert.ToInt32(PermissionBox.Text);
                 this.Close();
             }

+ 6 - 10
Kusach/Windows/DriverEditWindow.xaml.cs

@@ -3,20 +3,17 @@ using System.Linq;
 using System.Windows;
 namespace Kusach.Windows
 {
-    /// <summary>
-    /// Логика взаимодействия для DriverEditWindow.xaml
-    /// </summary>
     public partial class DriverEditWindow : Window
     {
-        int driverId;
+        Drivers driver;
         public DriverEditWindow(int id)
         {
             InitializeComponent();
-            driverId = id;
-            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();
+            driver = cnt.db.Drivers.Where(item => item.IdDriver == id).FirstOrDefault();
+            NumberPlate.Text = driver.Transport.NumberPlate.ToString();
+            SurnameBox.Text = driver.Surname;
+            NameBox.Text = driver.Name;
+            PatronymicBox.Text = driver.Patronymic;
         }
         private void BackButton_Click(object sender, RoutedEventArgs e)
         {
@@ -24,7 +21,6 @@ namespace Kusach.Windows
         }
         private void SaveDriverButton_Click(object sender, RoutedEventArgs e)
         {
-            Drivers driver = cnt.db.Drivers.Where(item => item.IdDriver == driverId).FirstOrDefault();
             driver.Name = NameBox.Text;
             driver.IdTransport = Convert.ToInt32(cnt.db.Transport.Where(item => item.NumberPlate == NumberPlate.Text).Select(item => item.IdTransport).FirstOrDefault());
             driver.Surname = SurnameBox.Text;

+ 2 - 7
Kusach/Windows/LogWindow.xaml.cs

@@ -3,9 +3,6 @@ using System.Windows;
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для LogWindow.xaml
-    /// </summary>
     public partial class LogWindow : Window
     {
         public LogWindow()
@@ -26,16 +23,14 @@ namespace Kusach
             {
                 profile.DispatcherId = cnt.db.Dispatcher.First(item => item.Login == logbox.Text).IdDispatcher;
                 profile.Permission = cnt.db.Dispatcher.First(item => item.Login == logbox.Text).Permission;
-                MainWindow mw = new MainWindow();
-                mw.Show();
+                new MainWindow().Show();
                 this.Close();
             }
                 
         }
         private void RegButton_Click(object sender, RoutedEventArgs e)
         {
-            RegWindow rw = new RegWindow();
-            rw.Show();
+            new RegWindow().Show();
             this.Close();
         }
     }

+ 4 - 8
Kusach/Windows/PointEditWindow.xaml.cs

@@ -3,18 +3,15 @@ using System.Windows;
 
 namespace Kusach.Windows
 {
-    /// <summary>
-    /// Логика взаимодействия для PointEditWindow.xaml
-    /// </summary>
     public partial class PointEditWindow : Window
     {
-        int pointId;
+        Points point;
         public PointEditWindow(int id)
         {
             InitializeComponent();
-            pointId = id;
-            NameBox.Text = Functions.GetNameOfPoint(pointId);
-            LocationBox.Text = Functions.GetLocationOfPoint(pointId);
+            point = cnt.db.Points.Where(item => item.IdPoint == id).FirstOrDefault();
+            NameBox.Text = point.Name;
+            LocationBox.Text = point.location;
         }
         private void BackButton_Click(object sender, RoutedEventArgs e)
         {
@@ -22,7 +19,6 @@ namespace Kusach.Windows
         }
         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();

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

@@ -4,9 +4,6 @@ using System.Windows;
 
 namespace Kusach
 {
-    /// <summary>
-    /// Логика взаимодействия для RegWindow.xaml
-    /// </summary>
     public partial class RegWindow : Window
     {
         public RegWindow()

+ 0 - 3
Kusach/Windows/RouteEditWindow.xaml.cs

@@ -4,9 +4,6 @@ using System.Windows.Input;
 
 namespace Kusach.Windows
 {
-    /// <summary>
-    /// Логика взаимодействия для RouteEditWindow.xaml
-    /// </summary>
     public partial class RouteEditWindow : Window
     {
         int routeId;

+ 4 - 8
Kusach/Windows/TransportEditWindow.xaml.cs

@@ -3,18 +3,15 @@ using System.Windows;
 
 namespace Kusach.Windows
 {
-    /// <summary>
-    /// Логика взаимодействия для TransportEditWindow.xaml
-    /// </summary>
     public partial class TransportEditWindow : Window
     {
-        int transportId;
+        Transport transport;
         public TransportEditWindow(int id)
         {
             InitializeComponent();
-            transportId = id;
-            NameOfTransportBox.Text = Functions.GetNameOfTransport(transportId);
-            NumberPlateBox.Text = Functions.GetNumberPlate(transportId);
+            transport = cnt.db.Transport.Where(item => item.IdTransport == id).FirstOrDefault();
+            NameOfTransportBox.Text = transport.NameOfTransport;
+            NumberPlateBox.Text = transport.NumberPlate;
         }
         private void BackButton_Click(object sender, RoutedEventArgs e)
         {
@@ -22,7 +19,6 @@ namespace Kusach.Windows
         }
         private void SaveTransportButton_Click(object sender, RoutedEventArgs e)
         {
-            Transport transport = cnt.db.Transport.Where(item => item.IdTransport == transportId).FirstOrDefault();
             transport.NameOfTransport = NameOfTransportBox.Text;
             transport.NumberPlate = NumberPlateBox.Text;
             cnt.db.SaveChanges();

+ 1 - 7
Kusach/profile.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Kusach
+namespace Kusach
 {
     public class profile
     {