From 597981281f86596db5124bd92f154e5ea071f341 Mon Sep 17 00:00:00 2001 From: wangxiner55 <1468441589@qq.com> Date: Mon, 30 Sep 2024 18:58:56 +0800 Subject: [PATCH] All Finished --- StudentManager/Common/ErrorSet.cs | 2 +- StudentManager/Common/FileSystem.cs | 20 ++- StudentManager/Common/HomeWorkManager.cs | 31 +++- StudentManager/Common/HomeWorkSet.cs | 4 +- StudentManager/Common/SQLHelper.cs | 6 +- StudentManager/Common/Tool.cs | 36 +++++ StudentManager/Data/QuestionLib.cs | 39 +++-- StudentManager/Data/StudentInfo.cs | 10 +- StudentManager/Editor/MainEditor.xaml | 42 ++++- StudentManager/Editor/MainEditor.xaml.cs | 34 +++- StudentManager/Event/MessageEvent.cs | 13 ++ StudentManager/Extensions/DialogExtensions.cs | 22 +++ StudentManager/Model/Students.cs | 148 ++++++++++++------ 13 files changed, 317 insertions(+), 90 deletions(-) create mode 100644 StudentManager/Common/Tool.cs create mode 100644 StudentManager/Event/MessageEvent.cs create mode 100644 StudentManager/Extensions/DialogExtensions.cs diff --git a/StudentManager/Common/ErrorSet.cs b/StudentManager/Common/ErrorSet.cs index 7608cd5..c46f11c 100644 --- a/StudentManager/Common/ErrorSet.cs +++ b/StudentManager/Common/ErrorSet.cs @@ -92,7 +92,7 @@ namespace StudentManager.Common { list.Add(new DetailErrorInfo { - QuestionData = QuestionLib.Get(item.Key), + QuestionData = QuestionLib.Instance.Get(item.Key), CorrectCount = item.Value.CorrectCount, ErrorCount = item.Value.ErrorCount, TotalUseCount = item.Value.TotalUseCount, diff --git a/StudentManager/Common/FileSystem.cs b/StudentManager/Common/FileSystem.cs index 6dec314..0995257 100644 --- a/StudentManager/Common/FileSystem.cs +++ b/StudentManager/Common/FileSystem.cs @@ -10,18 +10,34 @@ namespace StudentManager.Common { public class FileSystem : Singleton { + public Action AutoSaveInvoke { get; set; } + + + + public void SaveAll() { StudentLib.Save(); - QuestionLib.Save(); + QuestionLib.Instance.Save(); } public void FreashAllInfo() { StudentLib.FreshAllStudentInfo(); - QuestionLib.FreshAllQuestion(); + QuestionLib.Instance.FreshAllQuestion(); SaveAll(); } + + public async void AutoSave(int time = 1) + { + await Task.Delay(time * 60 * 1000); + AutoSaveInvoke?.Invoke(); + + await Task.Delay(10000); + SaveAll(); + + AutoSave(time); + } } } diff --git a/StudentManager/Common/HomeWorkManager.cs b/StudentManager/Common/HomeWorkManager.cs index 0bc2eaa..43dd9e0 100644 --- a/StudentManager/Common/HomeWorkManager.cs +++ b/StudentManager/Common/HomeWorkManager.cs @@ -11,15 +11,34 @@ using System.Threading.Tasks; namespace StudentManager.Common { + public class HomeWorkError + { + public int Total { get; set; } + public int Error { get; set; } + public int Correct { get; set; } + } + + public class HomeWorkManager : Singleton { - public void PublicHomework(uint lesson, bool appedCommonWork = false, bool appendErrorSet = false, int workNum = -1) + public HomeWorkError PublicHomework(uint lesson, bool appedCommonWork = false, bool appendErrorSet = false, int workNum = -1) { - foreach (var item in StudentLib.StudentDic) - { - item.Value.PublicHomeWork(lesson, appedCommonWork, appendErrorSet, workNum); - } - } + HomeWorkError error= new HomeWorkError(); + foreach (var item in StudentLib.StudentDic) + { + if (item.Value.PublicHomeWork(lesson, appedCommonWork, appendErrorSet, workNum)) + { + error.Total++; + error.Correct++; + } + else + { + error.Total++; + error.Error++; + } + } + return error; + } internal void DeleteHomework(DetailHomeWorkSetInfo homeWork) { diff --git a/StudentManager/Common/HomeWorkSet.cs b/StudentManager/Common/HomeWorkSet.cs index 9bd5667..fd583e6 100644 --- a/StudentManager/Common/HomeWorkSet.cs +++ b/StudentManager/Common/HomeWorkSet.cs @@ -56,7 +56,7 @@ namespace StudentManager.Common //QuestionData = { // QuestionData = QuestionLib.Get(item.ID), // Status = item.Status }, - QuestionData = QuestionLib.Get(item.ID), + QuestionData = QuestionLib.Instance.Get(item.ID), Status = Status, //Lesson = Lesson, //DateTime = DateTime, @@ -200,7 +200,7 @@ namespace StudentManager.Common { list.Add(new DetailHomeWorkInfo { - QuestionData = QuestionLib.Get(item.ID), + QuestionData = QuestionLib.Instance.Get(item.ID), Status = item.Status, PID = item.ID }); diff --git a/StudentManager/Common/SQLHelper.cs b/StudentManager/Common/SQLHelper.cs index 4100c46..fe2bc24 100644 --- a/StudentManager/Common/SQLHelper.cs +++ b/StudentManager/Common/SQLHelper.cs @@ -238,8 +238,8 @@ namespace StudentManager.Common } string sql = $"DELETE " + - $"FROM {tableName}" + - "WHERE problem_id = @problem_id"; + $"FROM {tableName} " + + " WHERE problem_id = @problem_id"; using (var cmd = new MySqlCommand(sql, connection)) { @@ -423,7 +423,7 @@ namespace StudentManager.Common { connection.Open(); - string updateQuery = "UPDATE users SET total_hwq_count = @totalCont, total_hwq_error_count = @totalErrorCount, " + + string updateQuery = "UPDATE users SET total_hwq_count = @totalCont, total_hwq_error_count = @totalErrorCount " + "WHERE user_id = @user_id"; using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection)) { diff --git a/StudentManager/Common/Tool.cs b/StudentManager/Common/Tool.cs new file mode 100644 index 0000000..b0c5aec --- /dev/null +++ b/StudentManager/Common/Tool.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json.Linq; +using StudentManager.Interface; +using System.Net.Http; +using System.Windows.Threading; + + +namespace StudentManager.Common +{ + + public class Timer + { + private DispatcherTimer _timer; + private Action _onMinuteChanged; + private int _lastMinute; + + public Timer(Action onMinuteChanged) + { + _onMinuteChanged = onMinuteChanged; + _timer = new DispatcherTimer(); + _timer.Interval = TimeSpan.FromSeconds(1); + _timer.Tick += Timer_Tick; + _timer.Start(); + _lastMinute = DateTime.Now.Minute; + } + + private void Timer_Tick(object sender, EventArgs e) + { + var now = DateTime.Now; + if (now.Minute != _lastMinute) + { + _onMinuteChanged?.Invoke(); + _lastMinute = now.Minute; + } + } + } +} diff --git a/StudentManager/Data/QuestionLib.cs b/StudentManager/Data/QuestionLib.cs index b922ca1..19f2054 100644 --- a/StudentManager/Data/QuestionLib.cs +++ b/StudentManager/Data/QuestionLib.cs @@ -1,6 +1,7 @@ using Google.Protobuf.WellKnownTypes; using Microsoft.VisualBasic; using StudentManager.Common; +using StudentManager.Interface; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -22,7 +23,7 @@ namespace StudentManager.Data } - public static class QuestionLib + public class QuestionLib : Singleton { public static string FileName = "questionLib.dbqi"; public static string TableDicFileName = "questionTableDicLib.dbqi"; @@ -32,7 +33,7 @@ namespace StudentManager.Data public static Dictionary> QuestionTableDic { get; set; } = new Dictionary>(); public static int TotalCount { get { return QuestionDic.Count; } } - public static void Load() + public void Load() { QuestionDic.Clear(); @@ -57,14 +58,14 @@ namespace StudentManager.Data if (file.Length != 0) QuestionTableDesc = JsonSerializer.Deserialize>(file); } - public static void Save() + public void Save() { File.WriteAllText((StudentLib.LibPath + FileName), JsonSerializer.Serialize(QuestionDic)); File.WriteAllText((StudentLib.LibPath + TableDicFileName), JsonSerializer.Serialize(QuestionTableDic)); File.WriteAllText((StudentLib.LibPath + TableDescFileName), JsonSerializer.Serialize(QuestionTableDesc)); } - public static void FreshAllQuestion() + public void FreshAllQuestion() { QuestionDic.Clear (); @@ -90,7 +91,7 @@ namespace StudentManager.Data } } - public static ObservableCollection GetAllQuestion() + public ObservableCollection GetAllQuestion() { var list = new ObservableCollection(); foreach (QuestionData data in QuestionDic.Values) @@ -99,7 +100,7 @@ namespace StudentManager.Data } return list; } - public static ObservableCollection GetAllQuestionByLesson(uint lesson) + public ObservableCollection GetAllQuestionByLesson(uint lesson) { var list = new ObservableCollection(); foreach (QuestionData data in QuestionTableDic[lesson].Values) @@ -109,24 +110,28 @@ namespace StudentManager.Data return list; } - public static QuestionData Get(int id) + public QuestionData Get(int id) { if (!QuestionDic.ContainsKey(id)) return null; return QuestionDic[id]; } - public static QuestionData Get(uint lesson , int id) + public QuestionData Get(uint lesson , int id) { if (!QuestionDic.ContainsKey(id)) return null; return QuestionDic[id]; } - public static void Add(QuestionData question) + public bool Add(QuestionData question) { + if(question == null) return false; + if(QuestionDic.ContainsKey(question.Id)) return false; + if (!SQLHelper.Instance.Add(question)) return false; + + QuestionDic.Add(question.Id, question); - if (!QuestionTableDic.ContainsKey(question.Lesson)) { QuestionTableDic[question.Lesson] = new Dictionary(); @@ -135,25 +140,25 @@ namespace StudentManager.Data QuestionTableDesc[question.Lesson].UpdateTime = DateTime.Now; QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count; - - SQLHelper.Instance.Add(question); + return true; } - public static void Remove(QuestionData question) + public bool Remove(QuestionData question) { - if (question == null) throw new NullReferenceException(); - QuestionDic.Remove(question.Id); + if (question == null || !QuestionDic.ContainsKey(question.Id) || !QuestionTableDic[question.Lesson].ContainsKey(question.Id)) return false; + QuestionDic.Remove(question.Id); QuestionTableDic[question.Lesson].Remove(question.Id); QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count; + return true; } - public static void Remove(int id) + public void Remove(int id) { QuestionDic.Remove(id); } - internal static void Update(QuestionData selectedQuestion) + internal void Update(QuestionData selectedQuestion) { if(QuestionDic[selectedQuestion.Id] != null) QuestionDic[selectedQuestion.Id] = selectedQuestion; diff --git a/StudentManager/Data/StudentInfo.cs b/StudentManager/Data/StudentInfo.cs index cc41bae..4278a44 100644 --- a/StudentManager/Data/StudentInfo.cs +++ b/StudentManager/Data/StudentInfo.cs @@ -126,7 +126,7 @@ namespace StudentManager.Data public uint CurrentHomeWorkIndex = 0; public HomeWork CurentHomeWork { get; set; } = new HomeWork(); - public void PublicHomeWork(uint lesson, bool appendCommonWork = false, bool appendErrorSet = false, int workNum = -1) + public bool PublicHomeWork(uint lesson, bool appendCommonWork = false, bool appendErrorSet = false, int workNum = -1) { HomeWork homeWork = new HomeWork(); homeWork.Lesson = (uint)(HomeWorkSet.TotalSetCount + 1); @@ -142,7 +142,7 @@ namespace StudentManager.Data } if (appendCommonWork) { - foreach (var item in QuestionLib.GetAllQuestionByLesson(lesson)) + foreach (var item in QuestionLib.Instance.GetAllQuestionByLesson(lesson)) { homeWork.AddHomeWork(item.Id); } @@ -174,10 +174,14 @@ namespace StudentManager.Data { HomeWorkSet.AddHomeWork(homeWork); HomeWorkSet.UpdateDate(); + + SQLHelper.Instance.UpdateHomeworkTotalInfo(UID, (uint)HomeWorkSet.TotalQuestionCount, (uint)HomeWorkSet.TotalErrorQuestionCount); + CurentHomeWork = homeWork; + return true; } else { - //TODO: NOTIFY + return false; } } } diff --git a/StudentManager/Editor/MainEditor.xaml b/StudentManager/Editor/MainEditor.xaml index e8eb080..2baaa9f 100644 --- a/StudentManager/Editor/MainEditor.xaml +++ b/StudentManager/Editor/MainEditor.xaml @@ -9,6 +9,7 @@ xmlns:extent="clr-namespace:StudentManager.Extensions" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:dt="clr-namespace:StudentManager.Data" + xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes" Background="#00000000" WindowStyle="None" mc:Ignorable="d" Title="MainEditor" Height="800" Width="1400"> @@ -48,7 +49,7 @@ - + @@ -57,20 +58,45 @@ - + - - - - + + + + - + + + + + + + - + + + + + + + + + + + diff --git a/StudentManager/Editor/MainEditor.xaml.cs b/StudentManager/Editor/MainEditor.xaml.cs index 8dd35ae..52e6a2e 100644 --- a/StudentManager/Editor/MainEditor.xaml.cs +++ b/StudentManager/Editor/MainEditor.xaml.cs @@ -1,5 +1,6 @@ using StudentManager.Common; using StudentManager.Data; +using StudentManager.Extensions; using System; using System.Collections.Generic; using System.Linq; @@ -18,9 +19,40 @@ namespace StudentManager.Editor { public partial class MainEditor : Window { - public MainEditor() + private readonly IEventAggregator eventAggregator; + + public MainEditor(IEventAggregator aggregator) { InitializeComponent(); + this.eventAggregator = eventAggregator; + + aggregator.ResgiterMessage(arg => + { + SnackBar.MessageQueue.Enqueue(arg); + }); + + Bar.MouseMove += (s, e) => + { + if(e.LeftButton == MouseButtonState.Pressed) + this.DragMove(); + }; + + Bar.MouseDoubleClick += (s, e) => + { + if (this.WindowState == WindowState.Normal) + this.WindowState = WindowState.Maximized; + else + this.WindowState = WindowState.Normal; + }; + + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + var c = MessageBox.Show("确定退出吗?", "确认", MessageBoxButton.OKCancel); + if (c != MessageBoxResult.OK) return; + FileSystem.Instance.SaveAll(); + this.Close(); } } } diff --git a/StudentManager/Event/MessageEvent.cs b/StudentManager/Event/MessageEvent.cs new file mode 100644 index 0000000..7ecb7aa --- /dev/null +++ b/StudentManager/Event/MessageEvent.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentManager.Event +{ + public class MessageEvent : PubSubEvent + { + + } +} diff --git a/StudentManager/Extensions/DialogExtensions.cs b/StudentManager/Extensions/DialogExtensions.cs new file mode 100644 index 0000000..0b1af78 --- /dev/null +++ b/StudentManager/Extensions/DialogExtensions.cs @@ -0,0 +1,22 @@ +using StudentManager.Event; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentManager.Extensions +{ + internal static class DialogExtensions + { + public static void ResgiterMessage(this IEventAggregator aggregator, Action message) + { + aggregator.GetEvent().Subscribe(message); + } + + public static void SendMessage(this IEventAggregator aggregator, string message) + { + aggregator.GetEvent().Publish(message); + } + } +} diff --git a/StudentManager/Model/Students.cs b/StudentManager/Model/Students.cs index 5975c73..c102dad 100644 --- a/StudentManager/Model/Students.cs +++ b/StudentManager/Model/Students.cs @@ -2,6 +2,7 @@ using LiveCharts; using LiveCharts.Wpf; using Mysqlx.Crud; +using MySqlX.XDevAPI.Common; using Newtonsoft.Json; using Org.BouncyCastle.Utilities; using StudentManager.Common; @@ -18,6 +19,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using Timer = StudentManager.Common.Timer; namespace StudentManager.Model { @@ -209,7 +211,18 @@ namespace StudentManager.Model set { labels = value; RaisePropertyChanged(); } } + + private string currentTime; + + public string CurrentTime + { + get { return currentTime; } + set { currentTime = value; RaisePropertyChanged(); } + } + + private readonly IRegionManager regionManager; + private readonly IEventAggregator aggregator; public DelegateCommand RegionTo { get; set; } public DelegateCommand SelectedCommand { get; set; } @@ -230,9 +243,23 @@ namespace StudentManager.Model public DelegateCommand PublicHomeWorkCommand { get; set; } public DelegateCommand FreshAllCommand { get; set; } - Students(IRegionManager regionManager) + Students(IRegionManager regionManager, IEventAggregator aggregator) { + + CreateMenuBar(); + CurrentTime = DateTime.Now.ToString("HH:mm"); + + Timer timer = new Timer(() => { + CurrentTime = DateTime.Now.ToString("HH:mm"); + }); + + FileSystem.Instance.AutoSaveInvoke += () => + { + aggregator.SendMessage(" 将在10秒后自动保存 "); + }; + + FileSystem.Instance.AutoSave(); RegionTo = new DelegateCommand((x) => { @@ -275,11 +302,20 @@ namespace StudentManager.Model DeleteQuestionCommand = new DelegateCommand(() => { - if (SelectedQuestion == null) return; + if (SelectedQuestion == null) + { + aggregator.SendMessage($" 当前没有选中任何题目 "); + return; + } var c = MessageBox.Show("确定删除吗?", "确认", MessageBoxButton.OKCancel); if (c != MessageBoxResult.OK) return; - QuestionLib.Remove(SelectedQuestion); - QuestionDatas = QuestionLib.GetAllQuestion(); + if (!SQLHelper.Instance.Delete(SelectedQuestion)) return; + QuestionLib.Instance.Remove(SelectedQuestion); + QuestionDatas = QuestionLib.Instance.GetAllQuestion(); + aggregator.SendMessage($" 成功删除 "); + + FileSystem.Instance.SaveAll(); + }); UpdateQuestionCommand = new DelegateCommand(() => @@ -287,23 +323,13 @@ namespace StudentManager.Model if (SelectedQuestion == null) return; var c = MessageBox.Show("确定修改吗?", "确认", MessageBoxButton.OKCancel); if (c != MessageBoxResult.OK) return; - QuestionLib.Update(SelectedQuestion); + QuestionLib.Instance.Update(SelectedQuestion); SelectedQuestion.UpdateTime = DateTime.Now; SQLHelper.Instance.UpdateQuestion(SelectedQuestion); - }); - ShowContextMenuCommand = new DelegateCommand((e) => - { - if (e.OriginalSource is FrameworkElement element) - { - var contextMenu = element.FindResource("MyContextMenu") as ContextMenu; - if (contextMenu != null) - { - contextMenu.PlacementTarget = element; - contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; - contextMenu.IsOpen = true; - } - } + aggregator.SendMessage("已更新问题信息"); + + FileSystem.Instance.SaveAll(); }); SelectedQuestionChangedCommand = new DelegateCommand((x) => @@ -313,19 +339,6 @@ namespace StudentManager.Model }); - RemoveNewColumnCommand = new DelegateCommand((x) => - { - if (x == null) return; - var c = MessageBox.Show("确定删除吗?", "确认", MessageBoxButton.OKCancel); - if (c != MessageBoxResult.OK) return; - ADDQuestionDatas.Remove(x); - }); - - AddNewColumnCommand = new DelegateCommand(() => - { - ADDQuestionDatas.Add(new QuestionData { }); - }); - ClearnAddQuestionsCommand = new DelegateCommand(() => { var c = MessageBox.Show("确定清除吗?", "清除所有题目", MessageBoxButton.OKCancel); @@ -341,7 +354,8 @@ namespace StudentManager.Model }); PublicHomeWorkCommand = new DelegateCommand(() => { - HomeWorkManager.Instance.PublicHomework(PublicLesson, IsAddPublicQuestionsLib, isNeedErrorset); + var result = HomeWorkManager.Instance.PublicHomework(PublicLesson, IsAddPublicQuestionsLib, isNeedErrorset); + aggregator.SendMessage($"总发布{result.Total}个作业, {result.Correct}已发布, {result.Error}未发布"); }); @@ -349,15 +363,20 @@ namespace StudentManager.Model { var cq = new CursonQuestionsData { Lesson = SelectedHomeWorkSet.Lesson, UID = SelectedStudent.UID }; - - if(!SQLHelper.Instance.Delete(cq)) + + if (!SQLHelper.Instance.Delete(cq)) { - //TODO: NOTIFY: + aggregator.SendMessage(" 服务器删除失败 "); return; } if (SelectedHomeWorkSet != null && SelectedStudent != null) SelectedStudent.HomeWorkSet.DeleteHomework(SelectedHomeWorkSet.Lesson); + else + { + aggregator.SendMessage(" 本地数据错误,已为你从服务器更新 "); + QuestionLib.Instance.FreshAllQuestion(); + } if (SelectedStudent != null) { @@ -366,6 +385,11 @@ namespace StudentManager.Model } + aggregator.SendMessage(" 删除成功 "); + + + FileSystem.Instance.SaveAll(); + }); @@ -375,13 +399,21 @@ namespace StudentManager.Model Debug.Assert(Lesson != 0); + preToRemove.Clear(); + foreach (var item in ADDQuestionDatas) { item.Id = ConvertToHashInt(item.Stem); item.Lesson = Lesson; - if (!(QuestionLib.Get(item.Id) == null)) continue; + if (!(QuestionLib.Instance.Get(item.Id) == null)) continue; if (string.IsNullOrEmpty(item.Stem) || string.IsNullOrEmpty(item.Source) || string.IsNullOrEmpty(item.Answer)) continue; - QuestionLib.Add(item); + if (!SQLHelper.Instance.Add(item)) + { + aggregator.SendMessage($" {item.Stem}服务器添加失败, ID 可能重复 "); + continue; + } + + QuestionLib.Instance.Add(item); preToRemove.Add(item); } @@ -390,7 +422,9 @@ namespace StudentManager.Model ADDQuestionDatas.Remove(item); } - QuestionLib.Save(); + aggregator.SendMessage($" {preToRemove.Count}添加成功, {ADDQuestionDatas.Count}添加失败 "); + + QuestionLib.Instance.Save(); }); @@ -406,12 +440,12 @@ namespace StudentManager.Model UpdateGird(); this.regionManager = regionManager; - + this.aggregator = aggregator; } private void UpdateGird() { - if(SelectedStudent == null) return; + if (SelectedStudent == null) return; SelectedStudent.HomeWorkSet.UpdateDataView(); @@ -431,7 +465,7 @@ namespace StudentManager.Model Labels = SelectedStudent.HomeWorkSet.Lessons; } - + private int ConvertToHashInt(string item) { @@ -445,17 +479,30 @@ namespace StudentManager.Model private void UpdateHomeWork() { // update error set and local homework + + bool isChanged = false; + SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Questions.ForEach(x => { if (x.Status != HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status || selectedHomeWorkSet.Status == false) { + isChanged = true; x.Status = HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status; SelectedStudent.ErrorSet.AddQuestion(x); - ErrorBase error = SelectedStudent.ErrorSet.Get(x.ID) ?? new ErrorBase { QuestionBase = new QuestionBase { ID = x.ID, Status = x.Status} }; - SQLHelper.Instance.UpdateErrorSet(SelectedStudent.UID, error); + ErrorBase error = SelectedStudent.ErrorSet.Get(x.ID) ?? new ErrorBase { QuestionBase = new QuestionBase { ID = x.ID, Status = x.Status } }; + if (!SQLHelper.Instance.UpdateErrorSet(SelectedStudent.UID, error)) + { + aggregator.SendMessage($"{error.QuestionBase.ID} 更新错题集数据失败"); + } } - }); + + if (!isChanged) + { + aggregator.SendMessage($" 当前作业没有变更 "); + return; + } + SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).UpdateData(); SelectedStudent.HomeWorkSet.UpdateDate(); SQLHelper.Instance.UpdateErrorSetUserInfo(SelectedStudent.UID, (uint)SelectedStudent.ErrorSet.TotalCount, (uint)SelectedStudent.ErrorSet.CorrectCount); @@ -476,7 +523,14 @@ namespace StudentManager.Model SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Status); + SQLHelper.Instance.UpdateHomeworkTotalInfo(SelectedStudent.UID, (uint)SelectedStudent.HomeWorkSet.TotalQuestionCount, (uint)SelectedStudent.HomeWorkSet.TotalErrorQuestionCount); + aggregator.SendMessage($" 更新错题集数据和家庭作业成功 "); + selectedHomeWorkSet.Status = true; + + + HomeWorkSet = SelectedStudent.HomeWorkSet.GetDetailHomeWorkSetList(); + FileSystem.Instance.SaveAll(); //TODO: Notify } @@ -516,7 +570,7 @@ namespace StudentManager.Model private void Load() { StudentLib.Load(); - QuestionLib.Load(); + QuestionLib.Instance.Load(); Reload(); } @@ -525,7 +579,7 @@ namespace StudentManager.Model studentDatas.Clear(); questionDatas.Clear(); StudentDatas = StudentLib.GetAllStudents(); - QuestionDatas = QuestionLib.GetAllQuestion(); + QuestionDatas = QuestionLib.Instance.GetAllQuestion(); } @@ -534,7 +588,7 @@ namespace StudentManager.Model HomeworkTestData.Clear(); if (IsAddPublicQuestionsLib) { - HomeworkTestData = QuestionLib.GetAllQuestionByLesson(PublicLesson); + HomeworkTestData = QuestionLib.Instance.GetAllQuestionByLesson(PublicLesson); } if (IsNeedErrorset) {