Compare commits

...

10 Commits

Author SHA1 Message Date
wangxiner55
d60ef97525 CursonQuestionsTable 2024-12-23 22:13:46 +08:00
597981281f All Finished 2024-09-30 18:58:56 +08:00
6ace9eabd8 UIAndData 2024-09-27 19:07:59 +08:00
ab4d872f3e UI Update 2024-09-25 19:00:49 +08:00
a5d33f9f99 StyleSet 2024-09-24 19:00:10 +08:00
da9c3b7041 last 2024-09-23 19:08:19 +08:00
f19c955def Online 2024-09-20 19:07:08 +08:00
8672bd5fc8 Create question local 2024-09-14 18:51:47 +08:00
13d82faca1 Init default Material 2024-09-14 16:18:12 +08:00
b52303fd21 1 2024-09-13 19:13:29 +08:00
34 changed files with 2787 additions and 493 deletions

View File

@ -2,8 +2,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StudentManager"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/">
<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>
</prism:PrismApplication>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,26 +1,16 @@
using DryIoc.ImTools;
using Google.Protobuf.WellKnownTypes;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using StudentManager.Common;
using StudentManager.Data;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using Enum = System.Enum;
using System.Security.Cryptography;
using StudentManager.Interface;
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 void Mapping<T>(MySqlDataReader reader)
@ -32,7 +22,7 @@ namespace StudentManager.Common
{
if (typeof(T) == typeof(StudentData))
{
(data as StudentData).UID = (int)reader[0];
(data as StudentData).UID = (long)reader[0];
(data as StudentData).Name = reader[1].ToString();
(data as StudentData).Gender = reader[2].ToString();
(data as StudentData).Contact = reader[3].ToString();
@ -40,14 +30,20 @@ namespace StudentManager.Common
(data as StudentData).Grade = (byte)reader[5];
(data as StudentData).TotalsQuestions = (UInt16)reader[6];
(data as StudentData).CorrectionCount = (UInt16)reader[7];
(data as StudentData).HomeWork = (UInt16)reader[8];
(data as StudentData).CurronHomeWorkIndex = (uint)reader[8];
(data as StudentData).Password = reader[9].ToString();
(data as StudentData).Birthdate = (DateTime)reader[10];
(data as StudentData).HWQTotalCount = (uint)reader[11];
(data as StudentData).HWQTotalErrorCount = (uint)reader[12];
}
else if (typeof(T) == typeof(QuestionData))
{
DifficultyLevel dLevel = DifficultyLevel.easy;
QStatus qStatus = QStatus.published;
QType qType = QType.;
(data as QuestionData).Id = (int)reader[0];
(data as QuestionData).Type = reader[1].ToString();
Enum.TryParse(reader[1].ToString(), true, out qType);
(data as QuestionData).Type = qType;
(data as QuestionData).Stem = reader[2].ToString();
(data as QuestionData).Answer = reader[3].ToString();
Enum.TryParse(reader[4].ToString(), true, out dLevel);
@ -55,16 +51,17 @@ namespace StudentManager.Common
(data as QuestionData).Category = reader[5].ToString();
(data as QuestionData).Tags = reader[6].ToString();
(data as QuestionData).Source = reader[7].ToString();
Enum.TryParse(reader[8].ToString(), true, out qStatus);
(data as QuestionData).Lesson = (uint)reader[8];
Enum.TryParse(reader[9].ToString(), true, out qStatus);
(data as QuestionData).Status = qStatus;
}
else if (typeof(T) == typeof(CursonQuestionsData))
{
(data as CursonQuestionsData).UID = (int)reader[0];
(data as CursonQuestionsData).UID = (long)reader[0];
(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).Lesson = (byte)reader[3];
(data as CursonQuestionsData).Lesson = (uint)reader[3];
(data as CursonQuestionsData).Status = (byte)reader[4];
(data as CursonQuestionsData).DateTime = (DateTime)reader[5];
(data as CursonQuestionsData).TotalCount = (data as CursonQuestionsData).ProblemIDS.Length;
@ -77,139 +74,491 @@ namespace StudentManager.Common
(data as UserQuestionData).CorrectCount = (byte)reader[3];
(data as UserQuestionData).Status = (byte)reader[4] == 1;
}
//for (int i = 0; i < reader.FieldCount; ++i)
//{
// data?.GetType().GetProperties().ForEach(x => { x.SetValue(reader[i].GetType(), reader[i]); });
//}
}
}
}
struct userTable
public class SQLHelper : Singleton<SQLHelper>
{
}
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()
private Dictionary<System.Type, string> TypeMap = new Dictionary<System.Type, string>
{
connection = new MySqlConnection(config);
{ typeof(QuestionData), "questions" },
{ typeof(CursonQuestionsData), "curson_questions" },
{ typeof(StudentData), "users" },
{ typeof(UserQuestionData), "user_data" },
};
List<T> result = new List<T>();
private string config = "server=8.137.125.29;port=3306;user=StudentManager;password=wangxin55;database=studentmanager";
private MySqlConnection connection = null;
private MySqlCommand cmd = null;
string idName = typeof(T) == typeof(StudentData) ? "user_id" : typeof(T) == typeof(QuestionData) ? "problem_id" : "user_id";
try
public List<T> Query<T>(long? id = null, params string[] queryParams) where T : IDataCommon, new()
{
string tableName = string.Empty;
TypeMap.TryGetValue(typeof(T), out tableName);
using (var connection = new MySqlConnection(config))
{
connection.Open();
string queryStr = "";
if (queryParams.Length > 0)
List<T> result = new List<T>();
string idName = typeof(T) == typeof(StudentData) ? "user_id" : typeof(T) == typeof(QuestionData) ? "problem_id" : "user_id";
try
{
string filedList = string.Join(",", queryParams);
queryStr = $"select {filedList} from {tableName};";
connection.Open();
string queryStr = "";
if (queryParams.Length > 0)
{
string fieldList = string.Join(",", queryParams);
queryStr = $"SELECT {fieldList} FROM {tableName}";
if (id != -1)
queryStr = $@"select {filedList} from {tableName} WHERE {idName} = {id};";
if (id.HasValue)
queryStr += $" 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;
}
else
catch (MySqlException ex)
{
queryStr = $"select * from {tableName};";
if (id != -1)
queryStr = $@"select * from {tableName} WHERE {idName} = {id};";
Console.WriteLine($"MySQL error: {ex.Message}");
return new List<T> { };
}
cmd = new MySqlCommand(queryStr, connection);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
catch (Exception ex)
{
T row = new T();
SQLMapping.Mapping(row, reader);
result.Add(row);
Console.WriteLine($"General error: {ex.Message}");
return new List<T> { };
}
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
{
connection = new MySqlConnection(config);
string tableName = string.Empty;
TypeMap.TryGetValue(typeof(T), out tableName);
List<T> result = new List<T>();
try
using (var connection = new MySqlConnection(config))
{
connection.Open();
string queryStr = "";
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}";
cmd = new MySqlCommand(queryStr, connection);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
try
{
T row = new T();
SQLMapping.Mapping(row, reader);
result.Add(row);
}
connection.Open();
return result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
finally
{
cmd.Dispose();
connection.Close();
if (typeof(T) == typeof(QuestionData))
{
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();
}
}
}
catch (MySqlException ex)
{
Console.WriteLine($"MySQL error: {ex.Message}");
return false;
}
catch (Exception ex)
{
Console.WriteLine($"General error: {ex.Message}");
return false;
}
return true;
}
}
public static void Add()
public bool Delete<T>(T value) where T : IDataCommon
{
try
{
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
string tableName = string.Empty;
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;
}
}
internal bool UpdateErrorSet(long UID, ErrorBase error)
{
using (MySqlConnection connection = new MySqlConnection(config))
{
try
{
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;
}
}
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

@ -0,0 +1,36 @@
using Newtonsoft.Json.Linq;
using StudentManager.Interface;
using System.Net.Http;
using System.Windows.Threading;
namespace StudentManager.Common
{
public class Timer
{
private DispatcherTimer _timer;
private Action _onMinuteChanged;
private int _lastMinute;
public Timer(Action onMinuteChanged)
{
_onMinuteChanged = onMinuteChanged;
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Tick += Timer_Tick;
_timer.Start();
_lastMinute = DateTime.Now.Minute;
}
private void Timer_Tick(object sender, EventArgs e)
{
var now = DateTime.Now;
if (now.Minute != _lastMinute)
{
_onMinuteChanged?.Invoke();
_lastMinute = now.Minute;
}
}
}
}

View File

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

View File

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

View File

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

View File

@ -6,24 +6,41 @@ using System.Threading.Tasks;
namespace StudentManager.Data
{
public enum Gender
{
,
,
}
public class StudentData : IDataCommon
{
public int UID { get; set; } = 1;
// Count info
public long UID { get; set; } = 1;
public string Password { get; set; } = "123456";
// Base info
public string Name { get; set; } = "Name";
public string Gender { get; set; } = "Gender";
public string Contact { get; set; } = "Contact";
public string Address { get; set; } = "Address";
public int Grade { get; set; } = 1;
public DateTime Birthdate { get; set; } = DateTime.Now;
// Error Set
public int TotalsQuestions { 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 CorrectRate { 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 FileName = "studentLib.dbsi";
public static Dictionary<int, StudentInfo> StudentDic { get; set; } = new Dictionary<int, StudentInfo>();
public static Dictionary<long, StudentInfo> StudentDic { get; set; } = new Dictionary<long, StudentInfo>();
public static void Add(StudentInfo studentInfo)
{
@ -28,9 +28,9 @@ namespace StudentManager.Data
{
StudentDic.Clear();
Debug.Assert(Path.Exists(LibPath));
if (!Path.Exists(LibPath + FileName)) return;
string file = File.ReadAllText(LibPath + FileName);
StudentDic = JsonSerializer.Deserialize<Dictionary<int, StudentInfo>>(file);
StudentDic = JsonSerializer.Deserialize<Dictionary<long, StudentInfo>>(file);
}
public static void Save()
@ -43,7 +43,7 @@ namespace StudentManager.Data
{
StudentDic.Clear();
SQLHelper.Query<StudentData>(Tables.UserTable).ForEach(x =>
SQLHelper.Instance.Query<StudentData>().ForEach(x =>
StudentDic.Add(x.UID, new StudentInfo
{
UID = x.UID,
@ -51,14 +51,15 @@ namespace StudentManager.Data
Address = x.Address,
Contact = x.Contact,
Grade = x.Grade,
CurrentHomeWorkIndex = x.HomeWork,
Gender = x.Gender,
CurrentHomeWorkIndex = x.CurronHomeWorkIndex,
}));
foreach (var item in StudentDic)
{
foreach (var item in StudentDic)
{
GetStudentDetailInfo(item.Value);
}
}
}
public static ObservableCollection<StudentInfo> GetAllStudents()
{
@ -70,12 +71,12 @@ namespace StudentManager.Data
return list;
}
public static StudentInfo QueryStudentDetailInfo(int uid)
public static StudentInfo QueryStudentDetailInfo(long uid)
{
return GetStudentDetailInfo(Get(uid));
}
public static StudentInfo Get(int uid)
public static StudentInfo Get(long uid)
{
if (!StudentDic.ContainsKey(uid)) return null;
return StudentDic[uid];
@ -86,7 +87,7 @@ namespace StudentManager.Data
StudentDic.Remove(studentInfo.UID);
}
public static void Remove(int id)
public static void Remove(long id)
{
StudentDic.Remove(id);
}
@ -96,6 +97,8 @@ namespace StudentManager.Data
studentData.ErrorSet.QueryErrorSet(studentData.UID);
studentData.HomeWorkSet.FreshAllHomeWork(studentData.UID);
studentData.CurentHomeWork = studentData.HomeWorkSet.Get(studentData.CurrentHomeWorkIndex);
return studentData;
}
@ -108,7 +111,7 @@ namespace StudentManager.Data
public class StudentInfo
{
public int UID { get; set; } = 1;
public long UID { get; set; } = 1;
public string Name { get; set; } = "Name";
public string Gender { get; set; } = "Gender";
public string Contact { get; set; } = "Contact";
@ -120,12 +123,66 @@ namespace StudentManager.Data
public ErrorSet ErrorSet { get; set; } = new ErrorSet();
public HomeWorkSet HomeWorkSet { get; set; } = new HomeWorkSet();
public int CurrentHomeWorkIndex = 0;
public uint CurrentHomeWorkIndex = 0;
public HomeWork CurentHomeWork { get; set; } = new HomeWork();
public void PublicHomeWork(HomeWork homeWork)
public bool PublicHomeWork(uint lesson, bool appendCommonWork = false, bool appendErrorSet = false, int workNum = -1)
{
HomeWorkSet.AddHomeWork(homeWork);
HomeWork homeWork = new 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

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

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

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

@ -0,0 +1,28 @@
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,20 +7,126 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<UserControl.Resources>
<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>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border CornerRadius="20"/>
<ListBox ItemsSource="{Binding StudentDatas}"
SelectedItem="{Binding SelectedStudent}">
<ListBox ItemsSource="{Binding StudentDatas}" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0" x:Name="StudentListBox"
SelectedItem="{Binding SelectedStudent}" Loaded="StudentListBox_Loaded">
<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:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding DataContext.SelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
CommandParameter="{Binding SelectedItem, ElementName=StudentListBox}"
Command="{Binding DataContext.SelectedCommand ,ElementName=StudentListBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
@ -28,32 +134,116 @@
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Column="1">
<StackPanel>
<TextBlock Text="{Binding SelectedStudent.Name}"/>
<ListBox ItemsSource="{Binding CQDatas}"
SelectionChanged="ListBox_SelectionChanged">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction
CommandParameter="DetailCheckView"
Command="{Binding DataContext.RegionTo ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<Border Grid.Column="1">
<ScrollViewer Grid.Column="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Margin="0">
<ItemsControl ItemsSource="{Binding HomeWorkSet}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding TotalCount}"/>
<TextBlock Text="{Binding CorrectCount}"/>
<TextBlock Text="{Binding Lesson}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Border Background="#FFF9F9F9" BorderBrush="Gray" BorderThickness="0" CornerRadius="10" Margin="5" MouseRightButtonUp="Border_MouseRightButtonUp"
Padding="5" Height="240" Width="140" 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="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding DataContext.HomeWorkSetSelectedCommand ,RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding }"/>
</i:EventTrigger>
</StackPanel>
</Grid>
</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>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Border>
</Grid>
</UserControl>

View File

@ -30,5 +30,30 @@ 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,36 +7,127 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<DockPanel LastChildFill="False">
<UserControl.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="10,5"/>
</Style>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding HomeWorkSet}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
Command="{Binding DataContext.HomeWorkSetSelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<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 ItemsSource="{Binding SelectedHomeWorkSet}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding DataContext.HomeWorkSelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Lesson}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<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>
</UserControl>

View File

@ -5,14 +5,16 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StudentManager.Editor"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<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="Width" Value="50"/>
</Style>
<Setter Property="Foreground" Value="White"/>
</Style>-->
</UserControl.Resources>
<Grid>
@ -22,15 +24,65 @@
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding StudentDatas}"
<ListBox ItemsSource="{Binding StudentDatas}" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0"
x:Name="StudentListBox" SelectedIndex="0" 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:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
Command="{Binding DataContext.SelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
CommandParameter="{Binding SelectedItem, ElementName=StudentListBox}"
Command="{Binding DataContext.SelectedCommand ,ElementName=StudentListBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
@ -38,82 +90,214 @@
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Column="1">
<Grid Grid.Column="1" Margin="0" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="0.3*"/>
<RowDefinition Height="0.2*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<Border Background="Transparent" Margin="5" Grid.RowSpan="2" Grid.ColumnSpan="2" CornerRadius="10"/>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Text="姓名"/>
<TextBlock Style="{StaticResource TextStyle}" Text="正确数"/>
<TextBlock Style="{StaticResource TextStyle}" Text="第几课"/>
<TextBlock Style="{StaticResource TextStyle}" Text="状态"/>
</StackPanel>
<Border Grid.Row="0" Background="#FF0069FE" CornerRadius="10" Margin="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<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 Grid.Row="1">
<StackPanel Margin="30" Grid.Column="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 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="修正率"/>
</StackPanel>
</StackPanel>
</Grid>
</Border>
<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 Grid.Row="1">
</StackPanel>
<Grid.ColumnDefinitions>
<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>
</StackPanel>
<Grid Grid.Row="2">
<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>
<StackPanel Grid.Row="2">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Text="第几课"/>
<TextBlock Style="{StaticResource TextStyle}" Text="总数"/>
<TextBlock Style="{StaticResource TextStyle}" Text="正确数"/>
<TextBlock Style="{StaticResource TextStyle}" Text="状态"/>
</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 Status}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
<ListBox ItemsSource="{Binding HomeWorkSet}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction
CommandParameter="DetailCheckView"
Command="{Binding DataContext.RegionTo ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
Command="{Binding DataContext.HomeWorkSetSelectedCommand ,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<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 CorrectCount}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</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>
</UserControl>

View File

@ -30,5 +30,20 @@ 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,25 +7,97 @@
xmlns:prism="http://prismlibrary.com/"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
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"
Title="MainEditor" Height="450" Width="800">
Title="MainEditor" Height="800" Width="1400">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ItemsControl ItemsSource="{Binding MenuBars}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Title}" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
CommandParameter="{Binding NameSpace}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Border Background="#FFFAFAFA" Grid.ColumnSpan="2" CornerRadius="20"/>
<ContentControl Grid.Column="1" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}"/>
<DockPanel LastChildFill="False">
<StackPanel DockPanel.Dock="Top">
<TextBlock Text="STUDENTMANAGER" VerticalAlignment="Center" HorizontalAlignment="Left"
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>
</Window>

View File

@ -1,5 +1,6 @@
using StudentManager.Common;
using StudentManager.Data;
using StudentManager.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
@ -18,9 +19,40 @@ namespace StudentManager.Editor
{
public partial class MainEditor : Window
{
public MainEditor()
private readonly IEventAggregator eventAggregator;
public MainEditor(IEventAggregator aggregator)
{
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,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StudentManager.Editor"
xmlns:i ="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
@ -12,27 +13,187 @@
</Style>
</UserControl.Resources>
<Grid>
<ListBox ItemsSource="{Binding QuestionDatas}">
<!--<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction x:Name="menuTrigger" Command="{Binding navigateCommand}" CommandParameter="{Binding ElementName=menu, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>-->
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Id}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Type}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Stem}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Answer}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding DifficultyLevel}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Category}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Tags}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Source}"/>
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Status}"/>
<Grid.RowDefinitions>
<RowDefinition Height="0.0*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*"/>
<ColumnDefinition Width="0.22*"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Margin="0">
<ItemsControl ItemsSource="{Binding QuestionDatas}" HorizontalAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</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>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="0,0">
<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>
</UserControl>

View File

@ -8,34 +8,139 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10,5"/>
<Setter Property="Width" Value="50"/>
</Style>
</UserControl.Resources>
<Grid>
<ListBox ItemsSource="{Binding StudentDatas}"
SelectedItem="{Binding SelectedStudent}">
<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>
<Grid Background="Transparent">
<Border Background="#FFFAFAFA" CornerRadius="10"/>
<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>
</UserControl>

View File

@ -30,5 +30,20 @@ namespace StudentManager.Editor
{
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

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Event
{
public class MessageEvent : PubSubEvent<string>
{
}
}

View File

@ -0,0 +1,22 @@
using StudentManager.Event;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentManager.Extensions
{
internal static class DialogExtensions
{
public static void ResgiterMessage(this IEventAggregator aggregator, Action<string> message)
{
aggregator.GetEvent<MessageEvent>().Subscribe(message);
}
public static void SendMessage(this IEventAggregator aggregator, string message)
{
aggregator.GetEvent<MessageEvent>().Publish(message);
}
}
}

View File

@ -0,0 +1,24 @@
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,4 +1,10 @@
using Mysqlx.Crud;
using DryIoc.ImTools;
using LiveCharts;
using LiveCharts.Wpf;
using Mysqlx.Crud;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json;
using Org.BouncyCastle.Utilities;
using StudentManager.Common;
using StudentManager.Data;
using StudentManager.Extensions;
@ -7,8 +13,13 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Timer = StudentManager.Common.Timer;
namespace StudentManager.Model
{
@ -48,20 +59,27 @@ namespace StudentManager.Model
{
private ObservableCollection<StudentInfo> studentDatas = new ObservableCollection<StudentInfo>();
public ReadOnlyObservableCollection<StudentInfo> StudentDatas { get; private set; }
public ObservableCollection<StudentInfo> StudentDatas { get { return studentDatas; } private set { studentDatas = value; RaisePropertyChanged(); } }
private ObservableCollection<QuestionData> questionDatas = new ObservableCollection<QuestionData>();
public ReadOnlyObservableCollection<QuestionData> QuestionDatas { get; private set; }
public ObservableCollection<QuestionData> QuestionDatas { get { return questionDatas; } private set { questionDatas = value; RaisePropertyChanged(); } }
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>();
public ReadOnlyObservableCollection<DetailErrorInfo> ErrorSetDatas { get; private set; }
public ObservableCollection<DetailErrorInfo> ErrorSetDatas { get { return errorSetDatas; } private set { errorSetDatas = value; RaisePropertyChanged(); } }
private ObservableCollection<CursonQuestionsData> cQDatas = new ObservableCollection<CursonQuestionsData>();
public ReadOnlyObservableCollection<CursonQuestionsData> CQDatas { get; private set; }
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>();
public ObservableCollection<DetailHomeWorkInfo> HomeWork { get { return homeWork; } private set { homeWork = value; RaisePropertyChanged(); } }
@ -117,24 +135,142 @@ namespace StudentManager.Model
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 IEventAggregator aggregator;
public DelegateCommand<string> RegionTo { get; set; }
public DelegateCommand<StudentInfo> SelectedCommand { get; set; }
public DelegateCommand<DetailHomeWorkInfo> HomeWorkSelectedCommand { 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 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)
Students(IRegionManager regionManager, IEventAggregator aggregator)
{
CreateMenuBar();
RegionTo = new DelegateCommand<string>((x) => {
regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString());
if(x == "DetailCheckView")
CreateMenuBar();
CurrentTime = DateTime.Now.ToString("HH:mm");
Timer timer = new Timer(() =>
{
CurrentTime = DateTime.Now.ToString("HH:mm");
});
FileSystem.Instance.AutoSaveInvoke += () =>
{
aggregator.SendMessage(" 将在10秒后自动保存 ");
};
FileSystem.Instance.SavedInvoke += () =>
{
aggregator.SendMessage(" 已保存 ");
};
FileSystem.Instance.AutoSave();
RegionTo = new DelegateCommand<string>((x) =>
{
regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString());
if (x == "DetailCheckView")
{
RegionToDetailCheckView();
}
@ -142,52 +278,280 @@ namespace StudentManager.Model
{
RegionToDetailView();
}
RegionToStudents();
RegionToStudents();
});
UpdateHomeWorkCommand = new DelegateCommand(() => UpdateHomeWork());
SelectedCommand = new DelegateCommand<StudentInfo>((x) =>
{
if (x == null) return;
SelectedStudent = x;
UpdateGird();
RegionToDetailView();
});
HomeWorkSetSelectedCommand = new DelegateCommand<DetailHomeWorkSetInfo>((x) =>
{
if (x == null) return;
selectedHomeWorkSet = x;
if (x == null || SelectedStudent == null) return;
SelectedHomeWorkSet = x;
HomeWork = SelectedStudent.HomeWorkSet.GetDetailHomeWorkList(SelectedHomeWorkSet.Lesson);
});
HomeWorkSelectedCommand = new DelegateCommand<DetailHomeWorkInfo>((e) =>
{
if(e == null) return;
//HomeWork =
if (e == null) return;
//selectedHomeWork = e;
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();
StudentDatas = new ReadOnlyObservableCollection<StudentInfo>(studentDatas);
QuestionDatas = new ReadOnlyObservableCollection<QuestionData>(questionDatas);
ErrorSetDatas = new ReadOnlyObservableCollection<DetailErrorInfo>(errorSetDatas);
StudentDatas = new ObservableCollection<StudentInfo>(studentDatas);
QuestionDatas = new ObservableCollection<QuestionData>(questionDatas);
ErrorSetDatas = new ObservableCollection<DetailErrorInfo>(errorSetDatas);
MenuBars = new ReadOnlyObservableCollection<MenuBar>(menuBars);
//CQDatas = new ReadOnlyObservableCollection<CursonQuestionsData>(cQDatas);
HomeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>(homeWorkSet);
UpdateGird();
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;
}
SaveAll();
private int ConvertToHashInt(string item)
{
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()
{
if(selectedStudent == null) return;
ErrorSet = selectedStudent.ErrorSet.GetDetailErrorSetInfo();
if (selectedStudent == null) return;
ErrorSetDatas = selectedStudent.ErrorSet.GetDetailErrorQuestionList();
HomeWorkSet = selectedStudent.HomeWorkSet.GetDetailHomeWorkSetList();
}
@ -199,7 +563,7 @@ namespace StudentManager.Model
private void RegionToStudents()
{
}
void CreateMenuBar()
@ -208,22 +572,45 @@ namespace StudentManager.Model
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 = "CheckView" });
//menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "出题", NameSpace = "QuestionsView" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "出题", NameSpace = "DetailCheckView" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "发布家庭作业", NameSpace = "AddHomeWork" });
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "出题", NameSpace = "AddQuestionView" });
}
private void Load()
{
StudentLib.Load();
QuestionLib.Load();
studentDatas = StudentLib.GetAllStudents();
questionDatas = QuestionLib.GetAllQuestion();
QuestionLib.Instance.Load();
Reload();
}
private void SaveAll()
private void Reload()
{
StudentLib.Save();
QuestionLib.Save();
studentDatas.Clear();
questionDatas.Clear();
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,13 +9,14 @@
</PropertyGroup>
<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="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Prism.DryIoc" Version="9.0.537" />
</ItemGroup>
<ItemGroup>
<Folder Include="Interface\" />
</ItemGroup>
</Project>

View File

@ -7,6 +7,12 @@
</ApplicationDefinition>
</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">
<SubType>Code</SubType>
</Compile>
@ -27,6 +33,12 @@
</Compile>
</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">
<SubType>Designer</SubType>
</Page>