Compare commits

..

No commits in common. "d60ef9752509f84325e44d27b3e21a665e18d65a" and "6ec84c76b90e79df1f89dff83e755851456e5f85" have entirely different histories.

34 changed files with 482 additions and 2776 deletions

View File

@ -2,14 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StudentManager" xmlns:local="clr-namespace:StudentManager"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"> xmlns:prism="http://prismlibrary.com/">
<Application.Resources> <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<md:BundledTheme BaseTheme="Light" PrimaryColor="Grey" SecondaryColor="Cyan" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources> </Application.Resources>
</prism:PrismApplication> </prism:PrismApplication>

View File

@ -24,8 +24,6 @@ namespace StudentManager
containerRegistry.RegisterForNavigation<CheckView>(); containerRegistry.RegisterForNavigation<CheckView>();
containerRegistry.RegisterForNavigation<DetailView>(); containerRegistry.RegisterForNavigation<DetailView>();
containerRegistry.RegisterForNavigation<DetailCheckView>(); containerRegistry.RegisterForNavigation<DetailCheckView>();
containerRegistry.RegisterForNavigation<AddQuestionView>();
containerRegistry.RegisterForNavigation<AddHomeWork>();
} }
} }

View File

@ -11,5 +11,6 @@ namespace StudentManager.Common
public int CursonIndex { get; set; } = 0; public int CursonIndex { get; set; } = 0;
public int CursonCount { get; set; } = 0; public int CursonCount { get; set; } = 0;
public string CursonName { get; set; } = string.Empty; public string CursonName { get; set; } = string.Empty;
} }
} }

View File

@ -34,30 +34,24 @@ namespace StudentManager.Common
public class DetailErrorSetInfo public class DetailErrorSetInfo
{ {
public int TotalQuestionsCount { get; set; } = 0; public int TotalCount { get; set; } = 0;
public int TotalErrorSetQuestionsCount { get; set; } = 0; public int TotalErrorCount { get; set; } = 0;
public int CorrectCount { get; set; } = 0; public int CorrectCount { get; set; } = 0;
public int ErrorCount { get; set; } = 0; public int ErrorCount { get; set; } = 0;
public float ErrorRate { get; set; } = 0; public float ErrorRate { get; set; } = 0;
public float CorrectRate { get; set; } = 0; public float CorrectRate { get; set; } = 0;
} }
public class ErrorSet public class ErrorSet
{ {
public int TotalCount { get { return Errores.Count; } } public int TotalCount { get; set; } = 0;
public int CorrectCount { get { return CorrectArray.Count; } } public int CorrectCount { get; set; } = 0;
public int ErrorCount { get { return ErrorArray.Count; } }
public Dictionary<int, ErrorBase> Errores { get; set; } = new Dictionary<int, ErrorBase>(); public Dictionary<int, ErrorBase> Errores { get; set; } = new Dictionary<int, ErrorBase>();
public List<int> ErrorArray { get; set; } = new List<int>(); public List<int> ErrorArray { get; set; } = new List<int>();
public List<int> CorrectArray { get; set; } = new List<int>(); public List<int> CorrectArray { get; set; } = new List<int>();
public int CorrectThresholds { get; set; } = 2; public int CorrectThresholds { get; set; } = 2;
public ErrorBase Get(int id) public void InitErrorSetData()
{
return Errores.ContainsKey(id) ? Errores[id] : null;
}
public void UpdateErrorSetData()
{ {
foreach (var item in Errores) foreach (var item in Errores)
{ {
@ -70,21 +64,15 @@ namespace StudentManager.Common
{ {
return new DetailErrorSetInfo return new DetailErrorSetInfo
{ {
TotalQuestionsCount = QuestionLib.TotalCount, TotalCount = QuestionLib.GetQuestionCount(),
TotalErrorSetQuestionsCount = Errores.Count(), TotalErrorCount = Errores.Count(),
CorrectCount = CorrectArray.Count(), CorrectCount = CorrectArray.Count(),
ErrorCount = ErrorArray.Count(), ErrorCount = ErrorArray.Count(),
ErrorRate = QuestionLib.TotalCount == 0 ? 100 : ErrorArray.Count() / QuestionLib.TotalCount, ErrorRate = ErrorArray.Count() / QuestionLib.GetQuestionCount(),
CorrectRate = Errores.Count() == 0 ? 100 : CorrectArray.Count() / Errores.Count() CorrectRate = CorrectArray.Count() / Errores.Count()
}; };
} }
public List<int> GetErrorsList()
{
return ErrorArray;
}
public ObservableCollection<DetailErrorInfo> GetDetailErrorQuestionList() public ObservableCollection<DetailErrorInfo> GetDetailErrorQuestionList()
{ {
ObservableCollection<DetailErrorInfo> list = new ObservableCollection<DetailErrorInfo>(); ObservableCollection<DetailErrorInfo> list = new ObservableCollection<DetailErrorInfo>();
@ -92,10 +80,9 @@ namespace StudentManager.Common
{ {
list.Add(new DetailErrorInfo list.Add(new DetailErrorInfo
{ {
QuestionData = QuestionLib.Instance.Get(item.Key), QuestionData = QuestionLib.Get(item.Key),
CorrectCount = item.Value.CorrectCount, CorrectCount = item.Value.CorrectCount,
ErrorCount = item.Value.ErrorCount, ErrorCount = item.Value.ErrorCount,
TotalUseCount = item.Value.TotalUseCount,
Status = item.Value.QuestionBase.Status Status = item.Value.QuestionBase.Status
}); });
} }
@ -115,6 +102,13 @@ namespace StudentManager.Common
} }
} }
public void AddErrorQuestion(int id)
{
}
public void AddCorrectQuestion(int id)
{
}
public void AddErrorQuestion(QuestionBase question) public void AddErrorQuestion(QuestionBase question)
{ {
@ -127,19 +121,24 @@ namespace StudentManager.Common
} }
else else
{ {
TotalCount++;
Errores.Add(question.ID, new ErrorBase { QuestionBase = { ID = question.ID } }); Errores.Add(question.ID, new ErrorBase { QuestionBase = { ID = question.ID } });
ErrorArray.Add(question.ID); ErrorArray.Add(question.ID);
} }
} }
public void AddErrorQuestion(QuestionData question)
{
}
public void AddCorrectQuestion(QuestionBase id) public void AddCorrectQuestion(QuestionBase id)
{ {
if (Errores.ContainsKey(id.ID)) if (Errores.ContainsKey(id.ID))
{ {
CorrectCount++;
Errores[id.ID].QuestionBase.Status = true;
Errores[id.ID].CorrectCount++; Errores[id.ID].CorrectCount++;
Errores[id.ID].TotalUseCount++;
CompareToCorrectArray(Errores[id.ID]); CompareToCorrectArray(Errores[id.ID]);
} }
@ -150,7 +149,7 @@ namespace StudentManager.Common
if (id.QuestionBase.Status == false || ErrorArray.Contains(id.QuestionBase.ID)) return; if (id.QuestionBase.Status == false || ErrorArray.Contains(id.QuestionBase.ID)) return;
if ((id.CorrectCount - id.ErrorCount) <= CorrectThresholds) if ((id.CorrectCount - id.CorrectCount) <= CorrectThresholds)
{ {
id.QuestionBase.Status = false; id.QuestionBase.Status = false;
CorrectArray.Remove(id.QuestionBase.ID); CorrectArray.Remove(id.QuestionBase.ID);
@ -163,7 +162,7 @@ namespace StudentManager.Common
if (id.QuestionBase.Status == true || CorrectArray.Contains(id.QuestionBase.ID)) return; if (id.QuestionBase.Status == true || CorrectArray.Contains(id.QuestionBase.ID)) return;
if ((id.CorrectCount - id.ErrorCount) > CorrectThresholds) if ((id.CorrectCount - id.CorrectCount) > CorrectThresholds)
{ {
id.QuestionBase.Status = true; id.QuestionBase.Status = true;
ErrorArray.Remove(id.QuestionBase.ID); ErrorArray.Remove(id.QuestionBase.ID);
@ -176,13 +175,13 @@ namespace StudentManager.Common
AddCorrectQuestion(new QuestionBase { ID = question.Id }); AddCorrectQuestion(new QuestionBase { ID = question.Id });
} }
public void QueryErrorSet(long id) public void QueryErrorSet(int id)
{ {
Errores.Clear(); Errores.Clear();
SQLHelper.Instance.Query<UserQuestionData>(id).ForEach(x => SQLHelper.Query<UserQuestionData>(Tables.UQTable, id).ForEach(x =>
{ {
Errores.Add(x.PID, new ErrorBase { CorrectCount = x.CorrectCount, ErrorCount = x.ErrorCount, TotalUseCount = x.CorrectCount + x.ErrorCount, QuestionBase = new QuestionBase { ID= x.PID, Status = x.Status } }); AddQuestion(new QuestionBase { ID = x.PID, Status = x.Status });
}); });
} }
} }

View File

@ -1,48 +0,0 @@
using StudentManager.Data;
using StudentManager.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Common
{
public class FileSystem : Singleton<FileSystem>
{
public Action AutoSaveInvoke { get; set; }
public Action SavedInvoke { get; set; }
public void SaveAll()
{
StudentLib.Save();
QuestionLib.Instance.Save();
SavedInvoke?.Invoke();
}
public void FreashAllInfo()
{
StudentLib.FreshAllStudentInfo();
QuestionLib.Instance.FreshAllQuestion();
SaveAll();
}
public async void AutoSave(int time = 1)
{
await Task.Delay(time * 60 * 1000);
AutoSaveInvoke?.Invoke();
await Task.Delay(10000);
SaveAll();
SavedInvoke?.Invoke();
AutoSave(time);
}
}
}

View File

@ -1,9 +1,7 @@
using DryIoc.ImTools; using DryIoc.ImTools;
using StudentManager.Data; using StudentManager.Data;
using StudentManager.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
@ -11,38 +9,34 @@ using System.Threading.Tasks;
namespace StudentManager.Common namespace StudentManager.Common
{ {
public class HomeWorkError public static class HomeWorkManager
{ {
public int Total { get; set; } public static HomeWork CommonHomeWork { get; set; } = new HomeWork();
public int Error { get; set; }
public int Correct { get; set; }
}
public static void Create(StudentInfo student,int lesson, bool appedCommonWork = false, int workNum = 10)
public class HomeWorkManager : Singleton<HomeWorkManager>
{
public HomeWorkError PublicHomework(uint lesson, bool appedCommonWork = false, bool appendErrorSet = false, int workNum = -1)
{ {
HomeWorkError error= new HomeWorkError(); HomeWork work = new HomeWork { Lesson = lesson};
foreach (var item in StudentLib.StudentDic) foreach(var item in student.ErrorSet.ErrorArray)
{ {
if (item.Value.PublicHomeWork(lesson, appedCommonWork, appendErrorSet, workNum)) work.AddHomeWork(item);
{
error.Total++;
error.Correct++;
}
else
{
error.Total++;
error.Error++;
}
} }
return error;
if (appedCommonWork && CommonHomeWork.Questions.Count > 0)
{
work.Append(CommonHomeWork);
}
Public(work);
} }
internal void DeleteHomework(DetailHomeWorkSetInfo homeWork)
public static void Public(HomeWork homeWork)
{ {
throw new NotImplementedException(); foreach (var item in StudentLib.StudentDic)
} {
item.Value.PublicHomeWork(homeWork);
}
}
} }
} }

View File

@ -1,5 +1,4 @@
using DryIoc.ImTools; using DryIoc.ImTools;
using LiveCharts;
using MySqlX.XDevAPI; using MySqlX.XDevAPI;
using StudentManager.Data; using StudentManager.Data;
using System; using System;
@ -18,34 +17,30 @@ namespace StudentManager.Common
public bool Status { get; set; } = false; public bool Status { get; set; } = false;
} }
public class DetailHomeWorkInfo : BindableBase public class DetailHomeWorkInfo
{ {
//public DetailQuestionBase QuestionData { get; set; } = new DetailQuestionBase(); public DetailQuestionBase QuestionData { get; set; } = new DetailQuestionBase();
public QuestionData QuestionData { get; set; } = new QuestionData(); public DateTime DateTime { get; set; } = DateTime.Now;
//public DateTime DateTime { get; set; } = DateTime.Now; public int Lesson { get; set; } = 0;
//public int Lesson { get; set; } = 0;
public bool Status { get; set; } = false; public bool Status { get; set; } = false;
//public int TotalCount { get; set; } = 0; public int TotalCount { get; set; } = 0;
//public int ErrorCount { get; set; } = 0; public int ErrorCount { get; set; } = 0;
//public int CorrectCount { get; set; } = 0; public int CorrectCount { get; set; } = 0;
public int PID { get; set; } = 0;
} }
public class HomeWork public class HomeWork
{ {
public uint Lesson { get; set; } = 0; public int Lesson { get; set; } = 0;
public bool Status { get; set; } = false; public bool Status { get; set; } = false;
public DateTime DateTime { get; set; } = DateTime.Now; public DateTime DateTime { get; set; } = DateTime.Now;
public List<QuestionBase> Questions { get; set; } = new List<QuestionBase>(); public List<QuestionBase> Questions { get; set; } = new List<QuestionBase>();
public int TotalCount { get{return Questions.Count;} } public int TotalCount { get; set; } = 0;
public int ErrorCount { get; set; } = 0; public int ErrorCount { get; set; } = 0;
public int CorrectCount { get; set; } = 0; public int CorrectCount { get; set; } = 0;
public ObservableCollection<DetailHomeWorkInfo> GetDetailHomeWorkList() public ObservableCollection<DetailHomeWorkInfo> GetDetailHomeWorkList()
{ {
ObservableCollection<DetailHomeWorkInfo> list = new ObservableCollection<DetailHomeWorkInfo>(); ObservableCollection<DetailHomeWorkInfo> list = new ObservableCollection<DetailHomeWorkInfo>();
@ -53,28 +48,26 @@ namespace StudentManager.Common
{ {
list.Add(new DetailHomeWorkInfo list.Add(new DetailHomeWorkInfo
{ {
//QuestionData = { QuestionData = {
// QuestionData = QuestionLib.Get(item.ID), QuestionData = QuestionLib.Get(item.ID),
// Status = item.Status }, Status = item.Status },
QuestionData = QuestionLib.Instance.Get(item.ID),
Status = Status, Status = Status,
//Lesson = Lesson, Lesson = Lesson,
//DateTime = DateTime, DateTime = DateTime,
//TotalCount = TotalCount, TotalCount = TotalCount,
//ErrorCount = ErrorCount, ErrorCount = ErrorCount,
//CorrectCount = CorrectCount, CorrectCount = CorrectCount
PID = item.ID
}); });
} }
return list; return list;
} }
public void UpdateData(bool FirstAdd = false) private void FreshData()
{ {
CorrectCount = 0; CorrectCount = 0;
ErrorCount = 0; ErrorCount = 0;
if(FirstAdd) return; TotalCount = Questions.Count;
foreach (var item in Questions) foreach (var item in Questions)
{ {
if (item.Status == true) CorrectCount++; if (item.Status == true) CorrectCount++;
@ -87,18 +80,19 @@ namespace StudentManager.Common
public void AddHomeWork(QuestionBase workInfo) public void AddHomeWork(QuestionBase workInfo)
{ {
Questions.Add(workInfo); Questions.Add(workInfo);
UpdateData(); FreshData();
} }
public void AddHomeWork(int id) public void AddHomeWork(int id)
{ {
Questions.Add(new QuestionBase { ID = id }); Questions.Add(new QuestionBase { ID = id });
FreshData();
} }
public void RemoveHomeWork(QuestionBase workInfo) public void RemoveHomeWork(QuestionBase workInfo)
{ {
Questions.Remove(workInfo); Questions.Remove(workInfo);
UpdateData(); FreshData();
} }
public void Append(HomeWork homeWork) public void Append(HomeWork homeWork)
@ -107,7 +101,7 @@ namespace StudentManager.Common
{ {
Questions.Add(item); Questions.Add(item);
} }
UpdateData();
} }
} }
@ -115,94 +109,46 @@ namespace StudentManager.Common
public class DetailHomeWorkSetInfo public class DetailHomeWorkSetInfo
{ {
public uint Lesson { get; set; } = 0;
public int TotalCount { get; set; } = 0; public int TotalCount { get; set; } = 0;
public bool Status { get; set; } = false;
public DateTime DateTime { get; set; } = DateTime.Now;
public int Lesson { get; set; } = 0;
public int ErrorCount { get; set; } = 0; public int ErrorCount { get; set; } = 0;
public int CorrectCount { get; set; } = 0; public int CorrectCount { get; set; } = 0;
public bool Status { get; set; } = false;
public DateTime DateTime { get; set; } = DateTime.Now;
} }
public class HomeWorkSet public class HomeWorkSet
{ {
[JsonInclude] [JsonInclude]
private Dictionary<uint, HomeWork> HomeWorks { get; set; } = new Dictionary<uint, HomeWork>(); private Dictionary<int, HomeWork> HomeWorks { get; set; } = new Dictionary<int, HomeWork>();
public int TotalSetCount { get; set; } = 0; public int TotalCount { 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;
[JsonIgnore]
public List<string> Lessons { get; set; } = new List<string>();
[JsonIgnore]
public ChartValues<double> ErrorCounts { get; set; } = new ChartValues<double>();
[JsonIgnore]
public ChartValues<double> CorrectCounts { get; set; } = new ChartValues<double>();
public void UpdateDataView()
{
if(ErrorCounts.Count == 0)
{
foreach (var item in HomeWorks)
{
Lessons.Add(item.Key.ToString());
ErrorCounts.Add(item.Value.ErrorCount);
CorrectCounts.Add(item.Value.CorrectCount);
}
}
}
public void UpdateDate()
{
TotalSetCount = HomeWorks.Count;
TotalQuestionCount = 0;
TotalErrorQuestionCount = 0;
TotalCorrectQuestionCount = 0;
Lessons.Clear();
ErrorCounts.Clear();
CorrectCounts.Clear();
foreach (var item in HomeWorks)
{
TotalQuestionCount += item.Value.TotalCount;
TotalErrorQuestionCount += item.Value.ErrorCount;
TotalCorrectQuestionCount += item.Value.CorrectCount;
Lessons.Add(item.Key.ToString());
ErrorCounts.Add(item.Value.ErrorCount);
CorrectCounts.Add(item.Value.CorrectCount);
}
TotalErrorQuestionRate = TotalQuestionCount == 0 ? 0 : TotalErrorQuestionCount / TotalQuestionCount;
}
public bool Contain(uint id)
{
return HomeWorks.ContainsKey(id);
}
public void AddHomeWork(HomeWork homeWork) public void AddHomeWork(HomeWork homeWork)
{ {
HomeWorks.Add(homeWork.Lesson, homeWork); HomeWorks.Add(homeWork.Lesson, homeWork);
TotalCount = HomeWorks.Count;
} }
public ObservableCollection<DetailHomeWorkInfo> GetDetailHomeWorkList(uint lesson) public ObservableCollection<DetailHomeWorkInfo> GetDetailHomeWorkList(int lesson)
{ {
ObservableCollection<DetailHomeWorkInfo> list = new ObservableCollection<DetailHomeWorkInfo>(); ObservableCollection<DetailHomeWorkInfo> list = new ObservableCollection<DetailHomeWorkInfo>();
foreach (var item in HomeWorks[lesson].Questions) foreach (var item in HomeWorks[lesson].Questions)
{ {
list.Add(new DetailHomeWorkInfo list.Add(new DetailHomeWorkInfo
{ {
QuestionData = QuestionLib.Instance.Get(item.ID), QuestionData = {
Status = item.Status, QuestionData = QuestionLib.Get(item.ID),
PID = item.ID Status = item.Status },
Status = HomeWorks[lesson].Status,
Lesson = HomeWorks[lesson].Lesson,
DateTime = HomeWorks[lesson].DateTime,
TotalCount = HomeWorks[lesson].TotalCount,
ErrorCount = HomeWorks[lesson].ErrorCount,
CorrectCount = HomeWorks[lesson].CorrectCount
}); });
} }
@ -233,10 +179,9 @@ namespace StudentManager.Common
public void RemoveHomeWork(HomeWork homeWork) public void RemoveHomeWork(HomeWork homeWork)
{ {
HomeWorks.Remove(homeWork.Lesson); HomeWorks.Remove(homeWork.Lesson);
UpdateDate();
} }
public HomeWork Get(uint cursonId) public HomeWork Get(int cursonId)
{ {
if (HomeWorks.ContainsKey(cursonId)) return HomeWorks[cursonId]; if (HomeWorks.ContainsKey(cursonId)) return HomeWorks[cursonId];
return null; return null;
@ -244,7 +189,7 @@ namespace StudentManager.Common
public HomeWork GetLast() public HomeWork GetLast()
{ {
return HomeWorks[(uint)TotalSetCount]; return HomeWorks[TotalCount];
} }
public List<HomeWork> GetAll() public List<HomeWork> GetAll()
@ -263,32 +208,25 @@ namespace StudentManager.Common
return works; return works;
} }
public void FreshAllHomeWork(long id) public void FreshAllHomeWork(int id)
{ {
HomeWorks.Clear(); HomeWorks.Clear();
SQLHelper.Instance.Query<CursonQuestionsData>(id).ForEach(x => SQLHelper.Query<CursonQuestionsData>(Tables.CQTable, id).ForEach(x =>
{ {
List<QuestionBase> Questions = new List<QuestionBase>(); List<QuestionBase> Questions = new List<QuestionBase>();
x.ProblemIDS.ForEach(y => Questions.Add(new QuestionBase { ID = y, Status = x.CorrectIDS.Contains(y) })); x.ProblemIDS.ForEach(y => Questions.Add(new QuestionBase { ID = y, Status = x.CorrectIDS.Contains(y) }));
HomeWorks.Add(x.Lesson, new HomeWork HomeWorks.Add(x.Lesson, new HomeWork
{ {
Lesson = x.Lesson, Lesson = x.Lesson,
TotalCount = x.ProblemIDS.Length,
CorrectCount = x.CorrectCount, CorrectCount = x.CorrectCount,
ErrorCount = x.Status == 1 ? x.TotalCount - x.CorrectCount : 0, ErrorCount = x.TotalCount - x.CorrectCount,
DateTime = x.DateTime, DateTime = x.DateTime,
Questions = Questions, Questions = Questions,
Status = x.Status == 1 Status = x.Status == 1
}); });
}); });
UpdateDate();
}
internal void DeleteHomework(uint lesson)
{
HomeWorks.Remove(lesson);
UpdateDate();
} }
} }

View File

@ -1,16 +1,26 @@
using DryIoc.ImTools; using DryIoc.ImTools;
using Google.Protobuf.WellKnownTypes;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Newtonsoft.Json; using Newtonsoft.Json;
using StudentManager.Common;
using StudentManager.Data; using StudentManager.Data;
using System.Diagnostics;
using System; using System;
using Enum = System.Enum; using System.Collections.Generic;
using System.Security.Cryptography; using System.Diagnostics;
using StudentManager.Interface; using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Common namespace StudentManager.Common
{ {
static class Tables
{
static public string UserTable { get; } = "users";
static public string QuesTable { get; } = "questions";
static public string UQTable { get; } = "user_data";
static public string CQTable { get; } = "curson_questions";
}
public static class SQLMapping public static class SQLMapping
{ {
public static void Mapping<T>(MySqlDataReader reader) public static void Mapping<T>(MySqlDataReader reader)
@ -22,7 +32,7 @@ namespace StudentManager.Common
{ {
if (typeof(T) == typeof(StudentData)) if (typeof(T) == typeof(StudentData))
{ {
(data as StudentData).UID = (long)reader[0]; (data as StudentData).UID = (int)reader[0];
(data as StudentData).Name = reader[1].ToString(); (data as StudentData).Name = reader[1].ToString();
(data as StudentData).Gender = reader[2].ToString(); (data as StudentData).Gender = reader[2].ToString();
(data as StudentData).Contact = reader[3].ToString(); (data as StudentData).Contact = reader[3].ToString();
@ -30,20 +40,14 @@ namespace StudentManager.Common
(data as StudentData).Grade = (byte)reader[5]; (data as StudentData).Grade = (byte)reader[5];
(data as StudentData).TotalsQuestions = (UInt16)reader[6]; (data as StudentData).TotalsQuestions = (UInt16)reader[6];
(data as StudentData).CorrectionCount = (UInt16)reader[7]; (data as StudentData).CorrectionCount = (UInt16)reader[7];
(data as StudentData).CurronHomeWorkIndex = (uint)reader[8]; (data as StudentData).HomeWork = (UInt16)reader[8];
(data as StudentData).Password = reader[9].ToString();
(data as StudentData).Birthdate = (DateTime)reader[10];
(data as StudentData).HWQTotalCount = (uint)reader[11];
(data as StudentData).HWQTotalErrorCount = (uint)reader[12];
} }
else if (typeof(T) == typeof(QuestionData)) else if (typeof(T) == typeof(QuestionData))
{ {
DifficultyLevel dLevel = DifficultyLevel.easy; DifficultyLevel dLevel = DifficultyLevel.easy;
QStatus qStatus = QStatus.published; QStatus qStatus = QStatus.published;
QType qType = QType.;
(data as QuestionData).Id = (int)reader[0]; (data as QuestionData).Id = (int)reader[0];
Enum.TryParse(reader[1].ToString(), true, out qType); (data as QuestionData).Type = reader[1].ToString();
(data as QuestionData).Type = qType;
(data as QuestionData).Stem = reader[2].ToString(); (data as QuestionData).Stem = reader[2].ToString();
(data as QuestionData).Answer = reader[3].ToString(); (data as QuestionData).Answer = reader[3].ToString();
Enum.TryParse(reader[4].ToString(), true, out dLevel); Enum.TryParse(reader[4].ToString(), true, out dLevel);
@ -51,17 +55,16 @@ namespace StudentManager.Common
(data as QuestionData).Category = reader[5].ToString(); (data as QuestionData).Category = reader[5].ToString();
(data as QuestionData).Tags = reader[6].ToString(); (data as QuestionData).Tags = reader[6].ToString();
(data as QuestionData).Source = reader[7].ToString(); (data as QuestionData).Source = reader[7].ToString();
(data as QuestionData).Lesson = (uint)reader[8]; Enum.TryParse(reader[8].ToString(), true, out qStatus);
Enum.TryParse(reader[9].ToString(), true, out qStatus);
(data as QuestionData).Status = qStatus; (data as QuestionData).Status = qStatus;
} }
else if (typeof(T) == typeof(CursonQuestionsData)) else if (typeof(T) == typeof(CursonQuestionsData))
{ {
(data as CursonQuestionsData).UID = (long)reader[0]; (data as CursonQuestionsData).UID = (int)reader[0];
(data as CursonQuestionsData).ProblemIDS = string.IsNullOrEmpty(reader[1].ToString()) ? Array.Empty<int>() : JsonConvert.DeserializeObject<int[]>(reader[1].ToString()); (data as CursonQuestionsData).ProblemIDS = string.IsNullOrEmpty(reader[1].ToString()) ? Array.Empty<int>() : JsonConvert.DeserializeObject<int[]>(reader[1].ToString());
(data as CursonQuestionsData).CorrectIDS = string.IsNullOrEmpty(reader[2].ToString()) ? Array.Empty<int>() : JsonConvert.DeserializeObject<int[]>(reader[2].ToString()); (data as CursonQuestionsData).CorrectIDS = string.IsNullOrEmpty(reader[2].ToString()) ? Array.Empty<int>() : JsonConvert.DeserializeObject<int[]>(reader[2].ToString());
(data as CursonQuestionsData).Lesson = (uint)reader[3]; (data as CursonQuestionsData).Lesson = (byte)reader[3];
(data as CursonQuestionsData).Status = (byte)reader[4]; (data as CursonQuestionsData).Status = (byte)reader[4];
(data as CursonQuestionsData).DateTime = (DateTime)reader[5]; (data as CursonQuestionsData).DateTime = (DateTime)reader[5];
(data as CursonQuestionsData).TotalCount = (data as CursonQuestionsData).ProblemIDS.Length; (data as CursonQuestionsData).TotalCount = (data as CursonQuestionsData).ProblemIDS.Length;
@ -74,491 +77,139 @@ namespace StudentManager.Common
(data as UserQuestionData).CorrectCount = (byte)reader[3]; (data as UserQuestionData).CorrectCount = (byte)reader[3];
(data as UserQuestionData).Status = (byte)reader[4] == 1; (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]); });
//}
}
} }
public class SQLHelper : Singleton<SQLHelper>
struct userTable
{ {
private Dictionary<System.Type, string> TypeMap = new Dictionary<System.Type, string>
}
public static class SQLHelper
{
static string config = "server=8.137.125.29;port=3306;user=StudentManager;password=wangxin55;database=studentmanager";
static MySqlConnection connection = null;
static MySqlCommand cmd = null;
// update ** set ** = '**',... where ** = **;
// insert into ** values('**','**'...);
// delete from ** where ** = **;
public static List<T> Query<T>(string tableName, int id = -1, params string[] queryParams) where T : IDataCommon, new()
{ {
{ typeof(QuestionData), "questions" }, connection = new MySqlConnection(config);
{ typeof(CursonQuestionsData), "curson_questions" },
{ typeof(StudentData), "users" },
{ typeof(UserQuestionData), "user_data" },
};
private string config = "server=8.137.125.29;port=3306;user=StudentManager;password=wangxin55;database=studentmanager"; List<T> result = new List<T>();
private MySqlConnection connection = null;
private MySqlCommand cmd = null;
string idName = typeof(T) == typeof(StudentData) ? "user_id" : typeof(T) == typeof(QuestionData) ? "problem_id" : "user_id";
public List<T> Query<T>(long? id = null, params string[] queryParams) where T : IDataCommon, new() try
{
string tableName = string.Empty;
TypeMap.TryGetValue(typeof(T), out tableName);
using (var connection = new MySqlConnection(config))
{ {
List<T> result = new List<T>(); connection.Open();
string idName = typeof(T) == typeof(StudentData) ? "user_id" : typeof(T) == typeof(QuestionData) ? "problem_id" : "user_id"; string queryStr = "";
if (queryParams.Length > 0)
try
{ {
connection.Open(); string filedList = string.Join(",", queryParams);
string queryStr = ""; queryStr = $"select {filedList} from {tableName};";
if (queryParams.Length > 0)
{
string fieldList = string.Join(",", queryParams);
queryStr = $"SELECT {fieldList} FROM {tableName}";
if (id.HasValue) if (id != -1)
queryStr += $" WHERE {idName} = @id"; queryStr = $@"select {filedList} from {tableName} WHERE {idName} = {id};";
}
else
{
queryStr = $"SELECT * FROM {tableName}";
if (id.HasValue)
queryStr += $" WHERE {idName} = @id";
}
using (var cmd = new MySqlCommand(queryStr, connection))
{
if (id.HasValue)
cmd.Parameters.AddWithValue("@id", id.Value);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
T row = new T();
SQLMapping.Mapping(row, reader);
result.Add(row);
}
}
}
return result;
} }
catch (MySqlException ex) else
{ {
Console.WriteLine($"MySQL error: {ex.Message}"); queryStr = $"select * from {tableName};";
return new List<T> { }; if (id != -1)
queryStr = $@"select * from {tableName} WHERE {idName} = {id};";
} }
catch (Exception ex)
cmd = new MySqlCommand(queryStr, connection);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{ {
Console.WriteLine($"General error: {ex.Message}"); T row = new T();
return new List<T> { }; SQLMapping.Mapping(row, reader);
result.Add(row);
} }
return result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
finally
{
cmd.Dispose();
connection.Close();
} }
} }
public static List<T> UnionQuery<T>(int id = -1, string tableName = "questions", string otherTable = "user_data") where T : IDataCommon, new()
public bool Add<T>(T value) where T : IDataCommon
{ {
string tableName = string.Empty; connection = new MySqlConnection(config);
TypeMap.TryGetValue(typeof(T), out tableName);
using (var connection = new MySqlConnection(config)) List<T> result = new List<T>();
try
{ {
try connection.Open();
{ string queryStr = "";
connection.Open(); if(id == -1)
queryStr = $@"SELECT u.user_id, q.* FROM {otherTable} u JOIN {tableName} q ON u.problem_id = q.problem_id";
else
queryStr = $@"SELECT q.* FROM {tableName} q JOIN {otherTable} u ON q.problem_id = u.problem_id WHERE u.user_id = {id}";
if (typeof(T) == typeof(QuestionData)) cmd = new MySqlCommand(queryStr, connection);
{ MySqlDataReader reader = cmd.ExecuteReader();
var ques = value as QuestionData;
string sql = $"INSERT INTO {tableName} " +
"(problem_id, problem_type, problem_stem, problem_answer, difficulty_level, category, tags, source, lesson, status) " +
"VALUES (@Id, @Type, @Stem, @Answer, @DifficultyLevel, @Category, @Tags, @Source, @Lesson, @Status)";
using (var cmd = new MySqlCommand(sql, connection))
{
cmd.Parameters.AddWithValue("@Id", ques.Id);
cmd.Parameters.AddWithValue("@Type", ques.Type.ToString());
cmd.Parameters.AddWithValue("@Stem", ques.Stem);
cmd.Parameters.AddWithValue("@Answer", ques.Answer);
cmd.Parameters.AddWithValue("@DifficultyLevel", ques.DifficultyLevel.ToString());
cmd.Parameters.AddWithValue("@Category", ques.Category);
cmd.Parameters.AddWithValue("@Tags", ques.Tags);
cmd.Parameters.AddWithValue("@Source", ques.Source);
cmd.Parameters.AddWithValue("@Lesson", ques.Lesson);
cmd.Parameters.AddWithValue("@Status", ques.Status.ToString());
cmd.ExecuteNonQuery();
} while (reader.Read())
}
}
catch (MySqlException ex)
{ {
Console.WriteLine($"MySQL error: {ex.Message}"); T row = new T();
return false; SQLMapping.Mapping(row, reader);
result.Add(row);
} }
catch (Exception ex)
{ return result;
Console.WriteLine($"General error: {ex.Message}"); }
return false; catch (Exception ex)
} {
return true; Console.WriteLine(ex.Message);
return null;
}
finally
{
cmd.Dispose();
connection.Close();
} }
} }
public bool Delete<T>(T value) where T : IDataCommon public static void Add()
{ {
string tableName = string.Empty; try
TypeMap.TryGetValue(typeof(T), out tableName);
using (var connection = new MySqlConnection(config))
{ {
try
{
connection.Open();
if (typeof(T) == typeof(CursonQuestionsData))
{
var ques = value as CursonQuestionsData;
string sql = "DELETE FROM " +
$"{tableName} " +
"WHERE user_id = @user_id AND lesson = @lesson";
using (var cmd = new MySqlCommand(sql, connection))
{
cmd.Parameters.AddWithValue("@user_id", ques.UID);
cmd.Parameters.AddWithValue("@lesson", ques.Lesson);
cmd.ExecuteNonQuery();
}
}
if (typeof(T) == typeof(QuestionData))
{
var ques = value as QuestionData;
if (ques == null)
{
Console.WriteLine($"ERROR: Check Input");
return false;
}
string sql = $"DELETE " +
$"FROM {tableName} " +
" WHERE problem_id = @problem_id";
using (var cmd = new MySqlCommand(sql, connection))
{
cmd.Parameters.AddWithValue("@problem_id", ques.Id);
cmd.ExecuteNonQuery();
}
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine($"General error: {ex.Message}");
return false;
}
return true;
} }
} catch (Exception ex)
internal bool UpdateErrorSet(long UID, ErrorBase error)
{
using (MySqlConnection connection = new MySqlConnection(config))
{ {
try Console.WriteLine(ex.Message);
{
connection.Open();
// 检查记录是否存在
string checkQuery = "SELECT COUNT(*) FROM user_data WHERE user_id = @user_id AND problem_id = @problem_id";
using (MySqlCommand checkCmd = new MySqlCommand(checkQuery, connection))
{
checkCmd.Parameters.AddWithValue("@user_id", UID);
checkCmd.Parameters.AddWithValue("@problem_id", error.QuestionBase.ID);
int recordCount = Convert.ToInt32(checkCmd.ExecuteScalar());
if (recordCount > 0)
{
// 记录存在,执行更新操作
string updateQuery = "UPDATE user_data SET status = @status, error_count = @error_count, correct_count = @correct_count" +
" WHERE user_id = @user_id AND problem_id = @problem_id";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{
updateCmd.Parameters.AddWithValue("@user_id", UID);
updateCmd.Parameters.AddWithValue("@problem_id", error.QuestionBase.ID);
updateCmd.Parameters.AddWithValue("@error_count", error.ErrorCount);
updateCmd.Parameters.AddWithValue("@correct_count", error.CorrectCount);
updateCmd.Parameters.AddWithValue("@status", error.QuestionBase.Status);
updateCmd.ExecuteNonQuery();
}
}
else
{
if (error.QuestionBase.Status == false)
{
string updateQuery = $"INSERT INTO user_data (user_id, problem_id) VALUES (@user_id, @problem_id)";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{
updateCmd.Parameters.AddWithValue("@user_id", UID);
updateCmd.Parameters.AddWithValue("@problem_id", error.QuestionBase.ID);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
finally
{
connection.Close();
}
return true;
} }
} finally
internal bool UpdateHomework(long UID, uint lesson, string totalArray, string correctArray, DateTime dateTime, bool status)
{
using (MySqlConnection connection = new MySqlConnection(config))
{ {
try
{
connection.Open();
string updateQuery = "UPDATE curson_questions SET status = @status, problem_ids = @problem_ids, " +
"correct_ids = @correct_ids, update_time = @update_time WHERE user_id = @user_id AND lesson = @lesson";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{
updateCmd.Parameters.AddWithValue("@user_id", UID);
updateCmd.Parameters.AddWithValue("@lesson", lesson);
updateCmd.Parameters.AddWithValue("@status", status);
updateCmd.Parameters.AddWithValue("@problem_ids", totalArray);
updateCmd.Parameters.AddWithValue("@correct_ids", correctArray);
updateCmd.Parameters.AddWithValue("@update_time", dateTime);
updateCmd.ExecuteNonQuery();
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
finally
{
connection.Close();
}
return true;
}
}
internal bool UpdateErrorSetUserInfo(long UID, uint totalCont, uint totalCorrectCount)
{
using (MySqlConnection connection = new MySqlConnection(config))
{
try
{
connection.Open();
string updateQuery = "UPDATE users SET errset_totals_questions = @totalCont, errset_correction_count = @totalErrorCount " +
" WHERE user_id = @user_id";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{
updateCmd.Parameters.AddWithValue("@user_id", UID);
updateCmd.Parameters.AddWithValue("@totalCont", totalCont);
updateCmd.Parameters.AddWithValue("@totalErrorCount", totalCorrectCount);
updateCmd.ExecuteNonQuery();
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
finally
{
connection.Close();
}
return true;
}
}
internal bool UpdateHomeworkTotalInfo(long UID, uint totalCont, uint totalErrorCount)
{
using (MySqlConnection connection = new MySqlConnection(config))
{
try
{
connection.Open();
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))
{
updateCmd.Parameters.AddWithValue("@user_id", UID);
updateCmd.Parameters.AddWithValue("@totalCont", totalCont);
updateCmd.Parameters.AddWithValue("@totalErrorCount", totalErrorCount);
updateCmd.ExecuteNonQuery();
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
finally
{
connection.Close();
}
return true;
}
}
internal bool AddHomework(CursonQuestionsData homeWork)
{
using (MySqlConnection connection = new MySqlConnection(config))
{
try
{
connection.Open();
string updateQuery = "insert into curson_questions (user_id, problem_ids, correct_ids, lesson, status, update_time)" +
"values (@user_id, @problem_ids, @correct_ids, @lesson, @status, @update_time)";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{
updateCmd.Parameters.AddWithValue("@user_id", homeWork.UID);
updateCmd.Parameters.AddWithValue("@problem_ids", JsonConvert.SerializeObject(homeWork.ProblemIDS));
updateCmd.Parameters.AddWithValue("@correct_ids", JsonConvert.SerializeObject(homeWork.CorrectIDS));
updateCmd.Parameters.AddWithValue("@lesson", homeWork.Lesson);
updateCmd.Parameters.AddWithValue("@status", homeWork.Status);
updateCmd.Parameters.AddWithValue("@update_time", homeWork.DateTime);
updateCmd.ExecuteNonQuery();
}
updateQuery = "UPDATE users SET home_work = @lesson " +
"WHERE user_id = @user_id";
using (MySqlCommand updateCmd = new MySqlCommand(updateQuery, connection))
{
updateCmd.Parameters.AddWithValue("@user_id", homeWork.UID);
updateCmd.Parameters.AddWithValue("@lesson", homeWork.Lesson);
updateCmd.ExecuteNonQuery();
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
return false;
}
finally
{
connection.Close();
}
return true;
}
}
internal bool 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 (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
finally
{
connection.Close();
}
return true;
} }
} }
} }

View File

@ -1,36 +0,0 @@
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

@ -8,12 +8,12 @@ namespace StudentManager.Data
{ {
public class CursonQuestionsData : IDataCommon public class CursonQuestionsData : IDataCommon
{ {
public long UID { get; set; } = 0; public int UID { get; set; } = 0;
public int[] ProblemIDS { get; set; } = { }; public int[] ProblemIDS { get; set; } = { };
public int[] CorrectIDS { get; set; } = { }; public int[] CorrectIDS { get; set; } = { };
public DateTime DateTime { get; set; } = DateTime.Now; public DateTime DateTime { get; set; } = DateTime.Now;
public uint Lesson { get; set; } = 0; public int Lesson { get; set; } = 0;
public int TotalCount { get; set; } = 0; public int TotalCount { get; set; } = 0;
public int CorrectCount { get; set; } = 0; public int CorrectCount { get; set; } = 0;
public int Status { get; set; } = 0; public int Status { get; set; } = 0;

View File

@ -20,27 +20,18 @@ namespace StudentManager.Data
deprecated, deprecated,
} }
public enum QType public class QuestionData : IDataCommon
{
,
,
,
}
public class QuestionData : IDataCommon
{ {
public int Id { get; set; } = 0; public int Id { get; set; } = 0;
public QType Type { get; set; } = QType.; public string Type { get; set; } = string.Empty;
public string Stem { get; set; } = string.Empty; public string Stem { get; set; } = string.Empty;
public string Answer { get; set; } = String.Empty; public string Answer { get; set; } = String.Empty;
public DifficultyLevel DifficultyLevel { get; set; } = DifficultyLevel.easy; public DifficultyLevel DifficultyLevel { get; set; } = DifficultyLevel.easy;
public string Category { get; set; } = string.Empty; public string Category { get; set; } = string.Empty;
public string Tags { get; set; } = "默认"; public string Tags { get; set; } = string.Empty;
public string Source { get; set; } = string.Empty; public string Source { get; set; } = string.Empty;
public uint Lesson { get; set; } = 0; public int Lesson { get; set; } = 0;
public QStatus Status { get; set; } = QStatus.published; public QStatus Status { get; set; } = QStatus.published;
public DateTime UpdateTime { get; set; } = DateTime.MinValue;
//public string TableName { get => "questions"; set => throw new NotImplementedException(); } //public string TableName { get => "questions"; set => throw new NotImplementedException(); }

View File

@ -1,7 +1,5 @@
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;
@ -11,90 +9,39 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Mysqlx.Crud.UpdateOperation.Types;
namespace StudentManager.Data namespace StudentManager.Data
{ {
public class QuestionSetDesc public static class QuestionLib
{
public uint TotalQuestions { get; set; } = 0;
public DateTime UpdateTime { get; set; } = DateTime.Now;
public uint Lesson { get; set; } = 0;
}
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 TableDescFileName = "questionTableDescLib.dbqi";
public static Dictionary<int, QuestionData> QuestionDic { get; set; } = new Dictionary<int, QuestionData>(); public static Dictionary<int, QuestionData> QuestionDic { get; set; } = new Dictionary<int, QuestionData>();
public static Dictionary<uint, QuestionSetDesc> QuestionTableDesc { get; set; } = new Dictionary<uint, QuestionSetDesc>(); public static int TotalCount { get; set; } = 0;
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 void Load() public static int GetQuestionCount()
{
TotalCount = QuestionDic.Count;
return TotalCount;
}
public static void Load()
{ {
QuestionDic.Clear(); QuestionDic.Clear();
if(!Path.Exists(StudentLib.LibPath))
Directory.CreateDirectory(Path.GetFullPath( StudentLib.LibPath));
Debug.Assert(Path.Exists(StudentLib.LibPath)); Debug.Assert(Path.Exists(StudentLib.LibPath));
if (!Path.Exists(StudentLib.LibPath + FileName))
File.WriteAllText((StudentLib.LibPath + FileName), "");
string file = File.ReadAllText(StudentLib.LibPath + FileName); string file = File.ReadAllText(StudentLib.LibPath + FileName);
if (file.Length != 0) QuestionDic = JsonSerializer.Deserialize<Dictionary<int, QuestionData>>(file);
QuestionDic = JsonSerializer.Deserialize<Dictionary<int, QuestionData>>(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<Dictionary<uint, Dictionary<int, QuestionData>>>(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<Dictionary<uint, QuestionSetDesc>>(file);
} }
public void Save() public static 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 + TableDescFileName), JsonSerializer.Serialize(QuestionTableDesc));
} }
public void FreshAllQuestion() public static void FreshAllQuestion()
{ {
SQLHelper.Query<QuestionData>(Tables.QuesTable).ForEach(x => QuestionDic.Add(x.Id, x));
}
QuestionDic.Clear (); public static ObservableCollection<QuestionData> GetAllQuestion()
QuestionTableDic.Clear ();
QuestionTableDesc.Clear ();
SQLHelper.Instance.Query<QuestionData>().ForEach(x => QuestionDic.Add(x.Id, x));
SQLHelper.Instance.Query<QuestionData>().ForEach(x => {
if (!QuestionTableDic.ContainsKey(x.Lesson))
{
QuestionTableDic[x.Lesson] = new Dictionary<int, QuestionData>();
}
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 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)
@ -103,72 +50,27 @@ namespace StudentManager.Data
} }
return list; return list;
} }
public ObservableCollection<QuestionData> GetAllQuestionByLesson(uint lesson)
{
if (!QuestionTableDic.ContainsKey(lesson)) return new ObservableCollection<QuestionData>();
var list = new ObservableCollection<QuestionData>(); public static QuestionData Get(int id)
foreach (QuestionData data in QuestionTableDic[lesson].Values)
{
list.Add(data);
}
return list;
}
public QuestionData Get(int id)
{ {
if (!QuestionDic.ContainsKey(id)) return null; if (!QuestionDic.ContainsKey(id)) return null;
return QuestionDic[id]; return QuestionDic[id];
} }
public QuestionData Get(uint lesson , int id) public static void Add(QuestionData question)
{ {
if (!QuestionDic.ContainsKey(id)) return null;
return QuestionDic[id];
}
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))
{
QuestionTableDic[question.Lesson] = new Dictionary<int, QuestionData>();
}
QuestionTableDic[question.Lesson][question.Id] = question;
QuestionTableDesc[question.Lesson].UpdateTime = DateTime.Now;
QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count;
return true;
} }
public bool Remove(QuestionData question) public static void Remove(QuestionData question)
{ {
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);
QuestionTableDesc[question.Lesson].TotalQuestions = (uint)QuestionTableDic[question.Lesson].Count;
return true;
} }
public void Remove(int id) public static void Remove(int id)
{ {
QuestionDic.Remove(id); QuestionDic.Remove(id);
} }
internal void Update(QuestionData selectedQuestion)
{
if(QuestionDic[selectedQuestion.Id] != null)
QuestionDic[selectedQuestion.Id] = selectedQuestion;
else
QuestionDic.Add(selectedQuestion.Id, selectedQuestion);
}
} }
} }

View File

@ -6,41 +6,24 @@ using System.Threading.Tasks;
namespace StudentManager.Data namespace StudentManager.Data
{ {
public enum Gender
{
,
,
}
public class StudentData : IDataCommon public class StudentData : IDataCommon
{ {
// Count info public int UID { get; set; } = 1;
public long UID { get; set; } = 1;
public string Password { get; set; } = "123456";
// Base info
public string Name { get; set; } = "Name"; public string Name { get; set; } = "Name";
public string Gender { get; set; } = "Gender"; public string Gender { get; set; } = "Gender";
public string Contact { get; set; } = "Contact"; public string Contact { get; set; } = "Contact";
public string Address { get; set; } = "Address"; public string Address { get; set; } = "Address";
public int Grade { get; set; } = 1; public int Grade { get; set; } = 1;
public DateTime Birthdate { get; set; } = DateTime.Now;
// Error Set
public int TotalsQuestions { get; set; } = 0; public int TotalsQuestions { get; set; } = 0;
public int CorrectionCount { get; set; } = 0; public int CorrectionCount { get; set; } = 0;
public int HomeWork { get; set; } = 0;
// HomeWork
public uint CurronHomeWorkIndex { get; set; } = 0;
// HomeWorkSet
public uint HWQTotalCount { get; set; } = 0;
public uint HWQTotalErrorCount { get; set; } = 0;
// Extension
public float ErrorRate { get; set; } = 0; public float ErrorRate { get; set; } = 0;
public float CorrectRate { get; set; } = 0; public float CorrectRate { get; set; } = 0;
public int UnCorrectCount { get; set; } = 0; public int UnCorrectCount { get; set; } = 0;
//public string TableName { get => "users"; set => throw new NotImplementedException(); }
} }
} }

View File

@ -16,7 +16,7 @@ namespace StudentManager.Data
{ {
public static string LibPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\FileLib\\"; public static string LibPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\FileLib\\";
public static string FileName = "studentLib.dbsi"; public static string FileName = "studentLib.dbsi";
public static Dictionary<long, StudentInfo> StudentDic { get; set; } = new Dictionary<long, StudentInfo>(); public static Dictionary<int, StudentInfo> StudentDic { get; set; } = new Dictionary<int, StudentInfo>();
public static void Add(StudentInfo studentInfo) public static void Add(StudentInfo studentInfo)
{ {
@ -28,9 +28,9 @@ namespace StudentManager.Data
{ {
StudentDic.Clear(); StudentDic.Clear();
if (!Path.Exists(LibPath + FileName)) return; Debug.Assert(Path.Exists(LibPath));
string file = File.ReadAllText(LibPath + FileName); string file = File.ReadAllText(LibPath + FileName);
StudentDic = JsonSerializer.Deserialize<Dictionary<long, StudentInfo>>(file); StudentDic = JsonSerializer.Deserialize<Dictionary<int, StudentInfo>>(file);
} }
public static void Save() public static void Save()
@ -43,7 +43,7 @@ namespace StudentManager.Data
{ {
StudentDic.Clear(); StudentDic.Clear();
SQLHelper.Instance.Query<StudentData>().ForEach(x => SQLHelper.Query<StudentData>(Tables.UserTable).ForEach(x =>
StudentDic.Add(x.UID, new StudentInfo StudentDic.Add(x.UID, new StudentInfo
{ {
UID = x.UID, UID = x.UID,
@ -51,15 +51,14 @@ namespace StudentManager.Data
Address = x.Address, Address = x.Address,
Contact = x.Contact, Contact = x.Contact,
Grade = x.Grade, Grade = x.Grade,
Gender = x.Gender, CurrentHomeWorkIndex = x.HomeWork,
CurrentHomeWorkIndex = x.CurronHomeWorkIndex,
})); }));
foreach (var item in StudentDic) foreach (var item in StudentDic)
{ {
GetStudentDetailInfo(item.Value); GetStudentDetailInfo(item.Value);
} }
} }
public static ObservableCollection<StudentInfo> GetAllStudents() public static ObservableCollection<StudentInfo> GetAllStudents()
{ {
@ -71,12 +70,12 @@ namespace StudentManager.Data
return list; return list;
} }
public static StudentInfo QueryStudentDetailInfo(long uid) public static StudentInfo QueryStudentDetailInfo(int uid)
{ {
return GetStudentDetailInfo(Get(uid)); return GetStudentDetailInfo(Get(uid));
} }
public static StudentInfo Get(long uid) public static StudentInfo Get(int uid)
{ {
if (!StudentDic.ContainsKey(uid)) return null; if (!StudentDic.ContainsKey(uid)) return null;
return StudentDic[uid]; return StudentDic[uid];
@ -87,7 +86,7 @@ namespace StudentManager.Data
StudentDic.Remove(studentInfo.UID); StudentDic.Remove(studentInfo.UID);
} }
public static void Remove(long id) public static void Remove(int id)
{ {
StudentDic.Remove(id); StudentDic.Remove(id);
} }
@ -97,8 +96,6 @@ namespace StudentManager.Data
studentData.ErrorSet.QueryErrorSet(studentData.UID); studentData.ErrorSet.QueryErrorSet(studentData.UID);
studentData.HomeWorkSet.FreshAllHomeWork(studentData.UID); studentData.HomeWorkSet.FreshAllHomeWork(studentData.UID);
studentData.CurentHomeWork = studentData.HomeWorkSet.Get(studentData.CurrentHomeWorkIndex); studentData.CurentHomeWork = studentData.HomeWorkSet.Get(studentData.CurrentHomeWorkIndex);
return studentData; return studentData;
} }
@ -111,7 +108,7 @@ namespace StudentManager.Data
public class StudentInfo public class StudentInfo
{ {
public long UID { get; set; } = 1; public int UID { get; set; } = 1;
public string Name { get; set; } = "Name"; public string Name { get; set; } = "Name";
public string Gender { get; set; } = "Gender"; public string Gender { get; set; } = "Gender";
public string Contact { get; set; } = "Contact"; public string Contact { get; set; } = "Contact";
@ -123,66 +120,12 @@ namespace StudentManager.Data
public ErrorSet ErrorSet { get; set; } = new ErrorSet(); public ErrorSet ErrorSet { get; set; } = new ErrorSet();
public HomeWorkSet HomeWorkSet { get; set; } = new HomeWorkSet(); public HomeWorkSet HomeWorkSet { get; set; } = new HomeWorkSet();
public uint CurrentHomeWorkIndex = 0; public int CurrentHomeWorkIndex = 0;
public HomeWork CurentHomeWork { get; set; } = new HomeWork(); public HomeWork CurentHomeWork { get; set; } = new HomeWork();
public bool PublicHomeWork(uint lesson, bool appendCommonWork = false, bool appendErrorSet = false, int workNum = -1) public void PublicHomeWork(HomeWork homeWork)
{ {
HomeWork homeWork = new HomeWork(); HomeWorkSet.AddHomeWork(homeWork);
homeWork.Lesson = (uint)(HomeWorkSet.TotalSetCount + 1);
while (HomeWorkSet.Contain(homeWork.Lesson))
{
homeWork.Lesson++;
}
homeWork.DateTime = DateTime.Now;
if (appendErrorSet)
{
ErrorSet.ErrorArray.ForEach(error =>
homeWork.AddHomeWork(error));
}
if (appendCommonWork)
{
foreach (var item in QuestionLib.Instance.GetAllQuestionByLesson(lesson))
{
homeWork.AddHomeWork(item.Id);
}
}
if (workNum != -1)
{
}
homeWork.UpdateData(true);
CursonQuestionsData cqd = new CursonQuestionsData();
cqd.ProblemIDS = new int[homeWork.Questions.Count];
int index = 0;
homeWork.Questions.ForEach(question =>
{
cqd.ProblemIDS[index] = question.ID;
index++;
});
cqd.UID = UID;
cqd.Lesson = homeWork.Lesson;
cqd.DateTime = homeWork.DateTime;
cqd.Status = 0;
if (SQLHelper.Instance.AddHomework(cqd))
{
HomeWorkSet.AddHomeWork(homeWork);
HomeWorkSet.UpdateDate();
SQLHelper.Instance.UpdateHomeworkTotalInfo(UID, (uint)HomeWorkSet.TotalQuestionCount, (uint)HomeWorkSet.TotalErrorQuestionCount);
CurentHomeWork = homeWork;
return true;
}
else
{
return false;
}
} }
} }
} }

View File

@ -1,144 +0,0 @@
<UserControl x:Class="StudentManager.Editor.AddHomeWork"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel VerticalAlignment="Stretch">
<Border Background="#FFFFFF" BorderBrush="Gray" BorderThickness="0" CornerRadius="5" Padding="10" Margin="5" Height="150">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<StackPanel>
<CheckBox Margin="2,10" Content="是否加入公共题库" IsChecked="{Binding IsAddPublicQuestionsLib}"/>
<CheckBox Margin="2,10" Content="是否需要纠错" IsChecked="{Binding IsNeedErrorset}"/>
<CheckBox Margin="2,10" Content="是否控制题目数量" IsChecked="{Binding IsControlQuestionNum}"/>
</StackPanel>
</Border>
<Border Background="#FFFFFF" BorderBrush="Gray" BorderThickness="0" CornerRadius="5" Padding="10" Margin="5">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<StackPanel Margin="5">
<TextBlock Margin="0,10" Text=" 课程章节序号 "/>
<TextBox Text="{Binding PublicLesson}" MinWidth="50"/>
</StackPanel>
</Border>
<Border Background="#FFFFFF" BorderBrush="Gray" BorderThickness="0" CornerRadius="5" Padding="10" Margin="5">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<StackPanel Margin="5">
<TextBlock Margin="0,10" Text=" 问题数量 "/>
<TextBox Text="{Binding QuestionCount}" MinWidth="50"/>
</StackPanel>
</Border>
</StackPanel>
<Border BorderBrush="#FFE1E1E1" BorderThickness="1,0,0,0" Margin="0,0,0,0" Grid.Column="1"/>
<DockPanel Grid.Column="1" LastChildFill="False">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" DockPanel.Dock="Top" VerticalScrollBarVisibility="Hidden" Margin="10">
<ItemsControl Grid.Row="1" ItemsSource="{Binding StudentDatas}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="#FFF9F9F9" BorderBrush="Gray" BorderThickness="0" CornerRadius="10"
Padding="5" Height="150" Width="120" Margin="5" IsHitTestVisible="True">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel>
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="{Binding Type}"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" DockPanel.Dock="Bottom" VerticalScrollBarVisibility="Hidden" Margin="10">
<ItemsControl Grid.Row="1" ItemsSource="{Binding HomeworkTestData}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="#FFF9F9F9" BorderBrush="Gray" BorderThickness="0" CornerRadius="10"
Padding="5" Height="150" Width="120" Margin="5" IsHitTestVisible="True">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel>
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="{Binding Type}"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,60,10"/>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="题干" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="12" Margin="5"
Text="{Binding Stem}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
</Grid>
<Button Grid.Row="1" DockPanel.Dock="Bottom" Content="发布作业" Style="{DynamicResource MaterialDesignFlatDarkButton}"
Command="{Binding PublicHomeWorkCommand}"/>
</Grid>
</UserControl>

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace StudentManager.Editor
{
/// <summary>
/// AddHomeWork.xaml 的交互逻辑
/// </summary>
public partial class AddHomeWork : UserControl
{
public AddHomeWork()
{
InitializeComponent();
}
}
}

View File

@ -1,55 +0,0 @@
<UserControl x:Class="StudentManager.Editor.AddQuestionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:dt="clr-namespace:StudentManager.Data"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<Style TargetType="TextBox" BasedOn="{StaticResource MaterialDesignTextBox}" >
<Setter Property="MinWidth" Value="100"/>
</Style>
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="DifficultyEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="dt:DifficultyLevel"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="TypeEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="dt:QType"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="PublishEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="dt:QStatus"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</UserControl.Resources>
<Grid>
<DockPanel LastChildFill="False">
<DataGrid DockPanel.Dock="Top" ItemsSource="{Binding ADDQuestionDatas}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" CanUserDeleteRows="True"
ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<Grid HorizontalAlignment="Stretch" DockPanel.Dock="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Content="提交" HorizontalContentAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="0"
Command="{Binding SubmitAddQuestionsCommand}" Style="{DynamicResource MaterialDesignFlatDarkButton}"/>
<Button Content="清除" HorizontalContentAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="1"
Command="{Binding ClearnAddQuestionsCommand}" Style="{DynamicResource MaterialDesignFlatDarkButton}"/>
</Grid>
</DockPanel>
</Grid>
</UserControl>

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace StudentManager.Editor
{
/// <summary>
/// AddQuestionView.xaml 的交互逻辑
/// </summary>
public partial class AddQuestionView : UserControl
{
public AddQuestionView()
{
InitializeComponent();
}
}
}

View File

@ -7,126 +7,20 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources> <Grid>
<Style x:Key="TextStyle" TargetType="TextBlock">
<Setter Property="Width" Value="200"/>
</Style>
<Style x:Key="ModernMenuItemStyle" TargetType="MenuItem">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Padding" Value="10,5"/>
<Setter Property="Margin" Value="20,10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem">
<Border Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" CornerRadius="5" Height="20" Width="50">
<Grid>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" ContentSource="Header"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkGray"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- 定义 ContextMenu 的样式 -->
<Style x:Key="ModernContextMenuStyle" TargetType="ContextMenu">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="#FF007ACC"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContextMenu">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="10">
<StackPanel>
<ItemsPresenter/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ContextMenu x:Key="MyModernContextMenu" Style="{StaticResource ModernContextMenuStyle}">
<MenuItem Header="查看详情" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="DetailCheckView" Style="{StaticResource ModernMenuItemStyle}"/>
<MenuItem Header="删除" Command="{Binding DataContext.DeleteHomeworkCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" Style="{StaticResource ModernMenuItemStyle}"/>
</ContextMenu>
</UserControl.Resources>
<Grid Background="Transparent">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/>
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border CornerRadius="20"/>
<ListBox ItemsSource="{Binding StudentDatas}" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0" x:Name="StudentListBox" <ListBox ItemsSource="{Binding StudentDatas}"
SelectedItem="{Binding SelectedStudent}" Loaded="StudentListBox_Loaded"> SelectedItem="{Binding SelectedStudent}">
<ListBox.Resources>
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<ScrollViewer Margin="0" Focusable="false">
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="White"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
CornerRadius="5">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FF007ACC"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFBEE6FD"/>
<Setter Property="BorderBrush" Value="#FF3C7FB1"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged"> <i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction <i:InvokeCommandAction
CommandParameter="{Binding SelectedItem, ElementName=StudentListBox}" Command="{Binding DataContext.SelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
Command="{Binding DataContext.SelectedCommand ,ElementName=StudentListBox}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name}"/> <TextBlock Text="{Binding Name}"/>
@ -134,116 +28,32 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<Border Grid.Column="1"> <Grid Grid.Column="1">
<ScrollViewer Grid.Column="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Margin="0"> <StackPanel>
<ItemsControl ItemsSource="{Binding HomeWorkSet}" HorizontalAlignment="Left"> <TextBlock Text="{Binding SelectedStudent.Name}"/>
<ItemsControl.ItemsPanel> <ListBox ItemsSource="{Binding CQDatas}"
<ItemsPanelTemplate> SelectionChanged="ListBox_SelectionChanged">
<WrapPanel/>
</ItemsPanelTemplate> <i:Interaction.Triggers>
</ItemsControl.ItemsPanel> <i:EventTrigger EventName="MouseDoubleClick">
<ItemsControl.ItemTemplate> <i:InvokeCommandAction
CommandParameter="DetailCheckView"
Command="{Binding DataContext.RegionTo ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border Background="#FFF9F9F9" BorderBrush="Gray" BorderThickness="0" CornerRadius="10" Margin="5" MouseRightButtonUp="Border_MouseRightButtonUp" <StackPanel Orientation="Horizontal">
Padding="5" Height="240" Width="140" IsHitTestVisible="True"> <TextBlock Text="{Binding TotalCount}"/>
<Border.Effect> <TextBlock Text="{Binding CorrectCount}"/>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/> <TextBlock Text="{Binding Lesson}"/>
</Border.Effect> </StackPanel>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding DataContext.HomeWorkSetSelectedCommand ,RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding }"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DockPanel LastChildFill="False">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="Lesson:"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="{Binding Lesson}"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
</StackPanel>
<Border DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="总题数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding TotalCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="总错误数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding ErrorCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
<Border DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="错误率" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding TotalCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="总正确数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding ErrorCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
<StackPanel.Resources>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="true">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding Status}" Value="false">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<TextBlock TextWrapping="Wrap" FontSize="8" Margin="0,2" FontWeight="Bold"
Text="{Binding DateTime}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<Border Height="10" Width="10" Margin="10,0" CornerRadius="20"/>
</StackPanel>
</DockPanel>
</Border>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ListBox.ItemTemplate>
</ItemsControl> </ListBox>
</ScrollViewer>
</Border> </StackPanel>
</Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -30,30 +30,5 @@ namespace StudentManager.Editor
{ {
} }
}
private void Border_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
if (e.OriginalSource is FrameworkElement element)
{
var contextMenu = element.FindResource("MyModernContextMenu") as ContextMenu;
if (contextMenu != null)
{
contextMenu.PlacementTarget = element;
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
contextMenu.Style = (Style)element.FindResource("ModernContextMenuStyle");
contextMenu.IsOpen = true;
}
}
}
private void StudentListBox_Loaded(object sender, RoutedEventArgs e)
{
var listBox = sender as ListBox;
if (listBox != null)
{
listBox.SetBinding(ListBox.SelectedItemProperty, new Binding("SelectedStudent") { Source = this.DataContext });
listBox.SetBinding(ListBox.ItemsSourceProperty, new Binding("StudentDatas") { Source = this.DataContext });
}
}
}
} }

View File

@ -7,127 +7,36 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="10,5"/>
</Style>
</UserControl.Resources>
<Grid> <Grid>
<DockPanel LastChildFill="False">
<Grid.ColumnDefinitions> <ListBox ItemsSource="{Binding SelectedHomeWorkSet}">
<ColumnDefinition Width="100"/> <i:Interaction.Triggers>
<ColumnDefinition Width="*"/> <i:EventTrigger EventName="SelectionChanged">
</Grid.ColumnDefinitions> <i:InvokeCommandAction
Command="{Binding DataContext.HomeWorkSelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
<ListBox ItemsSource="{Binding HomeWorkSet}"> </i:EventTrigger>
<i:Interaction.Triggers> </i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged"> <ListBox.ItemTemplate>
<i:InvokeCommandAction <DataTemplate>
CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}" <TextBlock Text="{Binding Lesson}"/>
Command="{Binding DataContext.HomeWorkSetSelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/> </DataTemplate>
</i:EventTrigger> </ListBox.ItemTemplate>
</i:Interaction.Triggers> </ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Lesson}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!--<DockPanel LastChildFill="False" HorizontalAlignment="Stretch">
-->
<!--<ListView DockPanel.Dock="Top" ItemsSource="{Binding HomeWork}">
<ListView.View>
<GridView>
<GridViewColumn
DisplayMemberBinding="{Binding QuestionData.Id}"
Header="ID" />
<GridViewColumn
DisplayMemberBinding="{Binding QuestionData.Stem}"
Header="题干" />
<GridViewColumn Header="正确?">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Status}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>-->
<!--<DataGrid DockPanel.Dock="Top" ItemsSource="{Binding HomeWork}" CanUserAddRows="False" CanUserDeleteRows="False" >
-->
<!--<DataGrid.Columns>
<DataGridCheckBoxColumn Header="正确?" Binding="{Binding Status}" />
</DataGrid.Columns>-->
<!--
</DataGrid>-->
<!--
</DockPanel>-->
<Grid Grid.Column="1" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Margin="0">
<ItemsControl ItemsSource="{Binding HomeWork}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" BorderThickness="0" CornerRadius="10" Margin="5"
Padding="5" Height="150" Width="120" IsHitTestVisible="True">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
<!--<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding DataContext.HomeWorkSelectedCommand ,RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding }"/>
</i:EventTrigger>-->
</i:Interaction.Triggers>
<Grid>
<StackPanel>
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="{Binding QuestionData.Type}"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Margin="5" Height="60"
Text="{Binding QuestionData.Stem}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
<CheckBox IsChecked="{Binding Status}" Padding="200,0" HorizontalAlignment="Stretch" VerticalContentAlignment="Bottom" VerticalAlignment="Stretch"/>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<Button Grid.Row="1" MinHeight=" 50" Content="提交" Command="{Binding UpdateHomeWorkCommand}" Style="{DynamicResource MaterialDesignFlatDarkButton}"/>
</Grid>
<ListBox DockPanel.Dock="Top" ItemsSource="{Binding HomeWork}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel Width="800" HorizontalAlignment="Stretch" LastChildFill="False">
<TextBlock Text="{Binding DateTime}"/>
<TextBlock Text="{Binding QuestionData.QuestionData.Stem}"/>
<TextBlock Text="{Binding QuestionData.Stem}" TextWrapping="Wrap"/>
<CheckBox DockPanel.Dock="Right" Content="正确?"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button DockPanel.Dock="Bottom" Content="提交"/>
</DockPanel>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -5,16 +5,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StudentManager.Editor" xmlns:local="clr-namespace:StudentManager.Editor"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources> <UserControl.Resources>
<!--<Style x:Key="TextStyle" TargetType="{x:Type TextBlock}"> <Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10,5"/> <Setter Property="Margin" Value="10,5"/>
<Setter Property="Width" Value="50"/> <Setter Property="Width" Value="50"/>
<Setter Property="Foreground" Value="White"/> </Style>
</Style>-->
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
@ -24,65 +22,15 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding StudentDatas}" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0" <ListBox ItemsSource="{Binding StudentDatas}"
x:Name="StudentListBox" SelectedIndex="0" Loaded="StudentListBox_Loaded"
SelectedItem="{Binding SelectedStudent}"> SelectedItem="{Binding SelectedStudent}">
<ListBox.Resources>
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<ScrollViewer Margin="0" Focusable="false">
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="White"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
CornerRadius="5">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FF007ACC"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFBEE6FD"/>
<Setter Property="BorderBrush" Value="#FF3C7FB1"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged"> <i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction <i:InvokeCommandAction
CommandParameter="{Binding SelectedItem, ElementName=StudentListBox}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
Command="{Binding DataContext.SelectedCommand ,ElementName=StudentListBox}"/> Command="{Binding DataContext.SelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name}"/> <TextBlock Text="{Binding Name}"/>
@ -90,214 +38,82 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<Grid Grid.Column="1" Margin="0" Background="Transparent"> <Grid Grid.Column="1">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="0.3*"/> <RowDefinition/>
<RowDefinition Height="0.2*"/> <RowDefinition/>
<RowDefinition Height="0.5*"/> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Border Background="Transparent" Margin="5" Grid.RowSpan="2" Grid.ColumnSpan="2" CornerRadius="10"/>
<Border Grid.Row="0" Background="#FF0069FE" CornerRadius="10" Margin="10"> <StackPanel Orientation="Horizontal">
<Grid> <TextBlock Style="{StaticResource TextStyle}" Text="姓名"/>
<Grid.ColumnDefinitions> <TextBlock Style="{StaticResource TextStyle}" Text="正确数"/>
<ColumnDefinition/> <TextBlock Style="{StaticResource TextStyle}" Text="第几课"/>
<ColumnDefinition/> <TextBlock Style="{StaticResource TextStyle}" Text="状态"/>
</Grid.ColumnDefinitions> </StackPanel>
<StackPanel Margin="30">
<TextBlock Text="{Binding SelectedStudent.Name}" FontWeight="Black" FontSize="22" Foreground="White"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="性别:" Foreground="LightGoldenrodYellow" HorizontalAlignment="Left" FontSize="14" Margin="5" />
<TextBlock Text="{Binding SelectedStudent.Gender}" Foreground="LightGoldenrodYellow" HorizontalAlignment="Left" FontSize="14" Margin="5" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="年级:" Foreground="LightGoldenrodYellow" HorizontalAlignment="Left" FontSize="14" Margin="5" />
<TextBlock Text="{Binding SelectedStudent.Grade}" Foreground="LightGoldenrodYellow" HorizontalAlignment="Left" FontSize="14" Margin="5" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="地址:" Foreground="LightGray" HorizontalAlignment="Left" FontSize="8" Margin="5,2" />
<TextBlock Text="{Binding SelectedStudent.Address}" Width="350" Foreground="LightGray" HorizontalAlignment="Left" FontSize="8" Margin="5,2" TextWrapping="Wrap"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="联系方式:" Foreground="LightGray" HorizontalAlignment="Left" FontSize="8" Margin="5,2" />
<TextBlock Text="{Binding SelectedStudent.Contact}" Foreground="LightGray" HorizontalAlignment="Left" FontSize="8" Margin="5,2" />
</StackPanel>
</StackPanel>
<StackPanel Margin="30" Grid.Column="1"> <StackPanel Grid.Row="1">
<TextBlock Text="DETAIL" FontWeight="Black" FontSize="22" Foreground="White"/>
<TextBlock Text="{Binding SelectedStudent.Address}" Width="350" Foreground="LightGoldenrodYellow" HorizontalAlignment="Left" FontSize="14" Margin="5" TextWrapping="Wrap"/>
<TextBlock Text="{Binding SelectedStudent.Gender}" TextWrapping="Wrap" FontSize="8" Margin="5,20" Foreground="LightGray"/>
</StackPanel> <StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Text="总题数量"/>
<TextBlock Style="{StaticResource TextStyle}" Text="总错题数量"/>
<TextBlock Style="{StaticResource TextStyle}" Text="修正数量"/>
<TextBlock Style="{StaticResource TextStyle}" Text="错误数量"/>
<TextBlock Style="{StaticResource TextStyle}" Text="错误率"/>
<TextBlock Style="{StaticResource TextStyle}" Text="修正率"/>
</Grid> </StackPanel>
</Border>
<Grid Grid.Row="1"> <StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorSet.TotalCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorSet.TotalErrorCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorSet.CorrectCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorSet.ErrorCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorSet.ErrorRate}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorSet.CorrectRate}"/>
<Grid.ColumnDefinitions> </StackPanel>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Margin="10" CornerRadius="10" Background="LightBlue">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".4*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Margin="10" >
<TextBlock Text="错题集总数量" FontWeight="Bold"
FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="20,10,60,10">
<DockPanel LastChildFill="False">
<TextBlock Margin="5" Text="总数量" />
<TextBlock Margin="5" DockPanel.Dock="Right" Text="{Binding SelectedStudent.ErrorSet.TotalCount}"/>
</DockPanel>
<DockPanel LastChildFill="False">
<TextBlock Margin="5" Text="正确数量"/>
<TextBlock Margin="5" DockPanel.Dock="Right" Text="{Binding SelectedStudent.ErrorSet.CorrectCount}"/>
</DockPanel>
<DockPanel LastChildFill="False">
<TextBlock Margin="5" Text="错误数量"/>
<TextBlock Margin="5" DockPanel.Dock="Right" Text="{Binding SelectedStudent.ErrorSet.ErrorCount}"/>
</DockPanel>
</StackPanel>
</Grid>
</Border>
<Border Grid.Column="1">
<lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Top">
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Time" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Values"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Border>
</Grid>
<Grid Grid.Row="2"> </StackPanel>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Background="Transparent">
<ScrollViewer Grid.Column="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Margin="10">
<ItemsControl Grid.Row="1" ItemsSource="{Binding ErrorSetDatas}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="#FFF9F9F9" BorderBrush="Gray" BorderThickness="0" CornerRadius="10"
Padding="5" Height="200" Width="120" Margin="5" IsHitTestVisible="True" MouseRightButtonDown="Border_MouseRightButtonDown">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<StackPanel>
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="{Binding QuestionData.Stem}" Height="60"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="使用数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding TotalUseCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="错误数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding ErrorCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
<Grid > <StackPanel Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="状态" Margin="5" Foreground="Gray" <TextBlock Style="{StaticResource TextStyle}" Text="第几课"/>
VerticalAlignment="Center" HorizontalAlignment="Left"/> <TextBlock Style="{StaticResource TextStyle}" Text="总数"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5" <TextBlock Style="{StaticResource TextStyle}" Text="正确数"/>
Text="{Binding Status}" VerticalAlignment="Center" HorizontalAlignment="Left"/> <TextBlock Style="{StaticResource TextStyle}" Text="状态"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical"> <ListBox ItemsSource="{Binding HomeWorkSet}">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="正确数" Margin="5" Foreground="Gray" <i:Interaction.Triggers>
VerticalAlignment="Center" HorizontalAlignment="Left"/> <i:EventTrigger EventName="MouseDoubleClick">
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5" <i:InvokeCommandAction
Text="{Binding CorrectCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/> CommandParameter="DetailCheckView"
</StackPanel> Command="{Binding DataContext.RegionTo ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</Grid> </i:EventTrigger>
</StackPanel> <i:EventTrigger EventName="SelectionChanged">
</Border> <i:InvokeCommandAction
</DataTemplate> CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
</ItemsControl.ItemTemplate> Command="{Binding DataContext.HomeWorkSetSelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</ItemsControl> </i:EventTrigger>
</ScrollViewer> </i:Interaction.Triggers>
</Border>
<Border Grid.Column="0" Background="Gray" Margin="10" CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<DataGrid ItemsSource="{Binding HomeWorkSet}" ScrollViewer.HorizontalScrollBarVisibility="Auto" IsReadOnly="True">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridRow">
<Border CornerRadius="10" Margin="5" Background="White">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<DataGridCellsPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowStyle>
</DataGrid>
</Border>
</Grid>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Lesson}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding TotalCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding CorrectCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Status}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid> </Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -30,20 +30,5 @@ namespace StudentManager.Editor
{ {
} }
private void Border_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
}
private void StudentListBox_Loaded(object sender, RoutedEventArgs e)
{
var listBox = sender as ListBox;
if (listBox != null)
{
listBox.SetBinding(ListBox.SelectedItemProperty, new Binding("SelectedStudent") { Source = this.DataContext });
listBox.SetBinding(ListBox.ItemsSourceProperty, new Binding("StudentDatas") { Source = this.DataContext });
}
}
} }
} }

View File

@ -7,97 +7,25 @@
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:extent="clr-namespace:StudentManager.Extensions" 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" mc:Ignorable="d"
Title="MainEditor" Height="800" Width="1400"> Title="MainEditor" Height="450" Width="800">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/> <ColumnDefinition Width="100"/>
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding MenuBars}">
<Border Background="#FFFAFAFA" Grid.ColumnSpan="2" CornerRadius="20"/>
<DockPanel LastChildFill="False"> <ItemsControl.ItemTemplate>
<StackPanel DockPanel.Dock="Top"> <DataTemplate>
<Button Content="{Binding Title}" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
CommandParameter="{Binding NameSpace}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Text="STUDENTMANAGER" VerticalAlignment="Center" HorizontalAlignment="Left" <ContentControl Grid.Column="1" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}"/>
FontSize="12" FontWeight="Bold"
TextAlignment="Center" Padding="25,10" Height="40"/>
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding MenuBars}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Title}" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
Style="{DynamicResource MaterialDesignFlatDarkButton}" HorizontalAlignment="Stretch" Padding="40,0,0,0" HorizontalContentAlignment="Left"
CommandParameter="{Binding NameSpace}" Margin="5.0"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<Button Margin="5" HorizontalAlignment="Stretch" DockPanel.Dock="Bottom" Content="保存" Style="{DynamicResource MaterialDesignFlatDarkButton}"
Command="{Binding SaveAllCommand}"/>
<Button Margin="5" HorizontalAlignment="Stretch" DockPanel.Dock="Bottom" Content="刷新数据" Style="{DynamicResource MaterialDesignFlatDarkButton}"
Command="{Binding FreshAllCommand}"/>
</DockPanel>
<Border BorderBrush="Gray" BorderThickness="1,0,0,0" Margin="2,50" Grid.Column="1" />
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Margin="10">
<md:ColorZone Background="#FFFFFFFF" CornerRadius="10" Height="100" x:Name="Bar" />
<DockPanel VerticalAlignment="Center" LastChildFill="False">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Border Margin="20,0" CornerRadius="50" Height="20" Width="20" Background="Gray"/>
<StackPanel VerticalAlignment=" Center" Margin="10,0">
<TextBlock DockPanel.Dock="Left" Text="HELLO" HorizontalAlignment="Left" Margin="2" FontWeight="Bold" VerticalAlignment="Center"/>
<TextBlock DockPanel.Dock="Left" Text="美好的一天从此刻开始" HorizontalAlignment="Left" FontSize="8" Foreground="Gray" Margin="2" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
<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>
</Grid>
<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>
</Window> </Window>

View File

@ -1,6 +1,5 @@
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;
@ -19,40 +18,9 @@ namespace StudentManager.Editor
{ {
public partial class MainEditor : Window public partial class MainEditor : Window
{ {
private readonly IEventAggregator eventAggregator; public MainEditor()
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

@ -4,7 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StudentManager.Editor" xmlns:local="clr-namespace:StudentManager.Editor"
xmlns:i ="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources> <UserControl.Resources>
@ -13,187 +12,27 @@
</Style> </Style>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<ListBox ItemsSource="{Binding QuestionDatas}">
<Grid.RowDefinitions> <!--<i:Interaction.Triggers>
<RowDefinition Height="0.0*"/> <i:EventTrigger EventName="SelectionChanged">
<RowDefinition/> <i:InvokeCommandAction x:Name="menuTrigger" Command="{Binding navigateCommand}" CommandParameter="{Binding ElementName=menu, Path=SelectedItem}"/>
</Grid.RowDefinitions> </i:EventTrigger>
</i:Interaction.Triggers>-->
<Grid Grid.Row="1"> <ListBox.ItemTemplate>
<Grid.ColumnDefinitions> <DataTemplate>
<ColumnDefinition Width="0.7*"/> <StackPanel Orientation="Horizontal">
<ColumnDefinition Width="0.22*"/> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Id}"/>
</Grid.ColumnDefinitions> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Type}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Stem}"/>
<ScrollViewer Grid.Column="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Margin="0"> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Answer}"/>
<ItemsControl ItemsSource="{Binding QuestionDatas}" HorizontalAlignment="Left"> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding DifficultyLevel}"/>
<ItemsControl.ItemsPanel> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Category}"/>
<ItemsPanelTemplate> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Tags}"/>
<WrapPanel/> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Source}"/>
</ItemsPanelTemplate> <TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Status}"/>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="#FFF9F9F9" BorderBrush="Gray" BorderThickness="0" CornerRadius="10" Margin="5"
Padding="5" Height="150" Width="120" IsHitTestVisible="True">
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding DataContext.SelectedQuestionChangedCommand ,RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding }"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel>
<TextBlock TextWrapping="Wrap" FontSize="12" FontWeight="Bold" Text="{Binding Type}"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="题干" Foreground="Gray" Margin="5,5"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="12" Margin="5"
Text="{Binding Stem}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<Border Background="#FFF5F5F5" Grid.Column="1" CornerRadius="10" Padding="10">
<Border.Effect>
<DropShadowEffect Color="#FFA5A5A5" BlurRadius="10" ShadowDepth="5" />
</Border.Effect>
<DockPanel LastChildFill="False">
<StackPanel DockPanel.Dock="Top">
<StackPanel.Resources>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</StackPanel.Resources>
<TextBlock Text="DETAIL DIALOG" FontSize="20" FontWeight="Bold" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="{Binding SelectedQuestion.Type, Mode=TwoWay}" FontSize="22" FontWeight="Bold"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="0,0">
<TextBlock Text="课文" Foreground="Gray"/>
<TextBox Text="{Binding SelectedQuestion.Lesson, Mode=TwoWay}" DockPanel.Dock="Right"/>
</StackPanel>
</Grid>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="题干" Foreground="Gray"/>
<TextBox Text="{Binding SelectedQuestion.Stem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="0,0">
<TextBlock Text="答案:" Foreground="Gray"/>
<TextBox Text="{Binding SelectedQuestion.Answer, Mode=TwoWay}" TextWrapping="Wrap"/>
</StackPanel>
</Grid>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="Category:" Foreground="Gray"/>
<TextBox Text="{Binding SelectedQuestion.Category, Mode=TwoWay}" TextWrapping="Wrap"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="0,0">
<TextBlock Text="难度:" Foreground="Gray"/>
<TextBlock Text="{Binding SelectedQuestion.DifficultyLevel, Mode=TwoWay}" />
</StackPanel>
</Grid>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="Tags:" Foreground="Gray"/>
<TextBox Text="{Binding SelectedQuestion.Tags, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="0,0">
<TextBlock Text="Source:" Foreground="Gray"/>
<TextBox Text="{Binding SelectedQuestion.Source, Mode=TwoWay}" TextWrapping="Wrap"/>
</StackPanel>
</Grid>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="Status:" Foreground="Gray"/>
<TextBlock Text="{Binding SelectedQuestion.Status, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<StackPanel Grid.Column="1" Margin="0,0">
<TextBlock Text="Update Time:" Foreground="Gray"/>
<TextBlock Text="{Binding SelectedQuestion.UpdateTime, Mode=TwoWay}" />
</StackPanel>
</Grid>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5,0,5,10"/>
</StackPanel> </StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="0,0"> </ListBox>
<Button Content="修改" HorizontalAlignment="Center" Command="{Binding UpdateQuestionCommand}" Style="{DynamicResource MaterialDesignFlatDarkButton}"/>
<Button Content="删除" HorizontalAlignment="Center" Command="{Binding DeleteQuestionCommand}" Style="{DynamicResource MaterialDesignFlatDarkButton}"/>
</StackPanel>
</DockPanel>
</Border>
</Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -8,139 +8,34 @@
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources> <UserControl.Resources>
<Style TargetType="{x:Type TextBlock}"> <Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10,5"/> <Setter Property="Margin" Value="10,5"/>
<Setter Property="Width" Value="50"/> <Setter Property="Width" Value="50"/>
</Style> </Style>
<Style x:Key="ModernMenuItemStyle" TargetType="MenuItem">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Padding" Value="10,5"/>
<Setter Property="Margin" Value="20,10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem">
<Border Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" CornerRadius="5" Height="20" Width="50">
<Grid>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" ContentSource="Header"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkGray"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- 定义 ContextMenu 的样式 -->
<Style x:Key="ModernContextMenuStyle" TargetType="ContextMenu">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="#FF007ACC"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContextMenu">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="10">
<StackPanel>
<ItemsPresenter/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ContextMenu x:Key="MyModernContextMenu" Style="{StaticResource ModernContextMenuStyle}">
<MenuItem Header="查看详情" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="DetailView" Style="{StaticResource ModernMenuItemStyle}"/>
</ContextMenu>
</UserControl.Resources> </UserControl.Resources>
<Grid Background="Transparent"> <Grid>
<Border Background="#FFFAFAFA" CornerRadius="10"/> <ListBox ItemsSource="{Binding StudentDatas}"
SelectedItem="{Binding SelectedStudent}">
<ScrollViewer Grid.Column="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" Margin="10">
<ItemsControl Grid.Row="1" ItemsSource="{Binding StudentDatas}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="#FFFEFEFE" BorderBrush="Gray" BorderThickness="0" CornerRadius="10"
Padding="5" Height="240" Width="120" Margin="5" IsHitTestVisible="True" MouseRightButtonDown="Border_MouseRightButtonDown">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:ChangePropertyAction PropertyName="Background" Value="#FFFEFEFE"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:ChangePropertyAction PropertyName="Background" Value="#FFF9F9F9"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<!--<i:EventTrigger EventName="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding DataContext.ShowContextMenuCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding}"/>
</i:EventTrigger>-->
</i:Interaction.Triggers>
<Border.Effect>
<DropShadowEffect Color="#FFF5F5F5" BlurRadius="10" ShadowDepth="1" Direction="0"/>
</Border.Effect>
<StackPanel>
<TextBlock TextWrapping="Wrap" FontSize="20" FontWeight="Bold" Text="{Binding Name}"
VerticalAlignment="Center" HorizontalAlignment="Left" Padding="10,10"/>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="错误总数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding ErrorSet.TotalCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="修正总数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Margin="5"
Text="{Binding ErrorSet.CorrectCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
<Border BorderBrush="Gray" BorderThickness="0,0.5,0,0" Margin="5"/>
<StackPanel Orientation="Vertical" >
<TextBlock TextWrapping="Wrap" FontSize="12" Text="作业次数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Text="{Binding HomeWorkSet.TotalSetCount}" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="总题数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Text="{Binding HomeWorkSet.TotalQuestionCount}" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" FontSize="12" Text="总错题数" Margin="5" Foreground="Gray"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" FontSize="18" Text="{Binding HomeWorkSet.TotalErrorQuestionCount}" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction
CommandParameter="DetailView"
Command="{Binding DataContext.RegionTo ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Name}"/>
<!--<TextBlock Style="{StaticResource TextStyle}" Text="{Binding TotalsQuestions}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding CorrectionCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding UnCorrectCount}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding ErrorRate}"/>
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding CorrectRate}"/>-->
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -30,20 +30,5 @@ namespace StudentManager.Editor
{ {
var data = DataContext; var data = DataContext;
} }
}
private void Border_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.OriginalSource is FrameworkElement element)
{
var contextMenu = element.FindResource("MyModernContextMenu") as ContextMenu;
if (contextMenu != null)
{
contextMenu.PlacementTarget = element;
contextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
contextMenu.Style = (Style)element.FindResource("ModernContextMenuStyle");
contextMenu.IsOpen = true;
}
}
}
}
} }

View File

@ -1,13 +0,0 @@
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

@ -1,22 +0,0 @@
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

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Interface
{
public class Singleton<T> where T : class, new()
{
private static readonly Lazy<T> instance = new Lazy<T>(() => new T());
public Singleton() { }
public static T Instance
{
get
{
return instance.Value;
}
}
}
}

View File

@ -1,10 +1,4 @@
using DryIoc.ImTools; using Mysqlx.Crud;
using LiveCharts;
using LiveCharts.Wpf;
using Mysqlx.Crud;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json;
using Org.BouncyCastle.Utilities;
using StudentManager.Common; using StudentManager.Common;
using StudentManager.Data; using StudentManager.Data;
using StudentManager.Extensions; using StudentManager.Extensions;
@ -13,13 +7,8 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Timer = StudentManager.Common.Timer;
namespace StudentManager.Model namespace StudentManager.Model
{ {
@ -59,27 +48,20 @@ namespace StudentManager.Model
{ {
private ObservableCollection<StudentInfo> studentDatas = new ObservableCollection<StudentInfo>(); private ObservableCollection<StudentInfo> studentDatas = new ObservableCollection<StudentInfo>();
public ObservableCollection<StudentInfo> StudentDatas { get { return studentDatas; } private set { studentDatas = value; RaisePropertyChanged(); } } public ReadOnlyObservableCollection<StudentInfo> StudentDatas { get; private set; }
private ObservableCollection<QuestionData> questionDatas = new ObservableCollection<QuestionData>(); private ObservableCollection<QuestionData> questionDatas = new ObservableCollection<QuestionData>();
public ObservableCollection<QuestionData> QuestionDatas { get { return questionDatas; } private set { questionDatas = value; RaisePropertyChanged(); } } public ReadOnlyObservableCollection<QuestionData> QuestionDatas { get; private set; }
private ObservableCollection<QuestionData> homeworkTestData = new ObservableCollection<QuestionData>();
public ObservableCollection<QuestionData> HomeworkTestData { get { return homeworkTestData; } private set { homeworkTestData = value; RaisePropertyChanged(); } }
private ObservableCollection<QuestionData> preToRemove = new ObservableCollection<QuestionData>();
private ObservableCollection<QuestionData> addQuestionDatas = new ObservableCollection<QuestionData>();
public ObservableCollection<QuestionData> ADDQuestionDatas { get { return addQuestionDatas; } private set { addQuestionDatas = value; RaisePropertyChanged(); } }
private ObservableCollection<DetailErrorInfo> errorSetDatas = new ObservableCollection<DetailErrorInfo>(); private ObservableCollection<DetailErrorInfo> errorSetDatas = new ObservableCollection<DetailErrorInfo>();
public ObservableCollection<DetailErrorInfo> ErrorSetDatas { get { return errorSetDatas; } private set { errorSetDatas = value; RaisePropertyChanged(); } } public ReadOnlyObservableCollection<DetailErrorInfo> ErrorSetDatas { get; private set; }
private ObservableCollection<CursonQuestionsData> cQDatas = new ObservableCollection<CursonQuestionsData>(); private ObservableCollection<CursonQuestionsData> cQDatas = new ObservableCollection<CursonQuestionsData>();
public ReadOnlyObservableCollection<CursonQuestionsData> CQDatas { get; private set; } public ReadOnlyObservableCollection<CursonQuestionsData> CQDatas { get; private set; }
private ObservableCollection<DetailHomeWorkSetInfo> homeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>(); private ObservableCollection<DetailHomeWorkSetInfo> homeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>();
public ObservableCollection<DetailHomeWorkSetInfo> HomeWorkSet { get { return homeWorkSet; } private set { homeWorkSet = value; RaisePropertyChanged(); } } public ObservableCollection<DetailHomeWorkSetInfo> HomeWorkSet { get { return homeWorkSet; } private set { homeWorkSet = value; RaisePropertyChanged(); } }
private ObservableCollection<DetailHomeWorkInfo> homeWork = new ObservableCollection<DetailHomeWorkInfo>(); private ObservableCollection<DetailHomeWorkInfo> homeWork = new ObservableCollection<DetailHomeWorkInfo>();
public ObservableCollection<DetailHomeWorkInfo> HomeWork { get { return homeWork; } private set { homeWork = value; RaisePropertyChanged(); } } public ObservableCollection<DetailHomeWorkInfo> HomeWork { get { return homeWork; } private set { homeWork = value; RaisePropertyChanged(); } }
@ -135,142 +117,24 @@ namespace StudentManager.Model
set { errorSet = value; RaisePropertyChanged(); } set { errorSet = value; RaisePropertyChanged(); }
} }
private uint lesson;
public uint Lesson
{
get { return lesson; }
set { lesson = value; RaisePropertyChanged(); }
}
private bool isAddPublicQuestionsLib;
public bool IsAddPublicQuestionsLib
{
get { return isAddPublicQuestionsLib; }
set { isAddPublicQuestionsLib = value; OnPublicHomeworkSelectionChanged(); RaisePropertyChanged(); }
}
private bool isNeedErrorset;
public bool IsNeedErrorset
{
get { return isNeedErrorset; }
set { isNeedErrorset = value; OnPublicHomeworkSelectionChanged(); RaisePropertyChanged(); }
}
private bool isControlQuestionNum;
public bool IsControlQuestionNum
{
get { return isControlQuestionNum; }
set { isControlQuestionNum = value; OnPublicHomeworkSelectionChanged(); RaisePropertyChanged(); }
}
private uint publicLesson;
public uint PublicLesson
{
get { return publicLesson; }
set { publicLesson = value; OnPublicHomeworkSelectionChanged(); RaisePropertyChanged(); }
}
private int questionCount;
public int QuestionCount
{
get { return questionCount; }
set { questionCount = value; RaisePropertyChanged(); }
}
private QuestionData selectedQuestion = new QuestionData();
public QuestionData SelectedQuestion
{
get { return selectedQuestion; }
set { selectedQuestion = value; RaisePropertyChanged(); }
}
public SeriesCollection seriesCollection;
public SeriesCollection SeriesCollection
{
get { return seriesCollection; }
set { seriesCollection = value; RaisePropertyChanged(); }
}
public List<string> labels;
public List<string> Labels
{
get { return labels; }
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; }
public DelegateCommand<DetailHomeWorkInfo> HomeWorkSelectedCommand { get; set; } public DelegateCommand<DetailHomeWorkInfo> HomeWorkSelectedCommand { get; set; }
public DelegateCommand<DetailHomeWorkSetInfo> HomeWorkSetSelectedCommand { get; set; } public DelegateCommand<DetailHomeWorkSetInfo> HomeWorkSetSelectedCommand { get; set; }
public DelegateCommand DeleteQuestionCommand { get; set; }
public DelegateCommand UpdateQuestionCommand { get; set; }
public DelegateCommand<MouseButtonEventArgs> ShowContextMenuCommand { get; set; }
public DelegateCommand<QuestionData> RemoveNewColumnCommand { get; set; }
public DelegateCommand<QuestionData> SelectedQuestionChangedCommand { get; set; }
public DelegateCommand RegionToDetailCommand { get; set; } public DelegateCommand RegionToDetailCommand { get; set; }
public DelegateCommand UpdateHomeWorkCommand { get; set; }
public DelegateCommand DeleteHomeworkCommand { get; set; }
public DelegateCommand AddNewColumnCommand { get; set; }
public DelegateCommand SubmitAddQuestionsCommand { get; set; }
public DelegateCommand ClearnAddQuestionsCommand { get; set; }
public DelegateCommand SaveAllCommand { get; set; }
public DelegateCommand PublicHomeWorkCommand { get; set; }
public DelegateCommand FreshAllCommand { get; set; }
Students(IRegionManager regionManager, IEventAggregator aggregator) Students(IRegionManager regionManager)
{ {
CreateMenuBar(); CreateMenuBar();
CurrentTime = DateTime.Now.ToString("HH:mm");
Timer timer = new Timer(() => RegionTo = new DelegateCommand<string>((x) => {
{
CurrentTime = DateTime.Now.ToString("HH:mm");
});
FileSystem.Instance.AutoSaveInvoke += () =>
{
aggregator.SendMessage(" 将在10秒后自动保存 ");
};
FileSystem.Instance.SavedInvoke += () =>
{
aggregator.SendMessage(" 已保存 ");
};
FileSystem.Instance.AutoSave();
RegionTo = new DelegateCommand<string>((x) =>
{
regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString()); regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString());
if (x == "DetailCheckView") if(x == "DetailCheckView")
{ {
RegionToDetailCheckView(); RegionToDetailCheckView();
} }
@ -281,277 +145,49 @@ namespace StudentManager.Model
RegionToStudents(); RegionToStudents();
}); });
UpdateHomeWorkCommand = new DelegateCommand(() => UpdateHomeWork());
SelectedCommand = new DelegateCommand<StudentInfo>((x) => SelectedCommand = new DelegateCommand<StudentInfo>((x) =>
{ {
if (x == null) return; if (x == null) return;
SelectedStudent = x; SelectedStudent = x;
UpdateGird();
RegionToDetailView(); RegionToDetailView();
}); });
HomeWorkSetSelectedCommand = new DelegateCommand<DetailHomeWorkSetInfo>((x) => HomeWorkSetSelectedCommand = new DelegateCommand<DetailHomeWorkSetInfo>((x) =>
{ {
if (x == null || SelectedStudent == null) return; if (x == null) return;
SelectedHomeWorkSet = x; selectedHomeWorkSet = x;
HomeWork = SelectedStudent.HomeWorkSet.GetDetailHomeWorkList(SelectedHomeWorkSet.Lesson); HomeWork = SelectedStudent.HomeWorkSet.GetDetailHomeWorkList(SelectedHomeWorkSet.Lesson);
}); });
HomeWorkSelectedCommand = new DelegateCommand<DetailHomeWorkInfo>((e) => HomeWorkSelectedCommand = new DelegateCommand<DetailHomeWorkInfo>((e) =>
{ {
if (e == null) return; if(e == null) return;
//selectedHomeWork = e; //HomeWork =
e.Status = true;
});
DeleteQuestionCommand = new DelegateCommand(() =>
{
if (SelectedQuestion == null)
{
aggregator.SendMessage($" 当前没有选中任何题目 ");
return;
}
var c = MessageBox.Show("确定删除吗?", "确认", MessageBoxButton.OKCancel);
if (c != MessageBoxResult.OK) return;
if (!SQLHelper.Instance.Delete(SelectedQuestion)) return;
QuestionLib.Instance.Remove(SelectedQuestion);
QuestionDatas = QuestionLib.Instance.GetAllQuestion();
aggregator.SendMessage($" 成功删除 ");
FileSystem.Instance.SaveAll();
});
UpdateQuestionCommand = new DelegateCommand(() =>
{
if (SelectedQuestion == null) return;
var c = MessageBox.Show("确定修改吗?", "确认", MessageBoxButton.OKCancel);
if (c != MessageBoxResult.OK) return;
QuestionLib.Instance.Update(SelectedQuestion);
SelectedQuestion.UpdateTime = DateTime.Now;
SQLHelper.Instance.UpdateQuestion(SelectedQuestion);
aggregator.SendMessage("已更新问题信息");
FileSystem.Instance.SaveAll();
});
SelectedQuestionChangedCommand = new DelegateCommand<QuestionData>((x) =>
{
if (x == null) return;
SelectedQuestion = x;
});
ClearnAddQuestionsCommand = new DelegateCommand(() =>
{
var c = MessageBox.Show("确定清除吗?", "清除所有题目", MessageBoxButton.OKCancel);
if (c != MessageBoxResult.OK) return;
ADDQuestionDatas.Clear();
});
SaveAllCommand = new DelegateCommand(() =>
{
FileSystem.Instance.SaveAll();
});
FreshAllCommand = new DelegateCommand(() =>
{
FileSystem.Instance.FreashAllInfo();
Reload();
});
PublicHomeWorkCommand = new DelegateCommand(() =>
{
var result = HomeWorkManager.Instance.PublicHomework(PublicLesson, IsAddPublicQuestionsLib, isNeedErrorset);
aggregator.SendMessage($"总发布{result.Total}个作业, {result.Correct}已发布, {result.Error}未发布");
});
DeleteHomeworkCommand = new DelegateCommand(() =>
{
var cq = new CursonQuestionsData { Lesson = SelectedHomeWorkSet.Lesson, UID = SelectedStudent.UID };
if (!SQLHelper.Instance.Delete(cq))
{
aggregator.SendMessage(" 服务器删除失败 ");
return;
}
if (SelectedHomeWorkSet != null && SelectedStudent != null)
SelectedStudent.HomeWorkSet.DeleteHomework(SelectedHomeWorkSet.Lesson);
else
{
aggregator.SendMessage(" 本地数据错误,已为你从服务器更新 ");
QuestionLib.Instance.FreshAllQuestion();
}
if (SelectedStudent != null)
{
HomeWorkSet = SelectedStudent.HomeWorkSet.GetDetailHomeWorkSetList();
SelectedStudent.HomeWorkSet.UpdateDate();
}
aggregator.SendMessage(" 删除成功 ");
FileSystem.Instance.SaveAll();
});
SubmitAddQuestionsCommand = new DelegateCommand(() =>
{
Debug.Assert(Lesson != 0);
preToRemove.Clear();
foreach (var item in ADDQuestionDatas)
{
item.Id = ConvertToHashInt(item.Stem);
item.Lesson = Lesson;
if (!(QuestionLib.Instance.Get(item.Id) == null)) continue;
if (string.IsNullOrEmpty(item.Stem) || string.IsNullOrEmpty(item.Source) || string.IsNullOrEmpty(item.Answer)) continue;
if (!SQLHelper.Instance.Add(item))
{
aggregator.SendMessage($" {item.Stem}服务器添加失败, ID 可能重复 ");
continue;
}
QuestionLib.Instance.Add(item);
preToRemove.Add(item);
}
foreach (var item in preToRemove)
{
ADDQuestionDatas.Remove(item);
}
aggregator.SendMessage($" {preToRemove.Count}添加成功, {ADDQuestionDatas.Count}添加失败 ");
QuestionLib.Instance.Save();
}); });
Load(); Load();
StudentDatas = new ObservableCollection<StudentInfo>(studentDatas); StudentDatas = new ReadOnlyObservableCollection<StudentInfo>(studentDatas);
QuestionDatas = new ObservableCollection<QuestionData>(questionDatas); QuestionDatas = new ReadOnlyObservableCollection<QuestionData>(questionDatas);
ErrorSetDatas = new ObservableCollection<DetailErrorInfo>(errorSetDatas); ErrorSetDatas = new ReadOnlyObservableCollection<DetailErrorInfo>(errorSetDatas);
MenuBars = new ReadOnlyObservableCollection<MenuBar>(menuBars); MenuBars = new ReadOnlyObservableCollection<MenuBar>(menuBars);
//CQDatas = new ReadOnlyObservableCollection<CursonQuestionsData>(cQDatas);
HomeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>(homeWorkSet); HomeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>(homeWorkSet);
UpdateGird();
this.regionManager = regionManager; this.regionManager = regionManager;
this.aggregator = aggregator;
}
private void UpdateGird()
{
if (SelectedStudent == null) return;
SelectedStudent.HomeWorkSet.UpdateDataView();
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "错题数量",
Values = SelectedStudent.HomeWorkSet.ErrorCounts,
},
new LineSeries
{
Title = "正确数量",
Values = SelectedStudent.HomeWorkSet.CorrectCounts,
}
};
Labels = SelectedStudent.HomeWorkSet.Lessons;
}
private int ConvertToHashInt(string item) SaveAll();
{
var hash = SHA256.Create();
var result = hash.ComputeHash(Encoding.UTF8.GetBytes(item));
return BitConverter.ToInt32(result, 0);
}
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 } };
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);
// update homework other info and online info
SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Status = true;
SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).DateTime = DateTime.Now;
List<int> correctHomeworkArray = new List<int>();
List<int> totalHomeworkArray = new List<int>();
SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Questions.ForEach(x =>
{
totalHomeworkArray.Add(x.ID);
if (x.Status != false) correctHomeworkArray.Add(x.ID);
});
SQLHelper.Instance.UpdateHomework(SelectedStudent.UID, SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Lesson,
JsonConvert.SerializeObject(totalHomeworkArray),
JsonConvert.SerializeObject(correctHomeworkArray), SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).DateTime,
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
}
private void UpdateData()
{
} }
private void RegionToDetailView() private void RegionToDetailView()
{ {
if (selectedStudent == null) return; if(selectedStudent == null) return;
ErrorSetDatas = selectedStudent.ErrorSet.GetDetailErrorQuestionList(); ErrorSet = selectedStudent.ErrorSet.GetDetailErrorSetInfo();
HomeWorkSet = selectedStudent.HomeWorkSet.GetDetailHomeWorkSetList(); HomeWorkSet = selectedStudent.HomeWorkSet.GetDetailHomeWorkSetList();
} }
@ -572,45 +208,22 @@ namespace StudentManager.Model
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "详情", NameSpace = "DetailView" }); menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "详情", NameSpace = "DetailView" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "题库", NameSpace = "QuestionsView" }); menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "题库", NameSpace = "QuestionsView" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "审批", NameSpace = "CheckView" }); menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "审批", NameSpace = "CheckView" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "发布家庭作业", NameSpace = "AddHomeWork" }); //menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "出题", NameSpace = "QuestionsView" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "出题", NameSpace = "AddQuestionView" }); menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "出题", NameSpace = "DetailCheckView" });
} }
private void Load() private void Load()
{ {
StudentLib.Load(); StudentLib.Load();
QuestionLib.Instance.Load(); QuestionLib.Load();
Reload(); studentDatas = StudentLib.GetAllStudents();
questionDatas = QuestionLib.GetAllQuestion();
} }
private void Reload() private void SaveAll()
{ {
studentDatas.Clear(); StudentLib.Save();
questionDatas.Clear(); QuestionLib.Save();
StudentDatas = StudentLib.GetAllStudents();
QuestionDatas = QuestionLib.Instance.GetAllQuestion();
} }
private void OnPublicHomeworkSelectionChanged()
{
HomeworkTestData.Clear();
if (IsAddPublicQuestionsLib)
{
HomeworkTestData = QuestionLib.Instance.GetAllQuestionByLesson(PublicLesson);
}
if (IsNeedErrorset)
{
if (SelectedStudent != null)
{
foreach (var item in SelectedStudent.ErrorSet.GetDetailErrorQuestionList())
{
homeworkTestData.Add(item.QuestionData);
}
}
}
}
} }
} }

View File

@ -9,14 +9,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.1" />
<PackageReference Include="LiveCharts" Version="0.9.7" />
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="MyNet.Wpf.LiveCharts" Version="6.0.0" />
<PackageReference Include="MySql.Data" Version="9.0.0" /> <PackageReference Include="MySql.Data" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Prism.DryIoc" Version="9.0.537" /> <PackageReference Include="Prism.DryIoc" Version="9.0.537" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Interface\" />
</ItemGroup>
</Project> </Project>

View File

@ -7,12 +7,6 @@
</ApplicationDefinition> </ApplicationDefinition>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Editor\AddHomeWork.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Editor\AddQuestionView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Editor\CheckView.xaml.cs"> <Compile Update="Editor\CheckView.xaml.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@ -33,12 +27,6 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Update="Editor\AddHomeWork.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Editor\AddQuestionView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Editor\CheckView.xaml"> <Page Update="Editor\CheckView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>