AnnaBezaeva пре 1 недеља
родитељ
комит
4179c7e269

+ 1 - 1
AvaloniaApplication5/Models/_43pBezaevaContext.cs

@@ -30,7 +30,7 @@ public partial class _43pBezaevaContext : 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 https://go.microsoft.com/fwlink/?LinkId=723263.
-        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.ru;Port=5442;Database=43P_Bezaeva;Username=43P;Password=444444");
+        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.local;Port=5432;Database=43P_Bezaeva;Username=43P;Password=444444");
 
     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {

+ 88 - 0
AvaloniaApplication5/ViewModels/AddPageViewModel.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using AvaloniaApplication5.Models;
+using Microsoft.EntityFrameworkCore;
+using ReactiveUI;
+
+namespace AvaloniaApplication5.ViewModels
+{
+	internal class AddPageViewModel : ViewModelBase
+    {
+		Teacher? _newTeacher;
+
+		public List<TeacherCourse> TeacherCourses { get => _teacherCourses; set => this.RaiseAndSetIfChanged(ref _teacherCourses, value); }
+        public Teacher? NewTeacher { get => _newTeacher; set => this.RaiseAndSetIfChanged(ref _newTeacher, value); }
+	    public AddPageViewModel()
+		{
+			_newTeacher = new Teacher()
+			{
+				Gender = new Gender() 
+			};
+		}
+		public AddPageViewModel(int id)
+		{
+			_newTeacher = MainWindowViewModel.myConnection.Teachers.Include(x=>x.Gender).Include(x=>x.TeacherCourses).ThenInclude(x=>x.Course).Include(x=>x.TeacherDisciplines).ThenInclude(x=>x.Discipline).FirstOrDefault(x=>x.Id == id);
+            TeacherCourses = NewTeacher.TeacherCourses.ToList();
+		}
+	    public List<Gender> Genders => MainWindowViewModel.myConnection.Genders.ToList();
+	    public List<Discipline> Disciplines => MainWindowViewModel.myConnection.Disciplines.ToList();
+	    public List<Course> Courses => MainWindowViewModel.myConnection.Courses.ToList();
+		List<TeacherCourse>? _teacherCourses;
+		List<TeacherDiscipline>? _teacherDisciplines;
+		public List<TeacherDiscipline> TeacherDisciplines { get => _teacherDisciplines; set => this.RaiseAndSetIfChanged(ref _teacherDisciplines, value); }
+		Course? selectedCourse;
+		Discipline? selectedDiscipline;
+	    public Course? SelectedCourse
+		{
+			get => null;
+			set
+			{
+				if(value != null)
+				{
+					NewTeacher.TeacherCourses.Add(new TeacherCourse()
+					{
+						Teacher = NewTeacher, Course = value
+					});
+					TeacherCourses = NewTeacher.TeacherCourses.ToList();
+					this.RaisePropertyChanged(nameof(Courses));
+				}
+			}
+		}
+		public Discipline? SelectedDiscipline
+		{
+			get => null;
+			set
+			{
+				if (value != null)
+				{
+					NewTeacher.TeacherDisciplines.Add(new TeacherDiscipline()
+					{
+						Teacher = NewTeacher, Discipline = value
+					});
+					TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
+					this.RaisePropertyChanged(nameof(Disciplines));
+				}
+			}
+		}
+
+       
+
+		public void DeleteDiscipline(int id)
+		{
+			NewTeacher.TeacherDisciplines.Remove(NewTeacher.TeacherDisciplines.FirstOrDefault(x => x.Id == id));
+			TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
+            this.RaisePropertyChanged(nameof(Disciplines));
+        }
+
+        public void AddTeacher()
+		{
+			if(NewTeacher.Id == 0)
+			{
+				MainWindowViewModel.myConnection.Teachers.Add(NewTeacher);
+			}
+			MainWindowViewModel.myConnection.SaveChanges();	
+		}
+    }
+}

+ 7 - 5
AvaloniaApplication5/ViewModels/ShowViewModel.cs

@@ -7,15 +7,17 @@ using AvaloniaApplication5.Models;
 using Microsoft.EntityFrameworkCore;
 namespace AvaloniaApplication5.ViewModels
 {
-    public class ShowViewModel : ReactiveObject
-	{
+    internal class ShowViewModel : ViewModelBase
+    {
         public List<Teacher> TeacherList => MainWindowViewModel.myConnection.Teachers.
                                                                        Include(x => x.Gender).
                                                                        Include(x => x.TeacherDisciplines).ThenInclude(x =>x.Discipline).
                                                                       Include(x => x.TeacherCourses).ThenInclude(x => x.Course).
             ToList();
-
-        public string chas;
-
+        public void ToAddPage()
+        {
+            MainWindowViewModel.Instance.PageContent = new AddPage();
+        }
+     
     }
 }

+ 68 - 0
AvaloniaApplication5/Views/AddPage.axaml

@@ -0,0 +1,68 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:vm="using:AvaloniaApplication5.ViewModels"
+			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+             x:Class="AvaloniaApplication5.AddPage"
+			 x:DataType="vm:AddPageViewModel" FontSize="20"
+			 >
+	<UserControl.Resources>
+		
+	</UserControl.Resources>
+	<Grid>
+		<ScrollViewer>
+
+
+			<Border BorderThickness="2" BorderBrush="Purple" CornerRadius="10" Width="600">
+			
+			<StackPanel  HorizontalAlignment="Center" >
+				<TextBlock FontWeight="Bold" Margin="40 20 0 0">Редактор</TextBlock>
+				<TextBox Watermark="Фамилия" Width="300" Margin="0 10 0 0"></TextBox>
+				<TextBox Watermark="Имя" Width="300" Margin="0 10 0 0"></TextBox>
+				<TextBox Watermark="Отчество" Width="300" Margin="0 10 0 0"></TextBox>
+				<TextBox Watermark="Почта" Width="300" Margin="0 10 0 0"></TextBox>
+				<TextBox Watermark="Телефон" Width="300" Margin="0 10 0 0"></TextBox>
+				<TextBox Watermark="Стаж" Width="300" Margin="0 10 0 0"></TextBox>
+				<ComboBox PlaceholderText="Выберите пол" ItemsSource="{Binding Genders}" Width="300" Margin="0 10 0 0" SelectedItem="{Binding NewTeacher.Gender}">
+					<ComboBox.ItemTemplate>
+						<DataTemplate>
+							<TextBlock Text="{Binding GenderName}"></TextBlock>
+						</DataTemplate>
+					</ComboBox.ItemTemplate>
+				</ComboBox>
+				<ComboBox PlaceholderText="Добавить дисциплину" ItemsSource="{Binding Disciplines}" SelectedValue="{Binding SelectedDiscipline} " Width="300" Margin="0 10 0 0">
+					<ComboBox.ItemTemplate>
+						<DataTemplate>
+							<TextBlock Text="{Binding Name}"></TextBlock>
+						</DataTemplate>
+					</ComboBox.ItemTemplate>
+				</ComboBox>
+
+				<ComboBox PlaceholderText="Добавить курс" ItemsSource="{Binding Courses}" SelectedValue="{Binding SelectedCourse} " Width="300" Margin="0 10 0 0">
+					<ComboBox.ItemTemplate>
+						<DataTemplate>
+							<TextBlock Text="{Binding Name}"></TextBlock>
+						</DataTemplate>
+					</ComboBox.ItemTemplate>
+				</ComboBox>
+
+
+				<TextBlock>Выбранные дисциплины</TextBlock>
+				<ListBox ItemsSource="{Binding TeacherDisciplines}">
+					<ListBox.ItemTemplate>
+						<DataTemplate>
+							<StackPanel>
+								<TextBlock Text="{Binding Discipline.Name}"></TextBlock>
+								<Button Command="{Binding $parent[UserControl].((vm:AddPageViewModel)DataContext).DeleteDiscipline}" CommandParameter="{Binding Id}">Удалить</Button>
+							</StackPanel>
+						</DataTemplate>
+					</ListBox.ItemTemplate>
+				</ListBox>
+				
+				
+			</StackPanel>
+				</Border>
+		</ScrollViewer>
+	</Grid>
+</UserControl>

+ 14 - 0
AvaloniaApplication5/Views/AddPage.axaml.cs

@@ -0,0 +1,14 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using AvaloniaApplication5.ViewModels;
+namespace AvaloniaApplication5;
+
+public partial class AddPage : UserControl
+{
+    public AddPage()
+    {
+        InitializeComponent();
+        DataContext = new AddPageViewModel();
+    }
+}

+ 3 - 2
AvaloniaApplication5/Views/Show.axaml

@@ -1,7 +1,8 @@
 <UserControl xmlns="https://github.com/avaloniaui"
              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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
                xmlns:vm="using:AvaloniaApplication5.ViewModels"
 			 x:DataType="vm:ShowViewModel"
@@ -11,7 +12,7 @@
 			<RowDefinition></RowDefinition>
 			<RowDefinition Height="8*"></RowDefinition>
 		</Grid.RowDefinitions>
-	
+		<Button Command="{Binding ToAddPage}">Добавить преподавателя</Button>
 		<ListBox ItemsSource="{Binding TeacherList}" Grid.Row="1" SelectionMode="Multiple">
 			<ListBox.ItemTemplate>
 				<DataTemplate>