Example #1
0
        private void GuestSearchBtn_Click(object sender, EventArgs e)
        {
            if ((!string.IsNullOrWhiteSpace(GuestFNameTB.Text) && !string.IsNullOrWhiteSpace(GuestLNameTB.Text)) || !string.IsNullOrWhiteSpace(GuestPhoneTB.Text) || !string.IsNullOrWhiteSpace(GuestEmailTB.Text))
            {
                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        GuestsDGV.DataSource = context.Guests.Where(g => (g.First_Name == GuestFNameTB.Text &&
                                                                          g.Last_Name == GuestLNameTB.Text) ||
                                                                    g.E_Mail == GuestEmailTB.Text ||
                                                                    g.Phone == GuestPhoneTB.Text)
                                               .Select(g => new
                        {
                            g.Id,
                            g.First_Name,
                            g.Last_Name,
                            g.Address,
                            g.E_Mail,
                            g.Phone
                        }).ToList();
                    }
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ClearGuestInputs();
            }
            else
            {
                MetroMessageBox.Show(this, "Please enter full name, e-mail or Phone number to start searching", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        /// <summary>
        /// Called when the add button is pressed
        /// it addes or updates room, reservation guest, room type, room status, etc.
        /// </summary>
        private void AddEntity <T>(T entity, bool inputsValidation, int id) where T : class
        {
            if (inputsValidation)
            {
                try
                {
                    string state = (id == 0) ? "Added" : "Modified";    //To print a message to the user of wether an item is added or modified

                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        context.Set <T>().AddOrUpdate(entity);
                        context.SaveChanges();
                    }

                    MetroMessageBox.Show(this, $"A record has been {state}", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ShowData(entity);   //To fill the Data grid view and clear the input values
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Please fill the missing data or click on a row to update it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        public void ShowRoomData()
        {
            try
            {
                using (GrandLuxEntities context = new GrandLuxEntities())
                {
                    RoomsDGV.DataSource = context.Rooms.Select(r => new {
                        r.Id,
                        r.Room_Number,
                        r.Floor_Number,
                        Room_Type   = r.Room_Type.Name,
                        Room_Status = r.Room_Status.Name
                    }).ToList();

                    RoomTypeCB.DataSource    = context.Room_Type.ToList();
                    RoomTypeCB.DisplayMember = "Name";
                    RoomTypeCB.ValueMember   = "Id";

                    RoomStatusCB.DataSource    = context.Room_Status.ToList();
                    RoomStatusCB.DisplayMember = "Name";
                    RoomStatusCB.ValueMember   = "Id";
                }
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            ResetRoomInputs();
        }
Example #4
0
        private void EmployeesDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (EmployeesDGV.CurrentRow.Index != -1)
            {
                try
                {
                    employee.Id = Convert.ToInt32(EmployeesDGV.CurrentRow.Cells["Id"].Value);
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        employee = context.Employees.Where(a => a.Id == employee.Id).FirstOrDefault();
                    }

                    EmployeeFNameTB.Text   = bookingFNameTB.Text = employee.First_Name;
                    EmployeeLNameTB.Text   = bookingLNameTB.Text = employee.Last_Name;
                    EmployeeAddressTB.Text = employee.Address;
                    EmployeeEmailTB.Text   = employee.E_Mail;
                    EmployeePhoneTB.Text   = employee.Phone;
                    EmployeeJobTB.Text     = employee.Job_Title;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #5
0
        public void ShowReservationData()
        {
            try
            {
                using (GrandLuxEntities context = new GrandLuxEntities())
                {
                    ReservationsDGV.DataSource = context.Reservations.Select(r => new
                    {
                        r.Id,
                        r.Guest.First_Name,
                        r.Guest.Last_Name,
                        r.Check_In,
                        r.Check_Out,
                        r.Adults,
                        r.Children,
                        Room_No   = r.Room.Room_Number,
                        Room_Type = r.Room.Room_Type.Name
                    }).ToList();
                }

                GuestFNameTB.Text = GuestLNameTB.Text = GuestAddressTB.Text = "";
                GuestEmailTB.Text = GuestPhoneTB.Text = "";
                guest.Id          = 0;
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #6
0
        private void GuestsDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (GuestsDGV.CurrentRow.Index != -1)
            {
                guest.Id = Convert.ToInt32(GuestsDGV.CurrentRow.Cells["Id"].Value);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        guest = context.Guests.Where(g => g.Id == guest.Id).FirstOrDefault();
                    }

                    GuestFNameTB.Text   = bookingFNameTB.Text = guest.First_Name;
                    GuestLNameTB.Text   = bookingLNameTB.Text = guest.Last_Name;
                    GuestAddressTB.Text = guest.Address;
                    GuestEmailTB.Text   = guest.E_Mail;
                    GuestPhoneTB.Text   = guest.Phone;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                BookingConfirmBtn.Enabled = true;
            }
        }
Example #7
0
        /// <summary>
        /// Called when the delete button is pressed
        /// it deletes room, reservation guest, room type, room status, etc.
        /// </summary>
        private void DeleteEntity <T>(T entity, int id) where T : class
        {
            if (id != 0)
            {
                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        context.Entry(entity).State = EntityState.Deleted;
                        context.SaveChanges();
                    }

                    MetroMessageBox.Show(this, $"A record has been removed", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ShowData(entity);
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Please click on a row to delete it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #8
0
        public void ShowGuestData()
        {
            try
            {
                using (GrandLuxEntities context = new GrandLuxEntities())
                {
                    GuestsDGV.DataSource = context.Guests.Select(g => new { g.Id, g.First_Name, g.Last_Name, g.Address, g.E_Mail, g.Phone }).ToList();
                }
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            ClearGuestInputs();
        }
Example #9
0
        public void ShowEmployeeData()
        {
            try
            {
                using (GrandLuxEntities context = new GrandLuxEntities())
                {
                    EmployeesDGV.DataSource = context.Employees.Select(a => new { a.Id, a.First_Name, a.Last_Name, a.Address, a.E_Mail, a.Phone, a.Job_Title }).ToList();
                }
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            ClearEmployeeInputs();
        }
Example #10
0
 private void ShowMiscData()
 {
     try
     {
         using (GrandLuxEntities context = new GrandLuxEntities())
         {
             RoomTypeDGV.DataSource   = context.Room_Type.Select(r => new { Type_Id = r.Id, Type_Name = r.Name, No_Of_Beds = r.No_of_Beds, Maximum_Capacity = r.Max_Capacity }).ToList();
             RoomStatusDGV.DataSource = context.Room_Status.Select(r => new { Status_Id = r.Id, Status_Name = r.Name, r.Description }).ToList();
         }
         RoomTypeNameTB.Text   = "";
         BedsNUD.Value         = MaxCapacityNUD.Value = 0;
         RoomStatusNameTB.Text = RoomStatusDescriptionTB.Text = "";
         roomType.Id           = roomStatus.Id = 0;
     }
     catch (Exception)
     {
         MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #11
0
        private void ReservationCheckBtn_Click(object sender, EventArgs e)
        {
            reservation.Check_In  = CheckInDTP.Value.Date;
            reservation.Check_Out = CheckOutDTP.Value.Date;
            reservation.Adults    = Convert.ToInt32(AdultsNUD.Value);
            reservation.Children  = Convert.ToInt32(ChildernNUD.Value);

            var TotalCapacity = Convert.ToInt32(reservation.Adults + reservation.Children);

            try
            {
                using (GrandLuxEntities context = new GrandLuxEntities())
                {
                    var roomList        = context.Rooms.ToList();
                    var roomDisplayList = new List <Room>();

                    foreach (var ro in roomList)
                    {
                        bool inDate       = reservation.Check_In >= ro.Check_In && reservation.Check_In <= ro.Check_Out;
                        bool outDate      = reservation.Check_Out >= ro.Check_In && reservation.Check_Out <= ro.Check_Out;
                        bool capacity     = ro.Room_Type.Max_Capacity >= TotalCapacity;
                        bool availability = ro.Room_Status.Name == "Available";
                        if (!(inDate || outDate) && capacity && availability)
                        {
                            roomDisplayList.Add(ro);
                        }
                    }

                    CheckDGV.DataSource = roomDisplayList.Select(r => new
                    {
                        r.Id,
                        r.Room_Number,
                        r.Floor_Number,
                        Room_Type = r.Room_Type.Name,
                        r.Room_Type.Max_Capacity
                    }).ToList();
                }
            }
            catch (Exception)
            {
                MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #12
0
        private void RoomsSearchBtn_Click(object sender, EventArgs e)
        {
            bool numericInputs    = RoomNoNUD.Value != 0 && FloorNoNUD.Value != 0;
            bool roomTypeCBText   = RoomTypeCB.SelectedText != "      ------- Select a room Type -------    ";
            bool roomStatusCBText = RoomStatusCB.SelectedText != "      ------- Select a room status -------    ";
            bool inputsValidation = numericInputs || roomTypeCBText || roomStatusCBText;

            if (inputsValidation)
            {
                var roomTypeId   = Convert.ToInt32(RoomTypeCB.SelectedValue);
                var roomStatusId = Convert.ToInt32(RoomStatusCB.SelectedValue);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        RoomsDGV.DataSource = context.Rooms.Where(r => r.Room_Number == RoomNoNUD.Value ||
                                                                  r.Floor_Number == FloorNoNUD.Value ||
                                                                  r.Type_Id == roomTypeId ||
                                                                  r.Status_Id == roomStatusId)
                                              .Select(r => new {
                            r.Room_Number,
                            r.Floor_Number,
                            Room_Type   = r.Room_Type.Name,
                            Room_Status = r.Room_Status.Name
                        }).ToList();
                    }
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ResetRoomInputs();
            }
            else
            {
                MetroMessageBox.Show(this, "Please insert valid data to start searching", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #13
0
        private void ReservationsDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (ReservationsDGV.CurrentRow.Index != -1)
            {
                reservation.Id = Convert.ToInt32(ReservationsDGV.CurrentRow.Cells["Id"].Value);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        reservation = context.Reservations.Where(r => r.Id == reservation.Id).FirstOrDefault();
                        room        = context.Rooms.Where(r => r.Id == reservation.Room_Id).FirstOrDefault();
                    }

                    ReservationDeleteBtn.Enabled = true;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #14
0
        private void RoomStatusDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (RoomStatusDGV.CurrentRow.Index != -1)
            {
                roomStatus.Id = Convert.ToInt32(RoomStatusDGV.CurrentRow.Cells["Status_Id"].Value);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        roomStatus = context.Room_Status.Where(s => s.Id == roomStatus.Id).FirstOrDefault();
                    }

                    RoomStatusNameTB.Text        = roomStatus.Name;
                    RoomStatusDescriptionTB.Text = roomStatus.Description;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #15
0
        private void RoomTypeDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (RoomTypeDGV.CurrentRow.Index != -1)
            {
                roomType.Id = Convert.ToInt32(RoomTypeDGV.CurrentRow.Cells["Type_Id"].Value);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        roomType = context.Room_Type.Where(t => t.Id == roomType.Id).FirstOrDefault();
                    }

                    RoomTypeNameTB.Text  = roomType.Name;
                    BedsNUD.Value        = roomType.No_of_Beds;
                    MaxCapacityNUD.Value = roomType.Max_Capacity;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #16
0
        private void RoomsDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (RoomsDGV.CurrentRow.Index != -1)
            {
                room.Id = Convert.ToInt32(RoomsDGV.CurrentRow.Cells["Id"].Value);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        room = context.Rooms.Where(r => r.Id == room.Id).FirstOrDefault();
                    }

                    RoomNoNUD.Value            = room.Room_Number;
                    FloorNoNUD.Value           = room.Floor_Number;
                    RoomTypeCB.SelectedValue   = room.Type_Id;
                    RoomStatusCB.SelectedValue = room.Status_Id;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #17
0
        private void CheckDGV_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (CheckDGV.CurrentRow.Index != -1)
            {
                room.Id = Convert.ToInt32(CheckDGV.CurrentRow.Cells["Id"].Value);

                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        room = context.Rooms.Where(r => r.Id == room.Id).FirstOrDefault();
                    }

                    RoomNoDisplayOnlyTB.Text = room.Room_Number.ToString();
                    room.Check_In            = CheckInDTP.Value.Date;
                    room.Check_Out           = CheckOutDTP.Value.Date;
                    BookBtn.Enabled          = true;
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #18
0
        private void EmployeesSearchBtn_Click(object sender, EventArgs e)
        {
            if ((!string.IsNullOrWhiteSpace(EmployeeFNameTB.Text) && !string.IsNullOrWhiteSpace(EmployeeLNameTB.Text)) || !string.IsNullOrWhiteSpace(EmployeePhoneTB.Text) || !string.IsNullOrWhiteSpace(EmployeeEmailTB.Text))
            {
                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        EmployeesDGV.DataSource = context.Employees.Where(a => (a.First_Name == EmployeeFNameTB.Text &&
                                                                                a.Last_Name == EmployeeLNameTB.Text) ||
                                                                          a.E_Mail == EmployeeEmailTB.Text ||
                                                                          a.Phone == EmployeePhoneTB.Text ||
                                                                          a.Job_Title == EmployeeJobTB.Text)
                                                  .Select(a => new {
                            a.Id,
                            a.First_Name,
                            a.Last_Name,
                            a.Address,
                            a.E_Mail,
                            a.Phone,
                            a.Job_Title
                        }).ToList();
                    }
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ClearEmployeeInputs();
            }
            else
            {
                MetroMessageBox.Show(this, "Please enter full name, e-mail Phone number or job title to start searching", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #19
0
        private void ReservationSearchBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(ReservationFNameTB.Text) && !string.IsNullOrWhiteSpace(ReservationLNameTB.Text))
            {
                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        var guestsList = context.Guests.Where(g => (g.First_Name == ReservationFNameTB.Text &&
                                                                    g.Last_Name == ReservationLNameTB.Text))
                                         .Select(g => new
                        {
                            g.Id,
                            g.First_Name,
                            g.Last_Name,
                            g.Address,
                            g.E_Mail,
                            g.Phone
                        }).ToList();

                        var resList = new List <Reservation>();

                        foreach (var member in guestsList)
                        {
                            resList.AddRange(context.Reservations.Where(a => a.Guest_Id == member.Id).ToList());
                        }

                        ReservationsDGV.DataSource = resList.Select(r => new
                        {
                            r.Id,
                            r.Guest.First_Name,
                            r.Guest.Last_Name,
                            r.Check_In,
                            r.Check_Out,
                            r.Adults,
                            r.Children,
                            Room_No   = r.Room.Room_Number,
                            Room_Type = r.Room.Room_Type.Name
                        }).ToList();
                    }
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ClearreservationInputs();
            }
            else if (!string.IsNullOrWhiteSpace(ReservationRoomNoTB.Text))
            {
                try
                {
                    using (GrandLuxEntities context = new GrandLuxEntities())
                    {
                        var roomNumber = Convert.ToInt32(ReservationRoomNoTB.Text);

                        ReservationsDGV.DataSource = context.Reservations.Where(a => a.Room.Room_Number == roomNumber)
                                                     .Select(r => new
                        {
                            r.Id,
                            r.Guest.First_Name,
                            r.Guest.Last_Name,
                            r.Check_In,
                            r.Check_Out,
                            r.Adults,
                            r.Children,
                            Room_No   = r.Room.Room_Number,
                            Room_Type = r.Room.Room_Type.Name
                        }).ToList();
                    }
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ClearreservationInputs();
            }
            else
            {
                MetroMessageBox.Show(this, "Please enter full name, e-mail Phone number or check in date to start searching", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }