Manager classes added and model updates

This commit introduces a large number of changes. Namely there are a
number of additions to a new set of classes that manage the database
and/ or the models shared between the code and databse. There is
fragmented non-functional code in this commit and there may be debug/
old code that still needs to be removed. This commit is just to version
these changes as they were not commited previously. There is also some
console interface code written, but has next to no functionality
attached to any existing prompts. More details will be published per .cs
file, ie specific manager or model, once they are finished as they are
undergoing rapid and significant changes regularly.
This commit is contained in:
雲華
2022-04-11 23:40:37 -04:00
parent f1a1b5d067
commit 349589674f
8 changed files with 395 additions and 30 deletions

View 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;
}
}
}

View 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);
}
}
}

View 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;
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using System.Net.Mail;
namespace Ophelias.Models
{

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using Ophelias.Models;
namespace Ophelias.Models
{
@@ -58,6 +53,7 @@ namespace Ophelias.Models
{
Status = ReservationStatus.Cancelled;
t.Penalize(this);
}
}
internal enum ReservationStatus

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using Ophelias.Managers;
namespace Ophelias.Models
{
@@ -11,20 +12,17 @@ namespace Ophelias.Models
{
private double PenaltyMultipler = 1.1;
internal int Id;
internal double Rate;
internal double Paid;
internal double Owed;
internal double? Penalty;
internal double? Multiplier;
internal double RefundAmount;
internal bool? Late;
internal bool PaidOff;
internal DateTime PayBy;
internal DateTime PaidOn;
internal int Id { get; set; }
internal double Rate { get; set; }
internal double Paid { get; set; }
internal double Owed { get; set; }
internal double? Penalty { get; set; }
internal double Multiplier { get; set; }
internal double RefundAmount { get; set; }
internal bool? Late { get; set; }
internal bool PaidOff { get; set; }
internal DateTime PayBy { get; set; }
internal DateTime PaidOn { get; set; }
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 List<Transaction> Transactions;

View File

View File

@@ -1,18 +1,92 @@
using Reservations
using Ophelias.Models;
using Ophelias.Managers;
using System.Data.SQLite;
class Program
{
Reservation CreateReservation()
private static void GuestMode()
{
GuestInformation guestInformation = new GuestInformation();
Console.WriteLine
Console.ReadLine()
Reservation? activeReservation = null;
Guest? activeGuest = null;
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()
{
Console.WriteLine(
"1. Employee\n" +
"2. Customer\n" +
"Are you an employee or customer?: "
);
SQLiteConnection.CreateFile("OpheliasOasis.sqlite");
bool run = true;
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;
}
}
}
}