First commit

This commit is contained in:
2018-12-22 23:44:18 +08:00
commit 2da0eb3bd1
20 changed files with 1578 additions and 0 deletions

223
.gitignore vendored Normal file
View File

@ -0,0 +1,223 @@
## Ignore Visual Studio build files, cache files, and rubbish files.
## This .gitignore file only use in this project(bus_rode).
# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
*.dat
*.db
## ------------------------Visual Studio normal settings---------------------------------------
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Visual Studio 2015 cache/options directory
.vs/
# Build result
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
## TODO: Comment the next line if you want to checkin your
## web deploy settings but do note that will include unencrypted
## passwords
#*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

25
HFUTCourseSimulation.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2047
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HFUTCourseSimulation", "HFUTCourseSimulation\HFUTCourseSimulation.csproj", "{25CF9351-6A95-48AC-89D1-B3700593ADE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{25CF9351-6A95-48AC-89D1-B3700593ADE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25CF9351-6A95-48AC-89D1-B3700593ADE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25CF9351-6A95-48AC-89D1-B3700593ADE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25CF9351-6A95-48AC-89D1-B3700593ADE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {20F50CFE-0517-4471-BB0D-64563A817585}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

View File

@ -0,0 +1,9 @@
<Application x:Class="HFUTCourseSimulation.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:HFUTCourseSimulation"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace HFUTCourseSimulation {
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application {
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HFUTCourseSimulation {
public class Semester {
public Semester() {
this.Courses = new List<CourseItem>();
StartDate = DateTime.Today.ToString();
WeekCount = 1;
}
public string StartDate { get; set; }
public int WeekCount { get; set; }
public List<CourseItem> Courses { get; set; }
}
public class CourseItem {
public CourseItem() {
this.Schedule = new List<ScheduleItem>();
}
public string Name { get; set; }
public string Description { get; set; }
public List<ScheduleItem> Schedule { get; set; }
public CourseItem Clone() {
var newobj = new CourseItem();
newobj.Name = this.Name;
newobj.Description = this.Description;
newobj.Schedule = new List<ScheduleItem>();
newobj.Schedule.AddRange((from item in this.Schedule select item.Clone()));
return newobj;
}
}
public class ScheduleItem {
public string Week { get; set; }
public string Day { get; set; }
public string Index { get; set; }
public ScheduleItem Clone() {
return new ScheduleItem() { Week = this.Week, Index = this.Index, Day = this.Day };
}
public override string ToString() {
return Week + " - " + Day + " - " + Index;
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HFUTCourseSimulation {
public static class General {
public static Semester GeneralSheet;
public static CourseItem CourseCache = new CourseItem();
public static ScheduleItem ScheduleCache = new ScheduleItem();
public static string FilePath = "";
}
}

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{25CF9351-6A95-48AC-89D1-B3700593ADE4}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>HFUTCourseSimulation</RootNamespace>
<AssemblyName>HFUTCourseSimulation</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
<Compile Include="Course.cs" />
<Compile Include="General.cs" />
<Compile Include="Simulation.xaml.cs">
<DependentUpon>Simulation.xaml</DependentUpon>
</Compile>
<Compile Include="SimulationItem.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Simulation.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,134 @@
<Window x:Class="HFUTCourseSimulation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HFUTCourseSimulation"
mc:Ignorable="d"
Title="HFUT课表模拟" Height="450" Width="800">
<Grid>
<Menu IsMainMenu="True">
<MenuItem Header="文件">
<MenuItem x:Name="uiMenuNew" Header="新建" Click="uiMenuNew_Click" />
<MenuItem x:Name="uiMenuOpen" Header="打开" Click="uiMenuOpen_Click" />
<MenuItem x:Name="uiMenuSave" Header="保存" Click="uiMenuSave_Click"/>
<MenuItem x:Name="uiMenuClose" Header="关闭" Click="uiMenuClose_Click"/>
</MenuItem>
<MenuItem x:Name="uiMenuSimulation" Header="模拟" Click="uiMenuSimulation_Click"/>
<MenuItem x:Name="uiMenuAbout" Header="关于" Click="uiMenuAbout_Click"/>
</Menu>
<TabControl Margin="0,20,0,0">
<TabItem Header="通用设置">
<StackPanel Orientation="Vertical">
<TextBlock Text="起始周日期(教学第一周星期一的日期)" Margin="10,10,10,5"/>
<DatePicker x:Name="uiDate" Height="25" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" SelectedDateChanged="uiDate_SelectedDateChanged"/>
<TextBlock Text="本学年周数" Margin="10,10,10,5"/>
<TextBox x:Name="uiWeekCount" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" TextChanged="uiWeekCount_TextChanged"/>
</StackPanel>
</TabItem>
<TabItem Header="课程设置">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Background="LightYellow">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Text="课程列表" HorizontalAlignment="Center" Margin="0,10,0,10"/>
<ListBox x:Name="uiCoursesList" Margin="5" Grid.Row="1" Background="#00000000" MouseDoubleClick="uiCoursesList_MouseDoubleClick"/>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="uiCourseBtnAdd" Content="添加" ToolTip="将右侧列表所填写的数据作为一个新项插入列表" Margin="5" Click="uiCourseBtnAdd_Click"/>
<Button x:Name="uiCourseBtnUpdate" Content="更新" Grid.Column="1" ToolTip="将右侧列表中的内容更新到列表的选中项中" Margin="5" Click="uiCourseBtnUpdate_Click"/>
<Button x:Name="uiCourseBtnDelete" Content="删除" Grid.Column="2" ToolTip="删除列表选中项" Margin="5" Click="uiCourseBtnDelete_Click"/>
</Grid>
</Grid>
<ScrollViewer Grid.Column="1">
<StackPanel Orientation="Vertical">
<GroupBox Header="基本信息" Margin="5">
<StackPanel Orientation="Vertical">
<TextBlock Text="课程名称" Margin="10,10,10,5"/>
<TextBox x:Name="uiCourseName" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" TextChanged="uiCourseName_TextChanged"/>
<TextBlock Text="注释" Margin="10,10,10,5"/>
<TextBox x:Name="uiCourseDescription" Height="100" Width="400" HorizontalAlignment="Left" Margin="10,0,10,10" AcceptsReturn="True" TextChanged="uiCourseDescription_TextChanged"/>
</StackPanel>
</GroupBox>
<GroupBox Header="课时设置" Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Background="LightYellow">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Text="课时安排" HorizontalAlignment="Center" Margin="0,10,0,10"/>
<ListBox x:Name="uiScheduleList" Margin="5" Grid.Row="1" Background="#00000000" MinHeight="200" MouseDoubleClick="uiScheduleList_MouseDoubleClick"/>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="uiScheduleBtnAdd" Content="添加" ToolTip="将右侧列表所填写的数据作为一个新项插入列表" Margin="5" Click="uiScheduleBtnAdd_Click"/>
<Button x:Name="uiScheduleBtnUpdate" Content="更新" Grid.Column="1" ToolTip="将右侧列表中的内容更新到列表的选中项中" Margin="5" Click="uiScheduleBtnUpdate_Click"/>
<Button x:Name="uiScheduleBtnDelete" Content="删除" Grid.Column="2" ToolTip="删除列表选中项" Margin="5" Click="uiScheduleBtnDelete_Click"/>
</Grid>
</Grid>
<StackPanel Grid.Column="1" Orientation="Vertical">
<TextBlock Text="周设置" Margin="10,10,10,5"/>
<TextBlock Text="输入格式:开始周-结束周 或 周号1,周号2,周号3" Margin="10,5,10,5"/>
<TextBlock Text="例如3-11 或 1,3,5" Margin="10,5,10,5"/>
<TextBox x:Name="uiScheduleWeek" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" TextChanged="uiScheduleWeek_TextChanged"/>
<TextBlock Text="课程星期" Margin="10,10,10,5"/>
<TextBlock Text="输入格式:开始星期-结束星期 或 星期号1,星期号2,星期号3 或 星期号" Margin="10,5,10,5"/>
<TextBlock Text="例如3-7 或 1,3,5 或 6" Margin="10,5,10,5"/>
<TextBox x:Name="uiScheduleDay" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" TextChanged="uiScheduleDay_TextChanged"/>
<TextBlock Text="当日课程节次" Margin="10,10,10,5"/>
<TextBlock Text="输入格式:开始节次-结束节次 或 节次号1,节次号2,节次号3" Margin="10,5,10,5"/>
<TextBlock Text="例如3-11 或 1,3,5" Margin="10,5,10,5"/>
<TextBox x:Name="uiScheduleIndex" Width="200" HorizontalAlignment="Left" Margin="10,0,10,10" TextChanged="uiScheduleIndex_TextChanged"/>
</StackPanel>
</Grid>
</GroupBox>
</StackPanel>
</ScrollViewer>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>

View File

@ -0,0 +1,350 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json;
namespace HFUTCourseSimulation {
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
UpdateUI();
}
bool isUpdatingData = false;
void UpdateUI() {
if (General.FilePath == "") {
//no file
uiMenuNew.IsEnabled = true;
uiMenuOpen.IsEnabled = true;
uiMenuSave.IsEnabled = false;
uiMenuClose.IsEnabled = false;
uiMenuSimulation.IsEnabled = false;
uiCourseBtnAdd.IsEnabled = false;
uiCourseBtnDelete.IsEnabled = false;
uiCourseBtnUpdate.IsEnabled = false;
uiScheduleBtnAdd.IsEnabled = false;
uiScheduleBtnDelete.IsEnabled = false;
uiScheduleBtnUpdate.IsEnabled = false;
uiScheduleIndex.IsEnabled = false;
uiScheduleWeek.IsEnabled = false;
uiCourseName.IsEnabled = false;
uiCourseDescription.IsEnabled = false;
uiDate.IsEnabled = false;
uiWeekCount.IsEnabled = false;
uiCoursesList.IsEnabled = false;
uiScheduleList.IsEnabled = false;
} else {
//no file
uiMenuNew.IsEnabled = false;
uiMenuOpen.IsEnabled = false;
uiMenuSave.IsEnabled = true;
uiMenuClose.IsEnabled = true;
uiMenuSimulation.IsEnabled = true;
uiCourseBtnAdd.IsEnabled = true;
uiCourseBtnDelete.IsEnabled = true;
uiCourseBtnUpdate.IsEnabled = true;
uiScheduleBtnAdd.IsEnabled = true;
uiScheduleBtnDelete.IsEnabled = true;
uiScheduleBtnUpdate.IsEnabled = true;
uiScheduleIndex.IsEnabled = true;
uiScheduleWeek.IsEnabled = true;
uiCourseName.IsEnabled = true;
uiCourseDescription.IsEnabled = true;
uiDate.IsEnabled = true;
uiWeekCount.IsEnabled = true;
uiCoursesList.IsEnabled = true;
uiScheduleList.IsEnabled = true;
}
}
#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();
}
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;
if (!File.Exists(getFile)) {
MessageBox.Show("文件不存在", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
return;
}
General.FilePath = getFile;
var fs = new StreamReader(getFile, Encoding.UTF8);
General.GeneralSheet = JsonConvert.DeserializeObject<Semester>(fs.ReadToEnd());
fs.Close();
fs.Dispose();
UpdateUI();
SyncMainData();
}
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();
}
private void uiMenuClose_Click(object sender, RoutedEventArgs e) {
//save
this.uiMenuSave_Click(sender, e);
General.FilePath = "";
UpdateUI();
}
private void uiMenuSimulation_Click(object sender, RoutedEventArgs e) {
var win = new Simulation();
win.ShowDialog();
}
private void uiMenuAbout_Click(object sender, RoutedEventArgs e) {
MessageBox.Show("本程序为开源程序。" + Environment.NewLine + "开源地址https://gitee.com/yyc12345/HFUTCourseSimulation" + Environment.NewLine +
"本程序旨在为各位选课的同学提供一个用于查验课程冲突以及查看课表的功能。如果您想参与开发提交PullRequest即可欢迎您的加入。", "关于", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}
void SyncMainData() {
isUpdatingData = true;
this.uiDate.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;
}
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;
}
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;
SyncScheduleListData();
isUpdatingData = false;
}
#endregion
#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 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;
}
//main
private void uiDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e) {
if (isUpdatingData) return;
General.GeneralSheet.StartDate = this.uiDate.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
}
}

View File

@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("HFUTCourseSimulation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HFUTCourseSimulation")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请设置
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
//例如,如果您在源文件中使用的是美国英语,
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
//对以下 NeutralResourceLanguage 特性的注释。 更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,62 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace HFUTCourseSimulation.Properties {
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if ((resourceMan == null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HFUTCourseSimulation.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace HFUTCourseSimulation.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@ -0,0 +1,110 @@
<Window x:Class="HFUTCourseSimulation.Simulation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HFUTCourseSimulation"
mc:Ignorable="d"
Title="课表输出" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- operator-->
<Grid>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="周:"/>
<TextBlock x:Name="uiWeek" Text="1"/>
</StackPanel>
<Button x:Name="uiBtnPre" HorizontalAlignment="Left" Content="上一周" Margin="5" Height="20" Click="uiBtnPre_Click"/>
<Button x:Name="uiBtnNext" HorizontalAlignment="Right" Content="下一周" Margin="5" Height="20" Click="uiBtnNext_Click"/>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Background="Gray"/>
<UniformGrid Background="Gray" Rows="1" Columns="7" Grid.Row="0" Grid.Column="1">
<StackPanel Orientation="Vertical">
<TextBlock Text="星期一"/>
<TextBlock x:Name="uiWeek1" Text="1/1"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="星期二"/>
<TextBlock x:Name="uiWeek2" Text="1/1"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="星期三"/>
<TextBlock x:Name="uiWeek3" Text="1/1"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="星期四"/>
<TextBlock x:Name="uiWeek4" Text="1/1"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="星期五"/>
<TextBlock x:Name="uiWeek5" Text="1/1"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="星期六"/>
<TextBlock x:Name="uiWeek6" Text="1/1"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="星期日"/>
<TextBlock x:Name="uiWeek7" Text="1/1"/>
</StackPanel>
</UniformGrid>
<UniformGrid Background="Gray" Rows="11" Columns="1" Grid.Row="1" Grid.Column="0">
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
<TextBlock Text="10"/>
<TextBlock Text="11"/>
</UniformGrid>
<Grid x:Name="uiArrangeGrid" Grid.Row="1" Grid.Column="1">
</Grid>
</Grid>
</Grid>
<Grid Grid.Column="1" Background="LightYellow">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="安排冲突" HorizontalAlignment="Center" Margin="0,10,0,10"/>
<ListBox x:Name="uiArrangeError" Margin="5" Grid.Row="1" Background="#00000000" MouseDoubleClick="uiArrangeError_MouseDoubleClick"/>
</Grid>
</Grid>
</Window>

View File

@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace HFUTCourseSimulation {
/// <summary>
/// Simulation.xaml 的交互逻辑
/// </summary>
public partial class Simulation : Window {
public Simulation() {
InitializeComponent();
//init colums and rows
for (int i = 0; i < 11; i++) {
var rows = new RowDefinition();
rows.Height = new GridLength(1, GridUnitType.Star);
this.uiArrangeGrid.RowDefinitions.Add(rows);
}
for (int i = 0; i < 7; i++) {
var colums = new ColumnDefinition();
colums.Width = new GridLength(1, GridUnitType.Star);
this.uiArrangeGrid.ColumnDefinitions.Add(colums);
}
try {
originDate = DateTime.Parse(General.GeneralSheet.StartDate);
weekCount = General.GeneralSheet.WeekCount;
} catch (Exception) {
MessageBox.Show("周数或日期转换错误,请关闭窗口", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
this.uiArrangeError.IsEnabled = false;
this.uiBtnNext.IsEnabled = false;
this.uiBtnPre.IsEnabled = false;
return;
}
Generate();
//refresh error list
this.uiArrangeError.Items.Clear();
foreach (var item in errorList) {
this.uiArrangeError.Items.Add(item);
}
currentWeek = 1;
Render();
}
Dictionary<Vector3, SimulationItem> itemDict = new Dictionary<Vector3, SimulationItem>();
List<string> errorList = new List<string>();
List<Grid> uiList = new List<Grid>();
DateTime originDate;
int weekCount;
int currentWeek;
void Generate() {
foreach (var item in General.GeneralSheet.Courses) {
foreach (var inner in item.Schedule) {
var weekRes = GetArrange(inner.Week);
var dayRes = GetArrange(inner.Day);
var indexRes = GetArrange(inner.Index);
foreach (var weekItem in weekRes) {
foreach (var dayItem in dayRes) {
foreach (var indexItem in indexRes) {
var vectorCache = new Vector3(weekItem, dayItem, indexItem);
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 });
}
}
}
}
}
}
}
List<int> GetArrange(string str) {
var res = new List<int>();
try {
if (str.Contains('-')) {
var strSp = str.Split('-');
int start = int.Parse(strSp[0]), end = int.Parse(strSp[1]);
for (int i = start; i <= end; i++) {
res.Add(i);
}
} else if (str.Contains(',')) {
var strSp = str.Split(',');
foreach (var item in strSp) {
res.Add(int.Parse(item));
}
} else {
res.Add(int.Parse(str));
}
} catch (Exception) {
errorList.Add("解析错误:" + str);
}
return res;
}
void Render() {
//remove all old grid
this.uiArrangeGrid.Children.Clear();
uiList.Clear();
//update date
//comput start date
uiWeek.Text = currentWeek.ToString();
var pointer = originDate;
pointer = pointer.AddDays(7 * (currentWeek - 1));
uiWeek1.Text = $"{pointer.Month}/{pointer.Day}";
pointer = pointer.AddDays(1);
uiWeek2.Text = $"{pointer.Month}/{pointer.Day}";
pointer = pointer.AddDays(1);
uiWeek3.Text = $"{pointer.Month}/{pointer.Day}";
pointer = pointer.AddDays(1);
uiWeek4.Text = $"{pointer.Month}/{pointer.Day}";
pointer = pointer.AddDays(1);
uiWeek5.Text = $"{pointer.Month}/{pointer.Day}";
pointer = pointer.AddDays(1);
uiWeek6.Text = $"{pointer.Month}/{pointer.Day}";
pointer = pointer.AddDays(1);
uiWeek7.Text = $"{pointer.Month}/{pointer.Day}";
//create grid
var query = from item in itemDict.Keys
where item.teachingweek == currentWeek
select item;
foreach (var item in query) {
//get data
var data = itemDict[item];
//create
var warp = new Border();
warp.Background = new SolidColorBrush(Colors.LightBlue);
warp.CornerRadius = new CornerRadius(5);
var nGrid = new Grid();
nGrid.ToolTip = data.Desc;
var courseName = new TextBlock();
courseName.VerticalAlignment = VerticalAlignment.Center;
courseName.Text = data.Name;
nGrid.Children.Add(courseName);
warp.Child = nGrid;
Grid.SetRow(warp, item.index - 1);
Grid.SetColumn(warp, item.week - 1);
this.uiArrangeGrid.Children.Add(warp);
}
}
private void uiBtnPre_Click(object sender, RoutedEventArgs e) {
if (currentWeek == 1) {
MessageBox.Show("已经是第一周了", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
return;
}
currentWeek--;
Render();
}
private void uiBtnNext_Click(object sender, RoutedEventArgs e) {
if (currentWeek == weekCount) {
MessageBox.Show("已经是最后一周了", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
return;
}
currentWeek++;
Render();
}
private void uiArrangeError_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
if (this.uiArrangeError.SelectedIndex < 0) {
MessageBox.Show("未选择任何项", "错误", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
return;
}
MessageBox.Show(errorList[this.uiArrangeError.SelectedIndex], "错误详情", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HFUTCourseSimulation {
public class SimulationItem {
public string Name { get; set; }
public string Desc { get; set; }
}
public struct Vector3 {
public Vector3(int x, int y, int z) {
teachingweek = x;
week = y;
index = z;
}
public int teachingweek;
public int week;
public int index;
public static bool operator ==(Vector3 a, Vector3 b) {
return (a.teachingweek == b.teachingweek && a.week == b.week && a.index == b.index);
}
public static bool operator !=(Vector3 a, Vector3 b) {
return !(a == b);
}
public override bool Equals(object obj) {
return (Vector3)obj == this;
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" />
</packages>

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 Tad William
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.