From 349589674f8511f931bcbd5cdeac0b648f00893f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?= <42814579+yunwah@users.noreply.github.com> Date: Mon, 11 Apr 2022 23:40:37 -0400 Subject: [PATCH] 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. --- OpheliasOasis/Managers/DatabaseManager.cs | 212 ++++++++++++++++++++++ OpheliasOasis/Managers/ResTableManager.cs | 38 ++++ OpheliasOasis/Managers/TxTableManager.cs | 22 +++ OpheliasOasis/Models/Guest.cs | 1 + OpheliasOasis/Models/Reservation.cs | 8 +- OpheliasOasis/Models/Transaction.cs | 50 +++-- OpheliasOasis/OpheliasOasis.sqlite | 0 OpheliasOasis/Program.cs | 94 +++++++++- 8 files changed, 395 insertions(+), 30 deletions(-) create mode 100644 OpheliasOasis/Managers/DatabaseManager.cs create mode 100644 OpheliasOasis/Managers/ResTableManager.cs create mode 100644 OpheliasOasis/Managers/TxTableManager.cs create mode 100644 OpheliasOasis/OpheliasOasis.sqlite diff --git a/OpheliasOasis/Managers/DatabaseManager.cs b/OpheliasOasis/Managers/DatabaseManager.cs new file mode 100644 index 0000000..9ff5be9 --- /dev/null +++ b/OpheliasOasis/Managers/DatabaseManager.cs @@ -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 queryComponents = new List(); + 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 queryComponents = new List(); + 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; + } + } +} diff --git a/OpheliasOasis/Managers/ResTableManager.cs b/OpheliasOasis/Managers/ResTableManager.cs new file mode 100644 index 0000000..4a19832 --- /dev/null +++ b/OpheliasOasis/Managers/ResTableManager.cs @@ -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); + + } + + + + } +} diff --git a/OpheliasOasis/Managers/TxTableManager.cs b/OpheliasOasis/Managers/TxTableManager.cs new file mode 100644 index 0000000..32a06d6 --- /dev/null +++ b/OpheliasOasis/Managers/TxTableManager.cs @@ -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; + } + } +} diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs index 681fdc8..58df59c 100644 --- a/OpheliasOasis/Models/Guest.cs +++ b/OpheliasOasis/Models/Guest.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Ophelias.Models; +using System.Net.Mail; namespace Ophelias.Models { diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs index 851c096..a3787ff 100644 --- a/OpheliasOasis/Models/Reservation.cs +++ b/OpheliasOasis/Models/Reservation.cs @@ -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 diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs index 598c9d6..44f9fc2 100644 --- a/OpheliasOasis/Models/Transaction.cs +++ b/OpheliasOasis/Models/Transaction.cs @@ -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 Transactions; diff --git a/OpheliasOasis/OpheliasOasis.sqlite b/OpheliasOasis/OpheliasOasis.sqlite new file mode 100644 index 0000000..e69de29 diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs index 20150ef..92aaad1 100644 --- a/OpheliasOasis/Program.cs +++ b/OpheliasOasis/Program.cs @@ -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; + } + } } } \ No newline at end of file