From fe9c8a3f0ccc06984fddec948f0a17a946e7eae5 Mon Sep 17 00:00:00 2001 From: wangxiner55 <47072643+wangxiner55@users.noreply.github.com> Date: Thu, 12 Sep 2024 21:12:58 +0800 Subject: [PATCH] 1 --- StudentManager/Common/CursonManager.cs | 16 +++ StudentManager/Common/ErrorSet.cs | 132 ++++++++++++++++------- StudentManager/Common/HomeWorkManager.cs | 11 +- StudentManager/Common/HomeWorkSet.cs | 39 ++++--- StudentManager/Common/SQLHelper.cs | 19 ++-- StudentManager/Data/QuestionLib.cs | 16 ++- StudentManager/Data/StudentInfo.cs | 58 ++++++++-- StudentManager/Data/UserQuestionData.cs | 16 +++ StudentManager/Model/Students.cs | 8 +- 9 files changed, 229 insertions(+), 86 deletions(-) create mode 100644 StudentManager/Common/CursonManager.cs create mode 100644 StudentManager/Data/UserQuestionData.cs diff --git a/StudentManager/Common/CursonManager.cs b/StudentManager/Common/CursonManager.cs new file mode 100644 index 0000000..10f4b11 --- /dev/null +++ b/StudentManager/Common/CursonManager.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentManager.Common +{ + public class CursonManager + { + public int CursonIndex { get; set; } = 0; + public int CursonCount { get; set; } = 0; + public string CursonName { get; set; } = string.Empty; + + } +} diff --git a/StudentManager/Common/ErrorSet.cs b/StudentManager/Common/ErrorSet.cs index be26481..9a3e09a 100644 --- a/StudentManager/Common/ErrorSet.cs +++ b/StudentManager/Common/ErrorSet.cs @@ -1,4 +1,5 @@ -using StudentManager.Data; +using DryIoc.ImTools; +using StudentManager.Data; using System; using System.Collections.Generic; using System.Linq; @@ -7,80 +8,131 @@ using System.Threading.Tasks; namespace StudentManager.Common { - public class ErrorInfo + public class QuestionBase { public int ID { get; set; } = 0; public bool Status { get; set; } = false; } + public class ErrorBase + { + public QuestionBase QuestionBase { get; set; } = new QuestionBase(); + public int TotalUseCount { get; set; } = 1; + public int ErrorCount { get; set; } = 1; + public int CorrectCount { get; set; } = 0; + } + public class ErrorSet - { + { public int TotalCount { get; set; } = 0; public int CorrectCount { get; set; } = 0; - public Dictionary Errores { get; set; } = new Dictionary(); + public Dictionary Errores { get; set; } = new Dictionary(); public List ErrorArray { get; set; } = new List(); public List CorrectArray { get; set; } = new List(); + public int CorrectThresholds { get; set; } = 2; public void InitErrorSetData() { - foreach (var item in Errores) - { - if(item.Value.Status == true) CorrectArray.Add(item.Value.ID); - else ErrorArray.Add(item.Value.ID); - } - } - - public void AddErrorQuestion(int id) - { - if (Errores.ContainsKey(id)) + foreach (var item in Errores) { - TotalCount++; - ErrorArray.Add(id); + if (item.Value.QuestionBase.Status == true) CorrectArray.Add(item.Value.QuestionBase.ID); + else ErrorArray.Add(item.Value.QuestionBase.ID); + } + } + + public void AddQuestion(QuestionBase question) + { + if (question.Status) + { + AddCorrectQuestion(question); } else { - Errores.Add(id, new ErrorInfo { ID = id }); + AddErrorQuestion(question); } } + public void AddErrorQuestion(int id) + { + } + public void AddCorrectQuestion(int id) { - if (Errores.ContainsKey(id)) - { - TotalCount++; - CorrectCount++; - Errores[id].Status = true; - - ErrorArray.Remove(id); - CorrectArray.Add(id); - } } - - public void AddErrorQuestion(QuestionData question) + public void AddErrorQuestion(QuestionBase question) { - if (Errores.ContainsKey(question.Id)) + if (Errores.ContainsKey(question.ID)) { - TotalCount++; - ErrorArray.Add(question.Id); + Errores[question.ID].TotalUseCount++; + Errores[question.ID].ErrorCount++; + + CompareToErrorArray(Errores[question.ID]); } else { - Errores.Add(question.Id, new ErrorInfo { ID = question.Id }); + TotalCount++; + Errores.Add(question.ID, new ErrorBase { QuestionBase = { ID = question.ID } }); + ErrorArray.Add(question.ID); + } + } + + public void AddErrorQuestion(QuestionData question) + { + + } + + public void AddCorrectQuestion(QuestionBase id) + { + if (Errores.ContainsKey(id.ID)) + { + CorrectCount++; + Errores[id.ID].QuestionBase.Status = true; + Errores[id.ID].CorrectCount++; + + CompareToCorrectArray(Errores[id.ID]); + } + } + + private void CompareToErrorArray(ErrorBase id) + { + if (id.QuestionBase.Status == false || ErrorArray.Contains(id.QuestionBase.ID)) return; + + + if ((id.CorrectCount - id.CorrectCount) <= CorrectThresholds) + { + id.QuestionBase.Status = false; + CorrectArray.Remove(id.QuestionBase.ID); + ErrorArray.Add(id.QuestionBase.ID); + } + } + + private void CompareToCorrectArray(ErrorBase id) + { + if (id.QuestionBase.Status == true || CorrectArray.Contains(id.QuestionBase.ID)) return; + + + if ((id.CorrectCount - id.CorrectCount) > CorrectThresholds) + { + id.QuestionBase.Status = true; + ErrorArray.Remove(id.QuestionBase.ID); + CorrectArray.Add(id.QuestionBase.ID); } } public void AddCorrectQuestion(QuestionData question) { - if (Errores.ContainsKey(question.Id)) - { - TotalCount++; - CorrectCount++; - Errores[question.Id].Status = true; + AddCorrectQuestion(new QuestionBase { ID = question.Id }); + } - ErrorArray.Remove(question.Id); - CorrectArray.Add(question.Id); - } + public void QueryErrorSet(int id) + { + Errores.Clear(); + + SQLHelper.Query(Tables.UQTable, id).ForEach(x => + { + AddQuestion(new QuestionBase { ID = x.PID, Status = x.Status}); + }); } } } diff --git a/StudentManager/Common/HomeWorkManager.cs b/StudentManager/Common/HomeWorkManager.cs index 8afdd7f..1ea0cb8 100644 --- a/StudentManager/Common/HomeWorkManager.cs +++ b/StudentManager/Common/HomeWorkManager.cs @@ -21,17 +21,22 @@ namespace StudentManager.Common work.AddHomeWork(item); } - if (CommonHomeWork.QuestionInfo.Count > 0) + if (CommonHomeWork.Questions.Count > 0) { work.Append(CommonHomeWork); } + + student.CurentHomeWork = work; } public static void Public() { - - } + foreach (var item in StudentLib.StudentDic) + { + item.Value.PublicHomeWork(); + } + } } } diff --git a/StudentManager/Common/HomeWorkSet.cs b/StudentManager/Common/HomeWorkSet.cs index ad562e0..634b13f 100644 --- a/StudentManager/Common/HomeWorkSet.cs +++ b/StudentManager/Common/HomeWorkSet.cs @@ -1,4 +1,5 @@ using DryIoc.ImTools; +using StudentManager.Data; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -12,30 +13,30 @@ namespace StudentManager.Common { public int Lesson { get; set; } = 0; public bool Status { get; set; } = false; - public HashSet QuestionInfo { get; set; } = new HashSet(); + public HashSet Questions { get; set; } = new HashSet(); - public void AddHomeWork(ErrorInfo workInfo) + public void AddHomeWork(QuestionBase workInfo) { - QuestionInfo.Add(workInfo); + Questions.Add(workInfo); } public void AddHomeWork(int id) { - QuestionInfo.Add(new ErrorInfo { ID = id }); + Questions.Add(new QuestionBase { ID = id }); } - public void RemoveHomeWork(ErrorInfo workInfo) + public void RemoveHomeWork(QuestionBase workInfo) { - QuestionInfo.Remove(workInfo); + Questions.Remove(workInfo); } public void Append(HomeWork homeWork) { - foreach (var item in homeWork.QuestionInfo) + foreach (var item in homeWork.Questions) { - QuestionInfo.Add(item); + Questions.Add(item); } - + } } @@ -67,14 +68,26 @@ namespace StudentManager.Common public ObservableCollection GetAllByColl() { - ObservableCollection works = new ObservableCollection(); + ObservableCollection works = new ObservableCollection(); foreach (var item in HomeWorks) - { - works.Add(item.Value); - } + { + works.Add(item.Value); + } return works; } + + public void QueryCQSet(int id) + { + HomeWorks.Clear(); + + SQLHelper.Query(Tables.CQTable, id).ForEach(x => + { + HashSet Questions = new HashSet(); + x.ProblemIDS.ForEach(y => Questions.Add(new QuestionBase { ID = y, Status = x.CorrectIDS.Contains(y) })); + HomeWorks.Add(x.Lesson, new HomeWork { Lesson = x.Lesson, Questions = Questions, Status = x.Status == 1 }); + }); + } } } diff --git a/StudentManager/Common/SQLHelper.cs b/StudentManager/Common/SQLHelper.cs index 5c7829d..30333e3 100644 --- a/StudentManager/Common/SQLHelper.cs +++ b/StudentManager/Common/SQLHelper.cs @@ -41,7 +41,7 @@ namespace StudentManager.Common (data as StudentData).TotalsQuestions = (UInt16)reader[6]; (data as StudentData).CorrectionCount = (UInt16)reader[7]; } - else if(typeof(T) == typeof(QuestionData)) + else if (typeof(T) == typeof(QuestionData)) { DifficultyLevel dLevel = DifficultyLevel.easy; QStatus qStatus = QStatus.published; @@ -68,14 +68,21 @@ namespace StudentManager.Common (data as CursonQuestionsData).TotalCount = (data as CursonQuestionsData).ProblemIDS.Length; (data as CursonQuestionsData).CorrectCount = (data as CursonQuestionsData).CorrectIDS.Length; } + else if (typeof(T) == typeof(UserQuestionData)) + { + (data as UserQuestionData).PID = (int)reader[1]; + (data as UserQuestionData).ErrorCount = (byte)reader[2]; + (data as UserQuestionData).CorrectCount = (byte)reader[3]; + (data as UserQuestionData).Status = (byte)reader[4] == 1; + } - //for (int i = 0; i < reader.FieldCount; ++i) - //{ - // data?.GetType().GetProperties().ForEach(x => { x.SetValue(reader[i].GetType(), reader[i]); }); - //} - } + //for (int i = 0; i < reader.FieldCount; ++i) + //{ + // data?.GetType().GetProperties().ForEach(x => { x.SetValue(reader[i].GetType(), reader[i]); }); + //} + } } diff --git a/StudentManager/Data/QuestionLib.cs b/StudentManager/Data/QuestionLib.cs index 2317fca..fffdb91 100644 --- a/StudentManager/Data/QuestionLib.cs +++ b/StudentManager/Data/QuestionLib.cs @@ -1,4 +1,5 @@ using Microsoft.VisualBasic; +using StudentManager.Common; using System; using System.Collections.Generic; using System.Diagnostics; @@ -12,7 +13,6 @@ namespace StudentManager.Data { public static class QuestionLib { - public static string LibPath = "C:\\Users\\zc\\Desktop\\FileLib\\"; public static string FileName = "questionLib.dbqi"; public static Dictionary QuestionDic { get; set; } = new Dictionary(); @@ -20,22 +20,18 @@ namespace StudentManager.Data { QuestionDic.Clear(); - Debug.Assert(Path.Exists(LibPath)); - string file = File.ReadAllText(LibPath + FileName); + Debug.Assert(Path.Exists(StudentLib.LibPath)); + string file = File.ReadAllText(StudentLib.LibPath + FileName); QuestionDic = JsonSerializer.Deserialize>(file); } public static void Save() { - File.WriteAllText((LibPath + FileName), JsonSerializer.Serialize(QuestionDic)); + File.WriteAllText((StudentLib.LibPath + FileName), JsonSerializer.Serialize(QuestionDic)); } - public static void Test() + public static void FreshAllQuestion() { - QuestionDic.Add(1, new QuestionData - { - Id = 1, - Type = "test" - }); + SQLHelper.Query(Tables.QuesTable).ForEach(x => QuestionDic.Add(x.Id, x)); } public static QuestionData Get(int id) diff --git a/StudentManager/Data/StudentInfo.cs b/StudentManager/Data/StudentInfo.cs index 62c61da..0ed6b81 100644 --- a/StudentManager/Data/StudentInfo.cs +++ b/StudentManager/Data/StudentInfo.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection.Metadata.Ecma335; using System.Text; using System.Text.Json; using System.Threading.Tasks; @@ -12,7 +13,7 @@ namespace StudentManager.Data { public static class StudentLib { - public static string LibPath = "C:\\Users\\zc\\Desktop\\FileLib\\"; + public static string LibPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\FileLib\\"; public static string FileName = "studentLib.dbsi"; public static Dictionary StudentDic { get; set; } = new Dictionary(); @@ -33,20 +34,39 @@ namespace StudentManager.Data public static void Save() { + Directory.CreateDirectory(Path.GetFullPath(LibPath)); File.WriteAllText((LibPath + FileName), JsonSerializer.Serialize(StudentDic)); } - public static void Test() + public static void FreshAllStudentInfo() { - StudentDic.Add(1, new StudentInfo + StudentDic.Clear(); + + SQLHelper.Query(Tables.UserTable).ForEach(x => + StudentDic.Add(x.UID, new StudentInfo { - UID = 123, - Name = "John Doe", - Gender = "Male", - Contact = "123-456-7890", - Address = "123 Main St", - Grade = 10, - }); + UID = x.UID, + Name = x.Name, + Address = x.Address, + Contact = x.Contact, + Grade = x.Grade, + })); + + foreach (var item in StudentDic) + { + GetStudentDetailInfo(item.Value); + } + } + + public static StudentInfo QueryStudentDetailInfo(int uid) + { + return GetStudentDetailInfo(Get(uid)); + } + + public static StudentInfo Get(int uid) + { + if (!StudentDic.ContainsKey(uid)) return null; + return StudentDic[uid]; } public static void Remove(StudentInfo studentInfo) @@ -58,6 +78,19 @@ namespace StudentManager.Data { StudentDic.Remove(id); } + + public static StudentInfo GetStudentDetailInfo(StudentInfo studentData) + { + studentData.ErrorSet.QueryErrorSet(studentData.UID); + studentData.HomeWorkSet.QueryCQSet(studentData.UID); + return studentData; + } + + public static void GetStudentDetailInfo(ref StudentInfo studentData) + { + studentData.ErrorSet.QueryErrorSet(studentData.UID); + studentData.HomeWorkSet.QueryCQSet(studentData.UID); + } } public class StudentInfo @@ -74,6 +107,9 @@ namespace StudentManager.Data public HomeWork CurentHomeWork { get; set; } = new HomeWork(); - + public void PublicHomeWork() + { + HomeWorkSet.AddHomeWork(CurentHomeWork); + } } } diff --git a/StudentManager/Data/UserQuestionData.cs b/StudentManager/Data/UserQuestionData.cs new file mode 100644 index 0000000..4b61896 --- /dev/null +++ b/StudentManager/Data/UserQuestionData.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentManager.Data +{ + public class UserQuestionData : IDataCommon + { + public int PID { get; set; } = 0; + public int ErrorCount { get; set; } = 0; + public int CorrectCount { get; set; } = 0; + public bool Status = false; + } +} diff --git a/StudentManager/Model/Students.cs b/StudentManager/Model/Students.cs index 3bb609e..4cfde50 100644 --- a/StudentManager/Model/Students.cs +++ b/StudentManager/Model/Students.cs @@ -135,14 +135,16 @@ namespace StudentManager.Model this.regionManager = regionManager; - QueryAll(); + StudentInfo studentInfo = new StudentInfo(); - StudentLib.Test(); + //QueryAll(); + + StudentLib.FreshAllStudentInfo(); StudentLib.Save(); - QuestionLib.Test(); + QuestionLib.Load(); QuestionLib.Save(); }