Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_
Title="Error Resource Reservation"
ContentTemplate="{DataTemplate views:ResourceRequestPage}"/>

<ShellContent
Title="Operations"
ContentTemplate="{DataTemplate views:OperationPage}"/>

</TabBar>

Expand Down
49 changes: 49 additions & 0 deletions Models/Operation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace UndacApp.Models
{
public class Operation : AModel
{
private OperationStatus _status;
public OperationStatus Status
{
get => _status;
set => SetField(ref _status, value);
}

private DateTime _dateStarted;
public DateTime DateStarted
{
get => _dateStarted;
set => SetField(ref _dateStarted, value);
}

private string _location;
public string Location
{
get => _location;
set => SetField(ref _location, value);
}

private int _numberOfPersonnel;
public int NumberOfPersonnel
{
get => _numberOfPersonnel;
set => SetField(ref _numberOfPersonnel, value);
}

private string _finalReport;
public string FinalReport
{
get => _finalReport;
set => SetField(ref _finalReport, value);
}

}

public enum OperationStatus
{
NotStarted,
InProgress,
Completed,
Aborted
}
}
9 changes: 9 additions & 0 deletions Services/Operation/IOperationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using UndacApp.Models;

namespace UndacApp.Services
{
public interface IOperationService : IService<Operation>
{
Task<List<Operation>> GetOperationsByStatus(OperationStatus status);
}
}
16 changes: 16 additions & 0 deletions Services/Operation/OperationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UndacApp.Data;
using UndacApp.Models;
using SQLite;

namespace UndacApp.Services
{
public class OperationService : AService<Operation>, IOperationService
{

public async Task<List<Operation>> GetOperationsByStatus(OperationStatus status)
{
return await _database.Table<Operation>().Where(a => a.Status == status).ToListAsync();
}

}
}
6 changes: 6 additions & 0 deletions UndacApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<MauiXaml Update="Views\BuildingTypePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\OperationPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\MethodologicalDocumentationPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
Expand Down Expand Up @@ -150,6 +153,9 @@
<Compile Update="Views\BuildingTypePage.xaml.cs">
<DependentUpon>BuildingTypePage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\OperationPage.xaml.cs">
<DependentUpon>OperationPage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\MethodologicalDocumentationPage.xaml.cs">
<DependentUpon>MethodologicalDocumentationPage.xaml</DependentUpon>
</Compile>
Expand Down
42 changes: 42 additions & 0 deletions Views/OperationPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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="UndacApp.Views.OperationPage"
Title="OperationPage"
xmlns:local="clr-namespace:Undac.Models">
<VerticalStackLayout Spacing="10" Margin="5">
<Entry Placeholder="Name" x:Name="NameEntry" />
<Picker Title="Status" x:Name="StatusEntry">

<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>NotStarted</x:String>
<x:String>InProgress</x:String>
<x:String>Completed</x:String>
<x:String>Aborted</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<DatePicker x:Name="DateStartedEntry" />
<Entry Placeholder="Location" x:Name="LocationEntry" />
<Entry Placeholder="NumberOfPersonnel" x:Name="NumberOfPersonnelEntry" />
<Entry Placeholder="FinalReport" x:Name="FinalReportEntry" />

<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
<Button Text="Save"
Clicked="SaveButton_Clicked" />

<Button Grid.Column="1"
Text="Delete"
Clicked="DeleteButton_Clicked" />
</Grid>

<ListView x:Name="ltv_operations" Background="white" ItemSelected="ltv_operations_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell TextColor="Black" Text="{Binding Name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</VerticalStackLayout>
</ContentPage>
118 changes: 118 additions & 0 deletions Views/OperationPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

using UndacApp.Models;
using UndacApp.Services;
using System.Collections.ObjectModel;

namespace UndacApp.Views;

public partial class OperationPage : ContentPage
{

private Operation? selectedOperation = null;

OperationService operationService;

ObservableCollection<Operation> operations = new ObservableCollection<Operation>();

public OperationPage()
{
InitializeComponent();
this.BindingContext = new Operation();
this.operationService = new OperationService();

}

protected override async void OnAppearing()
{
await LoadOperations();
NameEntry.Text = "";
}

private async Task LoadOperations()
{
operations = new ObservableCollection<Operation>(await operationService.GetAll());
ltv_operations.ItemsSource = operations;
}

/*! <summary>
Method responsible for saving Continent into SQLite database, triggered by selection of save button.
</summary>
<param name="sender">Details about the element that triggered the event.</param>
<param name="e">Event details, passed by eventHandler due to clicking event button.</param> */
private async void SaveButton_Clicked(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(NameEntry.Text)) return;
if (String.IsNullOrEmpty(StatusEntry.SelectedItem as string)) return;
if (DateStartedEntry.Date == default) return;
if (String.IsNullOrEmpty(LocationEntry.Text)) return;
if (String.IsNullOrEmpty(NumberOfPersonnelEntry.Text)) return;
if (String.IsNullOrEmpty(FinalReportEntry.Text)) return;

if (selectedOperation == null)
{
var operation = new Operation()
{
Name = NameEntry.Text,
Status = Enum.Parse<OperationStatus>(StatusEntry.SelectedItem as string),
DateStarted = DateStartedEntry.Date,
Location = LocationEntry.Text,
NumberOfPersonnel = int.Parse(NumberOfPersonnelEntry.Text),
FinalReport = FinalReportEntry.Text,

};
await operationService.Add(operation);
operations.Add(operation);
}
else
{
selectedOperation.Name = NameEntry.Text;
selectedOperation.Status = Enum.Parse<OperationStatus>(StatusEntry.SelectedItem as string);
selectedOperation.DateStarted = DateStartedEntry.Date;
selectedOperation.Location = LocationEntry.Text;
selectedOperation.NumberOfPersonnel = int.Parse(NumberOfPersonnelEntry.Text);
selectedOperation.FinalReport = FinalReportEntry.Text;
await operationService.Update(selectedOperation);
var operation = this.operations.FirstOrDefault(x => x.ID == selectedOperation.ID);
operation.Name = NameEntry.Text;
operation.Status = Enum.Parse<OperationStatus>(StatusEntry.SelectedItem as string);
operation.DateStarted = DateStartedEntry.Date;
operation.Location = LocationEntry.Text;
operation.NumberOfPersonnel = int.Parse(NumberOfPersonnelEntry.Text);
operation.FinalReport = FinalReportEntry.Text;
}


selectedOperation = null;
ltv_operations.SelectedItem = null;
NameEntry.Text = "";
}

private async void DeleteButton_Clicked(object sender, EventArgs e)
{
if (ltv_operations.SelectedItem == null)
{
await Shell.Current.DisplayAlert("No Operation Selected", "Select the operation you want to delete from the list", "OK");
return;
}

await operationService.Remove(selectedOperation);
operations.Remove(selectedOperation);

ltv_operations.SelectedItem = null;
NameEntry.Text = "";
}

private void ltv_operations_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
selectedOperation = e.SelectedItem as Operation;
if (selectedOperation == null) return;

NameEntry.Text = selectedOperation.Name;
StatusEntry.SelectedItem = selectedOperation.Status.ToString();
DateStartedEntry.Date = selectedOperation.DateStarted;
LocationEntry.Text = selectedOperation.Location;
NumberOfPersonnelEntry.Text = selectedOperation.NumberOfPersonnel.ToString();
FinalReportEntry.Text = selectedOperation.FinalReport;

}
}