WIP: Adds several core models needed for functionality #24
212
OpheliasOasis/Managers/DatabaseManager.cs
Normal file
212
OpheliasOasis/Managers/DatabaseManager.cs
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
using System.Data.SQLite;
|
||||||
|
using Ophelias.Models;
|
||||||
|
|
||||||
|
namespace Ophelias.Managers
|
||||||
|
{
|
||||||
|
internal class DatabaseManager : IDisposable
|
||||||
|
{
|
||||||
|
internal SQLiteConnection con = new SQLiteConnection("OpheliasOasis.sqlite");
|
||||||
|
internal SQLiteCommand? cur;
|
||||||
|
|
||||||
|
internal DatabaseManager()
|
||||||
|
{
|
||||||
|
cur = new SQLiteCommand(con);
|
||||||
|
}
|
||||||
|
internal void Connect()
|
||||||
|
{
|
||||||
|
con.Open();
|
||||||
|
}
|
||||||
|
internal void Close()
|
||||||
|
{
|
||||||
|
con.Close();
|
||||||
|
con.Dispose();
|
||||||
|
}
|
||||||
|
internal void InitializeTables()
|
||||||
|
{
|
||||||
|
if (cur == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string tableCommands =
|
||||||
|
@"CREATE TABLE IF NOT EXISTS [transactions] (
|
||||||
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
[Rate] INTEGER NOT NULL,
|
||||||
|
[Owed] INTEGER NOT NULL,
|
||||||
|
[Penalty] INTEGER NULL,
|
||||||
|
[Multiplier] INTEGER NOT NULL,
|
||||||
|
[RefundAmount] INTEGER NOT NULL,
|
||||||
|
[IsLate] BOOLEAN NOT NULL CHECK ([IsLate] IN (0,1)),
|
||||||
|
[PaidOff] BOOLEAN NOT NULL CHECK ([PaidOff] IN (0,1)),
|
||||||
|
[PayBy] TEXT NOT NULL,
|
||||||
|
[PaidOn] TEXT NULL);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS [reservations] (
|
||||||
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
[RoomID] INTEGER NOT NULL,
|
||||||
|
[GuestID] INTEGER NOT NULL,
|
||||||
|
[TransactionID] INTEGER NOT NULL,
|
||||||
|
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
|
||||||
|
[Type] INTEGER NOT NULL CHECK ([Type] IN (0,1,2,3)),
|
||||||
|
[Status] INTEGER NOT NULL CHECK ([Status] IN (0,1,2,3)),
|
||||||
|
[CreationDate] TEXT NOT NULL,
|
||||||
|
[StartDate] TEXT NOT NULL,
|
||||||
|
[EndDate] TEXT NOT NULL,
|
||||||
|
[CheckIn] TEXT NOT NULL,
|
||||||
|
[CheckOut] TEXT NOT NULL,
|
||||||
|
[DateChanged] TEXT NOT NULL,
|
||||||
|
FOREIGN KEY ([RoomID]) REFERENCES ROOMS(ID),
|
||||||
|
FOREIGN KEY ([GuestID]) REFERENCES GUESTS(ID),
|
||||||
|
FOREIGN KEY ([TransactionID]) REFERENCES TRANSACTIONS(ID));
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS [guests] (
|
||||||
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
[Fname] TEXT NOT NULL,
|
||||||
|
[Lname] TEXT NOT NULL,
|
||||||
|
[Email] TEXT NULL,
|
||||||
|
[Phone] TEXT NULL,
|
||||||
|
[CreditCard] TEXT NULL,
|
||||||
|
[CCV] TEXT NULL,
|
||||||
|
[CCExpiration] TEXT NULL);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS [rooms] (
|
||||||
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS [rates] (
|
||||||
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
[Rate] INTEGER NOT NULL,
|
||||||
|
[DateSet] TEXT NOT NULL);";
|
||||||
|
|
||||||
|
cur.CommandText = tableCommands;
|
||||||
|
cur.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void InitializeRoomsTable()
|
||||||
|
{
|
||||||
|
if (cur == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Initialize Rooms
|
||||||
|
for (int i = 1; i < 46; i++)
|
||||||
|
{
|
||||||
|
cur.CommandText = $"INSERT INTO ROOMS (ID) VALUES ({i});";
|
||||||
|
cur.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class DatabaseFunctions
|
||||||
|
{
|
||||||
|
internal static int GetLastId(SQLiteCommand cmd, string tableName)
|
||||||
|
{
|
||||||
|
if (cmd == null)
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=\"{tableName}\";";
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
reader.Read();
|
||||||
|
return reader.GetInt32(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal static int GetThirtyDayOccupancy(SQLiteCommand cmd, DateTime start)
|
||||||
|
{
|
||||||
|
if (cmd == null)
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
cmd.CommandText = $@"SELECT COUNT(*)
|
||||||
|
FROM reservations
|
||||||
|
WHERE StartDate => date({start.ToString("yyyy-MM-dd")}) AND EndDate <= date({start.AddDays(30).ToString("yyyy-MM-dd")});";
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
int thirtyDayOcc;
|
||||||
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
reader.Read();
|
||||||
|
thirtyDayOcc = reader.GetInt32(0);
|
||||||
|
}
|
||||||
|
return thirtyDayOcc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal static class QueryBuilder
|
||||||
|
{
|
||||||
|
|
||||||
|
internal static string? UpdateTransaction(int id,
|
||||||
|
double? rate = null, double? owed = null, double? penalty = null,
|
||||||
|
double? multiplier = null, double? refund = null, bool? isLate = null,
|
||||||
|
bool? paidOff = null, DateTime? paidBy = null, DateTime? paidOn = null)
|
||||||
|
{
|
||||||
|
List<string> queryComponents = new List<string>();
|
||||||
|
string query = "UPDATE transactions SET";
|
||||||
|
|
||||||
|
if (rate.HasValue)
|
||||||
|
queryComponents.Add($"Rate = {rate}");
|
||||||
|
if (owed.HasValue)
|
||||||
|
queryComponents.Add($"Owed = {owed}");
|
||||||
|
if (penalty.HasValue)
|
||||||
|
queryComponents.Add($"Penalty = {penalty}");
|
||||||
|
if (multiplier.HasValue)
|
||||||
|
queryComponents.Add($"Multiplier = {multiplier}");
|
||||||
|
if (refund.HasValue)
|
||||||
|
queryComponents.Add($"Refund = {refund}");
|
||||||
|
if (isLate.HasValue)
|
||||||
|
queryComponents.Add($"IsLate = {Convert.ToInt32(isLate)}");
|
||||||
|
if (paidOff.HasValue)
|
||||||
|
queryComponents.Add($"PaidOff = {Convert.ToInt32(paidOff)}");
|
||||||
|
if (paidBy.HasValue)
|
||||||
|
queryComponents.Add($"PaidBy = {paidBy.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
if (paidOn.HasValue)
|
||||||
|
queryComponents.Add($"PaidOn = {paidOn.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
|
||||||
|
if (queryComponents.Count == 0)
|
||||||
|
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string? UpdateReservation(int id,
|
||||||
|
int? roomid = null, int? guestid = null, int? transactionid = null, bool? isnoshow = null, ReservationType? type = null,
|
||||||
|
ReservationStatus? status = null, DateTime? creationdate = null, DateTime? startdate = null, DateTime? enddate = null,
|
||||||
|
DateTime? checkin = null, DateTime? checkout = null, DateTime? datechanged = null)
|
||||||
|
{
|
||||||
|
List<string> queryComponents = new List<string>();
|
||||||
|
string query = "UPDATE reservations SET";
|
||||||
|
|
||||||
|
if (roomid.HasValue)
|
||||||
|
queryComponents.Add($"RoomID = {roomid}");
|
||||||
|
if (guestid.HasValue)
|
||||||
|
queryComponents.Add($"GuestID = {guestid}");
|
||||||
|
if (transactionid.HasValue)
|
||||||
|
queryComponents.Add($"TransactionID = {transactionid}");
|
||||||
|
if (isnoshow.HasValue)
|
||||||
|
queryComponents.Add($"IsNoShow = {Convert.ToInt32(isnoshow)}");
|
||||||
|
if (type.HasValue)
|
||||||
|
queryComponents.Add($"Type = {(int)type}");
|
||||||
|
if (status.HasValue)
|
||||||
|
queryComponents.Add($"Type = {(int)status}");
|
||||||
|
if (creationdate.HasValue)
|
||||||
|
queryComponents.Add($"CreationDate = {creationdate.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
if (startdate.HasValue)
|
||||||
|
queryComponents.Add($"StartDate = {startdate.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
if (enddate.HasValue)
|
||||||
|
queryComponents.Add($"EndDate = {enddate.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
if (checkin.HasValue)
|
||||||
|
queryComponents.Add($"CheckIn = {checkin.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
if (checkout.HasValue)
|
||||||
|
queryComponents.Add($"CheckOut = {checkout.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
if (datechanged.HasValue)
|
||||||
|
queryComponents.Add($"CheckOut = {datechanged.Value.ToString("yyyy-MM-dd")}");
|
||||||
|
|
||||||
|
if (queryComponents.Count == 0)
|
||||||
|
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
OpheliasOasis/Managers/ResTableManager.cs
Normal file
38
OpheliasOasis/Managers/ResTableManager.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Ophelias.Managers;
|
||||||
|
using Ophelias.Models;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
|
||||||
|
namespace Ophelias.Managers
|
||||||
|
{
|
||||||
|
internal class ReservationTableManager
|
||||||
|
{
|
||||||
|
DatabaseManager dbManager;
|
||||||
|
SQLiteCommand? cur;
|
||||||
|
internal ReservationTableManager(DatabaseManager manager)
|
||||||
|
{
|
||||||
|
dbManager = manager;
|
||||||
|
cur = manager.cur;
|
||||||
|
}
|
||||||
|
internal void ChangeReservationDates(Reservation r, DateTime start, DateTime end)
|
||||||
|
{
|
||||||
|
string? query = QueryBuilder.UpdateReservation(id: r.Id, startdate: start, enddate: end, datechanged: DateTime.Now);
|
||||||
|
|
||||||
|
if (query == null)
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
query += QueryBuilder.UpdateTransaction(id: r.TransactionId, multiplier: 1.1);
|
||||||
|
|
||||||
|
|
||||||
|
QueryBuilder.UpdateTransaction(r.TransactionId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
22
OpheliasOasis/Managers/TxTableManager.cs
Normal file
22
OpheliasOasis/Managers/TxTableManager.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Ophelias.Managers;
|
||||||
|
using Ophelias.Models;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
|
||||||
|
namespace Ophelias.Managers
|
||||||
|
{
|
||||||
|
internal class TransactionTableManager
|
||||||
|
{
|
||||||
|
DatabaseManager dbManager;
|
||||||
|
SQLiteCommand? cur;
|
||||||
|
internal TransactionTableManager(DatabaseManager manager)
|
||||||
|
{
|
||||||
|
dbManager = manager;
|
||||||
|
cur = manager.cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ophelias.Models;
|
using Ophelias.Models;
|
||||||
|
using System.Net.Mail;
|
||||||
|
|
||||||
namespace Ophelias.Models
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
using System;
|
using Ophelias.Models;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Ophelias.Models;
|
|
||||||
|
|
||||||
namespace Ophelias.Models
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
@@ -58,6 +53,7 @@ namespace Ophelias.Models
|
|||||||
{
|
{
|
||||||
Status = ReservationStatus.Cancelled;
|
Status = ReservationStatus.Cancelled;
|
||||||
t.Penalize(this);
|
t.Penalize(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal enum ReservationStatus
|
internal enum ReservationStatus
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ophelias.Models;
|
using Ophelias.Models;
|
||||||
|
using Ophelias.Managers;
|
||||||
|
|
||||||
namespace Ophelias.Models
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
@@ -11,20 +12,17 @@ namespace Ophelias.Models
|
|||||||
{
|
{
|
||||||
private double PenaltyMultipler = 1.1;
|
private double PenaltyMultipler = 1.1;
|
||||||
|
|
||||||
internal int Id;
|
internal int Id { get; set; }
|
||||||
|
internal double Rate { get; set; }
|
||||||
internal double Rate;
|
internal double Paid { get; set; }
|
||||||
internal double Paid;
|
internal double Owed { get; set; }
|
||||||
internal double Owed;
|
internal double? Penalty { get; set; }
|
||||||
internal double? Penalty;
|
internal double Multiplier { get; set; }
|
||||||
internal double? Multiplier;
|
internal double RefundAmount { get; set; }
|
||||||
internal double RefundAmount;
|
internal bool? Late { get; set; }
|
||||||
|
internal bool PaidOff { get; set; }
|
||||||
internal bool? Late;
|
internal DateTime PayBy { get; set; }
|
||||||
internal bool PaidOff;
|
internal DateTime PaidOn { get; set; }
|
||||||
|
|
||||||
internal DateTime PayBy;
|
|
||||||
internal DateTime PaidOn;
|
|
||||||
|
|
||||||
internal Transaction(int id, Reservation r, DateTime payby)
|
internal Transaction(int id, Reservation r, DateTime payby)
|
||||||
{
|
{
|
||||||
@@ -155,6 +153,30 @@ namespace Ophelias.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static class TransactionFees
|
||||||
|
{
|
||||||
|
static double ConventionalFee = 1.0;
|
||||||
|
static double PrepaidFee = 0.75;
|
||||||
|
static double IncentiveFee = OccupancyIncentive();
|
||||||
|
static double SixtyDayFee = 0.85;
|
||||||
|
|
||||||
|
private static double OccupancyIncentive()
|
||||||
|
{
|
||||||
|
int thirtyDayOcc;
|
||||||
|
using (DatabaseManager dbm = new DatabaseManager())
|
||||||
|
{
|
||||||
|
if (dbm.cur == null)
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
thirtyDayOcc = DatabaseFunctions.GetThirtyDayOccupancy(dbm.cur, DateTime.Now);
|
||||||
|
}
|
||||||
|
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
|
||||||
|
return 0.80;
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
internal class TransactionList
|
internal class TransactionList
|
||||||
{
|
{
|
||||||
internal List<Transaction> Transactions;
|
internal List<Transaction> Transactions;
|
||||||
|
|||||||
0
OpheliasOasis/OpheliasOasis.sqlite
Normal file
0
OpheliasOasis/OpheliasOasis.sqlite
Normal file
@@ -1,18 +1,92 @@
|
|||||||
using Reservations
|
using Ophelias.Models;
|
||||||
|
using Ophelias.Managers;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
Reservation CreateReservation()
|
private static void GuestMode()
|
||||||
{
|
{
|
||||||
GuestInformation guestInformation = new GuestInformation();
|
Reservation? activeReservation = null;
|
||||||
Console.WriteLine
|
Guest? activeGuest = null;
|
||||||
Console.ReadLine()
|
TransactionTableManager tx = new TransactionTableManager(null);
|
||||||
|
tx.UpdateTransactionInfo(1);
|
||||||
|
void help()
|
||||||
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
"Reservation Commands:\n" +
|
||||||
|
"\treservation create\n" +
|
||||||
|
"\treservation update\n" +
|
||||||
|
"\treservation cancel\n" +
|
||||||
|
"Account Commands:" +
|
||||||
|
"\taccount create\n" +
|
||||||
|
"\taccount update\n" +
|
||||||
|
"Enter Q to quit.\n"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateNewReservation()
|
||||||
|
{
|
||||||
|
Reservation newReservation;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
"Welcome to the Ophelias Oasis Hotel Registration System!\n" +
|
||||||
|
"Type help to get a full list of commands or enter a command.\n" +
|
||||||
|
"Command: "
|
||||||
|
);
|
||||||
|
string? input = Console.ReadLine();
|
||||||
|
switch(input)
|
||||||
|
{
|
||||||
|
case "help": help(); break;
|
||||||
|
case "reservation create": break;
|
||||||
|
case "reservation update": break;
|
||||||
|
case "reservation cancel": break;
|
||||||
|
case "account update": break;
|
||||||
|
case "q": return;
|
||||||
|
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AdminMode()
|
||||||
|
{
|
||||||
|
void help()
|
||||||
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
"Report Commands:\n" +
|
||||||
|
"\treservation create\n" +
|
||||||
|
"\treservation update\n" +
|
||||||
|
"\treservation cancel\n" +
|
||||||
|
"Account Commands:" +
|
||||||
|
"\taccount create\n" +
|
||||||
|
"\taccount update\n" +
|
||||||
|
"Enter Q to quit.\n"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
SQLiteConnection.CreateFile("OpheliasOasis.sqlite");
|
||||||
"1. Employee\n" +
|
|
||||||
"2. Customer\n" +
|
bool run = true;
|
||||||
"Are you an employee or customer?: "
|
while (run)
|
||||||
);
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
"Are you an employee or customer?\n" +
|
||||||
|
"1. Employee\n" +
|
||||||
|
"2. Customer/ Guest"
|
||||||
|
);
|
||||||
|
switch(Console.ReadLine().ToUpper())
|
||||||
|
{
|
||||||
|
case "1": break;
|
||||||
|
case "2": GuestMode(); break;
|
||||||
|
case "Q": run = false; break;
|
||||||
|
default: Console.WriteLine("You must either specify 1 for Employee, 2 for Customer/ Guest, or Q to quit.\n\n"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user