Skip to content

Commit

Permalink
完善课表编辑器布局,解决Issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Nov 12, 2023
1 parent 93287cf commit cc10cbf
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 30 deletions.
2 changes: 1 addition & 1 deletion ZongziTEK_Blackboard_Sticker/LauncherEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Title="ZongziTEK 黑板贴 - 启动台编辑器" Height="450" Width="800" MinHeight="450" MinWidth="800"
ui:WindowHelper.UseModernWindowStyle="True"
ui:ThemeManager.RequestedTheme="Light"
Background="#fff3f3f3">
Background="#fff3f3f3" WindowStartupLocation="CenterScreen">
<Grid>
<TextBlock Text="编辑启动台" Margin="24,12,24,12" FontSize="32"/>
<ui:ProgressBar Name="ListProgressBar" IsIndeterminate="True" Margin="48" Visibility="Collapsed"/>
Expand Down
2 changes: 1 addition & 1 deletion ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ private void ShowLastClassOverNotification()

private void Clock(object sender, EventArgs e)
{
textBlockTime.Text = DateTime.Now.ToString(("HH:mm:ss"));
textBlockTime.Text = DateTime.Now.ToString("HH:mm:ss");
}

private DispatcherTimer clockTimer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<TextBox x:Name="TextBoxSubject" BorderThickness="0"
Text="{Binding Subject, RelativeSource={RelativeSource AncestorType=UserControl}}"
TextAlignment="Center" VerticalContentAlignment="Center" Background="{x:Null}"
GotFocus="TextBoxSubject_GotFocus" LostFocus="TextBoxSubject_LostFocus"/>
GotFocus="TextBoxSubject_GotFocus" LostFocus="TextBoxSubject_LostFocus" TextChanged="TextBoxSubject_TextChanged"/>
</Grid>
<local:TimeTextBox BorderThickness="0" Grid.Column="1" Margin="8,6"
Text="{Binding StartTime, RelativeSource={RelativeSource AncestorType=UserControl}}" VerticalContentAlignment="Center" Background="{x:Null}"/>
Expand Down
21 changes: 21 additions & 0 deletions ZongziTEK_Blackboard_Sticker/Resources/TimetableEditorItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public partial class TimetableEditorItem : UserControl
public TimetableEditorItem()
{
InitializeComponent();

if (TextBoxSubject.Text == "")
{
TextBlockHintSubject.Visibility = Visibility.Visible;
}
else
{
TextBlockHintSubject.Visibility = Visibility.Hidden;
}
}

public static readonly DependencyProperty SubjectProperty =
Expand Down Expand Up @@ -64,5 +73,17 @@ private void TextBoxSubject_LostFocus(object sender, RoutedEventArgs e)
TextBlockHintSubject.Visibility = Visibility.Visible;
}
}

private void TextBoxSubject_TextChanged(object sender, TextChangedEventArgs e)
{
if (TextBoxSubject.Text == "")
{
TextBlockHintSubject.Visibility = Visibility.Visible;
}
else
{
TextBlockHintSubject.Visibility = Visibility.Hidden;
}
}
}
}
32 changes: 16 additions & 16 deletions ZongziTEK_Blackboard_Sticker/TimetableEditor.xaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
<Window xmlns:Resources="clr-namespace:ZongziTEK_Blackboard_Sticker.Resources" x:Class="ZongziTEK_Blackboard_Sticker.TimetableEditor"
<Window x:Class="ZongziTEK_Blackboard_Sticker.TimetableEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:local="clr-namespace:ZongziTEK_Blackboard_Sticker"
xmlns:local="clr-namespace:ZongziTEK_Blackboard_Sticker.Resources"
mc:Ignorable="d"
Title="ZongziTEK 黑板贴 - 课程表编辑器" Height="450" Width="800" MinHeight="450" MinWidth="800"
ui:WindowHelper.UseModernWindowStyle="True"
ui:ThemeManager.RequestedTheme="Light"
Background="#fff3f3f3"
Closing="Window_Closing">
Closing="Window_Closing" WindowStartupLocation="CenterScreen">
<Grid>
<Grid VerticalAlignment="Top" Margin="24,12,24,12">
<TextBlock Text="编辑课程表" FontSize="32"/>
<Button Name="ButtonUseCurriculum" Content="切换为旧版课程表 ( 无时间 )" HorizontalAlignment="Right" VerticalAlignment="Center" Click="ButtonUseCurriculum_Click"/>
</Grid>
<ui:SimpleStackPanel Spacing="8" Margin="24,64,24,64">
<StackPanel Orientation="Horizontal">
<Grid Margin="24,64,24,64">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="64"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" Height="21" Opacity="0.8" VerticalAlignment="Top">
<TextBlock Text="当前编辑的是: " FontSize="16"/>
<TextBlock FontSize="16" Text="{Binding SelectedItem.Content, ElementName=comboBox}"/>
<TextBlock FontSize="16" Text="{Binding SelectedItem.Content, ElementName=ComboBoxDay}"/>
<TextBlock Text="课表" FontSize="16"/>
</StackPanel>
<Border Height="48"
Background="#FFFBFBFB"
CornerRadius="2" BorderBrush="#FFE1E6EA" BorderThickness="1">
<Border Height="48" Background="#FFFBFBFB" CornerRadius="2" BorderBrush="#FFE1E6EA" BorderThickness="1" Grid.Row="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
Expand All @@ -36,16 +39,13 @@
<TextBlock Grid.Column="2" Text="结束时间" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Border>
<ScrollViewer PanningMode="VerticalOnly">
<ui:SimpleStackPanel Name="ListStackPanel" Spacing="4">
<Resources:TimetableEditorItem />
<Resources:TimetableEditorItem />
<Resources:TimetableEditorItem />
<ScrollViewer PanningMode="VerticalOnly" Grid.Row="2">
<ui:SimpleStackPanel Name="ListStackPanel" Spacing="4">
</ui:SimpleStackPanel>
</ScrollViewer>
</ui:SimpleStackPanel>
</Grid>
<Grid VerticalAlignment="Bottom" Margin="24,12,24,12">
<ComboBox x:Name="comboBox" Width="120" VerticalAlignment="Center" HorizontalAlignment="Left" SelectedIndex="0">
<ComboBox Name="ComboBoxDay" Width="120" VerticalAlignment="Center" HorizontalAlignment="Left" SelectionChanged="ComboBoxDay_SelectionChanged">
<ComboBoxItem Content="周一"/>
<ComboBoxItem Content="周二"/>
<ComboBoxItem Content="周三"/>
Expand Down
93 changes: 82 additions & 11 deletions ZongziTEK_Blackboard_Sticker/TimetableEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ZongziTEK_Blackboard_Sticker.Resources;

namespace ZongziTEK_Blackboard_Sticker
{
Expand All @@ -24,8 +25,12 @@ public partial class TimetableEditor : Window
public TimetableEditor()
{
InitializeComponent();

ComboBoxDay.SelectedIndex = 7;
ChangeComboBoxDaySelectedIndexToday();
}


#region Window & Controls
public static event Action EditorButtonUseCurriculum_Click;

private bool isCloseWithButtonUseCurriculum = false;
Expand Down Expand Up @@ -54,29 +59,95 @@ private void ButtonClose_Click(object sender, RoutedEventArgs e)

private void ButtonUseCurriculum_Click(object sender, RoutedEventArgs e)
{
if(MessageBox.Show("是否保存当前含时间信息的课程表内容","ZongziTEK 黑板贴", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.OK)
if (MessageBox.Show("是否保存当前含时间信息的课程表内容", "ZongziTEK 黑板贴", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.OK)
{
ButtonSave_Click(null, null);
}
MessageBox.Show("若后续需要使用含时间信息的课程表,请在设置中启用","ZongziTEK 黑板贴");
MessageBox.Show("若后续需要使用含时间信息的课程表,请在设置中启用", "ZongziTEK 黑板贴");
EditorButtonUseCurriculum_Click?.Invoke();
isCloseWithButtonUseCurriculum = true;
Close();
}

public static Timetable Timetable = new Timetable();
public static string timetableFileName = "Timetable.json";
private void ComboBoxDay_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LoadTimetable();
}
#endregion

#region Load & Save
private Timetable Timetable = MainWindow.Timetable;

private void LoadTimetable()
{
if (File.Exists(MainWindow.GetDataPath() + timetableFileName))
ListStackPanel.Children.Clear();
foreach (Lesson lesson in GetSelectedDay())
{
try
TimetableEditorItem item = new TimetableEditorItem()
{
string text = File.ReadAllText(MainWindow.GetDataPath() + timetableFileName);
Timetable = JsonConvert.DeserializeObject<Timetable>(text);
}
catch { }
Subject = lesson.Subject,
StartTime = lesson.StartTime.ToString(@"hh\:mm"),
EndTime = lesson.EndTime.ToString(@"hh\:mm")
};
ListStackPanel.Children.Add(item);
}
}
#endregion

#region Other Functions
private List<Lesson> GetSelectedDay()
{
switch (ComboBoxDay.SelectedIndex)
{
case 0:
return Timetable.Monday;
case 1:
return Timetable.Tuesday;
case 2:
return Timetable.Wednesday;
case 3:
return Timetable.Thursday;
case 4:
return Timetable.Friday;
case 5:
return Timetable.Saturday;
case 6:
return Timetable.Sunday;
case 7:
return Timetable.Temp;
}
return Timetable.Monday;
}

private void ChangeComboBoxDaySelectedIndexToday()
{

string day = DateTime.Today.DayOfWeek.ToString();
switch (day)
{
case "Monday":
ComboBoxDay.SelectedIndex = 0;
break;
case "Tuesday":
ComboBoxDay.SelectedIndex = 1;
break;
case "Wednesday":
ComboBoxDay.SelectedIndex = 2;
break;
case "Thursday":
ComboBoxDay.SelectedIndex = 3;
break;
case "Friday":
ComboBoxDay.SelectedIndex = 4;
break;
case "Saturday":
ComboBoxDay.SelectedIndex = 5;
break;
case "Sunday":
ComboBoxDay.SelectedIndex = 6;
break;
}
}
#endregion
}
}

0 comments on commit cc10cbf

Please sign in to comment.