Online
This commit is contained in:
parent
8672bd5fc8
commit
f19c955def
@ -149,7 +149,7 @@ namespace StudentManager.Common
|
|||||||
if (id.QuestionBase.Status == false || ErrorArray.Contains(id.QuestionBase.ID)) return;
|
if (id.QuestionBase.Status == false || ErrorArray.Contains(id.QuestionBase.ID)) return;
|
||||||
|
|
||||||
|
|
||||||
if ((id.CorrectCount - id.CorrectCount) <= CorrectThresholds)
|
if ((id.CorrectCount - id.ErrorCount) <= CorrectThresholds)
|
||||||
{
|
{
|
||||||
id.QuestionBase.Status = false;
|
id.QuestionBase.Status = false;
|
||||||
CorrectArray.Remove(id.QuestionBase.ID);
|
CorrectArray.Remove(id.QuestionBase.ID);
|
||||||
@ -162,7 +162,7 @@ namespace StudentManager.Common
|
|||||||
if (id.QuestionBase.Status == true || CorrectArray.Contains(id.QuestionBase.ID)) return;
|
if (id.QuestionBase.Status == true || CorrectArray.Contains(id.QuestionBase.ID)) return;
|
||||||
|
|
||||||
|
|
||||||
if ((id.CorrectCount - id.CorrectCount) > CorrectThresholds)
|
if ((id.CorrectCount - id.ErrorCount) > CorrectThresholds)
|
||||||
{
|
{
|
||||||
id.QuestionBase.Status = true;
|
id.QuestionBase.Status = true;
|
||||||
ErrorArray.Remove(id.QuestionBase.ID);
|
ErrorArray.Remove(id.QuestionBase.ID);
|
||||||
@ -175,11 +175,11 @@ namespace StudentManager.Common
|
|||||||
AddCorrectQuestion(new QuestionBase { ID = question.Id });
|
AddCorrectQuestion(new QuestionBase { ID = question.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueryErrorSet(int id)
|
public void QueryErrorSet(long id)
|
||||||
{
|
{
|
||||||
Errores.Clear();
|
Errores.Clear();
|
||||||
|
|
||||||
SQLHelper.Query<UserQuestionData>(Tables.UQTable, id).ForEach(x =>
|
SQLHelper.Query<UserQuestionData>(id).ForEach(x =>
|
||||||
{
|
{
|
||||||
AddQuestion(new QuestionBase { ID = x.PID, Status = x.Status });
|
AddQuestion(new QuestionBase { ID = x.PID, Status = x.Status });
|
||||||
});
|
});
|
||||||
|
18
StudentManager/Common/FileSystem.cs
Normal file
18
StudentManager/Common/FileSystem.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using StudentManager.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StudentManager.Common
|
||||||
|
{
|
||||||
|
public static class FileSystem
|
||||||
|
{
|
||||||
|
public static void SaveAll()
|
||||||
|
{
|
||||||
|
StudentLib.Save();
|
||||||
|
QuestionLib.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -215,11 +215,11 @@ namespace StudentManager.Common
|
|||||||
return works;
|
return works;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FreshAllHomeWork(int id)
|
public void FreshAllHomeWork(long id)
|
||||||
{
|
{
|
||||||
HomeWorks.Clear();
|
HomeWorks.Clear();
|
||||||
|
|
||||||
SQLHelper.Query<CursonQuestionsData>(Tables.CQTable, id).ForEach(x =>
|
SQLHelper.Query<CursonQuestionsData>(id).ForEach(x =>
|
||||||
{
|
{
|
||||||
List<QuestionBase> Questions = new List<QuestionBase>();
|
List<QuestionBase> Questions = new List<QuestionBase>();
|
||||||
x.ProblemIDS.ForEach(y => Questions.Add(new QuestionBase { ID = y, Status = x.CorrectIDS.Contains(y) }));
|
x.ProblemIDS.ForEach(y => Questions.Add(new QuestionBase { ID = y, Status = x.CorrectIDS.Contains(y) }));
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
using DryIoc.ImTools;
|
using DryIoc.ImTools;
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using StudentManager.Common;
|
|
||||||
using StudentManager.Data;
|
using StudentManager.Data;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System;
|
||||||
using System.Text;
|
using Enum = System.Enum;
|
||||||
using System.Threading.Tasks;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace StudentManager.Common
|
namespace StudentManager.Common
|
||||||
{
|
{
|
||||||
@ -19,7 +17,7 @@ namespace StudentManager.Common
|
|||||||
static public string UQTable { get; } = "user_data";
|
static public string UQTable { get; } = "user_data";
|
||||||
static public string CQTable { get; } = "curson_questions";
|
static public string CQTable { get; } = "curson_questions";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class SQLMapping
|
public static class SQLMapping
|
||||||
{
|
{
|
||||||
@ -32,7 +30,7 @@ namespace StudentManager.Common
|
|||||||
{
|
{
|
||||||
if (typeof(T) == typeof(StudentData))
|
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).Name = reader[1].ToString();
|
||||||
(data as StudentData).Gender = reader[2].ToString();
|
(data as StudentData).Gender = reader[2].ToString();
|
||||||
(data as StudentData).Contact = reader[3].ToString();
|
(data as StudentData).Contact = reader[3].ToString();
|
||||||
@ -40,14 +38,20 @@ namespace StudentManager.Common
|
|||||||
(data as StudentData).Grade = (byte)reader[5];
|
(data as StudentData).Grade = (byte)reader[5];
|
||||||
(data as StudentData).TotalsQuestions = (UInt16)reader[6];
|
(data as StudentData).TotalsQuestions = (UInt16)reader[6];
|
||||||
(data as StudentData).CorrectionCount = (UInt16)reader[7];
|
(data as StudentData).CorrectionCount = (UInt16)reader[7];
|
||||||
(data as StudentData).HomeWork = (UInt16)reader[8];
|
(data as StudentData).CurronHomeWorkIndex = (UInt16)reader[8];
|
||||||
|
(data as StudentData).Password = reader[9].ToString();
|
||||||
|
(data as StudentData).Birthdate = (DateTime)reader[10];
|
||||||
|
(data as StudentData).HWQTotalCount = (uint)reader[11];
|
||||||
|
(data as StudentData).HWQTotalErrorCount = (uint)reader[12];
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(QuestionData))
|
else if (typeof(T) == typeof(QuestionData))
|
||||||
{
|
{
|
||||||
DifficultyLevel dLevel = DifficultyLevel.easy;
|
DifficultyLevel dLevel = DifficultyLevel.easy;
|
||||||
QStatus qStatus = QStatus.published;
|
QStatus qStatus = QStatus.published;
|
||||||
|
QType qType = QType.填空题;
|
||||||
(data as QuestionData).Id = (int)reader[0];
|
(data as QuestionData).Id = (int)reader[0];
|
||||||
(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).Stem = reader[2].ToString();
|
||||||
(data as QuestionData).Answer = reader[3].ToString();
|
(data as QuestionData).Answer = reader[3].ToString();
|
||||||
Enum.TryParse(reader[4].ToString(), true, out dLevel);
|
Enum.TryParse(reader[4].ToString(), true, out dLevel);
|
||||||
@ -80,11 +84,11 @@ namespace StudentManager.Common
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//for (int i = 0; i < reader.FieldCount; ++i)
|
//for (int i = 0; i < reader.FieldCount; ++i)
|
||||||
//{
|
//{
|
||||||
// data?.GetType().GetProperties().ForEach(x => { x.SetValue(reader[i].GetType(), reader[i]); });
|
// data?.GetType().GetProperties().ForEach(x => { x.SetValue(reader[i].GetType(), reader[i]); });
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -98,6 +102,14 @@ namespace StudentManager.Common
|
|||||||
|
|
||||||
public static class SQLHelper
|
public static class SQLHelper
|
||||||
{
|
{
|
||||||
|
private static Dictionary<System.Type, string> TypeMap = new Dictionary<System.Type, string>
|
||||||
|
{
|
||||||
|
{ typeof(QuestionData), "questions" },
|
||||||
|
{ typeof(CursonQuestionsData), "curson_questions" },
|
||||||
|
{ typeof(StudentData), "users" },
|
||||||
|
{ typeof(UserQuestionData), "user_data" },
|
||||||
|
};
|
||||||
|
|
||||||
static string config = "server=8.137.125.29;port=3306;user=StudentManager;password=wangxin55;database=studentmanager";
|
static string config = "server=8.137.125.29;port=3306;user=StudentManager;password=wangxin55;database=studentmanager";
|
||||||
static MySqlConnection connection = null;
|
static MySqlConnection connection = null;
|
||||||
static MySqlCommand cmd = null;
|
static MySqlCommand cmd = null;
|
||||||
@ -105,13 +117,16 @@ namespace StudentManager.Common
|
|||||||
// update ** set ** = '**',... where ** = **;
|
// update ** set ** = '**',... where ** = **;
|
||||||
// insert into ** values('**','**'...);
|
// insert into ** values('**','**'...);
|
||||||
// delete from ** where ** = **;
|
// delete from ** where ** = **;
|
||||||
public static List<T> Query<T>(string tableName, int id = -1, params string[] queryParams) where T : IDataCommon, new()
|
public static List<T> Query<T>(long id = 9999999, params string[] queryParams) where T : IDataCommon, new()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
string tableName = string.Empty;
|
||||||
|
TypeMap.TryGetValue(typeof(T), out tableName);
|
||||||
connection = new MySqlConnection(config);
|
connection = new MySqlConnection(config);
|
||||||
|
|
||||||
List<T> result = new List<T>();
|
List<T> result = new List<T>();
|
||||||
|
|
||||||
string idName = typeof(T) == typeof(StudentData) ? "user_id" : typeof(T) == typeof(QuestionData) ? "problem_id" : "user_id";
|
string idName = typeof(T) == typeof(StudentData) ? "user_id" : typeof(T) == typeof(QuestionData) ? "problem_id" : "user_id";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@ -121,14 +136,14 @@ namespace StudentManager.Common
|
|||||||
string filedList = string.Join(",", queryParams);
|
string filedList = string.Join(",", queryParams);
|
||||||
queryStr = $"select {filedList} from {tableName};";
|
queryStr = $"select {filedList} from {tableName};";
|
||||||
|
|
||||||
if (id != -1)
|
if (id != 9999999)
|
||||||
queryStr = $@"select {filedList} from {tableName} WHERE {idName} = {id};";
|
queryStr = $@"select {filedList} from {tableName} WHERE {idName} = {id};";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
queryStr = $"select * from {tableName};";
|
queryStr = $"select * from {tableName};";
|
||||||
if (id != -1)
|
if (id != 9999999)
|
||||||
queryStr = $@"select * from {tableName} WHERE {idName} = {id};";
|
queryStr = $@"select * from {tableName} WHERE {idName} = {id};";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = new MySqlCommand(queryStr, connection);
|
cmd = new MySqlCommand(queryStr, connection);
|
||||||
@ -157,7 +172,7 @@ namespace StudentManager.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<T> UnionQuery<T>(int id = -1, string tableName = "questions", string otherTable = "user_data") where T : IDataCommon, new()
|
public static List<T> UnionQuery<T>(int id = 9999999, string tableName = "questions", string otherTable = "user_data") where T : IDataCommon, new()
|
||||||
{
|
{
|
||||||
connection = new MySqlConnection(config);
|
connection = new MySqlConnection(config);
|
||||||
|
|
||||||
@ -165,9 +180,9 @@ namespace StudentManager.Common
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection = new MySqlConnection(config);
|
||||||
string queryStr = "";
|
string queryStr = "";
|
||||||
if(id == -1)
|
if (id == 9999999)
|
||||||
queryStr = $@"SELECT u.user_id, q.* FROM {otherTable} u JOIN {tableName} q ON u.problem_id = q.problem_id";
|
queryStr = $@"SELECT u.user_id, q.* FROM {otherTable} u JOIN {tableName} q ON u.problem_id = q.problem_id";
|
||||||
else
|
else
|
||||||
queryStr = $@"SELECT q.* FROM {tableName} q JOIN {otherTable} u ON q.problem_id = u.problem_id WHERE u.user_id = {id}";
|
queryStr = $@"SELECT q.* FROM {tableName} q JOIN {otherTable} u ON q.problem_id = u.problem_id WHERE u.user_id = {id}";
|
||||||
@ -198,10 +213,39 @@ namespace StudentManager.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add()
|
|
||||||
|
public static void Add<T>(T value)
|
||||||
{
|
{
|
||||||
|
connection = new MySqlConnection(config);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
string stableName = string.Empty;
|
||||||
|
TypeMap.TryGetValue(typeof(T), out stableName);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
if (typeof(T) == typeof(QuestionData))
|
||||||
|
{
|
||||||
|
var ques = value as QuestionData;
|
||||||
|
string sql = $"INSERT INTO {stableName} " +
|
||||||
|
$"(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)";
|
||||||
|
|
||||||
|
MySqlCommand 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();
|
||||||
|
|
||||||
|
}
|
||||||
|
//string sql = $"insert into {stableName}"
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -209,7 +253,100 @@ namespace StudentManager.Common
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
cmd.Dispose();
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void UpdateErrorSet(long UID, int PID, bool status)
|
||||||
|
{
|
||||||
|
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", PID);
|
||||||
|
|
||||||
|
int recordCount = Convert.ToInt32(checkCmd.ExecuteScalar());
|
||||||
|
|
||||||
|
if (recordCount > 0)
|
||||||
|
{
|
||||||
|
// 记录存在,执行更新操作
|
||||||
|
string updateQuery = "UPDATE user_data SET status = @status 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", PID);
|
||||||
|
updateCmd.Parameters.AddWithValue("@status", status);
|
||||||
|
|
||||||
|
updateCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (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", PID);
|
||||||
|
|
||||||
|
updateCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void UpdateHomework(long UID, int 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 (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,12 @@ namespace StudentManager.Data
|
|||||||
public class QuestionData : IDataCommon
|
public class QuestionData : IDataCommon
|
||||||
{
|
{
|
||||||
public int Id { get; set; } = 0;
|
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 Stem { get; set; } = string.Empty;
|
||||||
public string Answer { get; set; } = String.Empty;
|
public string Answer { get; set; } = String.Empty;
|
||||||
public DifficultyLevel DifficultyLevel { get; set; } = DifficultyLevel.easy;
|
public DifficultyLevel DifficultyLevel { get; set; } = DifficultyLevel.easy;
|
||||||
public string Category { get; set; } = string.Empty;
|
public string Category { get; set; } = string.Empty;
|
||||||
public string Tags { get; set; } = string.Empty;
|
public string Tags { get; set; } = "默认";
|
||||||
public string Source { get; set; } = string.Empty;
|
public string Source { get; set; } = string.Empty;
|
||||||
public int Lesson { get; set; } = 0;
|
public int Lesson { get; set; } = 0;
|
||||||
public QStatus Status { get; set; } = QStatus.published;
|
public QStatus Status { get; set; } = QStatus.published;
|
||||||
|
@ -39,7 +39,7 @@ namespace StudentManager.Data
|
|||||||
|
|
||||||
public static void FreshAllQuestion()
|
public static void FreshAllQuestion()
|
||||||
{
|
{
|
||||||
SQLHelper.Query<QuestionData>(Tables.QuesTable).ForEach(x => QuestionDic.Add(x.Id, x));
|
SQLHelper.Query<QuestionData>().ForEach(x => QuestionDic.Add(x.Id, x));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObservableCollection<QuestionData> GetAllQuestion()
|
public static ObservableCollection<QuestionData> GetAllQuestion()
|
||||||
@ -62,6 +62,7 @@ namespace StudentManager.Data
|
|||||||
public static void Add(QuestionData question)
|
public static void Add(QuestionData question)
|
||||||
{
|
{
|
||||||
QuestionDic.Add(question.Id, question);
|
QuestionDic.Add(question.Id, question);
|
||||||
|
SQLHelper.Add(question);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Remove(QuestionData question)
|
public static void Remove(QuestionData question)
|
||||||
|
@ -6,24 +6,41 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StudentManager.Data
|
namespace StudentManager.Data
|
||||||
{
|
{
|
||||||
|
public enum Gender
|
||||||
|
{
|
||||||
|
男,
|
||||||
|
女,
|
||||||
|
}
|
||||||
public class StudentData : IDataCommon
|
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 Name { get; set; } = "Name";
|
||||||
public string Gender { get; set; } = "Gender";
|
public string Gender { get; set; } = "Gender";
|
||||||
public string Contact { get; set; } = "Contact";
|
public string Contact { get; set; } = "Contact";
|
||||||
public string Address { get; set; } = "Address";
|
public string Address { get; set; } = "Address";
|
||||||
public int Grade { get; set; } = 1;
|
public int Grade { get; set; } = 1;
|
||||||
|
public DateTime Birthdate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
// Error Set
|
||||||
public int TotalsQuestions { get; set; } = 0;
|
public int TotalsQuestions { get; set; } = 0;
|
||||||
public int CorrectionCount { get; set; } = 0;
|
public int CorrectionCount { get; set; } = 0;
|
||||||
public int HomeWork { get; set; } = 0;
|
|
||||||
|
|
||||||
|
// HomeWork
|
||||||
|
public int CurronHomeWorkIndex { get; set; } = 0;
|
||||||
|
|
||||||
|
// HomeWorkSet
|
||||||
|
public uint HWQTotalCount { get; set; } = 0;
|
||||||
|
public uint HWQTotalErrorCount { get; set; } = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Extension
|
||||||
public float ErrorRate { get; set; } = 0;
|
public float ErrorRate { get; set; } = 0;
|
||||||
public float CorrectRate { get; set; } = 0;
|
public float CorrectRate { get; set; } = 0;
|
||||||
public int UnCorrectCount { get; set; } = 0;
|
public int UnCorrectCount { get; set; } = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//public string TableName { get => "users"; set => throw new NotImplementedException(); }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace StudentManager.Data
|
|||||||
{
|
{
|
||||||
public static string LibPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\FileLib\\";
|
public static string LibPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\FileLib\\";
|
||||||
public static string FileName = "studentLib.dbsi";
|
public static string FileName = "studentLib.dbsi";
|
||||||
public static Dictionary<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)
|
public static void Add(StudentInfo studentInfo)
|
||||||
{
|
{
|
||||||
@ -30,7 +30,7 @@ namespace StudentManager.Data
|
|||||||
|
|
||||||
Debug.Assert(Path.Exists(LibPath));
|
Debug.Assert(Path.Exists(LibPath));
|
||||||
string file = File.ReadAllText(LibPath + FileName);
|
string file = File.ReadAllText(LibPath + FileName);
|
||||||
StudentDic = JsonSerializer.Deserialize<Dictionary<int, StudentInfo>>(file);
|
StudentDic = JsonSerializer.Deserialize<Dictionary<long, StudentInfo>>(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Save()
|
public static void Save()
|
||||||
@ -43,7 +43,7 @@ namespace StudentManager.Data
|
|||||||
{
|
{
|
||||||
StudentDic.Clear();
|
StudentDic.Clear();
|
||||||
|
|
||||||
SQLHelper.Query<StudentData>(Tables.UserTable).ForEach(x =>
|
SQLHelper.Query<StudentData>().ForEach(x =>
|
||||||
StudentDic.Add(x.UID, new StudentInfo
|
StudentDic.Add(x.UID, new StudentInfo
|
||||||
{
|
{
|
||||||
UID = x.UID,
|
UID = x.UID,
|
||||||
@ -51,7 +51,7 @@ namespace StudentManager.Data
|
|||||||
Address = x.Address,
|
Address = x.Address,
|
||||||
Contact = x.Contact,
|
Contact = x.Contact,
|
||||||
Grade = x.Grade,
|
Grade = x.Grade,
|
||||||
CurrentHomeWorkIndex = x.HomeWork,
|
CurrentHomeWorkIndex = x.CurronHomeWorkIndex,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
foreach (var item in StudentDic)
|
foreach (var item in StudentDic)
|
||||||
@ -70,12 +70,12 @@ namespace StudentManager.Data
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StudentInfo QueryStudentDetailInfo(int uid)
|
public static StudentInfo QueryStudentDetailInfo(long uid)
|
||||||
{
|
{
|
||||||
return GetStudentDetailInfo(Get(uid));
|
return GetStudentDetailInfo(Get(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StudentInfo Get(int uid)
|
public static StudentInfo Get(long uid)
|
||||||
{
|
{
|
||||||
if (!StudentDic.ContainsKey(uid)) return null;
|
if (!StudentDic.ContainsKey(uid)) return null;
|
||||||
return StudentDic[uid];
|
return StudentDic[uid];
|
||||||
@ -86,7 +86,7 @@ namespace StudentManager.Data
|
|||||||
StudentDic.Remove(studentInfo.UID);
|
StudentDic.Remove(studentInfo.UID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Remove(int id)
|
public static void Remove(long id)
|
||||||
{
|
{
|
||||||
StudentDic.Remove(id);
|
StudentDic.Remove(id);
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ namespace StudentManager.Data
|
|||||||
|
|
||||||
public class StudentInfo
|
public class StudentInfo
|
||||||
{
|
{
|
||||||
public int UID { get; set; } = 1;
|
public long UID { get; set; } = 1;
|
||||||
public string Name { get; set; } = "Name";
|
public string Name { get; set; } = "Name";
|
||||||
public string Gender { get; set; } = "Gender";
|
public string Gender { get; set; } = "Gender";
|
||||||
public string Contact { get; set; } = "Contact";
|
public string Contact { get; set; } = "Contact";
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
<GridViewColumn Header="类型">
|
<GridViewColumn Header="类型">
|
||||||
<GridViewColumn.CellTemplate>
|
<GridViewColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ComboBox SelectedIndex="0" ItemsSource="{Binding Source={StaticResource TypeEnumValues}}"/>
|
<ComboBox SelectedItem="{Binding Type, Mode=TwoWay}" ItemsSource="{Binding Source={StaticResource TypeEnumValues}}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.CellTemplate>
|
</GridViewColumn.CellTemplate>
|
||||||
</GridViewColumn>
|
</GridViewColumn>
|
||||||
@ -76,7 +76,7 @@
|
|||||||
<GridViewColumn Header="难度">
|
<GridViewColumn Header="难度">
|
||||||
<GridViewColumn.CellTemplate>
|
<GridViewColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ComboBox SelectedIndex="0" ItemsSource="{Binding Source={StaticResource DifficultyEnumValues}}"/>
|
<ComboBox SelectedItem="{Binding DifficultyLevel, Mode=TwoWay}" ItemsSource="{Binding Source={StaticResource DifficultyEnumValues}}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.CellTemplate>
|
</GridViewColumn.CellTemplate>
|
||||||
</GridViewColumn>
|
</GridViewColumn>
|
||||||
@ -97,7 +97,7 @@
|
|||||||
<GridViewColumn Header="状态">
|
<GridViewColumn Header="状态">
|
||||||
<GridViewColumn.CellTemplate>
|
<GridViewColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ComboBox SelectedIndex="0" ItemsSource="{Binding Source={StaticResource PublishEnumValues}}"/>
|
<ComboBox SelectedItem="{Binding Status, Mode=TwoWay}" ItemsSource="{Binding Source={StaticResource PublishEnumValues}}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.CellTemplate>
|
</GridViewColumn.CellTemplate>
|
||||||
</GridViewColumn>
|
</GridViewColumn>
|
||||||
@ -124,14 +124,16 @@
|
|||||||
<StackPanel>
|
<StackPanel>
|
||||||
|
|
||||||
<Button Content="删除" Style="{StaticResource MaterialDesignFlatButton}" Padding="5" Foreground="White"
|
<Button Content="删除" Style="{StaticResource MaterialDesignFlatButton}" Padding="5" Foreground="White"
|
||||||
Command="{Binding DataContext.RemoveNewColumnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
|
/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.HeaderTemplate>
|
</GridViewColumn.HeaderTemplate>
|
||||||
<GridViewColumn.CellTemplate>
|
<GridViewColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Button Content="删除" Style="{StaticResource MaterialDesignFlatButton}" Padding="5"
|
<Button Content="删除" Style="{StaticResource MaterialDesignFlatButton}" Padding="5"
|
||||||
Command="{Binding DataContext.RemoveNewColumnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"/>
|
|
||||||
|
Command="{Binding DataContext.RemoveNewColumnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
|
||||||
|
CommandParameter="{Binding}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.CellTemplate>
|
</GridViewColumn.CellTemplate>
|
||||||
</GridViewColumn>
|
</GridViewColumn>
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
<ColumnDefinition Width="100"/>
|
<ColumnDefinition Width="100"/>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ItemsControl ItemsSource="{Binding MenuBars}">
|
<DockPanel LastChildFill="False">
|
||||||
|
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding MenuBars}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Button Content="{Binding Title}" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
<Button Content="{Binding Title}" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||||
@ -31,6 +31,10 @@
|
|||||||
</ItemsControl.ItemTemplate>
|
</ItemsControl.ItemTemplate>
|
||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
|
|
||||||
|
<Button Margin="5" HorizontalAlignment="Stretch" DockPanel.Dock="Bottom" Content="保存"
|
||||||
|
Command="{Binding SaveAllCommand}"/>
|
||||||
|
</DockPanel>
|
||||||
|
|
||||||
<ContentControl Grid.Column="1" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}"/>
|
<ContentControl Grid.Column="1" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Mysqlx.Crud;
|
using Mysqlx.Crud;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Org.BouncyCastle.Utilities;
|
using Org.BouncyCastle.Utilities;
|
||||||
using StudentManager.Common;
|
using StudentManager.Common;
|
||||||
using StudentManager.Data;
|
using StudentManager.Data;
|
||||||
@ -68,7 +69,7 @@ namespace StudentManager.Model
|
|||||||
|
|
||||||
|
|
||||||
private ObservableCollection<DetailHomeWorkSetInfo> homeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>();
|
private ObservableCollection<DetailHomeWorkSetInfo> homeWorkSet = new ObservableCollection<DetailHomeWorkSetInfo>();
|
||||||
public ObservableCollection<DetailHomeWorkSetInfo> HomeWorkSet { get { return homeWorkSet; } private set { homeWorkSet = value; RaisePropertyChanged(); } }
|
public ObservableCollection<DetailHomeWorkSetInfo> HomeWorkSet { get { return homeWorkSet; } private set { homeWorkSet = value; RaisePropertyChanged(); } }
|
||||||
|
|
||||||
private ObservableCollection<DetailHomeWorkInfo> homeWork = new ObservableCollection<DetailHomeWorkInfo>();
|
private ObservableCollection<DetailHomeWorkInfo> homeWork = new ObservableCollection<DetailHomeWorkInfo>();
|
||||||
public ObservableCollection<DetailHomeWorkInfo> HomeWork { get { return homeWork; } private set { homeWork = value; RaisePropertyChanged(); } }
|
public ObservableCollection<DetailHomeWorkInfo> HomeWork { get { return homeWork; } private set { homeWork = value; RaisePropertyChanged(); } }
|
||||||
@ -140,14 +141,16 @@ namespace StudentManager.Model
|
|||||||
public DelegateCommand AddNewColumnCommand { get; set; }
|
public DelegateCommand AddNewColumnCommand { get; set; }
|
||||||
public DelegateCommand SubmitAddQuestionsCommand { get; set; }
|
public DelegateCommand SubmitAddQuestionsCommand { get; set; }
|
||||||
public DelegateCommand ClearnAddQuestionsCommand { get; set; }
|
public DelegateCommand ClearnAddQuestionsCommand { get; set; }
|
||||||
|
public DelegateCommand SaveAllCommand { get; set; }
|
||||||
|
|
||||||
Students(IRegionManager regionManager)
|
Students(IRegionManager regionManager)
|
||||||
{
|
{
|
||||||
CreateMenuBar();
|
CreateMenuBar();
|
||||||
|
|
||||||
RegionTo = new DelegateCommand<string>((x) => {
|
RegionTo = new DelegateCommand<string>((x) =>
|
||||||
regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString());
|
{
|
||||||
if(x == "DetailCheckView")
|
regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString());
|
||||||
|
if (x == "DetailCheckView")
|
||||||
{
|
{
|
||||||
RegionToDetailCheckView();
|
RegionToDetailCheckView();
|
||||||
}
|
}
|
||||||
@ -155,7 +158,7 @@ namespace StudentManager.Model
|
|||||||
{
|
{
|
||||||
RegionToDetailView();
|
RegionToDetailView();
|
||||||
}
|
}
|
||||||
RegionToStudents();
|
RegionToStudents();
|
||||||
});
|
});
|
||||||
|
|
||||||
SubmitHomeWorkCommand = new DelegateCommand(() => SubmitHomeWork());
|
SubmitHomeWorkCommand = new DelegateCommand(() => SubmitHomeWork());
|
||||||
@ -176,14 +179,14 @@ namespace StudentManager.Model
|
|||||||
|
|
||||||
HomeWorkSelectedCommand = new DelegateCommand<DetailHomeWorkInfo>((e) =>
|
HomeWorkSelectedCommand = new DelegateCommand<DetailHomeWorkInfo>((e) =>
|
||||||
{
|
{
|
||||||
if(e == null) return;
|
if (e == null) return;
|
||||||
//HomeWork =
|
//HomeWork =
|
||||||
});
|
});
|
||||||
|
|
||||||
DeleteQuestionCommand = new DelegateCommand<QuestionData>((x) =>
|
DeleteQuestionCommand = new DelegateCommand<QuestionData>((x) =>
|
||||||
{
|
{
|
||||||
if(x == null) return;
|
if (x == null) return;
|
||||||
var c = MessageBox.Show("确定删除吗?","确认",MessageBoxButton.OKCancel);
|
var c = MessageBox.Show("确定删除吗?", "确认", MessageBoxButton.OKCancel);
|
||||||
if (c != MessageBoxResult.OK) return;
|
if (c != MessageBoxResult.OK) return;
|
||||||
QuestionLib.Remove(x);
|
QuestionLib.Remove(x);
|
||||||
QuestionDatas = QuestionLib.GetAllQuestion();
|
QuestionDatas = QuestionLib.GetAllQuestion();
|
||||||
@ -210,6 +213,8 @@ namespace StudentManager.Model
|
|||||||
ADDQuestionDatas.Clear();
|
ADDQuestionDatas.Clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SaveAllCommand = new DelegateCommand(() => FileSystem.SaveAll());
|
||||||
|
|
||||||
SubmitAddQuestionsCommand = new DelegateCommand(() =>
|
SubmitAddQuestionsCommand = new DelegateCommand(() =>
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -225,10 +230,10 @@ namespace StudentManager.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var item in preToRemove)
|
foreach (var item in preToRemove)
|
||||||
{
|
{
|
||||||
ADDQuestionDatas.Remove(item);
|
ADDQuestionDatas.Remove(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
@ -245,8 +250,6 @@ namespace StudentManager.Model
|
|||||||
|
|
||||||
this.regionManager = regionManager;
|
this.regionManager = regionManager;
|
||||||
|
|
||||||
|
|
||||||
SaveAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ConvertToHashInt(string item)
|
private int ConvertToHashInt(string item)
|
||||||
@ -258,15 +261,39 @@ namespace StudentManager.Model
|
|||||||
|
|
||||||
private void SubmitHomeWork()
|
private void SubmitHomeWork()
|
||||||
{
|
{
|
||||||
|
// update error set and local homework
|
||||||
SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Questions.ForEach(x =>
|
SelectedStudent.HomeWorkSet.Get(SelectedHomeWorkSet.Lesson).Questions.ForEach(x =>
|
||||||
{
|
{
|
||||||
x.Status = HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status;
|
if (x.Status != HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status)
|
||||||
|
{
|
||||||
|
x.Status = HomeWork.FirstOrDefault(hw => hw.PID == x.ID).Status;
|
||||||
|
SelectedStudent.ErrorSet.AddQuestion(x);
|
||||||
|
SQLHelper.UpdateErrorSet(SelectedStudent.UID, x.ID, x.Status);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegionToDetailView()
|
private void RegionToDetailView()
|
||||||
{
|
{
|
||||||
if(selectedStudent == null) return;
|
if (selectedStudent == null) return;
|
||||||
ErrorSet = selectedStudent.ErrorSet.GetDetailErrorSetInfo();
|
ErrorSet = selectedStudent.ErrorSet.GetDetailErrorSetInfo();
|
||||||
HomeWorkSet = selectedStudent.HomeWorkSet.GetDetailHomeWorkSetList();
|
HomeWorkSet = selectedStudent.HomeWorkSet.GetDetailHomeWorkSetList();
|
||||||
}
|
}
|
||||||
@ -279,7 +306,7 @@ namespace StudentManager.Model
|
|||||||
|
|
||||||
private void RegionToStudents()
|
private void RegionToStudents()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateMenuBar()
|
void CreateMenuBar()
|
||||||
@ -300,10 +327,6 @@ namespace StudentManager.Model
|
|||||||
questionDatas = QuestionLib.GetAllQuestion();
|
questionDatas = QuestionLib.GetAllQuestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveAll()
|
|
||||||
{
|
|
||||||
StudentLib.Save();
|
|
||||||
QuestionLib.Save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user