refactor: write shit and has bugs

This commit is contained in:
2025-09-05 13:32:42 +08:00
parent ff5dc9b22b
commit 7470bc58b3
15 changed files with 272 additions and 164 deletions

View File

@ -7,7 +7,8 @@
xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance userdata:Course}"
Title="编辑课程" Height="500" Width="600" WindowStyle="ToolWindow">
x:Name="uiMainWindow"
Title="编辑课程" Height="500" Width="600" WindowStyle="ToolWindow" Loaded="uiMainWindow_Loaded" Closed="uiMainWindow_Closed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
@ -21,16 +22,16 @@
<ScrollViewer>
<StackPanel Orientation="Vertical" Margin="10,0,10,0">
<TextBlock Text="课程名称" FontWeight="Bold" Margin="0,10,0,0"/>
<TextBox Text="{Binding Name, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0"/>
<TextBox Text="{Binding Name, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
<TextBlock Text="课程颜色" FontWeight="Bold" Padding="5" Margin="0,10,0,0"/>
<Border ToolTip="单击改变颜色" Width="200" HorizontalAlignment="Left" BorderBrush="Black" BorderThickness="1" Cursor="Hand" Margin="0,5,0,0">
<Border.Background>
<SolidColorBrush Color="{Binding Color.Background, Mode=TwoWay}"/>
<SolidColorBrush Color="{Binding Background, Mode=TwoWay}"/>
</Border.Background>
<TextBlock Text="示例颜色" Margin="5">
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding Color.Foreground, Mode=TwoWay}"/>
<SolidColorBrush Color="{Binding Foreground, Mode=TwoWay}"/>
</TextBlock.Foreground>
</TextBlock>
</Border>
@ -41,7 +42,46 @@
</ScrollViewer>
</TabItem>
<TabItem Header="课程安排" Padding="5">
<ListBox x:Name="uiSchedulesList" ItemsSource="{Binding Schedules, Mode=OneWay}" Margin="10" MouseDoubleClick="uiSchedulesList_MouseDoubleClick">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid d:DataContext="{d:DesignInstance userdata:Schedule}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="#607D8B" BorderBrush="Black" BorderThickness="1" CornerRadius="2" Margin="5" VerticalAlignment="Top">
<TextBlock Text="排" Foreground="White" Margin="5"/>
</Border>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="周次:" Grid.Column="0" Grid.Row="0" FontWeight="Bold"/>
<TextBlock Text="星期:" Grid.Column="0" Grid.Row="1" FontWeight="Bold"/>
<TextBlock Text="节次:" Grid.Column="0" Grid.Row="2" FontWeight="Bold"/>
<TextBlock Text="{Binding Week, Mode=OneWay}" Grid.Column="1" Grid.Row="0"/>
<TextBlock Text="{Binding Day, Mode=OneWay}" Grid.Column="1" Grid.Row="1"/>
<TextBlock Text="{Binding Index, Mode=OneWay}" Grid.Column="1" Grid.Row="2"/>
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem x:Name="uiCtxMenuNewSchedule" Header="插入新安排" Click="uiCtxMenuNewSchedule_Click"/>
<MenuItem x:Name="uiCtxMenuEditSchedule" Header="编辑选中" Click="uiCtxMenuEditSchedule_Click"/>
<MenuItem x:Name="uiCtxMenuDeleteSchedule" Header="删除选中" Click="uiCtxMenuDeleteSchedule_Click"/>
<MenuItem x:Name="uiCtxMenuClearSchedule" Header="清空全部" Click="uiCtxMenuClearSchedule_Click"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
</TabItem>
</TabControl>

View File

@ -19,7 +19,72 @@ namespace HFUTCourseSimulation.Dialog {
public partial class EditCourse : Window {
public EditCourse() {
InitializeComponent();
this.DataContext = Kernel.Context.Instance.currentCourse;
}
public Kernel.UserData.Course CurrentCourse { get; set; }
private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) {
this.DataContext = CurrentCourse;
}
private void uiMainWindow_Closed(object sender, EventArgs e) {
this.DataContext = null;
}
private void uiSchedulesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
// It just an alias to edit
uiCtxMenuEditSchedule_Click(sender, e);
}
private void uiCtxMenuNewSchedule_Click(object sender, RoutedEventArgs e) {
// Create new item and order user edit it
var item = new Kernel.UserData.Schedule();
var dialog = new EditSchedule();
dialog.CurrentSchedule = item;
dialog.ShowDialog();
// Then insert or append it into list
var idx = uiSchedulesList.SelectedIndex;
if (idx < 0) {
// No selection, append.
CurrentCourse.Schedules.Add(item);
} else {
// Has selection, insert
CurrentCourse.Schedules.Insert(idx, item);
}
}
private void uiCtxMenuEditSchedule_Click(object sender, RoutedEventArgs e) {
var idx = uiSchedulesList.SelectedIndex;
if (idx < 0) return;
var dialog = new EditSchedule();
dialog.CurrentSchedule = CurrentCourse.Schedules[idx];
dialog.ShowDialog();
}
private void uiCtxMenuDeleteSchedule_Click(object sender, RoutedEventArgs e) {
// Check whether there is item can be deleted
var idx = uiSchedulesList.SelectedIndex;
if (idx < 0) return;
// Order a confirm
var rv = Util.Win32Dialog.Confirm("确认删除选中的课程安排吗?该操作不可撤销!", "确认删除");
if (!rv) return;
// Remove it
CurrentCourse.Schedules.RemoveAt(idx);
}
private void uiCtxMenuClearSchedule_Click(object sender, RoutedEventArgs e) {
// Order a confirm
var rv = Util.Win32Dialog.Confirm("确认删除所有课程安排吗?该操作不可撤销!", "确认清空");
if (!rv) return;
// Clear all schedules
CurrentCourse.Schedules.Clear();
}
}
}

View File

@ -7,7 +7,8 @@
xmlns:userdata="clr-namespace:HFUTCourseSimulation.Kernel.UserData"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance userdata:Schedule}"
Title="编辑课程安排" Height="450" Width="600" WindowStyle="ToolWindow">
x:Name="uiMainWindow"
Title="编辑课程安排" Height="450" Width="600" WindowStyle="ToolWindow" Loaded="uiMainWindow_Loaded" Closed="uiMainWindow_Closed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>

View File

@ -19,9 +19,17 @@ namespace HFUTCourseSimulation.Dialog {
public partial class EditSchedule : Window {
public EditSchedule() {
InitializeComponent();
this.DataContext = Kernel.Context.Instance.currentSchedule;
}
public Kernel.UserData.Schedule CurrentSchedule { get; set; }
private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) {
this.DataContext = CurrentSchedule;
}
private void uiMainWindow_Closed(object sender, EventArgs e) {
this.DataContext = null;
}
}
}

View File

@ -83,7 +83,6 @@
</Compile>
<Compile Include="General.cs" />
<Compile Include="ImageExport.cs" />
<Compile Include="Kernel\Context.cs" />
<Compile Include="Kernel\MsgRecorder.cs" />
<Compile Include="Kernel\OldUserData\V1.cs" />
<Compile Include="Kernel\SimData.cs" />

View File

@ -89,7 +89,7 @@ namespace HFUTCourseSimulation {
var cellx = courses.Start.week - 1;
var celly = courses.Start.index - 1;
//background
cellBrush = new SolidBrush(Util.ColorTrans.ToWpfColor(courses.BkColor));
cellBrush = new SolidBrush(Util.ColorTrans.ToWinformColor(courses.BkColor));
graphics.FillRectangle(cellBrush, cellx * BodyCellWidth, celly * BodyCellHeight, BodyCellWidth, BodyCellHeight * courses.Span);
//draw text

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HFUTCourseSimulation.Kernel {
public class Context {
public static readonly Context Instance = new Context();
private Context() {
currentSemester = null;
currentCourse = null;
currentSchedule = null;
}
public UserData.Semester currentSemester;
public UserData.Course currentCourse;
public UserData.Schedule currentSchedule;
public UserData.ColorPair currentColor;
public string currentFilePath;
}
}

View File

@ -1,6 +1,4 @@
using HFUTCourseSimulation.Kernel.UserData;
using HFUTCourseSimulation.Util;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
@ -56,10 +54,8 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 {
return new UserData.Course() {
Name = Name,
Description = Description,
Color = new UserData.ColorPair() {
Foreground = System.Drawing.Color.White,
Background = ColorTrans.ToWpfColor(BkColor)
},
Foreground = Colors.Black,
Background = BkColor,
Schedules = Schedule.Select((item) => item.ToLatest()).ToList()
};
}
@ -106,7 +102,7 @@ namespace HFUTCourseSimulation.Kernel.OldUserData.V1 {
if (reader.TokenType == JsonToken.Integer) {
var argb = Convert.ToInt32(reader.Value);
// Read color and force set its Alpha to zero.
var rv = Util.ColorTrans.ToWinformColor(argb);
var rv = Util.ColorTrans.ToWpfColor(argb);
rv.A = 255;
return rv;
} else {

View File

@ -105,7 +105,7 @@ namespace HFUTCourseSimulation.Kernel.SimData {
/// <summary>
/// 课程的颜色
/// </summary>
public readonly UserData.ColorPair color;
public readonly Util.ColorPair color;
/// <summary>
/// 课程的起始节次。
/// 该类保证该值位于1到indexCount之间含首尾

View File

@ -1,11 +1,11 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using HFUTCourseSimulation.Util;
namespace HFUTCourseSimulation.Kernel.UserData {
@ -66,7 +66,9 @@ namespace HFUTCourseSimulation.Kernel.UserData {
public Course() {
Name = "";
Description = "";
Color = ColorTrans.ToStorageColor(Util.ColorPreset.MdColors.Indigo);
var color = Util.ColorPreset.MdColors.Indigo;
Foreground = color.Foreground;
Background = color.Background;
Schedules = new List<Schedule>();
}
@ -81,10 +83,17 @@ namespace HFUTCourseSimulation.Kernel.UserData {
[JsonProperty("description")]
public string Description { get; set; }
/// <summary>
/// 课程的颜色
/// 课程的前景色(文本)
/// </summary>
[JsonProperty("color")]
public ColorPair Color { get; set; }
[JsonProperty("foreground")]
[JsonConverter(typeof(CustomColorConverter))]
public Color Foreground { get; set; }
/// <summary>
/// 课程的背景色(背景)
/// </summary>
[JsonProperty("background")]
[JsonConverter(typeof(CustomColorConverter))]
public Color Background { get; set; }
/// <summary>
/// 课程的所有安排
/// </summary>
@ -116,29 +125,6 @@ namespace HFUTCourseSimulation.Kernel.UserData {
public string Index { get; set; }
}
/// <summary>
/// 存储时所用的颜色对,与辅助类里的颜色对有所区别。
/// </summary>
public class ColorPair {
public ColorPair() {
Foreground = Color.Black;
Background = Color.White;
}
/// <summary>
/// 前景色(文本的颜色)
/// </summary>
[JsonProperty("foreground")]
[JsonConverter(typeof(CustomColorConverter))]
public Color Foreground { get; set; }
/// <summary>
/// 背景色
/// </summary>
[JsonProperty("background")]
[JsonConverter(typeof(CustomColorConverter))]
public Color Background { get; set; }
}
internal class CustomDateTimeConverter : JsonConverter<DateTime> {
private static readonly string DatetimeFormat = "yyyy-MM-dd";
@ -164,14 +150,14 @@ namespace HFUTCourseSimulation.Kernel.UserData {
public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer) {
if (reader.TokenType == JsonToken.Integer) {
var argb = Convert.ToInt32(reader.Value);
return Color.FromArgb(argb);
return ColorTrans.ToWpfColor(argb);
} else {
throw new JsonSerializationException($"expect a integer but got {reader.TokenType}");
}
}
public override void WriteJson(JsonWriter writer, Color value, JsonSerializer serializer) {
writer.WriteValue(value.ToArgb());
writer.WriteValue(ColorTrans.ToInt(value));
}
}

View File

@ -62,11 +62,29 @@
</ScrollViewer>
</TabItem>
<TabItem Header="课程设置" Padding="5">
<ListBox x:Name="uiCoursesList" ItemsSource="{Binding Courses}" Margin="10" MouseDoubleClick="uiCoursesList_MouseDoubleClick">
<ListBox x:Name="uiCoursesList" ItemsSource="{Binding Courses, Mode=OneWay}" Margin="10" MouseDoubleClick="uiCoursesList_MouseDoubleClick">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid d:DataContext="{d:DesignInstance userdata:Course}">
<TextBlock Text="{Binding Name, Mode=OneWay}"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="Black" BorderThickness="1" CornerRadius="2" Margin="5" VerticalAlignment="Top">
<Border.Background>
<SolidColorBrush Color="{Binding Background, Mode=OneWay}"/>
</Border.Background>
<TextBlock Text="课" Margin="5">
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding Foreground, Mode=OneWay}"/>
</TextBlock.Foreground>
</TextBlock>
</Border>
<StackPanel Orientation="Vertical" Grid.Column="1">
<TextBlock Text="{Binding Name, Mode=OneWay}" FontWeight="Bold"/>
<TextBlock Text="这是一段注释"/>
<TextBlock Text="共计N个课程安排"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
@ -75,6 +93,7 @@
<MenuItem x:Name="uiCtxMenuNewCourse" Header="插入新课程" Click="uiCtxMenuNewCourse_Click"/>
<MenuItem x:Name="uiCtxMenuEditCourse" Header="编辑选中" Click="uiCtxMenuEditCourse_Click"/>
<MenuItem x:Name="uiCtxMenuDeleteCourse" Header="删除选中" Click="uiCtxMenuDeleteCourse_Click"/>
<MenuItem x:Name="uiCtxMenuClearCourse" Header="清空全部" Click="uiCtxMenuClearCourse_Click"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>

View File

@ -1,7 +1,9 @@
using System;
using HFUTCourseSimulation.Dialog;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@ -13,7 +15,6 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json;
namespace HFUTCourseSimulation {
/// <summary>
@ -22,20 +23,20 @@ namespace HFUTCourseSimulation {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
this.context = Kernel.Context.Instance;
UpdateUiLayout();
}
#region Context and Assistant Functions
private readonly Kernel.Context context;
private Kernel.UserData.Semester CurrentSemester { get; set; }
private string CurrentFilePath { get; set; }
/// <summary>
/// 返回当前是否有文件被加载。
/// </summary>
/// <returns></returns>
private bool IsFileLoaded() {
return !(context.currentSemester is null);
return !(CurrentSemester is null);
}
/// <summary>
@ -43,7 +44,7 @@ namespace HFUTCourseSimulation {
/// </summary>
/// <returns></returns>
private bool HasAssocFile() {
return !(context.currentFilePath is null);
return !(CurrentFilePath is null);
}
/// <summary>
@ -75,7 +76,7 @@ namespace HFUTCourseSimulation {
// Window Caption
if (isFileLoaded) {
if (hasAssocFile) {
this.Title = $"HFUT课表模拟 - {context.currentFilePath}";
this.Title = $"HFUT课表模拟 - {CurrentFilePath}";
} else {
this.Title = "HFUT课表模拟 - [未命名]";
}
@ -89,7 +90,7 @@ namespace HFUTCourseSimulation {
/// </summary>
private void UpdateDataSource() {
if (this.IsFileLoaded()) {
this.DataContext = context.currentSemester;
this.DataContext = CurrentSemester;
} else {
this.DataContext = null;
}
@ -100,8 +101,8 @@ namespace HFUTCourseSimulation {
#region Menu Handlers
private void uiMenuNew_Click(object sender, RoutedEventArgs e) {
context.currentSemester = new Kernel.UserData.Semester();
context.currentFilePath = null;
CurrentSemester = new Kernel.UserData.Semester();
CurrentFilePath = null;
UpdateUiLayout();
UpdateDataSource();
}
@ -114,8 +115,8 @@ namespace HFUTCourseSimulation {
// Try to read file.
try {
using (var fs = new StreamReader(filepath, Encoding.UTF8)) {
context.currentSemester = JsonConvert.DeserializeObject<Kernel.UserData.Semester>(fs.ReadToEnd());
context.currentFilePath = filepath;
CurrentSemester = JsonConvert.DeserializeObject<Kernel.UserData.Semester>(fs.ReadToEnd());
CurrentFilePath = filepath;
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
@ -136,8 +137,8 @@ namespace HFUTCourseSimulation {
try {
using (var fs = new StreamReader(filepath, Encoding.UTF8)) {
var obj = JsonConvert.DeserializeObject<Kernel.OldUserData.V1.Semester>(fs.ReadToEnd());
context.currentSemester = obj.ToLatest();
context.currentFilePath = filepath;
CurrentSemester = obj.ToLatest();
CurrentFilePath = filepath;
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
@ -152,16 +153,16 @@ namespace HFUTCourseSimulation {
private void uiMenuSave_Click(object sender, RoutedEventArgs e) {
// Check whether there is associated file.
// If it not, order user select one.
if (context.currentFilePath is null) {
if (CurrentFilePath is null) {
var filepath = Util.Win32Dialog.SaveSemester();
if (filepath is null) return;
context.currentFilePath = filepath;
CurrentFilePath = filepath;
}
// Try to save file
try {
using (var fs = new StreamWriter(context.currentFilePath, false, Encoding.UTF8)) {
fs.Write(JsonConvert.SerializeObject(context.currentSemester));
using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) {
fs.Write(JsonConvert.SerializeObject(CurrentSemester));
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
@ -178,12 +179,12 @@ namespace HFUTCourseSimulation {
if (filepath is null) return;
// Update it to current path for following editing.
context.currentFilePath = filepath;
CurrentFilePath = filepath;
// Try to save file
try {
using (var fs = new StreamWriter(context.currentFilePath, false, Encoding.UTF8)) {
fs.Write(JsonConvert.SerializeObject(context.currentSemester));
using (var fs = new StreamWriter(CurrentFilePath, false, Encoding.UTF8)) {
fs.Write(JsonConvert.SerializeObject(CurrentSemester));
}
} catch (Exception ex) {
Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
@ -200,8 +201,8 @@ namespace HFUTCourseSimulation {
if (!rv) return;
// Clear semester and assoc file
context.currentSemester = null;
context.currentFilePath = null;
CurrentSemester = null;
CurrentFilePath = null;
// Update UI and data source
UpdateUiLayout();
@ -260,25 +261,57 @@ namespace HFUTCourseSimulation {
#region Main Area Handlers
private void uiCoursesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
//if (this.uiCoursesList.SelectedIndex < 0) {
// MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
// return;
//}
//General.CourseCache = General.GeneralSheet.Courses[uiCoursesList.SelectedIndex].Clone();
//SyncCourseData();
// It just an alias to edit
uiCtxMenuEditCourse_Click(sender, e);
}
private void uiCtxMenuNewCourse_Click(object sender, RoutedEventArgs e) {
// Create new item and order user edit it
var item = new Kernel.UserData.Course();
var dialog = new Dialog.EditCourse();
dialog.CurrentCourse = item;
dialog.ShowDialog();
// Then insert or append it into list
var idx = uiCoursesList.SelectedIndex;
if (idx < 0) {
// No selection, append.
CurrentSemester.Courses.Add(item);
} else {
// Has selection, insert
CurrentSemester.Courses.Insert(idx, item);
}
}
private void uiCtxMenuEditCourse_Click(object sender, RoutedEventArgs e) {
var idx = uiCoursesList.SelectedIndex;
if (idx < 0) return;
var dialog = new Dialog.EditCourse();
dialog.CurrentCourse = CurrentSemester.Courses[idx];
dialog.ShowDialog();
}
private void uiCtxMenuDeleteCourse_Click(object sender, RoutedEventArgs e) {
// Check whether there is item can be deleted
var idx = uiCoursesList.SelectedIndex;
if (idx < 0) return;
// Order a confirm
var rv = Util.Win32Dialog.Confirm("确认删除选中的课程吗?该操作不可撤销!", "确认删除");
if (!rv) return;
// Remove it
CurrentSemester.Courses.RemoveAt(idx);
}
private void uiCtxMenuClearCourse_Click(object sender, RoutedEventArgs e) {
// Order a confirm
var rv = Util.Win32Dialog.Confirm("确认删除所有课程吗?该操作不可撤销!", "确认清空");
if (!rv) return;
// Clear all schedules
CurrentSemester.Courses.Clear();
}
#endregion

View File

@ -37,7 +37,7 @@ namespace HFUTCourseSimulation {
if (this.itemDict.Keys.Contains(vectorCache)) {
ErrorList.Add($"课程冲突:无法将{item.Name}安排到 {weekItem}周,星期{dayItem},第{indexItem}节。因为此处已被{itemDict[vectorCache].Name}占据");
} else {
itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWinformColor(item.BkColor) });
itemDict.Add(vectorCache, new SimulationItem() { Name = item.Name, Desc = item.Description, BkColor = Util.ColorTrans.ToWpfColor(item.BkColor) });
}
}
}

View File

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace HFUTCourseSimulation.Util {
@ -32,28 +32,28 @@ namespace HFUTCourseSimulation.Util {
/// Material Design颜色合集
/// </summary>
public static class MdColors {
private static Color LightText => Color.White;
private static Color DarkText => Color.FromArgb(33, 33, 33);
private static Color LightText => Colors.White;
private static Color DarkText => Color.FromRgb(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));
public static ColorPair Red => new ColorPair(LightText, Color.FromRgb(244, 67, 54));
public static ColorPair Pink => new ColorPair(LightText, Color.FromRgb(233, 30, 99));
public static ColorPair Purple => new ColorPair(LightText, Color.FromRgb(156, 39, 176));
public static ColorPair DeepPurple => new ColorPair(LightText, Color.FromRgb(103, 58, 183));
public static ColorPair Indigo => new ColorPair(LightText, Color.FromRgb(63, 81, 181));
public static ColorPair Blue => new ColorPair(LightText, Color.FromRgb(33, 150, 243));
public static ColorPair LightBlue => new ColorPair(LightText, Color.FromRgb(3, 169, 244));
public static ColorPair Cyan => new ColorPair(LightText, Color.FromRgb(0, 188, 212));
public static ColorPair Teal => new ColorPair(LightText, Color.FromRgb(0, 150, 136));
public static ColorPair Green => new ColorPair(LightText, Color.FromRgb(76, 175, 80));
public static ColorPair LightGreen => new ColorPair(DarkText, Color.FromRgb(139, 195, 74));
public static ColorPair Lime => new ColorPair(DarkText, Color.FromRgb(205, 220, 57));
public static ColorPair Yellow => new ColorPair(DarkText, Color.FromRgb(255, 235, 59));
public static ColorPair Amber => new ColorPair(DarkText, Color.FromRgb(255, 193, 7));
public static ColorPair Orange => new ColorPair(DarkText, Color.FromRgb(255, 152, 0));
public static ColorPair DeepOrange => new ColorPair(LightText, Color.FromRgb(255, 87, 34));
public static ColorPair Brown => new ColorPair(LightText, Color.FromRgb(121, 85, 72));
public static ColorPair Grey => new ColorPair(DarkText, Color.FromRgb(158, 158, 158));
public static ColorPair BlueGrey => new ColorPair(LightText, Color.FromRgb(96, 125, 139));
}
}

View File

@ -4,11 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinformColor = System.Windows.Media.Color;
using WpfColor = System.Drawing.Color;
using StorageColorPair = HFUTCourseSimulation.Kernel.UserData.ColorPair;
using RuntimeColorPair = HFUTCourseSimulation.Util.ColorPair;
using WpfColor = System.Windows.Media.Color;
using WinformColor = System.Drawing.Color;
namespace HFUTCourseSimulation.Util {
@ -16,32 +13,32 @@ namespace HFUTCourseSimulation.Util {
#region Color Transform
public static WpfColor ToWpfColor(int argb) {
return WpfColor.FromArgb(argb);
}
public static WpfColor ToWpfColor(WinformColor c) {
return WpfColor.FromArgb(c.A, c.R, c.G, c.B);
}
public static WinformColor ToWinformColor(int _argb) {
var argb = (uint)_argb;
var a = (argb & 0xff000000) >> 24;
var r = (argb & 0x00ff0000) >> 16;
var g = (argb & 0x0000ff00) >> 8;
var b = (argb & 0x000000ff);
return WinformColor.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
public static WinformColor ToWinformColor(int argb) {
return WinformColor.FromArgb(argb);
}
public static WinformColor ToWinformColor(WpfColor c) {
return WinformColor.FromArgb(c.A, c.R, c.G, c.B);
}
public static int ToInt(WpfColor c) {
return c.ToArgb();
public static WpfColor ToWpfColor(int _argb) {
var argb = (uint)_argb;
var a = (argb & 0xff000000) >> 24;
var r = (argb & 0x00ff0000) >> 16;
var g = (argb & 0x0000ff00) >> 8;
var b = (argb & 0x000000ff);
return WpfColor.FromArgb((byte)a, (byte)r, (byte)g, (byte)b);
}
public static WpfColor ToWpfColor(WinformColor c) {
return WpfColor.FromArgb(c.A, c.R, c.G, c.B);
}
public static int ToInt(WinformColor c) {
return c.ToArgb();
}
public static int ToInt(WpfColor c) {
uint argb = 0;
argb |= c.A; argb <<= 8;
argb |= c.R; argb <<= 8;
@ -52,17 +49,5 @@ namespace HFUTCourseSimulation.Util {
#endregion
#region Color Pair Transform
public static StorageColorPair ToStorageColor(RuntimeColorPair cp) {
return new StorageColorPair() { Foreground = cp.Foreground, Background = cp.Background };
}
public static RuntimeColorPair ToRuntimeColor(StorageColorPair cp) {
return new RuntimeColorPair(cp.Foreground, cp.Background);
}
#endregion
}
}