Skip to content

Commit 24ab06a

Browse files
committed
added Button to clear the entry fields. Needed for: updating an existing entry and then moving on to adding another one.
1 parent 767adde commit 24ab06a

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

ReceiptOverview/Assets/clear.png

1.17 KB
Loading

ReceiptOverview/ViewModels/MainWindowViewModel.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public bool CheckVisible
8383
}
8484

8585

86+
public ICommand ClearEntryCommand { get; set; }
8687
public ICommand CopyEntryCommand { get; set; }
8788
public ICommand NewPositionCommand { get; }
8889
public ICommand RemovePositionCommand { get; }
@@ -115,11 +116,12 @@ public MainWindowViewModel()
115116

116117
CopyEntryCommand = ReactiveCommand.Create(() => CopyEntry());
117118
NewPositionCommand = ReactiveCommand.Create(() => CreateNewPosition());
118-
NewEntryCommand = ReactiveCommand.Create(() => SaveEntry());
119-
SaveCommand = ReactiveCommand.Create(() => Save());
120-
ExportToCsvCommand = ReactiveCommand.Create(async() => await ExportToCsv());
121-
CheckDbConnectionCommand = ReactiveCommand.Create(async () => await CheckDbConnection());
122-
119+
NewEntryCommand = ReactiveCommand.Create(() => AddEntry());
120+
SaveCommand = ReactiveCommand.Create(() => SavePositionsWithEntries());
121+
ExportToCsvCommand = ReactiveCommand.Create(()=> ExportToCsv());
122+
CheckDbConnectionCommand = ReactiveCommand.Create(() => CheckDbConnection());
123+
ClearEntryCommand = ReactiveCommand.Create(() => ClearEntry());
124+
123125
LoadPositionsWithEntries();
124126
}
125127

@@ -194,7 +196,7 @@ private void CreateNewPosition()
194196
CrossVisible = true;
195197
}
196198

197-
private void SaveEntry()
199+
private void AddEntry()
198200
{
199201
int entryId = Logic.SaveEntry(CurrentEntry.VmToModel());
200202
EntryViewModel entryWithId = CurrentEntry;
@@ -236,8 +238,12 @@ private async Task RemovePosition()
236238

237239
private async Task RemoveEntry()
238240
{
239-
if (CurrentEntry == null! || CurrentEntry.Id == 0)
241+
if (CurrentEntry == null || CurrentEntry.Id == 0)
242+
{
243+
if (CurrentPosition.Entries.Contains(CurrentEntry))
244+
CurrentPosition.Entries.Remove(CurrentEntry);
240245
return;
246+
}
241247

242248
MainUiActive = false;
243249

@@ -259,7 +265,7 @@ private async Task RemoveEntry()
259265
MainUiActive = true;
260266
}
261267

262-
private void Save()
268+
private void SavePositionsWithEntries()
263269
{
264270
Logic.SavePosition(CurrentPosition.VmToModel());
265271

@@ -315,6 +321,11 @@ private void CopyEntry()
315321
CrossVisible = true;
316322
CheckVisible = false;
317323
}
324+
325+
private void ClearEntry()
326+
{
327+
CurrentEntry = new EntryViewModel();
328+
}
318329

319330

320331
private string GetConnectionErrorMessage()

ReceiptOverview/Views/MainWindow.axaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,36 @@
272272

273273
<DockPanel HorizontalAlignment="Right"
274274
DockPanel.Dock="Top"
275-
Name="DockEntryButtons"
275+
Name="DockEntryButtons"
276276
Margin="0,5,0,25">
277277
<StackPanel Orientation="Horizontal">
278-
<Button Margin="5,0,10,0"
278+
<Button Margin="0,0,5,0"
279+
HorizontalAlignment="Stretch"
280+
Command="{Binding ClearEntryCommand}"
281+
IsTabStop="False"
282+
Name="BtnClearEntry">
283+
<Button.Template>
284+
<ControlTemplate>
285+
<Border Background="{TemplateBinding Background}"
286+
VerticalAlignment="Center"
287+
HorizontalAlignment="Stretch"
288+
BorderThickness="8"
289+
CornerRadius="3">
290+
<StackPanel Orientation="Horizontal"
291+
HorizontalAlignment="Center">
292+
<TextBlock Text="Clear Entry"
293+
VerticalAlignment="Center"
294+
Margin="5,0,0,0" />
295+
<Image Source="avares://ReceiptOverview/Assets/clear.png"
296+
Width="18"
297+
Height="18" />
298+
</StackPanel>
299+
</Border>
300+
</ControlTemplate>
301+
</Button.Template>
302+
</Button>
303+
304+
<Button Margin="0,0,5,0"
279305
HorizontalAlignment="Stretch"
280306
Command="{Binding NewEntryCommand}"
281307
IsTabStop="False"

0 commit comments

Comments
 (0)