Forráskód Böngészése

Спидран по окну админа

Imagara 2 éve
szülő
commit
8b80c2e539

+ 3 - 0
RaspisKusach/EDM.edmx

@@ -84,6 +84,7 @@
           <Property Name="IdUser" Type="int" Nullable="false" />
           <Property Name="Login" Type="nvarchar" MaxLength="50" Nullable="false" />
           <Property Name="Password" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Image" Type="varbinary(max)" />
           <Property Name="Email" Type="nvarchar" MaxLength="50" Nullable="false" />
           <Property Name="PhoneNum" Type="nvarchar" MaxLength="11" Nullable="false" />
           <Property Name="Passport" Type="nvarchar" MaxLength="10" Nullable="false" />
@@ -380,6 +381,7 @@
           <NavigationProperty Name="Tickets" Relationship="RouteScheduleDataBaseModel.FK_Tickets_Users" FromRole="Users" ToRole="Tickets" />
           <Property Name="Email" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
           <Property Name="PhoneNum" Type="String" Nullable="false" MaxLength="11" FixedLength="false" Unicode="true" />
+          <Property Name="Image" Type="Binary" MaxLength="Max" FixedLength="false" />
         </EntityType>
         <Association Name="FK_Carriages_Trains">
           <End Type="RouteScheduleDataBaseModel.Trains" Role="Trains" Multiplicity="1" />
@@ -566,6 +568,7 @@
           <EntitySetMapping Name="Users">
             <EntityTypeMapping TypeName="RouteScheduleDataBaseModel.Users">
               <MappingFragment StoreEntitySet="Users">
+                <ScalarProperty Name="Image" ColumnName="Image" />
                 <ScalarProperty Name="PhoneNum" ColumnName="PhoneNum" />
                 <ScalarProperty Name="Email" ColumnName="Email" />
                 <ScalarProperty Name="Permissions" ColumnName="Permissions" />

+ 25 - 10
RaspisKusach/Functions.cs

@@ -79,6 +79,21 @@ namespace RaspisKusach
             }
             return availableSeat;
         }
+        // Получение номера вагона по билету
+        public static int GetCarriageNum(Tickets ticket)
+        {
+            Carriages requiredСarriage = cnt.db.Carriages.Where(item => item.IdCarriage == ticket.IdCarriage).FirstOrDefault();
+            int carrNum = 2;
+
+            foreach(Carriages item in cnt.db.Carriages.Where(item => item.IdTrain == ticket.Trips.IdTrain))
+            {
+                if (item == requiredСarriage)
+                    return carrNum;
+                carrNum++;
+            }
+
+            return -1;
+        }
 
         // Проверка на необходимую длину и содержание только цифр
         public static bool IsOnlyDigitsAndLengthCorrect(string str, int length)
@@ -171,15 +186,15 @@ namespace RaspisKusach
             return op.ShowDialog() == true ? new BitmapImage(new Uri(op.FileName)) : null;
             #endregion
         }
-        ////Декодирование картинки
-        //public static BitmapImage NewImage(Users user)
-        //{
-        //    MemoryStream ms = new MemoryStream(user.Image);
-        //    BitmapImage image = new BitmapImage();
-        //    image.BeginInit();
-        //    image.StreamSource = ms;
-        //    image.EndInit();
-        //    return image;
-        //}
+        //Декодирование картинки
+        public static BitmapImage NewImage(Users user)
+        {
+            MemoryStream ms = new MemoryStream(user.Image);
+            BitmapImage image = new BitmapImage();
+            image.BeginInit();
+            image.StreamSource = ms;
+            image.EndInit();
+            return image;
+        }
     }
 }

+ 4 - 3
RaspisKusach/MainWindow.xaml

@@ -10,7 +10,9 @@
         WindowStyle="None"
         ResizeMode="CanResize"
         Height="450" 
-        Width="800">
+        MinHeight="450" 
+        Width="800"
+        MinWidth="800">
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="25"/>
@@ -44,8 +46,7 @@
                             FontWeight="Bold" 
                             Click="ButtonMininize_Click"/>
 
-                    <Button Visibility="Collapsed"
-                            Style="{x:Null}"
+                    <Button Style="{x:Null}"
                             Width="20" Height="20"
                             Content="☐"
                             Background="Transparent"

+ 120 - 51
RaspisKusach/Pages/AdministrationPage.xaml

@@ -10,59 +10,128 @@
       Title="Администратор">
 
     <Grid Background="White">
-        <Grid.RowDefinitions>
-            <RowDefinition Height="35"/>
-            <RowDefinition/>
-            <RowDefinition/>
-        </Grid.RowDefinitions>
-        
-        <Label Content="Администрирование"
-               HorizontalContentAlignment="Center"
-               FontSize="20"
-               FontWeight="SemiBold"/>
+        <TabControl>
+            <TabItem 
+                Height="30" 
+                Width="120">
+                <TabItem.Header>
+                    <Label Content="Поезда"
+                            FontSize="14">
+                    </Label>
+                </TabItem.Header>
+                <Grid>
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="198"/>
+                        <ColumnDefinition/>
+                    </Grid.ColumnDefinitions>
+                    <!--LEFTBAR-->
+                    <Border CornerRadius="15" 
+                Background="{StaticResource ItemColor}"
+                BorderThickness="1.5"
+                BorderBrush="{StaticResource Selection}"
+                Margin="5"
+                Grid.Column="0">
 
-        <StackPanel Grid.Row="1"
-                    Orientation="Horizontal"
-                    HorizontalAlignment="Center">
-            
-            <Button Width="120"
-                    Height="40"
-                    Margin="10,0,10,0">
-                <StackPanel Orientation="Horizontal">
-                    <Image Width="15" Height="15" Source="/RaspisKusach;component/Resources/Train.png"></Image>
-                    <Label>Маршруты</Label>
-                </StackPanel>
-            </Button>
-            
-            <Button Width="120"
-                    Height="40"
-                    Content="Станции"
-                    Margin="10,0,10,0">
-            </Button>
-            
-            <Button Width="120"
-                    Height="40"
-                    Content="Поезда"
-                    Margin="10,0,10,0">
-            </Button>
-            
-        </StackPanel>
+                        <Grid Background="{x:Null}">
+                            <StackPanel>
+                                <Button Content="Поезда"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="TrainsButton_Click">
+                                </Button>
+                                <Button Content="Поиск"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="FindRoutesButton_Click">
+                                </Button>
+                                <Button Content="Поиск"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="FindRoutesButton_Click">
+                                </Button>
+                                <Button Content="Поиск"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30">
+                                </Button>
+                                <Button Content="Сохранить"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="SaveButton_Click">
+                                </Button>
+                            </StackPanel>
+                        </Grid>
+                    </Border>
+                    <DataGrid Name="CarriagesDataGrid"
+                              Grid.Column="1"
+                              SelectionChanged="CarriagesDataGrid_SelectionChanged"/>
+                </Grid>
+            </TabItem>
+            <TabItem 
+                Height="30" 
+                Width="120">
+                <TabItem.Header>
+                    <Label Content="Вагоны"
+                           FontSize="14">
+                    </Label>
+                </TabItem.Header>
+                <Grid>
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="198"/>
+                        <ColumnDefinition/>
+                    </Grid.ColumnDefinitions>
+                    <!--LEFTBAR-->
+                    <Border CornerRadius="15" 
+                Background="{StaticResource ItemColor}"
+                BorderThickness="1.5"
+                BorderBrush="{StaticResource Selection}"
+                Margin="5"
+                Grid.Column="0">
 
-        <StackPanel Grid.Row="2"
-                    Orientation="Horizontal"
-                    HorizontalAlignment="Center">
-            
-            <Button Width="120"
-                    Height="40"
-                    Content="Профиль"
-                    Margin="10,0,10,0">
-            </Button>
+                        <Grid Background="{x:Null}">
+                            <StackPanel>
+                                <Button Content="Поезда"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="TrainsButton_Click">
+                                </Button>
+                                <Button Content="Поиск"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="FindRoutesButton_Click">
+                                </Button>
+                                <Button Content="Поиск"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="FindRoutesButton_Click">
+                                </Button>
+                                <Button Content="Поиск"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30">
+                                </Button>
+                                <Button Content="Сохранить"
+                            Margin="0,10,0,10"
+                            Width="120"
+                            Height="30"
+                            Click="SaveButton_Click">
+                                </Button>
+                            </StackPanel>
 
-            <Button Width="120"
-                    Height="40"
-                    Content="Профиль"
-                    Margin="10,0,10,0">
-            </Button>
-        </StackPanel>
+                        </Grid>
+                    </Border>
+                    <DataGrid Name="TrainsDataGrid"
+                  Grid.Column="1"
+                  SelectionChanged="TrainsDataGrid_SelectionChanged"/>
+                </Grid>
+            </TabItem>
+        </TabControl>
     </Grid>
 </Page>

+ 25 - 0
RaspisKusach/Pages/AdministrationPage.xaml.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Data.Entity;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -24,5 +25,29 @@ namespace RaspisKusach.Pages
         {
             InitializeComponent();
         }
+
+        private void SaveButton_Click(object sender, RoutedEventArgs e)
+        {
+            cnt.db.SaveChanges();
+
+        }
+
+        private void TrainsButton_Click(object sender, RoutedEventArgs e)
+        {
+            TrainsDataGrid.ItemsSource = cnt.db.Trains.ToList();
+        }
+        private void FindRoutesButton_Click(object sender, RoutedEventArgs e)
+        {
+            //temp
+        }
+
+        private void TrainsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            
+        }
+        private void CarriagesDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            
+        }
     }
 }

+ 3 - 3
RaspisKusach/Pages/LoginPage.xaml

@@ -8,8 +8,6 @@
       d:DesignHeight="367" 
       d:DesignWidth="792"
       Title="Вход">
-
-
     <Grid>
         <Grid.ColumnDefinitions>
             <ColumnDefinition/>
@@ -28,7 +26,9 @@
         <Border Grid.Row="1" 
                 Grid.Column="1"
                 BorderBrush="Black"
-                BorderThickness="2">
+                BorderThickness="2"
+                Width="396"
+                Height="294">
             <Grid Style="{x:Null}" 
                   Background="{x:Null}">
                 <Grid Background="#a0a0a0"

+ 67 - 15
RaspisKusach/Pages/ProfilePage.xaml

@@ -12,40 +12,92 @@
     <Page.Resources>
         <math:MathConverter x:Key="math"/>
     </Page.Resources>
-    <Grid Background="White">
+    <ScrollViewer Background="White"
+                  VerticalScrollBarVisibility="Visible">
         <StackPanel>
-            <Label>
+            <Border Background="#F5F5F5"
+                    Margin="15"
+                    CornerRadius="15"
+                    BorderThickness="1.5"
+                    BorderBrush="{StaticResource Selection}">
+                <Grid>
+                    <Grid>
+                        <Grid.ColumnDefinitions>
+                            <ColumnDefinition Width="*"/>
+                            <ColumnDefinition Width="*"/>
+                        </Grid.ColumnDefinitions>
+                        <Image Grid.Row="0"
+                               Name="ProfileImage"
+                               MouseDown="ProfileImage_MouseDown" 
+                               Source="/RaspisKusach;component/Resources/StandartProfile.png"
+                               MinHeight="50"
+                               MinWidth="50"
+                               Width="150"
+                               Height="150">
+                        </Image>
+                        <StackPanel Grid.Column="1">
+                            <Label Content="ФИО:"/>
+                            <Label Name="FIOLabel"/>
+                            <Label Content="Email:"/>
+                            <Label Name="EmailLabel"/>
+                            <Label Content="Номер телефона:"/>
+                            <Label Name="PhoneLabel"/>
+                        </StackPanel>
+                    </Grid>
+                </Grid>
+            </Border>
 
-            </Label>
+            <Label Content="Купленные билеты:"/>
             <ListBox Name="TicketsListBox"
                  Grid.Row="1"
-                 Margin="10,0,10,0"
+                 Margin="10"
                  BorderBrush="{x:Null}"
-                 SelectionChanged="TicketsListBox_SelectionChanged"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                  ScrollViewer.VerticalScrollBarVisibility="Hidden">
-                <ScrollBar></ScrollBar>
+                temp
                 <ListBox.ItemTemplate>
                     <DataTemplate>
                         <Border Width="{Binding Path=ActualWidth, Mode=OneWay, ElementName=TicketsListBox, Converter={StaticResource math}, ConverterParameter=x-15}"
                                 CornerRadius="15"
-                                Height="70"
                                 Background="{StaticResource ItemColor}"
                                 BorderThickness="1.5"
                                 BorderBrush="Black"
-                                Style="{StaticResource IsBorderMouseOver}">
+                                Style="{StaticResource IsBorderMouseOver}"
+                                Margin="0,10,0,10">
                             <Grid Margin="7">
                                 <StackPanel Orientation="Horizontal">
                                     <Image Width="30"
-                               Height="30"
-                               Margin="10,5,5,5"
-                               HorizontalAlignment="Left"
-                               Source="/RaspisKusach;component/Resources/Train.png">
+                                           Height="30"
+                                           Margin="10,5,5,5"
+                                           HorizontalAlignment="Left"
+                                           Source="/RaspisKusach;component/Resources/Train.png">
                                     </Image>
                                     <StackPanel>
                                         <StackPanel Orientation="Horizontal">
-                                            <Label Content="qwe"/>
-                                            <Label Content="qweq"/>
+                                            <Label Content="Билет:"/>
+                                            <Label Content="{Binding Ticket.IdTicket}"
+                                                   Margin="-7,0,0,0"/>
+                                            <Label Content="{Binding FIO}"/>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal">
+                                            <Label Content="Вагон:"/>
+                                            <Label Content="{Binding CarriageNum}"
+                                                   Margin="-7,0,0,0"/>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal">
+                                            <Label Content="Место:"/>
+                                            <Label Content="{Binding Ticket.PlaceNumber}"
+                                                   Margin="-7,0,0,0"/>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal">
+                                            <Label Content="Класс:"/>
+                                            <Label Content="{Binding Ticket.Carriages.Category}"
+                                                   Margin="-7,0,0,0"/>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal">
+                                            <Label Content="Дата покупки:"/>
+                                            <Label Content="{Binding BuyDate}"
+                                                   Margin="-7,0,0,0"/>
                                         </StackPanel>
                                     </StackPanel>
                                 </StackPanel>
@@ -61,5 +113,5 @@
                 </ListBox.ItemTemplate>
             </ListBox>
         </StackPanel>
-    </Grid>
+    </ScrollViewer>
 </Page>

+ 45 - 4
RaspisKusach/Pages/ProfilePage.xaml.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -21,12 +22,52 @@ namespace RaspisKusach.Pages
         {
             InitializeComponent();
             TicketsListBox.Items.Clear();
-            TicketsListBox.ItemsSource = cnt.db.Tickets.Where(item => item.IdUser == Session.User.IdUser).ToList();
+            UpdateUserInfo();
+            UpdateCarriagesList();
         }
-
-        private void TicketsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        private void UpdateUserInfo()
         {
-
+            FIOLabel.Content = string.Concat(Session.User.Surname, " ", Session.User.Name, " ", Session.User.Patronymic);
+            EmailLabel.Content = Session.User.Email;
+            ProfileImage.Source = Session.User.Image == null ?
+                new BitmapImage(new Uri("../Resources/StandartProfile.png", UriKind.RelativeOrAbsolute)) :
+                ProfileImage.Source = Functions.NewImage(Session.User);
+            string temp = Session.User.PhoneNum;
+            PhoneLabel.Content = $"+{temp.Substring(0, 1)}({temp.Substring(1, 3)}){temp.Substring(4, 3)}-{temp.Substring(7, 2)}-{temp.Substring(9, 2)}";
+        }
+        private void UpdateCarriagesList()
+        {
+            List<TicketsClass> routeList = new List<TicketsClass>();
+            int carrNum = 2;
+            foreach (var item in cnt.db.Tickets.Where(item => item.IdUser == Session.User.IdUser).ToList())
+            {
+                routeList.Add(new TicketsClass()
+                {
+                    Ticket = item,
+                    FIO = string.Concat(item.Users.Surname, " ", item.Users.Name, " ", item.Users.Patronymic),
+                    CarriageNum = Functions.GetCarriageNum(item),
+                    BuyDate = item.BuyDate.ToString(new CultureInfo("ru-RU"))
+                });
+                carrNum++;
+            }
+            TicketsListBox.ItemsSource = routeList;
+        }
+        private void ProfileImage_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            BitmapImage image = Functions.SelectImage();
+            if (image != null)
+            {
+                ProfileImage.Source = image;
+                Session.User.Image = Functions.BitmapSourceToByteArray((BitmapSource)ProfileImage.Source);
+                cnt.db.SaveChanges();
+            }
+        }
+        public class TicketsClass
+        {
+            public Tickets Ticket { get; set; }
+            public string FIO { get; set; }
+            public int CarriageNum { get; set; }
+            public string BuyDate { get; set; }
         }
     }
 }

+ 4 - 2
RaspisKusach/Pages/RegisterPage.xaml

@@ -24,10 +24,12 @@
                Grid.RowSpan="3" 
                Grid.ColumnSpan="3"
                Stretch="Fill"/>
-        <Border Grid.Row="1" 
+        <Border Grid.Row="1"
                 Grid.Column="1"
                 BorderBrush="Black"
-                BorderThickness="2">
+                BorderThickness="2"
+                Width="396"
+                Height="294">
             <Grid Style="{x:Null}" 
                   Background="{x:Null}">
                 <Grid Background="#a0a0a0"

+ 2 - 2
RaspisKusach/Pages/SchedulePage.xaml

@@ -15,8 +15,8 @@
     </Page.Resources>
     <Grid Background="White">
         <Grid.RowDefinitions>
-            <RowDefinition Height="80*"/>
-            <RowDefinition Height="287*"/>
+            <RowDefinition Height="80"/>
+            <RowDefinition/>
         </Grid.RowDefinitions>
         <Border 
             Background="{StaticResource ItemColor}"

+ 2 - 2
RaspisKusach/Pages/SearchForTicketsPage.xaml

@@ -14,8 +14,8 @@
     </Page.Resources>
     <Grid Background="White">
         <Grid.ColumnDefinitions>
-            <ColumnDefinition Width="*"/>
-            <ColumnDefinition Width="3*"/>
+            <ColumnDefinition Width="198"/>
+            <ColumnDefinition/>
         </Grid.ColumnDefinitions>
 
         <!--LEFTBAR-->

+ 1 - 1
RaspisKusach/Pages/TripInfoPage.xaml

@@ -57,7 +57,7 @@
 
                         <Label Grid.Column="1"
                                Content="15:30"
-                               VerticalAlignment="Center">
+                               VerticalContentAlignment="Center">
                         </Label>
 
                         <StackPanel Grid.Column="2"

+ 1 - 0
RaspisKusach/Users.cs

@@ -30,6 +30,7 @@ namespace RaspisKusach
         public int Permissions { get; set; }
         public string Email { get; set; }
         public string PhoneNum { get; set; }
+        public byte[] Image { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<Tickets> Tickets { get; set; }

+ 2 - 1
RaspisKusach/todo.txt

@@ -1,7 +1,8 @@
 ✓Подредактировать регистрацию + вход
 ✓Добавить проверку на фио
 ✓Добавить авто форматирование фио
-✘Добавить возможность покупки билетов
+✓Добавить возможность покупки билетов
+✓Профиль
 ✘Добавить Админ меню(?)
 ✘Сделать юнит тесты
 ✘Получить 4/5 за защиту