Quellcode durchsuchen

начата работа по присваиванию свойств, остановилась на поле

ГончароваНЕ vor 6 Tagen
Ursprung
Commit
6f65d861f8

+ 6 - 0
WorkWithDatabase/Styles.axaml

@@ -57,6 +57,12 @@
 		<Setter Property="Margin" Value="20 10 0 10"></Setter>
 	</Style>
 
+	<Style Selector="TextBlock.TBChoices">
+		<Setter Property="Width" Value="350"></Setter>
+		<Setter Property="Margin" Value="20 5 0 5"></Setter>
+		<Setter Property="HorizontalAlignment" Value="Left"></Setter>
+	</Style>
+
 	<Style Selector="TextBox.Field">
 		<Setter Property="Width" Value="350"></Setter>
 		<Setter Property="Margin" Value="20 10 0 10"></Setter>

+ 44 - 10
WorkWithDatabase/ViewModels/PageAddTeacherVM.cs

@@ -1,4 +1,5 @@
-using Microsoft.EntityFrameworkCore;
+using Avalonia.Media;
+using Microsoft.EntityFrameworkCore;
 using ReactiveUI;
 using System;
 using System.Collections.Generic;
@@ -17,16 +18,7 @@ namespace WorkWithDatabase.ViewModels
         }
 
         Teacher? _newTeaher;
-
-        List<TeacherCourse> _courseTable;
-        List<TeacherSubject> _subjectTable;
-
-        public List<TeacherCourse> CourseTable { get => _courseTable; set => this.RaiseAndSetIfChanged(ref _courseTable, value); }
-
-        public List<TeacherSubject> SubjectTable { get => _subjectTable; set => this.RaiseAndSetIfChanged(ref _subjectTable, value); }
-
         public Teacher? NewTeaher { get => _newTeaher; set => this.RaiseAndSetIfChanged(ref _newTeaher, value); }
-        
 
         public PageAddTeacherVM()
         {
@@ -42,5 +34,47 @@ namespace WorkWithDatabase.ViewModels
             CourseTable = NewTeaher.TeacherCourses.ToList();
             SubjectTable = NewTeaher.TeacherSubjects.ToList();
         }
+
+        public List<Gender> Genders => MainWindowViewModel.myConnection.Genders.ToList();
+        public List<Subject> Subjects => MainWindowViewModel.myConnection.Subjects.ToList().Except(_newTeaher.TeacherSubjects.Select(x => x.SubjectNavigation)).ToList();
+        public List<Course> Courses => MainWindowViewModel.myConnection.Courses.ToList().Except(_newTeaher.TeacherCourses.Select(x => x.CourseNavigation)).ToList();
+
+        List<TeacherCourse>? _courseTable;
+        public List<TeacherCourse>? CourseTable { get => _courseTable; set => this.RaiseAndSetIfChanged(ref _courseTable, value); }
+        List<TeacherSubject>? _subjectTable; 
+        public List<TeacherSubject>? SubjectTable { get => _subjectTable; set => this.RaiseAndSetIfChanged(ref _subjectTable, value); }
+       
+        Course? selectedCourse;
+        Subject? selectedSubject;
+
+        public Course? SelectedCourse 
+        { 
+            get => null;
+            set
+            {
+                if (value != null)
+                {
+                    NewTeaher.TeacherCourses.Add(new TeacherCourse() { TeacherNavigation = NewTeaher, CourseNavigation = value });
+                    CourseTable = NewTeaher.TeacherCourses.ToList();
+                    this.RaisePropertyChanged(nameof(Courses));
+                }
+            }
+        }
+
+        public Subject? SelectedSubject
+        {
+            get => null;
+            set
+            {
+                if (value != null)
+                {
+                    NewTeaher.TeacherSubjects.Add(new TeacherSubject() { TeacherNavigation = NewTeaher, SubjectNavigation = value });
+                    SubjectTable = NewTeaher.TeacherSubjects.ToList();
+                    this.RaisePropertyChanged(nameof(Subjects));
+                }
+            }
+        }
+
+
     }
 }

+ 7 - 5
WorkWithDatabase/Views/PageAddTeacher.axaml

@@ -15,16 +15,18 @@
 					<Button Classes="BtEd" Command="{Binding ToMainPage}">Отменить</Button>
 					<Button Classes="BtEd" Command="{Binding }">Сохранить</Button>
 				</StackPanel>
-				<TextBox Classes="Field" Text="" Watermark="Введите фамилию преподавателя"></TextBox>
-				<TextBox Classes="Field" Text="" Watermark="Введите имя преподавателя"></TextBox>
-				<TextBox  Classes="Field" Text="" Watermark="Введите отчество преподавателя"></TextBox>
-				<ComboBox ItemsSource="" SelectedItem="" Classes="FieldChoices">
+				<TextBox Classes="Field" Text="{Binding NewTeaher.Surname}" Watermark="Введите фамилию преподавателя"></TextBox>
+				<TextBox Classes="Field" Text="{Binding NewTeaher.Name}" Watermark="Введите имя преподавателя"></TextBox>
+				<TextBox  Classes="Field" Text="{Binding NewTeaher.Patronymic}" Watermark="Введите отчество преподавателя"></TextBox>
+				<TextBlock Classes="TBChoices">Выберите пол преподавателя:</TextBlock>
+				<ComboBox ItemsSource="{Binding Genders}" SelectedItem="{Binding NewTeaher.GenderNavigation}" Classes="FieldChoices">
 					<ComboBox.ItemTemplate>
 						<DataTemplate>
-							<TextBlock Text=""></TextBlock>
+							<TextBlock Text="{Binding TitleGender}"></TextBlock>
 						</DataTemplate>
 					</ComboBox.ItemTemplate>
 				</ComboBox>
+				<TextBlock Classes="TBChoices">Введите день рождение преподавателя:</TextBlock>
 				<DatePicker Classes="FieldDate" SelectedDate=""></DatePicker>
 				<TextBox Classes="Field" Text="" Watermark="Введите стаж в количестве месяцов"></TextBox>
 				<TextBox Classes="Field" Text="" Watermark="Введите почту"></TextBox>