Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZjzMisaka committed Jun 24, 2024
1 parent 72a0dcd commit b869d80
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 8 deletions.
38 changes: 38 additions & 0 deletions Powork/Repository/MemoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@ public static string SelectMemo(string date)
return string.Empty;
}

public static string SelectPreviousMemoDate(string date)
{
SQLiteConnection connection = CommonRepository.GetConnection();

string sql = $"SELECT * FROM TMemo WHERE date < '{date}' AND memo IS NOT NULL AND memo <> '' ORDER BY date DESC LIMIT 1";

using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return reader["date"].ToString().Split(" ")[0];
}
}
}
return null;
}

public static string SelectNextMemoDate(string date)
{
SQLiteConnection connection = CommonRepository.GetConnection();

string sql = $"SELECT * FROM TMemo WHERE date > '{date}' AND memo IS NOT NULL AND memo <> '' ORDER BY date ASC LIMIT 1";

using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return reader["date"].ToString().Split(" ")[0];
}
}
}
return null;
}

public static void InsertOrUpdateMemo(string date, string memo)
{
SQLiteConnection connection = CommonRepository.GetConnection();
Expand Down
37 changes: 30 additions & 7 deletions Powork/View/MemoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
</i:Interaction.Triggers>

<Grid>
<Grid.InputBindings>
<KeyBinding Key="Left" Modifiers="Control" Command="{Binding PreviousDayCommand, Mode=OneWay}" />
<KeyBinding Key="Right" Modifiers="Control" Command="{Binding NextDayCommand, Mode=OneWay}" />
<KeyBinding Key="Left" Modifiers="Control+Shift" Command="{Binding PreviousMemoCommand, Mode=OneWay}" />
<KeyBinding Key="Right" Modifiers="Control+Shift" Command="{Binding NextMemoCommand, Mode=OneWay}" />
</Grid.InputBindings>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
Expand All @@ -35,19 +43,29 @@
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="&lt;" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviousDayCommand}"></Button>
<Button Grid.Column="1" Content=">" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding NextDayCommand}"></Button>
<DatePicker Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" SelectedDateFormat="Short" SelectedDate="{Binding Date}"></DatePicker>
<Button Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding EditVisibleChangeCommand}">
<Button Grid.Column="0" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviousDayCommand}">
<ui:SymbolIcon Symbol="ArrowLeft24" />
</Button>
<Button Grid.Column="1" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding NextDayCommand}">
<ui:SymbolIcon Symbol="ArrowRight24" />
</Button>
<Button Grid.Column="2" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviousMemoCommand}">
<ui:SymbolIcon Symbol="ArrowStepInLeft24" />
</Button>
<Button Grid.Column="3" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding NextMemoCommand}">
<ui:SymbolIcon Symbol="ArrowStepInRight24" />
</Button>
<DatePicker Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" SelectedDateFormat="Short" SelectedDate="{Binding Date}"></DatePicker>
<Button Grid.Column="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding EditVisibleChangeCommand}">
<ui:SymbolIcon Symbol="DocumentEdit24" />
</Button>
<Button Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviewVisibleChangeCommand}">
<Button Grid.Column="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviewVisibleChangeCommand}">
<ui:SymbolIcon Symbol="PreviewLink24" />
</Button>
<Button Grid.Column="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding SwapCommand}">
<Button Grid.Column="7" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding SwapCommand}">
<ui:SymbolIcon Symbol="ArrowSwap24" />
</Button>
<Button Grid.Column="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 5, 0" Command="{Binding SaveCommand}">
<Button Grid.Column="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 5, 0" Command="{Binding SaveCommand}">
<ui:SymbolIcon Symbol="Save24" />
</Button>
</Grid>
Expand All @@ -60,6 +78,11 @@
<TextBox ScrollViewer.CanContentScroll="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AcceptsReturn="True" Text="{Binding Memo, UpdateSourceTrigger=PropertyChanged}" Grid.Column="{Binding MemoColumn}" Grid.ColumnSpan="{Binding MemoColumnSpan}" Visibility="{Binding MemoVisibility}" Margin="{Binding MemoMargin}">
<TextBox.InputBindings>
<KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand, Mode=OneWay}" />

<KeyBinding Key="Left" Modifiers="Control" Command="{Binding PreviousDayCommand, Mode=OneWay}" />
<KeyBinding Key="Right" Modifiers="Control" Command="{Binding NextDayCommand, Mode=OneWay}" />
<KeyBinding Key="Left" Modifiers="Control+Shift" Command="{Binding PreviousMemoCommand, Mode=OneWay}" />
<KeyBinding Key="Right" Modifiers="Control+Shift" Command="{Binding NextMemoCommand, Mode=OneWay}" />
</TextBox.InputBindings>
</TextBox>
<GridSplitter Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch" Width="5" Background="Transparent" ShowsPreview="True"></GridSplitter>
Expand Down
29 changes: 28 additions & 1 deletion Powork/ViewModel/MemoPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public Thickness PreviewMargin
public ICommand WindowUnloadedCommand { get; set; }
public ICommand PreviousDayCommand { get; set; }
public ICommand NextDayCommand { get; set; }
public ICommand PreviousMemoCommand { get; set; }
public ICommand NextMemoCommand { get; set; }
public ICommand EditVisibleChangeCommand { get; set; }
public ICommand PreviewVisibleChangeCommand { get; set; }
public ICommand SwapCommand { get; set; }
Expand All @@ -168,6 +170,8 @@ public MemoPageViewModel()
WindowUnloadedCommand = new RelayCommand<RoutedEventArgs>(WindowUnloaded);
PreviousDayCommand = new RelayCommand(PreviousDay);
NextDayCommand = new RelayCommand(NextDay);
PreviousMemoCommand = new RelayCommand(PreviousMemo);
NextMemoCommand = new RelayCommand(NextMemo);
EditVisibleChangeCommand = new RelayCommand(EditVisibleChange);
PreviewVisibleChangeCommand = new RelayCommand(PreviewVisibleChange);
SwapCommand = new RelayCommand(Swap);
Expand Down Expand Up @@ -215,7 +219,30 @@ private void NextDay()
dateTime = dateTime.AddDays(1);
string formattedDate = dateTime.ToString(Format.DateTimeFormat);
Date = dateTime.ToString(Format.DateTimeFormat);
Memo = MemoRepository.SelectMemo(formattedDate);
}
}

private void PreviousMemo()
{
if (DateTime.TryParse(Date, out DateTime dateTime))
{
string date = MemoRepository.SelectPreviousMemoDate(dateTime.ToString(Format.DateTimeFormat));
if (date != null)
{
Date = date;
}
}
}

private void NextMemo()
{
if (DateTime.TryParse(Date, out DateTime dateTime))
{
string date = MemoRepository.SelectNextMemoDate(dateTime.ToString(Format.DateTimeFormat));
if (date != null)
{
Date = date;
}
}
}

Expand Down

0 comments on commit b869d80

Please sign in to comment.