Skip to content

Commit

Permalink
[+] memo search
Browse files Browse the repository at this point in the history
  • Loading branch information
ZjzMisaka committed Jul 3, 2024
1 parent 5c09ab9 commit 9d78988
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Powork/Repository/MemoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public static string SelectMemo(string date)
return string.Empty;
}

public static string SelectPreviousMemoDate(string date)
public static string SelectPreviousMemoDate(string date, string search)
{
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";
string sql = $"SELECT * FROM TMemo WHERE date < '{date}' AND memo IS NOT NULL AND memo <> '' AND memo LIKE '%{search}%' ORDER BY date DESC LIMIT 1";

using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
Expand All @@ -42,11 +42,11 @@ public static string SelectPreviousMemoDate(string date)
return null;
}

public static string SelectNextMemoDate(string date)
public static string SelectNextMemoDate(string date, string search)
{
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";
string sql = $"SELECT * FROM TMemo WHERE date > '{date}' AND memo IS NOT NULL AND memo <> '' AND memo LIKE '%{search}%' ORDER BY date ASC LIMIT 1";

using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
Expand Down
2 changes: 1 addition & 1 deletion Powork/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
</ui:NavigationViewItem>
<ui:NavigationViewItem Content="{DynamicResource Memo}" TargetPageType="{x:Type view:MemoPage}">
<ui:NavigationViewItem.Icon>
<ui:SymbolIcon Symbol="Pen24" />
<ui:SymbolIcon Symbol="DocumentEdit24" />
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationView.MenuItems>
Expand Down
20 changes: 11 additions & 9 deletions Powork/View/MemoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
Expand All @@ -50,26 +51,27 @@
<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}">
<DatePicker Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" SelectedDateFormat="Short" SelectedDate="{Binding Date}" IsTodayHighlighted="True" Width="130"></DatePicker>
<Button Grid.Column="3" 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}">
<Button Grid.Column="4" 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" />
<ui:TextBox Grid.Column="5" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Text="{Binding Search}"></ui:TextBox>
<Button Grid.Column="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding EditVisibleChangeCommand}">
<ui:SymbolIcon Symbol="Pen24" />
</Button>
<Button Grid.Column="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviewVisibleChangeCommand}">
<Button Grid.Column="7" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding PreviewVisibleChangeCommand}">
<ui:SymbolIcon Symbol="PreviewLink24" />
</Button>
<Button Grid.Column="7" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding SwapCommand}">
<Button Grid.Column="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 0, 0" Command="{Binding SwapCommand}">
<ui:SymbolIcon Symbol="ArrowSwap24" />
</Button>
<Button Grid.Column="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 5, 0" Command="{Binding SaveDocumentCommand}">
<Button Grid.Column="9" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 5, 0" Command="{Binding SaveDocumentCommand}">
<ui:SymbolIcon Symbol="DocumentSave24" />
</Button>
<Button Grid.Column="9" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 5, 0" Command="{Binding SaveCommand}">
<Button Grid.Column="10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5, 5, 5, 0" Command="{Binding SaveCommand}">
<ui:SymbolIcon Symbol="Save24" />
</Button>
</Grid>
Expand Down
10 changes: 8 additions & 2 deletions Powork/ViewModel/MemoPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public string Date
}
}
}
private string _search;
public string Search
{
get => _search;
set => SetProperty<string>(ref _search, value);
}
private string _memo;
public string Memo
{
Expand Down Expand Up @@ -179,7 +185,7 @@ private void PreviousMemo()
{
if (DateTime.TryParse(Date, out DateTime dateTime))
{
string date = MemoRepository.SelectPreviousMemoDate(dateTime.ToString(Format.DateTimeFormat));
string date = MemoRepository.SelectPreviousMemoDate(dateTime.ToString(Format.DateTimeFormat), Search);
if (date != null)
{
Date = date;
Expand All @@ -191,7 +197,7 @@ private void NextMemo()
{
if (DateTime.TryParse(Date, out DateTime dateTime))
{
string date = MemoRepository.SelectNextMemoDate(dateTime.ToString(Format.DateTimeFormat));
string date = MemoRepository.SelectNextMemoDate(dateTime.ToString(Format.DateTimeFormat), Search);
if (date != null)
{
Date = date;
Expand Down

0 comments on commit 9d78988

Please sign in to comment.