parent
38ca3b3d10
commit
e49bf6af26
@ -0,0 +1,28 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.ViewReportsPage" |
||||
Title="View Reports"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" /> |
||||
|
||||
<!-- List of Reports --> |
||||
<ListView x:Name="ReportsListView" |
||||
HasUnevenRows="True" |
||||
ItemSelected="OnReportSelected"> |
||||
<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> |
||||
</ViewCell> |
||||
</DataTemplate> |
||||
</ListView.ItemTemplate> |
||||
</ListView> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -0,0 +1,64 @@ |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using System; |
||||
using System.Collections.ObjectModel; |
||||
using System.Threading.Tasks; |
||||
using Justice.Services; |
||||
|
||||
namespace Justice.Views |
||||
{ |
||||
public partial class ViewReportsPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _databaseHelper; |
||||
public ObservableCollection<IncidentReport> Reports { get; set; } |
||||
|
||||
public ViewReportsPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_databaseHelper = new DatabaseHelper(); |
||||
Reports = new ObservableCollection<IncidentReport>(); |
||||
ReportsListView.ItemsSource = Reports; |
||||
} |
||||
|
||||
protected override async void OnAppearing() |
||||
{ |
||||
base.OnAppearing(); |
||||
await LoadReportsAsync(); |
||||
} |
||||
|
||||
private async Task LoadReportsAsync() |
||||
{ |
||||
try |
||||
{ |
||||
var reportsFromDb = await _databaseHelper.GetAllAsync<IncidentReport>(); |
||||
Reports.Clear(); |
||||
|
||||
foreach (var report in reportsFromDb) |
||||
{ |
||||
Reports.Add(report); |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
|
||||
private async void OnReportSelected(object sender, SelectedItemChangedEventArgs e) |
||||
{ |
||||
if (e.SelectedItem is IncidentReport selectedReport) |
||||
{ |
||||
await DisplayAlert("Report Details", |
||||
$"Type: {selectedReport.IncidentType}\n" + |
||||
$"Description: {selectedReport.Description}\n" + |
||||
$"Address: {selectedReport.Address}\n" + |
||||
$"Submitted on: {selectedReport.DateTime:MMM dd, yyyy HH:mm}\n" + |
||||
$"Attachment: {(string.IsNullOrWhiteSpace(selectedReport.AttachmentPath) ? "None" : "Attached")}", |
||||
"OK"); |
||||
|
||||
// Deselect the item |
||||
ReportsListView.SelectedItem = null; |
||||
} |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue