diff --git a/HFUTCourseSimulation/Dialog/Simulator.xaml b/HFUTCourseSimulation/Dialog/Simulator.xaml
index efeed49..2592476 100644
--- a/HFUTCourseSimulation/Dialog/Simulator.xaml
+++ b/HFUTCourseSimulation/Dialog/Simulator.xaml
@@ -7,6 +7,19 @@
mc:Ignorable="d"
x:Name="uiMainWindow"
Title="课表模拟器" Height="500" Width="700" Closed="uiMainWindow_Closed" Loaded="uiMainWindow_Loaded">
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -19,8 +32,8 @@
-
-
+
+
diff --git a/HFUTCourseSimulation/Dialog/Simulator.xaml.cs b/HFUTCourseSimulation/Dialog/Simulator.xaml.cs
index 0a80baa..743ac7a 100644
--- a/HFUTCourseSimulation/Dialog/Simulator.xaml.cs
+++ b/HFUTCourseSimulation/Dialog/Simulator.xaml.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -168,29 +169,49 @@ namespace HFUTCourseSimulation.Dialog {
// 更新教学周序号
uiWeek.Text = currentWeek.ToString();
// 更新按钮启用情况
- uiBtnPrev.IsEnabled = currentWeek > 1;
- uiBtnNext.IsEnabled = currentWeek < CurrentSemester.weekCount;
+ uiBtnPrevWeek.IsEnabled = currentWeek > 1;
+ uiBtnNextWeek.IsEnabled = currentWeek < CurrentSemester.weekCount;
}
- private void uiBtnPrev_Click(object sender, RoutedEventArgs e) {
- if (currentWeek == 1) {
- Win32Dialog.Info("已经是第一周了", "错误");
- return;
+ private bool HasPrevWeek() {
+ return currentWeek > 1;
+ }
+
+ private void PrevWeek() {
+ if (HasPrevWeek()) {
+ currentWeek--;
+ RenderWeek();
}
-
- currentWeek--;
- RenderWeek();
}
- private void uiBtnNext_Click(object sender, RoutedEventArgs e) {
- if (currentWeek == CurrentSemester.weekCount) {
- Win32Dialog.Info("已经是最后一周了", "错误");
- return;
+ private bool HasNextWeek() {
+ return currentWeek < CurrentSemester.weekCount;
+ }
+
+ private void NextWeek() {
+ if (HasNextWeek()) {
+ currentWeek++;
+ RenderWeek();
}
-
- currentWeek++;
- RenderWeek();
}
+ #region UI and Shotcuts
+
+ private void uiBtnPrevWeek_Click(object sender, RoutedEventArgs e) {
+ PrevWeek();
+ }
+
+ private void uiBtnNextWeek_Click(object sender, RoutedEventArgs e) {
+ NextWeek();
+ }
+
+ private void commandBtnPrevWeek_Execute(object sender, ExecutedRoutedEventArgs e) => uiBtnPrevWeek_Click(sender, e);
+ private void commandBtnNextWeek_Execute(object sender, ExecutedRoutedEventArgs e) => uiBtnNextWeek_Click(sender, e);
+
+ private void commandBtnPrevWeek_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = HasPrevWeek();
+ private void commandBtnNextWeek_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = HasNextWeek();
+
+ #endregion
+
}
}
diff --git a/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs b/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs
index c225c4b..a3ee892 100644
--- a/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs
+++ b/HFUTCourseSimulation/Kernel/Data/LegacyStorage/V1.cs
@@ -40,9 +40,9 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
this.Schedule = new List();
}
- [JsonProperty("Name", Required = Required.Always)]
+ [JsonProperty("Name", Required = Required.AllowNull)]
public string Name { get; set; }
- [JsonProperty("Description", Required = Required.Always)]
+ [JsonProperty("Description", Required = Required.AllowNull)]
public string Description { get; set; }
[JsonProperty("BkColor", Required = Required.Always)]
[JsonConverter(typeof(CustomColorConverter))]
@@ -52,8 +52,8 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
public Storage.Course ToLatest() {
return new Storage.Course() {
- Name = Name,
- Description = Description,
+ Name = Name is null ? "" : Name,
+ Description = Description is null ? "" : Description,
Color = new Storage.ColorPair() {
Foreground = Colors.Black,
Background = BkColor
diff --git a/HFUTCourseSimulation/MainWindow.xaml b/HFUTCourseSimulation/MainWindow.xaml
index e2f7eeb..bf30011 100644
--- a/HFUTCourseSimulation/MainWindow.xaml
+++ b/HFUTCourseSimulation/MainWindow.xaml
@@ -19,9 +19,9 @@
-
-
-
+
+
+
diff --git a/HFUTCourseSimulation/MainWindow.xaml.cs b/HFUTCourseSimulation/MainWindow.xaml.cs
index fc8251a..f9e7618 100644
--- a/HFUTCourseSimulation/MainWindow.xaml.cs
+++ b/HFUTCourseSimulation/MainWindow.xaml.cs
@@ -140,7 +140,7 @@ namespace HFUTCourseSimulation {
_context.FilePath = filepath;
}
} catch (Exception ex) {
- Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
+ Util.Win32Dialog.Error(ex.Message, "打开文件时出错");
return;
}
@@ -164,7 +164,7 @@ namespace HFUTCourseSimulation {
_context.FilePath = filepath;
}
} catch (Exception ex) {
- Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
+ Util.Win32Dialog.Error(ex.Message, "打开文件时出错");
return;
}
@@ -191,7 +191,7 @@ namespace HFUTCourseSimulation {
fs.Write(JsonConvert.SerializeObject(_context.Semester.ToStorage()));
}
} catch (Exception ex) {
- Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
+ Util.Win32Dialog.Error(ex.Message, "保存文件时出错");
return;
}
@@ -213,7 +213,7 @@ namespace HFUTCourseSimulation {
fs.Write(JsonConvert.SerializeObject(_context.Semester.ToStorage()));
}
} catch (Exception ex) {
- Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
+ Util.Win32Dialog.Error(ex.Message, "保存文件时出错");
return;
}
@@ -289,12 +289,13 @@ namespace HFUTCourseSimulation {
#region Shortcut Handlers
- private void commandCanExec_Loaded(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnLoaded;
- private void commandCanExec_NotLoaded(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
+ private void commandMenuNew_Execute(object sender, ExecutedRoutedEventArgs e) => uiMenuNew_Click(sender, e);
+ private void commandMenuOpen_Execute(object sender, ExecutedRoutedEventArgs e) => uiMenuOpen_Click(sender, e);
+ private void commandMenuSave_Execute(object sender, ExecutedRoutedEventArgs e) => uiMenuSave_Click(sender, e);
- private void commandMenuNew_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuNew_Click(sender, e);
- private void commandMenuOpen_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuOpen_Click(sender, e);
- private void commandMenuSave_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuSave_Click(sender, e);
+ private void commandMenuNew_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
+ private void commandMenuOpen_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
+ private void commandMenuSave_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnLoaded;
#endregion