parent
22ee251227
commit
28afc9a2a5
@ -1,12 +1,41 @@ |
||||
<?xml version="1.0" encoding="utf-8" ?> |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.IncidentReportPage" |
||||
Title="IncidentReportPage"> |
||||
<VerticalStackLayout> |
||||
<Label |
||||
Text="Welcome to .NET MAUI!" |
||||
VerticalOptions="Center" |
||||
HorizontalOptions="Center" /> |
||||
</VerticalStackLayout> |
||||
Title="Report Incident"> |
||||
|
||||
<ScrollView> |
||||
<StackLayout Padding="20" Spacing="15"> |
||||
<!-- Reporter Name --> |
||||
<Label Text="Your Name" FontSize="Medium" /> |
||||
<Entry x:Name="ReporterNameEntry" Placeholder="Enter your name" /> |
||||
|
||||
<!-- Incident Type --> |
||||
<Label Text="Incident Type" FontSize="Medium" /> |
||||
<Picker x:Name="IncidentTypePicker"> |
||||
<Picker.ItemsSource> |
||||
<x:Array Type="{x:Type x:String}"> |
||||
<x:String>Accident</x:String> |
||||
<x:String>Crime</x:String> |
||||
<x:String>Fire</x:String> |
||||
<x:String>Other</x:String> |
||||
</x:Array> |
||||
</Picker.ItemsSource> |
||||
</Picker> |
||||
|
||||
<!-- Description --> |
||||
<Label Text="Description" FontSize="Medium" /> |
||||
<Editor x:Name="DescriptionEditor" Placeholder="Enter incident details" AutoSize="TextChanges" /> |
||||
|
||||
<!-- Location --> |
||||
<Label Text="Location (Auto-filled)" FontSize="Medium" /> |
||||
<Entry x:Name="LocationEntry" IsReadOnly="True" /> |
||||
|
||||
<!-- Attachment --> |
||||
<Label Text="Attachment (Optional)" FontSize="Medium" /> |
||||
<Button Text="Choose File" Clicked="OnChooseFileClicked" /> |
||||
|
||||
<!-- Submit Button --> |
||||
<Button Text="Submit Report" Clicked="OnSubmitReportClicked" /> |
||||
</StackLayout> |
||||
</ScrollView> |
||||
</ContentPage> |
@ -1,9 +1,109 @@ |
||||
namespace Justice.Views; |
||||
using ChildGuard.Services; |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using System; |
||||
|
||||
public partial class IncidentReportPage : ContentPage |
||||
namespace Justice.Views |
||||
{ |
||||
public partial class IncidentReportPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _databaseHelper; |
||||
private readonly EmailService _emailService; |
||||
|
||||
public IncidentReportPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_databaseHelper = new DatabaseHelper(); |
||||
_emailService = new EmailService(); |
||||
} |
||||
|
||||
protected override async void OnAppearing() |
||||
{ |
||||
base.OnAppearing(); |
||||
await FetchLocationAsync(); |
||||
} |
||||
|
||||
private async Task FetchLocationAsync() |
||||
{ |
||||
try |
||||
{ |
||||
var (latitude, longitude, address) = await GeolocationHelper.GetLocationAsync(); |
||||
LocationEntry.Text = address; |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
LocationEntry.Text = "Unable to fetch location."; |
||||
Console.WriteLine($"Error fetching location: {ex.Message}"); |
||||
} |
||||
} |
||||
|
||||
private async void OnSubmitReportClicked(object sender, EventArgs e) |
||||
{ |
||||
if (string.IsNullOrWhiteSpace(ReporterNameEntry.Text) || |
||||
IncidentTypePicker.SelectedItem == null || |
||||
string.IsNullOrWhiteSpace(DescriptionEditor.Text)) |
||||
{ |
||||
await DisplayAlert("Error", "Please fill in all required fields.", "OK"); |
||||
return; |
||||
} |
||||
|
||||
var (latitude, longitude, address) = await GeolocationHelper.GetLocationAsync(); |
||||
|
||||
var report = new IncidentReport |
||||
{ |
||||
ReporterName = ReporterNameEntry.Text.Trim(), |
||||
IncidentType = IncidentTypePicker.SelectedItem.ToString(), |
||||
Description = DescriptionEditor.Text.Trim(), |
||||
Latitude = latitude, |
||||
Longitude = longitude, |
||||
Address = address, |
||||
DateTime = DateTime.Now, |
||||
AttachmentPath = null // Optional |
||||
}; |
||||
|
||||
try |
||||
{ |
||||
// Save to database |
||||
await _databaseHelper.InsertAsync(report); |
||||
|
||||
// Get recipient email based on incident type |
||||
string recipientEmail = _emailService.GetRecipientEmail(report.IncidentType); |
||||
|
||||
// Prepare email content |
||||
string emailBody = $"Incident Report:\n\n" + |
||||
$"Name: {report.ReporterName}\n" + |
||||
$"Type: {report.IncidentType}\n" + |
||||
$"Description: {report.Description}\n" + |
||||
$"Latitude: {report.Latitude}\n" + |
||||
$"Longitude: {report.Longitude}\n" + |
||||
$"Location: {report.Address}\n" + |
||||
$"Date/Time: {report.DateTime}"; |
||||
|
||||
// Send email |
||||
bool emailSent = await _emailService.SendEmailAsync(recipientEmail, "Incident Report", emailBody); |
||||
|
||||
if (emailSent) |
||||
{ |
||||
await DisplayAlert("Success", "Incident report submitted and email alert sent.", "OK"); |
||||
} |
||||
else |
||||
{ |
||||
await DisplayAlert("Error", "Failed to send email alert.", "OK"); |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to submit report: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
|
||||
private async void OnChooseFileClicked(object sender, EventArgs e) |
||||
{ |
||||
var result = await FilePicker.PickAsync(); |
||||
if (result != null) |
||||
{ |
||||
await DisplayAlert("File Selected", $"File: {result.FileName}", "OK"); |
||||
} |
||||
} |
||||
} |
||||
} |
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.
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