All Finished

This commit is contained in:
wangxiner55 2024-09-30 18:58:56 +08:00
parent 6ace9eabd8
commit 597981281f
13 changed files with 317 additions and 90 deletions

View File

@ -92,7 +92,7 @@ namespace StudentManager.Common
{ {
list.Add(new DetailErrorInfo list.Add(new DetailErrorInfo
{ {
QuestionData = QuestionLib.Get(item.Key), QuestionData = QuestionLib.Instance.Get(item.Key),
CorrectCount = item.Value.CorrectCount, CorrectCount = item.Value.CorrectCount,
ErrorCount = item.Value.ErrorCount, ErrorCount = item.Value.ErrorCount,
TotalUseCount = item.Value.TotalUseCount, TotalUseCount = item.Value.TotalUseCount,

View File

@ -10,18 +10,34 @@ namespace StudentManager.Common
{ {
public class FileSystem : Singleton<FileSystem> public class FileSystem : Singleton<FileSystem>
{ {
public Action AutoSaveInvoke { get; set; }
public void SaveAll() public void SaveAll()
{ {
StudentLib.Save(); StudentLib.Save();
QuestionLib.Save(); QuestionLib.Instance.Save();
} }
public void FreashAllInfo() public void FreashAllInfo()
{ {
StudentLib.FreshAllStudentInfo(); StudentLib.FreshAllStudentInfo();
QuestionLib.FreshAllQuestion(); QuestionLib.Instance.FreshAllQuestion();
SaveAll(); SaveAll();
} }
public async void AutoSave(int time = 1)
{
await Task.Delay(time * 60 * 1000);
AutoSaveInvoke?.Invoke();
await Task.Delay(10000);
SaveAll();
AutoSave(time);
}
} }
} }

View File

@ -11,15 +11,34 @@ using System.Threading.Tasks;
namespace StudentManager.Common 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<HomeWorkManager> public class HomeWorkManager : Singleton<HomeWorkManager>
{ {
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) HomeWorkError error= new HomeWorkError();
{ foreach (var item in StudentLib.StudentDic)
item.Value.PublicHomeWork(lesson, appedCommonWork, appendErrorSet, workNum); {
} if (item.Value.PublicHomeWork(lesson, appedCommonWork, appendErrorSet, workNum))
} {
error.Total++;
error.Correct++;
}
else
{
error.Total++;
error.Error++;
}
}
return error;
}
internal void DeleteHomework(DetailHomeWorkSetInfo homeWork) internal void DeleteHomework(DetailHomeWorkSetInfo homeWork)
{ {

View File

@ -56,7 +56,7 @@ namespace StudentManager.Common
//QuestionData = { //QuestionData = {
// QuestionData = QuestionLib.Get(item.ID), // QuestionData = QuestionLib.Get(item.ID),
// Status = item.Status }, // Status = item.Status },
QuestionData = QuestionLib.Get(item.ID), QuestionData = QuestionLib.Instance.Get(item.ID),
Status = Status, Status = Status,
//Lesson = Lesson, //Lesson = Lesson,
//DateTime = DateTime, //DateTime = DateTime,
@ -200,7 +200,7 @@ namespace StudentManager.Common
{ {
list.Add(new DetailHomeWorkInfo list.Add(new DetailHomeWorkInfo
{ {
QuestionData = QuestionLib.Get(item.ID), QuestionData = QuestionLib.Instance.Get(item.ID),
Status = item.Status, Status = item.Status,
PID = item.ID PID = item.ID
}); });

View File

@ -238,8 +238,8 @@ namespace StudentManager.Common
} }
string sql = $"DELETE " + string sql = $"DELETE " +
$"FROM {tableName}" + $"FROM {tableName} " +
"WHERE problem_id = @problem_id"; " WHERE problem_id = @problem_id";
using (var cmd = new MySqlCommand(sql, connection)) using (var cmd = new MySqlCommand(sql, connection))
{ {
@ -423,7 +423,7 @@ namespace StudentManager.Common
{ {
connection.Open(); 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"; "WHERE user_id = @user_id";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection)) using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{ {

View File

@ -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;
}
}
}
}

View File

@ -1,6 +1,7 @@
using Google.Protobuf.WellKnownTypes; using Google.Protobuf.WellKnownTypes;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using StudentManager.Common; using StudentManager.Common;
using StudentManager.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -22,7 +23,7 @@ namespace StudentManager.Data
} }
public static class QuestionLib public class QuestionLib : Singleton<QuestionLib>
{ {
public static string FileName = "questionLib.dbqi"; public static string FileName = "questionLib.dbqi";
public static string TableDicFileName = "questionTableDicLib.dbqi"; public static string TableDicFileName = "questionTableDicLib.dbqi";
@ -32,7 +33,7 @@ namespace StudentManager.Data
public static Dictionary<uint, Dictionary<int, QuestionData>> QuestionTableDic { get; set; } = new Dictionary<uint, Dictionary<int, QuestionData>>(); public static Dictionary<uint, Dictionary<int, QuestionData>> QuestionTableDic { get; set; } = new Dictionary<uint, Dictionary<int, QuestionData>>();
public static int TotalCount { get { return QuestionDic.Count; } } public static int TotalCount { get { return QuestionDic.Count; } }
public static void Load() public void Load()
{ {
QuestionDic.Clear(); QuestionDic.Clear();
@ -57,14 +58,14 @@ namespace StudentManager.Data
if (file.Length != 0) if (file.Length != 0)
QuestionTableDesc = JsonSerializer.Deserialize<Dictionary<uint, QuestionSetDesc>>(file); QuestionTableDesc = JsonSerializer.Deserialize<Dictionary<uint, QuestionSetDesc>>(file);
} }
public static void Save() public void Save()
{ {
File.WriteAllText((StudentLib.LibPath + FileName), JsonSerializer.Serialize(QuestionDic)); File.WriteAllText((StudentLib.LibPath + FileName), JsonSerializer.Serialize(QuestionDic));
File.WriteAllText((StudentLib.LibPath + TableDicFileName), JsonSerializer.Serialize(QuestionTableDic)); File.WriteAllText((StudentLib.LibPath + TableDicFileName), JsonSerializer.Serialize(QuestionTableDic));
File.WriteAllText((StudentLib.LibPath + TableDescFileName), JsonSerializer.Serialize(QuestionTableDesc)); File.WriteAllText((StudentLib.LibPath + TableDescFileName), JsonSerializer.Serialize(QuestionTableDesc));
} }
public static void FreshAllQuestion() public void FreshAllQuestion()
{ {
QuestionDic.Clear (); QuestionDic.Clear ();
@ -90,7 +91,7 @@ namespace StudentManager.Data
} }
} }
public static ObservableCollection<QuestionData> GetAllQuestion() public ObservableCollection<QuestionData> GetAllQuestion()
{ {
var list = new ObservableCollection<QuestionData>(); var list = new ObservableCollection<QuestionData>();
foreach (QuestionData data in QuestionDic.Values) foreach (QuestionData data in QuestionDic.Values)
@ -99,7 +100,7 @@ namespace StudentManager.Data
} }
return list; return list;
} }
public static ObservableCollection<QuestionData> GetAllQuestionByLesson(uint lesson) public ObservableCollection<QuestionData> GetAllQuestionByLesson(uint lesson)
{ {
var list = new ObservableCollection<QuestionData>(); var list = new ObservableCollection<QuestionData>();
foreach (QuestionData data in QuestionTableDic[lesson].Values) foreach (QuestionData data in QuestionTableDic[lesson].Values)
@ -109,24 +110,28 @@ namespace StudentManager.Data
return list; return list;
} }
public static QuestionData Get(int id) public QuestionData Get(int id)
{ {
if (!QuestionDic.ContainsKey(id)) return null; if (!QuestionDic.ContainsKey(id)) return null;
return QuestionDic[id]; return QuestionDic[id];
} }
public static QuestionData Get(uint lesson , int id) public QuestionData Get(uint lesson , int id)
{ {
if (!QuestionDic.ContainsKey(id)) return null; if (!QuestionDic.ContainsKey(id)) return null;
return QuestionDic[id]; 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); QuestionDic.Add(question.Id, question);
if (!QuestionTableDic.ContainsKey(question.Lesson)) if (!QuestionTableDic.ContainsKey(question.Lesson))
{ {
QuestionTableDic[question.Lesson] = new Dictionary<int, QuestionData>(); QuestionTableDic[question.Lesson] = new Dictionary<int, QuestionData>();
@ -135,25 +140,25 @@ namespace StudentManager.Data
QuestionTableDesc[question.Lesson].UpdateTime = DateTime.Now; QuestionTableDesc[question.Lesson].UpdateTime = DateTime.Now;
QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count; QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count;
return true;
SQLHelper.Instance.Add(question);
} }
public static void Remove(QuestionData question) public bool Remove(QuestionData question)
{ {
if (question == null) throw new NullReferenceException(); if (question == null || !QuestionDic.ContainsKey(question.Id) || !QuestionTableDic[question.Lesson].ContainsKey(question.Id)) return false;
QuestionDic.Remove(question.Id);
QuestionDic.Remove(question.Id);
QuestionTableDic[question.Lesson].Remove(question.Id); QuestionTableDic[question.Lesson].Remove(question.Id);
QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count; 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); QuestionDic.Remove(id);
} }
internal static void Update(QuestionData selectedQuestion) internal void Update(QuestionData selectedQuestion)
{ {
if(QuestionDic[selectedQuestion.Id] != null) if(QuestionDic[selectedQuestion.Id] != null)
QuestionDic[selectedQuestion.Id] = selectedQuestion; QuestionDic[selectedQuestion.Id] = selectedQuestion;

View File

@ -126,7 +126,7 @@ namespace StudentManager.Data
public uint CurrentHomeWorkIndex = 0; public uint CurrentHomeWorkIndex = 0;
public HomeWork CurentHomeWork { get; set; } = new HomeWork(); 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 homeWork = new HomeWork();
homeWork.Lesson = (uint)(HomeWorkSet.TotalSetCount + 1); homeWork.Lesson = (uint)(HomeWorkSet.TotalSetCount + 1);
@ -142,7 +142,7 @@ namespace StudentManager.Data
} }
if (appendCommonWork) if (appendCommonWork)
{ {
foreach (var item in QuestionLib.GetAllQuestionByLesson(lesson)) foreach (var item in QuestionLib.Instance.GetAllQuestionByLesson(lesson))
{ {
homeWork.AddHomeWork(item.Id); homeWork.AddHomeWork(item.Id);
} }
@ -174,10 +174,14 @@ namespace StudentManager.Data
{ {
HomeWorkSet.AddHomeWork(homeWork); HomeWorkSet.AddHomeWork(homeWork);
HomeWorkSet.UpdateDate(); HomeWorkSet.UpdateDate();
SQLHelper.Instance.UpdateHomeworkTotalInfo(UID, (uint)HomeWorkSet.TotalQuestionCount, (uint)HomeWorkSet.TotalErrorQuestionCount);
CurentHomeWork = homeWork;
return true;
} }
else else
{ {
//TODO: NOTIFY return false;
} }
} }
} }

View File

@ -9,6 +9,7 @@
xmlns:extent="clr-namespace:StudentManager.Extensions" xmlns:extent="clr-namespace:StudentManager.Extensions"
xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:dt="clr-namespace:StudentManager.Data" xmlns:dt="clr-namespace:StudentManager.Data"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
Background="#00000000" WindowStyle="None" Background="#00000000" WindowStyle="None"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainEditor" Height="800" Width="1400"> Title="MainEditor" Height="800" Width="1400">
@ -48,7 +49,7 @@
</DockPanel> </DockPanel>
<Border BorderBrush="Gray" BorderThickness="1,0,0,0" Margin="2,50" Grid.Column="1"/> <Border BorderBrush="Gray" BorderThickness="1,0,0,0" Margin="2,50" Grid.Column="1" />
<Grid Grid.Column="1"> <Grid Grid.Column="1">
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -57,20 +58,45 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Margin="10"> <Grid Margin="10">
<Border Background="#FFFFFFFF" CornerRadius="10"/> <md:ColorZone Background="#FFFFFFFF" CornerRadius="10" Height="100" x:Name="Bar" />
<DockPanel VerticalAlignment="Center" LastChildFill="False"> <DockPanel VerticalAlignment="Center" LastChildFill="False">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Border Margin="50,0" CornerRadius="50" Height="20" Width="20" Background="Gray"/> <Border Margin="20,0" CornerRadius="50" Height="20" Width="20" Background="Gray"/>
<StackPanel VerticalAlignment="Center" Margin="20,0"> <StackPanel VerticalAlignment=" Center" Margin="10,0">
<TextBlock DockPanel.Dock="Left" Text="USERNAME" HorizontalAlignment="Left" Margin="2" FontWeight="Bold" VerticalAlignment="Center"/> <TextBlock DockPanel.Dock="Left" Text="HELLO" HorizontalAlignment="Left" Margin="2" FontWeight="Bold" VerticalAlignment="Center"/>
<TextBlock DockPanel.Dock="Left" Text="desc" HorizontalAlignment="Left" FontSize="8" Foreground="Gray" Margin="2" VerticalAlignment="Center"/> <TextBlock DockPanel.Dock="Left" Text="美好的一天从此刻开始" HorizontalAlignment="Left" FontSize="8" Foreground="Gray" Margin="2" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<TextBlock DockPanel.Dock="Right" Text="NAME" HorizontalAlignment="Left" Margin="20" VerticalAlignment="Center"/> <Button DockPanel.Dock="Right" Style="{DynamicResource MaterialDesignFlatDarkButton}" Click="Button_Click" Height="80">
<StackPanel>
<md:PackIcon Kind="Close" VerticalAlignment="Top"/>
<TextBlock Text="QUIT" FontSize="10" Margin="0,10"/>
</StackPanel>
</Button>
<TextBlock Text="{Binding CurrentTime}" HorizontalAlignment="Left" Margin="20,0,20,5" FontWeight="Bold" VerticalAlignment="Center"/>
<StackPanel DockPanel.Dock="Right" HorizontalAlignment="Center" Margin="20,20">
<TextBlock Text="DESIGNED BY" HorizontalAlignment="Left" Margin="20,0,20,5" FontWeight="Bold" VerticalAlignment="Center"/>
<TextBlock Text="XINER" HorizontalAlignment="Left" FontSize="10" Foreground="Gray" Margin="20,1" VerticalAlignment="Center"/>
</StackPanel>
</DockPanel> </DockPanel>
</Grid> </Grid>
<ContentControl Grid.Row="1" Margin="10" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}" BorderBrush="White"/> <md:Snackbar x:Name="SnackBar" MessageQueue="{md:MessageQueue}" Panel.ZIndex="1"
Background="#FFFAFAFA" Foreground="Black"
HorizontalAlignment="Center" VerticalAlignment="Top"
Margin="0,20"
>
<md:Snackbar.Effect>
<DropShadowEffect Color="#FFE5E5E5" BlurRadius="20" ShadowDepth="1" Direction="180"/>
</md:Snackbar.Effect>
</md:Snackbar>
<Grid Grid.Row="1">
<ContentControl Grid.Row="1" Margin="10" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}" BorderBrush="White"/>
</Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -1,5 +1,6 @@
using StudentManager.Common; using StudentManager.Common;
using StudentManager.Data; using StudentManager.Data;
using StudentManager.Extensions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -18,9 +19,40 @@ namespace StudentManager.Editor
{ {
public partial class MainEditor : Window public partial class MainEditor : Window
{ {
public MainEditor() private readonly IEventAggregator eventAggregator;
public MainEditor(IEventAggregator aggregator)
{ {
InitializeComponent(); 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();
} }
} }
} }

View File

@ -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<string>
{
}
}

View File

@ -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<string> message)
{
aggregator.GetEvent<MessageEvent>().Subscribe(message);
}
public static void SendMessage(this IEventAggregator aggregator, string message)
{
aggregator.GetEvent<MessageEvent>().Publish(message);
}
}
}

View File

@ -2,6 +2,7 @@
using LiveCharts; using LiveCharts;
using LiveCharts.Wpf; using LiveCharts.Wpf;
using Mysqlx.Crud; using Mysqlx.Crud;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json; using Newtonsoft.Json;
using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities;
using StudentManager.Common; using StudentManager.Common;
@ -18,6 +19,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using Timer = StudentManager.Common.Timer;
namespace StudentManager.Model namespace StudentManager.Model
{ {
@ -209,7 +211,18 @@ namespace StudentManager.Model
set { labels = value; RaisePropertyChanged(); } set { labels = value; RaisePropertyChanged(); }
} }
private string currentTime;
public string CurrentTime
{
get { return currentTime; }
set { currentTime = value; RaisePropertyChanged(); }
}
private readonly IRegionManager regionManager; private readonly IRegionManager regionManager;
private readonly IEventAggregator aggregator;
public DelegateCommand<string> RegionTo { get; set; } public DelegateCommand<string> RegionTo { get; set; }
public DelegateCommand<StudentInfo> SelectedCommand { get; set; } public DelegateCommand<StudentInfo> SelectedCommand { get; set; }
@ -230,9 +243,23 @@ namespace StudentManager.Model
public DelegateCommand PublicHomeWorkCommand { get; set; } public DelegateCommand PublicHomeWorkCommand { get; set; }
public DelegateCommand FreshAllCommand { get; set; } public DelegateCommand FreshAllCommand { get; set; }
Students(IRegionManager regionManager) Students(IRegionManager regionManager, IEventAggregator aggregator)
{ {
CreateMenuBar(); 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<string>((x) => RegionTo = new DelegateCommand<string>((x) =>
{ {
@ -275,11 +302,20 @@ namespace StudentManager.Model
DeleteQuestionCommand = new DelegateCommand(() => DeleteQuestionCommand = new DelegateCommand(() =>
{ {
if (SelectedQuestion == null) return; if (SelectedQuestion == null)
{
aggregator.SendMessage($" 当前没有选中任何题目 ");
return;
}
var c = MessageBox.Show("确定删除吗?", "确认", MessageBoxButton.OKCancel); var c = MessageBox.Show("确定删除吗?", "确认", MessageBoxButton.OKCancel);
if (c != MessageBoxResult.OK) return; if (c != MessageBoxResult.OK) return;
QuestionLib.Remove(SelectedQuestion); if (!SQLHelper.Instance.Delete(SelectedQuestion)) return;
QuestionDatas = QuestionLib.GetAllQuestion(); QuestionLib.Instance.Remove(SelectedQuestion);
QuestionDatas = QuestionLib.Instance.GetAllQuestion();
aggregator.SendMessage($" 成功删除 ");
FileSystem.Instance.SaveAll();
}); });
UpdateQuestionCommand = new DelegateCommand(() => UpdateQuestionCommand = new DelegateCommand(() =>
@ -287,23 +323,13 @@ namespace StudentManager.Model
if (SelectedQuestion == null) return; if (SelectedQuestion == null) return;
var c = MessageBox.Show("确定修改吗?", "确认", MessageBoxButton.OKCancel); var c = MessageBox.Show("确定修改吗?", "确认", MessageBoxButton.OKCancel);
if (c != MessageBoxResult.OK) return; if (c != MessageBoxResult.OK) return;
QuestionLib.Update(SelectedQuestion); QuestionLib.Instance.Update(SelectedQuestion);
SelectedQuestion.UpdateTime = DateTime.Now; SelectedQuestion.UpdateTime = DateTime.Now;
SQLHelper.Instance.UpdateQuestion(SelectedQuestion); SQLHelper.Instance.UpdateQuestion(SelectedQuestion);
});
ShowContextMenuCommand = new DelegateCommand<MouseButtonEventArgs>((e) => aggregator.SendMessage("已更新问题信息");
{
if (e.OriginalSource is FrameworkElement element) FileSystem.Instance.SaveAll();
{
var contextMenu = element.FindResource("MyContextMenu") as ContextMenu;
if (contextMenu != null)
{
contextMenu.PlacementTarget = element;
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
contextMenu.IsOpen = true;
}
}
}); });
SelectedQuestionChangedCommand = new DelegateCommand<QuestionData>((x) => SelectedQuestionChangedCommand = new DelegateCommand<QuestionData>((x) =>
@ -313,19 +339,6 @@ namespace StudentManager.Model
}); });
RemoveNewColumnCommand = new DelegateCommand<QuestionData>((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(() => ClearnAddQuestionsCommand = new DelegateCommand(() =>
{ {
var c = MessageBox.Show("确定清除吗?", "清除所有题目", MessageBoxButton.OKCancel); var c = MessageBox.Show("确定清除吗?", "清除所有题目", MessageBoxButton.OKCancel);
@ -341,7 +354,8 @@ namespace StudentManager.Model
}); });
PublicHomeWorkCommand = new DelegateCommand(() => 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}未发布");
}); });
@ -350,14 +364,19 @@ namespace StudentManager.Model
var cq = new CursonQuestionsData { Lesson = SelectedHomeWorkSet.Lesson, UID = SelectedStudent.UID }; 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; return;
} }
if (SelectedHomeWorkSet != null && SelectedStudent != null) if (SelectedHomeWorkSet != null && SelectedStudent != null)
SelectedStudent.HomeWorkSet.DeleteHomework(SelectedHomeWorkSet.Lesson); SelectedStudent.HomeWorkSet.DeleteHomework(SelectedHomeWorkSet.Lesson);
else
{
aggregator.SendMessage(" 本地数据错误,已为你从服务器更新 ");
QuestionLib.Instance.FreshAllQuestion();
}
if (SelectedStudent != null) 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); Debug.Assert(Lesson != 0);
preToRemove.Clear();
foreach (var item in ADDQuestionDatas) foreach (var item in ADDQuestionDatas)
{ {
item.Id = ConvertToHashInt(item.Stem); item.Id = ConvertToHashInt(item.Stem);
item.Lesson = Lesson; 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; 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); preToRemove.Add(item);
} }
@ -390,7 +422,9 @@ namespace StudentManager.Model
ADDQuestionDatas.Remove(item); ADDQuestionDatas.Remove(item);
} }
QuestionLib.Save(); aggregator.SendMessage($" {preToRemove.Count}添加成功, {ADDQuestionDatas.Count}添加失败 ");
QuestionLib.Instance.Save();
}); });
@ -406,12 +440,12 @@ namespace StudentManager.Model
UpdateGird(); UpdateGird();
this.regionManager = regionManager; this.regionManager = regionManager;
this.aggregator = aggregator;
} }
private void UpdateGird() private void UpdateGird()
{ {
if(SelectedStudent == null) return; if (SelectedStudent == null) return;
SelectedStudent.HomeWorkSet.UpdateDataView(); SelectedStudent.HomeWorkSet.UpdateDataView();
@ -445,17 +479,30 @@ namespace StudentManager.Model
private void UpdateHomeWork() private void UpdateHomeWork()
{ {
// update error set and local homework // update error set and local homework
bool isChanged = false;
SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Questions.ForEach(x => SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Questions.ForEach(x =>
{ {
if (x.Status != HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status || selectedHomeWorkSet.Status == false) 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; x.Status = HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status;
SelectedStudent.ErrorSet.AddQuestion(x); SelectedStudent.ErrorSet.AddQuestion(x);
ErrorBase error = SelectedStudent.ErrorSet.Get(x.ID) ?? new ErrorBase { QuestionBase = new QuestionBase { ID = x.ID, Status = x.Status} }; ErrorBase error = SelectedStudent.ErrorSet.Get(x.ID) ?? new ErrorBase { QuestionBase = new QuestionBase { ID = x.ID, Status = x.Status } };
SQLHelper.Instance.UpdateErrorSet(SelectedStudent.UID, error); 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.Get(SelectedHomeWorkSet.Lesson).UpdateData();
SelectedStudent.HomeWorkSet.UpdateDate(); SelectedStudent.HomeWorkSet.UpdateDate();
SQLHelper.Instance.UpdateErrorSetUserInfo(SelectedStudent.UID, (uint)SelectedStudent.ErrorSet.TotalCount, (uint)SelectedStudent.ErrorSet.CorrectCount); 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); 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 //TODO: Notify
} }
@ -516,7 +570,7 @@ namespace StudentManager.Model
private void Load() private void Load()
{ {
StudentLib.Load(); StudentLib.Load();
QuestionLib.Load(); QuestionLib.Instance.Load();
Reload(); Reload();
} }
@ -525,7 +579,7 @@ namespace StudentManager.Model
studentDatas.Clear(); studentDatas.Clear();
questionDatas.Clear(); questionDatas.Clear();
StudentDatas = StudentLib.GetAllStudents(); StudentDatas = StudentLib.GetAllStudents();
QuestionDatas = QuestionLib.GetAllQuestion(); QuestionDatas = QuestionLib.Instance.GetAllQuestion();
} }
@ -534,7 +588,7 @@ namespace StudentManager.Model
HomeworkTestData.Clear(); HomeworkTestData.Clear();
if (IsAddPublicQuestionsLib) if (IsAddPublicQuestionsLib)
{ {
HomeworkTestData = QuestionLib.GetAllQuestionByLesson(PublicLesson); HomeworkTestData = QuestionLib.Instance.GetAllQuestionByLesson(PublicLesson);
} }
if (IsNeedErrorset) if (IsNeedErrorset)
{ {