View Report Update

main
unknown 6 months ago
parent e49bf6af26
commit d478bb57fc
  1. 18
      Views/ViewReportsPage.xaml
  2. 30
      Views/ViewReportsPage.xaml.cs
  3. BIN
      bin/Debug/net9.0-android/Justice.dll
  4. BIN
      bin/Debug/net9.0-android/Justice.pdb

@ -13,16 +13,22 @@
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" />
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}"
FontSize="Small" />
<Label Text="{Binding Description}" FontSize="Small" />
<StackLayout Padding="10" Orientation="Horizontal">
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" />
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}"
FontSize="Small" />
<Label Text="{Binding Description}" FontSize="Small" />
</StackLayout>
<Button Text="Delete"
Clicked="OnDeleteReportClicked"
CommandParameter="{Binding .}" HeightRequest="10" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

@ -60,5 +60,35 @@ namespace Justice.Views
ReportsListView.SelectedItem = null;
}
}
private async void OnDeleteReportClicked(object sender, EventArgs e)
{
// Get the button's binding context
if (sender is Button deleteButton && deleteButton.CommandParameter is IncidentReport reportToDelete)
{
bool confirm = await DisplayAlert("Delete Report", "Are you sure you want to delete this report?", "Yes", "No");
if (confirm)
{
try
{
// Delete the report from the database
await _databaseHelper.DeleteAsync(reportToDelete);
// Remove the report from the ObservableCollection
Reports.Remove(reportToDelete);
await DisplayAlert("Success", "Report deleted successfully.", "OK");
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to delete report: {ex.Message}", "OK");
}
}
}
}
private void MenuItem_Clicked(object sender, EventArgs e)
{
}
}
}

Loading…
Cancel
Save