You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
6 months ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|