Ejemplo n.º 1
0
        /// <summary>
        /// The form is initially created, but loaded each time it is shown.
        /// Reload data each time the form loaded.
        /// This is the handler for the Load event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReservationForm_Load()
        {
            // bind the listbox of guest and rooms

            listBoxGuestName.DataSource = Controller <VancouverHotelEntities, Guest> .SetBindingList();

            listBoxRoomType.DataSource = Controller <VancouverHotelEntities, Room> .SetBindingList();

            // no guest or room is selected to start

            listBoxGuestName.SelectedIndex = -1;
            listBoxGuestName.SelectedIndex = -1;

            // set all textboxes to blank

            textBoxGuestID.ResetText();
            textBoxRoomID.ResetText();
            textBoxResevationID.ResetText();

            InitializeDataGridView <Reservation>(dataGridViewReservations, "Reservations");
            this.dataGridViewReservations.Columns["Guest"].Visible            = false;
            this.dataGridViewReservations.Columns["Payments"].Visible         = false;
            this.dataGridViewReservations.Columns["Room"].Visible             = false;
            this.dataGridViewReservations.Columns["RoomReservations"].Visible = false;

            dataGridViewReservations.DataSource = context.Reservations.ToList();

            context = new VancouverHotelEntities();
            context.Database.Log = (s => Debug.Write(s));
            context.Reservations.Load();
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a room to the db
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonRoomAdd_Click(object sender, EventArgs e)
        {
            RoomType roomType       = new RoomType();
            string   selectedStatus = listBoxStatus.SelectedItem.ToString(); // get selected status

            foreach (DataGridViewRow row in dataGridViewRoom.SelectedRows)
            {
                roomType = row.DataBoundItem as RoomType; // get sleceted roomType infomation
            }
            Room room = new Room
            {
                RoomTypeId = roomType.RoomTypeId,
                Status     = selectedStatus,
            };

            if (Controller <VancouverHotelEntities, Room> .AddEntity(room) == null)
            {
                MessageBox.Show("Cannot add Room to database");
                return;
            }

            context = new VancouverHotelEntities();

            RoomInfoForm_Load();
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public RoomInfoForm()
        {
            InitializeComponent();
            this.Text = "Room Information Form";

            hotelDataSet = new DataSet()
            {
                DataSetName = "VancouverHOtelDataSet",
            };

            context = new VancouverHotelEntities();

            // register the event handlers
            this.Load += (s, e) => RoomInfoForm_Load();
            buttonRoomTypeAdd.Click    += ButtonRoomTypeAdd_Click;
            buttonRoomTypeUpdate.Click += ButtonRoomTypeUpdate_Click;
            buttonRoomTypeDelete.Click += ButtonRoomTypeDelete_Click;
            buttonBackupDatabase.Click += (s, e) => BackupDataSetToXML();
            buttonRoomAdd.Click        += ButtonRoomAdd_Click;
            buttonRoomUpdate.Click     += ButtonRoomUpdate_Click;
            buttonRoomDelete.Click     += ButtonRoomDelete_Click;

            // register event handler for when a RoomType is selected
            dataGridViewRoom.SelectionChanged    += DataGridViewRoom_SelectionChanged;
            dataGridViewAddRoom.SelectionChanged += DataGridViewAddRoom_SelectionChanged;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update the db with the new reservation data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonUpdateRoom_Click(object sender, EventArgs e)
        {
            if ((dataGridViewReservations.SelectedRows == null))
            {
                MessageBox.Show("Reservation to be updated must be selected");
                return;
            }

            if (!string.IsNullOrEmpty(textBoxResevationID.Text) && !string.IsNullOrEmpty(textBoxGuestID.Text) && !string.IsNullOrEmpty(textBoxRoomID.Text) &&
                !string.IsNullOrEmpty(dateTimePickerReservation.Text) && !string.IsNullOrEmpty(textBoxNumberOfGuests.Text) && !string.IsNullOrEmpty(dateTimePickerCheckin.Text) &&
                !string.IsNullOrEmpty(dateTimePickerCheckOut.Text))
            {
                var numNight = dateTimePickerCheckOut.Value.Day - dateTimePickerCheckin.Value.Day;
                //  var reservation = context.Reservations.Find(int.Parse(textBoxResevationID.Text));
                Reservation reservation = new Reservation();
                reservation.ReservationId   = int.Parse(textBoxResevationID.Text);
                reservation.GuestId         = int.Parse(textBoxGuestID.Text);
                reservation.RoomId          = int.Parse(textBoxRoomID.Text);
                reservation.ReservationDate = dateTimePickerReservation.Text;
                reservation.NumberOfGuest   = int.Parse(textBoxNumberOfGuests.Text);
                reservation.CheckInDate     = dateTimePickerCheckin.Text;
                reservation.CheckOutDate    = dateTimePickerCheckOut.Text;
                reservation.NumberOfNight   = Convert.ToInt32(numNight);

                if (InfoIsInvalid(reservation))
                {
                    MessageBox.Show("Reservation Information is missing");
                    return;
                }

                if (CapacityIsValid(reservation))
                {
                    MessageBox.Show("Number of guest is greater than the capacity of the room");
                    return;
                }

                if (DateIsValid(reservation))
                {
                    MessageBox.Show("Check-in date is greater than Check-out date or Check-in date is greater than Reservation date");
                    return;
                }

                // now update the db

                if (Controller <VancouverHotelEntities, Reservation> .UpdateEntity(reservation) == false)
                {
                    MessageBox.Show("Cannot add reservation to database");
                    return;
                }

                context = new VancouverHotelEntities();
                ReservationForm_Load();
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update the db with the new room data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonRoomUpdate_Click(object sender, EventArgs e)
        {
            if ((dataGridViewAddRoom.SelectedRows == null))
            {
                MessageBox.Show("Room to be updated must be selected");
                return;
            }
            try
            {
                string selectedStatus = listBoxStatus.SelectedItem.ToString(); // get selected status

                Room room         = new Room();
                Room selectedRoom = new Room();

                foreach (DataGridViewRow row in dataGridViewAddRoom.SelectedRows)
                {
                    selectedRoom = row.DataBoundItem as Room; // get sleceted roomType infomation
                }
                if (selectedRoom.Status == "Occupied")
                {
                    listBoxStatus.SelectedIndex = 0;
                }
                else
                {
                    listBoxStatus.SelectedIndex = 1;
                }

                room.RoomId     = selectedRoom.RoomId;
                room.RoomTypeId = selectedRoom.RoomTypeId;
                room.Status     = selectedStatus;

                if (Controller <VancouverHotelEntities, Room> .UpdateEntity(room) == false)
                {
                    MessageBox.Show("Cannot update room to database");
                    return;
                }

                context = new VancouverHotelEntities();

                context.SaveChanges();
                RoomInfoForm_Load();
            }

            catch (Exception)
            {
                MessageBox.Show("Unable update room to database");
            }
        }
Ejemplo n.º 6
0
        public GuestForm()
        {
            InitializeComponent();

            this.Text            = "Guest Form";
            context              = new VancouverHotelEntities();
            context.Database.Log = (s => Debug.Write(s));

            // register the event handlers
            this.Load += (s, e) => GuestForm_Load();
            btnAddCustomerInfo.Click += BtnAddCustomerInfo_Click;
            btnUpdateCustomer.Click  += BtnUpdateCustomer_Click;
            btnDeleteCustomer.Click  += BtnDeleteCustomer_Click;

            dataGridViewCustomer.CellClick += DataGridViewCustomer_CellClick;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add a payment to the db
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonPay_Click(object sender, EventArgs e)
        {
            Reservation reservation = new Reservation();

            foreach (DataGridViewRow row in dataGridViewReservationInfo.SelectedRows)
            {
                reservation = row.DataBoundItem as Reservation;
            }
            // get the guest data from the textboxes

            // check if it's already paid
            if (IsPaid(reservation))
            {
                MessageBox.Show("The reservation is already paid");
                return;
            }

            Payment pay = new Payment()
            {
                ReservationId = reservation.ReservationId,
                GuestId       = reservation.GuestId,
                Amount        = Convert.ToDecimal(textBoxTotalAmount.Text),
                PaymentType   = textBoxPayType.Text.ToString()
            };

            if (pay.PaymentType.Trim() == null || pay.PaymentType.Length == 0)
            {
                MessageBox.Show("Payment Type is requird");
                return;
            }

            // now update the db

            if (Controller <VancouverHotelEntities, Payment> .AddEntity(pay) == null)
            {
                MessageBox.Show("Cannot add payment to database");
                return;
            }

            context = new VancouverHotelEntities();
            context.Database.Log = (s => Debug.Write(s));
            context.Payments.Load();
            context.SaveChanges();

            PaymentForm_Load();
            context.SaveChanges();
        }
Ejemplo n.º 8
0
        public ReservationForm()
        {
            InitializeComponent();
            this.Text = "Reservation Form";
            context   = new VancouverHotelEntities();

            // register the event handkers
            this.Load                 += (s, e) => ReservationForm_Load();
            buttonBook.Click          += ButtonBook_Click;
            buttonCancelBooking.Click += ButtonCancelBooking_Click;
            buttonUpdateRoom.Click    += ButtonUpdateRoom_Click;

            // register event handler for when a guest is selected
            listBoxGuestName.SelectedIndexChanged     += (s, e) => GetReservation();
            listBoxRoomType.SelectedIndexChanged      += (s, e) => GetReservation();
            dataGridViewReservations.SelectionChanged += DataGridViewReservation_SelectionChanged;
        }
Ejemplo n.º 9
0
        public HotelMainForm()
        {
            InitializeComponent();

            this.Text = "Vancouver Beachside Hotel";
            VancouverHotelEntities context = new VancouverHotelEntities();

            context.Database.Log = (s => Debug.Write(s));
            context.SeedDatabase();
            context.SaveChanges();

            // register the event handlers
            buttonAdmin.Click       += ButtonAdmin_Click;
            buttonFrontDesk.Click   += ButtonFrontDesk_Click;
            buttonPayment.Click     += ButtonPayment_Click;
            buttonReservation.Click += ButtonReservation_Click;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Update the db with the payment data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonPayUpdate_Click(object sender, EventArgs e)
        {
            if ((dataGridViewPayments.SelectedRows == null))
            {
                MessageBox.Show("Payment to be updated must be selected");
                return;
            }

            Payment selectedPayment = new Payment();

            // get selected payment information
            foreach (DataGridViewRow row in dataGridViewPayments.SelectedRows)
            {
                selectedPayment = row.DataBoundItem as Payment;
            }

            Payment payment = new Payment();

            payment.PaymentId     = selectedPayment.PaymentId;
            payment.PaymentType   = textBoxPayType.Text.ToString();
            payment.ReservationId = selectedPayment.ReservationId;
            payment.GuestId       = selectedPayment.GuestId;
            payment.Amount        = selectedPayment.Amount;

            if (payment.PaymentType.Trim() == null || payment.PaymentType.Length == 0)
            {
                MessageBox.Show("Payment Type is requird");
                return;
            }

            if (payment.PaymentType == selectedPayment.PaymentType)
            {
                MessageBox.Show("The payment already exists");
                return;
            }

            if (Controller <VancouverHotelEntities, Payment> .UpdateEntity(payment) == false)
            {
                MessageBox.Show("Cannot update payment type to database");
                return;
            }

            context = new VancouverHotelEntities();
            PaymentForm_Load();
            context.SaveChanges();
        }
Ejemplo n.º 11
0
        public PaymentForm()
        {
            InitializeComponent();

            this.Text = "Payment Form";
            context   = new VancouverHotelEntities();

            // register the event handlers
            this.Load             += (s, e) => PaymentForm_Load();
            buttonPay.Click       += ButtonPay_Click;
            buttonPayUpdate.Click += ButtonPayUpdate_Click;
            buttonPayDelete.Click += ButtonPayDelete_Click;

            // register event handler for when a reservation is selected
            dataGridViewReservationInfo.SelectionChanged += DataGridViewReservationInfo_SelectionChanged;
            dataGridViewPayments.SelectionChanged        += DataGridViewPayments_SelectionChanged;
        }
        /// <summary>
        /// zero out the db tables, then seed all tables with initial data
        /// </summary>
        public static void SeedDatabase(this VancouverHotelEntities context)
        {
            // set up database log to write to output window in VS
            context.Database.Log = (s => Debug.Write(s));

            // reset the db
            context.Database.Delete();
            context.Database.Create();

            context.SaveChanges();

            context.Guests.Load();
            context.Rooms.Load();
            context.RoomTypes.Load();
            context.Reservations.Load();
            context.Payments.Load();

            // seed Guests data


            List <Guest> guestList = new List <Guest>()
            {
                new Guest {
                    GuestFirstName = "Pepi", GuestLastName = "Nattrass", Adress = "209 Dixon Alle",
                    City           = "Bangkok", PostCode = "66110", Country = "Thailand", Email = "*****@*****.**", Phone = "999-103-078"
                },

                new Guest {
                    GuestFirstName = "Kennan", GuestLastName = "Ciottoi", Adress = "9921 Holy Cross Crossing",
                    City           = "Stockholm", PostCode = "38680-000", Country = "Brazil", Email = "*****@*****.**", Phone = "560-917-1312"
                },

                new Guest {
                    GuestFirstName = "Meggy", GuestLastName = "Flann", Adress = "8528 Darwin Park",
                    City           = "Stockholm", PostCode = "114 49", Country = "Sweden", Email = "*****@*****.**", Phone = "181-757-8748"
                },

                new Guest {
                    GuestFirstName = "Taryn", GuestLastName = "Duinbleton", Adress = "2168 Holy Cross Pass,Qianfoling",
                    City           = "Qianfoling", PostCode = "45467", Country = "China", Email = "*****@*****.**", Phone = "539-339-6374"
                },

                new Guest {
                    GuestFirstName = "Sam", GuestLastName = "Li", Adress = "443 Glass st",
                    City           = "Vancouver", PostCode = "34334", Country = "Chanada", Email = "*****@*****.**", Phone = "778-454-3454"
                },

                new Guest {
                    GuestFirstName = "Karen", GuestLastName = "Smith", Adress = "4545 Victoria ave",
                    City           = "New York", PostCode = "34334", Country = "America", Email = "*****@*****.**", Phone = "343-454-2333"
                },
            };


            context.Guests.AddRange(guestList);
            context.SaveChanges();


            List <RoomType> roomTypeList = new List <RoomType>()
            {
                new RoomType {
                    RoomTypeName = "Single Room", Capacity = 1, PricePerNight = 100
                },
                new RoomType {
                    RoomTypeName = "Double Room", Capacity = 3, PricePerNight = 300
                },
                new RoomType {
                    RoomTypeName = "Twin Room", Capacity = 3, PricePerNight = 300
                },
                new RoomType {
                    RoomTypeName = "King Room", Capacity = 4, PricePerNight = 400
                },
            };

            context.RoomTypes.AddRange(roomTypeList);
            context.SaveChanges();


            List <Room> roomList = new List <Room>()
            {
                new Room {
                    RoomTypeId = 1, Status = "Occupied"
                },
                new Room {
                    RoomTypeId = 2, Status = "Vacant"
                },
                new Room {
                    RoomTypeId = 2, Status = "Vacant"
                },
                new Room {
                    RoomTypeId = 4, Status = "Vacant"
                }
            };

            context.Rooms.AddRange(roomList);
            context.SaveChanges();


            List <Reservation> reservationList = new List <Reservation>()
            {
                new Reservation {
                    GuestId = 1, RoomId = 1, ReservationDate = "2010-01-01", CheckInDate = "2010-01-02", CheckOutDate = "2010-01-03", NumberOfGuest = 1, NumberOfNight = 1
                },
                new Reservation {
                    GuestId = 2, RoomId = 2, ReservationDate = "2020-01-01", CheckInDate = "2020-01-02", CheckOutDate = "2020-01-03", NumberOfGuest = 2, NumberOfNight = 1
                },
                new Reservation {
                    GuestId = 4, RoomId = 3, ReservationDate = "2020-01-01", CheckInDate = "2020-01-02", CheckOutDate = "2020-01-04", NumberOfGuest = 2, NumberOfNight = 2
                },
                new Reservation {
                    GuestId = 4, RoomId = 3, ReservationDate = "2020-10-23", CheckInDate = "2020-12-02", CheckOutDate = "2020-12-10", NumberOfGuest = 2, NumberOfNight = 8
                }
            };

            context.Reservations.AddRange(reservationList);
            context.SaveChanges();

            List <Payment> paymentsList = new List <Payment>()
            {
                new Payment {
                    ReservationId = 1, GuestId = 1, Amount = 100, PaymentType = "VISA"
                },
            };

            context.Payments.AddRange(paymentsList);
            context.SaveChanges();


            guestList[0].Reservations.Add(reservationList[0]);
            guestList[1].Reservations.Add(reservationList[1]);

            context.SaveChanges();
        }