Артем Гавриленко 3 年之前
父節點
當前提交
3ff4223281

+ 3 - 3
Kusach/Functions.cs

@@ -82,14 +82,14 @@ namespace Kusach
         // Проверка на валидность информации о водителе
         public static bool IsValidInfoAboutDriver(string idTransport, string name, string surname, string patronymic)
         {
-            if (IsIdOnlyDigits(idTransport) && idTransport != "" && name != "" && surname != "" && patronymic != "")
+            if (IsOnlyDigits(idTransport) && idTransport != "" && name != "" && surname != "" && patronymic != "")
                 return true;
             else
                 return false;
         }
-        public static bool IsIdOnlyDigits (string idTransport)
+        public static bool IsOnlyDigits (string str)
         {
-            foreach (char c in idTransport)
+            foreach (char c in str)
                 if (!char.IsDigit(c))
                     return false;
             return true;

+ 7 - 0
Kusach/Kusach.csproj

@@ -146,6 +146,9 @@
     </Compile>
     <Compile Include="cnt.cs" />
     <Compile Include="Encrypt.cs" />
+    <Compile Include="Windows\DispatcherEditWindow.xaml.cs">
+      <DependentUpon>DispatcherEditWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Windows\LogWindow.xaml.cs">
       <DependentUpon>LogWindow.xaml</DependentUpon>
     </Compile>
@@ -214,6 +217,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Windows\DispatcherEditWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Windows\LogWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

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

@@ -29,7 +29,11 @@ namespace Kusach.Pages
         }
         private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
-            
+            if (profile.Permission == 0)
+            {
+                Windows.DispatcherEditWindow dew = new Windows.DispatcherEditWindow(((Dispatcher)DispatcherList.SelectedItem).IdDispatcher);
+                dew.ShowDialog();
+            }
         }
 
         #region Поиск

+ 7 - 23
Kusach/Pages/ProfilePage.xaml.cs

@@ -1,17 +1,9 @@
-using System;
-using System.Collections.Generic;
+using Microsoft.Win32;
+using System;
 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 Kusach.Pages
 {
@@ -34,21 +26,13 @@ namespace Kusach.Pages
         }
         private void EditImageButton_Click(object sender, RoutedEventArgs e)
         {
-            // Создаем OpenFileDialog 
-            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
-
-            // Устанавливаем фильтры и стандартное расширение файла
-            dlg.DefaultExt = ".png";
-            dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg";
-
-            // Отображаем OpenFileDialog
-            Nullable<bool> result = dlg.ShowDialog();
-
-            // Получаем и устанавливаем новое изображение 
+            OpenFileDialog ofd = new OpenFileDialog();
+            ofd.DefaultExt = ".png";
+            ofd.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg";
+            Nullable<bool> result = ofd.ShowDialog();
             if (result == true)
             {
-                // Open document 
-                string filename = dlg.FileName;
+                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;

+ 53 - 0
Kusach/Windows/DispatcherEditWindow.xaml

@@ -0,0 +1,53 @@
+<Window x:Class="Kusach.Windows.DispatcherEditWindow"
+        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"
+        Height="160" 
+        Width="300"
+        ResizeMode="NoResize"
+        WindowStyle="None"
+        WindowStartupLocation="CenterScreen"
+        Title="DispatcherEditWindow">
+    <Grid>
+        <StackPanel
+            Margin="0,10,0,0"
+            HorizontalAlignment="Center"
+            VerticalAlignment="Top">
+            <Label 
+            Content="Права доступа:" 
+            HorizontalAlignment="Left" 
+            VerticalAlignment="Top" 
+            Height="30" 
+            Width="190"/>
+            <TextBox 
+            x:Name="PermissionBox"
+            HorizontalAlignment="Left" 
+            VerticalAlignment="Top" 
+            Height="30" 
+            Width="190"/>
+        </StackPanel>
+        <Button 
+            Content="Сохранить" 
+            HorizontalAlignment="Left"
+            Margin="170,100,0,0" 
+            VerticalAlignment="Top" 
+            Height="40" 
+            Width="120" 
+            Click="SaveButton_Click"/>
+        <Button 
+            Content="Отмена"
+            HorizontalAlignment="Left" 
+            Margin="10,100,0,0" 
+            VerticalAlignment="Top" 
+            Height="40" 
+            Width="120" 
+            Click="BackButton_Click"
+            IsDefault="True"/>
+        <Border 
+            BorderBrush="Black" 
+            BorderThickness="2"/>
+    </Grid>
+</Window>

+ 48 - 0
Kusach/Windows/DispatcherEditWindow.xaml.cs

@@ -0,0 +1,48 @@
+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;
+        public DispatcherEditWindow(int id)
+        {
+            InitializeComponent();
+            dispatcherId = id;
+            PermissionBox.Text = cnt.db.Dispatcher.Where(item => item.IdDispatcher == id).Select(item => item.Permission).FirstOrDefault().ToString();
+        }
+        private void BackButton_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+        private void SaveButton_Click(object sender, RoutedEventArgs e)
+        {
+            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)
+                    profile.Permission = Convert.ToInt32(PermissionBox.Text);
+                this.Close();
+            }
+            else
+                MessageBox.Show("Данное поле может содержать только цифры");
+        }
+    }
+}

+ 1 - 1
UnitTests/App.config

@@ -10,6 +10,6 @@
     </providers>
   </entityFramework>
   <connectionStrings>
-    <add name="EDMEntities" connectionString="metadata=res://*/EDM.csdl|res://*/EDM.ssdl|res://*/EDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\MSSQLLocalDB;initial catalog=gr692_gav;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+    <add name="EDM" connectionString="metadata=res://*/EDM.csdl|res://*/EDM.ssdl|res://*/EDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\MSSQLLocalDB;initial catalog=gr692_gav;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
 </configuration>

+ 1 - 1
UnitTests/UnitTest1.cs

@@ -101,7 +101,7 @@ namespace UnitTests
         public void IsIdOnlyDigits()
         {
             string IdTransport = "123";
-            Assert.IsTrue(Functions.IsIdOnlyDigits(IdTransport));
+            Assert.IsTrue(Functions.IsOnlyDigits(IdTransport));
         }
     }
 }