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 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HFUTCourseSimulation/MainWindow.xaml.cs b/HFUTCourseSimulation/MainWindow.xaml.cs
index 115a6bd..b4e0a1a 100644
--- a/HFUTCourseSimulation/MainWindow.xaml.cs
+++ b/HFUTCourseSimulation/MainWindow.xaml.cs
@@ -22,134 +22,186 @@ namespace HFUTCourseSimulation {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
- UpdateUI();
+ this.context = Kernel.Context.Instance;
+ UpdateUiLayout();
}
- bool isUpdatingData = false;
+ #region Context and Assistant Functions
- void UpdateUI() {
- if (General.FilePath == "") {
- //no file
- uiMenuNew.IsEnabled = true;
- uiMenuOpen.IsEnabled = true;
- uiMenuSave.IsEnabled = false;
- uiMenuClose.IsEnabled = false;
- uiMenuSimulator.IsEnabled = false;
- uiMenuRender.IsEnabled = false;
+ private readonly Kernel.Context context;
- uiMainTab.Visibility = Visibility.Collapsed;
- /*
- uiCourseBtnAdd.IsEnabled = false;
- uiCourseBtnDelete.IsEnabled = false;
- uiCourseBtnUpdate.IsEnabled = false;
+ ///
+ /// 返回当前是否有文件被加载。
+ ///
+ ///
+ private bool IsFileLoaded() {
+ return !(context.currentSemester is null);
+ }
- uiScheduleBtnAdd.IsEnabled = false;
- uiScheduleBtnDelete.IsEnabled = false;
- uiScheduleBtnUpdate.IsEnabled = false;
+ ///
+ /// 检查当前加载的文件是否是关联到某个本地文件上的。
+ ///
+ ///
+ private bool HasAssocFile() {
+ return !(context.currentFilePath is null);
+ }
- uiScheduleIndex.IsEnabled = false;
- uiScheduleWeek.IsEnabled = false;
- uiScheduleDay.IsEnabled = false;
+ ///
+ /// 更新整个界面的UI状态(包括启用与否等)
+ ///
+ ///
+ private void UpdateUiLayout() {
+ bool isFileLoaded = this.IsFileLoaded();
+ bool hasAssocFile = this.HasAssocFile();
- uiCourseName.IsEnabled = false;
- uiCourseDescription.IsEnabled = false;
+ // Menus
+ uiMenuNew.IsEnabled = !isFileLoaded;
+ uiMenuOpen.IsEnabled = !isFileLoaded;
+ uiMenuOpenOld.IsEnabled = !isFileLoaded;
+ uiMenuOpenV1.IsEnabled = uiMenuOpenOld.IsEnabled;
- uiStartDate.IsEnabled = false;
- uiWeekCount.IsEnabled = false;
+ uiMenuSave.IsEnabled = isFileLoaded;
+ uiMenuSaveAs.IsEnabled = isFileLoaded;
- uiCoursesList.IsEnabled = false;
- uiScheduleList.IsEnabled = false;
- */
+ uiMenuClose.IsEnabled = isFileLoaded;
+ uiMenuQuit.IsEnabled = true;
+
+ uiMenuSimulator.IsEnabled = isFileLoaded;
+ uiMenuRender.IsEnabled = isFileLoaded;
+
+ // Main Area
+ uiMainTab.Visibility = isFileLoaded ? Visibility.Visible : Visibility.Collapsed;
+
+ // Window Caption
+ if (isFileLoaded) {
+ if (hasAssocFile) {
+ this.Title = $"HFUT课表模拟 - {context.currentFilePath}";
+ } else {
+ this.Title = "HFUT课表模拟 - [未命名]";
+ }
} else {
- //no file
- uiMenuNew.IsEnabled = false;
- uiMenuOpen.IsEnabled = false;
- uiMenuSave.IsEnabled = true;
- uiMenuClose.IsEnabled = true;
- uiMenuSimulator.IsEnabled = true;
- uiMenuRender.IsEnabled = true;
-
- uiMainTab.Visibility = Visibility.Visible;
- /*
- uiCourseBtnAdd.IsEnabled = true;
- uiCourseBtnDelete.IsEnabled = true;
- uiCourseBtnUpdate.IsEnabled = true;
-
- uiScheduleBtnAdd.IsEnabled = true;
- uiScheduleBtnDelete.IsEnabled = true;
- uiScheduleBtnUpdate.IsEnabled = true;
-
- uiScheduleIndex.IsEnabled = true;
- uiScheduleWeek.IsEnabled = true;
- uiScheduleDay.IsEnabled = true;
-
- uiCourseName.IsEnabled = true;
- uiCourseDescription.IsEnabled = true;
-
- uiStartDate.IsEnabled = true;
- uiWeekCount.IsEnabled = true;
-
- uiCoursesList.IsEnabled = true;
- uiScheduleList.IsEnabled = true;
- */
+ this.Title = "HFUT课表模拟";
}
}
+ ///
+ /// 更新界面的数据源
+ ///
+ private void UpdateDataSource() {
+ if (this.IsFileLoaded()) {
+ this.DataContext = context.currentSemester;
+ } else {
+ this.DataContext = null;
+ }
+ }
+
+ #endregion
+
+ #region Menu Handlers
- #region menu
private void uiMenuNew_Click(object sender, RoutedEventArgs e) {
- var sp = new Microsoft.Win32.SaveFileDialog();
- sp.RestoreDirectory = true;
- sp.Filter = "学期课程存档文件(*.json)|*.json|所有文件(*.*)|*.*";
- var status = sp.ShowDialog();
- if (!(status.HasValue && status.Value)) return;
- var getFile = sp.FileName;
-
- General.FilePath = getFile;
-
- General.GeneralSheet = new Semester();
- UpdateUI();
- SyncMainData();
+ context.currentSemester = new Kernel.UserData.Semester();
+ context.currentFilePath = null;
+ UpdateUiLayout();
+ UpdateDataSource();
}
private void uiMenuOpen_Click(object sender, RoutedEventArgs e) {
- Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();
- op.RestoreDirectory = true;
- op.Multiselect = false;
- op.Filter = "学期课程存档文件(*.json)|*.json|所有文件(*.*)|*.*";
- var status = op.ShowDialog();
- if (!(status.HasValue && status.Value)) return;
- var getFile = op.FileName;
+ // Fetch file path.
+ var filepath = Util.Win32Dialog.OpenSemester();
+ if (filepath is null) return;
- if (!File.Exists(getFile)) {
- MessageBox.Show("文件不存在", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
+ // Try to read file.
+ try {
+ using (var fs = new StreamReader(filepath, Encoding.UTF8)) {
+ context.currentSemester = JsonConvert.DeserializeObject(fs.ReadToEnd());
+ context.currentFilePath = filepath;
+ }
+ } catch (Exception ex) {
+ Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
return;
}
- General.FilePath = getFile;
+ // Update UI and data source
+ UpdateUiLayout();
+ UpdateDataSource();
+ }
- var fs = new StreamReader(getFile, Encoding.UTF8);
- General.GeneralSheet = JsonConvert.DeserializeObject(fs.ReadToEnd());
- fs.Close();
- fs.Dispose();
+ private void uiMenuOpenV1_Click(object sender, RoutedEventArgs e) {
- UpdateUI();
- SyncMainData();
+ // Update UI and data source
+ UpdateUiLayout();
+ UpdateDataSource();
}
private void uiMenuSave_Click(object sender, RoutedEventArgs e) {
- var fs = new StreamWriter(General.FilePath, false, Encoding.UTF8);
- fs.Write(JsonConvert.SerializeObject(General.GeneralSheet));
- fs.Close();
- fs.Dispose();
+ // Check whether there is associated file.
+ // If it not, order user select one.
+ if (context.currentFilePath is null) {
+ var filepath = Util.Win32Dialog.SaveSemester();
+ if (filepath is null) return;
+ context.currentFilePath = filepath;
+ }
+
+ // Try to save file
+ try {
+ using (var fs = new StreamWriter(context.currentFilePath, false, Encoding.UTF8)) {
+ fs.Write(JsonConvert.SerializeObject(context.currentSemester));
+ }
+ } catch (Exception ex) {
+ Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
+ return;
+ }
+
+ // Update UI
+ UpdateUiLayout();
+ }
+
+ private void uiMenuSaveAs_Click(object sender, RoutedEventArgs e) {
+ // Always order user give a path
+ var filepath = Util.Win32Dialog.SaveSemester();
+ if (filepath is null) return;
+
+ // Update it to current path for following editing.
+ context.currentFilePath = filepath;
+
+ // Try to save file
+ try {
+ using (var fs = new StreamWriter(context.currentFilePath, false, Encoding.UTF8)) {
+ fs.Write(JsonConvert.SerializeObject(context.currentSemester));
+ }
+ } catch (Exception ex) {
+ Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
+ return;
+ }
+
+ // Update UI
+ UpdateUiLayout();
}
private void uiMenuClose_Click(object sender, RoutedEventArgs e) {
- //save
- this.uiMenuSave_Click(sender, e);
+ // Confirm close
+ var rv = Util.Win32Dialog.Confirm("确认关闭吗?所有未保存的更改都将永久丢失!", "确认关闭");
+ if (!rv) return;
- General.FilePath = "";
- UpdateUI();
+ // Clear semester and assoc file
+ context.currentSemester = null;
+ context.currentFilePath = null;
+
+ // Update UI and data source
+ UpdateUiLayout();
+ UpdateDataSource();
+ }
+
+ private void uiMenuQuit_Click(object sender, RoutedEventArgs e) {
+ // If there is an opened document, let we confirm it first
+ if (IsFileLoaded()) {
+ var rv = Util.Win32Dialog.Confirm("确认退出吗?所有未保存的更改都将永久丢失!", "确认退出");
+ if (!rv) return;
+ }
+
+ // Close window
+ this.Close();
}
private void uiMenuSimulator_Click(object sender, RoutedEventArgs e) {
@@ -176,7 +228,7 @@ namespace HFUTCourseSimulation {
var status = sp.ShowDialog();
if (!(status.HasValue && status.Value)) return;
var getFile = sp.FileName;
-
+
//export
var res = ImageExport.Export(originDate, weekCount, getFile);
if (!res) MessageBox.Show("当前课程安排存在冲突,请通过实时预览消除所有错误后才能使用此功能来导出为图片", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
@@ -188,211 +240,32 @@ namespace HFUTCourseSimulation {
"本程序旨在为各位选课的同学提供一个用于查验课程冲突以及查看课表的功能。如果您想参与开发,提交PullRequest即可,欢迎您的加入。", "关于", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}
- void SyncMainData() {
- isUpdatingData = true;
- this.uiStartDate.SelectedDate = DateTime.Parse(General.GeneralSheet.StartDate);
- this.uiWeekCount.Text = General.GeneralSheet.WeekCount.ToString();
-
- SyncCourseListData();
- isUpdatingData = false;
- }
-
-
#endregion
- #region course
- private void uiCourseBtnAdd_Click(object sender, RoutedEventArgs e) {
- if (this.uiCourseName.Text == "") {
- MessageBox.Show("课程名不得为空", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
+ #region Main Area Handlers
- General.GeneralSheet.Courses.Add(General.CourseCache.Clone());
- SyncCourseListData();
- }
-
- private void uiCourseBtnUpdate_Click(object sender, RoutedEventArgs e) {
- if (this.uiCourseName.Text == "") {
- MessageBox.Show("课程名不得为空", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
- if (this.uiCoursesList.SelectedIndex < 0) {
- MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
-
- var index = this.uiCoursesList.SelectedIndex;
-
- General.GeneralSheet.Courses[index] = General.CourseCache.Clone();
- SyncCourseListData();
- }
-
- private void uiCourseBtnDelete_Click(object sender, RoutedEventArgs e) {
- if (this.uiCoursesList.SelectedIndex < 0) {
- MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
-
- General.GeneralSheet.Courses.RemoveAt(uiCoursesList.SelectedIndex);
- SyncCourseListData();
- }
-
- void SyncCourseListData() {
- this.uiCoursesList.Items.Clear();
- foreach (var item in General.GeneralSheet.Courses) {
- this.uiCoursesList.Items.Add(item.Name);
- }
- }
-
- //===========================================================get item
private void uiCoursesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
- if (this.uiCoursesList.SelectedIndex < 0) {
- MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
+ //if (this.uiCoursesList.SelectedIndex < 0) {
+ // MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
+ // return;
+ //}
- General.CourseCache = General.GeneralSheet.Courses[uiCoursesList.SelectedIndex].Clone();
- SyncCourseData();
+ //General.CourseCache = General.GeneralSheet.Courses[uiCoursesList.SelectedIndex].Clone();
+ //SyncCourseData();
}
- void SyncCourseData() {
- isUpdatingData = true;
-
- this.uiCourseName.Text = General.CourseCache.Name;
- this.uiCourseDescription.Text = General.CourseCache.Description;
- this.uiCourseColor.Background = new SolidColorBrush(General.CourseCache.BkColor.IntToColor());
-
- SyncScheduleListData();
-
- isUpdatingData = false;
+ private void uiCtxMenuNewCourse_Click(object sender, RoutedEventArgs e) {
}
- #endregion
+ private void uiCtxMenuEditCourse_Click(object sender, RoutedEventArgs e) {
- #region schedule
-
- void SyncScheduleListData() {
- this.uiScheduleList.Items.Clear();
- foreach (var item in General.CourseCache.Schedule) {
- uiScheduleList.Items.Add(item.ToString());
- }
}
- void SyncScheduleData() {
- isUpdatingData = true;
- this.uiScheduleIndex.Text = General.ScheduleCache.Index;
- this.uiScheduleWeek.Text = General.ScheduleCache.Week;
- this.uiScheduleDay.Text = General.ScheduleCache.Day;
- isUpdatingData = false;
+ private void uiCtxMenuDeleteCourse_Click(object sender, RoutedEventArgs e) {
+
}
- private void uiScheduleBtnAdd_Click(object sender, RoutedEventArgs e) {
- if (this.uiScheduleIndex.Text == "" || this.uiScheduleWeek.Text == "") {
- MessageBox.Show("数据不得为空", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
-
- General.CourseCache.Schedule.Add(General.ScheduleCache.Clone());
- SyncScheduleListData();
- }
-
- private void uiScheduleBtnUpdate_Click(object sender, RoutedEventArgs e) {
- if (this.uiScheduleIndex.Text == "" || this.uiScheduleWeek.Text == "") {
- MessageBox.Show("数据不得为空", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
- if (this.uiScheduleList.SelectedIndex < 0) {
- MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
-
- var index = this.uiScheduleList.SelectedIndex;
-
- General.CourseCache.Schedule[index] = General.ScheduleCache.Clone();
- SyncScheduleListData();
- }
-
- private void uiScheduleBtnDelete_Click(object sender, RoutedEventArgs e) {
- if (this.uiScheduleList.SelectedIndex < 0) {
- MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
-
- General.CourseCache.Schedule.RemoveAt(this.uiScheduleList.SelectedIndex);
- SyncScheduleListData();
- }
-
-
- private void uiScheduleList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
- if (this.uiScheduleList.SelectedIndex < 0) {
- MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
- return;
- }
-
- General.ScheduleCache = General.CourseCache.Schedule[uiScheduleList.SelectedIndex].Clone();
- SyncScheduleData();
- }
-
-
- #endregion
-
- #region control change
- //schedule
-
- private void uiScheduleWeek_TextChanged(object sender, TextChangedEventArgs e) {
- if (isUpdatingData) return;
- General.ScheduleCache.Week = this.uiScheduleWeek.Text;
- }
-
- private void uiScheduleIndex_TextChanged(object sender, TextChangedEventArgs e) {
- if (isUpdatingData) return;
- General.ScheduleCache.Index = this.uiScheduleIndex.Text;
- }
-
- private void uiScheduleDay_TextChanged(object sender, TextChangedEventArgs e) {
- if (isUpdatingData) return;
- General.ScheduleCache.Day = this.uiScheduleDay.Text;
- }
-
- //course
- private void uiCourseName_TextChanged(object sender, TextChangedEventArgs e) {
- if (isUpdatingData) return;
- General.CourseCache.Name = this.uiCourseName.Text;
- }
-
- private void uiCourseDescription_TextChanged(object sender, TextChangedEventArgs e) {
- if (isUpdatingData) return;
- General.CourseCache.Description = this.uiCourseDescription.Text;
- }
-
- private void uiCourseBtnColor_Click(object sender, RoutedEventArgs e) {
- var cor = new System.Windows.Forms.ColorDialog();
- var status = cor.ShowDialog();
- if (!(status == System.Windows.Forms.DialogResult.OK)) return;
- var color = cor.Color.ConvertWinformColor();
- //force a channel
- color.A = 255;
-
- General.CourseCache.BkColor = color.ColorToInt();
- this.uiCourseColor.Background = new SolidColorBrush(color);
- }
-
- //main
- private void uiStartDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e) {
- if (isUpdatingData) return;
- General.GeneralSheet.StartDate = this.uiStartDate.SelectedDate.ToString();
- }
-
- private void uiWeekCount_TextChanged(object sender, TextChangedEventArgs e) {
- if (isUpdatingData) return;
- int res;
- var tryres = int.TryParse(this.uiWeekCount.Text, out res);
- if (tryres) General.GeneralSheet.WeekCount = res;
- else General.GeneralSheet.WeekCount = 1;
- }
-
-
#endregion
}
diff --git a/HFUTCourseSimulation/Util/ColorPreset.cs b/HFUTCourseSimulation/Util/ColorPreset.cs
new file mode 100644
index 0000000..9fe3b5d
--- /dev/null
+++ b/HFUTCourseSimulation/Util/ColorPreset.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+using HFUTCourseSimulation.Kernel.UserData;
+
+namespace HFUTCourseSimulation.Util.ColorPreset {
+
+ ///
+ /// Material Design颜色合集
+ ///
+ public static class MdColors {
+ private static Color LightText => Color.White;
+ private static Color DarkText => Color.FromArgb(33, 33, 33);
+
+ public static ColorPair Red => new ColorPair(LightText, Color.FromArgb(244, 67, 54));
+ public static ColorPair Pink => new ColorPair(LightText, Color.FromArgb(233, 30, 99));
+ public static ColorPair Purple => new ColorPair(LightText, Color.FromArgb(156, 39, 176));
+ public static ColorPair DeepPurple => new ColorPair(LightText, Color.FromArgb(103, 58, 183));
+ public static ColorPair Indigo => new ColorPair(LightText, Color.FromArgb(63, 81, 181));
+ public static ColorPair Blue => new ColorPair(LightText, Color.FromArgb(33, 150, 243));
+ public static ColorPair LightBlue => new ColorPair(LightText, Color.FromArgb(3, 169, 244));
+ public static ColorPair Cyan => new ColorPair(LightText, Color.FromArgb(0, 188, 212));
+ public static ColorPair Teal => new ColorPair(LightText, Color.FromArgb(0, 150, 136));
+ public static ColorPair Green => new ColorPair(LightText, Color.FromArgb(76, 175, 80));
+ public static ColorPair LightGreen => new ColorPair(DarkText, Color.FromArgb(139, 195, 74));
+ public static ColorPair Lime => new ColorPair(DarkText, Color.FromArgb(205, 220, 57));
+ public static ColorPair Yellow => new ColorPair(DarkText, Color.FromArgb(255, 235, 59));
+ public static ColorPair Amber => new ColorPair(DarkText, Color.FromArgb(255, 193, 7));
+ public static ColorPair Orange => new ColorPair(DarkText, Color.FromArgb(255, 152, 0));
+ public static ColorPair DeepOrange => new ColorPair(LightText, Color.FromArgb(255, 87, 34));
+ public static ColorPair Brown => new ColorPair(LightText, Color.FromArgb(121, 85, 72));
+ public static ColorPair Grey => new ColorPair(DarkText, Color.FromArgb(158, 158, 158));
+ public static ColorPair BlueGrey => new ColorPair(LightText, Color.FromArgb(96, 125, 139));
+ }
+
+}
diff --git a/HFUTCourseSimulation/Util/Win32Dialog.cs b/HFUTCourseSimulation/Util/Win32Dialog.cs
new file mode 100644
index 0000000..d6972ef
--- /dev/null
+++ b/HFUTCourseSimulation/Util/Win32Dialog.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace HFUTCourseSimulation.Util {
+ public static class Win32Dialog {
+
+ ///
+ /// 打开学期存档文件
+ ///
+ /// 如果用户选定了文件,返回文件路径,否则返回null
+ public static string OpenSemester() {
+ Microsoft.Win32.OpenFileDialog op = new Microsoft.Win32.OpenFileDialog();
+ op.RestoreDirectory = true;
+ op.Multiselect = false;
+ op.Filter = "学期课程存档文件(*.json)|*.json|所有文件(*.*)|*.*";
+ var status = op.ShowDialog();
+ if (!(status.HasValue && status.Value)) return null;
+ else return op.FileName;
+ }
+
+ ///
+ /// 保存学期存档文件
+ ///
+ /// 如果用户选定了文件,返回文件路径,否则返回null
+ public static string SaveSemester() {
+ var sp = new Microsoft.Win32.SaveFileDialog();
+ sp.RestoreDirectory = true;
+ sp.Filter = "学期课程存档文件(*.json)|*.json|所有文件(*.*)|*.*";
+ var status = sp.ShowDialog();
+ if (!(status.HasValue && status.Value)) return null;
+ else return sp.FileName;
+ }
+
+ ///
+ /// 保存渲染的学期图片文件
+ ///
+ /// 如果用户选定了文件,返回文件路径,否则返回null
+ public static string SaveRender() {
+ var sp = new Microsoft.Win32.SaveFileDialog();
+ sp.RestoreDirectory = true;
+ sp.Filter = "图片文件(*.png)|*.png|所有文件(*.*)|*.*";
+ var status = sp.ShowDialog();
+ if (!(status.HasValue && status.Value)) return null;
+ else return sp.FileName;
+ }
+
+ ///
+ /// 显示一个经典的Windows错误对话框
+ ///
+ public static void Error(string message, string caption) {
+ MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
+ }
+
+ ///
+ /// 显示一个经典的Windows信息对话框
+ ///
+ public static void Info(string message, string caption) {
+ MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
+ }
+
+ ///
+ /// 显示一个经典的Windows确认操作对话框
+ ///
+ /// 如果用户点击了确认,则返回true,否则返回false
+ public static bool Confirm(string message, string caption) {
+ var rv = MessageBox.Show(message, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
+ return rv == MessageBoxResult.OK;
+ }
+
+ }
+}