diff --git a/StudentManager/App.xaml b/StudentManager/App.xaml index c302656..f937f54 100644 --- a/StudentManager/App.xaml +++ b/StudentManager/App.xaml @@ -7,7 +7,7 @@ - + diff --git a/StudentManager/Common/SQLHelper.cs b/StudentManager/Common/SQLHelper.cs index 18a5d4d..8f2ee79 100644 --- a/StudentManager/Common/SQLHelper.cs +++ b/StudentManager/Common/SQLHelper.cs @@ -352,5 +352,39 @@ namespace StudentManager.Common } } } + + internal static void 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(); + } + + } + catch (Exception ex) + { + + } + finally + { + connection.Close(); + } + } + } } } diff --git a/StudentManager/Data/CursonQuestionsData.cs b/StudentManager/Data/CursonQuestionsData.cs index 4535d8f..05e2890 100644 --- a/StudentManager/Data/CursonQuestionsData.cs +++ b/StudentManager/Data/CursonQuestionsData.cs @@ -8,7 +8,7 @@ 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; diff --git a/StudentManager/Data/StudentInfo.cs b/StudentManager/Data/StudentInfo.cs index 3ba2bd2..b3cff21 100644 --- a/StudentManager/Data/StudentInfo.cs +++ b/StudentManager/Data/StudentInfo.cs @@ -147,6 +147,23 @@ namespace StudentManager.Data HomeWorkSet.AddHomeWork(homeWork); + 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; + + + SQLHelper.AddHomework(cqd); } } } diff --git a/StudentManager/Editor/AddHomeWork.xaml b/StudentManager/Editor/AddHomeWork.xaml index 5ed1b0e..f8d768e 100644 --- a/StudentManager/Editor/AddHomeWork.xaml +++ b/StudentManager/Editor/AddHomeWork.xaml @@ -20,23 +20,44 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + - + - - + + + + + @@ -44,8 +65,35 @@ - - + + + + + + + + + + + + + + + + + + @@ -54,7 +102,7 @@ -