From 91825d0292766734d92c8c5100fbf60eb6513fb6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Wed, 6 Apr 2022 02:20:59 -0400
Subject: [PATCH 01/10] Adds several core models needed for functionality
This commit includes the following models:
- Guest
- Reservation
- Room
- Transaction
The guest model is used to represent a guest which will create a unique
guest entry represented through its ID. The model also collects
represents and reflects a guests first and last name and their personal
information including email and credit card, phone number still needs to
be included.
The reservation model focuses on #9. See the issue for more specific
details. The changes made to better define this model include changing
the original Cancellation variable to a more meaningful one called
Status. The Status variable can either be Active, Changed, or Cancelled
and enums are used as a better approach than creating and setting an int
value for an int variable. The same approach was used for the
reservation types. Furthermore, the original model was missing the
StartDate and EndDate, confusing them for the CheckIn and CheckOut date,
which can, but is not guaranteed to be identical. NoShow was moved from
the transaction model to the reservation model because it made more
sense.
The Transaction and Room models are currently empty and were created in
preperation of work. Transaction, formerly Payments, did have a model
built, however git stash did not properly store these changes.
Additional changes include the beginning of working on the main
Program.cs, however, this was mostly to ensure that the console was
outputting and the project was building.
Other (less important) notes...
A .gitignore has been added for C#, this is modified to include .vs
files since they are mostly cache files. If this breaks the project it
can always be dropped later.
The project file itself has been versioned, it may not play nice on
other machines, but ideally should be fine and nothing should go wrong
when running the project file.
---
.gitignore | 137 ++++++++++++++++++++++++++++
OpheliasOasis.sln | 25 +++++
OpheliasOasis/Models/Guest.cs | 34 +++++++
OpheliasOasis/Models/Reservation.cs | 65 +++++++++++++
OpheliasOasis/Models/Room.cs | 12 +++
OpheliasOasis/Models/Transaction.cs | 12 +++
OpheliasOasis/OpheliasOasis.csproj | 14 +++
OpheliasOasis/Program.cs | 18 ++++
8 files changed, 317 insertions(+)
create mode 100644 .gitignore
create mode 100644 OpheliasOasis.sln
create mode 100644 OpheliasOasis/Models/Guest.cs
create mode 100644 OpheliasOasis/Models/Reservation.cs
create mode 100644 OpheliasOasis/Models/Room.cs
create mode 100644 OpheliasOasis/Models/Transaction.cs
create mode 100644 OpheliasOasis/OpheliasOasis.csproj
create mode 100644 OpheliasOasis/Program.cs
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5f36235
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,137 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.svclog
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Visual Studio cache files
+*.vs
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+*.azurePubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+packages/
+## TODO: If the tool you use requires repositories.config, also uncomment the next line
+!packages/repositories.config
+
+# Windows Azure Build Output
+csx/
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+![Ss]tyle[Cc]op.targets
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+# =========================
+# Windows detritus
+# =========================
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac desktop service store files
+.DS_Store
+
+_NCrunch*
+
diff --git a/OpheliasOasis.sln b/OpheliasOasis.sln
new file mode 100644
index 0000000..e96a389
--- /dev/null
+++ b/OpheliasOasis.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.1.32328.378
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpheliasOasis", "OpheliasOasis\OpheliasOasis.csproj", "{69288F69-68F7-4A9E-A740-507AE1CBF6CF}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {69288F69-68F7-4A9E-A740-507AE1CBF6CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {69288F69-68F7-4A9E-A740-507AE1CBF6CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {69288F69-68F7-4A9E-A740-507AE1CBF6CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {69288F69-68F7-4A9E-A740-507AE1CBF6CF}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A72041BE-1FE9-4C15-AED6-91C0217466EA}
+ EndGlobalSection
+EndGlobal
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
new file mode 100644
index 0000000..d0e91f9
--- /dev/null
+++ b/OpheliasOasis/Models/Guest.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ophelias.Guest.Models
+{
+ internal class Guest
+ {
+ internal int Id;
+ internal string FirstName;
+ internal string LastName;
+ internal string Email;
+ internal string? CreditCard;
+
+ internal Guest(int id, string fname, string lname, string email)
+ {
+ Id = id;
+ FirstName = fname;
+ LastName = lname;
+ Email = email;
+ }
+ internal Guest(int id, string fname, string lname, string email, string cc)
+ {
+ Id = id;
+ FirstName = fname;
+ LastName = lname;
+ Email = email;
+ CreditCard = cc;
+ }
+
+ }
+}
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
new file mode 100644
index 0000000..28d0ace
--- /dev/null
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Oasis.Reservation.Models
+{
+ internal class Reservation
+ {
+ internal int Id;
+ internal int RoomId;
+ internal int GuestId;
+ internal int TransactionId;
+
+ internal bool IsNoShow;
+
+ internal ReservationType Type;
+ internal ReservationStatus Status;
+
+ internal DateTime CreationDate;
+ internal DateTime StartDate;
+ internal DateTime EndDate;
+
+ internal DateTime? CheckIn;
+ internal DateTime? CheckOut;
+ internal DateTime? DateChanged;
+
+ internal Reservation(int id, int gid, int tid, int room, ReservationType type, ReservationStatus status,
+ DateTime startdate, DateTime enddate)
+ {
+ Id = id;
+ RoomId = room;
+ GuestId = gid;
+ TransactionId = tid;
+
+ IsNoShow = false;
+
+ Type = type;
+ Status = status;
+
+ CreationDate = DateTime.Now;
+ StartDate = startdate;
+ EndDate = enddate;
+
+ CheckIn = null;
+ CheckOut = null;
+ DateChanged = null;
+ }
+ }
+
+ internal enum ReservationStatus
+ {
+ Active,
+ Changed,
+ Cancelled,
+ }
+ internal enum ReservationType
+ {
+ Conventional,
+ Prepaid,
+ Incentive,
+ SixtyDayAdvance,
+ }
+}
diff --git a/OpheliasOasis/Models/Room.cs b/OpheliasOasis/Models/Room.cs
new file mode 100644
index 0000000..505d30e
--- /dev/null
+++ b/OpheliasOasis/Models/Room.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpheliasOasis.Models
+{
+ internal class Class1
+ {
+ }
+}
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
new file mode 100644
index 0000000..d2b458d
--- /dev/null
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpheliasOasis
+{
+ internal class Class1
+ {
+ }
+}
diff --git a/OpheliasOasis/OpheliasOasis.csproj b/OpheliasOasis/OpheliasOasis.csproj
new file mode 100644
index 0000000..beb2f6a
--- /dev/null
+++ b/OpheliasOasis/OpheliasOasis.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs
new file mode 100644
index 0000000..20150ef
--- /dev/null
+++ b/OpheliasOasis/Program.cs
@@ -0,0 +1,18 @@
+using Reservations
+class Program
+{
+ Reservation CreateReservation()
+ {
+ GuestInformation guestInformation = new GuestInformation();
+ Console.WriteLine
+ Console.ReadLine()
+ }
+ static void Main()
+ {
+ Console.WriteLine(
+ "1. Employee\n" +
+ "2. Customer\n" +
+ "Are you an employee or customer?: "
+ );
+ }
+}
\ No newline at end of file
From c1526a123f8d460fa7740aad4add26f8f4412070 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Fri, 8 Apr 2022 15:23:48 -0400
Subject: [PATCH 02/10] Updated and added various models
This commit includes functionality for many of the models that the
program will use. The transaction model, rate, and room model have been
implemented, but still need further review to determine if they are
finished. The same applies to guest and reservation. Currently all
models include a simple list class, the decision to use a database or
a serialized object (JSON, array, list, etc). These lists are currently
a placeholder and are not guaranteed to land in main.
---
OpheliasOasis/Models/Guest.cs | 11 ++-
OpheliasOasis/Models/Rate.cs | 33 +++++++
OpheliasOasis/Models/Reservation.cs | 23 ++++-
OpheliasOasis/Models/Room.cs | 20 +++-
OpheliasOasis/Models/Transaction.cs | 137 +++++++++++++++++++++++++++-
5 files changed, 218 insertions(+), 6 deletions(-)
create mode 100644 OpheliasOasis/Models/Rate.cs
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
index d0e91f9..2bdc344 100644
--- a/OpheliasOasis/Models/Guest.cs
+++ b/OpheliasOasis/Models/Guest.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace Ophelias.Guest.Models
+namespace Ophelias.Models
{
internal class Guest
{
@@ -31,4 +31,13 @@ namespace Ophelias.Guest.Models
}
}
+ internal class GuestList
+ {
+ internal List Guests;
+
+ internal GuestList()
+ {
+ Guests = new List();
+ }
+ }
}
diff --git a/OpheliasOasis/Models/Rate.cs b/OpheliasOasis/Models/Rate.cs
new file mode 100644
index 0000000..40253e6
--- /dev/null
+++ b/OpheliasOasis/Models/Rate.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Ophelias.Models;
+
+namespace Ophelias.Models
+{
+ internal class BaseRate
+ {
+ internal int Id;
+ internal double Rate;
+ internal DateTime DateSet;
+
+ internal BaseRate(int id, double rate)
+ {
+ Id = id;
+ Rate = rate;
+ DateSet = DateTime.Now;
+ }
+ }
+
+ internal class Rates
+ {
+ internal List BaseRates;
+
+ internal Rates()
+ {
+ BaseRates = new List();
+ }
+ }
+}
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index 28d0ace..0e628d6 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Ophelias.Models;
-namespace Oasis.Reservation.Models
+namespace Ophelias.Models
{
internal class Reservation
{
@@ -47,13 +48,22 @@ namespace Oasis.Reservation.Models
CheckOut = null;
DateChanged = null;
}
+ internal void ChangeReservation(ReservationType type)
+ {
+ Status = ReservationStatus.Changed;
+ Type = type;
+ }
+ internal void CancelReservation()
+ {
+ Status = ReservationStatus.Cancelled;
+ }
}
-
internal enum ReservationStatus
{
Active,
Changed,
Cancelled,
+ Ended,
}
internal enum ReservationType
{
@@ -62,4 +72,13 @@ namespace Oasis.Reservation.Models
Incentive,
SixtyDayAdvance,
}
+ internal class ReservationList
+ {
+ internal List Reservations;
+
+ internal ReservationList()
+ {
+ Reservations = new List();
+ }
+ }
}
diff --git a/OpheliasOasis/Models/Room.cs b/OpheliasOasis/Models/Room.cs
index 505d30e..d1bbe2e 100644
--- a/OpheliasOasis/Models/Room.cs
+++ b/OpheliasOasis/Models/Room.cs
@@ -6,7 +6,25 @@ using System.Threading.Tasks;
namespace OpheliasOasis.Models
{
- internal class Class1
+ internal class Room
{
+ internal int Id;
+ internal bool Occupied;
+
+ internal Room(int id)
+ {
+ Id = id;
+ Occupied = false;
+ }
+ }
+
+ internal class RoomList
+ {
+ internal List Rooms;
+
+ internal RoomList()
+ {
+ Rooms = new List();
+ }
}
}
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index d2b458d..887f4ee 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -3,10 +3,143 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Ophelias.Models;
-namespace OpheliasOasis
+namespace Ophelias.Models
{
- internal class Class1
+ internal class Transaction
{
+ 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 Transaction(int id, ReservationType type, DateTime payby)
+ {
+ Id = id;
+ Paid = 0;
+ Owed = 0;
+ RefundAmount = 0;
+ PaidOff = false;
+ PayBy = payby;
+ Multiplier = Fee(type);
+ }
+ private bool IsOverdue()
+ {
+ if (DateTime.Now > PayBy)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ private void SetChangeFees(ReservationType type, double rate)
+ {
+ switch (type)
+ {
+ case ReservationType.Conventional: return;
+ case ReservationType.Prepaid: SetFee(PenaltyMultipler); SetRate(rate); return;
+ case ReservationType.Incentive: return;
+ case ReservationType.SixtyDayAdvance: SetFee(PenaltyMultipler); SetRate(rate); return;
+ default: throw new NotImplementedException();
+ }
+ }
+ private void CancellationHandler(ReservationType type)
+ {
+ void SetRefund()
+ {
+ if (DateTime.Now.AddDays(+3).Day <= PayBy.Day)
+ {
+ RefundAmount = Paid;
+ Paid = 0;
+ Owed = 0;
+ PaidOff = false;
+ }
+ }
+
+ switch (type)
+ {
+ case ReservationType.Conventional: SetRefund(); return;
+ case ReservationType.Prepaid: return;
+ case ReservationType.Incentive: SetRefund(); return;
+ case ReservationType.SixtyDayAdvance: return;
+ default: throw new NotImplementedException();
+ }
+ }
+
+ internal void Penalize(ReservationStatus status, ReservationType type, double rate)
+ {
+ switch(status)
+ {
+ case ReservationStatus.Active: IsOverdue(); return;
+ case ReservationStatus.Cancelled: CancellationHandler(type); return;
+ case ReservationStatus.Changed: SetChangeFees(type, rate); return;
+ }
+ }
+ internal double Fee(ReservationType type)
+ {
+ switch (type)
+ {
+ case ReservationType.Conventional: return 1.0;
+ case ReservationType.Prepaid: return 0.75;
+ case ReservationType.Incentive: return 1.0;
+ case ReservationType.SixtyDayAdvance: return 0.85;
+ default: throw new NotImplementedException();
+ }
+ }
+ internal void SetFee(double mult)
+ {
+ Multiplier = mult;
+ }
+ internal void SetRate(double rate)
+ {
+ Rate = rate;
+ }
+
+ internal void Pay(double amount)
+ {
+ if (RefundAmount > -1)
+ {
+ return;
+ }
+ Paid += amount;
+ if (Paid == Owed)
+ {
+ Owed -= Paid;
+ PaidOn = DateTime.Now;
+ PaidOff = true;
+ } else if (Paid > Owed)
+ {
+ RefundAmount = Paid - Owed;
+ Owed = Owed - Paid + RefundAmount;
+ PaidOn = DateTime.Now;
+ PaidOff = true;
+ } else
+ {
+ Owed -= Paid;
+ PaidOn = DateTime.Now;
+ }
+ }
+ }
+ internal class TransactionList
+ {
+ internal List Transactions;
+
+ internal TransactionList()
+ {
+ Transactions = new List();
+ }
}
}
From f1a1b5d067bcfba780f3c45bb67af29d8b5408d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Sat, 9 Apr 2022 04:45:42 -0400
Subject: [PATCH 03/10] Update models with more functionality
This is a small commit that aims to add some more descriptive
functionality to the models.
Guest now has more creditcard information
such as CCV and an expiration date to bring it in-line with what would
be expected.
Reservation implemented a very loose cancellation function,
this may be moved out.
Transaction has a few more tweaks that follows the same goal as guest,
however this functionality may be migrated as well.
---
OpheliasOasis/Models/Guest.cs | 18 +++++++++--
OpheliasOasis/Models/Reservation.cs | 6 ++--
OpheliasOasis/Models/Transaction.cs | 48 +++++++++++++++++++++--------
3 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
index 2bdc344..681fdc8 100644
--- a/OpheliasOasis/Models/Guest.cs
+++ b/OpheliasOasis/Models/Guest.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Ophelias.Models;
namespace Ophelias.Models
{
@@ -12,24 +13,35 @@ namespace Ophelias.Models
internal string FirstName;
internal string LastName;
internal string Email;
+ internal string PhoneNumber;
internal string? CreditCard;
+ internal string? CCV;
+ internal DateTime CreditCardExpiration;
- internal Guest(int id, string fname, string lname, string email)
+ internal Guest(int id, string fname, string lname, string email, string phone)
{
Id = id;
FirstName = fname;
LastName = lname;
Email = email;
+ PhoneNumber = phone;
}
- internal Guest(int id, string fname, string lname, string email, string cc)
+ internal Guest(int id, string fname, string lname, string email, string phone, string cc, DateTime expiration, string ccv)
{
Id = id;
FirstName = fname;
LastName = lname;
Email = email;
+ PhoneNumber = phone;
CreditCard = cc;
+ CreditCardExpiration = expiration;
+ }
+ internal void SetCreditCardInformation(string cc, DateTime expiration, string ccv)
+ {
+ CreditCard = cc;
+ CreditCardExpiration = expiration;
+ CCV = ccv;
}
-
}
internal class GuestList
{
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index 0e628d6..851c096 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -48,14 +48,16 @@ namespace Ophelias.Models
CheckOut = null;
DateChanged = null;
}
- internal void ChangeReservation(ReservationType type)
+ internal void ChangeReservation(ReservationType type, Transaction t, BaseRate b)
{
Status = ReservationStatus.Changed;
Type = type;
+ t.Penalize(this, b.Rate);
}
- internal void CancelReservation()
+ internal void CancelReservation(Transaction t)
{
Status = ReservationStatus.Cancelled;
+ t.Penalize(this);
}
}
internal enum ReservationStatus
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index 887f4ee..598c9d6 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -26,15 +26,15 @@ namespace Ophelias.Models
internal DateTime PayBy;
internal DateTime PaidOn;
- internal Transaction(int id, ReservationType type, DateTime payby)
+ internal Transaction(int id, Reservation r, DateTime payby)
{
Id = id;
Paid = 0;
Owed = 0;
RefundAmount = 0;
PaidOff = false;
- PayBy = payby;
- Multiplier = Fee(type);
+ PayBy = SetPayByDate(r);
+ Multiplier = Fee(r.Type);
}
private bool IsOverdue()
{
@@ -44,7 +44,17 @@ namespace Ophelias.Models
}
return false;
}
-
+ private DateTime SetPayByDate(Reservation r)
+ {
+ switch(r.Type)
+ {
+ case ReservationType.Conventional: return r.EndDate;
+ case ReservationType.Prepaid: return r.StartDate;
+ case ReservationType.Incentive: return r.EndDate;
+ case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30);
+ default: throw new NotImplementedException();
+ }
+ }
private void SetChangeFees(ReservationType type, double rate)
{
switch (type)
@@ -78,32 +88,44 @@ namespace Ophelias.Models
default: throw new NotImplementedException();
}
}
-
- internal void Penalize(ReservationStatus status, ReservationType type, double rate)
+ internal void Penalize(Reservation r)
{
- switch(status)
+ switch (r.Status)
{
case ReservationStatus.Active: IsOverdue(); return;
- case ReservationStatus.Cancelled: CancellationHandler(type); return;
- case ReservationStatus.Changed: SetChangeFees(type, rate); return;
+ case ReservationStatus.Ended: IsOverdue(); return;
+ case ReservationStatus.Cancelled: CancellationHandler(r.Type); return;
+ default: throw new NotImplementedException();
}
}
- internal double Fee(ReservationType type)
+ internal void Penalize(Reservation r, double rate)
+ {
+ switch(r.Status)
+ {
+ case ReservationStatus.Changed: SetChangeFees(r.Type, rate); return;
+ default: throw new NotImplementedException();
+ }
+ }
+ private double Fee(ReservationType type)
{
switch (type)
{
case ReservationType.Conventional: return 1.0;
case ReservationType.Prepaid: return 0.75;
- case ReservationType.Incentive: return 1.0;
+ case ReservationType.Incentive: return GetIncentiveRate();
case ReservationType.SixtyDayAdvance: return 0.85;
default: throw new NotImplementedException();
}
}
- internal void SetFee(double mult)
+ private double GetIncentiveRate()
+ {
+ return 0.80;
+ }
+ private void SetFee(double mult)
{
Multiplier = mult;
}
- internal void SetRate(double rate)
+ private void SetRate(double rate)
{
Rate = rate;
}
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 04/10] 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
From 306ac411b314bb6ae7ecb20d21a998d195a6a527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Wed, 13 Apr 2022 02:59:21 -0400
Subject: [PATCH 05/10] Further major refactoring of code
This is another commit to mostly version the code. There have been a
considerable number of changes and there is functionality that I am
still determining whether it should lie within the manager or the model
class itself. It makes the most sense to possibly add the "Update" or
database manipulation functions on the models themselves. On the other
hand, instead of creating and generating the ID in the model, the
current design is to create the entry in the database first, get the
last insert row ID and create a new and complete model that is returned
back by the function. This allows us to leverage the autoincrement
functionality of the database rather than trying to design a function
and/ or make an additional call to the database.
**NOTE: Code is non-functional due to some classes not having their
errors resolved.
---
OpheliasOasis/Managers/DatabaseManager.cs | 135 ++++++++++----------
OpheliasOasis/Managers/HotelManager.cs | 133 ++++++++++++++++++++
OpheliasOasis/Managers/ResTableManager.cs | 24 +---
OpheliasOasis/Managers/TxTableManager.cs | 1 -
OpheliasOasis/Models/Guest.cs | 37 +++---
OpheliasOasis/Models/Reservation.cs | 29 ++---
OpheliasOasis/Models/Transaction.cs | 142 ++++++----------------
OpheliasOasis/OpheliasOasis.sqlite | 0
OpheliasOasis/Program.cs | 102 ++++++++++++++--
OpheliasOasis/Validation.cs | 49 ++++++++
10 files changed, 397 insertions(+), 255 deletions(-)
create mode 100644 OpheliasOasis/Managers/HotelManager.cs
delete mode 100644 OpheliasOasis/OpheliasOasis.sqlite
create mode 100644 OpheliasOasis/Validation.cs
diff --git a/OpheliasOasis/Managers/DatabaseManager.cs b/OpheliasOasis/Managers/DatabaseManager.cs
index 9ff5be9..253eca7 100644
--- a/OpheliasOasis/Managers/DatabaseManager.cs
+++ b/OpheliasOasis/Managers/DatabaseManager.cs
@@ -5,12 +5,11 @@ namespace Ophelias.Managers
{
internal class DatabaseManager : IDisposable
{
- internal SQLiteConnection con = new SQLiteConnection("OpheliasOasis.sqlite");
- internal SQLiteCommand? cur;
+ internal SQLiteConnection con = new SQLiteConnection("DataSource=database.sqlite3;Version=3;");
internal DatabaseManager()
{
- cur = new SQLiteCommand(con);
+ Connect();
}
internal void Connect()
{
@@ -23,9 +22,6 @@ namespace Ophelias.Managers
}
internal void InitializeTables()
{
- if (cur == null)
- return;
-
string tableCommands =
@"CREATE TABLE IF NOT EXISTS [transactions] (
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -34,8 +30,6 @@ namespace Ophelias.Managers
[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);
@@ -61,35 +55,40 @@ namespace Ophelias.Managers
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[Fname] TEXT NOT NULL,
[Lname] TEXT NOT NULL,
- [Email] TEXT NULL,
- [Phone] TEXT NULL,
+ [Email] TEXT NOT NULL,
[CreditCard] TEXT NULL,
- [CCV] TEXT NULL,
- [CCExpiration] TEXT NULL);
+ [Expiration] TEXT NULL,
+ [CCV] TEXT NULL);
CREATE TABLE IF NOT EXISTS [rooms] (
- [ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);
+ [ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ [Occupied] BOOLEAN NOT NULL CHECK ([Occupied] IN (0,1)));
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();
+ using (SQLiteCommand cmd = con.CreateCommand())
+ {
+ cmd.CommandText = tableCommands;
+ cmd.ExecuteNonQuery();
+ }
}
internal void InitializeRoomsTable()
{
- if (cur == null)
- return;
+ using (SQLiteCommand cmd = con.CreateCommand())
+ {
+ for (int i = 1; i < 46; i++)
+ {
+ cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
+ cmd.ExecuteNonQuery();
+ }
+ }
// Initialize Rooms
- for (int i = 1; i < 46; i++)
- {
- cur.CommandText = $"INSERT INTO ROOMS (ID) VALUES ({i});";
- cur.ExecuteNonQuery();
- }
+
}
public void Dispose()
{
@@ -99,66 +98,33 @@ namespace Ophelias.Managers
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)
+ double? Rate = null, double? Owed = null, double? Penalty = null,
+ double? Multiplier = null, double? Refund = null,
+ DateTime? PayBy = 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 (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 (PayBy.HasValue)
+ queryComponents.Add($"PaidBy = {PayBy.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};";
@@ -208,5 +174,30 @@ namespace Ophelias.Managers
return query;
}
+
+ internal static string CreateTransaction(double Rate, double Owed, double Penalty,
+ double Multiplier, double Refund, bool isLate,
+ bool PaidOff, DateTime PaidBy, DateTime? PaidOn = null)
+ {
+
+ return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, Refund, IsLate, PaidOff, PaidBy, PaidOn)
+ VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {isLate}, {PaidOff}, {PaidBy}, {PaidOn});";
+ }
+
+ internal static string CreateReservation(int roomid, int guestid, int transactionid, bool isnoshow, ReservationType type,
+ ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
+ DateTime checkin, DateTime checkout, DateTime datechanged)
+ {
+ return @$"INSERT INTO reservations (RoomID, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
+ VALUES ({roomid}, {guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
+ }
+
+ internal static string CreateGuest(string FirstName, string LastName, string Email, string? CreditCard, string? Expiration, string? CCV)
+ {
+ if (CreditCard != null && Expiration != null && CCV != null)
+ return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ({FirstName}, {LastName}, {Email});";
+ else
+ return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ({FirstName}, {LastName}, {Email}, {CreditCard}, {Expiration}, {CCV});";
+ }
}
}
diff --git a/OpheliasOasis/Managers/HotelManager.cs b/OpheliasOasis/Managers/HotelManager.cs
new file mode 100644
index 0000000..cdd393a
--- /dev/null
+++ b/OpheliasOasis/Managers/HotelManager.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Ophelias.Models;
+using System.Data.SQLite;
+
+namespace Ophelias.Managers
+{
+ internal static class HotelManager
+ {
+ internal static int GetLastId(string tableName)
+ {
+ int lastId = 0;
+ using (DatabaseManager manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = manager.con.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=\"{tableName}\";";
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ lastId = reader.GetInt32(0);
+ }
+ }
+ }
+ return lastId;
+ }
+ internal static int GetThirtyDayOccupancy(DateTime start)
+ {
+ int thirtyDayOcc;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand()) {
+ 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();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ thirtyDayOcc = reader.GetInt32(0);
+ }
+ }
+ }
+
+ return thirtyDayOcc;
+ }
+ internal static int CreateReservation(int roomid, int guestid, int transactionid, bool isnoshow, ReservationType type,
+ ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
+ DateTime checkin, DateTime checkout, DateTime datechanged)
+ {
+ int id;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = QueryBuilder.CreateReservation(roomid, guestid, transactionid, isnoshow, type,
+ status, creationdate, startdate, enddate,
+ checkin, checkout, datechanged);
+ cmd.ExecuteNonQuery();
+ }
+ id = (int)Manager.con.LastInsertRowId;
+ }
+ return id;
+ }
+ internal static void ChangeReservationDates(Reservation r, Transaction t, DateTime start, DateTime end)
+ {
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string? query = QueryBuilder.UpdateReservation(id: r.Id, startdate: start, enddate: end, datechanged: DateTime.Now);
+
+ if (query == null)
+ throw new Exception();
+
+ query += QueryBuilder.UpdateTransaction(id: r.TransactionId, Multiplier: 1.1);
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ internal static Transaction CreateTransaction(double Rate, double Owed, double Penalty,
+ double Multiplier, double Refund, bool isLate,
+ bool PaidOff, DateTime PaidBy, DateTime? PaidOn = null)
+ {
+ int Id;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Penalty, Multiplier, Refund, isLate, PaidOff, PaidBy, PaidOn);
+ cmd.ExecuteNonQuery();
+ }
+ Id = (int)Manager.con.LastInsertRowId;
+ }
+ return new Transaction(Id, Rate, Owed, Penalty, Multiplier, Refund, PaidBy, PaidOn);
+ }
+ internal static int CheckInGuest(DateTime CheckIn)
+ {
+ return 1;
+ }
+ internal static int CheckOutGuest(DateTime CheckOut)
+ {
+ return 1;
+ }
+
+ internal static Guest CreateGuest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
+ {
+ string query = QueryBuilder.CreateGuest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
+
+ int Id;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = QueryBuilder.CreateGuest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
+ cmd.ExecuteNonQuery();
+ }
+ Id = (int)Manager.con.LastInsertRowId;
+ }
+
+ if (CreditCard != null && Expiration != null && CCV != null)
+ return new Guest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
+ else
+ return new Guest(FirstName, LastName, Email);
+ }
+ }
+}
diff --git a/OpheliasOasis/Managers/ResTableManager.cs b/OpheliasOasis/Managers/ResTableManager.cs
index 4a19832..16eb956 100644
--- a/OpheliasOasis/Managers/ResTableManager.cs
+++ b/OpheliasOasis/Managers/ResTableManager.cs
@@ -9,30 +9,8 @@ using System.Data.SQLite;
namespace Ophelias.Managers
{
- internal class ReservationTableManager
+ internal static 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
index 32a06d6..27499f1 100644
--- a/OpheliasOasis/Managers/TxTableManager.cs
+++ b/OpheliasOasis/Managers/TxTableManager.cs
@@ -16,7 +16,6 @@ namespace Ophelias.Managers
internal TransactionTableManager(DatabaseManager manager)
{
dbManager = manager;
- cur = manager.cur;
}
}
}
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
index 58df59c..2fc8042 100644
--- a/OpheliasOasis/Models/Guest.cs
+++ b/OpheliasOasis/Models/Guest.cs
@@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
-using System.Net.Mail;
namespace Ophelias.Models
{
@@ -14,34 +13,30 @@ namespace Ophelias.Models
internal string FirstName;
internal string LastName;
internal string Email;
- internal string PhoneNumber;
internal string? CreditCard;
internal string? CCV;
- internal DateTime CreditCardExpiration;
+ internal string? Expiration;
- internal Guest(int id, string fname, string lname, string email, string phone)
+ internal Guest(string FirstName, string LastName, string Email)
{
- Id = id;
- FirstName = fname;
- LastName = lname;
- Email = email;
- PhoneNumber = phone;
+ this.FirstName = FirstName;
+ this.LastName = LastName;
+ this.Email = Email;
}
- internal Guest(int id, string fname, string lname, string email, string phone, string cc, DateTime expiration, string ccv)
+ internal Guest(string FirstName, string LastName, string Email, string CreditCard, string Expiration, string CCV)
{
- Id = id;
- FirstName = fname;
- LastName = lname;
- Email = email;
- PhoneNumber = phone;
- CreditCard = cc;
- CreditCardExpiration = expiration;
+ this.FirstName = FirstName;
+ this.LastName = LastName;
+ this.Email = Email;
+ this.CreditCard = CreditCard;
+ this.Expiration = Expiration;
+ this.CCV = CCV;
}
- internal void SetCreditCardInformation(string cc, DateTime expiration, string ccv)
+ internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
{
- CreditCard = cc;
- CreditCardExpiration = expiration;
- CCV = ccv;
+ this.CreditCard = CreditCard;
+ this.Expiration = Expiration;
+ this.CCV = CCV;
}
}
internal class GuestList
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index a3787ff..ba9c94b 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -1,4 +1,10 @@
-using Ophelias.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Ophelias.Models;
+using Ophelias.Managers;
namespace Ophelias.Models
{
@@ -43,18 +49,6 @@ namespace Ophelias.Models
CheckOut = null;
DateChanged = null;
}
- internal void ChangeReservation(ReservationType type, Transaction t, BaseRate b)
- {
- Status = ReservationStatus.Changed;
- Type = type;
- t.Penalize(this, b.Rate);
- }
- internal void CancelReservation(Transaction t)
- {
- Status = ReservationStatus.Cancelled;
- t.Penalize(this);
-
- }
}
internal enum ReservationStatus
{
@@ -70,13 +64,4 @@ namespace Ophelias.Models
Incentive,
SixtyDayAdvance,
}
- internal class ReservationList
- {
- internal List Reservations;
-
- internal ReservationList()
- {
- Reservations = new List();
- }
- }
}
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index 44f9fc2..8f267d9 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -14,57 +14,28 @@ namespace Ophelias.Models
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 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 DateTime? PaidOn { get; set; } = null;
- internal Transaction(int id, Reservation r, DateTime payby)
+ internal Transaction(int Id, double Rate, double Owed, double Penalty,
+ double Multiplier, double RefundAmount,
+ DateTime PayBy, DateTime? PaidOn = null)
{
- Id = id;
- Paid = 0;
- Owed = 0;
- RefundAmount = 0;
- PaidOff = false;
- PayBy = SetPayByDate(r);
- Multiplier = Fee(r.Type);
+ this.Id = Id;
+ this.Rate = Rate;
+ this.Owed = Owed;
+ this.Penalty = Penalty;
+ this.Multiplier = Multiplier;
+ this.RefundAmount = RefundAmount;
+ this.PayBy = PayBy;
+ this.PaidOn = PaidOn;
}
- private bool IsOverdue()
- {
- if (DateTime.Now > PayBy)
- {
- return true;
- }
- return false;
- }
- private DateTime SetPayByDate(Reservation r)
- {
- switch(r.Type)
- {
- case ReservationType.Conventional: return r.EndDate;
- case ReservationType.Prepaid: return r.StartDate;
- case ReservationType.Incentive: return r.EndDate;
- case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30);
- default: throw new NotImplementedException();
- }
- }
- private void SetChangeFees(ReservationType type, double rate)
- {
- switch (type)
- {
- case ReservationType.Conventional: return;
- case ReservationType.Prepaid: SetFee(PenaltyMultipler); SetRate(rate); return;
- case ReservationType.Incentive: return;
- case ReservationType.SixtyDayAdvance: SetFee(PenaltyMultipler); SetRate(rate); return;
- default: throw new NotImplementedException();
- }
- }
- private void CancellationHandler(ReservationType type)
+
+ private void Cancellation(ReservationType type)
{
void SetRefund()
{
@@ -98,84 +69,43 @@ namespace Ophelias.Models
}
internal void Penalize(Reservation r, double rate)
{
- switch(r.Status)
- {
- case ReservationStatus.Changed: SetChangeFees(r.Type, rate); return;
- default: throw new NotImplementedException();
- }
- }
- private double Fee(ReservationType type)
- {
- switch (type)
- {
- case ReservationType.Conventional: return 1.0;
- case ReservationType.Prepaid: return 0.75;
- case ReservationType.Incentive: return GetIncentiveRate();
- case ReservationType.SixtyDayAdvance: return 0.85;
- default: throw new NotImplementedException();
- }
- }
- private double GetIncentiveRate()
- {
- return 0.80;
- }
- private void SetFee(double mult)
- {
- Multiplier = mult;
- }
- private void SetRate(double rate)
- {
- Rate = rate;
+ throw new NotImplementedException();
}
internal void Pay(double amount)
{
- if (RefundAmount > -1)
- {
- return;
- }
- Paid += amount;
- if (Paid == Owed)
- {
- Owed -= Paid;
- PaidOn = DateTime.Now;
- PaidOff = true;
- } else if (Paid > Owed)
- {
- RefundAmount = Paid - Owed;
- Owed = Owed - Paid + RefundAmount;
- PaidOn = DateTime.Now;
- PaidOff = true;
- } else
- {
- Owed -= Paid;
- PaidOn = DateTime.Now;
- }
+
}
}
- internal static class TransactionFees
+ internal static class TransactionInfo
{
- static double ConventionalFee = 1.0;
- static double PrepaidFee = 0.75;
- static double IncentiveFee = OccupancyIncentive();
- static double SixtyDayFee = 0.85;
+ internal static double ConventionalFee = 1.0;
+ internal static double PrepaidFee = 0.75;
+ internal static double IncentiveFee = IncentiveRate();
+ internal static double SixtyDayFee = 0.85;
- private static double OccupancyIncentive()
+ private static double IncentiveRate()
{
int thirtyDayOcc;
- using (DatabaseManager dbm = new DatabaseManager())
- {
- if (dbm.cur == null)
- throw new NotImplementedException();
-
- thirtyDayOcc = DatabaseFunctions.GetThirtyDayOccupancy(dbm.cur, DateTime.Now);
- }
+ thirtyDayOcc = HotelManager.GetThirtyDayOccupancy(DateTime.Now);
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
return 0.80;
return 1.0;
}
+ internal static DateTime GetPayByDate(Reservation r)
+ {
+ switch (r.Type)
+ {
+ case ReservationType.Conventional: return r.EndDate;
+ case ReservationType.Prepaid: return r.StartDate;
+ case ReservationType.Incentive: return r.EndDate;
+ case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30);
+ default: throw new NotImplementedException();
+ }
+ }
+
}
internal class TransactionList
{
diff --git a/OpheliasOasis/OpheliasOasis.sqlite b/OpheliasOasis/OpheliasOasis.sqlite
deleted file mode 100644
index e69de29..0000000
diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs
index 92aaad1..5ff948f 100644
--- a/OpheliasOasis/Program.cs
+++ b/OpheliasOasis/Program.cs
@@ -1,5 +1,6 @@
using Ophelias.Models;
using Ophelias.Managers;
+using Ophelias.Expressions;
using System.Data.SQLite;
class Program
@@ -8,8 +9,7 @@ class Program
{
Reservation? activeReservation = null;
Guest? activeGuest = null;
- TransactionTableManager tx = new TransactionTableManager(null);
- tx.UpdateTransactionInfo(1);
+
void help()
{
Console.WriteLine(
@@ -17,7 +17,7 @@ class Program
"\treservation create\n" +
"\treservation update\n" +
"\treservation cancel\n" +
- "Account Commands:" +
+ "Account Commands:\n" +
"\taccount create\n" +
"\taccount update\n" +
"Enter Q to quit.\n"
@@ -25,18 +25,89 @@ class Program
return;
}
+
+
void CreateNewReservation()
{
Reservation newReservation;
}
- while(true)
+ void CreateNewGuestPrompt()
{
- Console.WriteLine(
+ (string?, string?, string?) GetCreditCardInformation()
+ {
+ Console.Write("What is your credit card number: ");
+ string CreditCard = "";
+ while (!Validation.ValidateCreditCard(CreditCard))
+ {
+ CreditCard = Console.ReadLine().Trim().Replace("\t", "");
+ if (CreditCard == "q" || CreditCard == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateCreditCard(CreditCard))
+ Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
+ }
+ Console.Write("What is your credit card expiration date (MM/yy): ");
+ string CardExpiration = "";
+ while (!Validation.ValidateExpirationDate(CardExpiration))
+ {
+ CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
+ if (CardExpiration == "q" || CardExpiration == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateExpirationDate(CardExpiration))
+ Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
+ }
+ Console.Write("What is your credit card CCV: ");
+ string CCV = "";
+ while (!Validation.ValidateCCV(CCV))
+ {
+ CCV = Console.ReadLine().Trim().Replace("\t", "");
+ if (CCV == "q" || CCV == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateCCV(CCV))
+ Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
+ }
+ return (CreditCard, CardExpiration, CCV);
+ }
+ Console.Write("What is your first name: ");
+ string FirstName = "";
+ while (FirstName.Length == 0)
+ {
+ FirstName = Console.ReadLine();
+ if (FirstName == "")
+ Console.Write("What is your first name: ");
+ }
+ Console.Write("What is your last name: ");
+ string LastName = "";
+ while (LastName.Length == 0)
+ {
+ LastName = Console.ReadLine();
+ if (LastName == "")
+ Console.Write("What is your last name: ");
+ }
+ Console.Write("What is your email: ");
+ string email = "";
+ while (!Validation.ValidateEmail(email))
+ {
+ email = Console.ReadLine();
+ if (!Validation.ValidateEmail(email))
+ Console.Write("Please enter a valid email: ");
+ }
+ Console.Write("Would you like to enter your credit card details? (Y/n): ");
+ string? CreditCard = null;
+ string? CardExpiration = null;
+ string? CCV = null;
+ if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
+ (CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
+
+ }
+ Console.Write(
"Welcome to the Ophelias Oasis Hotel Registration System!\n" +
"Type help to get a full list of commands or enter a command.\n" +
"Command: "
- );
+ );
+ while (true)
+ {
+
string? input = Console.ReadLine();
switch(input)
{
@@ -44,11 +115,12 @@ class Program
case "reservation create": break;
case "reservation update": break;
case "reservation cancel": break;
+ case "account create": CreateNewGuestPrompt(); break;
case "account update": break;
case "q": return;
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
}
-
+ Console.Write("Command: ");
}
}
private void AdminMode()
@@ -70,15 +142,25 @@ class Program
}
static void Main()
{
- SQLiteConnection.CreateFile("OpheliasOasis.sqlite");
+
+ if (!File.Exists("database.sqlite3") || new FileInfo("database.sqlite3").Length == 0)
+ {
+ SQLiteConnection.CreateFile("database.sqlite3");
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ Manager.InitializeTables();
+ Manager.InitializeRoomsTable();
+ }
+ }
bool run = true;
while (run)
{
- Console.WriteLine(
+ Console.Write(
"Are you an employee or customer?\n" +
"1. Employee\n" +
- "2. Customer/ Guest"
+ "2. Customer/ Guest\n" +
+ ": "
);
switch(Console.ReadLine().ToUpper())
{
diff --git a/OpheliasOasis/Validation.cs b/OpheliasOasis/Validation.cs
new file mode 100644
index 0000000..d7170cd
--- /dev/null
+++ b/OpheliasOasis/Validation.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Text.RegularExpressions;
+using System.ComponentModel.DataAnnotations;
+using System.Globalization;
+
+namespace Ophelias.Expressions
+{
+ internal static class Expressions
+ {
+ internal static Regex CardRx = new Regex(@"^[0-9]{16}$", RegexOptions.Compiled);
+ internal static Regex ExpriationRx = new Regex(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
+ internal static Regex CCVRx = new Regex(@"^[0-9]{3}$", RegexOptions.Compiled);
+ }
+ internal static class Validation
+ {
+ internal static bool ValidateCreditCard(string CreditCard)
+ {
+ if (Expressions.CardRx.IsMatch(CreditCard))
+ return true;
+ return false;
+ }
+ internal static bool ValidateExpirationDate(string Expiration)
+ {
+ if (Expressions.ExpriationRx.IsMatch(Expiration))
+ {
+ DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture);
+ if (dt.Year >= DateTime.Now.Year)
+ if (dt.Month >= DateTime.Now.Month)
+ return true;
+ }
+ return false;
+ }
+ internal static bool ValidateEmail(string email)
+ {
+ EmailAddressAttribute EmailChecker = new EmailAddressAttribute();
+ return EmailChecker.IsValid(email);
+ }
+ internal static bool ValidateCCV(string CCV)
+ {
+ if (Expressions.CCVRx.IsMatch(CCV))
+ return true;
+ return false;
+ }
+ }
+}
From 8764c2e57cb29afec455cf705d532f554403ac87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Wed, 13 Apr 2022 23:53:17 -0400
Subject: [PATCH 06/10] Begun integration of models and managers
The HotelManager class now has been connected to some aspects of the
command line interface and is functioning for a few cases such as
logging in as a specific guest via email, chaging a guests information
and creating a new guest account. This was implemented first over the
reservation system to test and implement something on a smaller scale.
Furthermore, the reservation depends on an existing guest account since
a Guest ID needs to be linked to the reservation that is created.
Other changes include redesigning, tweaking/ adjusting, and/ or fixing
of other modules that have not yet been implemented or are partially
implemented.
---
OpheliasOasis/Managers/DatabaseManager.cs | 132 +++++----
OpheliasOasis/Managers/HotelManager.cs | 295 +++++++++++++------
OpheliasOasis/Models/Guest.cs | 9 +-
OpheliasOasis/Models/Reservation.cs | 71 +++--
OpheliasOasis/Models/Room.cs | 2 +-
OpheliasOasis/Models/Transaction.cs | 115 +++++---
OpheliasOasis/Program.cs | 330 +++++++++++++++++-----
7 files changed, 673 insertions(+), 281 deletions(-)
diff --git a/OpheliasOasis/Managers/DatabaseManager.cs b/OpheliasOasis/Managers/DatabaseManager.cs
index 253eca7..06c774a 100644
--- a/OpheliasOasis/Managers/DatabaseManager.cs
+++ b/OpheliasOasis/Managers/DatabaseManager.cs
@@ -31,6 +31,7 @@ namespace Ophelias.Managers
[Multiplier] INTEGER NOT NULL,
[RefundAmount] INTEGER NOT NULL,
[PayBy] TEXT NOT NULL,
+ [LastPaid] TEXXT NULL,
[PaidOn] TEXT NULL);
CREATE TABLE IF NOT EXISTS [reservations] (
@@ -55,8 +56,8 @@ namespace Ophelias.Managers
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[Fname] TEXT NOT NULL,
[Lname] TEXT NOT NULL,
- [Email] TEXT NOT NULL,
- [CreditCard] TEXT NULL,
+ [Email] TEXT NOT NULL UNIQUE,
+ [CreditCard] TEXT NULL UNIQUE,
[Expiration] TEXT NULL,
[CCV] TEXT NULL);
@@ -67,7 +68,8 @@ namespace Ophelias.Managers
CREATE TABLE IF NOT EXISTS [rates] (
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[Rate] INTEGER NOT NULL,
- [DateSet] TEXT NOT NULL);";
+ [DateSet] TEXT NOT NULL UNIQUE,
+ [DefaultRate] INTEGER NULL UNIQUE CHECK ([DefaultRate] IN (1)));";
using (SQLiteCommand cmd = con.CreateCommand())
{
@@ -103,10 +105,10 @@ namespace Ophelias.Managers
internal static class QueryBuilder
{
- internal static string? UpdateTransaction(int id,
+ internal static string? UpdateTransaction(int Id,
double? Rate = null, double? Owed = null, double? Penalty = null,
double? Multiplier = null, double? Refund = null,
- DateTime? PayBy = null, DateTime? PaidOn = null)
+ DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null)
{
List queryComponents = new List();
string query = "UPDATE transactions SET";
@@ -122,82 +124,110 @@ namespace Ophelias.Managers
if (Refund.HasValue)
queryComponents.Add($"Refund = {Refund}");
if (PayBy.HasValue)
- queryComponents.Add($"PaidBy = {PayBy.Value.ToString("yyyy-MM-dd")}");
+ queryComponents.Add($"PayBy = {PayBy.Value.Date.ToString("yyyy-MM-dd")}");
+ if (LastPaid.HasValue)
+ queryComponents.Add($"LastPaid = {LastPaid.Value.Date.ToString("yyyy-MM-dd")}");
if (PaidOn.HasValue)
- queryComponents.Add($"PaidOn = {PaidOn.Value.ToString("yyyy-MM-dd")}");
+ queryComponents.Add($"PaidOn = {PaidOn.Value.Date.ToString("yyyy-MM-dd")}");
- if (queryComponents.Count == 0)
- query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
+ 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)
+ 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();
+ List QueryParts = 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 (RoomID.HasValue)
+ QueryParts.Add($"RoomID = {RoomID}");
+ if (GuestID.HasValue)
+ QueryParts.Add($"GuestID = {GuestID}");
+ if (TransactionID.HasValue)
+ QueryParts.Add($"TransactionID = {TransactionID}");
+ if (IsNoShow.HasValue)
+ QueryParts.Add($"IsNoShow = {Convert.ToInt32(IsNoShow)}");
+ if (Type.HasValue)
+ QueryParts.Add($"Type = {(int)Type}");
+ if (Status.HasValue)
+ QueryParts.Add($"Status = {(int)Status}");
+ if (CreationDate.HasValue)
+ QueryParts.Add($"CreationDate = {CreationDate.Value.Date.ToString("yyyy-MM-dd")}");
+ if (StartDate.HasValue)
+ QueryParts.Add($"StartDate = {StartDate.Value.Date.ToString("yyyy-MM-dd")}");
+ if (EndDate.HasValue)
+ QueryParts.Add($"EndDate = {EndDate.Value.Date.ToString("yyyy-MM-dd")}");
+ if (CheckIn.HasValue)
+ QueryParts.Add($"CheckIn = {CheckIn.Value.Date.ToString("yyyy-MM-dd")}");
+ if (CheckOut.HasValue)
+ QueryParts.Add($"CheckOut = {CheckOut.Value.Date.ToString("yyyy-MM-dd")}");
+ if (DateChanged.HasValue)
+ QueryParts.Add($"DateChanged = {DateChanged.Value.Date.ToString("yyyy-MM-dd")}");
- if (queryComponents.Count == 0)
- query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
+ if (QueryParts.Count > 0)
+ query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
else
return null;
return query;
}
- internal static string CreateTransaction(double Rate, double Owed, double Penalty,
- double Multiplier, double Refund, bool isLate,
- bool PaidOff, DateTime PaidBy, DateTime? PaidOn = null)
+ internal static string CreateTransaction(double Rate, double Owed,
+ double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
+ DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
{
- return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, Refund, IsLate, PaidOff, PaidBy, PaidOn)
- VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {isLate}, {PaidOff}, {PaidBy}, {PaidOn});";
+ return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn)
+ VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {PayBy}, {PayBy}, {PaidOn});";
}
- internal static string CreateReservation(int roomid, int guestid, int transactionid, bool isnoshow, ReservationType type,
+ internal static string CreateReservation(int guestid, int transactionid, ReservationType type,
ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
- DateTime checkin, DateTime checkout, DateTime datechanged)
+ DateTime? checkin = null, DateTime? checkout = null, DateTime? datechanged = null, bool? isnoshow = false)
{
- return @$"INSERT INTO reservations (RoomID, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
- VALUES ({roomid}, {guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
+ return @$"INSERT INTO reservations (GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
+ VALUES ({guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
}
internal static string CreateGuest(string FirstName, string LastName, string Email, string? CreditCard, string? Expiration, string? CCV)
{
if (CreditCard != null && Expiration != null && CCV != null)
- return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ({FirstName}, {LastName}, {Email});";
+ return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ('{FirstName}', '{LastName}', '{Email}', '{CreditCard}', '{Expiration}', '{CCV}');";
else
- return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ({FirstName}, {LastName}, {Email}, {CreditCard}, {Expiration}, {CCV});";
+ return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ('{FirstName}', '{LastName}', '{Email}');";
+ }
+
+ internal static string? UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
+ {
+ List QueryParts = new List();
+ string query = "UPDATE guests SET";
+
+ if (!string.IsNullOrEmpty(FirstName))
+ QueryParts.Add($"Fname = '{FirstName}'");
+ if (!string.IsNullOrEmpty(LastName))
+ QueryParts.Add($"Lname = '{LastName}'");
+ if (!string.IsNullOrEmpty(LastName))
+ QueryParts.Add($"Email = '{Email}'");
+ if (!string.IsNullOrEmpty(CreditCard))
+ QueryParts.Add($"CreditCard = '{CreditCard}'");
+ if (!string.IsNullOrEmpty(Expiration))
+ QueryParts.Add($"Expiration = '{Expiration}'");
+ if (!string.IsNullOrEmpty(CCV))
+ QueryParts.Add($"CCV = '{CCV}'");
+
+ if (QueryParts.Count > 0)
+ query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
+ else
+ return null;
+
+ return query;
}
}
}
diff --git a/OpheliasOasis/Managers/HotelManager.cs b/OpheliasOasis/Managers/HotelManager.cs
index cdd393a..e58df55 100644
--- a/OpheliasOasis/Managers/HotelManager.cs
+++ b/OpheliasOasis/Managers/HotelManager.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;
using System.Data.SQLite;
namespace Ophelias.Managers
@@ -12,107 +7,117 @@ namespace Ophelias.Managers
{
internal static int GetLastId(string tableName)
{
- int lastId = 0;
- using (DatabaseManager manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = manager.con.CreateCommand())
- {
- cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=\"{tableName}\";";
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- lastId = reader.GetInt32(0);
- }
- }
- }
- return lastId;
- }
- internal static int GetThirtyDayOccupancy(DateTime start)
- {
- int thirtyDayOcc;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand()) {
- 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();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- thirtyDayOcc = reader.GetInt32(0);
- }
- }
- }
-
- return thirtyDayOcc;
- }
- internal static int CreateReservation(int roomid, int guestid, int transactionid, bool isnoshow, ReservationType type,
- ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
- DateTime checkin, DateTime checkout, DateTime datechanged)
- {
- int id;
+ int LastId = 0;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- cmd.CommandText = QueryBuilder.CreateReservation(roomid, guestid, transactionid, isnoshow, type,
- status, creationdate, startdate, enddate,
- checkin, checkout, datechanged);
+ cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name='{tableName}';";
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ LastId = reader.GetInt32(0);
+ }
+ }
+ }
+ return LastId;
+ }
+ internal static List DailyOccupancies(DateTime Date)
+ {
+ List Occupancies = new List();
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $@"SELECT COUNT(*)
+ FROM reservations
+ WHERE DATE('{Date.Date.ToString("yyyy-MM-dd")}')
+ BETWEEN StartDate AND EndDate;";
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ Occupancies.Add(reader.GetInt32(0));
+ }
+ }
+ }
+ return Occupancies;
+ }
+ internal static int AvgOccupancySpan(DateTime Start, DateTime End)
+ {
+ int thirtyDayOcc = 0;
+ int days = (int)(Start.Date - End.Date).TotalDays;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ for (int i = 0; i < days; i++)
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $@"SELECT COUNT(*)
+ FROM reservations
+ WHERE DATE('{Start.AddDays(i).Date.ToString("yyyy-MM-dd")}')
+ BETWEEN StartDate AND EndDate;";
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ thirtyDayOcc += reader.GetInt32(0);
+ }
+ }
+ }
+ }
+ return thirtyDayOcc / days;
+ }
+ internal static Reservation CreateReservation(Guest Guest, ReservationType Type,
+ DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active)
+ {
+ int id; double Multiplier;
+ switch (Type)
+ {
+ case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
+ case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
+ case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
+ case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
+ default: throw new NotImplementedException();
+ }
+ Transaction t = CreateTransaction(
+ Rate: GetBaseRate(),
+ Owed: TxFunctions.CalculateOwed(GetBaseRate(), (int)(StartDate.Date - EndDate.Date).TotalDays),
+ Multiplier: Multiplier,
+ PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
+ );
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = QueryBuilder.CreateReservation(Guest.Id, t.Id, Type,
+ Status, CreationDate, StartDate, EndDate);
cmd.ExecuteNonQuery();
}
id = (int)Manager.con.LastInsertRowId;
}
- return id;
- }
- internal static void ChangeReservationDates(Reservation r, Transaction t, DateTime start, DateTime end)
- {
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string? query = QueryBuilder.UpdateReservation(id: r.Id, startdate: start, enddate: end, datechanged: DateTime.Now);
- if (query == null)
- throw new Exception();
-
- query += QueryBuilder.UpdateTransaction(id: r.TransactionId, Multiplier: 1.1);
- cmd.CommandText = query;
- cmd.ExecuteNonQuery();
- }
- }
+ return new Reservation(id, Guest, t, Type, Status, CreationDate, StartDate, EndDate);
}
- internal static Transaction CreateTransaction(double Rate, double Owed, double Penalty,
- double Multiplier, double Refund, bool isLate,
- bool PaidOff, DateTime PaidBy, DateTime? PaidOn = null)
+ internal static Transaction CreateTransaction(double Rate, double Owed,
+ double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
+ DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
{
int Id;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Penalty, Multiplier, Refund, isLate, PaidOff, PaidBy, PaidOn);
+ cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy,Refund: Refund, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
cmd.ExecuteNonQuery();
}
Id = (int)Manager.con.LastInsertRowId;
}
- return new Transaction(Id, Rate, Owed, Penalty, Multiplier, Refund, PaidBy, PaidOn);
+ return new Transaction(Id, Rate, Owed, Multiplier, Penalty: Penalty, RefundAmount: Refund, PayBy: PayBy, PaidOn: PaidOn);
}
- internal static int CheckInGuest(DateTime CheckIn)
- {
- return 1;
- }
- internal static int CheckOutGuest(DateTime CheckOut)
- {
- return 1;
- }
-
internal static Guest CreateGuest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
- string query = QueryBuilder.CreateGuest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
-
int Id;
using (DatabaseManager Manager = new DatabaseManager())
{
@@ -125,9 +130,127 @@ namespace Ophelias.Managers
}
if (CreditCard != null && Expiration != null && CCV != null)
- return new Guest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
+ return new Guest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
else
- return new Guest(FirstName, LastName, Email);
+ return new Guest(Id, FirstName, LastName, Email);
+ }
+ internal static void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
+ {
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ internal static Guest? GetGuestByEmail(string Email)
+ {
+ Guest? g = null;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT * FROM guests WHERE email = '{Email}'";
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ string? CreditCard = null, Expiration = null, CCV = null;
+ if (reader[4].GetType() != typeof(DBNull))
+ CreditCard = reader[4].ToString();
+ if (reader[5].GetType() != typeof(DBNull))
+ Expiration = reader[5].ToString();
+ if (reader[6].GetType() != typeof(DBNull))
+ CCV = reader[6].ToString();
+ g = new Guest(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), CreditCard, Expiration, CCV);
+ }
+ }
+ }
+ }
+ return g;
+ }
+ internal static double GetBaseRate()
+ {
+ double rate;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Rate FROM rates WHERE DefaultRate = 1;";
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ rate = reader.GetDouble(0);
+ }
+ }
+ }
+ return rate;
+ }
+ internal static void SetBaseRate(double Rate, DateTime DateSet)
+ {
+ double rate;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = $"INSERT INTO rates (Rate, DateSet) VALUES ({Rate}, {DateSet});";
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ internal static void CheckBaseRate()
+ {
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ int? OldId;
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Id FROM rates WHERE DefaultRate = 1;";
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ OldId = reader.GetInt32(0);
+ }
+ }
+ int? Id;
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = $"SELECT Id FROM rates WHERE DateSet = {DateTime.Now.Date.ToString("yyyy-MM-dd")};";
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ Id = reader.GetInt32(0);
+ }
+ }
+ if (Id != null)
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $@"UPDATE rates SET DefaultRate = NULL WHERE Id = {OldId};
+ UPDATE rates SET DefaultRate = 1 WHERE Id = {Id}";
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ }
+ internal static int CheckInGuest(DateTime CheckIn)
+ {
+ return 1;
+ }
+ internal static int CheckOutGuest(DateTime CheckOut)
+ {
+ return 1;
}
}
}
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
index 2fc8042..294b882 100644
--- a/OpheliasOasis/Models/Guest.cs
+++ b/OpheliasOasis/Models/Guest.cs
@@ -17,14 +17,9 @@ namespace Ophelias.Models
internal string? CCV;
internal string? Expiration;
- internal Guest(string FirstName, string LastName, string Email)
- {
- this.FirstName = FirstName;
- this.LastName = LastName;
- this.Email = Email;
- }
- internal Guest(string FirstName, string LastName, string Email, string CreditCard, string Expiration, string CCV)
+ internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
+ this.Id = Id;
this.FirstName = FirstName;
this.LastName = LastName;
this.Email = Email;
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index ba9c94b..5f85949 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -1,19 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Ophelias.Models;
using Ophelias.Managers;
+using System.Data.SQLite;
namespace Ophelias.Models
{
internal class Reservation
{
internal int Id;
- internal int RoomId;
- internal int GuestId;
- internal int TransactionId;
+ internal Room Room;
+ internal Guest Guest;
+ internal Transaction Transaction;
internal bool IsNoShow;
@@ -28,26 +26,57 @@ namespace Ophelias.Models
internal DateTime? CheckOut;
internal DateTime? DateChanged;
- internal Reservation(int id, int gid, int tid, int room, ReservationType type, ReservationStatus status,
- DateTime startdate, DateTime enddate)
+ internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
+ DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
{
- Id = id;
- RoomId = room;
- GuestId = gid;
- TransactionId = tid;
+ this.Id = Id;
+ this.Guest = Guest;
+ this.Transaction = Transaction;
+ this.IsNoShow = IsNoShow;
+ this.Type = Type;
+ this.Status = Status;
+ this.CreationDate = CreationDate;
+ this.StartDate = StartDate;
+ this.EndDate = EndDate;
+ this.CheckIn = CheckIn;
+ this.CheckOut = CheckOut;
+ this.DateChanged = DateChanged;
+ }
+ internal void ChangeReservationDates(DateTime StartDate, DateTime EndDate)
+ {
+ this.StartDate = StartDate;
+ this.EndDate = EndDate;
+ DateChanged = DateTime.Now.Date;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Changed, StartDate: this.StartDate, EndDate: this.EndDate, DateChanged: DateChanged);
- IsNoShow = false;
+ if (query == null)
+ throw new Exception();
- Type = type;
- Status = status;
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ }
+ }
+ Transaction.UpdateTransactionFees(HotelManager.GetBaseRate(), TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
+ }
+ internal void CancelReservation()
+ {
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: DateTime.Now.Date);
- CreationDate = DateTime.Now;
- StartDate = startdate;
- EndDate = enddate;
+ if (query == null)
+ throw new Exception();
- CheckIn = null;
- CheckOut = null;
- DateChanged = null;
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ }
+ }
}
}
internal enum ReservationStatus
diff --git a/OpheliasOasis/Models/Room.cs b/OpheliasOasis/Models/Room.cs
index d1bbe2e..0601331 100644
--- a/OpheliasOasis/Models/Room.cs
+++ b/OpheliasOasis/Models/Room.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace OpheliasOasis.Models
+namespace Ophelias.Models
{
internal class Room
{
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index 8f267d9..6b2d957 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -5,13 +5,12 @@ using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using Ophelias.Managers;
+using System.Data.SQLite;
namespace Ophelias.Models
{
internal class Transaction
{
- private double PenaltyMultipler = 1.1;
-
internal int Id { get; set; }
internal double Rate { get; set; }
internal double Owed { get; set; }
@@ -19,11 +18,12 @@ namespace Ophelias.Models
internal double Multiplier { get; set; }
internal double RefundAmount { get; set; }
internal DateTime PayBy { get; set; }
+ internal DateTime? LastPaid { get; set; } = null;
internal DateTime? PaidOn { get; set; } = null;
- internal Transaction(int Id, double Rate, double Owed, double Penalty,
- double Multiplier, double RefundAmount,
- DateTime PayBy, DateTime? PaidOn = null)
+ internal Transaction(int Id, double Rate, double Owed,
+ double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
+ DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
{
this.Id = Id;
this.Rate = Rate;
@@ -32,79 +32,102 @@ namespace Ophelias.Models
this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount;
this.PayBy = PayBy;
+ this.LastPaid = LastPaid;
this.PaidOn = PaidOn;
}
- private void Cancellation(ReservationType type)
+ internal void UpdateTransactionFees(double Rate, double Multiplier, DateTime PayBy)
{
- void SetRefund()
+ this.Rate = Rate;
+ this.Multiplier = Multiplier;
+ this.PayBy = PayBy;
+ using (DatabaseManager Manager = new DatabaseManager())
{
- if (DateTime.Now.AddDays(+3).Day <= PayBy.Day)
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- RefundAmount = Paid;
- Paid = 0;
- Owed = 0;
- PaidOff = false;
+ string? query = QueryBuilder.UpdateTransaction(Id: Id, Rate: this.Rate, Multiplier: this.Multiplier, PayBy: this.PayBy);
+
+ if (query == null)
+ throw new Exception();
+
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
}
}
-
- switch (type)
+ }
+ internal void Pay(double Amount)
+ {
+ if (Amount <= 0)
+ return;
+ LastPaid = DateTime.Now;
+ Owed -= Amount;
+ if (Owed < 0)
+ RefundAmount = Math.Abs(Owed);
+ else if (Owed == 0)
+ PaidOn = DateTime.Now;
+ using (DatabaseManager Manager = new DatabaseManager())
{
- case ReservationType.Conventional: SetRefund(); return;
- case ReservationType.Prepaid: return;
- case ReservationType.Incentive: SetRefund(); return;
- case ReservationType.SixtyDayAdvance: return;
- default: throw new NotImplementedException();
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string? query = QueryBuilder.UpdateTransaction(Id: Id, Owed: Owed, Refund: RefundAmount, LastPaid: LastPaid, PaidOn: PaidOn);
+
+ if (query == null)
+ throw new Exception();
+
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ }
}
}
- internal void Penalize(Reservation r)
+ internal void Refund()
{
- switch (r.Status)
+ RefundAmount = 0;
+ using (DatabaseManager Manager = new DatabaseManager())
{
- case ReservationStatus.Active: IsOverdue(); return;
- case ReservationStatus.Ended: IsOverdue(); return;
- case ReservationStatus.Cancelled: CancellationHandler(r.Type); return;
- default: throw new NotImplementedException();
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount);
+
+ if (query == null)
+ throw new Exception();
+
+ cmd.CommandText = query;
+ cmd.ExecuteNonQuery();
+ }
}
}
- internal void Penalize(Reservation r, double rate)
- {
- throw new NotImplementedException();
- }
-
- internal void Pay(double amount)
- {
-
- }
}
- internal static class TransactionInfo
+ internal static class TxFunctions
{
internal static double ConventionalFee = 1.0;
internal static double PrepaidFee = 0.75;
- internal static double IncentiveFee = IncentiveRate();
internal static double SixtyDayFee = 0.85;
-
- private static double IncentiveRate()
+ internal static double Changed = 1.1;
+ internal static double IncentiveFee(DateTime Start, DateTime End)
{
int thirtyDayOcc;
- thirtyDayOcc = HotelManager.GetThirtyDayOccupancy(DateTime.Now);
+ thirtyDayOcc = HotelManager.AvgOccupancySpan(Start, End);
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
return 0.80;
return 1.0;
}
-
- internal static DateTime GetPayByDate(Reservation r)
+ internal static DateTime GetPayByDate(ReservationType Type, DateTime StartDate, DateTime EndDate)
{
- switch (r.Type)
+ switch (Type)
{
- case ReservationType.Conventional: return r.EndDate;
- case ReservationType.Prepaid: return r.StartDate;
- case ReservationType.Incentive: return r.EndDate;
- case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30);
+ case ReservationType.Conventional: return EndDate;
+ case ReservationType.Prepaid: return StartDate;
+ case ReservationType.Incentive: return EndDate;
+ case ReservationType.SixtyDayAdvance: return StartDate.AddDays(-30);
default: throw new NotImplementedException();
}
}
+ internal static double CalculateOwed(double Rate, int Days)
+ {
+ return Rate * (double)Days;
+ }
+
}
internal class TransactionList
diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs
index 5ff948f..2fa774e 100644
--- a/OpheliasOasis/Program.cs
+++ b/OpheliasOasis/Program.cs
@@ -9,72 +9,14 @@ class Program
{
Reservation? activeReservation = null;
Guest? activeGuest = null;
-
- void help()
- {
- Console.WriteLine(
- "Reservation Commands:\n" +
- "\treservation create\n" +
- "\treservation update\n" +
- "\treservation cancel\n" +
- "Account Commands:\n" +
- "\taccount create\n" +
- "\taccount update\n" +
- "Enter Q to quit.\n"
- );
- return;
- }
-
-
-
- void CreateNewReservation()
- {
- Reservation newReservation;
- }
-
- void CreateNewGuestPrompt()
- {
- (string?, string?, string?) GetCreditCardInformation()
- {
- Console.Write("What is your credit card number: ");
- string CreditCard = "";
- while (!Validation.ValidateCreditCard(CreditCard))
- {
- CreditCard = Console.ReadLine().Trim().Replace("\t", "");
- if (CreditCard == "q" || CreditCard == "Q")
- return (null, null, null);
- if (!Validation.ValidateCreditCard(CreditCard))
- Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
- }
- Console.Write("What is your credit card expiration date (MM/yy): ");
- string CardExpiration = "";
- while (!Validation.ValidateExpirationDate(CardExpiration))
- {
- CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
- if (CardExpiration == "q" || CardExpiration == "Q")
- return (null, null, null);
- if (!Validation.ValidateExpirationDate(CardExpiration))
- Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
- }
- Console.Write("What is your credit card CCV: ");
- string CCV = "";
- while (!Validation.ValidateCCV(CCV))
- {
- CCV = Console.ReadLine().Trim().Replace("\t", "");
- if (CCV == "q" || CCV == "Q")
- return (null, null, null);
- if (!Validation.ValidateCCV(CCV))
- Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
- }
- return (CreditCard, CardExpiration, CCV);
- }
+ (string, string) GetGuestName() {
Console.Write("What is your first name: ");
- string FirstName = "";
- while (FirstName.Length == 0)
- {
- FirstName = Console.ReadLine();
- if (FirstName == "")
- Console.Write("What is your first name: ");
+ string FirstName = "";
+ while (FirstName.Length == 0)
+ {
+ FirstName = Console.ReadLine();
+ if (FirstName == "")
+ Console.Write("What is your first name: ");
}
Console.Write("What is your last name: ");
string LastName = "";
@@ -84,7 +26,38 @@ class Program
if (LastName == "")
Console.Write("What is your last name: ");
}
+ return (FirstName, LastName);
+ }
+ string GetGuestEmail()
+ {
Console.Write("What is your email: ");
+ string Email = "";
+ while (!Validation.ValidateEmail(Email))
+ {
+ Email = Console.ReadLine();
+ if (!Validation.ValidateEmail(Email))
+ Console.Write("Please enter a valid email: ");
+ }
+ return Email;
+ }
+ void help()
+ {
+ Console.WriteLine(
+ "Reservation Commands:\n" +
+ "\treservation create - Create a new reservation.\n" +
+ "\treservation update - Update your active reservation.\n" +
+ "\treservation cancel - Cancel a reservation.\n" +
+ "Account Commands:\n" +
+ "\taccount create - Create a new guest account.\n" +
+ "\taccount update - Update your account information.\n" +
+ "\taccount login - Log into your guest account." +
+ "Enter Q to quit.\n"
+ );
+ return;
+ }
+ void GuestLogin()
+ {
+ Console.Write("\nEnter your email address: ");
string email = "";
while (!Validation.ValidateEmail(email))
{
@@ -92,16 +65,234 @@ class Program
if (!Validation.ValidateEmail(email))
Console.Write("Please enter a valid email: ");
}
+ activeGuest = HotelManager.GetGuestByEmail(email);
+ if (activeGuest == null)
+ Console.WriteLine($"\nNo account was found with the email {email}.");
+ Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
+ }
+ void CreateNewGuestPrompt()
+ {
+ (string FirstName, string LastName) = GetGuestName();
+ string Email = GetGuestEmail();
Console.Write("Would you like to enter your credit card details? (Y/n): ");
string? CreditCard = null;
string? CardExpiration = null;
string? CCV = null;
if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
(CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
+
+ activeGuest = HotelManager.CreateGuest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
+ Console.Write($"You are now logged in as {FirstName} {LastName} ({Email})");
+ }
+ void UpdateGuestInformation()
+ {
+ if (activeGuest == null)
+ {
+ Console.WriteLine("No guest is currently logged in, please login.");
+ return;
+ }
+
+ string? NewFname = null, NewLname = null, NewEmail = null, NewCard = null, NewExpiry = null, NewCCV = null;
+ void SavePrompt()
+ {
+ if (NewFname == null && NewLname == null && NewEmail == null && NewCard == null && NewExpiry == null && NewCCV == null)
+ {
+ Console.WriteLine("No changes have been made.");
+ return;
+ }
+ string changes = "";
+ List NewDetails = new List();
+ if (!string.IsNullOrEmpty(NewFname))
+ {
+ NewDetails.Add($"\tFirst Name: {activeGuest.FirstName} -> {NewFname}");
+ activeGuest.FirstName = NewFname;
+ }
+ if (!string.IsNullOrEmpty(NewLname))
+ {
+ NewDetails.Add($"\tLast Name: {activeGuest.LastName} -> {NewLname}");
+ activeGuest.LastName = NewLname;
+ }
+ if (!string.IsNullOrEmpty(NewEmail))
+ {
+ NewDetails.Add($"\tEmail: {activeGuest.Email} -> {NewEmail}");
+ activeGuest.Email = NewEmail;
+ }
+ if (!string.IsNullOrEmpty(NewCard))
+ {
+ NewDetails.Add($"\tCredit Card: {activeGuest.CreditCard} -> {NewCard}");
+ activeGuest.CreditCard = NewCard;
+ }
+ if (!string.IsNullOrEmpty(NewExpiry))
+ {
+ NewDetails.Add($"\tCard Expiration Date: {activeGuest.Expiration} -> {NewExpiry}");
+ activeGuest.Expiration = NewExpiry;
+ }
+ if (!string.IsNullOrEmpty(NewCCV))
+ {
+ NewDetails.Add($"\tCard CCV: {activeGuest.CCV} -> {NewCCV}");
+ activeGuest.CCV = NewCCV;
+ }
+ if (NewDetails.Count > 0)
+ changes += string.Join("\n", NewDetails);
+ Console.WriteLine($"The following changes have been made:\n {changes}");
+ HotelManager.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
+ return;
+ }
+
+ Console.WriteLine($"You are currently logged in as {activeGuest.FirstName} {activeGuest.LastName} ({activeGuest.Email}).\n" +
+ $"If this is not your account, please (Q)uit and log into your account. Changes will be recorded, but not saved\n" +
+ $"until you enter S.\n");
+
+ do
+ {
+ Console.Write("Please select the option you would like to change or enter S to save:\n" +
+ "1. First Name and Last Name\n" +
+ "2. Email Address\n" +
+ "3. Credit Card Information\n");
+ switch (Console.ReadLine())
+ {
+ case "Q": return;
+ case "q": return;
+ case "1": (NewFname, NewLname) = GetGuestName(); break;
+ case "2": NewEmail = GetGuestEmail(); break;
+ case "3": (NewCard, NewExpiry, NewCCV) = GetCreditCardInformation(); break;
+ case "S": SavePrompt(); return;
+ default: break;
+ }
+ } while (true);
+ }
+ void CreateNewReservation()
+ {
+ if (activeGuest == null)
+ Console.WriteLine("No guest is currently logged in, please login.");
+ if (activeReservation != null)
+ Console.WriteLine("");
+
+ string input = "";
+ ReservationType SelectReservation()
+ {
+ Console.Write("What kind of reservation would you like to make?\n" +
+ "1. Conventional\n" +
+ "2. Prepaid\n" +
+ "3. 60 Day Advance\n" +
+ "4. Incentive\n" +
+ "Input a number: ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (input == "1" || input == "2" || input == "3" || input == "4")
+ break;
+ Console.Write("Please enter either 1, 2, 3, or 4: ");
+ }
+ return (ReservationType)Convert.ToInt32(input);
+ }
+ (DateTime, DateTime) SelectDate()
+ {
+ DateTime _StartDate;
+ DateTime _EndDate;
+ Console.Write("When would you like to begin your stay.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while(true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out _StartDate))
+ break;
+
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ Console.Write("When would you like to end your stay.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
+ break;
+
+ if (_EndDate < _StartDate)
+ Console.Write("End date cannot be before start date. Please enter a valid date (2021-12-31): ");
+ else
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ return (_StartDate.Date, _EndDate.Date);
+ }
+
+ ReservationType Type;
+ DateTime StartDate;
+ DateTime EndDate;
+
+ Type = SelectReservation();
+ (StartDate, EndDate) = SelectDate();
+ if (Type != ReservationType.SixtyDayAdvance &&
+ (activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))
+ GetCreditCardInformation();
+
+ Console.WriteLine($"Thank you for filling out your reservation details. Currently you have made a {Type}" +
+ $"reservation and are scheduled to stay from {StartDate.ToString("yyyy-MM-dd")} to {EndDate.ToString("yyyy-MM-dd")}." +
+ $"If these details are correct, enter YES to complete. If they are not enter...\n" +
+ $"1. Change your reservation type\n" +
+ $"2. Change your reservation dates\n" +
+ $": ");
+ input = Console.ReadLine();
+ if (input != "YES")
+ {
+ bool completed = false;
+ do
+ {
+ Console.Write("Would you like to edit any information, enter Q to exit and complete your reservation?\n" +
+ "1. Reservation type\n" +
+ "2. Reservation dates\n" +
+ "Enter 1 or 2: ");
+ switch (Console.ReadLine())
+ {
+ case "Q": completed = true; break;
+ case "q": completed = true; break;
+ case "1": SelectReservation(); break;
+ case "2": SelectDate(); break;
+ default: break;
+ }
+ } while (!completed);
+ }
+ HotelManager.CreateReservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
+ }
+ (string?, string?, string?) GetCreditCardInformation()
+ {
+ Console.Write("What is your credit card number: ");
+ string CreditCard = "";
+ while (!Validation.ValidateCreditCard(CreditCard))
+ {
+ CreditCard = Console.ReadLine().Trim().Replace("\t", "");
+ if (CreditCard == "q" || CreditCard == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateCreditCard(CreditCard))
+ Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
+ }
+ Console.Write("What is your credit card expiration date (MM/yy): ");
+ string CardExpiration = "";
+ while (!Validation.ValidateExpirationDate(CardExpiration))
+ {
+ CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
+ if (CardExpiration == "q" || CardExpiration == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateExpirationDate(CardExpiration))
+ Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
+ }
+ Console.Write("What is your credit card CCV: ");
+ string CCV = "";
+ while (!Validation.ValidateCCV(CCV))
+ {
+ CCV = Console.ReadLine().Trim().Replace("\t", "");
+ if (CCV == "q" || CCV == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateCCV(CCV))
+ Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
+ }
+ return (CreditCard, CardExpiration, CCV);
}
Console.Write(
- "Welcome to the Ophelias Oasis Hotel Registration System!\n" +
+ "\nWelcome to the Ophelias Oasis Hotel Registration System!\n" +
"Type help to get a full list of commands or enter a command.\n" +
"Command: "
);
@@ -112,15 +303,16 @@ class Program
switch(input)
{
case "help": help(); break;
- case "reservation create": break;
+ case "reservation create": CreateNewReservation(); break;
case "reservation update": break;
case "reservation cancel": break;
case "account create": CreateNewGuestPrompt(); break;
- case "account update": break;
+ case "account update": UpdateGuestInformation(); break;
+ case "account login": GuestLogin(); break;
case "q": return;
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
}
- Console.Write("Command: ");
+ Console.Write("\nCommand: ");
}
}
private void AdminMode()
From 34bebca414b8e941a1ded8ebb706357aa1ef5ad7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Fri, 15 Apr 2022 02:29:55 -0400
Subject: [PATCH 07/10] Finishes the guest part of the models and UI
integration
This commit branch has been muddled with changes that are out of scope
and cover more than just the models. Specifically it includes
completion of basic guest related models, database access, command line interface
integration and preventing SQL injection.
Total summary of changes:
**IMPORTANT CHANGE: All queries are now parameterized to prevent SQL
injections. Prior versions are subject to it since the strings were
built.
- HotelManager
This class is used to provide database operations that are outside of
scope from a given model. Furthermore if there is no model to work off
of, such as creating a new model based off an existing entry, these
functions live outside of the model since it makes no sense for models
to contain functions where it would retrieve itself with no context.
Realistically this could be placed in an empty constructor and address
itself, however, for now this functionality has been moved off the model
since it is a one use and is not guaranteed to generate a guest. Some
functionality for the coming employee management functions are already
in there since they share overlap with the guest module. Specifically
GetBaseRate for checking and getting the base rate.
- DatabaseManager
This class has mostly migrated functionality out or switch to
parameterized query generation to prevent SQL injections.
- Guest, Reservation, and Transaction Classes
Migrated functionality to create the database entry and a new entry of
guest upon creation as well as update them.
- Program (Terminal app)
Fully integrated the guest module. Has not undergone extensive testing
but does work as of this commit.
---
OpheliasOasis/Managers/DatabaseManager.cs | 109 +++---
OpheliasOasis/Managers/HotelManager.cs | 169 ++++-----
OpheliasOasis/Models/Guest.cs | 68 +++-
OpheliasOasis/Models/Reservation.cs | 97 ++++-
OpheliasOasis/Models/Room.cs | 8 +-
OpheliasOasis/Models/Transaction.cs | 56 ++-
OpheliasOasis/Program.cs | 410 +++++++++++++++-------
7 files changed, 621 insertions(+), 296 deletions(-)
diff --git a/OpheliasOasis/Managers/DatabaseManager.cs b/OpheliasOasis/Managers/DatabaseManager.cs
index 06c774a..ec768a6 100644
--- a/OpheliasOasis/Managers/DatabaseManager.cs
+++ b/OpheliasOasis/Managers/DatabaseManager.cs
@@ -27,30 +27,30 @@ namespace Ophelias.Managers
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[Rate] INTEGER NOT NULL,
[Owed] INTEGER NOT NULL,
- [Penalty] INTEGER NULL,
+ [Penalty] INTEGER NOT NULL,
[Multiplier] INTEGER NOT NULL,
[RefundAmount] INTEGER NOT NULL,
[PayBy] TEXT NOT NULL,
- [LastPaid] TEXXT NULL,
+ [LastPaid] TEXT 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,
+ [RoomNum] INTEGER NULL UNIQUE,
+ [GuestID] INTEGER NOT NULL UNIQUE,
+ [TransactionID] INTEGER NOT NULL UNIQUE,
[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));
+ [CheckIn] TEXT NULL,
+ [CheckOut] TEXT NULL,
+ [DateChanged] TEXT NULL,
+ FOREIGN KEY ([RoomNum]) 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,
@@ -98,10 +98,6 @@ namespace Ophelias.Managers
}
}
- internal static class DatabaseFunctions
- {
-
- }
internal static class QueryBuilder
{
@@ -114,24 +110,24 @@ namespace Ophelias.Managers
string query = "UPDATE transactions SET";
if (Rate.HasValue)
- queryComponents.Add($"Rate = {Rate}");
+ queryComponents.Add($"Rate = @Rate");
if (Owed.HasValue)
- queryComponents.Add($"Owed = {Owed}");
+ queryComponents.Add($"Owed = @Owed");
if (Penalty.HasValue)
- queryComponents.Add($"Penalty = {Penalty}");
+ queryComponents.Add($"Penalty = @Penalty");
if (Multiplier.HasValue)
- queryComponents.Add($"Multiplier = {Multiplier}");
+ queryComponents.Add($"Multiplier = @Multiplier");
if (Refund.HasValue)
- queryComponents.Add($"Refund = {Refund}");
+ queryComponents.Add($"Refund = @Refund");
if (PayBy.HasValue)
- queryComponents.Add($"PayBy = {PayBy.Value.Date.ToString("yyyy-MM-dd")}");
+ queryComponents.Add($"PayBy = @PayBy");
if (LastPaid.HasValue)
- queryComponents.Add($"LastPaid = {LastPaid.Value.Date.ToString("yyyy-MM-dd")}");
+ queryComponents.Add($"LastPaid = @LastPaid");
if (PaidOn.HasValue)
- queryComponents.Add($"PaidOn = {PaidOn.Value.Date.ToString("yyyy-MM-dd")}");
+ queryComponents.Add($"PaidOn = @PaidOn");
if (queryComponents.Count > 0)
- query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {Id};";
+ query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = @ID;";
else
return null;
@@ -147,83 +143,58 @@ namespace Ophelias.Managers
string query = "UPDATE reservations SET";
if (RoomID.HasValue)
- QueryParts.Add($"RoomID = {RoomID}");
+ QueryParts.Add($"RoomID = @RID");
if (GuestID.HasValue)
- QueryParts.Add($"GuestID = {GuestID}");
+ QueryParts.Add($"GuestID = @GID");
if (TransactionID.HasValue)
- QueryParts.Add($"TransactionID = {TransactionID}");
+ QueryParts.Add($"TransactionID = @TID");
if (IsNoShow.HasValue)
- QueryParts.Add($"IsNoShow = {Convert.ToInt32(IsNoShow)}");
+ QueryParts.Add($"IsNoShow = @IsNoShow");
if (Type.HasValue)
- QueryParts.Add($"Type = {(int)Type}");
+ QueryParts.Add($"Type = @Type");
if (Status.HasValue)
- QueryParts.Add($"Status = {(int)Status}");
+ QueryParts.Add($"Status = @Status");
if (CreationDate.HasValue)
- QueryParts.Add($"CreationDate = {CreationDate.Value.Date.ToString("yyyy-MM-dd")}");
+ QueryParts.Add($"CreationDate = @CreationDate");
if (StartDate.HasValue)
- QueryParts.Add($"StartDate = {StartDate.Value.Date.ToString("yyyy-MM-dd")}");
+ QueryParts.Add($"StartDate = @StartDate");
if (EndDate.HasValue)
- QueryParts.Add($"EndDate = {EndDate.Value.Date.ToString("yyyy-MM-dd")}");
+ QueryParts.Add($"EndDate = @EndDate");
if (CheckIn.HasValue)
- QueryParts.Add($"CheckIn = {CheckIn.Value.Date.ToString("yyyy-MM-dd")}");
+ QueryParts.Add($"CheckIn = @CheckIn");
if (CheckOut.HasValue)
- QueryParts.Add($"CheckOut = {CheckOut.Value.Date.ToString("yyyy-MM-dd")}");
+ QueryParts.Add($"CheckOut = @CheckOut");
if (DateChanged.HasValue)
- QueryParts.Add($"DateChanged = {DateChanged.Value.Date.ToString("yyyy-MM-dd")}");
+ QueryParts.Add($"DateChanged = @DateChanged");
if (QueryParts.Count > 0)
- query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
+ query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
else
return null;
return query;
}
- internal static string CreateTransaction(double Rate, double Owed,
- double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
- DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
- {
-
- return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn)
- VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {PayBy}, {PayBy}, {PaidOn});";
- }
-
- internal static string CreateReservation(int guestid, int transactionid, ReservationType type,
- ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
- DateTime? checkin = null, DateTime? checkout = null, DateTime? datechanged = null, bool? isnoshow = false)
- {
- return @$"INSERT INTO reservations (GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
- VALUES ({guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
- }
-
- internal static string CreateGuest(string FirstName, string LastName, string Email, string? CreditCard, string? Expiration, string? CCV)
- {
- if (CreditCard != null && Expiration != null && CCV != null)
- return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ('{FirstName}', '{LastName}', '{Email}', '{CreditCard}', '{Expiration}', '{CCV}');";
- else
- return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ('{FirstName}', '{LastName}', '{Email}');";
- }
-
internal static string? UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
List QueryParts = new List();
string query = "UPDATE guests SET";
if (!string.IsNullOrEmpty(FirstName))
- QueryParts.Add($"Fname = '{FirstName}'");
+ QueryParts.Add($"Fname = @Fname");
if (!string.IsNullOrEmpty(LastName))
- QueryParts.Add($"Lname = '{LastName}'");
+ QueryParts.Add($"Lname = @Lname");
if (!string.IsNullOrEmpty(LastName))
- QueryParts.Add($"Email = '{Email}'");
+ QueryParts.Add($"Email = @Email");
if (!string.IsNullOrEmpty(CreditCard))
- QueryParts.Add($"CreditCard = '{CreditCard}'");
+ QueryParts.Add($"CreditCard = @CC");
if (!string.IsNullOrEmpty(Expiration))
- QueryParts.Add($"Expiration = '{Expiration}'");
+ QueryParts.Add($"Expiration = @Expiry");
if (!string.IsNullOrEmpty(CCV))
- QueryParts.Add($"CCV = '{CCV}'");
+ QueryParts.Add($"CCV = @CCV");
if (QueryParts.Count > 0)
- query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
+ query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
else
return null;
diff --git a/OpheliasOasis/Managers/HotelManager.cs b/OpheliasOasis/Managers/HotelManager.cs
index e58df55..cd98936 100644
--- a/OpheliasOasis/Managers/HotelManager.cs
+++ b/OpheliasOasis/Managers/HotelManager.cs
@@ -12,12 +12,14 @@ namespace Ophelias.Managers
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name='{tableName}';";
+ cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=@Table;";
cmd.ExecuteNonQuery();
+ cmd.Parameters.AddWithValue("@Table", tableName);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
- LastId = reader.GetInt32(0);
+ if (reader.HasRows)
+ LastId = reader.GetInt32(0);
}
}
}
@@ -32,13 +34,15 @@ namespace Ophelias.Managers
{
cmd.CommandText = $@"SELECT COUNT(*)
FROM reservations
- WHERE DATE('{Date.Date.ToString("yyyy-MM-dd")}')
+ WHERE DATE(@Date)
BETWEEN StartDate AND EndDate;";
cmd.ExecuteNonQuery();
+ cmd.Parameters.AddWithValue("@Date", Date.Date.ToString("yyyy-MM-dd"));
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
- Occupancies.Add(reader.GetInt32(0));
+ if (reader.Read())
+ Occupancies.Add(reader.GetInt32(0));
}
}
}
@@ -47,7 +51,7 @@ namespace Ophelias.Managers
internal static int AvgOccupancySpan(DateTime Start, DateTime End)
{
int thirtyDayOcc = 0;
- int days = (int)(Start.Date - End.Date).TotalDays;
+ int days = (int)(End.Date - Start.Date).TotalDays;
using (DatabaseManager Manager = new DatabaseManager())
{
for (int i = 0; i < days; i++)
@@ -56,95 +60,21 @@ namespace Ophelias.Managers
{
cmd.CommandText = $@"SELECT COUNT(*)
FROM reservations
- WHERE DATE('{Start.AddDays(i).Date.ToString("yyyy-MM-dd")}')
+ WHERE DATE(@Date)
BETWEEN StartDate AND EndDate;";
cmd.ExecuteNonQuery();
+ cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
- thirtyDayOcc += reader.GetInt32(0);
+ if(reader.HasRows)
+ thirtyDayOcc += reader.GetInt32(0);
}
}
}
}
return thirtyDayOcc / days;
}
- internal static Reservation CreateReservation(Guest Guest, ReservationType Type,
- DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active)
- {
- int id; double Multiplier;
- switch (Type)
- {
- case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
- case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
- case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
- case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
- default: throw new NotImplementedException();
- }
- Transaction t = CreateTransaction(
- Rate: GetBaseRate(),
- Owed: TxFunctions.CalculateOwed(GetBaseRate(), (int)(StartDate.Date - EndDate.Date).TotalDays),
- Multiplier: Multiplier,
- PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
- );
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = QueryBuilder.CreateReservation(Guest.Id, t.Id, Type,
- Status, CreationDate, StartDate, EndDate);
- cmd.ExecuteNonQuery();
- }
- id = (int)Manager.con.LastInsertRowId;
- }
-
- return new Reservation(id, Guest, t, Type, Status, CreationDate, StartDate, EndDate);
- }
- internal static Transaction CreateTransaction(double Rate, double Owed,
- double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
- DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
- {
- int Id;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy,Refund: Refund, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
- cmd.ExecuteNonQuery();
- }
- Id = (int)Manager.con.LastInsertRowId;
- }
- return new Transaction(Id, Rate, Owed, Multiplier, Penalty: Penalty, RefundAmount: Refund, PayBy: PayBy, PaidOn: PaidOn);
- }
- internal static Guest CreateGuest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
- {
- int Id;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = QueryBuilder.CreateGuest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
- cmd.ExecuteNonQuery();
- }
- Id = (int)Manager.con.LastInsertRowId;
- }
-
- if (CreditCard != null && Expiration != null && CCV != null)
- return new Guest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
- else
- return new Guest(Id, FirstName, LastName, Email);
- }
- internal static void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
- {
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
- cmd.ExecuteNonQuery();
- }
- }
- }
internal static Guest? GetGuestByEmail(string Email)
{
Guest? g = null;
@@ -152,7 +82,8 @@ namespace Ophelias.Managers
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- cmd.CommandText = $"SELECT * FROM guests WHERE email = '{Email}'";
+ cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
+ cmd.Parameters.AddWithValue("@Email", Email);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
@@ -173,9 +104,57 @@ namespace Ophelias.Managers
}
return g;
}
- internal static double GetBaseRate()
+ internal static Reservation? GetResByGuestAndDate(Guest g)
{
- double rate;
+ Reservation? r = null;
+ Transaction? t;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ int? RoomNumber = null;
+ DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
+
+ cmd.CommandText = @"SELECT * FROM reservations
+ INNER JOIN transactions ON reservations.TransactionID = transactions.ID
+ WHERE GuestID = @GuestID AND Status = @Status;";
+ cmd.Parameters.AddWithValue("@GuestID", g.Id);
+ cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Active);
+ cmd.ExecuteNonQuery();
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ if (reader[20].GetType() != typeof(DBNull))
+ LastPaid = reader.GetDateTime(20);
+ if (reader[21].GetType() != typeof(DBNull))
+ PaidOn = reader.GetDateTime(21);
+ t = new Transaction(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(19),
+ LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16));
+
+ if (reader[1].GetType() != typeof(DBNull))
+ RoomNumber = reader.GetInt32(1);
+ if (reader[10].GetType() != typeof(DBNull))
+ CheckIn = reader.GetDateTime(10);
+ if (reader[11].GetType() != typeof(DBNull))
+ CheckOut = reader.GetDateTime(11);
+ if (reader[12].GetType() != typeof(DBNull))
+ DateChanged = reader.GetDateTime(12);
+
+ r = new Reservation(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
+ reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
+ CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
+ }
+ }
+ }
+ }
+ return r;
+ }
+ internal static double? GetBaseRate()
+ {
+ double? rate;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
@@ -186,7 +165,10 @@ namespace Ophelias.Managers
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
- rate = reader.GetDouble(0);
+ if (reader.HasRows)
+ rate = reader.GetDouble(0);
+ else
+ rate = null;
}
}
}
@@ -199,8 +181,10 @@ namespace Ophelias.Managers
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- string query = $"INSERT INTO rates (Rate, DateSet) VALUES ({Rate}, {DateSet});";
+ string query = $"INSERT INTO rates (Rate, DateSet) VALUES (@Rate, @DateSet);";
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Rate", Rate);
+ cmd.Parameters.AddWithValue("@DateSet", DateSet);
cmd.ExecuteNonQuery();
}
}
@@ -224,8 +208,9 @@ namespace Ophelias.Managers
int? Id;
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- string query = $"SELECT Id FROM rates WHERE DateSet = {DateTime.Now.Date.ToString("yyyy-MM-dd")};";
+ string query = "SELECT Id FROM rates WHERE DateSet = @Date;";
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
@@ -237,8 +222,10 @@ namespace Ophelias.Managers
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- cmd.CommandText = $@"UPDATE rates SET DefaultRate = NULL WHERE Id = {OldId};
- UPDATE rates SET DefaultRate = 1 WHERE Id = {Id}";
+ cmd.CommandText = @"UPDATE rates SET DefaultRate = NULL WHERE Id = @OldID;
+ UPDATE rates SET DefaultRate = 1 WHERE Id = @ID";
+ cmd.Parameters.AddWithValue("@OldID", OldId);
+ cmd.Parameters.AddWithValue("@ID", Id);
cmd.ExecuteNonQuery();
}
}
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
index 294b882..1f1cce7 100644
--- a/OpheliasOasis/Models/Guest.cs
+++ b/OpheliasOasis/Models/Guest.cs
@@ -1,9 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Ophelias.Models;
+using Ophelias.Managers;
+using System.Data.SQLite;
namespace Ophelias.Models
{
@@ -17,6 +13,44 @@ namespace Ophelias.Models
internal string? CCV;
internal string? Expiration;
+ internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
+ {
+ int Id;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " +
+ "VALUES (@Fname, @Lname, @Email, @CC, @Expiry, @CCV);";
+ cmd.Parameters.AddWithValue("@Fname", FirstName);
+ cmd.Parameters.AddWithValue("@Lname", LastName);
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@CreditCard", CreditCard);
+ cmd.Parameters.AddWithValue("@Expiration", Expiration);
+ cmd.Parameters.AddWithValue("@CCV", CCV);
+ cmd.ExecuteNonQuery();
+ }
+ Id = (int)Manager.con.LastInsertRowId;
+ }
+
+ if (CreditCard != null && Expiration != null && CCV != null)
+ {
+ this.Id = Id;
+ this.FirstName = FirstName;
+ this.LastName = LastName;
+ this.Email = Email;
+ this.CreditCard = CreditCard;
+ this.Expiration = Expiration;
+ this.CCV = CCV;
+ }
+ else
+ {
+ this.Id = Id;
+ this.FirstName = FirstName;
+ this.LastName = LastName;
+ this.Email = Email;
+ }
+ }
internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
this.Id = Id;
@@ -27,6 +61,28 @@ namespace Ophelias.Models
this.Expiration = Expiration;
this.CCV = CCV;
}
+ internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
+ {
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ if (FirstName != null)
+ this.FirstName = FirstName;
+ if (LastName != null)
+ this.LastName = LastName;
+ if (FirstName != null)
+ this.Email = Email;
+ this.CreditCard = CreditCard;
+ if (FirstName != null)
+ this.Expiration = Expiration;
+ if (FirstName != null)
+ this.CCV = CCV;
+ }
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
{
this.CreditCard = CreditCard;
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index 5f85949..9570da4 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -9,7 +9,7 @@ namespace Ophelias.Models
internal class Reservation
{
internal int Id;
- internal Room Room;
+ internal int? RoomNum;
internal Guest Guest;
internal Transaction Transaction;
@@ -26,10 +26,84 @@ namespace Ophelias.Models
internal DateTime? CheckOut;
internal DateTime? DateChanged;
+ internal Reservation(Guest Guest, ReservationType Type,
+ DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active,
+ bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null, int? RoomNum = null)
+ {
+ int Id; double Multiplier;
+ switch (Type)
+ {
+ case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
+ case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
+ case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
+ case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
+ default: throw new NotImplementedException();
+ }
+ double? BaseRate = HotelManager.GetBaseRate();
+ if (BaseRate == null) {
+ throw new NotImplementedException();
+ }
+
+ Transaction Transaction = new Transaction(
+ Rate: (double)BaseRate,
+ Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays),
+ Multiplier: Multiplier,
+ PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
+ );
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ if (RoomNum != null)
+ this.RoomNum = RoomNum;
+ cmd.CommandText =
+ "INSERT INTO reservations (RoomNum, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged) " +
+ "VALUES (@RoomNum, @GuestID, @TransactionID, @IsNoShow, @Type, @Status, @CreationDate, @StartDate, @EndDate, @CheckIn, @CheckOut, @DateChanged);";
+ cmd.Parameters.AddWithValue("@RoomNum", RoomNum);
+ cmd.Parameters.AddWithValue("@GuestID", Guest.Id);
+ cmd.Parameters.AddWithValue("@TransactionID", Transaction.Id);
+ cmd.Parameters.AddWithValue("@IsNoShow", Convert.ToInt32(IsNoShow));
+ cmd.Parameters.AddWithValue("@Type", (int)Type);
+ cmd.Parameters.AddWithValue("@Status", (int)Status);
+ cmd.Parameters.AddWithValue("@CreationDate", CreationDate.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
+ if (CheckIn.HasValue)
+ cmd.Parameters.AddWithValue("@CheckIn", CheckIn.Value.ToString("yyyy-MM-dd"));
+ else
+ cmd.Parameters.AddWithValue("@CheckIn", CheckIn);
+ if (CheckOut.HasValue)
+ cmd.Parameters.AddWithValue("@CheckOut", CheckOut.Value.ToString("yyyy-MM-dd"));
+ else
+ cmd.Parameters.AddWithValue("@CheckOut", CheckOut);
+ if (DateChanged.HasValue)
+ cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
+ else
+ cmd.Parameters.AddWithValue("@DateChanged", DateChanged);
+
+ cmd.ExecuteNonQuery();
+ }
+ Id = (int)Manager.con.LastInsertRowId;
+ }
+ this.Id = Id;
+ this.RoomNum = RoomNum;
+ this.Guest = Guest;
+ this.Transaction = Transaction;
+ this.IsNoShow = IsNoShow;
+ this.Type = Type;
+ this.Status = Status;
+ this.CreationDate = CreationDate;
+ this.StartDate = StartDate;
+ this.EndDate = EndDate;
+ this.CheckIn = CheckIn;
+ this.CheckOut = CheckOut;
+ this.DateChanged = DateChanged;
+ }
internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
- DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
+ DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null, int? RoomNum = null)
{
this.Id = Id;
+ this.RoomNum = RoomNum;
this.Guest = Guest;
this.Transaction = Transaction;
this.IsNoShow = IsNoShow;
@@ -57,23 +131,38 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@Status", Status);
+ cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
- Transaction.UpdateTransactionFees(HotelManager.GetBaseRate(), TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
+ double? BaseRate = HotelManager.GetBaseRate();
+ if (BaseRate == null)
+ throw new ArgumentNullException(nameof(BaseRate));
+ Transaction.UpdateTransactionFees((double)BaseRate, TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
}
internal void CancelReservation()
{
+ DateTime _DateChanged = DateTime.Now.Date;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: DateTime.Now.Date);
+ string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: _DateChanged);
if (query == null)
throw new Exception();
+ Status = ReservationStatus.Cancelled;
+ DateChanged = _DateChanged;
+
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@Status", Status);
+ cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
diff --git a/OpheliasOasis/Models/Room.cs b/OpheliasOasis/Models/Room.cs
index 0601331..68ab2e0 100644
--- a/OpheliasOasis/Models/Room.cs
+++ b/OpheliasOasis/Models/Room.cs
@@ -6,12 +6,12 @@ using System.Threading.Tasks;
namespace Ophelias.Models
{
- internal class Room
+ internal class @int
{
internal int Id;
internal bool Occupied;
- internal Room(int id)
+ internal @int(int id)
{
Id = id;
Occupied = false;
@@ -20,11 +20,11 @@ namespace Ophelias.Models
internal class RoomList
{
- internal List Rooms;
+ internal List<@int> Rooms;
internal RoomList()
{
- Rooms = new List();
+ Rooms = new List<@int>();
}
}
}
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index 6b2d957..d1c0e03 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -21,6 +21,49 @@ namespace Ophelias.Models
internal DateTime? LastPaid { get; set; } = null;
internal DateTime? PaidOn { get; set; } = null;
+ internal Transaction(double Rate, double Owed,
+ double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
+ DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
+ {
+ int Id;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn) " +
+ "VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @PayBy, @LastPaid, @PaidOn)";
+ cmd.Parameters.AddWithValue("@Rate", Rate);
+ cmd.Parameters.AddWithValue("@Owed", Owed);
+ cmd.Parameters.AddWithValue("@Multiplier", Multiplier);
+ cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
+ cmd.Parameters.AddWithValue("@Penalty", Penalty);
+ cmd.Parameters.AddWithValue("@PayBy", PayBy.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
+ cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
+ if (LastPaid != null)
+ cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
+ else
+ cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
+ if (PaidOn != null)
+ cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
+ else
+ cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
+
+ //cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy, Refund: RefundAmount, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
+ cmd.ExecuteNonQuery();
+ }
+ Id = (int)Manager.con.LastInsertRowId;
+ }
+ this.Id = Id;
+ this.Rate = Rate;
+ this.Owed = Owed;
+ this.Penalty = Penalty;
+ this.Multiplier = Multiplier;
+ this.RefundAmount = RefundAmount;
+ this.PayBy = PayBy;
+ this.LastPaid = LastPaid;
+ this.PaidOn = PaidOn;
+ }
internal Transaction(int Id, double Rate, double Owed,
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
@@ -51,6 +94,10 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@Rate", this.Rate);
+ cmd.Parameters.AddWithValue("@Multiplier", this.Multiplier);
+ cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
@@ -75,6 +122,11 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@Owed", Owed);
+ cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
+ cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
+ cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
cmd.ExecuteNonQuery();
}
}
@@ -92,6 +144,8 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
cmd.ExecuteNonQuery();
}
}
@@ -125,7 +179,7 @@ namespace Ophelias.Models
}
internal static double CalculateOwed(double Rate, int Days)
{
- return Rate * (double)Days;
+ return Rate * Days;
}
diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs
index 2fa774e..777295f 100644
--- a/OpheliasOasis/Program.cs
+++ b/OpheliasOasis/Program.cs
@@ -9,6 +9,56 @@ class Program
{
Reservation? activeReservation = null;
Guest? activeGuest = null;
+ void help()
+ {
+ Console.WriteLine(
+ "Reservation Commands:\n" +
+ "\treservation create - Create a new reservation.\n" +
+ "\treservation update - Update your active reservation.\n" +
+ "\treservation cancel - Cancel a reservation.\n" +
+ "Account Commands:\n" +
+ "\taccount create - Create a new guest account.\n" +
+ "\taccount update - Update your account information.\n" +
+ "\taccount login - Log into your guest account." +
+ "Enter Q to quit.\n"
+ );
+ return;
+ }
+
+ (string?, string?, string?) GetCreditCardInformation()
+ {
+ Console.Write("What is your credit card number: ");
+ string CreditCard = "";
+ while (!Validation.ValidateCreditCard(CreditCard))
+ {
+ CreditCard = Console.ReadLine().Trim().Replace("\t", "");
+ if (CreditCard == "q" || CreditCard == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateCreditCard(CreditCard))
+ Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
+ }
+ Console.Write("What is your credit card expiration date (MM/yy): ");
+ string CardExpiration = "";
+ while (!Validation.ValidateExpirationDate(CardExpiration))
+ {
+ CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
+ if (CardExpiration == "q" || CardExpiration == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateExpirationDate(CardExpiration))
+ Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
+ }
+ Console.Write("What is your credit card CCV: ");
+ string CCV = "";
+ while (!Validation.ValidateCCV(CCV))
+ {
+ CCV = Console.ReadLine().Trim().Replace("\t", "");
+ if (CCV == "q" || CCV == "Q")
+ return (null, null, null);
+ if (!Validation.ValidateCCV(CCV))
+ Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
+ }
+ return (CreditCard, CardExpiration, CCV);
+ }
(string, string) GetGuestName() {
Console.Write("What is your first name: ");
string FirstName = "";
@@ -40,21 +90,6 @@ class Program
}
return Email;
}
- void help()
- {
- Console.WriteLine(
- "Reservation Commands:\n" +
- "\treservation create - Create a new reservation.\n" +
- "\treservation update - Update your active reservation.\n" +
- "\treservation cancel - Cancel a reservation.\n" +
- "Account Commands:\n" +
- "\taccount create - Create a new guest account.\n" +
- "\taccount update - Update your account information.\n" +
- "\taccount login - Log into your guest account." +
- "Enter Q to quit.\n"
- );
- return;
- }
void GuestLogin()
{
Console.Write("\nEnter your email address: ");
@@ -67,8 +102,12 @@ class Program
}
activeGuest = HotelManager.GetGuestByEmail(email);
if (activeGuest == null)
+ {
Console.WriteLine($"\nNo account was found with the email {email}.");
+ return;
+ }
Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
+ activeReservation = HotelManager.GetResByGuestAndDate(activeGuest);
}
void CreateNewGuestPrompt()
{
@@ -81,7 +120,7 @@ class Program
if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
(CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
- activeGuest = HotelManager.CreateGuest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
+ activeGuest = new Guest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
Console.Write($"You are now logged in as {FirstName} {LastName} ({Email})");
}
void UpdateGuestInformation()
@@ -136,7 +175,7 @@ class Program
if (NewDetails.Count > 0)
changes += string.Join("\n", NewDetails);
Console.WriteLine($"The following changes have been made:\n {changes}");
- HotelManager.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
+ activeGuest.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
return;
}
@@ -153,7 +192,6 @@ class Program
switch (Console.ReadLine())
{
case "Q": return;
- case "q": return;
case "1": (NewFname, NewLname) = GetGuestName(); break;
case "2": NewEmail = GetGuestEmail(); break;
case "3": (NewCard, NewExpiry, NewCCV) = GetCreditCardInformation(); break;
@@ -162,134 +200,230 @@ class Program
}
} while (true);
}
+ ReservationType SelectReservation()
+ {
+ string input = "";
+ Console.Write("What kind of reservation would you like to make?\n" +
+ "1. Conventional\n" +
+ "2. Prepaid\n" +
+ "3. 60 Day Advance\n" +
+ "4. Incentive\n" +
+ "Input a number: ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (input == "1" || input == "2" || input == "3" || input == "4")
+ break;
+ Console.Write("Please enter either 1, 2, 3, or 4: ");
+ }
+ return (ReservationType)Convert.ToInt32(input);
+ }
+ (DateTime, DateTime) SelectDate()
+ {
+ string input = "";
+ DateTime _StartDate;
+ DateTime _EndDate;
+ Console.Write("When would you like to begin your stay.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out _StartDate))
+ break;
+
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ Console.Write("When would you like to end your stay.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
+ break;
+
+ if (_EndDate < _StartDate)
+ Console.Write("End date cannot be before start date. Please enter a valid date (2021-12-31): ");
+ else
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ return (_StartDate.Date, _EndDate.Date);
+ }
+ void EditReservationPrompt()
+ {
+ string input;
+ DateTime NewStartDate = activeReservation.StartDate, NewEndDate = activeReservation.EndDate;
+ ReservationType NewType = activeReservation.Type;
+
+ bool completed = false;
+ do
+ {
+ Console.Write("What information would you like to edit?\n" +
+ "If not and you wish to cancel, enter Q to exit. If you want to save and complete your changes, enter S.\n" +
+ "1. Reservation type\n" +
+ "2. Reservation dates\n" +
+ "Enter 1 or 2: ");
+ input = Console.ReadLine();
+ switch (input)
+ {
+ case "Q": Console.WriteLine("Changes have has been deleted."); return;
+ case "1": NewType = SelectReservation(); break;
+ case "2": (NewStartDate, NewEndDate) = SelectDate(); break;
+ case "S":
+ completed = true;
+ (activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, NewStartDate, NewEndDate);
+ break;
+ default: break;
+ }
+ } while (!completed);
+ }
void CreateNewReservation()
{
if (activeGuest == null)
+ {
Console.WriteLine("No guest is currently logged in, please login.");
+ return;
+ }
if (activeReservation != null)
- Console.WriteLine("");
-
- string input = "";
- ReservationType SelectReservation()
{
- Console.Write("What kind of reservation would you like to make?\n" +
- "1. Conventional\n" +
- "2. Prepaid\n" +
- "3. 60 Day Advance\n" +
- "4. Incentive\n" +
- "Input a number: ");
- while (true)
- {
- input = Console.ReadLine();
- if (input == "1" || input == "2" || input == "3" || input == "4")
- break;
- Console.Write("Please enter either 1, 2, 3, or 4: ");
- }
- return (ReservationType)Convert.ToInt32(input);
+ Console.WriteLine("You currently have an active registration.");
+ return;
}
- (DateTime, DateTime) SelectDate()
+ if (HotelManager.GetBaseRate() == null)
{
- DateTime _StartDate;
- DateTime _EndDate;
- Console.Write("When would you like to begin your stay.\n" +
- "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
- "Input a date (2021-12-31): ");
- while(true)
- {
- input = Console.ReadLine();
- if (DateTime.TryParse(input, out _StartDate))
- break;
-
- Console.Write("Please enter a valid date (2021-12-31): ");
- }
- Console.Write("When would you like to end your stay.\n" +
- "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
- "Input a date (2021-12-31): ");
- while (true)
- {
- input = Console.ReadLine();
- if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
- break;
-
- if (_EndDate < _StartDate)
- Console.Write("End date cannot be before start date. Please enter a valid date (2021-12-31): ");
- else
- Console.Write("Please enter a valid date (2021-12-31): ");
- }
- return (_StartDate.Date, _EndDate.Date);
+ Console.WriteLine("Unable to proceed with reservation due to no base rate being set. Please inform an employee.");
+ return;
}
+ string input;
+
ReservationType Type;
DateTime StartDate;
DateTime EndDate;
Type = SelectReservation();
(StartDate, EndDate) = SelectDate();
- if (Type != ReservationType.SixtyDayAdvance &&
- (activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))
+ while((Type != ReservationType.SixtyDayAdvance &&
+ (activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))) {
+ Console.Write("The reservation type you chose requires you to specify your credit card.\n" +
+ "If you are unable to provide one, enter Q to quit or hit enter to continue.\n" +
+ ": ");
+ input = Console.ReadLine();
+ if (input == "Q")
+ return;
GetCreditCardInformation();
+ }
- Console.WriteLine($"Thank you for filling out your reservation details. Currently you have made a {Type}" +
+ Console.Write($"Thank you for filling out your reservation details. Currently you have made a {Type} " +
$"reservation and are scheduled to stay from {StartDate.ToString("yyyy-MM-dd")} to {EndDate.ToString("yyyy-MM-dd")}." +
- $"If these details are correct, enter YES to complete. If they are not enter...\n" +
- $"1. Change your reservation type\n" +
- $"2. Change your reservation dates\n" +
+ $"If these details are correct, enter YES to complete. To cancel your reservation enter Q. Enter NO to edit your reservation.\n" +
$": ");
input = Console.ReadLine();
- if (input != "YES")
+ while(input != "YES")
{
- bool completed = false;
- do
+ if (input == "NO")
{
- Console.Write("Would you like to edit any information, enter Q to exit and complete your reservation?\n" +
- "1. Reservation type\n" +
- "2. Reservation dates\n" +
- "Enter 1 or 2: ");
- switch (Console.ReadLine())
- {
- case "Q": completed = true; break;
- case "q": completed = true; break;
- case "1": SelectReservation(); break;
- case "2": SelectDate(); break;
- default: break;
- }
- } while (!completed);
+ EditReservationPrompt();
+ Console.Write("You're changes have been saved. Are you done with your changes?\n" +
+ "Enter YES to finish, NO to continue editing, or Q to discard your reservation.\n" +
+ ": ");
+ input = Console.ReadLine();
+ }
+ else if (input == "Q")
+ {
+ Console.WriteLine("Reservation has been deleted.");
+ return;
+ } else
+ {
+ Console.WriteLine("Input must be YES, NO, or Q.\n: ");
+ input = Console.ReadLine();
+ }
}
- HotelManager.CreateReservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
+ activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
+ Console.WriteLine("Your reservation has been made.");
}
- (string?, string?, string?) GetCreditCardInformation()
+ void UpdateReservation()
{
- Console.Write("What is your credit card number: ");
- string CreditCard = "";
- while (!Validation.ValidateCreditCard(CreditCard))
+ string input = "NO";
+ if (activeGuest == null)
{
- CreditCard = Console.ReadLine().Trim().Replace("\t", "");
- if (CreditCard == "q" || CreditCard == "Q")
- return (null, null, null);
- if (!Validation.ValidateCreditCard(CreditCard))
- Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
+ Console.WriteLine("No guest is currently logged in, please login.");
+ return;
}
- Console.Write("What is your credit card expiration date (MM/yy): ");
- string CardExpiration = "";
- while (!Validation.ValidateExpirationDate(CardExpiration))
+ if (activeReservation == null)
{
- CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
- if (CardExpiration == "q" || CardExpiration == "Q")
- return (null, null, null);
- if (!Validation.ValidateExpirationDate(CardExpiration))
- Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
+ Console.WriteLine("You currently do not have an active registration.");
+ return;
}
- Console.Write("What is your credit card CCV: ");
- string CCV = "";
- while (!Validation.ValidateCCV(CCV))
+
+ Console.Write("Your current reservation details are:\n" +
+ $"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")}\n" +
+ $"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")}\n");
+ DateTime? _StartDate = null, _EndDate = null;
+ do
{
- CCV = Console.ReadLine().Trim().Replace("\t", "");
- if (CCV == "q" || CCV == "Q")
- return (null, null, null);
- if (!Validation.ValidateCCV(CCV))
- Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
+ if (input == "NO")
+ {
+ (_StartDate, _EndDate) = SelectDate();
+ if (_StartDate.HasValue && _EndDate.HasValue)
+ Console.Write("Your new reservation details are:\n" +
+ $"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")} -> {_StartDate.Value.ToString("yyyy-MM-dd")}\n" +
+ $"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")} -> {_EndDate.Value.ToString("yyyy-MM-dd")}\n");
+ Console.Write("Are you done with your changes?\n" +
+ "Enter YES to finish and save, NO to continue editing.\n" +
+ ": ");
+ } else if (input == "Q")
+ {
+ Console.WriteLine("Your changes have been discarded.");
+ return;
+ }
+ else
+ {
+ Console.WriteLine("Input must be YES, NO, or Q.");
+ Console.Write(": ");
+ }
+ input = Console.ReadLine();
+ } while (input != "YES");
+ if (_StartDate != null && _EndDate != null)
+ {
+ activeReservation.ChangeReservationDates((DateTime)_StartDate, (DateTime)_EndDate);
+ Console.WriteLine("Your changes have been saved.");
}
- return (CreditCard, CardExpiration, CCV);
+ return;
+ }
+ void CancelReservation()
+ {
+ if (activeGuest == null)
+ {
+ Console.WriteLine("No guest is currently logged in, please login.");
+ return;
+ }
+ if (activeReservation == null)
+ {
+ Console.WriteLine("You currently do not have an active registration.");
+ return;
+ }
+ string input;
+ Console.Write("Would you like to cancel your reservation?\n" +
+ "You may be charged depending on your reservation.\n" +
+ "Enter YES to confirm or NO to exit: ");
+ input = Console.ReadLine();
+ while(input != "YES")
+ {
+ if (input == "NO")
+ {
+ Console.Write("Reservation has not been cancelled.");
+ return;
+ } else
+ {
+ Console.Write("Your input must be YES or NO: ");
+ Console.ReadLine();
+ }
+ }
+ activeReservation.CancelReservation();
+ activeReservation = null;
+ Console.Write("Reservation has been cancelled, you may be charged based on your reservation.");
}
Console.Write(
"\nWelcome to the Ophelias Oasis Hotel Registration System!\n" +
@@ -304,8 +438,8 @@ class Program
{
case "help": help(); break;
case "reservation create": CreateNewReservation(); break;
- case "reservation update": break;
- case "reservation cancel": break;
+ case "reservation update": UpdateReservation(); break;
+ case "reservation cancel": CancelReservation(); break;
case "account create": CreateNewGuestPrompt(); break;
case "account update": UpdateGuestInformation(); break;
case "account login": GuestLogin(); break;
@@ -321,16 +455,50 @@ class Program
{
Console.WriteLine(
"Report Commands:\n" +
- "\treservation create\n" +
- "\treservation update\n" +
+ "\tgenerate daily report - Generates a daily report on expected occupancy, room income, and incentive losses.\n" +
+ "\tgenerate operational report - Generates a report of daily arrivals and occupancy.\n" +
+ "\tgenerate accomodation bills - Generates an accomodation bill that will be handed to guests upon checkout.\n" +
"\treservation cancel\n" +
- "Account Commands:" +
- "\taccount create\n" +
- "\taccount update\n" +
+ "Management Commands:" +
+ "\tcheckin guest - Checks in a guest and assigns them a room.\n" +
+ "\tcheckout guest - Checks out a guest and removes their room assignment.\n" +
+ "\tbaserate set - Sets a new base rate to begin after a specified date.\n" +
"Enter Q to quit.\n"
);
return;
}
+
+ void SetFutureBaseRate()
+ {
+ if (HotelManager.GetBaseRate() == null)
+ {
+ Console.Write("No base rate has been configured. " +
+ "You must set one for the current date.\n" +
+ "Enter new rate: ");
+ Console.ReadLine();
+ }
+ }
+
+ while (true)
+ {
+
+ string? input = Console.ReadLine();
+ switch (input)
+ {
+ case "help": help(); break;
+ case "generate daily report": break;
+ case "generate operational report": break;
+ case "generate accomodation bills": break;
+ case "reservation cancel": break;
+ case "checkin guest": break;
+ case "checkout guest": break;
+ case "baserate set": break;
+ case "Q": return;
+ default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
+ }
+ Console.Write("\nCommand: ");
+ }
+
}
static void Main()
{
From 14fb4b6050ab3f96e14c239e4cc378c0a00cf631 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Fri, 15 Apr 2022 03:09:43 -0400
Subject: [PATCH 08/10] Remove unused manager classes
---
OpheliasOasis/Managers/ResTableManager.cs | 16 ----------------
OpheliasOasis/Managers/TxTableManager.cs | 21 ---------------------
2 files changed, 37 deletions(-)
delete mode 100644 OpheliasOasis/Managers/ResTableManager.cs
delete mode 100644 OpheliasOasis/Managers/TxTableManager.cs
diff --git a/OpheliasOasis/Managers/ResTableManager.cs b/OpheliasOasis/Managers/ResTableManager.cs
deleted file mode 100644
index 16eb956..0000000
--- a/OpheliasOasis/Managers/ResTableManager.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-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 static class ReservationTableManager
- {
-
- }
-}
diff --git a/OpheliasOasis/Managers/TxTableManager.cs b/OpheliasOasis/Managers/TxTableManager.cs
deleted file mode 100644
index 27499f1..0000000
--- a/OpheliasOasis/Managers/TxTableManager.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-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;
- }
- }
-}
From 6fb0f5c466125939211e748115a5531bd5dc7881 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Fri, 15 Apr 2022 19:11:03 -0400
Subject: [PATCH 09/10] Added reporting classes and implemented/ updated
terminal commands
This commit versions the inital classes used for reporting. Some of the
manager classes have been adjusted so that they can also be used in the
reporting system since the queries are very similar. The terminal
commands and flow have been improved to further close in on the design
spec. Guests who make reservations now abide by the fixed rules
determined by the doc. For example Prepaid and 60 day reservations have
requirements on how far away a reservation needs to be at minimum. The
reservation creation process now takes this into account. The base rate
functionality has been hooked up and the queries have been verified to
work at least once. The same applies for CheckIn() and CheckOut()
functions.
---
OpheliasOasis/Managers/DatabaseManager.cs | 2 +-
OpheliasOasis/Managers/HotelManager.cs | 203 +++++++++++-
OpheliasOasis/Models/Reservation.cs | 4 +-
OpheliasOasis/Models/Transaction.cs | 6 +-
OpheliasOasis/Program.cs | 358 +++++++++++++++++-----
OpheliasOasis/Reporting/Accomodation.cs | 12 +
OpheliasOasis/Reporting/Email.cs | 12 +
OpheliasOasis/Reporting/Management.cs | 12 +
OpheliasOasis/Reporting/Operational.cs | 12 +
OpheliasOasis/Validation.cs | 22 +-
10 files changed, 549 insertions(+), 94 deletions(-)
create mode 100644 OpheliasOasis/Reporting/Accomodation.cs
create mode 100644 OpheliasOasis/Reporting/Email.cs
create mode 100644 OpheliasOasis/Reporting/Management.cs
create mode 100644 OpheliasOasis/Reporting/Operational.cs
diff --git a/OpheliasOasis/Managers/DatabaseManager.cs b/OpheliasOasis/Managers/DatabaseManager.cs
index ec768a6..ef9649b 100644
--- a/OpheliasOasis/Managers/DatabaseManager.cs
+++ b/OpheliasOasis/Managers/DatabaseManager.cs
@@ -37,7 +37,7 @@ namespace Ophelias.Managers
CREATE TABLE IF NOT EXISTS [reservations] (
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[RoomNum] INTEGER NULL UNIQUE,
- [GuestID] INTEGER NOT NULL UNIQUE,
+ [GuestID] INTEGER NOT NULL,
[TransactionID] INTEGER NOT NULL UNIQUE,
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
[Type] INTEGER NOT NULL CHECK ([Type] IN (0,1,2,3)),
diff --git a/OpheliasOasis/Managers/HotelManager.cs b/OpheliasOasis/Managers/HotelManager.cs
index cd98936..39010ac 100644
--- a/OpheliasOasis/Managers/HotelManager.cs
+++ b/OpheliasOasis/Managers/HotelManager.cs
@@ -48,9 +48,10 @@ namespace Ophelias.Managers
}
return Occupancies;
}
- internal static int AvgOccupancySpan(DateTime Start, DateTime End)
+ internal static (int, bool) AvgOccupancySpan(DateTime Start, DateTime End)
{
int thirtyDayOcc = 0;
+ bool maxCapacityInRange = false;
int days = (int)(End.Date - Start.Date).TotalDays;
using (DatabaseManager Manager = new DatabaseManager())
{
@@ -61,19 +62,26 @@ namespace Ophelias.Managers
cmd.CommandText = $@"SELECT COUNT(*)
FROM reservations
WHERE DATE(@Date)
- BETWEEN StartDate AND EndDate;";
- cmd.ExecuteNonQuery();
+ BETWEEN @Start AND @End;";
cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Start", Start);
+ cmd.Parameters.AddWithValue("@End", End);
+ cmd.ExecuteNonQuery();
+
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
- if(reader.HasRows)
+ if (reader.HasRows)
+ {
thirtyDayOcc += reader.GetInt32(0);
+ if (reader.GetInt32(0) == 45)
+ maxCapacityInRange = true;
+ }
}
}
}
}
- return thirtyDayOcc / days;
+ return (thirtyDayOcc / days, maxCapacityInRange);
}
internal static Guest? GetGuestByEmail(string Email)
{
@@ -104,7 +112,7 @@ namespace Ophelias.Managers
}
return g;
}
- internal static Reservation? GetResByGuestAndDate(Guest g)
+ internal static Reservation? GetResByGuest(Guest g)
{
Reservation? r = null;
Transaction? t;
@@ -152,6 +160,35 @@ namespace Ophelias.Managers
}
return r;
}
+ internal static TimeRefs? CanBeCheckedIn(string Email)
+ {
+ TimeRefs? status = null;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (0,1)";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ DateTime dt = reader.GetDateTime(8);
+ if (dt.Date == DateTime.Now.Date)
+ status = TimeRefs.OnTime;
+ else if (dt.Date > DateTime.Now.Date)
+ status = TimeRefs.Late;
+ else if (dt.Date < DateTime.Now.Date)
+ status = TimeRefs.Early;
+ } else
+ status = null;
+ }
+ }
+ }
+ return status;
+ }
internal static double? GetBaseRate()
{
double? rate;
@@ -174,6 +211,29 @@ namespace Ophelias.Managers
}
return rate;
}
+ internal static bool GetBaseRateByDate(DateTime dt)
+ {
+ bool configured;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Rate FROM rates WHERE DateSet = @Date;";
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Date", dt.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ configured = true;
+ else
+ configured = false;
+ }
+ }
+ }
+ return configured;
+ }
internal static void SetBaseRate(double Rate, DateTime DateSet)
{
double rate;
@@ -184,7 +244,22 @@ namespace Ophelias.Managers
string query = $"INSERT INTO rates (Rate, DateSet) VALUES (@Rate, @DateSet);";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Rate", Rate);
- cmd.Parameters.AddWithValue("@DateSet", DateSet);
+ cmd.Parameters.AddWithValue("@DateSet", DateSet.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ internal static void UpdateBaseRate(double Rate, DateTime DateSet)
+ {
+ double rate;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Rate", Rate);
+ cmd.Parameters.AddWithValue("@Date", DateSet.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
@@ -231,13 +306,119 @@ namespace Ophelias.Managers
}
}
}
- internal static int CheckInGuest(DateTime CheckIn)
+ internal static int? CheckInGuest(string Email, DateTime CheckIn)
{
- return 1;
+ int? RoomID = null;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE reservations SET RoomNum = (SELECT ID FROM rooms WHERE Occupied = 0 LIMIT 1), CheckIn = @Date " +
+ "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NULL AND Status in (@SActive,@SChanged);";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.Parameters.AddWithValue("@Date", CheckIn.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE rooms SET Occupied = 1 " +
+ "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.ExecuteNonQuery();
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ RoomID = (int)reader.GetValue(0);
+ }
+ }
+ }
+ Transaction.Commit();
+ }
+ }
+ return RoomID;
}
- internal static int CheckOutGuest(DateTime CheckOut)
+ internal static bool GuestCurrentlyCheckedIn(string Email)
{
- return 1;
+ bool EntryFound;
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT * FROM reservations " +
+ "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)) AND CheckIn IS NOT NULL";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.ExecuteNonQuery();
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ EntryFound = true;
+ else
+ EntryFound = false;
+ }
+ }
+ }
+ return EntryFound;
+ }
+ internal static void CheckOutGuest(string Email, DateTime CheckOut)
+ {
+ using (DatabaseManager Manager = new DatabaseManager())
+ {
+ using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE rooms SET Occupied = 0 " +
+ "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Ended);
+ cmd.ExecuteNonQuery();
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE reservations SET RoomNum = NULL, CheckOut = @Date, Status = @Status " +
+ "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NOT NULL AND Status in (@SActive,@SChanged);";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Ended);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.Parameters.AddWithValue("@Date", CheckOut.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ }
+ Transaction.Commit();
+ }
+ }
+ return;
+ }
+ internal static List GetActiveSixtyDayRes()
+ {
+ List list = new List();
+ return list;
}
}
+ internal enum TimeRefs
+ {
+ OnTime,
+ Early,
+ Late
+ }
}
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index 9570da4..c312430 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -46,7 +46,7 @@ namespace Ophelias.Models
Transaction Transaction = new Transaction(
Rate: (double)BaseRate,
- Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays),
+ Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays, Multiplier),
Multiplier: Multiplier,
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
);
@@ -179,7 +179,7 @@ namespace Ophelias.Models
{
Conventional,
Prepaid,
- Incentive,
SixtyDayAdvance,
+ Incentive,
}
}
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index d1c0e03..f9ccc7e 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -161,7 +161,7 @@ namespace Ophelias.Models
internal static double IncentiveFee(DateTime Start, DateTime End)
{
int thirtyDayOcc;
- thirtyDayOcc = HotelManager.AvgOccupancySpan(Start, End);
+ (thirtyDayOcc, _) = HotelManager.AvgOccupancySpan(Start, End);
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
return 0.80;
return 1.0;
@@ -177,9 +177,9 @@ namespace Ophelias.Models
default: throw new NotImplementedException();
}
}
- internal static double CalculateOwed(double Rate, int Days)
+ internal static double CalculateOwed(double Rate, int Days, double Multiplier)
{
- return Rate * Days;
+ return Rate * Days * Multiplier;
}
diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs
index 777295f..bbda8b8 100644
--- a/OpheliasOasis/Program.cs
+++ b/OpheliasOasis/Program.cs
@@ -5,6 +5,19 @@ using System.Data.SQLite;
class Program
{
+ private static string GetGuestEmail()
+ {
+ Console.Write("Specify email: ");
+ string Email = "";
+ while (!Validation.ValidateEmail(Email))
+ {
+ Email = Console.ReadLine();
+ if (!Validation.ValidateEmail(Email))
+ Console.Write("Please enter a valid email: ");
+ }
+ return Email;
+ }
+
private static void GuestMode()
{
Reservation? activeReservation = null;
@@ -78,18 +91,6 @@ class Program
}
return (FirstName, LastName);
}
- string GetGuestEmail()
- {
- Console.Write("What is your email: ");
- string Email = "";
- while (!Validation.ValidateEmail(Email))
- {
- Email = Console.ReadLine();
- if (!Validation.ValidateEmail(Email))
- Console.Write("Please enter a valid email: ");
- }
- return Email;
- }
void GuestLogin()
{
Console.Write("\nEnter your email address: ");
@@ -107,7 +108,7 @@ class Program
return;
}
Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
- activeReservation = HotelManager.GetResByGuestAndDate(activeGuest);
+ activeReservation = HotelManager.GetResByGuest(activeGuest);
}
void CreateNewGuestPrompt()
{
@@ -216,44 +217,113 @@ class Program
break;
Console.Write("Please enter either 1, 2, 3, or 4: ");
}
- return (ReservationType)Convert.ToInt32(input);
+ return (ReservationType)(Convert.ToInt32(input) - 1);
}
- (DateTime, DateTime) SelectDate()
+ bool CheckReservationRestrictions(DateTime Date, ReservationType Type)
{
- string input = "";
- DateTime _StartDate;
- DateTime _EndDate;
- Console.Write("When would you like to begin your stay.\n" +
- "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
- "Input a date (2021-12-31): ");
- while (true)
+ if (Type == ReservationType.Prepaid)
{
- input = Console.ReadLine();
- if (DateTime.TryParse(input, out _StartDate))
- break;
-
- Console.Write("Please enter a valid date (2021-12-31): ");
- }
- Console.Write("When would you like to end your stay.\n" +
- "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
- "Input a date (2021-12-31): ");
- while (true)
- {
- input = Console.ReadLine();
- if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
- break;
-
- if (_EndDate < _StartDate)
- Console.Write("End date cannot be before start date. Please enter a valid date (2021-12-31): ");
+ if ((Date - DateTime.Now).TotalDays < 90)
+ {
+ Console.WriteLine("Prepaid reservations must be made 90 days in advance.");
+ }
else
- Console.Write("Please enter a valid date (2021-12-31): ");
+ {
+ return true;
+ }
}
- return (_StartDate.Date, _EndDate.Date);
+ else if (Type == ReservationType.SixtyDayAdvance)
+ {
+ if ((Date - DateTime.Now).TotalDays < 60)
+ {
+ Console.WriteLine("Sixty-days-in-advance reservations must be made 60 days in advance.");
+ }
+ else
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ (DateTime?, DateTime?) SelectDate(ReservationType Type)
+ {
+
+ (DateTime, DateTime) Dates()
+ {
+ string input = "";
+ DateTime _StartDate;
+ DateTime _EndDate;
+ Console.Write("When would you like to begin your stay.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out _StartDate) && _StartDate >= DateTime.Now)
+ break;
+
+ if (_StartDate <= DateTime.Now)
+ Console.Write("Start date cannot be before current date. Please enter a valid date (2021-12-31): ");
+ else
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ Console.Write("When would you like to end your stay.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
+ break;
+
+ if (_EndDate < _StartDate)
+ Console.Write("End date must be after start date. Please enter a valid date (2021-12-31): ");
+ else
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ return (_StartDate.Date, _EndDate.Date);
+ }
+
+ DateTime StartDate;
+ DateTime EndDate;
+ string input;
+
+ while (true)
+ {
+ bool maxCapacity = false;
+ (StartDate, EndDate) = Dates();
+ if (StartDate == null || EndDate == null)
+ (_, maxCapacity) = HotelManager.AvgOccupancySpan(StartDate, EndDate);
+ if (!maxCapacity)
+ {
+ if (!CheckReservationRestrictions(StartDate, Type))
+ {
+ Console.Write("Do you want to quit? Type YES to quit and discard, enter anything or nothing to select another date range.\n" +
+ ": ");
+ input = Console.ReadLine();
+ if (input == "YES")
+ {
+ Console.WriteLine("Aborting reservation changes.");
+ return (null, null);
+ }
+ } else
+ {
+ break;
+ }
+ }
+ else
+ {
+ Console.WriteLine("Your reservation covers a range where we are already at max capacity, please change your reservation dates.");
+ }
+
+ }
+ return (StartDate, EndDate);
+
}
void EditReservationPrompt()
{
string input;
- DateTime NewStartDate = activeReservation.StartDate, NewEndDate = activeReservation.EndDate;
+ DateTime? NewStartDate = activeReservation.StartDate, NewEndDate = activeReservation.EndDate;
ReservationType NewType = activeReservation.Type;
bool completed = false;
@@ -269,10 +339,18 @@ class Program
{
case "Q": Console.WriteLine("Changes have has been deleted."); return;
case "1": NewType = SelectReservation(); break;
- case "2": (NewStartDate, NewEndDate) = SelectDate(); break;
+ case "2": (NewStartDate, NewEndDate) = SelectDate(NewType); break;
case "S":
- completed = true;
- (activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, NewStartDate, NewEndDate);
+ if (NewStartDate == null || NewEndDate == null)
+ return;
+ while (CheckReservationRestrictions((DateTime)NewStartDate, NewType))
+ {
+ (NewStartDate, NewEndDate) = SelectDate(NewType);
+ if (NewStartDate == null || NewEndDate == null)
+ return;
+ }
+ completed = true;
+ (activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, (DateTime)NewStartDate, (DateTime)NewEndDate);
break;
default: break;
}
@@ -299,11 +377,17 @@ class Program
string input;
ReservationType Type;
- DateTime StartDate;
- DateTime EndDate;
+ DateTime? StartDate;
+ DateTime? EndDate;
Type = SelectReservation();
- (StartDate, EndDate) = SelectDate();
+ (StartDate, EndDate) = SelectDate(Type);
+ if (StartDate == null || EndDate == null)
+ {
+ Console.WriteLine("Aborting reservation creation.");
+ return;
+ }
+
while((Type != ReservationType.SixtyDayAdvance &&
(activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))) {
Console.Write("The reservation type you chose requires you to specify your credit card.\n" +
@@ -316,31 +400,27 @@ class Program
}
Console.Write($"Thank you for filling out your reservation details. Currently you have made a {Type} " +
- $"reservation and are scheduled to stay from {StartDate.ToString("yyyy-MM-dd")} to {EndDate.ToString("yyyy-MM-dd")}." +
- $"If these details are correct, enter YES to complete. To cancel your reservation enter Q. Enter NO to edit your reservation.\n" +
+ $"reservation and are scheduled to stay from {StartDate.Value.ToString("yyyy-MM-dd")} to {EndDate.Value.ToString("yyyy-MM-dd")}." +
+ $"If these details are correct, enter YES to complete. To cancel your reservation enter Q.\n" +
$": ");
input = Console.ReadLine();
while(input != "YES")
{
- if (input == "NO")
- {
- EditReservationPrompt();
- Console.Write("You're changes have been saved. Are you done with your changes?\n" +
- "Enter YES to finish, NO to continue editing, or Q to discard your reservation.\n" +
- ": ");
- input = Console.ReadLine();
- }
- else if (input == "Q")
+ if (input == "Q")
{
Console.WriteLine("Reservation has been deleted.");
return;
} else
{
- Console.WriteLine("Input must be YES, NO, or Q.\n: ");
+ Console.Write("Input must be YES or Q.\n: ");
input = Console.ReadLine();
}
}
- activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
+ if (Type == ReservationType.Prepaid)
+ {
+ activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
+ activeReservation.Transaction.Pay(activeReservation.Transaction.Owed);
+ }
Console.WriteLine("Your reservation has been made.");
}
void UpdateReservation()
@@ -365,7 +445,7 @@ class Program
{
if (input == "NO")
{
- (_StartDate, _EndDate) = SelectDate();
+ (_StartDate, _EndDate) = SelectDate(activeReservation.Type);
if (_StartDate.HasValue && _EndDate.HasValue)
Console.Write("Your new reservation details are:\n" +
$"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")} -> {_StartDate.Value.ToString("yyyy-MM-dd")}\n" +
@@ -449,7 +529,7 @@ class Program
Console.Write("\nCommand: ");
}
}
- private void AdminMode()
+ private static void AdminMode()
{
void help()
{
@@ -460,9 +540,11 @@ class Program
"\tgenerate accomodation bills - Generates an accomodation bill that will be handed to guests upon checkout.\n" +
"\treservation cancel\n" +
"Management Commands:" +
+ "\nnotify pending payments - Generates and emails 60 day advance reservations that they must pay for their reservation or it will be cancelled." +
+ "\nissue penalties - Issues penalties for guests that are no shows." +
"\tcheckin guest - Checks in a guest and assigns them a room.\n" +
"\tcheckout guest - Checks out a guest and removes their room assignment.\n" +
- "\tbaserate set - Sets a new base rate to begin after a specified date.\n" +
+ "\tset rate - Sets a new base rate to begin after a specified date.\n" +
"Enter Q to quit.\n"
);
return;
@@ -470,15 +552,148 @@ class Program
void SetFutureBaseRate()
{
+ bool SetRatePrompt(DateTime? FixedDate = null)
+ {
+ string input;
+ string amount;
+ amount = Console.ReadLine();
+ if (Validation.ValidateMoney(amount))
+ {
+ Console.Write($"Is this the correct base rate {amount}?\n" +
+ $"Enter YES or NO: ");
+ input = Console.ReadLine();
+ while (input != "YES")
+ {
+ if (input == "NO")
+ {
+ break;
+ }
+ else
+ {
+ Console.Write("Input must be YES or NO: ");
+ }
+ input = Console.ReadLine();
+ }
+ if (input == "YES")
+ {
+ if (FixedDate != null)
+ {
+ HotelManager.SetBaseRate(Convert.ToDouble(amount), (DateTime)FixedDate);
+ Console.WriteLine($"A base rate of {amount} has been set and will take effect on {FixedDate.Value.ToString("yyyy-MM-dd")}.");
+ } else
+ {
+ DateTime StartDate;
+ Console.Write("When would you like the new rate to take effect.\n" +
+ "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
+ "Input a date (2021-12-31): ");
+ while (true)
+ {
+ input = Console.ReadLine();
+ if (DateTime.TryParse(input, out StartDate))
+ if (StartDate.Date <= DateTime.Now.Date)
+ {
+ Console.WriteLine("Base rate must be configured for a future night. Not the same day or past.");
+ }
+ else if (HotelManager.GetBaseRateByDate(StartDate))
+ {
+
+ Console.Write("There is already a base rate configured for this date.\n" +
+ "Would you like to overwrite it (YES)? If not enter anything to continue." +
+ ": ");
+ if(Console.ReadLine() == "YES")
+ {
+ HotelManager.UpdateBaseRate(Convert.ToDouble(amount), StartDate.Date);
+ return true;
+ }
+ } else
+ {
+ break;
+ }
+ Console.Write("Please enter a valid date (2021-12-31): ");
+ }
+ HotelManager.SetBaseRate(Convert.ToDouble(amount), StartDate);
+ Console.WriteLine($"A base rate of {amount} has been set and will take effect on {DateTime.Now.Date.ToString("yyyy-MM-dd")}.");
+ }
+ return true;
+ }
+ }
+ else
+ {
+ Console.WriteLine("Your input was not a valid input, an example of a valid input would be 100 or 100.00.");
+ }
+ Console.Write("Enter new rate: ");
+ return false;
+ }
+
if (HotelManager.GetBaseRate() == null)
{
Console.Write("No base rate has been configured. " +
"You must set one for the current date.\n" +
"Enter new rate: ");
- Console.ReadLine();
+ while (!SetRatePrompt(DateTime.Now.Date)) { }
+ } else
+ {
+ Console.Write("What is the value of the rate you would like to set.\n" +
+ "Enter new rate: ");
+ while (!SetRatePrompt()) { }
}
}
+ void CheckIn()
+ {
+ string Email = GetGuestEmail();
+ TimeRefs? status = HotelManager.CanBeCheckedIn(Email);
+ Guest? g = HotelManager.GetGuestByEmail(Email);
+ if (g == null)
+ {
+ Console.WriteLine("No guest with that email exists.");
+ return;
+ }
+ if (!status.HasValue)
+ {
+ Console.WriteLine("No reservation exists for this email.");
+ return;
+ }
+ if (status.Value == TimeRefs.OnTime)
+ {
+ int? RoomID = HotelManager.CheckInGuest(Email, DateTime.Now.Date);
+ if (RoomID != null)
+ Console.WriteLine($"Guest has been checked in, their room number is {RoomID}.");
+ }
+ else if (status.Value == TimeRefs.Late)
+ {
+ Console.WriteLine("Since the reservation was not checked in on the date scheduled, it has been cancelled. The guest will be charged the \"no show\" penalty.");
+ Reservation? r = HotelManager.GetResByGuest(g);
+
+ if (r == null)
+ throw new Exception();
+ r.CancelReservation();
+
+ }
+ else if (status.Value == TimeRefs.Early)
+ {
+ Console.WriteLine("Since the reservation was not checked in on the date scheduled, it has been cancelled. The guest will be charged the \"no show\" penalty.");
+ }
+ return;
+ }
+ void CheckOut()
+ {
+ string Email = GetGuestEmail();
+ if (HotelManager.GuestCurrentlyCheckedIn(Email))
+ {
+ HotelManager.CheckOutGuest(Email, DateTime.Now.Date);
+ Console.WriteLine($"Guest has been checked out.");
+ } else
+ {
+ Console.WriteLine($"Can't checkout a guest that hasn't been checked in.");
+ }
+ return;
+ }
+
+ Console.Write(
+ "\nWelcome to the Ophelias Oasis Hotel Management System!\n" +
+ "Type help to get a full list of commands or enter a command.\n" +
+ "Command: ");
while (true)
{
@@ -489,10 +704,11 @@ class Program
case "generate daily report": break;
case "generate operational report": break;
case "generate accomodation bills": break;
- case "reservation cancel": break;
- case "checkin guest": break;
- case "checkout guest": break;
- case "baserate set": break;
+ case "notify pending payments": break;
+ case "issue penalties": break;
+ case "checkin guest": CheckIn(); break;
+ case "checkout guest": CheckOut(); break;
+ case "set rate": SetFutureBaseRate(); break;
case "Q": return;
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
}
@@ -502,7 +718,7 @@ class Program
}
static void Main()
{
-
+ HotelManager.CheckBaseRate();
if (!File.Exists("database.sqlite3") || new FileInfo("database.sqlite3").Length == 0)
{
SQLiteConnection.CreateFile("database.sqlite3");
@@ -524,7 +740,7 @@ class Program
);
switch(Console.ReadLine().ToUpper())
{
- case "1": break;
+ case "1": AdminMode(); 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;
diff --git a/OpheliasOasis/Reporting/Accomodation.cs b/OpheliasOasis/Reporting/Accomodation.cs
new file mode 100644
index 0000000..47d1c82
--- /dev/null
+++ b/OpheliasOasis/Reporting/Accomodation.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ophelias.Reporting
+{
+ internal class Accomodation
+ {
+ }
+}
diff --git a/OpheliasOasis/Reporting/Email.cs b/OpheliasOasis/Reporting/Email.cs
new file mode 100644
index 0000000..420ad0b
--- /dev/null
+++ b/OpheliasOasis/Reporting/Email.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ophelias.Reporting
+{
+ internal class Email
+ {
+ }
+}
diff --git a/OpheliasOasis/Reporting/Management.cs b/OpheliasOasis/Reporting/Management.cs
new file mode 100644
index 0000000..130eb3f
--- /dev/null
+++ b/OpheliasOasis/Reporting/Management.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ophelias.Reporting
+{
+ internal class Management
+ {
+ }
+}
diff --git a/OpheliasOasis/Reporting/Operational.cs b/OpheliasOasis/Reporting/Operational.cs
new file mode 100644
index 0000000..f62ef52
--- /dev/null
+++ b/OpheliasOasis/Reporting/Operational.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ophelias.Reporting
+{
+ internal class Operational
+ {
+ }
+}
diff --git a/OpheliasOasis/Validation.cs b/OpheliasOasis/Validation.cs
index d7170cd..ea27f62 100644
--- a/OpheliasOasis/Validation.cs
+++ b/OpheliasOasis/Validation.cs
@@ -14,26 +14,31 @@ namespace Ophelias.Expressions
internal static Regex CardRx = new Regex(@"^[0-9]{16}$", RegexOptions.Compiled);
internal static Regex ExpriationRx = new Regex(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
internal static Regex CCVRx = new Regex(@"^[0-9]{3}$", RegexOptions.Compiled);
+ internal static Regex MoneyRx = new Regex(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled);
}
internal static class Validation
{
internal static bool ValidateCreditCard(string CreditCard)
{
- if (Expressions.CardRx.IsMatch(CreditCard))
- return true;
- return false;
+ return Expressions.CardRx.IsMatch(CreditCard);
}
internal static bool ValidateExpirationDate(string Expiration)
{
if (Expressions.ExpriationRx.IsMatch(Expiration))
{
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture);
- if (dt.Year >= DateTime.Now.Year)
- if (dt.Month >= DateTime.Now.Month)
- return true;
+ if (dt.Date >= DateTime.Now.Date)
+ return true;
}
return false;
}
+ internal static bool ValidateExpirationNotBeforeReservation(string Expiration, DateTime CollectionDate)
+ {
+ DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture);
+ if (dt.Date > CollectionDate.Date)
+ return true;
+ return false;
+ }
internal static bool ValidateEmail(string email)
{
EmailAddressAttribute EmailChecker = new EmailAddressAttribute();
@@ -45,5 +50,10 @@ namespace Ophelias.Expressions
return true;
return false;
}
+ internal static bool ValidateMoney(string Money)
+ {
+ return Expressions.MoneyRx.IsMatch(Money);
+ }
+
}
}
From fbb75a583d969c9582aede18b9d85f257a8b5d01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?=
<42814579+yunwah@users.noreply.github.com>
Date: Sat, 16 Apr 2022 04:42:13 -0400
Subject: [PATCH 10/10] First major version of the project
This finishes the first iteration of the project. Reports have been
tested and are functional in terms of writing out and outputting some
form of text. There are still a few bugs here and there that are found
but ultimately this commit is so testing can begin.
Since the changes are too large to individually summarize, here is the
generalization:
Reports have been integrated into the admin mode. They write out to text
files rather than export to say email or a printer as it was not to be
considered for this version. The files are appended too and exist in the
debug director of the project. I made this easier to find by outputting
where the files were output to after running the report.
Other changes included some bug fixes, optimizations, and a few bit of
automatic cleanup. This may lead to sylistic inconsistencies.
Documentation will come in a later commit.
---
.../{DatabaseManager.cs => Database.cs} | 133 ++-
OpheliasOasis/Managers/Hotel.cs | 949 ++++++++++++++++++
OpheliasOasis/Managers/HotelManager.cs | 424 --------
OpheliasOasis/Models/Guest.cs | 43 +-
OpheliasOasis/Models/Rate.cs | 2 +-
OpheliasOasis/Models/Reservation.cs | 46 +-
OpheliasOasis/Models/Room.cs | 30 -
OpheliasOasis/Models/Transaction.cs | 168 ++--
OpheliasOasis/Program.cs | 310 ++++--
OpheliasOasis/Reporting/Accommodation.cs | 20 +
OpheliasOasis/Reporting/Accomodation.cs | 12 -
OpheliasOasis/Reporting/Email.cs | 26 +-
OpheliasOasis/Reporting/Management.cs | 54 +-
OpheliasOasis/Reporting/Operational.cs | 62 +-
OpheliasOasis/Validation.cs | 10 +-
15 files changed, 1615 insertions(+), 674 deletions(-)
rename OpheliasOasis/Managers/{DatabaseManager.cs => Database.cs} (78%)
create mode 100644 OpheliasOasis/Managers/Hotel.cs
delete mode 100644 OpheliasOasis/Managers/HotelManager.cs
delete mode 100644 OpheliasOasis/Models/Room.cs
create mode 100644 OpheliasOasis/Reporting/Accommodation.cs
delete mode 100644 OpheliasOasis/Reporting/Accomodation.cs
diff --git a/OpheliasOasis/Managers/DatabaseManager.cs b/OpheliasOasis/Managers/Database.cs
similarity index 78%
rename from OpheliasOasis/Managers/DatabaseManager.cs
rename to OpheliasOasis/Managers/Database.cs
index ef9649b..e043114 100644
--- a/OpheliasOasis/Managers/DatabaseManager.cs
+++ b/OpheliasOasis/Managers/Database.cs
@@ -1,13 +1,13 @@
-using System.Data.SQLite;
-using Ophelias.Models;
+using Ophelias.Models;
+using System.Data.SQLite;
namespace Ophelias.Managers
{
- internal class DatabaseManager : IDisposable
+ internal class Database : IDisposable
{
- internal SQLiteConnection con = new SQLiteConnection("DataSource=database.sqlite3;Version=3;");
+ internal SQLiteConnection con = new("DataSource=database.sqlite3;Version=3;");
- internal DatabaseManager()
+ internal Database()
{
Connect();
}
@@ -30,13 +30,14 @@ namespace Ophelias.Managers
[Penalty] INTEGER NOT NULL,
[Multiplier] INTEGER NOT NULL,
[RefundAmount] INTEGER NOT NULL,
+ [AmountPaid] INTEGER NOT NULL,
[PayBy] TEXT NOT NULL,
[LastPaid] TEXT NULL,
[PaidOn] TEXT NULL);
CREATE TABLE IF NOT EXISTS [reservations] (
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- [RoomNum] INTEGER NULL UNIQUE,
+ [RoomNum] INTEGER NULL,
[GuestID] INTEGER NOT NULL,
[TransactionID] INTEGER NOT NULL UNIQUE,
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
@@ -71,22 +72,18 @@ namespace Ophelias.Managers
[DateSet] TEXT NOT NULL UNIQUE,
[DefaultRate] INTEGER NULL UNIQUE CHECK ([DefaultRate] IN (1)));";
- using (SQLiteCommand cmd = con.CreateCommand())
- {
- cmd.CommandText = tableCommands;
- cmd.ExecuteNonQuery();
- }
+ using SQLiteCommand cmd = con.CreateCommand();
+ cmd.CommandText = tableCommands;
+ cmd.ExecuteNonQuery();
}
internal void InitializeRoomsTable()
{
- using (SQLiteCommand cmd = con.CreateCommand())
+ using SQLiteCommand cmd = con.CreateCommand();
+ for (int i = 1; i < 46; i++)
{
- for (int i = 1; i < 46; i++)
- {
- cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
- cmd.ExecuteNonQuery();
- }
+ cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
+ cmd.ExecuteNonQuery();
}
// Initialize Rooms
@@ -104,32 +101,64 @@ namespace Ophelias.Managers
internal static string? UpdateTransaction(int Id,
double? Rate = null, double? Owed = null, double? Penalty = null,
double? Multiplier = null, double? Refund = null,
- DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null)
+ DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null, double? AmountPaid = null)
{
- List queryComponents = new List();
+ List queryComponents = new();
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");
+ {
+ queryComponents.Add($"RefundAmount = @RefundAmount");
+ }
+
+ if (AmountPaid.HasValue)
+ {
+ queryComponents.Add($"AmountPaid = @AmountPaid");
+ }
+
if (PayBy.HasValue)
+ {
queryComponents.Add($"PayBy = @PayBy");
+ }
+
if (LastPaid.HasValue)
+ {
queryComponents.Add($"LastPaid = @LastPaid");
+ }
+
if (PaidOn.HasValue)
+ {
queryComponents.Add($"PaidOn = @PaidOn");
+ }
if (queryComponents.Count > 0)
+ {
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = @ID;";
+ }
else
+ {
return null;
+ }
return query;
}
@@ -139,64 +168,124 @@ namespace Ophelias.Managers
ReservationStatus? Status = null, DateTime? CreationDate = null, DateTime? StartDate = null, DateTime? EndDate = null,
DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
{
- List QueryParts = new List();
+ List QueryParts = new();
string query = "UPDATE reservations SET";
if (RoomID.HasValue)
+ {
QueryParts.Add($"RoomID = @RID");
+ }
+
if (GuestID.HasValue)
+ {
QueryParts.Add($"GuestID = @GID");
+ }
+
if (TransactionID.HasValue)
+ {
QueryParts.Add($"TransactionID = @TID");
+ }
+
if (IsNoShow.HasValue)
+ {
QueryParts.Add($"IsNoShow = @IsNoShow");
+ }
+
if (Type.HasValue)
+ {
QueryParts.Add($"Type = @Type");
+ }
+
if (Status.HasValue)
+ {
QueryParts.Add($"Status = @Status");
+ }
+
if (CreationDate.HasValue)
+ {
QueryParts.Add($"CreationDate = @CreationDate");
+ }
+
if (StartDate.HasValue)
+ {
QueryParts.Add($"StartDate = @StartDate");
+ }
+
if (EndDate.HasValue)
+ {
QueryParts.Add($"EndDate = @EndDate");
+ }
+
if (CheckIn.HasValue)
+ {
QueryParts.Add($"CheckIn = @CheckIn");
+ }
+
if (CheckOut.HasValue)
+ {
QueryParts.Add($"CheckOut = @CheckOut");
+ }
+
if (DateChanged.HasValue)
+ {
QueryParts.Add($"DateChanged = @DateChanged");
+ }
if (QueryParts.Count > 0)
+ {
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
+ }
else
+ {
return null;
+ }
return query;
}
internal static string? UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
- List QueryParts = new List();
+ List QueryParts = new();
string query = "UPDATE guests SET";
if (!string.IsNullOrEmpty(FirstName))
+ {
QueryParts.Add($"Fname = @Fname");
+ }
+
if (!string.IsNullOrEmpty(LastName))
+ {
QueryParts.Add($"Lname = @Lname");
+ }
+
if (!string.IsNullOrEmpty(LastName))
+ {
QueryParts.Add($"Email = @Email");
+ }
+
if (!string.IsNullOrEmpty(CreditCard))
+ {
QueryParts.Add($"CreditCard = @CC");
+ }
+
if (!string.IsNullOrEmpty(Expiration))
+ {
QueryParts.Add($"Expiration = @Expiry");
+ }
+
if (!string.IsNullOrEmpty(CCV))
+ {
QueryParts.Add($"CCV = @CCV");
+ }
if (QueryParts.Count > 0)
+ {
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
+ }
else
+ {
return null;
+ }
return query;
}
diff --git a/OpheliasOasis/Managers/Hotel.cs b/OpheliasOasis/Managers/Hotel.cs
new file mode 100644
index 0000000..f40e18e
--- /dev/null
+++ b/OpheliasOasis/Managers/Hotel.cs
@@ -0,0 +1,949 @@
+using Ophelias.Models;
+using System.Data.SQLite;
+
+namespace Ophelias.Managers
+{
+ internal static class Hotel
+ {
+ internal static int GetLastId(string tableName)
+ {
+ int LastId = 0;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=@Table;";
+ cmd.ExecuteNonQuery();
+ cmd.Parameters.AddWithValue("@Table", tableName);
+ using SQLiteDataReader reader = cmd.ExecuteReader();
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ LastId = reader.GetInt32(0);
+ }
+ }
+ }
+ return LastId;
+ }
+ internal static (List<(DateTime, int, string, string)>, List) GetDailyOccupancy()
+ {
+ List previousOccupancies = new();
+ List<(DateTime, int, string, string)> currentOccupancies = new();
+ using (Database Manager = new())
+ {
+ using SQLiteTransaction Transaction = Manager.con.BeginTransaction();
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT RoomNum, Lname, Fname, EndDate FROM reservations " +
+ "INNER JOIN guests ON reservations.GuestID = guests.ID " +
+ "INNER JOIN rooms ON reservations.RoomNum = rooms.ID " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2);";
+ cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ currentOccupancies.Add((reader.GetDateTime(3), reader.GetInt32(0), reader.GetString(1), reader.GetString(2)));
+ }
+ }
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT RoomNum FROM reservations " +
+ "INNER JOIN guests ON reservations.GuestID = guests.ID " +
+ "INNER JOIN rooms ON reservations.RoomNum = rooms.ID " +
+ "WHERE DATE (@Date) = EndDate AND Status IN (@Status1);";
+ cmd.Parameters.AddWithValue("@Date", DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Ended);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ foreach (int item in reader.GetValues())
+ {
+ previousOccupancies.Add(item);
+ }
+ }
+ }
+ }
+ Transaction.Commit();
+ }
+ return (currentOccupancies, previousOccupancies);
+ }
+ internal static List GetDailyArrivals()
+ {
+ List reservations = new();
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT * FROM reservations " +
+ "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
+ "INNER JOIN guests ON reservations.GuestID = guests.ID " +
+ "WHERE DATE (@Date) = StartDate AND Status IN (@Status1,@Status2)" +
+ "ORDER BY Lname ASC;";
+ cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ Reservation? r;
+ Transaction? t;
+ Guest g;
+ int? RoomNumber = null;
+ DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
+
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ if (reader[21].GetType() != typeof(DBNull))
+ {
+ LastPaid = reader.GetDateTime(21);
+ }
+
+ if (reader[22].GetType() != typeof(DBNull))
+ {
+ PaidOn = reader.GetDateTime(22);
+ }
+
+ t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
+ LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
+
+ g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
+
+ if (reader[1].GetType() != typeof(DBNull))
+ {
+ RoomNumber = reader.GetInt32(1);
+ }
+
+ if (reader[10].GetType() != typeof(DBNull))
+ {
+ CheckIn = reader.GetDateTime(10);
+ }
+
+ if (reader[11].GetType() != typeof(DBNull))
+ {
+ CheckOut = reader.GetDateTime(11);
+ }
+
+ if (reader[12].GetType() != typeof(DBNull))
+ {
+ DateChanged = reader.GetDateTime(12);
+ }
+
+ r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
+ reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
+ CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
+ reservations.Add(r);
+ }
+ }
+ }
+ }
+ }
+ return reservations;
+ }
+ internal static (double, double, List<(DateTime, double)>) GetIncentiveTransactions()
+ {
+ double losses;
+ double totalLosses = 0;
+ int days = 30;
+ DateTime dt = DateTime.Now;
+ List<(DateTime, double)> dailyLosses = new();
+ using (Database Manager = new())
+ {
+ for (int i = 0; i < days; i++)
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT sum(((julianday(EndDate) - julianday(StartDate)) * transactions.Rate) - transactions.Owed) AS Loss " +
+ "FROM reservations " +
+ "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND STATUS IN (@Status1,@Status2) AND Type = @Type";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+ cmd.Parameters.AddWithValue("@Type", (int)ReservationType.Incentive);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ totalLosses += reader.GetDouble(0);
+ losses = reader.GetDouble(0);
+ }
+ else
+ {
+ losses = 0;
+ }
+ }
+ }
+ dailyLosses.Add((dt.AddDays(i), losses));
+ }
+ }
+ return (totalLosses, totalLosses / 30, dailyLosses);
+ }
+ internal static (List<(DateTime, double)>, double, double) GetExpectedIncomeCount()
+ {
+ double totalIncome = 0;
+ double income;
+ int days = 30;
+ DateTime dt = DateTime.Now;
+ List<(DateTime, double)> dailyIncomes = new();
+ using (Database Manager = new())
+ {
+ for (int i = 0; i < days; i++)
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT sum(transactions.Owed) FROM reservations " +
+ "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2);";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ totalIncome += reader.GetDouble(0);
+ income = reader.GetDouble(0);
+ }
+ else
+ {
+ income = 0;
+ }
+ }
+ }
+ dailyIncomes.Add((dt.AddDays(i), income));
+ }
+ }
+ return (dailyIncomes, totalIncome, totalIncome / 30);
+ }
+ internal static (double, List<(DateTime, int, int, int, int, int)>) GetExpectedOccupancyCount()
+ {
+ double thirtyDayOcc = 0;
+ int days = 30;
+ DateTime dt = DateTime.Now;
+ List<(DateTime, int, int, int, int, int)> occData = new();
+ using (Database Manager = new())
+ {
+ for (int i = 0; i < days; i++)
+ {
+ int rooms, conventional, prepaid, sixty, incentive;
+ using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT COUNT(*) " +
+ "FROM reservations " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2);";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ thirtyDayOcc += reader.GetInt32(0);
+ rooms = reader.GetInt32(0);
+ }
+ else
+ {
+ rooms = 0;
+ }
+ }
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT COUNT(*) " +
+ "FROM reservations " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 0;";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ conventional = reader.GetInt32(0);
+ }
+ else
+ {
+ conventional = 0;
+ }
+ }
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT COUNT(*) " +
+ "FROM reservations " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 1;";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ prepaid = reader.GetInt32(0);
+ }
+ else
+ {
+ prepaid = 0;
+ }
+ }
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT COUNT(*) " +
+ "FROM reservations " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 2;";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ sixty = reader.GetInt32(0);
+ }
+ else
+ {
+ sixty = 0;
+ }
+ }
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT COUNT(*) " +
+ "FROM reservations " +
+ "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 3;";
+ cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ incentive = reader.GetInt32(0);
+ }
+ else
+ {
+ incentive = 0;
+ }
+ }
+ }
+ Transaction.Commit();
+ }
+ occData.Add((dt.AddDays(i), rooms, conventional, prepaid, sixty, incentive));
+ }
+ }
+ return (thirtyDayOcc / days, occData);
+ }
+ internal static (int, bool) AvgOccupancySpan(DateTime Start, DateTime End)
+ {
+ int thirtyDayOcc = 0;
+ bool maxCapacityInRange = false;
+ int days = (int)(End.Date - Start.Date).TotalDays;
+ using (Database Manager = new())
+ {
+ for (int i = 0; i < days; i++)
+ {
+ using SQLiteCommand cmd = Manager.con.CreateCommand();
+ cmd.CommandText = $@"SELECT COUNT(*)
+ FROM reservations
+ WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2);";
+ cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+
+ using SQLiteDataReader reader = cmd.ExecuteReader();
+ reader.Read();
+ if (reader.HasRows && !reader.IsDBNull(0))
+ {
+ thirtyDayOcc += reader.GetInt32(0);
+ if (reader.GetInt32(0) == 45)
+ {
+ maxCapacityInRange = true;
+ }
+ }
+ }
+ }
+ return (thirtyDayOcc / days, maxCapacityInRange);
+ }
+ internal static Guest? GetGuestByEmail(string Email)
+ {
+ Guest? g = null;
+ using (Database Manager = new())
+ {
+ using SQLiteCommand cmd = Manager.con.CreateCommand();
+ cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ using SQLiteDataReader reader = cmd.ExecuteReader();
+ reader.Read();
+ if (reader.HasRows)
+ {
+ string? CreditCard = null, Expiration = null, CCV = null;
+ if (reader[4].GetType() != typeof(DBNull))
+ {
+ CreditCard = reader[4].ToString();
+ }
+
+ if (reader[5].GetType() != typeof(DBNull))
+ {
+ Expiration = reader[5].ToString();
+ }
+
+ if (reader[6].GetType() != typeof(DBNull))
+ {
+ CCV = reader[6].ToString();
+ }
+
+ g = new(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), CreditCard, Expiration, CCV);
+ }
+ }
+ return g;
+ }
+ internal static Reservation? GetResByGuest(Guest g)
+ {
+ Reservation? r = null;
+ Transaction? t;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ int? RoomNumber = null;
+ DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
+
+ cmd.CommandText = @"SELECT * FROM reservations
+ INNER JOIN transactions ON reservations.TransactionID = transactions.ID
+ WHERE GuestID = @GuestID AND Status = @Status;";
+ cmd.Parameters.AddWithValue("@GuestID", g.Id);
+ cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Active);
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ if (reader[21].GetType() != typeof(DBNull))
+ {
+ LastPaid = reader.GetDateTime(21);
+ }
+
+ if (reader[22].GetType() != typeof(DBNull))
+ {
+ PaidOn = reader.GetDateTime(22);
+ }
+
+ t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
+ LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
+
+ if (reader[1].GetType() != typeof(DBNull))
+ {
+ RoomNumber = reader.GetInt32(1);
+ }
+
+ if (reader[10].GetType() != typeof(DBNull))
+ {
+ CheckIn = reader.GetDateTime(10);
+ }
+
+ if (reader[11].GetType() != typeof(DBNull))
+ {
+ CheckOut = reader.GetDateTime(11);
+ }
+
+ if (reader[12].GetType() != typeof(DBNull))
+ {
+ DateChanged = reader.GetDateTime(12);
+ }
+
+ r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
+ reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
+ CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
+ }
+ }
+ }
+ }
+ return r;
+ }
+ internal static TimeRefs? CanBeCheckedIn(string Email)
+ {
+ TimeRefs? status = null;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (0,1)";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ DateTime dt = reader.GetDateTime(8);
+ if (dt.Date == DateTime.Now.Date)
+ {
+ status = TimeRefs.OnTime;
+ }
+ else if (dt.Date > DateTime.Now.Date)
+ {
+ status = TimeRefs.Late;
+ }
+ else if (dt.Date < DateTime.Now.Date)
+ {
+ status = TimeRefs.Early;
+ }
+ }
+ else
+ {
+ status = null;
+ }
+ }
+ }
+ }
+ return status;
+ }
+ internal static double? GetBaseRate()
+ {
+ double? rate;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Rate FROM rates WHERE DefaultRate = 1;";
+ cmd.CommandText = query;
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ rate = reader.GetDouble(0);
+ }
+ else
+ {
+ rate = null;
+ }
+ }
+ }
+ }
+ return rate;
+ }
+ internal static bool GetBaseRateByDate(DateTime dt)
+ {
+ bool configured;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Rate FROM rates WHERE DateSet = @Date;";
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Date", dt.ToString("yyyy-MM-dd"));
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ configured = true;
+ }
+ else
+ {
+ configured = false;
+ }
+ }
+ }
+ }
+ return configured;
+ }
+ internal static void SetBaseRate(double Rate, DateTime DateSet, bool? DefaultRate = null)
+ {
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = $"INSERT INTO rates (Rate, DateSet, DefaultRate) VALUES (@Rate, @DateSet, @DefaultRate);";
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Rate", Rate);
+ cmd.Parameters.AddWithValue("@DateSet", DateSet.ToString("yyyy-MM-dd"));
+ if (DefaultRate != null)
+ {
+ if (DefaultRate.Value == true)
+ {
+ cmd.Parameters.AddWithValue("@DefaultRate", Convert.ToInt32(DefaultRate));
+ }
+ else
+ {
+ cmd.Parameters.AddWithValue("@DefaultRate", null);
+ }
+ }
+ else
+ {
+ cmd.Parameters.AddWithValue("@DefaultRate", null);
+ }
+
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ internal static void UpdateBaseRate(double Rate, DateTime DateSet, bool? DefaultRate = null)
+ {
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ if (DefaultRate != null)
+ {
+ if (DefaultRate.Value == true)
+ {
+ cmd.CommandText = $"UPDATE rates SET rate = @Rate, defaultrate = @DefaultRate WHERE DateSet = @Date;";
+ cmd.Parameters.AddWithValue("@DefaultRate", Convert.ToInt32(DefaultRate));
+ }
+ else
+ {
+ cmd.CommandText = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
+ }
+ }
+ else
+ {
+ cmd.CommandText = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
+ }
+ cmd.Parameters.AddWithValue("@Rate", Rate);
+ cmd.Parameters.AddWithValue("@Date", DateSet.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ internal static bool CheckBaseRate()
+ {
+ int? OldId = null;
+ bool Success = true;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Id FROM rates WHERE DefaultRate = 1;";
+ cmd.CommandText = query;
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ OldId = reader.GetInt32(0);
+ }
+ }
+ }
+ int? Id;
+ if (OldId != null)
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ string query = "SELECT Id FROM rates WHERE DateSet = @Date;";
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ Id = reader.GetInt32(0);
+ }
+ else
+ {
+ Id = null;
+ }
+ }
+ }
+ if (Id != null)
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = @"UPDATE rates SET DefaultRate = NULL WHERE Id = @OldID;
+ UPDATE rates SET DefaultRate = 1 WHERE Id = @ID";
+ cmd.Parameters.AddWithValue("@OldID", OldId);
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ else
+ {
+ Success = false;
+ }
+ }
+ return Success;
+ }
+ internal static int? CheckInGuest(string Email, DateTime CheckIn)
+ {
+ int? RoomID = null;
+ using (Database Manager = new())
+ {
+ using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE reservations SET RoomNum = (SELECT ID FROM rooms WHERE Occupied = 0 LIMIT 1), CheckIn = @Date " +
+ "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NULL AND Status in (@SActive,@SChanged);";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.Parameters.AddWithValue("@Date", CheckIn.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE rooms SET Occupied = 1 " +
+ "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.ExecuteNonQuery();
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ RoomID = (int)reader.GetValue(0);
+ }
+ }
+ }
+ Transaction.Commit();
+ }
+ }
+ return RoomID;
+ }
+ internal static bool GuestCurrentlyCheckedIn(string Email)
+ {
+ bool EntryFound;
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT * FROM reservations " +
+ "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)) AND CheckIn IS NOT NULL";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ reader.Read();
+ if (reader.HasRows)
+ {
+ EntryFound = true;
+ }
+ else
+ {
+ EntryFound = false;
+ }
+ }
+ }
+ }
+ return EntryFound;
+ }
+ internal static void CheckOutGuest(string Email, DateTime CheckOut)
+ {
+ using (Database Manager = new())
+ {
+ using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE rooms SET Occupied = 0 " +
+ "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Ended);
+ cmd.ExecuteNonQuery();
+ }
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "UPDATE reservations SET CheckOut = @Date, Status = @Status " +
+ "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NOT NULL AND Status in (@SActive,@SChanged);";
+ cmd.Parameters.AddWithValue("@Email", Email);
+ cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Ended);
+ cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
+ cmd.Parameters.AddWithValue("@Date", CheckOut.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
+ }
+ Transaction.Commit();
+ }
+ }
+ return;
+ }
+ internal static List GetActiveSixtyDayRes()
+ {
+ List list = new();
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT * FROM reservations " +
+ "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
+ "INNER JOIN guests ON reservations.GuestID = guests.ID " +
+ "WHERE Type = @Type AND Status IN (@Status1,@Status2);";
+ cmd.Parameters.AddWithValue("@Type", (int)ReservationType.SixtyDayAdvance);
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+ cmd.ExecuteNonQuery();
+
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ Reservation? r;
+ Transaction? t;
+ Guest g;
+ int? RoomNumber = null;
+ DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
+
+ if (reader.HasRows)
+ {
+ if (reader[21].GetType() != typeof(DBNull))
+ {
+ LastPaid = reader.GetDateTime(21);
+ }
+
+ if (reader[22].GetType() != typeof(DBNull))
+ {
+ PaidOn = reader.GetDateTime(22);
+ }
+
+ t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
+ LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
+
+ g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
+
+ if (reader[1].GetType() != typeof(DBNull))
+ {
+ RoomNumber = reader.GetInt32(1);
+ }
+
+ if (reader[10].GetType() != typeof(DBNull))
+ {
+ CheckIn = reader.GetDateTime(10);
+ }
+
+ if (reader[11].GetType() != typeof(DBNull))
+ {
+ CheckOut = reader.GetDateTime(11);
+ }
+
+ if (reader[12].GetType() != typeof(DBNull))
+ {
+ DateChanged = reader.GetDateTime(12);
+ }
+
+ r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
+ reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
+ CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
+ list.Add(r);
+ }
+ }
+ }
+ }
+ }
+ return list;
+ }
+ internal static List GetPastDueReservations()
+ {
+ List list = new();
+ using (Database Manager = new())
+ {
+ using (SQLiteCommand cmd = Manager.con.CreateCommand())
+ {
+ cmd.CommandText = "SELECT * FROM reservations " +
+ "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
+ "INNER JOIN guests ON reservations.GuestID = guests.ID " +
+ "WHERE DATE(@Date) > StartDate AND Status IN (@Status1,@Status2) AND CheckIn IS NULL;";
+ cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
+ cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
+ cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
+ using (SQLiteDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ Reservation? r;
+ Transaction? t;
+ Guest g;
+ int? RoomNumber = null;
+ DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
+
+ if (reader.HasRows)
+ {
+ if (reader[21].GetType() != typeof(DBNull))
+ {
+ LastPaid = reader.GetDateTime(21);
+ }
+
+ if (reader[22].GetType() != typeof(DBNull))
+ {
+ PaidOn = reader.GetDateTime(22);
+ }
+
+ t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
+ LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
+
+ g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
+
+ if (reader[1].GetType() != typeof(DBNull))
+ {
+ RoomNumber = reader.GetInt32(1);
+ }
+
+ if (reader[10].GetType() != typeof(DBNull))
+ {
+ CheckIn = reader.GetDateTime(10);
+ }
+
+ if (reader[11].GetType() != typeof(DBNull))
+ {
+ CheckOut = reader.GetDateTime(11);
+ }
+
+ if (reader[12].GetType() != typeof(DBNull))
+ {
+ DateChanged = reader.GetDateTime(12);
+ }
+
+ r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
+ reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
+ CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
+ list.Add(r);
+ }
+ }
+ }
+ }
+ }
+ return list;
+ }
+ }
+ internal enum TimeRefs
+ {
+ OnTime,
+ Early,
+ Late
+ }
+}
diff --git a/OpheliasOasis/Managers/HotelManager.cs b/OpheliasOasis/Managers/HotelManager.cs
deleted file mode 100644
index 39010ac..0000000
--- a/OpheliasOasis/Managers/HotelManager.cs
+++ /dev/null
@@ -1,424 +0,0 @@
-using Ophelias.Models;
-using System.Data.SQLite;
-
-namespace Ophelias.Managers
-{
- internal static class HotelManager
- {
- internal static int GetLastId(string tableName)
- {
- int LastId = 0;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=@Table;";
- cmd.ExecuteNonQuery();
- cmd.Parameters.AddWithValue("@Table", tableName);
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- LastId = reader.GetInt32(0);
- }
- }
- }
- return LastId;
- }
- internal static List DailyOccupancies(DateTime Date)
- {
- List Occupancies = new List();
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = $@"SELECT COUNT(*)
- FROM reservations
- WHERE DATE(@Date)
- BETWEEN StartDate AND EndDate;";
- cmd.ExecuteNonQuery();
- cmd.Parameters.AddWithValue("@Date", Date.Date.ToString("yyyy-MM-dd"));
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.Read())
- Occupancies.Add(reader.GetInt32(0));
- }
- }
- }
- return Occupancies;
- }
- internal static (int, bool) AvgOccupancySpan(DateTime Start, DateTime End)
- {
- int thirtyDayOcc = 0;
- bool maxCapacityInRange = false;
- int days = (int)(End.Date - Start.Date).TotalDays;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- for (int i = 0; i < days; i++)
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = $@"SELECT COUNT(*)
- FROM reservations
- WHERE DATE(@Date)
- BETWEEN @Start AND @End;";
- cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
- cmd.Parameters.AddWithValue("@Start", Start);
- cmd.Parameters.AddWithValue("@End", End);
- cmd.ExecuteNonQuery();
-
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- {
- thirtyDayOcc += reader.GetInt32(0);
- if (reader.GetInt32(0) == 45)
- maxCapacityInRange = true;
- }
- }
- }
- }
- }
- return (thirtyDayOcc / days, maxCapacityInRange);
- }
- internal static Guest? GetGuestByEmail(string Email)
- {
- Guest? g = null;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- {
- string? CreditCard = null, Expiration = null, CCV = null;
- if (reader[4].GetType() != typeof(DBNull))
- CreditCard = reader[4].ToString();
- if (reader[5].GetType() != typeof(DBNull))
- Expiration = reader[5].ToString();
- if (reader[6].GetType() != typeof(DBNull))
- CCV = reader[6].ToString();
- g = new Guest(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), CreditCard, Expiration, CCV);
- }
- }
- }
- }
- return g;
- }
- internal static Reservation? GetResByGuest(Guest g)
- {
- Reservation? r = null;
- Transaction? t;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- int? RoomNumber = null;
- DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
-
- cmd.CommandText = @"SELECT * FROM reservations
- INNER JOIN transactions ON reservations.TransactionID = transactions.ID
- WHERE GuestID = @GuestID AND Status = @Status;";
- cmd.Parameters.AddWithValue("@GuestID", g.Id);
- cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Active);
- cmd.ExecuteNonQuery();
-
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- {
- if (reader[20].GetType() != typeof(DBNull))
- LastPaid = reader.GetDateTime(20);
- if (reader[21].GetType() != typeof(DBNull))
- PaidOn = reader.GetDateTime(21);
- t = new Transaction(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(19),
- LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16));
-
- if (reader[1].GetType() != typeof(DBNull))
- RoomNumber = reader.GetInt32(1);
- if (reader[10].GetType() != typeof(DBNull))
- CheckIn = reader.GetDateTime(10);
- if (reader[11].GetType() != typeof(DBNull))
- CheckOut = reader.GetDateTime(11);
- if (reader[12].GetType() != typeof(DBNull))
- DateChanged = reader.GetDateTime(12);
-
- r = new Reservation(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
- reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
- CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
- }
- }
- }
- }
- return r;
- }
- internal static TimeRefs? CanBeCheckedIn(string Email)
- {
- TimeRefs? status = null;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (0,1)";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- {
- DateTime dt = reader.GetDateTime(8);
- if (dt.Date == DateTime.Now.Date)
- status = TimeRefs.OnTime;
- else if (dt.Date > DateTime.Now.Date)
- status = TimeRefs.Late;
- else if (dt.Date < DateTime.Now.Date)
- status = TimeRefs.Early;
- } else
- status = null;
- }
- }
- }
- return status;
- }
- internal static double? GetBaseRate()
- {
- double? rate;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string query = "SELECT Rate FROM rates WHERE DefaultRate = 1;";
- cmd.CommandText = query;
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- rate = reader.GetDouble(0);
- else
- rate = null;
- }
- }
- }
- return rate;
- }
- internal static bool GetBaseRateByDate(DateTime dt)
- {
- bool configured;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string query = "SELECT Rate FROM rates WHERE DateSet = @Date;";
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@Date", dt.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- configured = true;
- else
- configured = false;
- }
- }
- }
- return configured;
- }
- internal static void SetBaseRate(double Rate, DateTime DateSet)
- {
- double rate;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string query = $"INSERT INTO rates (Rate, DateSet) VALUES (@Rate, @DateSet);";
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@Rate", Rate);
- cmd.Parameters.AddWithValue("@DateSet", DateSet.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- }
- }
- }
- internal static void UpdateBaseRate(double Rate, DateTime DateSet)
- {
- double rate;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string query = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@Rate", Rate);
- cmd.Parameters.AddWithValue("@Date", DateSet.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- }
- }
- }
- internal static void CheckBaseRate()
- {
- using (DatabaseManager Manager = new DatabaseManager())
- {
- int? OldId;
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string query = "SELECT Id FROM rates WHERE DefaultRate = 1;";
- cmd.CommandText = query;
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- OldId = reader.GetInt32(0);
- }
- }
- int? Id;
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string query = "SELECT Id FROM rates WHERE DateSet = @Date;";
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- Id = reader.GetInt32(0);
- }
- }
- if (Id != null)
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = @"UPDATE rates SET DefaultRate = NULL WHERE Id = @OldID;
- UPDATE rates SET DefaultRate = 1 WHERE Id = @ID";
- cmd.Parameters.AddWithValue("@OldID", OldId);
- cmd.Parameters.AddWithValue("@ID", Id);
- cmd.ExecuteNonQuery();
- }
- }
- }
- }
- internal static int? CheckInGuest(string Email, DateTime CheckIn)
- {
- int? RoomID = null;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = "UPDATE reservations SET RoomNum = (SELECT ID FROM rooms WHERE Occupied = 0 LIMIT 1), CheckIn = @Date " +
- "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NULL AND Status in (@SActive,@SChanged);";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
- cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
- cmd.Parameters.AddWithValue("@Date", CheckIn.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- }
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = "UPDATE rooms SET Occupied = 1 " +
- "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
- cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
- cmd.ExecuteNonQuery();
- }
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = "SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
- cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- {
- RoomID = (int)reader.GetValue(0);
- }
- }
- }
- Transaction.Commit();
- }
- }
- return RoomID;
- }
- internal static bool GuestCurrentlyCheckedIn(string Email)
- {
- bool EntryFound;
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = "SELECT * FROM reservations " +
- "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)) AND CheckIn IS NOT NULL";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
- cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
- cmd.ExecuteNonQuery();
- using (SQLiteDataReader reader = cmd.ExecuteReader())
- {
- reader.Read();
- if (reader.HasRows)
- EntryFound = true;
- else
- EntryFound = false;
- }
- }
- }
- return EntryFound;
- }
- internal static void CheckOutGuest(string Email, DateTime CheckOut)
- {
- using (DatabaseManager Manager = new DatabaseManager())
- {
- using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
- {
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = "UPDATE rooms SET Occupied = 0 " +
- "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
- cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Ended);
- cmd.ExecuteNonQuery();
- }
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = "UPDATE reservations SET RoomNum = NULL, CheckOut = @Date, Status = @Status " +
- "WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NOT NULL AND Status in (@SActive,@SChanged);";
- cmd.Parameters.AddWithValue("@Email", Email);
- cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Ended);
- cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
- cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
- cmd.Parameters.AddWithValue("@Date", CheckOut.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- }
- Transaction.Commit();
- }
- }
- return;
- }
- internal static List GetActiveSixtyDayRes()
- {
- List list = new List();
- return list;
- }
- }
- internal enum TimeRefs
- {
- OnTime,
- Early,
- Late
- }
-}
diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs
index 1f1cce7..15e86e0 100644
--- a/OpheliasOasis/Models/Guest.cs
+++ b/OpheliasOasis/Models/Guest.cs
@@ -16,17 +16,17 @@ namespace Ophelias.Models
internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
int Id;
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " +
- "VALUES (@Fname, @Lname, @Email, @CC, @Expiry, @CCV);";
+ "VALUES (@Fname, @Lname, @Email, @CreditCard, @Expiry, @CCV);";
cmd.Parameters.AddWithValue("@Fname", FirstName);
cmd.Parameters.AddWithValue("@Lname", LastName);
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@CreditCard", CreditCard);
- cmd.Parameters.AddWithValue("@Expiration", Expiration);
+ cmd.Parameters.AddWithValue("@Expiry", Expiration);
cmd.Parameters.AddWithValue("@CCV", CCV);
cmd.ExecuteNonQuery();
}
@@ -63,25 +63,40 @@ namespace Ophelias.Models
}
internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
- cmd.ExecuteNonQuery();
- }
+ using SQLiteCommand cmd = Manager.con.CreateCommand();
+ cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
+ cmd.ExecuteNonQuery();
}
if (FirstName != null)
+ {
this.FirstName = FirstName;
+ }
+
if (LastName != null)
+ {
this.LastName = LastName;
- if (FirstName != null)
+ }
+
+ if (Email != null)
+ {
this.Email = Email;
- this.CreditCard = CreditCard;
- if (FirstName != null)
+ }
+
+ if (CreditCard != null)
+ {
+ this.CreditCard = CreditCard;
+ }
+ if (Expiration != null)
+ {
this.Expiration = Expiration;
- if (FirstName != null)
+ }
+
+ if (CCV != null)
+ {
this.CCV = CCV;
+ }
}
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
{
@@ -96,7 +111,7 @@ namespace Ophelias.Models
internal GuestList()
{
- Guests = new List();
+ Guests = new();
}
}
}
diff --git a/OpheliasOasis/Models/Rate.cs b/OpheliasOasis/Models/Rate.cs
index 40253e6..ef12544 100644
--- a/OpheliasOasis/Models/Rate.cs
+++ b/OpheliasOasis/Models/Rate.cs
@@ -27,7 +27,7 @@ namespace Ophelias.Models
internal Rates()
{
- BaseRates = new List();
+ BaseRates = new();
}
}
}
diff --git a/OpheliasOasis/Models/Reservation.cs b/OpheliasOasis/Models/Reservation.cs
index c312430..a099661 100644
--- a/OpheliasOasis/Models/Reservation.cs
+++ b/OpheliasOasis/Models/Reservation.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Ophelias.Managers;
+using Ophelias.Managers;
using System.Data.SQLite;
namespace Ophelias.Models
@@ -39,23 +36,27 @@ namespace Ophelias.Models
case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
default: throw new NotImplementedException();
}
- double? BaseRate = HotelManager.GetBaseRate();
- if (BaseRate == null) {
+ double? BaseRate = Hotel.GetBaseRate();
+ if (BaseRate == null)
+ {
throw new NotImplementedException();
}
- Transaction Transaction = new Transaction(
+ Transaction Transaction = new(
Rate: (double)BaseRate,
Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays, Multiplier),
Multiplier: Multiplier,
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
);
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
if (RoomNum != null)
+ {
this.RoomNum = RoomNum;
+ }
+
cmd.CommandText =
"INSERT INTO reservations (RoomNum, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged) " +
"VALUES (@RoomNum, @GuestID, @TransactionID, @IsNoShow, @Type, @Status, @CreationDate, @StartDate, @EndDate, @CheckIn, @CheckOut, @DateChanged);";
@@ -69,17 +70,31 @@ namespace Ophelias.Models
cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
if (CheckIn.HasValue)
+ {
cmd.Parameters.AddWithValue("@CheckIn", CheckIn.Value.ToString("yyyy-MM-dd"));
+ }
else
+ {
cmd.Parameters.AddWithValue("@CheckIn", CheckIn);
+ }
+
if (CheckOut.HasValue)
+ {
cmd.Parameters.AddWithValue("@CheckOut", CheckOut.Value.ToString("yyyy-MM-dd"));
+ }
else
+ {
cmd.Parameters.AddWithValue("@CheckOut", CheckOut);
+ }
+
if (DateChanged.HasValue)
+ {
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
+ }
else
+ {
cmd.Parameters.AddWithValue("@DateChanged", DateChanged);
+ }
cmd.ExecuteNonQuery();
}
@@ -99,7 +114,7 @@ namespace Ophelias.Models
this.CheckOut = CheckOut;
this.DateChanged = DateChanged;
}
- internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
+ internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null, int? RoomNum = null)
{
this.Id = Id;
@@ -121,14 +136,16 @@ namespace Ophelias.Models
this.StartDate = StartDate;
this.EndDate = EndDate;
DateChanged = DateTime.Now.Date;
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Changed, StartDate: this.StartDate, EndDate: this.EndDate, DateChanged: DateChanged);
if (query == null)
+ {
throw new Exception();
+ }
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id);
@@ -139,22 +156,27 @@ namespace Ophelias.Models
cmd.ExecuteNonQuery();
}
}
- double? BaseRate = HotelManager.GetBaseRate();
+ double? BaseRate = Hotel.GetBaseRate();
if (BaseRate == null)
+ {
throw new ArgumentNullException(nameof(BaseRate));
+ }
+
Transaction.UpdateTransactionFees((double)BaseRate, TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
}
internal void CancelReservation()
{
DateTime _DateChanged = DateTime.Now.Date;
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: _DateChanged);
if (query == null)
+ {
throw new Exception();
+ }
Status = ReservationStatus.Cancelled;
DateChanged = _DateChanged;
diff --git a/OpheliasOasis/Models/Room.cs b/OpheliasOasis/Models/Room.cs
deleted file mode 100644
index 68ab2e0..0000000
--- a/OpheliasOasis/Models/Room.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Ophelias.Models
-{
- internal class @int
- {
- internal int Id;
- internal bool Occupied;
-
- internal @int(int id)
- {
- Id = id;
- Occupied = false;
- }
- }
-
- internal class RoomList
- {
- internal List<@int> Rooms;
-
- internal RoomList()
- {
- Rooms = new List<@int>();
- }
- }
-}
diff --git a/OpheliasOasis/Models/Transaction.cs b/OpheliasOasis/Models/Transaction.cs
index f9ccc7e..8d7be35 100644
--- a/OpheliasOasis/Models/Transaction.cs
+++ b/OpheliasOasis/Models/Transaction.cs
@@ -1,53 +1,58 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Ophelias.Models;
-using Ophelias.Managers;
+using Ophelias.Managers;
using System.Data.SQLite;
namespace Ophelias.Models
{
internal class Transaction
{
- internal int Id { get; set; }
- internal double Rate { get; set; }
- internal double Owed { get; set; }
- internal double Penalty { get; set; }
- internal double Multiplier { get; set; }
- internal double RefundAmount { get; set; }
- internal DateTime PayBy { get; set; }
- internal DateTime? LastPaid { get; set; } = null;
- internal DateTime? PaidOn { get; set; } = null;
+ internal int Id;
+ internal double Rate;
+ internal double Owed;
+ internal double Penalty;
+ internal double Multiplier;
+ internal double RefundAmount;
+ internal double AmountPaid;
+ internal DateTime PayBy;
+ internal DateTime? LastPaid = null;
+ internal DateTime? PaidOn = null;
internal Transaction(double Rate, double Owed,
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
- DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
+ DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0, double AmountPaid = 0)
{
int Id;
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
- cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn) " +
- "VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @PayBy, @LastPaid, @PaidOn)";
+ cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, AmountPaid, PayBy, LastPaid, PaidOn) " +
+ "VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @AmountPaid, @PayBy, @LastPaid, @PaidOn)";
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@Owed", Owed);
cmd.Parameters.AddWithValue("@Multiplier", Multiplier);
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
+ cmd.Parameters.AddWithValue("@AmountPaid", AmountPaid);
cmd.Parameters.AddWithValue("@Penalty", Penalty);
cmd.Parameters.AddWithValue("@PayBy", PayBy.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
if (LastPaid != null)
+ {
cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
+ }
else
+ {
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
+ }
+
if (PaidOn != null)
+ {
cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
+ }
else
+ {
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
+ }
//cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy, Refund: RefundAmount, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
cmd.ExecuteNonQuery();
@@ -60,13 +65,14 @@ namespace Ophelias.Models
this.Penalty = Penalty;
this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount;
+ this.AmountPaid = AmountPaid;
this.PayBy = PayBy;
this.LastPaid = LastPaid;
this.PaidOn = PaidOn;
}
internal Transaction(int Id, double Rate, double Owed,
- double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
- DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
+ double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
+ DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0, double AmountPaid = 0)
{
this.Id = Id;
this.Rate = Rate;
@@ -74,6 +80,7 @@ namespace Ophelias.Models
this.Penalty = Penalty;
this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount;
+ this.AmountPaid = AmountPaid;
this.PayBy = PayBy;
this.LastPaid = LastPaid;
this.PaidOn = PaidOn;
@@ -84,71 +91,77 @@ namespace Ophelias.Models
this.Rate = Rate;
this.Multiplier = Multiplier;
this.PayBy = PayBy;
- using (DatabaseManager Manager = new DatabaseManager())
+ using Database Manager = new();
+ using SQLiteCommand cmd = Manager.con.CreateCommand();
+ string? query = QueryBuilder.UpdateTransaction(Id: Id, Rate: this.Rate, Multiplier: this.Multiplier, PayBy: this.PayBy);
+
+ if (query == null)
{
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string? query = QueryBuilder.UpdateTransaction(Id: Id, Rate: this.Rate, Multiplier: this.Multiplier, PayBy: this.PayBy);
-
- if (query == null)
- throw new Exception();
-
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@ID", Id);
- cmd.Parameters.AddWithValue("@Rate", this.Rate);
- cmd.Parameters.AddWithValue("@Multiplier", this.Multiplier);
- cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
- cmd.ExecuteNonQuery();
- }
+ throw new Exception();
}
+
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@Rate", this.Rate);
+ cmd.Parameters.AddWithValue("@Multiplier", this.Multiplier);
+ cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
}
internal void Pay(double Amount)
{
if (Amount <= 0)
- return;
- LastPaid = DateTime.Now;
- Owed -= Amount;
- if (Owed < 0)
- RefundAmount = Math.Abs(Owed);
- else if (Owed == 0)
- PaidOn = DateTime.Now;
- using (DatabaseManager Manager = new DatabaseManager())
{
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string? query = QueryBuilder.UpdateTransaction(Id: Id, Owed: Owed, Refund: RefundAmount, LastPaid: LastPaid, PaidOn: PaidOn);
-
- if (query == null)
- throw new Exception();
-
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@ID", Id);
- cmd.Parameters.AddWithValue("@Owed", Owed);
- cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
- cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
- cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
- cmd.ExecuteNonQuery();
- }
+ return;
}
+
+ LastPaid = DateTime.Now;
+ AmountPaid += Amount;
+ if (Owed - AmountPaid < 0)
+ {
+ RefundAmount = Math.Abs(Owed - Amount);
+ }
+
+ if (Owed - AmountPaid <= 0)
+ {
+ PaidOn = DateTime.Now;
+ }
+
+ using Database Manager = new();
+ using SQLiteCommand cmd = Manager.con.CreateCommand();
+ string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount, AmountPaid: AmountPaid, LastPaid: LastPaid, PaidOn: PaidOn);
+
+ if (query == null)
+ {
+ throw new Exception();
+ }
+
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
+ cmd.Parameters.AddWithValue("@AmountPaid", AmountPaid);
+ cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
+ if(!PaidOn.HasValue)
+ throw new Exception();
+ cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
+ cmd.ExecuteNonQuery();
}
internal void Refund()
{
+ AmountPaid -= RefundAmount;
RefundAmount = 0;
- using (DatabaseManager Manager = new DatabaseManager())
+ using Database Manager = new();
+ using SQLiteCommand cmd = Manager.con.CreateCommand();
+ string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount);
+
+ if (query == null)
{
- using (SQLiteCommand cmd = Manager.con.CreateCommand())
- {
- string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount);
-
- if (query == null)
- throw new Exception();
-
- cmd.CommandText = query;
- cmd.Parameters.AddWithValue("@ID", Id);
- cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
- cmd.ExecuteNonQuery();
- }
+ throw new Exception();
}
+
+ cmd.CommandText = query;
+ cmd.Parameters.AddWithValue("@ID", Id);
+ cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
+ cmd.ExecuteNonQuery();
}
}
@@ -161,9 +174,12 @@ namespace Ophelias.Models
internal static double IncentiveFee(DateTime Start, DateTime End)
{
int thirtyDayOcc;
- (thirtyDayOcc, _) = HotelManager.AvgOccupancySpan(Start, End);
+ (thirtyDayOcc, _) = Hotel.AvgOccupancySpan(Start, End);
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
+ {
return 0.80;
+ }
+
return 1.0;
}
internal static DateTime GetPayByDate(ReservationType Type, DateTime StartDate, DateTime EndDate)
@@ -179,7 +195,7 @@ namespace Ophelias.Models
}
internal static double CalculateOwed(double Rate, int Days, double Multiplier)
{
- return Rate * Days * Multiplier;
+ return Math.Round(Rate * Days * Multiplier);
}
@@ -190,7 +206,7 @@ namespace Ophelias.Models
internal TransactionList()
{
- Transactions = new List();
+ Transactions = new();
}
}
}
diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs
index bbda8b8..e08749a 100644
--- a/OpheliasOasis/Program.cs
+++ b/OpheliasOasis/Program.cs
@@ -1,9 +1,10 @@
-using Ophelias.Models;
+using Ophelias.Expressions;
using Ophelias.Managers;
-using Ophelias.Expressions;
+using Ophelias.Models;
+using Ophelias.Reporting;
using System.Data.SQLite;
-class Program
+internal class Program
{
private static string GetGuestEmail()
{
@@ -13,7 +14,9 @@ class Program
{
Email = Console.ReadLine();
if (!Validation.ValidateEmail(Email))
+ {
Console.Write("Please enter a valid email: ");
+ }
}
return Email;
}
@@ -46,9 +49,14 @@ class Program
{
CreditCard = Console.ReadLine().Trim().Replace("\t", "");
if (CreditCard == "q" || CreditCard == "Q")
+ {
return (null, null, null);
+ }
+
if (!Validation.ValidateCreditCard(CreditCard))
+ {
Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
+ }
}
Console.Write("What is your credit card expiration date (MM/yy): ");
string CardExpiration = "";
@@ -56,9 +64,14 @@ class Program
{
CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
if (CardExpiration == "q" || CardExpiration == "Q")
+ {
return (null, null, null);
+ }
+
if (!Validation.ValidateExpirationDate(CardExpiration))
+ {
Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
+ }
}
Console.Write("What is your credit card CCV: ");
string CCV = "";
@@ -66,20 +79,28 @@ class Program
{
CCV = Console.ReadLine().Trim().Replace("\t", "");
if (CCV == "q" || CCV == "Q")
+ {
return (null, null, null);
+ }
+
if (!Validation.ValidateCCV(CCV))
+ {
Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
+ }
}
return (CreditCard, CardExpiration, CCV);
}
- (string, string) GetGuestName() {
+ (string, string) GetGuestName()
+ {
Console.Write("What is your first name: ");
string FirstName = "";
while (FirstName.Length == 0)
{
FirstName = Console.ReadLine();
if (FirstName == "")
+ {
Console.Write("What is your first name: ");
+ }
}
Console.Write("What is your last name: ");
string LastName = "";
@@ -87,7 +108,9 @@ class Program
{
LastName = Console.ReadLine();
if (LastName == "")
+ {
Console.Write("What is your last name: ");
+ }
}
return (FirstName, LastName);
}
@@ -99,16 +122,18 @@ class Program
{
email = Console.ReadLine();
if (!Validation.ValidateEmail(email))
+ {
Console.Write("Please enter a valid email: ");
+ }
}
- activeGuest = HotelManager.GetGuestByEmail(email);
+ activeGuest = Hotel.GetGuestByEmail(email);
if (activeGuest == null)
{
Console.WriteLine($"\nNo account was found with the email {email}.");
return;
}
Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
- activeReservation = HotelManager.GetResByGuest(activeGuest);
+ activeReservation = Hotel.GetResByGuest(activeGuest);
}
void CreateNewGuestPrompt()
{
@@ -118,10 +143,25 @@ class Program
string? CreditCard = null;
string? CardExpiration = null;
string? CCV = null;
- if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
- (CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
+ while (true)
+ {
+ string input = Console.ReadLine();
+ if (input.Equals("y") || input.Equals("Y"))
+ {
+ (CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
+ break;
+ }
+ else if (input.Equals("n") || input.Equals("N"))
+ {
+ break;
+ }
+ else
+ {
+ Console.Write("Input must be Y, y or N, n: ");
+ }
+ }
- activeGuest = new Guest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
+ activeGuest = new(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
Console.Write($"You are now logged in as {FirstName} {LastName} ({Email})");
}
void UpdateGuestInformation()
@@ -133,7 +173,7 @@ class Program
}
string? NewFname = null, NewLname = null, NewEmail = null, NewCard = null, NewExpiry = null, NewCCV = null;
-
+
void SavePrompt()
{
if (NewFname == null && NewLname == null && NewEmail == null && NewCard == null && NewExpiry == null && NewCCV == null)
@@ -142,10 +182,10 @@ class Program
return;
}
string changes = "";
- List NewDetails = new List();
+ List NewDetails = new();
if (!string.IsNullOrEmpty(NewFname))
{
- NewDetails.Add($"\tFirst Name: {activeGuest.FirstName} -> {NewFname}");
+ NewDetails.Add($"\tFirst Name: {activeGuest.FirstName} -> {NewFname}");
activeGuest.FirstName = NewFname;
}
if (!string.IsNullOrEmpty(NewLname))
@@ -174,7 +214,10 @@ class Program
activeGuest.CCV = NewCCV;
}
if (NewDetails.Count > 0)
+ {
changes += string.Join("\n", NewDetails);
+ }
+
Console.WriteLine($"The following changes have been made:\n {changes}");
activeGuest.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
return;
@@ -214,7 +257,10 @@ class Program
{
input = Console.ReadLine();
if (input == "1" || input == "2" || input == "3" || input == "4")
+ {
break;
+ }
+
Console.Write("Please enter either 1, 2, 3, or 4: ");
}
return (ReservationType)(Convert.ToInt32(input) - 1);
@@ -223,7 +269,7 @@ class Program
{
if (Type == ReservationType.Prepaid)
{
- if ((Date - DateTime.Now).TotalDays < 90)
+ if ((int)(Date - DateTime.Now).TotalDays < 90)
{
Console.WriteLine("Prepaid reservations must be made 90 days in advance.");
}
@@ -234,7 +280,7 @@ class Program
}
else if (Type == ReservationType.SixtyDayAdvance)
{
- if ((Date - DateTime.Now).TotalDays < 60)
+ if ((int)(Date - DateTime.Now).TotalDays < 60)
{
Console.WriteLine("Sixty-days-in-advance reservations must be made 60 days in advance.");
}
@@ -260,12 +306,18 @@ class Program
{
input = Console.ReadLine();
if (DateTime.TryParse(input, out _StartDate) && _StartDate >= DateTime.Now)
+ {
break;
+ }
if (_StartDate <= DateTime.Now)
+ {
Console.Write("Start date cannot be before current date. Please enter a valid date (2021-12-31): ");
+ }
else
+ {
Console.Write("Please enter a valid date (2021-12-31): ");
+ }
}
Console.Write("When would you like to end your stay.\n" +
"Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
@@ -274,12 +326,18 @@ class Program
{
input = Console.ReadLine();
if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
+ {
break;
+ }
if (_EndDate < _StartDate)
+ {
Console.Write("End date must be after start date. Please enter a valid date (2021-12-31): ");
+ }
else
+ {
Console.Write("Please enter a valid date (2021-12-31): ");
+ }
}
return (_StartDate.Date, _EndDate.Date);
}
@@ -293,7 +351,10 @@ class Program
bool maxCapacity = false;
(StartDate, EndDate) = Dates();
if (StartDate == null || EndDate == null)
- (_, maxCapacity) = HotelManager.AvgOccupancySpan(StartDate, EndDate);
+ {
+ (_, maxCapacity) = Hotel.AvgOccupancySpan(StartDate, EndDate);
+ }
+
if (!maxCapacity)
{
if (!CheckReservationRestrictions(StartDate, Type))
@@ -306,7 +367,8 @@ class Program
Console.WriteLine("Aborting reservation changes.");
return (null, null);
}
- } else
+ }
+ else
{
break;
}
@@ -318,7 +380,7 @@ class Program
}
return (StartDate, EndDate);
-
+
}
void EditReservationPrompt()
{
@@ -340,17 +402,22 @@ class Program
case "Q": Console.WriteLine("Changes have has been deleted."); return;
case "1": NewType = SelectReservation(); break;
case "2": (NewStartDate, NewEndDate) = SelectDate(NewType); break;
- case "S":
+ case "S":
if (NewStartDate == null || NewEndDate == null)
+ {
return;
+ }
+
while (CheckReservationRestrictions((DateTime)NewStartDate, NewType))
{
(NewStartDate, NewEndDate) = SelectDate(NewType);
if (NewStartDate == null || NewEndDate == null)
+ {
return;
+ }
}
completed = true;
- (activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, (DateTime)NewStartDate, (DateTime)NewEndDate);
+ (activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, (DateTime)NewStartDate, (DateTime)NewEndDate);
break;
default: break;
}
@@ -368,7 +435,7 @@ class Program
Console.WriteLine("You currently have an active registration.");
return;
}
- if (HotelManager.GetBaseRate() == null)
+ if (Hotel.GetBaseRate() == null)
{
Console.WriteLine("Unable to proceed with reservation due to no base rate being set. Please inform an employee.");
return;
@@ -388,14 +455,18 @@ class Program
return;
}
- while((Type != ReservationType.SixtyDayAdvance &&
- (activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))) {
+ while ((Type != ReservationType.SixtyDayAdvance &&
+ (activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null)))
+ {
Console.Write("The reservation type you chose requires you to specify your credit card.\n" +
"If you are unable to provide one, enter Q to quit or hit enter to continue.\n" +
": ");
input = Console.ReadLine();
if (input == "Q")
+ {
return;
+ }
+
GetCreditCardInformation();
}
@@ -404,13 +475,14 @@ class Program
$"If these details are correct, enter YES to complete. To cancel your reservation enter Q.\n" +
$": ");
input = Console.ReadLine();
- while(input != "YES")
+ while (input != "YES")
{
if (input == "Q")
{
Console.WriteLine("Reservation has been deleted.");
return;
- } else
+ }
+ else
{
Console.Write("Input must be YES or Q.\n: ");
input = Console.ReadLine();
@@ -418,9 +490,13 @@ class Program
}
if (Type == ReservationType.Prepaid)
{
- activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
+ activeReservation = new(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
activeReservation.Transaction.Pay(activeReservation.Transaction.Owed);
}
+ else
+ {
+ activeReservation = new(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
+ }
Console.WriteLine("Your reservation has been made.");
}
void UpdateReservation()
@@ -447,13 +523,17 @@ class Program
{
(_StartDate, _EndDate) = SelectDate(activeReservation.Type);
if (_StartDate.HasValue && _EndDate.HasValue)
+ {
Console.Write("Your new reservation details are:\n" +
$"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")} -> {_StartDate.Value.ToString("yyyy-MM-dd")}\n" +
$"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")} -> {_EndDate.Value.ToString("yyyy-MM-dd")}\n");
+ }
+
Console.Write("Are you done with your changes?\n" +
"Enter YES to finish and save, NO to continue editing.\n" +
": ");
- } else if (input == "Q")
+ }
+ else if (input == "Q")
{
Console.WriteLine("Your changes have been discarded.");
return;
@@ -489,13 +569,14 @@ class Program
"You may be charged depending on your reservation.\n" +
"Enter YES to confirm or NO to exit: ");
input = Console.ReadLine();
- while(input != "YES")
+ while (input != "YES")
{
if (input == "NO")
{
Console.Write("Reservation has not been cancelled.");
return;
- } else
+ }
+ else
{
Console.Write("Your input must be YES or NO: ");
Console.ReadLine();
@@ -512,16 +593,16 @@ class Program
);
while (true)
{
-
+
string? input = Console.ReadLine();
- switch(input)
+ switch (input)
{
case "help": help(); break;
case "reservation create": CreateNewReservation(); break;
case "reservation update": UpdateReservation(); break;
case "reservation cancel": CancelReservation(); break;
case "account create": CreateNewGuestPrompt(); break;
- case "account update": UpdateGuestInformation(); break;
+ case "account update": UpdateGuestInformation(); break;
case "account login": GuestLogin(); break;
case "q": return;
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
@@ -535,9 +616,9 @@ class Program
{
Console.WriteLine(
"Report Commands:\n" +
- "\tgenerate daily report - Generates a daily report on expected occupancy, room income, and incentive losses.\n" +
+ "\tgenerate management report - Generates a daily management report on expected occupancy, room income, and incentive losses.\n" +
"\tgenerate operational report - Generates a report of daily arrivals and occupancy.\n" +
- "\tgenerate accomodation bills - Generates an accomodation bill that will be handed to guests upon checkout.\n" +
+ "\tgenerate accommodation bills - Generates an accommodation bill that will be handed to guests upon checkout.\n" +
"\treservation cancel\n" +
"Management Commands:" +
"\nnotify pending payments - Generates and emails 60 day advance reservations that they must pay for their reservation or it will be cancelled." +
@@ -578,9 +659,26 @@ class Program
{
if (FixedDate != null)
{
- HotelManager.SetBaseRate(Convert.ToDouble(amount), (DateTime)FixedDate);
- Console.WriteLine($"A base rate of {amount} has been set and will take effect on {FixedDate.Value.ToString("yyyy-MM-dd")}.");
- } else
+ if (Hotel.GetBaseRateByDate((DateTime)FixedDate))
+ {
+ Console.Write("There is already a base rate configured for this date.\n" +
+ "If you are entering a new rate because one was not configured and got this error, type YES.\n" +
+ "Would you like to overwrite it (YES)? If not enter anything to continue.\n" +
+ ": ");
+ if (Console.ReadLine() == "YES")
+ {
+ Hotel.UpdateBaseRate(Convert.ToDouble(amount), FixedDate.Value.Date, DefaultRate: true);
+ return true;
+ }
+ }
+ else
+ {
+ Hotel.SetBaseRate(Convert.ToDouble(amount), (DateTime)FixedDate, true);
+ }
+
+ Console.WriteLine($"A base rate of {amount} has been set and will take effect immediately.");
+ }
+ else
{
DateTime StartDate;
Console.Write("When would you like the new rate to take effect.\n" +
@@ -590,28 +688,31 @@ class Program
{
input = Console.ReadLine();
if (DateTime.TryParse(input, out StartDate))
+ {
if (StartDate.Date <= DateTime.Now.Date)
{
Console.WriteLine("Base rate must be configured for a future night. Not the same day or past.");
}
- else if (HotelManager.GetBaseRateByDate(StartDate))
+ else if (Hotel.GetBaseRateByDate(StartDate))
{
-
Console.Write("There is already a base rate configured for this date.\n" +
"Would you like to overwrite it (YES)? If not enter anything to continue." +
": ");
- if(Console.ReadLine() == "YES")
+ if (Console.ReadLine() == "YES")
{
- HotelManager.UpdateBaseRate(Convert.ToDouble(amount), StartDate.Date);
+ Hotel.UpdateBaseRate(Convert.ToDouble(amount), StartDate.Date);
return true;
}
- } else
+ }
+ else
{
break;
}
+ }
+
Console.Write("Please enter a valid date (2021-12-31): ");
}
- HotelManager.SetBaseRate(Convert.ToDouble(amount), StartDate);
+ Hotel.SetBaseRate(Convert.ToDouble(amount), StartDate);
Console.WriteLine($"A base rate of {amount} has been set and will take effect on {DateTime.Now.Date.ToString("yyyy-MM-dd")}.");
}
return true;
@@ -625,13 +726,14 @@ class Program
return false;
}
- if (HotelManager.GetBaseRate() == null)
+ if (Hotel.GetBaseRate() == null)
{
Console.Write("No base rate has been configured. " +
"You must set one for the current date.\n" +
"Enter new rate: ");
while (!SetRatePrompt(DateTime.Now.Date)) { }
- } else
+ }
+ else
{
Console.Write("What is the value of the rate you would like to set.\n" +
"Enter new rate: ");
@@ -641,8 +743,8 @@ class Program
void CheckIn()
{
string Email = GetGuestEmail();
- TimeRefs? status = HotelManager.CanBeCheckedIn(Email);
- Guest? g = HotelManager.GetGuestByEmail(Email);
+ TimeRefs? status = Hotel.CanBeCheckedIn(Email);
+ Guest? g = Hotel.GetGuestByEmail(Email);
if (g == null)
{
Console.WriteLine("No guest with that email exists.");
@@ -656,17 +758,22 @@ class Program
if (status.Value == TimeRefs.OnTime)
{
- int? RoomID = HotelManager.CheckInGuest(Email, DateTime.Now.Date);
+ int? RoomID = Hotel.CheckInGuest(Email, DateTime.Now.Date);
if (RoomID != null)
+ {
Console.WriteLine($"Guest has been checked in, their room number is {RoomID}.");
+ }
}
else if (status.Value == TimeRefs.Late)
{
Console.WriteLine("Since the reservation was not checked in on the date scheduled, it has been cancelled. The guest will be charged the \"no show\" penalty.");
- Reservation? r = HotelManager.GetResByGuest(g);
+ Reservation? r = Hotel.GetResByGuest(g);
if (r == null)
+ {
throw new Exception();
+ }
+
r.CancelReservation();
}
@@ -679,16 +786,97 @@ class Program
void CheckOut()
{
string Email = GetGuestEmail();
- if (HotelManager.GuestCurrentlyCheckedIn(Email))
+ if (Hotel.GuestCurrentlyCheckedIn(Email))
{
- HotelManager.CheckOutGuest(Email, DateTime.Now.Date);
+ Reservation r = Hotel.GetResByGuest(Hotel.GetGuestByEmail(Email));
+ if (r.Type == ReservationType.Incentive || r.Type == ReservationType.Conventional)
+ {
+ r.Transaction.Pay(r.Transaction.Owed);
+ }
+
+ Hotel.CheckOutGuest(Email, DateTime.Now.Date);
Console.WriteLine($"Guest has been checked out.");
- } else
+ }
+ else
{
Console.WriteLine($"Can't checkout a guest that hasn't been checked in.");
}
return;
}
+ void NotifyOutstandingPayments()
+ {
+ List activeSixtyRes = Hotel.GetActiveSixtyDayRes();
+ foreach (Reservation r in activeSixtyRes)
+ {
+ int days = (int)(r.StartDate.Date - DateTime.Now.Date).TotalDays - 30;
+ if (days < 0)
+ {
+ r.CancelReservation();
+ }
+ else if (days <= 15)
+ {
+ Email e = new(r.Guest.Email);
+ e.Send();
+ }
+ }
+ if (File.Exists("Emails.txt"))
+ {
+ FileInfo f = new("Emails.txt");
+ Console.WriteLine($"Emails have been written and appended to {f.FullName}");
+ }
+ }
+ void GenerateManagementReports()
+ {
+ var w = Hotel.GetExpectedOccupancyCount();
+ Management.CalculateExpectedOccupancy(w.Item2, w.Item1);
+ if (File.Exists("ExpectedOccupancy.txt"))
+ {
+ FileInfo f = new("ExpectedOccupancy.txt");
+ Console.WriteLine($"Expected occupancy has been written and appended to {f.FullName}");
+ }
+ var x = Hotel.GetExpectedIncomeCount();
+ Management.CalculateExpectedIncome(x.Item1, x.Item2, x.Item3);
+ if (File.Exists("ExpectedIncome.txt"))
+ {
+ FileInfo f = new("ExpectedIncome.txt");
+ Console.WriteLine($"Expected income has been written and appended to {f.FullName}");
+ }
+ var y = Hotel.GetIncentiveTransactions();
+ Management.CalculateIncentiveLosses(y.Item3, y.Item1, y.Item2);
+ if (File.Exists("IncentiveLosses.txt"))
+ {
+ FileInfo f = new("IncentiveLosses.txt");
+ Console.WriteLine($"Incentive losses have been written and appended to {f.FullName}");
+ }
+ }
+ void GenerateAccommodationBills()
+ {
+ List reservations = Hotel.GetDailyArrivals();
+ Accommodation.GenerateAccommodationBills(reservations);
+
+ if (File.Exists("AccommodationBills.txt"))
+ {
+ FileInfo f = new("AccommodationBills.txt");
+ Console.WriteLine($"Accommodation bills have been written and appended to {f.FullName}");
+ }
+ }
+ void GenerateOperationalReports()
+ {
+ List reservations = Hotel.GetDailyArrivals();
+ Operational.FetchDailyArriavals(reservations);
+ if (File.Exists("DailyArrivals.txt"))
+ {
+ FileInfo f = new("DailyArrivals.txt");
+ Console.WriteLine($"Daily arrivals have been written and appended to {f.FullName}");
+ }
+ var x = Hotel.GetDailyOccupancy();
+ Operational.FetchDailyOccupancy(x.Item1, x.Item2);
+ if (File.Exists("DailyOccupancy.txt"))
+ {
+ FileInfo f = new("DailyOccupancy.txt");
+ Console.WriteLine($"Daily occupancy has been written and appended to {f.FullName}");
+ }
+ }
Console.Write(
"\nWelcome to the Ophelias Oasis Hotel Management System!\n" +
@@ -701,10 +889,10 @@ class Program
switch (input)
{
case "help": help(); break;
- case "generate daily report": break;
- case "generate operational report": break;
- case "generate accomodation bills": break;
- case "notify pending payments": break;
+ case "generate management report": GenerateManagementReports(); break;
+ case "generate operational report": GenerateOperationalReports(); break;
+ case "generate accommodation bills": GenerateAccommodationBills(); break;
+ case "notify pending payments": NotifyOutstandingPayments(); break;
case "issue penalties": break;
case "checkin guest": CheckIn(); break;
case "checkout guest": CheckOut(); break;
@@ -716,18 +904,22 @@ class Program
}
}
- static void Main()
+
+ private static void Main()
{
- HotelManager.CheckBaseRate();
if (!File.Exists("database.sqlite3") || new FileInfo("database.sqlite3").Length == 0)
{
SQLiteConnection.CreateFile("database.sqlite3");
- using (DatabaseManager Manager = new DatabaseManager())
+ using (Database Manager = new())
{
Manager.InitializeTables();
Manager.InitializeRoomsTable();
}
}
+ if (!Hotel.CheckBaseRate())
+ {
+ Console.WriteLine("No base rate is configured. As a result reservations cannot be made until one is configured.");
+ }
bool run = true;
while (run)
@@ -738,7 +930,7 @@ class Program
"2. Customer/ Guest\n" +
": "
);
- switch(Console.ReadLine().ToUpper())
+ switch (Console.ReadLine().ToUpper())
{
case "1": AdminMode(); break;
case "2": GuestMode(); break;
diff --git a/OpheliasOasis/Reporting/Accommodation.cs b/OpheliasOasis/Reporting/Accommodation.cs
new file mode 100644
index 0000000..1041454
--- /dev/null
+++ b/OpheliasOasis/Reporting/Accommodation.cs
@@ -0,0 +1,20 @@
+using Ophelias.Models;
+namespace Ophelias.Reporting
+{
+ internal static class Accommodation
+ {
+ internal static void GenerateAccommodationBills(List reservations)
+ {
+ foreach (Reservation? r in reservations)
+ {
+ string report = $"ACCOMMODATION BILL - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
+ $"Name: {r.Guest.LastName}, {r.Guest.FirstName}\n" +
+ $"Arrival Date: {r.StartDate}\n" +
+ $"Departure Date: {r.EndDate}\n" +
+ $"Length of Stay: {(int)(r.EndDate.Date - r.StartDate.Date).TotalDays} days\n" +
+ $"Charged: ${r.Transaction.Owed}\n\n";
+ File.AppendAllText(Path.GetFullPath("AccommodationBills.txt"), report);
+ }
+ }
+ }
+}
diff --git a/OpheliasOasis/Reporting/Accomodation.cs b/OpheliasOasis/Reporting/Accomodation.cs
deleted file mode 100644
index 47d1c82..0000000
--- a/OpheliasOasis/Reporting/Accomodation.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Ophelias.Reporting
-{
- internal class Accomodation
- {
- }
-}
diff --git a/OpheliasOasis/Reporting/Email.cs b/OpheliasOasis/Reporting/Email.cs
index 420ad0b..8392100 100644
--- a/OpheliasOasis/Reporting/Email.cs
+++ b/OpheliasOasis/Reporting/Email.cs
@@ -1,12 +1,24 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Ophelias.Reporting
+namespace Ophelias.Reporting
{
internal class Email
{
+ private readonly string to;
+ private readonly string subject = "Your payment is due soon!";
+ private readonly string body = "Hello valued customer, this is a reminder that your payment for your reservation is due soon, please login to the system and pay for your reservation. If you do not it will be canceled.";
+ private readonly string from = "no-reply@ophelias.oasis";
+
+ internal Email(string to)
+ {
+ this.to = to;
+ }
+ internal void Send()
+ {
+ File.AppendAllText(Path.GetFullPath("Emails.txt"),
+ $"TO: {to}\n" +
+ $"FROM: {from}\n" +
+ $"SUBJECT: {subject}\n" +
+ $"MESSAGE: {body}\n" +
+ $"\n");
+ }
}
}
diff --git a/OpheliasOasis/Reporting/Management.cs b/OpheliasOasis/Reporting/Management.cs
index 130eb3f..98a9b10 100644
--- a/OpheliasOasis/Reporting/Management.cs
+++ b/OpheliasOasis/Reporting/Management.cs
@@ -1,12 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using Ophelias.Models;
+using Ophelias.Managers;
+
namespace Ophelias.Reporting
{
- internal class Management
+ internal static class Management
{
+ internal static void CalculateExpectedOccupancy(List<(DateTime, int, int, int, int, int)> items, double average)
+ {
+ List entries = new();
+ foreach (var x in items)
+ {
+ entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}\t{x.Item3}\t{x.Item4}\t{x.Item5}\t{x.Item6}");
+ }
+ string report = $"EXPECTED 30 DAY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
+ $"Date\tRooms Filled\tConventional\tPrepaid\t60-Day\tIncentive\n" +
+ $"{string.Join("\n", entries)}\n" +
+ $"Average Occupancy Rate: {average}\n\n";
+
+ File.AppendAllText(Path.GetFullPath("ExpectedOccupancy.txt"), report);
+ }
+ internal static void CalculateExpectedIncome(List<(DateTime, double)> items, double totalIncome, double average)
+ {
+ List entries = new();
+ foreach (var x in items)
+ {
+ entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}");
+ }
+ string report = $"EXPECTED 30 DAY INCOME REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
+ $"Date\tIncome\n" +
+ $"{string.Join("\n", entries)}\n" +
+ $"Average Income: {average}\n" +
+ $"Total Income: {totalIncome}\n\n";
+
+ File.AppendAllText(Path.GetFullPath("ExpectedIncome.txt"), report);
+ }
+ internal static void CalculateIncentiveLosses(List<(DateTime, double)> items, double totalLosses, double average)
+ {
+ List entries = new();
+ foreach (var x in items)
+ {
+ entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}");
+ }
+ string report = $"EXPECTED 30 DAY LOSSES (TO INCENTIVE) REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
+ $"Date\tLosses\n" +
+ $"{string.Join("\n", entries)}\n" +
+ $"Average Losses (Due to incentive): {average}\n" +
+ $"Total Losses (Due to incentive): {totalLosses}\n\n";
+
+ File.AppendAllText(Path.GetFullPath("IncentiveLosses.txt"), report);
+ }
}
}
diff --git a/OpheliasOasis/Reporting/Operational.cs b/OpheliasOasis/Reporting/Operational.cs
index f62ef52..c675f4e 100644
--- a/OpheliasOasis/Reporting/Operational.cs
+++ b/OpheliasOasis/Reporting/Operational.cs
@@ -1,12 +1,62 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using Ophelias.Models;
+
namespace Ophelias.Reporting
{
- internal class Operational
+ internal static class Operational
{
+ internal static void FetchDailyArriavals(List reservations)
+ {
+ List entries = new();
+ foreach (Reservation r in reservations)
+ {
+ string roominfo;
+ if (!r.RoomNum.HasValue)
+ {
+ roominfo = "N/A";
+ }
+ else
+ {
+
+ roominfo = r.RoomNum.Value.ToString();
+ }
+
+ entries.Add($"{r.Guest.LastName}, {r.Guest.FirstName}\t{r.Type}\t{roominfo}\t{r.EndDate}");
+ }
+ string report = $"DAILY ARRIVAL REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
+ $"Last, First\tType\tRoom\tDeparture" +
+ $"{string.Join("\n", entries)}\n\n";
+
+ File.AppendAllText(Path.GetFullPath("DailyArrivals.txt"), report);
+ }
+ internal static void FetchDailyOccupancy(List<(DateTime, int, string, string)> cop, List pop)
+ {
+ List entries = new();
+ foreach (var c in cop)
+ {
+ string lastOccupied;
+ string sameDayLeave = "";
+ if (pop.Contains(c.Item2))
+ {
+ lastOccupied = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
+ } else
+ {
+ lastOccupied = "N/A";
+ }
+
+ if(DateTime.Now.Date == c.Item1.Date)
+ {
+ sameDayLeave = "*";
+ }
+ entries.Add($"{c.Item2}\t{lastOccupied}\t{sameDayLeave}{c.Item3}, {c.Item4}");
+ }
+ string report = $"DAILY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
+ $"An * means that the guest is leaving the same day.\n" +
+ $"Room #\tPrev. Occupied\tCurrent Occupant\n" +
+ $"{string.Join("\n", entries)}\n\n";
+
+ File.AppendAllText(Path.GetFullPath("DailyOccupancy.txt"), report);
+ }
+
}
}
diff --git a/OpheliasOasis/Validation.cs b/OpheliasOasis/Validation.cs
index ea27f62..6f9c8da 100644
--- a/OpheliasOasis/Validation.cs
+++ b/OpheliasOasis/Validation.cs
@@ -11,10 +11,10 @@ namespace Ophelias.Expressions
{
internal static class Expressions
{
- internal static Regex CardRx = new Regex(@"^[0-9]{16}$", RegexOptions.Compiled);
- internal static Regex ExpriationRx = new Regex(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
- internal static Regex CCVRx = new Regex(@"^[0-9]{3}$", RegexOptions.Compiled);
- internal static Regex MoneyRx = new Regex(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled);
+ internal static Regex CardRx = new(@"^[0-9]{16}$", RegexOptions.Compiled);
+ internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
+ internal static Regex CCVRx = new(@"^[0-9]{3}$", RegexOptions.Compiled);
+ internal static Regex MoneyRx = new(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled);
}
internal static class Validation
{
@@ -41,7 +41,7 @@ namespace Ophelias.Expressions
}
internal static bool ValidateEmail(string email)
{
- EmailAddressAttribute EmailChecker = new EmailAddressAttribute();
+ EmailAddressAttribute EmailChecker = new();
return EmailChecker.IsValid(email);
}
internal static bool ValidateCCV(string CCV)