AnnaBezaeva 2 周之前
父節點
當前提交
a7980b4033

+ 1 - 0
AvaloniaApplication5/AvaloniaApplication5.csproj

@@ -21,6 +21,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.1.0" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
+    <PackageReference Include="MessageBox.Avalonia" Version="3.0.0" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 57 - 0
AvaloniaApplication5/ViewModels/AddDisCursViewModel.cs

@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+using System.Linq;
+using System.Data;
+using AvaloniaApplication5.Models; 
+using Microsoft.EntityFrameworkCore;
+using MsBox.Avalonia;
+using MsBox.Avalonia.Enums;
+namespace AvaloniaApplication5.ViewModels
+{
+	public class AddDisCursViewModel : ViewModelBase
+    {
+		Course? _newcourse;
+		public Course? NewCourse { get => _newcourse; set => this.RaiseAndSetIfChanged(ref _newcourse, value); }
+		public List<Course> CoursesList => MainWindowViewModel.myConnection.Courses.ToList();
+
+        public AddDisCursViewModel()
+		{
+            _newcourse = new Course();
+		}
+
+        string _message = "";
+
+        public string Message
+        {
+            get => _message;
+            set => this.RaiseAndSetIfChanged(ref _message, value);
+        }
+
+
+      
+        public async void AddCourse()
+		{
+            
+			if(string.IsNullOrEmpty(NewCourse.Time) || !IsNumeric(NewCourse.Time))
+			{
+                await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", " ïîëå êîëè÷åñòâà ÷àñîâ äîëæíû áûòü òîëüêî öèôðû").ShowAsync();
+                return;
+            }
+            else
+            {
+               if (NewCourse.Id == 0)
+			   {
+                 MainWindowViewModel.myConnection.Courses.Add(NewCourse);
+               }
+               MainWindowViewModel.myConnection.SaveChanges();
+               MainWindowViewModel.Instance.PageContent = new AddPage();
+            }
+			
+        }
+        private bool IsNumeric(string value)
+        {
+            return int.TryParse(value, out _); // Èëè double.TryParse, åñëè íóæíî ïîääåðæèâàòü äðîáíûå ÷èñëà
+        }
+    }
+}

+ 57 - 7
AvaloniaApplication5/ViewModels/AddPageViewModel.cs

@@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore;
 using ReactiveUI;
 using System.Text;
 using System.Threading.Tasks;
+using MsBox.Avalonia.Enums;
+using MsBox.Avalonia;
 
 namespace AvaloniaApplication5.ViewModels
 {
@@ -36,7 +38,7 @@ namespace AvaloniaApplication5.ViewModels
             TeacherCourses = NewTeacher.TeacherCourses.ToList();
 			TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
 			
-				TextButton = "Ðåäàêòèðîâàòü";
+				TextButton = "Ñîõðàíèòü èçìåíåíèÿ";
 			
 		}
 	    public List<Gender> Genders => MainWindowViewModel.myConnection.Genders.ToList();
@@ -97,13 +99,61 @@ namespace AvaloniaApplication5.ViewModels
             TeacherCourses = NewTeacher.TeacherCourses.ToList();
             this.RaisePropertyChanged(nameof(Courses));
         }
-        public void AddTeacher()
+
+        public async void  AddTeacher()
 		{
-			if(NewTeacher.Id == 0)
-			{
-				MainWindowViewModel.myConnection.Teachers.Add(NewTeacher);
+			
+			if (NewTeacher.Id == 0 && TextButton == "Äîáàâèòü")
+
+            {
+               ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Ïîäòâåðæäåíèå äîáàâëåíèÿ",
+               "Ïîäòâåðäèòü äîáàâëåíèå ó÷èòåëÿ?", ButtonEnum.YesNo).ShowAsync();
+			   if (result == ButtonResult.Yes)
+			   {
+
+                    MainWindowViewModel.myConnection.Teachers.Add(NewTeacher);
+                    await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", "Ó÷èòåëü äîáàâëåí", ButtonEnum.Ok).ShowAsync();
+
+               }
+				else
+				{
+                    await MessageBoxManager.GetMessageBoxStandard("Îòìåíà", "Äîáàâëåíèå îòìåíåî", ButtonEnum.Ok).ShowAsync();
+                }
+				
 			}
-			MainWindowViewModel.myConnection.SaveChanges();	
-		}
+
+			else { 
+                ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Ïîäòâåðæäåíèå ðåäàêòèðîâàíèÿ",
+              "Ïîäòâåðäèòü ðåäàêòèðîâàíèå ó÷èòåëÿ?", ButtonEnum.YesNo).ShowAsync();
+                if (result == ButtonResult.Yes)
+                {
+
+                   
+                    await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", "Ó÷èòåëü îòðåäàêòèðîâàí", ButtonEnum.Ok).ShowAsync();
+
+                }
+                else
+                {
+                    await MessageBoxManager.GetMessageBoxStandard("Îòìåíà", "Ðåäàêòèðîâàíèå îòìåíåíî", ButtonEnum.Ok).ShowAsync();
+                }
+
+            }
+			MainWindowViewModel.myConnection.SaveChanges();
+            MainWindowViewModel.Instance.PageContent = new Show();
+        }
+        public void ToAddDisCurs()
+        {
+            MainWindowViewModel.Instance.PageContent = new AddDisCurs();
+        }
+        string _message = "";
+
+        public string Message
+        {
+            get => _message;
+            set => this.RaiseAndSetIfChanged(ref _message, value);
+        }
+
+        
+
     }
 }

+ 33 - 8
AvaloniaApplication5/ViewModels/ShowViewModel.cs

@@ -5,6 +5,8 @@ using ReactiveUI;
 using System.Linq;
 using AvaloniaApplication5.Models;
 using Microsoft.EntityFrameworkCore;
+using MsBox.Avalonia.Enums;
+using MsBox.Avalonia;
 
 namespace AvaloniaApplication5.ViewModels
 {
@@ -12,24 +14,47 @@ namespace AvaloniaApplication5.ViewModels
     {
         public List<Teacher> TeacherList => MainWindowViewModel.myConnection.Teachers.
                                                                        Include(x => x.Gender).
-                                                                       Include(x => x.TeacherDisciplines).ThenInclude(x =>x.Discipline).
+                                                                       Include(x => x.TeacherDisciplines).ThenInclude(x => x.Discipline).
                                                                       Include(x => x.TeacherCourses).ThenInclude(x => x.Course).
             ToList();
         public void ToAddPage()
         {
             MainWindowViewModel.Instance.PageContent = new AddPage();
         }
-        public void DeleteTeacher(int idt)
+
+        public async void DeleteTeacher(int idt)
         {
-            Teacher deleteTeacher = MainWindowViewModel.myConnection.Teachers.First(x => x.Id == idt);
-        MainWindowViewModel.myConnection.Teachers.Remove(deleteTeacher);
-            MainWindowViewModel.myConnection.SaveChanges();
-            MainWindowViewModel.Instance.PageContent = new Show();
+            // Çàïðàøèâàåì ïîäòâåðæäåíèå óäàëåíèÿ
+            ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Ïîäòâåðæäåíèå óäàëåíèÿ",
+                "Ïîäòâåðäèòü óäàëåíèå ó÷èòåëÿ?", ButtonEnum.YesNo).ShowAsync();
+
+            if (result == ButtonResult.Yes)
+            {
+                // Åñëè ïîëüçîâàòåëü ïîäòâåðäèë, óäàëÿåì ó÷èòåëÿ
+                Teacher deleteTeacher = MainWindowViewModel.myConnection.Teachers.First(x => x.Id == idt);
+                MainWindowViewModel.myConnection.Teachers.Remove(deleteTeacher);
+                MainWindowViewModel.myConnection.SaveChanges();
+                await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", "Ó÷èòåëü óäàëåí", ButtonEnum.Ok).ShowAsync();
+                MainWindowViewModel.Instance.PageContent = new Show();
+            }
+            else
+            {
+                // Åñëè ïîëüçîâàòåëü îòìåíèë, ìîæíî, íàïðèìåð, ïîêàçàòü ñîîáùåíèå
+                await MessageBoxManager.GetMessageBoxStandard("Îòìåíà", "Óäàëåíèå îòìåíåíî.", ButtonEnum.Ok).ShowAsync();
+            }
         }
+
+        string _message = "";
+
+        public string Message
+        {
+            get => _message;
+            set => this.RaiseAndSetIfChanged(ref _message, value);
+        }
+
         public void UpdateTeacher(int idt)
         {
-           
             MainWindowViewModel.Instance.PageContent = new AddPage(idt);
         }
-    }
+    }  
 }

+ 25 - 0
AvaloniaApplication5/Views/AddDisCurs.axaml

@@ -0,0 +1,25 @@
+<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:DataType="vm:AddDisCursViewModel" FontSize="20"
+			 x:Class="AvaloniaApplication5.AddDisCurs">
+	<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" Text="{Binding NewCourse.Name}"></TextBox>
+					<TextBox Watermark="Количество часов" Width="300" Margin="0 10 0 0" Text="{Binding NewCourse.Time}" ></TextBox>
+					<Button Command="{Binding AddCourse}" >Добавить</Button>
+				</StackPanel> 
+			</Border>
+			</ScrollViewer>
+	</Grid>
+   </UserControl>

+ 16 - 0
AvaloniaApplication5/Views/AddDisCurs.axaml.cs

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

+ 1 - 1
AvaloniaApplication5/Views/AddPage.axaml

@@ -48,7 +48,7 @@
 						</DataTemplate>
 					</ComboBox.ItemTemplate>
 				</ComboBox>
-
+				<Button Command="{Binding ToAddDisCurs}" >Создать курс</Button>
 
 				<TextBlock>Выбранные дисциплины</TextBlock>
 				<ListBox ItemsSource="{Binding TeacherDisciplines}">