Skip to content
Open
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
19 changes: 15 additions & 4 deletions AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
xmlns:views="clr-namespace:MauiApp1.Views"
Shell.FlyoutBehavior="Disabled">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />
<TabBar>
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

<ShellContent
Title="Request Specialists"
ContentTemplate="{DataTemplate views:RequestSpecialists}" />

<ShellContent
Title="Accept Specialist Requests"
ContentTemplate="{DataTemplate views:AcceptSpecialistRequests}" />
</TabBar>

</Shell>
16 changes: 16 additions & 0 deletions DB-Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
Expand Down Expand Up @@ -61,4 +62,19 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Update="Views\RequestSpecialists.xaml.cs">
<DependentUpon>RequestSpecialists.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Views\AcceptSpecialistRequests.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\RequestSpecialists.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
22 changes: 18 additions & 4 deletions DatabaseInitialiser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.Xml.Linq;

/// <summary>
/// Initializes a SQLite database by creating the necessary tables.
Expand Down Expand Up @@ -85,7 +86,9 @@ private static List<string> GetTableCreationCommands()
"CREATE TABLE IF NOT EXISTS rota_type (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS equipment_type (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS organisation_type (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS order_status (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS organisation (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS person (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL, FieldName TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS order_status (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS resource_types (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS room_type (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS room_use_type (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
Expand All @@ -98,9 +101,20 @@ private static List<string> GetTableCreationCommands()
"CREATE TABLE IF NOT EXISTS assignment_status (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS position_status (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS role (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS skill (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS skill (Name TEXT NOT NULL PRIMARY KEY)",
"CREATE TABLE IF NOT EXISTS team_member (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS partner_agencies (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)"
};
"CREATE TABLE IF NOT EXISTS partner_agencies (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL)",
"CREATE TABLE IF NOT EXISTS skills_request (Id INTEGER PRIMARY KEY AUTOINCREMENT, skill_name TEXT, " +
"organisation_id INTEGER, request_date DATE, requested_by INTEGER, number_required INTEGER, " +
"start_date DATE, end_date DATE, status TEXT CHECK (status IN ('Pending', 'Approved'))," +
" confirmed_date DATE, FOREIGN KEY (skill_name) REFERENCES skill(Name), " +
"FOREIGN KEY (organisation_id) REFERENCES organisation(Id),FOREIGN KEY (requested_by) REFERENCES person(Id));"

//TEST Values for Specialist Requests
,"INSERT OR IGNORE INTO person (Id, Name, FieldName) VALUES (0,'John Doe', 'Healthcare');"
,"INSERT OR IGNORE INTO organisation (Id, Name) VALUES (0, 'No Organisation'),(2, 'Doctors Without Borders'),(2, 'Care'),(3, 'International Medical Corps');"
,"INSERT OR IGNORE INTO skill (Name) VALUES ('rescue'),('rebuild Infrastructure'),('mental & emotional support'),('first aid');"
//,"DROP TABLE IF EXISTS skills_request;"
};
}
}
44 changes: 34 additions & 10 deletions DatabaseOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,48 @@ public int GetRecordIdByName(string tableName, string name)
command.CommandText = commandText;
command.Parameters.AddWithValue("@name", name);

var result = command.ExecuteScalar();
var result = Convert.ToInt32(command.ExecuteScalar());

if (result != null && result is int id)
if (result is int id)
{
return id;
}

throw new Exception($"No record with the name '{name}' found in table '{tableName}'.");
throw new Exception($"No record with the name '{name}' found in table '{tableName}'." );
}


/// <summary>
/// Updates a record's name in the specified table based on the provided ID.
/// </summary>
/// <param name="tableName">Target table name.</param>
/// <param name="id">ID of the record to update.</param>
/// <param name="newName">New name to set for the record.</param>
public void UpdateRecord(string tableName, int id, string newName)
/// <summary>
/// Retrieves the name of a record from a specified table based on its ID.
/// </summary>
/// <param name="tableName">The table to search in.</param>
/// <param name="id">The id of the record to search for.</param>
/// <returns>The ID of the record if found; otherwise, throws an exception.</returns>
public string GetRecordNameById(string tableName, int id)
{
var commandText = $"SELECT Id FROM {tableName} WHERE Id = @Id LIMIT 1";

using var command = _connection.CreateCommand();
command.CommandText = commandText;
command.Parameters.AddWithValue("@Id", id);

var result = command.ExecuteScalar();

if (result != null && result is string name)
{
return name;
}

throw new Exception($"No record with the name '{id}' found in table '{tableName}'.");
}

/// <summary>
/// Updates a record's name in the specified table based on the provided ID.
/// </summary>
/// <param name="tableName">Target table name.</param>
/// <param name="id">ID of the record to update.</param>
/// <param name="newName">New name to set for the record.</param>
public void UpdateRecord(string tableName, int id, string newName)
{
var commandText = $"UPDATE {tableName} SET Name = @name WHERE Id = @id";
ExecuteNonQuery(commandText, ("@name", newName), ("@id", id));
Expand Down
22 changes: 22 additions & 0 deletions Models/SkillRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MauiApp1.Models
{
public class SkillRequest
{
public int Id { get; set; }
public string SkillName { get; set; }
public int OrganisationId { get; set; }
public DateTime RequestDate { get; set; }
public int RequestedBy { get; set; }
public int NumberRequired { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Status { get; set; }
public DateTime ConfirmedDate { get; set; }
}
}
41 changes: 41 additions & 0 deletions Services/ISpecialistRequestService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MauiApp1.Models;

namespace MauiApp1.Services
{
internal interface ISpecialistRequestService
{
/// <summary>
/// Inserts a new unapporved Specialist Request in the skills_request table
/// (confirmed_date can not be null so it is set to MinValue aswell as organisation.
/// requested_by is a dummy Value)
/// </summary>
/// <param name="skillName">Required Skill</param>
/// <param name="numberRequired">Number of Persons Required</param>
/// <param name="startDate">Start Date</param>
/// <param name="endDate">End Date</param>
void AddUnapprovedSkillRequest(string skillName, int numberRequired,
DateTime startDate,DateTime endDate);

/// <summary>
/// Returns a list of SkillRequest objects by Calling a
/// SELECT statement for skills_request
/// </summary>
/// <returns>A list of SkillRequest objects, created from the database</returns>
List<SkillRequest> GetAllSkillRequests();

/// <summary>
/// Approve Request by assingning the date of approval,
/// changing the Status to Approved, and Assignig the Corresponding Organisation
/// </summary>
/// <param name="id">Id of Request</param>
/// <param name="organisationId">Id of Organisation</param>
void approveSkillRequest(int id, int organisationId);

void deleteSkillRequestById(int id);
}
}
150 changes: 150 additions & 0 deletions Services/SpecialistRequestService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MauiApp1.Models;

namespace MauiApp1.Services
{
/// <summary>
/// Service to Apply the required SQL Statements to Add new
/// </summary>
internal class SpecialistRequestService : ISpecialistRequestService
{
private readonly SqliteConnection _connection;

/// <summary>
/// Creates a new database operation instance, initializing the connection to the SQLite database.
/// </summary>
/// <param name="connectionString">The SQLite database connection string.</param>
public SpecialistRequestService(string connectionString)
{
_connection = new SqliteConnection(connectionString);

try
{
_connection.Open();
}
catch (Exception ex)
{
throw new Exception("Error establishing database connection.", ex);
}
}

/// <summary>
/// Inserts a new unapporved Specialist Request in the skills_request table
/// (confirmed_date can not be null so it is set to MinValue aswell as organisation.
/// requested_by is a dummy Value)
/// </summary>
/// <param name="skillName">Required Skill</param>
/// <param name="numberRequired">Number of Persons Required</param>
/// <param name="startDate">Start Date</param>
/// <param name="endDate">End Date</param>
void ISpecialistRequestService.AddUnapprovedSkillRequest(string skillName, int numberRequired,
DateTime startDate, DateTime endDate)
{
var commandText = "INSERT INTO skills_request " +
"(skill_name, organisation_id, request_date, requested_by, number_required, " +
"start_date, end_date, status, confirmed_date) " +
"VALUES " +
"(@skill_name, @organisation_id, @request_date, @requested_by, @number_required, " +
"@start_date, @end_date, @status, @confirmed_date)";

using (var command = new SqliteCommand(commandText, _connection))
{
command.Parameters.AddWithValue("@skill_name", skillName);
command.Parameters.AddWithValue("@organisation_id", 0);
command.Parameters.AddWithValue("@request_date", DateTime.Today);
command.Parameters.AddWithValue("@requested_by", 0); // dummy value
command.Parameters.AddWithValue("@number_required", numberRequired);
command.Parameters.AddWithValue("@start_date", startDate);
command.Parameters.AddWithValue("@end_date", endDate);
command.Parameters.AddWithValue("@status", "Pending");
command.Parameters.AddWithValue("@confirmed_date", DateTime.MinValue);

command.ExecuteNonQuery();
}
}

/// <summary>
/// Approve Request by assingning the date of approval,
/// changing the Status to Approved, and Assignig the Corresponding Organisation
/// </summary>
/// <param name="id">Id of Request</param>
/// <param name="organisationId">Id of Organisation</param>
void ISpecialistRequestService.approveSkillRequest(int id, int organisationId)
{
var currentDate = DateTime.Today;
var commandText = "UPDATE skills_request SET confirmed_date = @currentDate," +
" organisation_id = @organisationId, status = 'Approved' WHERE Id = @id";

using (var command = new SqliteCommand(commandText, _connection))
{
command.Parameters.AddWithValue("@currentDate", currentDate);
command.Parameters.AddWithValue("@organisationId", organisationId);
command.Parameters.AddWithValue("@id", id);

command.ExecuteNonQuery();
}
}

/// <summary>
/// Returns a list of SkillRequest objects by Calling a
/// SELECT statement for skills_request
/// </summary>
/// <returns>A list of SkillRequest objects, created from the database</returns>
List<SkillRequest> ISpecialistRequestService.GetAllSkillRequests()
{
var skillRequests = new List<SkillRequest>();
var commandText = "SELECT * FROM skills_request";

using var command = _connection.CreateCommand();
command.CommandText = commandText;

using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
SkillRequest skillRequest = CreateSkillRequestFromReader(reader);
skillRequests.Add(skillRequest);
}
}
return skillRequests;
}

void ISpecialistRequestService.deleteSkillRequestById(int id)
{
var commandText = $"DELETE FROM skills_request WHERE Id = @id";
using (var command = new SqliteCommand(commandText, _connection))
{
command.Parameters.AddWithValue("@id", id);

command.ExecuteNonQuery();
}
}
/// <summary>
/// Creates one SkillRequest object by transfering
/// data from the reader.
/// </summary>
/// <param name="reader">Reading Database respose</param>
/// <returns></returns>
private SkillRequest CreateSkillRequestFromReader(SqliteDataReader reader)
{
return new SkillRequest
{
Id = reader.GetInt32(0),
SkillName = reader.GetString(1),
OrganisationId = reader.GetInt32(2),
RequestDate = reader.GetDateTime(3),
RequestedBy = reader.GetInt32(4),
NumberRequired = reader.GetInt32(5),
StartDate = reader.GetDateTime(6),
EndDate = reader.GetDateTime(7),
Status = reader.GetString(8),
ConfirmedDate = reader.GetDateTime(9)
};
}
}
}
Loading