diff --git a/StudentManager/App.xaml.cs b/StudentManager/App.xaml.cs index 0b1f059..18ec41e 100644 --- a/StudentManager/App.xaml.cs +++ b/StudentManager/App.xaml.cs @@ -25,6 +25,7 @@ namespace StudentManager containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); } } diff --git a/StudentManager/Common/ErrorSet.cs b/StudentManager/Common/ErrorSet.cs index 4d92847..e7db2c0 100644 --- a/StudentManager/Common/ErrorSet.cs +++ b/StudentManager/Common/ErrorSet.cs @@ -73,6 +73,12 @@ namespace StudentManager.Common }; } + public List GetErrorsList() + { + return ErrorArray; + } + + public ObservableCollection GetDetailErrorQuestionList() { ObservableCollection list = new ObservableCollection(); diff --git a/StudentManager/Common/FileSystem.cs b/StudentManager/Common/FileSystem.cs index 3a8b8dc..77138ab 100644 --- a/StudentManager/Common/FileSystem.cs +++ b/StudentManager/Common/FileSystem.cs @@ -14,5 +14,13 @@ namespace StudentManager.Common StudentLib.Save(); QuestionLib.Save(); } + + public static void FreashAllInfo() + { + StudentLib.FreshAllStudentInfo(); + QuestionLib.FreshAllQuestion(); + + SaveAll(); + } } } diff --git a/StudentManager/Common/HomeWorkManager.cs b/StudentManager/Common/HomeWorkManager.cs index 7b70bd7..39db1ba 100644 --- a/StudentManager/Common/HomeWorkManager.cs +++ b/StudentManager/Common/HomeWorkManager.cs @@ -13,29 +13,11 @@ namespace StudentManager.Common { public static HomeWork CommonHomeWork { get; set; } = new HomeWork(); - public static void Create(StudentInfo student,int lesson, bool appedCommonWork = false, int workNum = 10) - { - HomeWork work = new HomeWork { Lesson = lesson}; - foreach(var item in student.ErrorSet.ErrorArray) - { - work.AddHomeWork(item); - } - - if (appedCommonWork && CommonHomeWork.Questions.Count > 0) - { - work.Append(CommonHomeWork); - } - - Public(work); - - } - - - public static void Public(HomeWork homeWork) + public static void PublicHomework(uint lesson, bool appedCommonWork = false, bool appendErrorSet = false, int workNum = -1) { foreach (var item in StudentLib.StudentDic) { - item.Value.PublicHomeWork(homeWork); + item.Value.PublicHomeWork(lesson, appedCommonWork, appendErrorSet, workNum); } } } diff --git a/StudentManager/Common/HomeWorkSet.cs b/StudentManager/Common/HomeWorkSet.cs index 0988b4a..d4a4527 100644 --- a/StudentManager/Common/HomeWorkSet.cs +++ b/StudentManager/Common/HomeWorkSet.cs @@ -34,7 +34,7 @@ namespace StudentManager.Common public class HomeWork { - public int Lesson { get; set; } = 0; + public uint Lesson { get; set; } = 0; public bool Status { get; set; } = false; public DateTime DateTime { get; set; } = DateTime.Now; public List Questions { get; set; } = new List(); @@ -118,7 +118,7 @@ namespace StudentManager.Common public bool Status { get; set; } = false; public DateTime DateTime { get; set; } = DateTime.Now; - public int Lesson { get; set; } = 0; + public uint Lesson { get; set; } = 0; public int ErrorCount { get; set; } = 0; public int CorrectCount { get; set; } = 0; @@ -128,7 +128,7 @@ namespace StudentManager.Common public class HomeWorkSet { [JsonInclude] - private Dictionary HomeWorks { get; set; } = new Dictionary(); + private Dictionary HomeWorks { get; set; } = new Dictionary(); public int TotalCount { get; set; } = 0; @@ -138,7 +138,7 @@ namespace StudentManager.Common TotalCount = HomeWorks.Count; } - public ObservableCollection GetDetailHomeWorkList(int lesson) + public ObservableCollection GetDetailHomeWorkList(uint lesson) { ObservableCollection list = new ObservableCollection(); foreach (var item in HomeWorks[lesson].Questions) @@ -188,7 +188,7 @@ namespace StudentManager.Common HomeWorks.Remove(homeWork.Lesson); } - public HomeWork Get(int cursonId) + public HomeWork Get(uint cursonId) { if (HomeWorks.ContainsKey(cursonId)) return HomeWorks[cursonId]; return null; @@ -196,7 +196,7 @@ namespace StudentManager.Common public HomeWork GetLast() { - return HomeWorks[TotalCount]; + return HomeWorks[(uint)TotalCount]; } public List GetAll() diff --git a/StudentManager/Common/SQLHelper.cs b/StudentManager/Common/SQLHelper.cs index efe0951..18a5d4d 100644 --- a/StudentManager/Common/SQLHelper.cs +++ b/StudentManager/Common/SQLHelper.cs @@ -38,7 +38,7 @@ namespace StudentManager.Common (data as StudentData).Grade = (byte)reader[5]; (data as StudentData).TotalsQuestions = (UInt16)reader[6]; (data as StudentData).CorrectionCount = (UInt16)reader[7]; - (data as StudentData).CurronHomeWorkIndex = (UInt16)reader[8]; + (data as StudentData).CurronHomeWorkIndex = (uint)reader[8]; (data as StudentData).Password = reader[9].ToString(); (data as StudentData).Birthdate = (DateTime)reader[10]; (data as StudentData).HWQTotalCount = (uint)reader[11]; @@ -59,7 +59,8 @@ namespace StudentManager.Common (data as QuestionData).Category = reader[5].ToString(); (data as QuestionData).Tags = reader[6].ToString(); (data as QuestionData).Source = reader[7].ToString(); - Enum.TryParse(reader[8].ToString(), true, out qStatus); + (data as QuestionData).Lesson = (uint)reader[8]; + Enum.TryParse(reader[9].ToString(), true, out qStatus); (data as QuestionData).Status = qStatus; } else if (typeof(T) == typeof(CursonQuestionsData)) @@ -68,7 +69,7 @@ namespace StudentManager.Common (data as CursonQuestionsData).UID = (int)reader[0]; (data as CursonQuestionsData).ProblemIDS = string.IsNullOrEmpty(reader[1].ToString()) ? Array.Empty() : JsonConvert.DeserializeObject(reader[1].ToString()); (data as CursonQuestionsData).CorrectIDS = string.IsNullOrEmpty(reader[2].ToString()) ? Array.Empty() : JsonConvert.DeserializeObject(reader[2].ToString()); - (data as CursonQuestionsData).Lesson = (byte)reader[3]; + (data as CursonQuestionsData).Lesson = (uint)reader[3]; (data as CursonQuestionsData).Status = (byte)reader[4]; (data as CursonQuestionsData).DateTime = (DateTime)reader[5]; (data as CursonQuestionsData).TotalCount = (data as CursonQuestionsData).ProblemIDS.Length; @@ -244,6 +245,8 @@ namespace StudentManager.Common cmd.ExecuteNonQuery(); + cmd.Dispose(); + } //string sql = $"insert into {stableName}" } @@ -253,7 +256,7 @@ namespace StudentManager.Common } finally { - cmd.Dispose(); + //cmd.Dispose(); connection.Close(); } } @@ -315,7 +318,7 @@ namespace StudentManager.Common } } - internal static void UpdateHomework(long UID, int lesson, string totalArray, string correctArray, DateTime dateTime, bool status) + internal static void UpdateHomework(long UID, uint lesson, string totalArray, string correctArray, DateTime dateTime, bool status) { using (MySqlConnection connection = new MySqlConnection(config)) { diff --git a/StudentManager/Data/CursonQuestionsData.cs b/StudentManager/Data/CursonQuestionsData.cs index 3b0f56e..4535d8f 100644 --- a/StudentManager/Data/CursonQuestionsData.cs +++ b/StudentManager/Data/CursonQuestionsData.cs @@ -13,7 +13,7 @@ namespace StudentManager.Data public int[] CorrectIDS { get; set; } = { }; public DateTime DateTime { get; set; } = DateTime.Now; - public int Lesson { get; set; } = 0; + public uint Lesson { get; set; } = 0; public int TotalCount { get; set; } = 0; public int CorrectCount { get; set; } = 0; public int Status { get; set; } = 0; diff --git a/StudentManager/Data/QuestionData.cs b/StudentManager/Data/QuestionData.cs index 77e17b3..28f3b0d 100644 --- a/StudentManager/Data/QuestionData.cs +++ b/StudentManager/Data/QuestionData.cs @@ -38,8 +38,9 @@ namespace StudentManager.Data public string Category { get; set; } = string.Empty; public string Tags { get; set; } = "默认"; public string Source { get; set; } = string.Empty; - public int Lesson { get; set; } = 0; + public uint Lesson { get; set; } = 0; public QStatus Status { get; set; } = QStatus.published; + public DateTime UpdateTime { get; set; } = DateTime.MinValue; //public string TableName { get => "questions"; set => throw new NotImplementedException(); } diff --git a/StudentManager/Data/QuestionLib.cs b/StudentManager/Data/QuestionLib.cs index 8b63bde..8ece001 100644 --- a/StudentManager/Data/QuestionLib.cs +++ b/StudentManager/Data/QuestionLib.cs @@ -10,13 +10,26 @@ using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; +using static Mysqlx.Crud.UpdateOperation.Types; namespace StudentManager.Data { + public class QuestionSetDesc + { + public uint TotalQuestions { get; set; } = 0; + public DateTime UpdateTime { get; set; } = DateTime.Now; + public uint Lesson { get; set; } = 0; + } + + public static class QuestionLib { public static string FileName = "questionLib.dbqi"; + public static string TableDicFileName = "questionTableDicLib.dbqi"; + public static string TableDescFileName = "questionTableDescLib.dbqi"; public static Dictionary QuestionDic { get; set; } = new Dictionary(); + public static Dictionary QuestionTableDesc { get; set; } = new Dictionary(); + public static Dictionary> QuestionTableDic { get; set; } = new Dictionary>(); public static int TotalCount { get; set; } = 0; public static int GetQuestionCount() @@ -29,18 +42,58 @@ namespace StudentManager.Data QuestionDic.Clear(); Debug.Assert(Path.Exists(StudentLib.LibPath)); + + if (!Path.Exists(StudentLib.LibPath + FileName)) + File.WriteAllText((StudentLib.LibPath + FileName), ""); string file = File.ReadAllText(StudentLib.LibPath + FileName); - QuestionDic = JsonSerializer.Deserialize>(file); + if (file.Length != 0) + QuestionDic = JsonSerializer.Deserialize>(file); + + if (!Path.Exists(StudentLib.LibPath + TableDicFileName)) + File.WriteAllText((StudentLib.LibPath + TableDicFileName), ""); + + file = File.ReadAllText(StudentLib.LibPath + TableDicFileName); + if (file.Length != 0) + QuestionTableDic = JsonSerializer.Deserialize>>(file); + + if (!Path.Exists(StudentLib.LibPath + TableDescFileName)) + File.WriteAllText((StudentLib.LibPath + TableDescFileName), ""); + file = File.ReadAllText(StudentLib.LibPath + TableDescFileName); + if (file.Length != 0) + QuestionTableDesc = JsonSerializer.Deserialize>(file); } public static 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() { + + QuestionDic.Clear (); + QuestionTableDic.Clear (); + QuestionTableDesc.Clear (); SQLHelper.Query().ForEach(x => QuestionDic.Add(x.Id, x)); - } + SQLHelper.Query().ForEach(x => { + if (!QuestionTableDic.ContainsKey(x.Lesson)) + { + QuestionTableDic[x.Lesson] = new Dictionary(); + } + QuestionTableDic[x.Lesson][x.Id] = x; + }); + + foreach (var QuestionTables in QuestionTableDic) + { + DateTime update = DateTime.MinValue; + foreach(var item in QuestionTables.Value) + { + update = update > item.Value.UpdateTime ? item.Value.UpdateTime : update; + } + QuestionTableDesc.Add(QuestionTables.Key, new QuestionSetDesc{ TotalQuestions = (uint)QuestionTables.Value.Count ,UpdateTime = update, Lesson = QuestionTables.Key }); + } + } public static ObservableCollection GetAllQuestion() { @@ -51,6 +104,15 @@ namespace StudentManager.Data } return list; } + public static ObservableCollection GetAllQuestionByLesson(uint lesson) + { + var list = new ObservableCollection(); + foreach (QuestionData data in QuestionTableDic[lesson].Values) + { + list.Add(data); + } + return list; + } public static QuestionData Get(int id) { @@ -59,9 +121,26 @@ namespace StudentManager.Data return QuestionDic[id]; } + public static QuestionData Get(uint lesson , int id) + { + if (!QuestionDic.ContainsKey(id)) return null; + + return QuestionDic[id]; + } + public static void Add(QuestionData question) { QuestionDic.Add(question.Id, question); + + if (!QuestionTableDic.ContainsKey(question.Lesson)) + { + QuestionTableDic[question.Lesson] = new Dictionary(); + } + QuestionTableDic[question.Lesson][question.Id] = question; + + QuestionTableDesc[question.Lesson].UpdateTime = DateTime.Now; + QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count; + SQLHelper.Add(question); } @@ -69,6 +148,9 @@ namespace StudentManager.Data { if (question == null) throw new NullReferenceException(); QuestionDic.Remove(question.Id); + + QuestionTableDic[question.Lesson].Remove(question.Id); + QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count; } public static void Remove(int id) diff --git a/StudentManager/Data/StudentData.cs b/StudentManager/Data/StudentData.cs index 8b480d4..b755839 100644 --- a/StudentManager/Data/StudentData.cs +++ b/StudentManager/Data/StudentData.cs @@ -30,7 +30,7 @@ namespace StudentManager.Data public int CorrectionCount { get; set; } = 0; // HomeWork - public int CurronHomeWorkIndex { get; set; } = 0; + public uint CurronHomeWorkIndex { get; set; } = 0; // HomeWorkSet public uint HWQTotalCount { get; set; } = 0; diff --git a/StudentManager/Data/StudentInfo.cs b/StudentManager/Data/StudentInfo.cs index 607013c..3ba2bd2 100644 --- a/StudentManager/Data/StudentInfo.cs +++ b/StudentManager/Data/StudentInfo.cs @@ -120,12 +120,33 @@ namespace StudentManager.Data public ErrorSet ErrorSet { get; set; } = new ErrorSet(); public HomeWorkSet HomeWorkSet { get; set; } = new HomeWorkSet(); - public int CurrentHomeWorkIndex = 0; + public uint CurrentHomeWorkIndex = 0; public HomeWork CurentHomeWork { get; set; } = new HomeWork(); - public void PublicHomeWork(HomeWork homeWork) + public void PublicHomeWork(uint lesson, bool appendCommonWork = false, bool appendErrorSet = false, int workNum = -1) { + HomeWork homeWork = new HomeWork(); + homeWork.Lesson = (uint)(HomeWorkSet.TotalCount + 1) ; + homeWork.DateTime = DateTime.Now; + if(appendErrorSet) + { + ErrorSet.ErrorArray.ForEach(error => + homeWork.AddHomeWork(error)); + } + if(appendCommonWork) + { + foreach (var item in QuestionLib.GetAllQuestionByLesson(lesson)) + { + homeWork.AddHomeWork(item.Id); + } + } + if (workNum != -1) + { + + } HomeWorkSet.AddHomeWork(homeWork); + + } } } diff --git a/StudentManager/Editor/AddHomeWork.xaml b/StudentManager/Editor/AddHomeWork.xaml new file mode 100644 index 0000000..5ed1b0e --- /dev/null +++ b/StudentManager/Editor/AddHomeWork.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +