Иван Прытов 8 ay önce
ebeveyn
işleme
07e3b256f8

+ 5 - 0
UPtur/Models/Country.cs

@@ -5,6 +5,11 @@ namespace UPtur.Models;
 
 public partial class Country
 {
+    public Country()
+    {
+        Hotels = new HashSet<Hotel>();
+    }
+
     public string Code { get; set; } = null!;
 
     public string Name { get; set; } = null!;

+ 8 - 0
UPtur/Models/Hotel.cs

@@ -5,6 +5,14 @@ namespace UPtur.Models;
 
 public partial class Hotel
 {
+
+    public Hotel()
+    {
+        HotelComments = new HashSet<HotelComment>();
+        HotelImages = new HashSet<HotelImage>();
+        HotelOfTours = new HashSet<HotelOfTour>();
+    }
+
     public int Id { get; set; }
 
     public string Name { get; set; } = null!;

+ 7 - 0
UPtur/Models/Tour.cs

@@ -6,6 +6,13 @@ namespace UPtur.Models;
 
 public partial class Tour
 {
+
+    public Tour()
+    {
+        HotelOfTours = new HashSet<HotelOfTour>();
+        TypeOfTours = new HashSet<TypeOfTour>();
+    }
+
     public int Id { get; set; }
 
     public int TicketCount { get; set; }

+ 64 - 0
UPtur/Models/TourImage.cs

@@ -0,0 +1,64 @@
+using Avalonia.Media;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UPtur.Models
+{
+    public partial class Tour
+    {
+        public Avalonia.Media.Imaging.Bitmap GetPic
+        {
+            get
+            {
+                Avalonia.Media.Imaging.Bitmap pic = null;
+                try
+                {
+                    pic = new Avalonia.Media.Imaging.Bitmap($"Pictures/{Name}.jpg");
+                    return pic;
+                }
+                catch
+                {
+                    pic = new Avalonia.Media.Imaging.Bitmap("Pictures/pic.png");
+                    return pic;
+                }
+            }
+        }
+
+        public string Actual
+        {
+            get
+            {
+                if (IsActual[0] == true)
+                {
+                    return "Актуален";
+                }
+                else
+                {
+                    return "Не актуален";
+                }
+            }
+        }
+
+        public SolidColorBrush Color
+        {
+            get
+            {
+                if (IsActual[0] == true)
+                {
+                    return new SolidColorBrush(Avalonia.Media.Color.FromRgb(10, 206, 76));
+                }
+                else
+                {
+                    return new SolidColorBrush(Avalonia.Media.Color.FromRgb(249, 0, 0));
+                }
+            }
+
+        }
+
+    }
+
+   
+}

+ 1 - 1
UPtur/Models/UpPrytovContext.cs

@@ -33,7 +33,7 @@ public partial class UpPrytovContext : DbContext
 
     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
-        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.local;Port=5432;Database=UP_Prytov;Username=43P;Password=444444");
+        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.ru;Port=5442;Database=UP_Prytov;Username=43P;Password=444444");
 
     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {

+ 31 - 0
UPtur/Models/VivodHotel.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UPtur.Models
+{
+    public partial class Hotel
+    {
+        UpPrytovContext DB = new UpPrytovContext();
+        public string CountryName
+        {
+            get
+            {
+                return DB.Countries.Where(x => x.Code == CountryCode).Select(x => x.Name).FirstOrDefault();
+            }
+        }
+
+        public int AmountTours
+        {
+            get
+            {
+                List<HotelOfTour> HotelForAmount = DB.HotelOfTours.ToList();
+                HotelForAmount = HotelForAmount.Where(x => x.HotelId == Id).ToList();
+                return HotelForAmount.Count;
+            }
+        }
+
+    }
+}

+ 1 - 0
UPtur/UPtur.csproj

@@ -25,6 +25,7 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
+    <PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 117 - 4
UPtur/ViewModels/HotelsViewModel.cs

@@ -1,10 +1,123 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
+using MsBox.Avalonia;
+using MsBox.Avalonia.Enums;
 using ReactiveUI;
+using UPtur.Models;
 
 namespace UPtur.ViewModels
 {
-	public class HotelsViewModel : ReactiveObject
-	{
-	}
-}
+    public class HotelsViewModel : ReactiveObject
+    {
+        UpPrytovContext DB = new UpPrytovContext();
+        private List<Hotel>? _hotels; //ëèñòû îòåëåé
+        public List<Hotel>? Hotels { get => _hotels; set => this.RaiseAndSetIfChanged(ref _hotels, value); }
+        private int countElements;
+        public int CountElements
+        {
+            get => countElements;//äëÿ âûâîäà îïðåäåëåííûé ñòðàíèö íà ýêðàíå
+            set
+            {
+                this.RaiseAndSetIfChanged(ref countElements, value);
+                Hotels = DB.Hotels.ToList();
+                AmountOfPages = Hotels.Count / countElements + 1;
+                ToFirstPage();
+
+            }
+        }
+
+        private int _amountOfPages;
+        public int AmountOfPages
+        {
+            get => _amountOfPages;
+            set
+            {
+                this.RaiseAndSetIfChanged(ref _amountOfPages, value);
+            }
+        }
+        private int _page = 1;
+        public int Page { get => _page; set => this.RaiseAndSetIfChanged(ref _page, value); }
+        private bool _enableOrNotRight = true;
+        public bool EnableOrNotRight { get => _enableOrNotRight; set => this.RaiseAndSetIfChanged(ref _enableOrNotRight, value); }
+        private bool _enableOrNotLeft = false;
+        public bool EnableOrNotLeft { get => _enableOrNotLeft; set => this.RaiseAndSetIfChanged(ref _enableOrNotLeft, value); }
+        int flagElementCount = 0;
+
+        private List<int> _selectCountOfElements = new List<int>() { 10, 15, 20 };//âûáîð êîë-âî ñòðàíèö íà ýêðàíå
+        public List<int> SelectedCountOfElements { get => _selectCountOfElements; set => this.RaiseAndSetIfChanged(ref _selectCountOfElements, value); }
+
+        private List<Hotel> _selectedHotels;
+        public List<Hotel> SelectedHotels
+        {
+            get => _selectedHotels;
+            set => this.RaiseAndSetIfChanged(ref _selectedHotels, value);
+        }
+        public HotelsViewModel()//âûâîä ïåðâûõ 10 çàïèñåé
+        {
+            Hotels = DB.Hotels.ToList();
+            CountElements = SelectedCountOfElements[0];
+            Hotels = Hotels.Take(CountElements).ToList();
+        }
+
+        public void NextPage()//ïåðåõîä íà ñëåäóþùóþ ñòðàíèöó
+        {
+            Page++;
+            Hotels = DB.Hotels.ToList();
+            Hotels = Hotels.Skip((Page - 1) * CountElements).ToList();
+            flagElementCount = Hotels.Count();
+            Hotels = Hotels.Take(CountElements).ToList();
+            EnableOrNotLeft = true;
+            if (flagElementCount <= CountElements)
+            {
+                EnableOrNotRight = false;
+            }
+            else
+            {
+                EnableOrNotRight = true;
+            }
+        }
+
+        public void PrevPage()//ïåðåõîä íà ïðåäûäóùóþ ñòðàíèöó
+        {
+            Page--;
+            Hotels = DB.Hotels.ToList();
+            Hotels = Hotels.Skip((Page - 1) * CountElements).ToList();
+            Hotels = Hotels.Take(CountElements).ToList();
+            EnableOrNotRight = true;
+            if (Page == 1)
+            {
+                EnableOrNotLeft = false;
+            }
+            else
+            {
+                EnableOrNotLeft = true;
+            }
+        }
+
+        public void ToFirstPage()//ïåðåõîä íà ñàìóþ 1 ñòðàíèöó
+        {
+            Page = 1;
+            Hotels = DB.Hotels.ToList();
+            Hotels = Hotels.Take(CountElements).ToList();
+            EnableOrNotLeft = false;
+            EnableOrNotRight = true;
+        }
+
+        public void ToLastPage()//ïåðåõîä íà ïîñëåäíþþ ñòðàíèöó
+        {
+            Hotels = DB.Hotels.ToList();
+            Page = Hotels.Count / CountElements;
+            Hotels = Hotels.Skip(Page * CountElements).ToList();
+            Hotels = Hotels.Take(CountElements).ToList();
+            Page++;
+            EnableOrNotRight = false;
+            EnableOrNotLeft = true;
+        }
+
+       
+            
+
+        
+    }
+}

+ 14 - 0
UPtur/ViewModels/MainWindowViewModel.cs

@@ -39,6 +39,20 @@ namespace UPtur.ViewModels
         {
             US = new Views.PageNavigate();
         }
+        HotelsViewModel _hotelsVM = new HotelsViewModel();
+
+        public HotelsViewModel HotelsVM
+        {
+            get => _hotelsVM;
+            set => _hotelsVM = value;
+        }
+
+        
+
+        public void ToMenu()
+        {
+            US = new Views.PageNavigate();
+        }
 
     }
 

+ 18 - 24
UPtur/ViewModels/ToursViewModel.cs

@@ -10,22 +10,19 @@ namespace UPtur.ViewModels
 	{
         UpPrytovContext DB = new UpPrytovContext();
        private List<Tour>? _tours;
-        public List<Tour>? Tours { get => _tours; set => this.RaiseAndSetIfChanged(ref _tours, value); }
+      
+       
+        public List<Tour>? Tours { get => _tours; set => this.RaiseAndSetIfChanged(ref _tours, value); }//ëèñò äëÿ òóðîâ
 
         private static List<string>? _types;
-        public static List<string>? Types { get => _types; set => _types = value; }
+        public static List<string>? Types { get => _types; set => _types = value; }//ëèñò äëÿ òèïîâ
 
         private static List<string>? _sort;
-        public static List<string>? Sort { get => _sort; set => _sort = value; }
+        public static List<string>? Sort { get => _sort; set => _sort = value; }//ëèñò äëÿ ñîðòèðîâêè
+
 
-        private decimal _priceOfAll;
-        public decimal PriceOfAll
-        {
-            get => _priceOfAll; 
-            set => this.RaiseAndSetIfChanged(ref _priceOfAll, value);
-        }
 
-        private bool _checkOrNot = false;
+        private bool _checkOrNot = false; //àêòóàëüíîñòü
         public bool CheckOrNot
         {
             get => _checkOrNot;
@@ -36,7 +33,7 @@ namespace UPtur.ViewModels
             }
         }
 
-        private string? _findTour;
+        private string? _findTour; //ïîèñêîâàÿ ñòðîêà
         public string? FindTour
         {
             get => _findTour;
@@ -47,7 +44,7 @@ namespace UPtur.ViewModels
             }
         }
 
-        private string? _selectedItem;
+        private string? _selectedItem; //âûáîðû òèïîâ ôèëüòðàöèÿ
         public string? SelectedItem
         {
             get
@@ -61,7 +58,7 @@ namespace UPtur.ViewModels
             }
         }
 
-        private string? _selectedSort;
+        private string? _selectedSort;//ñîðòèðîâêà
         public string? SelectedSort
         {
             get
@@ -75,7 +72,7 @@ namespace UPtur.ViewModels
             }
         }
 
-        public ToursViewModel()
+        public ToursViewModel()//êîíñòðóêòîð ñîðòèðîâêè
         {
             Tours = DB.Tours.ToList();
             Types = DB.Types.Select(x=>x.Name).ToList();
@@ -85,12 +82,12 @@ namespace UPtur.ViewModels
             SelectedSort = Sort[0];
         }
 
-        public void Filter()
+        public void Filter()//ìåòîä äëÿ ôèëüòðà
         {
             Tours = DB.Tours.ToList();
-            PriceOfAll = 0;
+            
 
-            if (SelectedItem != "Âñå")
+            if (SelectedItem != "Âñå")//ôèëòðàöèÿ ïî òèïó 
             {
                 List <TypeOfTour> TypesForFilter = DB.TypeOfTours.ToList();
                 List <int> IdForFilter = new List<int>();
@@ -146,17 +143,17 @@ namespace UPtur.ViewModels
                 }
             }
 
-            if(CheckOrNot)
+            if(CheckOrNot)//ïðîâåðêà íà àêòóàëüíûå òóðû
             {
                 Tours = Tours.Where(x => x.IsActual[0]==true).ToList();
             }
 
-            if(FindTour!=null && FindTour != "")
+            if(FindTour!=null && FindTour != "")//ïðîâåðêà ñòðîêè ïîèñêà íà çàïîëíåíîñòü
             {
                 Tours = Tours.Where(x=>x.Name.ToUpper().Contains(FindTour.ToString().ToUpper()) || x.DescriptionWithoutNull.Contains(FindTour.ToString().ToUpper())).ToList();
             }
 
-            if(SelectedSort != "Áåç ñîðòèðîâêè")
+            if(SelectedSort != "Áåç ñîðòèðîâêè")//ïðîâåðêà íà íàëè÷èå ñîðòèðîâêè
             {
                 switch(SelectedSort)
                 {
@@ -169,10 +166,7 @@ namespace UPtur.ViewModels
                 }
             }
 
-            foreach(Tour t in Tours)
-            {
-                PriceOfAll += (t.Price * t.TicketCount);
-            }
+            
         }
     }
 

+ 59 - 1
UPtur/Views/Hotels.axaml

@@ -3,6 +3,64 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+             x:DataType="vm:MainWindowViewModel"
+             xmlns:vm="using:UPtur.ViewModels"
              x:Class="UPtur.Views.Hotels">
-  Welcome to Avalonia!
+  <Grid RowDefinitions="*,14*">
+    <Border Background="" BorderThickness="" >
+		<StackPanel Grid.Row="0" Width="800" HorizontalAlignment="Center" Orientation="Horizontal">
+			<TextBlock Text="Название отеля"/>
+			<TextBlock Margin="20,0,0,0" Text="Количество звёзд"/>
+			<TextBlock Margin="20,0,0,0" Text="Название страны"/>
+			<TextBlock Margin="20,0,0,0" Text="Количество туров "/>
+			<TextBlock Margin="20,0,0,0" Text="Количество отелей:"/>
+			<ComboBox ItemsSource="{Binding HotelsVM.SelectedCountOfElements}" SelectedItem="{Binding HotelsVM.CountElements}" Margin="30,0,0,0" />
+		</StackPanel>
+    </Border>
+		
+		<ListBox SelectionMode="Multiple" SelectedItems="{Binding HotelsVM.SelectedHotels}" ItemsSource="{Binding HotelsVM.Hotels}" Grid.Row="1">
+			<ListBox.ItemsPanel>
+				<ItemsPanelTemplate>
+					<WrapPanel Orientation="Vertical" HorizontalAlignment="Center"/>
+				</ItemsPanelTemplate>
+			</ListBox.ItemsPanel>
+			<ListBox.ItemTemplate>
+				<DataTemplate>
+					<Border HorizontalAlignment="Center" BorderBrush="Black" BorderThickness="1" Padding="15">
+						<Grid HorizontalAlignment="Center">
+							<StackPanel Width="800" Orientation="Horizontal" HorizontalAlignment="Center">
+								<Grid Width="800" ColumnDefinitions="*,*,*,*,1*">
+									<TextBlock Grid.Column="0" Text="{Binding Name}"/>
+									<TextBlock Grid.Column="1" Margin="20,0,0,0" Text="{Binding CountOfStars}"/>
+									<TextBlock Grid.Column="2" Margin="0,0,0,0" Text="{Binding CountryName}"/>
+									<TextBlock Grid.Column="3" Margin="0,0,0,0" Text="{Binding AmountTours}"/>
+									<StackPanel Grid.Column="4" HorizontalAlignment="Center">
+										
+										
+									</StackPanel>
+								</Grid>
+							</StackPanel>
+						</Grid>
+					</Border>
+				</DataTemplate>
+			</ListBox.ItemTemplate>
+		</ListBox>
+		<StackPanel Margin="10,0,0,10" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Grid.Row="1">
+			<Button Background="#445c93" IsEnabled="{Binding HotelsVM.EnableOrNotLeft}" Command="{Binding HotelsVM.ToFirstPage}" FontSize="15" Content="Начало"/>
+			<Button Background="#445c93" IsEnabled="{Binding HotelsVM.EnableOrNotLeft}" Command="{Binding HotelsVM.PrevPage}" Margin="10,0,0,0" FontSize="15" Content="Предыдущая"/>
+		</StackPanel>
+		<StackPanel Margin="0,0,10,10" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="1">
+			<Button Background="#445c93" IsEnabled="{Binding HotelsVM.EnableOrNotRight}" Command="{Binding HotelsVM.NextPage}" Margin="0,0,10,0" FontSize="15" Content="Следующая"/>
+			<Button Background="#445c93" IsEnabled="{Binding HotelsVM.EnableOrNotRight}" Command="{Binding HotelsVM.ToLastPage}" FontSize="15" Content="Конец"/>
+		</StackPanel>
+		<StackPanel Margin="0,0,0,10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Grid.Row="1">
+			<Button Background="#445c93" Content="Назад" Command="{Binding ToMenu}"/>
+		</StackPanel>
+		<StackPanel Margin="10,0,0,0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Grid.Row="1">
+			
+		</StackPanel>
+		<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
+      <Button Margin="240,30,0,10" Background="#fac716" Width="130"  HorizontalContentAlignment="Center" Content="Удалить"/>
+		</StackPanel>
+	</Grid>
 </UserControl>

+ 4 - 4
UPtur/Views/Tours.axaml

@@ -12,11 +12,11 @@
 		<StackPanel Margin="0,10,0,10" Orientation="Vertical" HorizontalAlignment="Center" >
 			<StackPanel Orientation="Vertical" VerticalAlignment="Center">
 				<TextBlock Text="Введите текст для поиска: "/>
-				<TextBox Text="{Binding ToursVM.FindTour}" Width="300" Watermark="Поиск по названию и описанию"></TextBox>
+				<TextBox Text="{Binding ToursVM.FindTour}" Width="300" Watermark="Поиск по названию"></TextBox>
 			</StackPanel>
 			<StackPanel Margin="0,10,0,0" Orientation="Vertical" VerticalAlignment="Center">
 				<TextBlock Margin="0,0,0,0" Text="Выберите тип: "/>
-				<ComboBox SelectedIndex="0" ItemsSource="{Binding ToursVM.Types}" Width="300"/>
+        <ComboBox SelectedIndex="0" SelectedItem="{Binding ToursVM.SelectedItem}" ItemsSource="{Binding ToursVM.Types}" Width="300"/>
 			</StackPanel>
 			<StackPanel HorizontalAlignment="Center" Margin="0,10,0,0" Orientation="Vertical" VerticalAlignment="Center">
 				<TextBlock VerticalAlignment="Center" Text="Выберите сортировку: "/>
@@ -36,7 +36,7 @@
 					<Border Width="300" Height="270" BorderBrush="Black" BorderThickness="1" Padding="5">
 						<StackPanel Orientation="Vertical" VerticalAlignment="Center">
 							<TextBlock Margin="0 0 0 5" TextWrapping="Wrap" FontSize="19" TextAlignment="Center" HorizontalAlignment="Center" Text="{Binding Name}"></TextBlock>
-							<Image Margin="5" Source="avares://UPtur/Assets/Pictures/pic.png" Width="270" Height="120"></Image>
+              <Image HorizontalAlignment="Center" Width="270" Height="150" Source="{Binding GetPic}"/>
 							<TextBlock Margin="5" FontSize="20" FontWeight="ExtraBold" HorizontalAlignment="Center" TextAlignment="Center" Text="{Binding StringFormat={}{0:#} РУБ, Path=Price}"></TextBlock>
 							<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
 								<StackPanel HorizontalAlignment="Left" Margin="0 0 25 0">
@@ -45,7 +45,7 @@
 								<StackPanel HorizontalAlignment="Right" Margin="25 0 0 0">
 									<TextBlock FontSize="16" Text="{Binding StringFormat=Билетов: {0:#}, Path=TicketCount}"></TextBlock>
 								</StackPanel>
-								
+                <TextBlock HorizontalAlignment="Left" FontSize="15" Foreground="{Binding Color}" Text="{Binding Actual}"/>
 							</StackPanel>
 						</StackPanel>
 					</Border>