diff --git a/HFUTCourseSimulation/Dialog/EditCourse.xaml b/HFUTCourseSimulation/Dialog/EditCourse.xaml index 7728ab2..742b885 100644 --- a/HFUTCourseSimulation/Dialog/EditCourse.xaml +++ b/HFUTCourseSimulation/Dialog/EditCourse.xaml @@ -14,24 +14,29 @@ - + - + - - - - - - + + + + + + + + + + + - + diff --git a/HFUTCourseSimulation/Dialog/EditSchedule.xaml b/HFUTCourseSimulation/Dialog/EditSchedule.xaml index 24f5254..b6d2a59 100644 --- a/HFUTCourseSimulation/Dialog/EditSchedule.xaml +++ b/HFUTCourseSimulation/Dialog/EditSchedule.xaml @@ -14,24 +14,24 @@ - + - + - + - + diff --git a/HFUTCourseSimulation/HFUTCourseSimulation.csproj b/HFUTCourseSimulation/HFUTCourseSimulation.csproj index 6c0cec8..39b2f89 100644 --- a/HFUTCourseSimulation/HFUTCourseSimulation.csproj +++ b/HFUTCourseSimulation/HFUTCourseSimulation.csproj @@ -92,6 +92,8 @@ + + Designer MSBuild:Compile diff --git a/HFUTCourseSimulation/Kernel/Context.cs b/HFUTCourseSimulation/Kernel/Context.cs index 5a87d2b..720bfa5 100644 --- a/HFUTCourseSimulation/Kernel/Context.cs +++ b/HFUTCourseSimulation/Kernel/Context.cs @@ -17,7 +17,8 @@ namespace HFUTCourseSimulation.Kernel { public UserData.Semester currentSemester; public UserData.Course currentCourse; public UserData.Schedule currentSchedule; - + public UserData.ColorPair currentColor; + public string currentFilePath; } } diff --git a/HFUTCourseSimulation/Kernel/SimData.cs b/HFUTCourseSimulation/Kernel/SimData.cs index 0bccdc6..2635fb2 100644 --- a/HFUTCourseSimulation/Kernel/SimData.cs +++ b/HFUTCourseSimulation/Kernel/SimData.cs @@ -4,7 +4,6 @@ using System.Collections.Immutable; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Drawing; namespace HFUTCourseSimulation.Kernel.SimData { @@ -106,7 +105,7 @@ namespace HFUTCourseSimulation.Kernel.SimData { /// /// 课程的颜色 /// - public readonly Color color; + public readonly UserData.ColorPair color; /// /// 课程的起始节次。 /// 该类保证该值位于1到indexCount之间(含首尾)。 diff --git a/HFUTCourseSimulation/Kernel/UserData.cs b/HFUTCourseSimulation/Kernel/UserData.cs index d9a3116..147f780 100644 --- a/HFUTCourseSimulation/Kernel/UserData.cs +++ b/HFUTCourseSimulation/Kernel/UserData.cs @@ -1,11 +1,12 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; +using System.Drawing; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Drawing; -using System.Globalization; -using Newtonsoft.Json; namespace HFUTCourseSimulation.Kernel.UserData { @@ -28,44 +29,44 @@ namespace HFUTCourseSimulation.Kernel.UserData { /// [JsonProperty("start_date")] [JsonConverter(typeof(CustomDateTimeConverter))] - public DateTime startDate; + public DateTime startDate { get; set; } /// /// 教学周个数 /// [JsonProperty("week_count")] - public string weekCount; + public string weekCount { get; set; } /// /// 每天课程的节次数 /// [JsonProperty("index_count")] - public string indexCount; + public string indexCount { get; set; } /// /// 早餐插入在第几节次后 /// [JsonProperty("breakfast_at")] - public string breakfastAt; + public string breakfastAt { get; set; } /// /// 午餐插入在第几节次后 /// [JsonProperty("lunch_at")] - public string lunchAt; + public string lunchAt { get; set; } /// /// 晚餐插入在第几节次后 /// [JsonProperty("dinner_at")] - public string dinnerAt; + public string dinnerAt { get; set; } /// /// 课程列表 /// [JsonProperty("courses")] - public List courses; + public List courses { get; set; } } public class Course { public Course() { name = ""; description = ""; - color = Color.LightBlue; + color = Util.ColorPreset.MdColors.Indigo; schedules = new List(); } @@ -73,23 +74,22 @@ namespace HFUTCourseSimulation.Kernel.UserData { /// 课程的名称 /// [JsonProperty("name")] - public string name; + public string name { get; set; } /// /// 课程的说明,例如教室位置,教师姓名等。 /// [JsonProperty("description")] - public string description; + public string description { get; set; } /// /// 课程的颜色 /// [JsonProperty("color")] - [JsonConverter(typeof(CustomColorConverter))] - public Color color; + public ColorPair color { get; set; } /// /// 课程的所有安排 /// [JsonProperty("schedules")] - public List schedules; + public List schedules { get; set; } } public class Schedule { @@ -103,26 +103,49 @@ namespace HFUTCourseSimulation.Kernel.UserData { /// 安排在哪些周 /// [JsonProperty("week")] - public string week; + public string week { get; set; } /// /// 安排在周的星期几 /// [JsonProperty("day")] - public string day; + public string day { get; set; } /// /// 安排在这些日子的哪些节次 /// [JsonProperty("index")] - public string index; + public string index { get; set; } + } + + /// + /// 代表一个颜色对,包括前景色和背景色 + /// + public struct ColorPair { + public ColorPair(Color foreground, Color background) { + this.foreground = foreground; + this.background = background; + } + + /// + /// 前景色(文本的颜色) + /// + [JsonProperty("foreground")] + [JsonConverter(typeof(CustomColorConverter))] + public Color foreground { get; set; } + /// + /// 背景色 + /// + [JsonProperty("background")] + [JsonConverter(typeof(CustomColorConverter))] + public Color background { get; set; } } internal class CustomDateTimeConverter : JsonConverter { - private static readonly string DATETIME_FORMAT = "yyyy-MM-dd"; + private static readonly string DatetimeFormat = "yyyy-MM-dd"; public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.String) { var value = reader.Value as string; - if (DateTime.TryParseExact(value, DATETIME_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime rv)) { + if (DateTime.TryParseExact(value, DatetimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime rv)) { return rv; } else { throw new JsonSerializationException($"given string can not be parsed as DateTime: {value}"); @@ -133,7 +156,7 @@ namespace HFUTCourseSimulation.Kernel.UserData { } public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer) { - writer.WriteValue(value.ToString(DATETIME_FORMAT, CultureInfo.InvariantCulture)); + writer.WriteValue(value.ToString(DatetimeFormat, CultureInfo.InvariantCulture)); } } diff --git a/HFUTCourseSimulation/MainWindow.xaml b/HFUTCourseSimulation/MainWindow.xaml index 7743d9e..d0fae36 100644 --- a/HFUTCourseSimulation/MainWindow.xaml +++ b/HFUTCourseSimulation/MainWindow.xaml @@ -4,7 +4,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:HFUTCourseSimulation" + xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData" mc:Ignorable="d" + d:DataContext="{d:DesignInstance userdata:Semester}" Title="HFUT课表模拟" Height="600" Width="800"> @@ -15,17 +17,23 @@ - + + + + + + + - + @@ -37,124 +45,39 @@ - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - -