From ab4d872f3e45a96027225c83f4a8e811bc5d340c Mon Sep 17 00:00:00 2001 From: wangxiner55 <1468441589@qq.com> Date: Wed, 25 Sep 2024 19:00:49 +0800 Subject: [PATCH] UI Update --- StudentManager/Common/ErrorSet.cs | 37 +-- StudentManager/Common/HomeWorkSet.cs | 50 +++- StudentManager/Common/SQLHelper.cs | 49 ++++ StudentManager/Data/QuestionData.cs | 2 +- StudentManager/Data/QuestionLib.cs | 15 +- StudentManager/Data/StudentInfo.cs | 2 +- StudentManager/Editor/AddHomeWork.xaml | 27 +- StudentManager/Editor/CheckView.xaml | 293 +++++++++++++++------ StudentManager/Editor/CheckView.xaml.cs | 15 ++ StudentManager/Editor/DetailCheckView.xaml | 136 +++++++--- StudentManager/Editor/DetailView.xaml | 272 ++++++++++++++----- StudentManager/Editor/DetailView.xaml.cs | 7 +- StudentManager/Editor/MainEditor.xaml | 3 + StudentManager/Editor/QuestionsView.xaml | 197 ++++++++++++-- StudentManager/Editor/StudentsView.xaml | 107 ++++++-- StudentManager/Editor/StudentsView.xaml.cs | 17 +- StudentManager/Model/Students.cs | 74 +++++- 17 files changed, 1004 insertions(+), 299 deletions(-) diff --git a/StudentManager/Common/ErrorSet.cs b/StudentManager/Common/ErrorSet.cs index e7db2c0..0207f8a 100644 --- a/StudentManager/Common/ErrorSet.cs +++ b/StudentManager/Common/ErrorSet.cs @@ -34,24 +34,25 @@ namespace StudentManager.Common public class DetailErrorSetInfo { - public int TotalCount { get; set; } = 0; - public int TotalErrorCount { get; set; } = 0; - public int CorrectCount { get; set; } = 0; - public int ErrorCount { get; set; } = 0; + public int TotalQuestionsCount { get; set; } = 0; + public int TotalErrorSetQuestionsCount { get; set; } = 0; + public int CorrectCount { get; set; } = 0; + public int ErrorCount { get; set; } = 0; public float ErrorRate { get; set; } = 0; public float CorrectRate { get; set; } = 0; } public class ErrorSet { - public int TotalCount { get; set; } = 0; - public int CorrectCount { get; set; } = 0; + public int TotalCount { get { return Errores.Count; } } + public int CorrectCount { get { return CorrectArray.Count; } } + public int ErrorCount { get { return ErrorArray.Count; } } 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() + public void UpdateErrorSetData() { foreach (var item in Errores) { @@ -64,11 +65,11 @@ namespace StudentManager.Common { return new DetailErrorSetInfo { - TotalCount = QuestionLib.GetQuestionCount(), - TotalErrorCount = Errores.Count(), + TotalQuestionsCount = QuestionLib.TotalCount, + TotalErrorSetQuestionsCount = Errores.Count(), CorrectCount = CorrectArray.Count(), ErrorCount = ErrorArray.Count(), - ErrorRate = QuestionLib.GetQuestionCount() == 0 ? 100 : ErrorArray.Count() / QuestionLib.GetQuestionCount(), + ErrorRate = QuestionLib.TotalCount == 0 ? 100 : ErrorArray.Count() / QuestionLib.TotalCount, CorrectRate = Errores.Count() == 0 ? 100 : CorrectArray.Count() / Errores.Count() }; } @@ -108,13 +109,6 @@ namespace StudentManager.Common } } - public void AddErrorQuestion(int id) - { - } - - public void AddCorrectQuestion(int id) - { - } public void AddErrorQuestion(QuestionBase question) { @@ -127,24 +121,19 @@ namespace StudentManager.Common } else { - 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++; + Errores[id.ID].TotalUseCount++; CompareToCorrectArray(Errores[id.ID]); } diff --git a/StudentManager/Common/HomeWorkSet.cs b/StudentManager/Common/HomeWorkSet.cs index d4a4527..41233b3 100644 --- a/StudentManager/Common/HomeWorkSet.cs +++ b/StudentManager/Common/HomeWorkSet.cs @@ -17,7 +17,7 @@ namespace StudentManager.Common public bool Status { get; set; } = false; } - public class DetailHomeWorkInfo + public class DetailHomeWorkInfo : BindableBase { //public DetailQuestionBase QuestionData { get; set; } = new DetailQuestionBase(); public QuestionData QuestionData { get; set; } = new QuestionData(); @@ -44,6 +44,7 @@ namespace StudentManager.Common public int ErrorCount { get; set; } = 0; public int CorrectCount { get; set; } = 0; + public ObservableCollection GetDetailHomeWorkList() { ObservableCollection list = new ObservableCollection(); @@ -68,7 +69,7 @@ namespace StudentManager.Common return list; } - private void FreshData() + public void UpdateData() { CorrectCount = 0; ErrorCount = 0; @@ -85,19 +86,19 @@ namespace StudentManager.Common public void AddHomeWork(QuestionBase workInfo) { Questions.Add(workInfo); - FreshData(); + UpdateData(); } public void AddHomeWork(int id) { Questions.Add(new QuestionBase { ID = id }); - FreshData(); + UpdateData(); } public void RemoveHomeWork(QuestionBase workInfo) { Questions.Remove(workInfo); - FreshData(); + UpdateData(); } public void Append(HomeWork homeWork) @@ -106,7 +107,7 @@ namespace StudentManager.Common { Questions.Add(item); } - + UpdateData(); } } @@ -114,14 +115,14 @@ namespace StudentManager.Common public class DetailHomeWorkSetInfo { - public int TotalCount { get; set; } = 0; - public bool Status { get; set; } = false; - - public DateTime DateTime { get; set; } = DateTime.Now; public uint Lesson { get; set; } = 0; + public int TotalCount { get; set; } = 0; + public int ErrorCount { get; set; } = 0; public int CorrectCount { get; set; } = 0; + public bool Status { get; set; } = false; + public DateTime DateTime { get; set; } = DateTime.Now; } @@ -129,13 +130,31 @@ namespace StudentManager.Common { [JsonInclude] private Dictionary HomeWorks { get; set; } = new Dictionary(); - public int TotalCount { get; set; } = 0; + public int TotalSetCount { get; set; } = 0; + public int TotalQuestionCount { get; set; } = 0; + public int TotalErrorQuestionCount { get; set; } = 0; + public int TotalCorrectQuestionCount { get; set; } = 0; + public int TotalErrorQuestionRate { get; set; } = 0; + public void UpdateDate() + { + TotalSetCount = HomeWorks.Count; + TotalQuestionCount = 0; + foreach (var item in HomeWorks) + { + TotalQuestionCount = item.Value.TotalCount; + TotalErrorQuestionCount = item.Value.ErrorCount; + TotalCorrectQuestionCount = item.Value.CorrectCount; + } + + TotalErrorQuestionRate = TotalErrorQuestionCount / TotalQuestionCount; + } + public void AddHomeWork(HomeWork homeWork) { HomeWorks.Add(homeWork.Lesson, homeWork); - TotalCount = HomeWorks.Count; + UpdateDate(); } public ObservableCollection GetDetailHomeWorkList(uint lesson) @@ -169,7 +188,7 @@ namespace StudentManager.Common { list.Add(new DetailHomeWorkSetInfo { - + Status = item.Value.Status, Lesson = item.Value.Lesson, DateTime = item.Value.DateTime, @@ -186,6 +205,7 @@ namespace StudentManager.Common public void RemoveHomeWork(HomeWork homeWork) { HomeWorks.Remove(homeWork.Lesson); + UpdateDate(); } public HomeWork Get(uint cursonId) @@ -196,7 +216,7 @@ namespace StudentManager.Common public HomeWork GetLast() { - return HomeWorks[(uint)TotalCount]; + return HomeWorks[(uint)TotalSetCount]; } public List GetAll() @@ -234,6 +254,8 @@ namespace StudentManager.Common Status = x.Status == 1 }); }); + + UpdateDate(); } } diff --git a/StudentManager/Common/SQLHelper.cs b/StudentManager/Common/SQLHelper.cs index 8f2ee79..5c28ba2 100644 --- a/StudentManager/Common/SQLHelper.cs +++ b/StudentManager/Common/SQLHelper.cs @@ -386,5 +386,54 @@ namespace StudentManager.Common } } } + + internal static void UpdateQuestion(QuestionData ques) + { + using (MySqlConnection connection = new MySqlConnection(config)) + { + try + { + connection.Open(); + string query = @"UPDATE questions SET + problem_type = @Type, + problem_stem = @Stem, + problem_answer = @Answer, + difficulty_level = @DifficultyLevel, + category = @Category, + tags = @Tags, + source = @Source, + lesson = @Lesson, + status = @Status, + update_time = @UpdateTime + WHERE problem_id = @Id"; + + using (MySqlCommand command = new MySqlCommand(query, connection)) + { + command.Parameters.AddWithValue("@Id", ques.Id); + command.Parameters.AddWithValue("@Type", ques.Type.ToString()); + command.Parameters.AddWithValue("@Stem", ques.Stem); + command.Parameters.AddWithValue("@Answer", ques.Answer); + command.Parameters.AddWithValue("@DifficultyLevel", ques.DifficultyLevel.ToString()); + command.Parameters.AddWithValue("@Category", ques.Category); + command.Parameters.AddWithValue("@Tags", ques.Tags); + command.Parameters.AddWithValue("@Source", ques.Source); + command.Parameters.AddWithValue("@Lesson", ques.Lesson); + command.Parameters.AddWithValue("@Status", ques.Status.ToString()); + command.Parameters.AddWithValue("@UpdateTime", ques.UpdateTime); + + int rowsAffected = command.ExecuteNonQuery(); + Console.WriteLine($"{rowsAffected} rows updated."); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + connection.Close(); + } + } + } } } diff --git a/StudentManager/Data/QuestionData.cs b/StudentManager/Data/QuestionData.cs index 28f3b0d..435d480 100644 --- a/StudentManager/Data/QuestionData.cs +++ b/StudentManager/Data/QuestionData.cs @@ -28,7 +28,7 @@ namespace StudentManager.Data } - public class QuestionData : IDataCommon + public class QuestionData : IDataCommon { public int Id { get; set; } = 0; public QType Type { get; set; } = QType.填空题; diff --git a/StudentManager/Data/QuestionLib.cs b/StudentManager/Data/QuestionLib.cs index 8ece001..d1b311a 100644 --- a/StudentManager/Data/QuestionLib.cs +++ b/StudentManager/Data/QuestionLib.cs @@ -30,13 +30,8 @@ namespace StudentManager.Data 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 TotalCount { get { return QuestionDic.Count; } } - public static int GetQuestionCount() - { - TotalCount = QuestionDic.Count; - return TotalCount; - } public static void Load() { QuestionDic.Clear(); @@ -157,5 +152,13 @@ namespace StudentManager.Data { QuestionDic.Remove(id); } + + internal static void Update(QuestionData selectedQuestion) + { + if(QuestionDic[selectedQuestion.Id] != null) + QuestionDic[selectedQuestion.Id] = selectedQuestion; + else + QuestionDic.Add(selectedQuestion.Id, selectedQuestion); + } } } diff --git a/StudentManager/Data/StudentInfo.cs b/StudentManager/Data/StudentInfo.cs index b3cff21..d907d2a 100644 --- a/StudentManager/Data/StudentInfo.cs +++ b/StudentManager/Data/StudentInfo.cs @@ -126,7 +126,7 @@ namespace StudentManager.Data 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.Lesson = (uint)(HomeWorkSet.TotalSetCount + 1) ; homeWork.DateTime = DateTime.Now; if(appendErrorSet) { diff --git a/StudentManager/Editor/AddHomeWork.xaml b/StudentManager/Editor/AddHomeWork.xaml index f8d768e..ca093be 100644 --- a/StudentManager/Editor/AddHomeWork.xaml +++ b/StudentManager/Editor/AddHomeWork.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:StudentManager.Editor" + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> @@ -38,8 +39,8 @@ - - + + @@ -48,8 +49,8 @@ - - + + @@ -70,16 +71,14 @@ - - - + + + + + + + + diff --git a/StudentManager/Editor/CheckView.xaml b/StudentManager/Editor/CheckView.xaml index 833f867..7a3ae6f 100644 --- a/StudentManager/Editor/CheckView.xaml +++ b/StudentManager/Editor/CheckView.xaml @@ -11,6 +11,55 @@ + + + + + + + + + @@ -20,24 +69,21 @@ - - - - - - - - + + - - + + + + + + + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - -