WIP: Adds several core models needed for functionality #24
@@ -5,12 +5,11 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
internal class DatabaseManager : IDisposable
|
internal class DatabaseManager : IDisposable
|
||||||
{
|
{
|
||||||
internal SQLiteConnection con = new SQLiteConnection("OpheliasOasis.sqlite");
|
internal SQLiteConnection con = new SQLiteConnection("DataSource=database.sqlite3;Version=3;");
|
||||||
internal SQLiteCommand? cur;
|
|
||||||
|
|
||||||
internal DatabaseManager()
|
internal DatabaseManager()
|
||||||
{
|
{
|
||||||
cur = new SQLiteCommand(con);
|
Connect();
|
||||||
}
|
}
|
||||||
internal void Connect()
|
internal void Connect()
|
||||||
{
|
{
|
||||||
@@ -23,9 +22,6 @@ namespace Ophelias.Managers
|
|||||||
}
|
}
|
||||||
internal void InitializeTables()
|
internal void InitializeTables()
|
||||||
{
|
{
|
||||||
if (cur == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
string tableCommands =
|
string tableCommands =
|
||||||
@"CREATE TABLE IF NOT EXISTS [transactions] (
|
@"CREATE TABLE IF NOT EXISTS [transactions] (
|
||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -34,8 +30,6 @@ namespace Ophelias.Managers
|
|||||||
[Penalty] INTEGER NULL,
|
[Penalty] INTEGER NULL,
|
||||||
[Multiplier] INTEGER NOT NULL,
|
[Multiplier] INTEGER NOT NULL,
|
||||||
[RefundAmount] 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,
|
[PayBy] TEXT NOT NULL,
|
||||||
[PaidOn] TEXT NULL);
|
[PaidOn] TEXT NULL);
|
||||||
|
|
||||||
@@ -61,36 +55,41 @@ namespace Ophelias.Managers
|
|||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
[Fname] TEXT NOT NULL,
|
[Fname] TEXT NOT NULL,
|
||||||
[Lname] TEXT NOT NULL,
|
[Lname] TEXT NOT NULL,
|
||||||
[Email] TEXT NULL,
|
[Email] TEXT NOT NULL,
|
||||||
[Phone] TEXT NULL,
|
|
||||||
[CreditCard] TEXT NULL,
|
[CreditCard] TEXT NULL,
|
||||||
[CCV] TEXT NULL,
|
[Expiration] TEXT NULL,
|
||||||
[CCExpiration] TEXT NULL);
|
[CCV] TEXT NULL);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS [rooms] (
|
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] (
|
CREATE TABLE IF NOT EXISTS [rates] (
|
||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
[Rate] INTEGER NOT NULL,
|
[Rate] INTEGER NOT NULL,
|
||||||
[DateSet] TEXT NOT NULL);";
|
[DateSet] TEXT NOT NULL);";
|
||||||
|
|
||||||
cur.CommandText = tableCommands;
|
using (SQLiteCommand cmd = con.CreateCommand())
|
||||||
cur.ExecuteNonQuery();
|
{
|
||||||
|
cmd.CommandText = tableCommands;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InitializeRoomsTable()
|
internal void InitializeRoomsTable()
|
||||||
{
|
{
|
||||||
if (cur == null)
|
using (SQLiteCommand cmd = con.CreateCommand())
|
||||||
return;
|
{
|
||||||
|
|
||||||
// Initialize Rooms
|
|
||||||
for (int i = 1; i < 46; i++)
|
for (int i = 1; i < 46; i++)
|
||||||
{
|
{
|
||||||
cur.CommandText = $"INSERT INTO ROOMS (ID) VALUES ({i});";
|
cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
|
||||||
cur.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize Rooms
|
||||||
|
|
||||||
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
@@ -99,66 +98,33 @@ namespace Ophelias.Managers
|
|||||||
|
|
||||||
internal static class DatabaseFunctions
|
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 class QueryBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static string? UpdateTransaction(int id,
|
internal static string? UpdateTransaction(int id,
|
||||||
double? rate = null, double? owed = null, double? penalty = null,
|
double? Rate = null, double? Owed = null, double? Penalty = null,
|
||||||
double? multiplier = null, double? refund = null, bool? isLate = null,
|
double? Multiplier = null, double? Refund = null,
|
||||||
bool? paidOff = null, DateTime? paidBy = null, DateTime? paidOn = null)
|
DateTime? PayBy = null, DateTime? PaidOn = null)
|
||||||
{
|
{
|
||||||
List<string> queryComponents = new List<string>();
|
List<string> queryComponents = new List<string>();
|
||||||
string query = "UPDATE transactions SET";
|
string query = "UPDATE transactions SET";
|
||||||
|
|
||||||
if (rate.HasValue)
|
if (Rate.HasValue)
|
||||||
queryComponents.Add($"Rate = {rate}");
|
queryComponents.Add($"Rate = {Rate}");
|
||||||
if (owed.HasValue)
|
if (Owed.HasValue)
|
||||||
queryComponents.Add($"Owed = {owed}");
|
queryComponents.Add($"Owed = {Owed}");
|
||||||
if (penalty.HasValue)
|
if (Penalty.HasValue)
|
||||||
queryComponents.Add($"Penalty = {penalty}");
|
queryComponents.Add($"Penalty = {Penalty}");
|
||||||
if (multiplier.HasValue)
|
if (Multiplier.HasValue)
|
||||||
queryComponents.Add($"Multiplier = {multiplier}");
|
queryComponents.Add($"Multiplier = {Multiplier}");
|
||||||
if (refund.HasValue)
|
if (Refund.HasValue)
|
||||||
queryComponents.Add($"Refund = {refund}");
|
queryComponents.Add($"Refund = {Refund}");
|
||||||
if (isLate.HasValue)
|
if (PayBy.HasValue)
|
||||||
queryComponents.Add($"IsLate = {Convert.ToInt32(isLate)}");
|
queryComponents.Add($"PaidBy = {PayBy.Value.ToString("yyyy-MM-dd")}");
|
||||||
if (paidOff.HasValue)
|
if (PaidOn.HasValue)
|
||||||
queryComponents.Add($"PaidOff = {Convert.ToInt32(paidOff)}");
|
queryComponents.Add($"PaidOn = {PaidOn.Value.ToString("yyyy-MM-dd")}");
|
||||||
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)
|
if (queryComponents.Count == 0)
|
||||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
|
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
|
||||||
@@ -208,5 +174,30 @@ namespace Ophelias.Managers
|
|||||||
|
|
||||||
return query;
|
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});";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
133
OpheliasOasis/Managers/HotelManager.cs
Normal file
133
OpheliasOasis/Managers/HotelManager.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,30 +9,8 @@ using System.Data.SQLite;
|
|||||||
|
|
||||||
namespace Ophelias.Managers
|
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ namespace Ophelias.Managers
|
|||||||
internal TransactionTableManager(DatabaseManager manager)
|
internal TransactionTableManager(DatabaseManager manager)
|
||||||
{
|
{
|
||||||
dbManager = manager;
|
dbManager = manager;
|
||||||
cur = manager.cur;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Ophelias.Models;
|
using Ophelias.Models;
|
||||||
using System.Net.Mail;
|
|
||||||
|
|
||||||
namespace Ophelias.Models
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
@@ -14,34 +13,30 @@ namespace Ophelias.Models
|
|||||||
internal string FirstName;
|
internal string FirstName;
|
||||||
internal string LastName;
|
internal string LastName;
|
||||||
internal string Email;
|
internal string Email;
|
||||||
internal string PhoneNumber;
|
|
||||||
internal string? CreditCard;
|
internal string? CreditCard;
|
||||||
internal string? CCV;
|
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;
|
this.FirstName = FirstName;
|
||||||
FirstName = fname;
|
this.LastName = LastName;
|
||||||
LastName = lname;
|
this.Email = Email;
|
||||||
Email = email;
|
|
||||||
PhoneNumber = phone;
|
|
||||||
}
|
}
|
||||||
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;
|
this.FirstName = FirstName;
|
||||||
FirstName = fname;
|
this.LastName = LastName;
|
||||||
LastName = lname;
|
this.Email = Email;
|
||||||
Email = email;
|
this.CreditCard = CreditCard;
|
||||||
PhoneNumber = phone;
|
this.Expiration = Expiration;
|
||||||
CreditCard = cc;
|
this.CCV = CCV;
|
||||||
CreditCardExpiration = expiration;
|
|
||||||
}
|
}
|
||||||
internal void SetCreditCardInformation(string cc, DateTime expiration, string ccv)
|
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
|
||||||
{
|
{
|
||||||
CreditCard = cc;
|
this.CreditCard = CreditCard;
|
||||||
CreditCardExpiration = expiration;
|
this.Expiration = Expiration;
|
||||||
CCV = ccv;
|
this.CCV = CCV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal class GuestList
|
internal class GuestList
|
||||||
|
|||||||
@@ -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
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
@@ -43,18 +49,6 @@ namespace Ophelias.Models
|
|||||||
CheckOut = null;
|
CheckOut = null;
|
||||||
DateChanged = 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
|
internal enum ReservationStatus
|
||||||
{
|
{
|
||||||
@@ -70,13 +64,4 @@ namespace Ophelias.Models
|
|||||||
Incentive,
|
Incentive,
|
||||||
SixtyDayAdvance,
|
SixtyDayAdvance,
|
||||||
}
|
}
|
||||||
internal class ReservationList
|
|
||||||
{
|
|
||||||
internal List<Reservation> Reservations;
|
|
||||||
|
|
||||||
internal ReservationList()
|
|
||||||
{
|
|
||||||
Reservations = new List<Reservation>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,57 +14,28 @@ namespace Ophelias.Models
|
|||||||
|
|
||||||
internal int Id { get; set; }
|
internal int Id { get; set; }
|
||||||
internal double Rate { get; set; }
|
internal double Rate { get; set; }
|
||||||
internal double Paid { get; set; }
|
|
||||||
internal double Owed { get; set; }
|
internal double Owed { get; set; }
|
||||||
internal double? Penalty { get; set; }
|
internal double Penalty { get; set; }
|
||||||
internal double Multiplier { get; set; }
|
internal double Multiplier { get; set; }
|
||||||
internal double RefundAmount { get; set; }
|
internal double RefundAmount { get; set; }
|
||||||
internal bool? Late { get; set; }
|
|
||||||
internal bool PaidOff { get; set; }
|
|
||||||
internal DateTime PayBy { 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;
|
this.Id = Id;
|
||||||
Paid = 0;
|
this.Rate = Rate;
|
||||||
Owed = 0;
|
this.Owed = Owed;
|
||||||
RefundAmount = 0;
|
this.Penalty = Penalty;
|
||||||
PaidOff = false;
|
this.Multiplier = Multiplier;
|
||||||
PayBy = SetPayByDate(r);
|
this.RefundAmount = RefundAmount;
|
||||||
Multiplier = Fee(r.Type);
|
this.PayBy = PayBy;
|
||||||
|
this.PaidOn = PaidOn;
|
||||||
}
|
}
|
||||||
private bool IsOverdue()
|
|
||||||
{
|
private void Cancellation(ReservationType type)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
void SetRefund()
|
void SetRefund()
|
||||||
{
|
{
|
||||||
@@ -98,84 +69,43 @@ namespace Ophelias.Models
|
|||||||
}
|
}
|
||||||
internal void Penalize(Reservation r, double rate)
|
internal void Penalize(Reservation r, double rate)
|
||||||
{
|
{
|
||||||
switch(r.Status)
|
throw new NotImplementedException();
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Pay(double amount)
|
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;
|
internal static double ConventionalFee = 1.0;
|
||||||
static double PrepaidFee = 0.75;
|
internal static double PrepaidFee = 0.75;
|
||||||
static double IncentiveFee = OccupancyIncentive();
|
internal static double IncentiveFee = IncentiveRate();
|
||||||
static double SixtyDayFee = 0.85;
|
internal static double SixtyDayFee = 0.85;
|
||||||
|
|
||||||
private static double OccupancyIncentive()
|
private static double IncentiveRate()
|
||||||
{
|
{
|
||||||
int thirtyDayOcc;
|
int thirtyDayOcc;
|
||||||
using (DatabaseManager dbm = new DatabaseManager())
|
thirtyDayOcc = HotelManager.GetThirtyDayOccupancy(DateTime.Now);
|
||||||
{
|
|
||||||
if (dbm.cur == null)
|
|
||||||
throw new NotImplementedException();
|
|
||||||
|
|
||||||
thirtyDayOcc = DatabaseFunctions.GetThirtyDayOccupancy(dbm.cur, DateTime.Now);
|
|
||||||
}
|
|
||||||
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
|
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
|
||||||
return 0.80;
|
return 0.80;
|
||||||
return 1.0;
|
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
|
internal class TransactionList
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Ophelias.Models;
|
using Ophelias.Models;
|
||||||
using Ophelias.Managers;
|
using Ophelias.Managers;
|
||||||
|
using Ophelias.Expressions;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
@@ -8,8 +9,7 @@ class Program
|
|||||||
{
|
{
|
||||||
Reservation? activeReservation = null;
|
Reservation? activeReservation = null;
|
||||||
Guest? activeGuest = null;
|
Guest? activeGuest = null;
|
||||||
TransactionTableManager tx = new TransactionTableManager(null);
|
|
||||||
tx.UpdateTransactionInfo(1);
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
@@ -17,7 +17,7 @@ class Program
|
|||||||
"\treservation create\n" +
|
"\treservation create\n" +
|
||||||
"\treservation update\n" +
|
"\treservation update\n" +
|
||||||
"\treservation cancel\n" +
|
"\treservation cancel\n" +
|
||||||
"Account Commands:" +
|
"Account Commands:\n" +
|
||||||
"\taccount create\n" +
|
"\taccount create\n" +
|
||||||
"\taccount update\n" +
|
"\taccount update\n" +
|
||||||
"Enter Q to quit.\n"
|
"Enter Q to quit.\n"
|
||||||
@@ -25,18 +25,89 @@ class Program
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CreateNewReservation()
|
void CreateNewReservation()
|
||||||
{
|
{
|
||||||
Reservation newReservation;
|
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" +
|
"Welcome to the Ophelias Oasis Hotel Registration System!\n" +
|
||||||
"Type help to get a full list of commands or enter a command.\n" +
|
"Type help to get a full list of commands or enter a command.\n" +
|
||||||
"Command: "
|
"Command: "
|
||||||
);
|
);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
string? input = Console.ReadLine();
|
string? input = Console.ReadLine();
|
||||||
switch(input)
|
switch(input)
|
||||||
{
|
{
|
||||||
@@ -44,11 +115,12 @@ class Program
|
|||||||
case "reservation create": break;
|
case "reservation create": break;
|
||||||
case "reservation update": break;
|
case "reservation update": break;
|
||||||
case "reservation cancel": break;
|
case "reservation cancel": break;
|
||||||
|
case "account create": CreateNewGuestPrompt(); break;
|
||||||
case "account update": break;
|
case "account update": break;
|
||||||
case "q": return;
|
case "q": return;
|
||||||
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
|
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
|
||||||
}
|
}
|
||||||
|
Console.Write("Command: ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void AdminMode()
|
private void AdminMode()
|
||||||
@@ -70,15 +142,25 @@ class Program
|
|||||||
}
|
}
|
||||||
static void Main()
|
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;
|
bool run = true;
|
||||||
while (run)
|
while (run)
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.Write(
|
||||||
"Are you an employee or customer?\n" +
|
"Are you an employee or customer?\n" +
|
||||||
"1. Employee\n" +
|
"1. Employee\n" +
|
||||||
"2. Customer/ Guest"
|
"2. Customer/ Guest\n" +
|
||||||
|
": "
|
||||||
);
|
);
|
||||||
switch(Console.ReadLine().ToUpper())
|
switch(Console.ReadLine().ToUpper())
|
||||||
{
|
{
|
||||||
|
|||||||
49
OpheliasOasis/Validation.cs
Normal file
49
OpheliasOasis/Validation.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user