using System; using System.Collections.Generic; using System.Linq; using Ophelias.Managers; using System.Data.SQLite; namespace Ophelias.Models { internal class Reservation { internal int Id; internal Room Room; internal Guest Guest; internal Transaction Transaction; 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, 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) { 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); if (query == null) throw new Exception(); 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); if (query == null) throw new Exception(); cmd.CommandText = query; cmd.ExecuteNonQuery(); } } } } internal enum ReservationStatus { Active, Changed, Cancelled, Ended, } internal enum ReservationType { Conventional, Prepaid, Incentive, SixtyDayAdvance, } }