예제 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstAvailableServices.Items.Count == 0)
            {
                return;
            }
            if (lstAvailableServices.SelectedIndex < 0)
            {
                MessageBox.Show("First choose available service from list");
                return;
            }
            Service service       = lstAvailableServices.SelectedItem as Service;
            int     choosenIndeks = lstAvailableServices.SelectedIndex;

            db.Services.Remove(service);
            db.SaveChanges();
            ListServices();
            if (lstAvailableServices.Items.Count >= 0)
            {
                if (choosenIndeks != lstAvailableServices.Items.Count)
                {
                    lstAvailableServices.SelectedIndex = choosenIndeks;
                }
                else
                {
                    lstAvailableServices.SelectedIndex = lstAvailableServices.Items.Count - 1;
                }
            }
        }
예제 #2
0
        private void btnAddFeature_Click(object sender, EventArgs e)
        {
            if (txtFeatureName.Text == "")
            {
                MessageBox.Show("Plase type Feature name");
                return;
            }

            Feature feature = new Feature();

            feature.FeatureName = txtFeatureName.Text.Trim();

            if (db.Features.Select(x => x.FeatureName).Contains(feature.FeatureName))
            {
                DialogResult dr = MessageBox.Show("Allready have feature for this Feature Name are you want to create new feature ? ", "İnfo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dr == DialogResult.Yes)
                {
                    txtFeatureName.Text = "";
                    lstAvailableFeatures.SelectedIndex = -1;
                    txtFeatureName.Focus();
                    return;
                }
                else
                {
                    return;
                }
            }
            db.Features.Add(feature);
            db.SaveChanges();
            ListFeature();
            lstAvailableFeatures.SelectedIndex = lstAvailableFeatures.Items.Count - 1;
        }
예제 #3
0
        private void btnAddRoom_Click(object sender, EventArgs e)
        {
            if (txtRoomName.Text == "")
            {
                MessageBox.Show("Plase type room name");
                return;
            }
            if (nudPrice.Value == 0)
            {
                MessageBox.Show("Price must over Zero");
                return;
            }
            Room room = new Room();

            room.RoomName = txtRoomName.Text.Trim();
            room.Price    = nudPrice.Value;
            room.Capacity = (int)nudCapacity.Value;

            if (cboFeatures.SelectedIndex >= 0)
            {
                Feature feature = cboFeatures.SelectedItem as Feature;
                room.Features.Add(feature);
            }
            if (db.Rooms.Select(x => x.RoomName).Contains(room.RoomName))
            {
                DialogResult dr = MessageBox.Show("Allready have room for this Room Name are you want to create new room ? ", "İnfo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dr == DialogResult.Yes)
                {
                    txtRoomName.Text                = "";
                    nudPrice.Value                  = 0;
                    nudCapacity.Value               = 1;
                    cboFeatures.SelectedIndex       = -1;
                    lstAvailableRooms.SelectedIndex = -1;
                    this.Height = 341;
                    txtRoomName.Focus();
                    return;
                }
                else
                {
                    return;
                }
            }
            db.Rooms.Add(room);
            db.SaveChanges();
            ListRooms();
            lstAvailableRooms.SelectedIndex = lstAvailableRooms.Items.Count - 1;
            cboFeatures.SelectedIndex       = -1;
        }
        private void BtnEditMode_Click(object sender, EventArgs e)
        {
            using (HotelCrownContext db = new HotelCrownContext())
            {
                int         selectedId = int.Parse(dgvReservations.SelectedRows[0].Cells["Id"].Value.ToString());
                Reservation editingOne = db.Reservations.FirstOrDefault(x => x.Id == selectedId);
                editingOne.CheckOutDate = dtExtendOut.Value;
                int quantity = (int)nudQuantity.Value;
                ReservationService reservationService = new ReservationService
                {
                    ServiceName = editingOne.ReservationServices + cboServices.Text,
                    Quantity    = quantity
                };
                editingOne.ReservationServices = new List <ReservationService> {
                    reservationService
                };
                db.SaveChanges();
                ListResarvation();
            }
            ListResarvation();

            btnNewReservation.Visible = true;
            btnEdit.Visible           = true;
            btnDelete.Visible         = true;
            dtExtendOut.Visible       = false;
            cboServices.Visible       = false;
            nudQuantity.Visible       = false;
            BtnEditMode.Visible       = false;
            PanelControls.Visible     = true;
            PanelEdit.Visible         = false;
        }
예제 #5
0
        private void btnAlloteRoom_Click(object sender, EventArgs e)
        {
            string   fullName    = txtFullName.Text;
            int      identityNo  = int.Parse(txtIdentityNumber.Text);
            int      mobileNo    = int.Parse(txtMobileNo.Text);
            Gender   gender      = (Gender)cboGender.SelectedValue;
            DateTime birthDate   = dtBirthDate.Value;
            string   description = rtxtDescriptions.Text;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                db.Customers.Add(new Customer()
                {
                    FullName       = fullName,
                    IdentityNumber = identityNo,
                    PhoneNumber    = mobileNo,
                    Gender         = gender,
                    BirthDate      = birthDate,
                    Description    = description
                });
                db.SaveChanges();
            }
            ListCustomers();
            ClearForm();
        }
예제 #6
0
        private void btnAddRoom_Click_1(object sender, EventArgs e)
        {
            if (txtRoomNo.Text == "" || txtPrice.Text == "" || cboBed.Text == "")
            {
                MessageBox.Show("Fill All Fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int            roomNo    = int.Parse(txtRoomNo.Text);
            List <Feature> features  = clbFeatures.CheckedItems.OfType <Feature>().ToList();
            int            price     = int.Parse(txtPrice.Text);
            string         bedNumber = cboBed.Text;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                db.Rooms.Add(new Room
                {
                    RoomNo   = roomNo,
                    Capacity = bedNumber,
                    Price    = price,
                    Features = features
                });
                db.SaveChanges();
            }
            ListRooms();
            Clear();
        }
예제 #7
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            btnAlloteRoom.Visible = true;
            btnEdit.Visible       = true;
            btnDelete.Enabled     = true;
            btnUpdate.Visible     = false;
            btnCancel.Visible     = false;
            string   fullName    = txtFullName.Text;
            int      identityNo  = int.Parse(txtIdentityNumber.Text);
            int      mobileNo    = int.Parse(txtMobileNo.Text);
            Gender   gender      = (Gender)cboGender.SelectedValue;
            DateTime birthDate   = dtBirthDate.Value;
            string   description = rtxtDescriptions.Text;

            Customer selectedCustomer = (Customer)dgvCustomers.SelectedRows[0].DataBoundItem;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                var editingPerson = db.Customers.FirstOrDefault(x => x.Id == selectedCustomer.Id);
                editingPerson.FullName       = fullName;
                editingPerson.IdentityNumber = identityNo;
                editingPerson.PhoneNumber    = mobileNo;
                editingPerson.Gender         = gender;
                editingPerson.BirthDate      = birthDate;
                editingPerson.Description    = description;
                db.SaveChanges();
            }
            ListCustomers();
            ClearForm();
        }
예제 #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string feature = txtFeatureName.Text;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                db.Features.Add(new Feature()
                {
                    FeatureName = feature
                });
                db.SaveChanges();
            }
            ListFeatures();
            ClearForm();
        }
        private void btnAlloteRoom_Click(object sender, EventArgs e)
        {
            Customer alloteCustomer = (Customer)dgvCustomers.SelectedRows[0].DataBoundItem;

            DateTime controlIn      = new DateTime(2020, 12, 6, 12, 04, 00);
            DateTime controlOut     = new DateTime(2020, 12, 6, 12, 04, 00);
            DateTime checkInDate    = dtCheckInDate.Value;
            DateTime checkOutDate   = dtCheckOutDate.Value;
            DateTime checkedInTime  = dtCheckInTime.Value;
            DateTime checkedOutTime = dtCheckOutTime.Value;
            string   service        = cboServices.Text;
            int      quantity       = int.Parse(nudQuantity.Text);
            int      customerId     = alloteCustomer.Id;

            //int roomId = reservation.RoomId;
            string checkedIn  = (cbxCheckedIn.Checked) ? "Yes" : "No";
            string checkedOut = (cbxCheckedOut.Checked) ? "Yes" : "No";

            using (HotelCrownContext db = new HotelCrownContext())
            {
                string             serveCustomer   = cboServices.Text;
                Room               addRoom         = (Room)db.Rooms.FirstOrDefault(x => x.RoomId == reservation);
                ReservationService serviceCustomer = db.ReservationServices.FirstOrDefault(x => x.ServiceName == serveCustomer);
                Customer           reserveCustomer = db.Customers.FirstOrDefault(x => x.Id == customerId);

                db.Reservations.Add(new Reservation()
                {
                    RoomId         = reservation,
                    CheckInDate    = checkInDate,
                    CheckOutDate   = checkOutDate,
                    CheckedInTime  = checkedInTime,
                    CheckedOutTime = checkedOutTime,
                    CheckedIn      = checkedIn,
                    CheckedOut     = checkedOut,
                    Room           = addRoom,
                    Customers      = new List <Customer> {
                        reserveCustomer
                    },
                    ReservationServices = new List <ReservationService> {
                        serviceCustomer
                    }
                });
                db.SaveChanges();
            }
            WhenChangesDone(EventArgs.Empty);
            Close();
        }
예제 #10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string service = txtServiceName.Text;
            string price   = txtPrice.Text;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                db.ReservationServices.Add(new ReservationService()
                {
                    ServiceName = service,
                    UnitPrice   = int.Parse(price)
                });
                db.SaveChanges();
            }
            ListFeatures();
            ClearForm();
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvReservations.SelectedRows.Count == 0)
            {
                return;
            }

            int selectedId = int.Parse(dgvReservations.SelectedRows[0].Cells["Id"].Value.ToString());

            using (HotelCrownContext db = new HotelCrownContext())
            {
                Reservation deletingReservation = db.Reservations.FirstOrDefault(x => x.Id == selectedId);
                db.Reservations.Attach(deletingReservation);
                db.Reservations.Remove(deletingReservation);
                db.SaveChanges();
            }
            ListResarvation();
        }
예제 #12
0
        private void btnDeleteReservation_Click(object sender, EventArgs e)
        {
            Reservation            reservation = dgvReservations.SelectedRows[0].DataBoundItem as Reservation;
            Room                   room        = reservation.Room;
            ICollection <Customer> customers   = reservation.Customers;

            room.Customers.Clear();
            room.Reservations.Remove(reservation);
            for (int i = 0; i < customers.Count; i++)
            {
                var      s        = customers.ToArray();
                Customer customer = s[i];
                customer.CustomerName = customer.CustomerName.Replace($"({room.RoomName})", "");
                customer.Room         = null;
            }
            db.Reservations.Remove(reservation);
            db.SaveChanges();
            dgvReservations.DataSource = db.Reservations.ToList();
        }
예제 #13
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvServices.SelectedRows.Count == 0)
            {
                return;
            }

            int selectedIndex = dgvServices.SelectedRows[0].Index;

            ReservationService deletingService = (ReservationService)dgvServices.SelectedRows[0].DataBoundItem;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                db.ReservationServices.Attach(deletingService);
                db.ReservationServices.Remove(deletingService);
                db.SaveChanges();
            }
            ListFeatures();
            ClearForm();
        }
예제 #14
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvCustomers.SelectedRows.Count == 0)
            {
                return;
            }

            int selectedIndex = dgvCustomers.SelectedRows[0].Index;

            Customer deletingCustomer = (Customer)dgvCustomers.SelectedRows[0].DataBoundItem;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                db.Customers.Attach(deletingCustomer);
                db.Customers.Remove(deletingCustomer);
                db.SaveChanges();
            }
            ListCustomers();
            ClearForm();
        }
예제 #15
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            btnAlloteRoom.Visible = false;
            btnEdit.Visible       = false;
            btnDelete.Enabled     = false;
            btnUpdate.Visible     = true;
            btnCancel.Visible     = true;
            Customer selectedCustomer = (Customer)dgvCustomers.SelectedRows[0].DataBoundItem;

            using (HotelCrownContext db = new HotelCrownContext())
            {
                var editingPerson = db.Customers.FirstOrDefault(x => x.Id == selectedCustomer.Id);
                txtFullName.Text       = editingPerson.FullName;
                txtIdentityNumber.Text = editingPerson.IdentityNumber.ToString();
                txtMobileNo.Text       = editingPerson.IdentityNumber.ToString();
                //cboGender.SelectedValue = editingPerson.Gender;
                dtBirthDate.Value     = (DateTime)editingPerson.BirthDate;
                rtxtDescriptions.Text = editingPerson.Description;
                db.SaveChanges();
            }
        }
예제 #16
0
        private void btnAddReservation_Click(object sender, EventArgs e)
        {
            Customer customer = lstCustomers.SelectedItem as Customer;
            Room     room     = lstRooms.SelectedItem as Room;

            if (room.Customers.Count == 0)
            {
                MessageBox.Show("You dont open empty room");
                return;
            }
            if (lstRooms.SelectedIndex < 0)
            {
                MessageBox.Show("Please select the room you want to add new reservation");
                return;
            }
            DateTime dateTimeNow = DateTime.Now;

            if (DateTime.Compare(dateTimeNow, dtpCheckInDate.Value) > 0 || DateTime.Compare(dateTimeNow, dtpCheckOutDate.Value) > 0)
            {
                MessageBox.Show("CheckIn Date or CheckOut Date must be to the future");
                return;
            }
            if (DateTime.Compare(dtpCheckInDate.Value, dtpCheckOutDate.Value) == 0)
            {
                MessageBox.Show("CheckIn Date and Check Out date cannot be equal");
                return;
            }
            if (DateTime.Compare(dtpCheckInDate.Value, dtpCheckOutDate.Value) > 0)
            {
                MessageBox.Show("CheckIn Date must be earlier then Check Out Date ");
                return;
            }

            var availableRooms = db.Rooms.Where(x => x.Reservations.All(r => r.CheckOutDate <= dtpCheckInDate.Value || r.CheckInDate >= dtpCheckOutDate.Value)).ToList();

            if (room.Capacity < room.Customers.Count())
            {
                MessageBox.Show("Room Capacity is full please delete customer or customers then try again");
                return;
            }
            if (customer.CustomerName.Contains(room.RoomName) == false)
            {
                MessageBox.Show($"Your customers room is not {room.RoomName}");
                return;
            }

            Reservation reservation = new Reservation();
            var         s           = room.Customers.ToArray();

            for (int i = 0; i < s.Length; i++)
            {
                reservation.Customers.Add(s[i]);
                s[i].Reservation = reservation;
            }
            reservation.CheckInDate  = dtpCheckInDate.Value;
            reservation.CheckOutDate = dtpCheckOutDate.Value;
            reservation.RoomName     = room.RoomName;
            room.Reservations.Add(reservation);
            if (availableRooms.Contains(room))
            {
                db.Reservations.Add(reservation);
                room.Customers.Clear();
                db.SaveChanges();
                WhenANewReservationIsAdded(EventArgs.Empty);
                int selectedIndexCustomer = lstCustomers.SelectedIndex;
                int selectedIndexRoom     = lstRooms.SelectedIndex;
                lstCustomers.DataSource = db.Customers.Where(x => x.Reservation == null).ToList();
                lstRooms.DataSource     = availableRooms;
                lstRooms.SelectedIndex  = selectedIndexRoom;
                if (lstCustomers.Items.Count > selectedIndexCustomer)
                {
                    lstCustomers.SelectedIndex = selectedIndexCustomer;
                }
            }
            else
            {
                room.Reservations.Remove(reservation);
                MessageBox.Show("This Room is full at this dates");
                return;
            }
            MessageBox.Show("Reservation Created");
            lstRooms.DataSource = db.Rooms.Where(x => x.Reservations.All(r => r.CheckOutDate <= dtpCheckInDate.Value || r.CheckInDate >= dtpCheckOutDate.Value)).ToList();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cboRooms.SelectedIndex >= 0)
            {
                var availablecustomers = reservation.Customers.ToList();
                foreach (var item in availablecustomers)
                {
                    item.CustomerName = item.CustomerName.Replace($"({reservation.Room.RoomName})", "");
                }
                reservation.Room.Reservations.Remove(reservation);
                Room room = cboRooms.SelectedItem as Room;
                reservation.Room     = room;
                reservation.RoomName = room.RoomName;

                room.Reservations.Add(reservation);
                foreach (var item in availablecustomers)
                {
                    item.CustomerName = item.CustomerName + "(" + room.RoomName + ")";
                }
                if (reservation.Customers.Count() > room.Capacity)
                {
                    MessageBox.Show($"{room.RoomName} capacity cannot be exceeded");
                    return;
                }
            }
            var availableRooms = db.Rooms.Where(x => x.Reservations.All(r => r.CheckOutDate <= dtpCheckInDate.Value || r.CheckInDate >= dtpCheckOutDate.Value)).ToList();

            DateTime dateTimeNow = DateTime.Now;

            if (cbOpenEditCheckIn.Checked == true)
            {
                if (DateTime.Compare(dateTimeNow, dtpCheckInDate.Value) > 0 || DateTime.Compare(dateTimeNow, dtpCheckOutDate.Value) > 0)
                {
                    MessageBox.Show("CheckIn Date or CheckOut Date must be to the future");
                    return;
                }
                if (DateTime.Compare(dtpCheckInDate.Value, dtpCheckOutDate.Value) == 0)
                {
                    MessageBox.Show("CheckIn Date and Check Out date cannot be equal");
                    return;
                }
                if (DateTime.Compare(dtpCheckInDate.Value, dtpCheckOutDate.Value) > 0)
                {
                    MessageBox.Show("CheckIn Date must be earlier then Check Out Date ");
                    return;
                }
                if (availableRooms.Contains(reservation.Room))
                {
                    reservation.CheckInDate  = dtpCheckInDate.Value;
                    reservation.CheckOutDate = dtpCheckOutDate.Value;
                }
            }

            if (cbCheckedIn.Checked == true)
            {
                if (DateTime.Compare(dateTimeNow, dtpCheckedInTime.Value) > 0)
                {
                    MessageBox.Show("CheckIn Date or CheckOut Date must be to the future or now");
                    return;
                }
                if (cbCheckedOut.Checked == true && DateTime.Compare(dtpCheckedInTime.Value, dtpCheckedOutTime.Value) == 0)
                {
                    MessageBox.Show("CheckIn Date and Check Out date cannot be equal");
                    return;
                }
                if (cbCheckedOut.Checked == true && DateTime.Compare(dtpCheckedInTime.Value, dtpCheckedOutTime.Value) > 0)
                {
                    MessageBox.Show("CheckIn Date must be earlier then Check Out Date ");
                    return;
                }
                reservation.CheckedInDate = dtpCheckedInTime.Value;
            }
            if (cbCheckedOut.Checked == true)
            {
                if (DateTime.Compare(dateTimeNow, dtpCheckedOutTime.Value) > 0)
                {
                    MessageBox.Show("CheckOut Date must be to the future or now");
                    return;
                }
                reservation.CheckedOutDate = dtpCheckedOutTime.Value;
            }
            if (lstServices.SelectedIndex >= 0)
            {
                Service       service       = lstServices.SelectedItem as Service;
                ServiceDetail serviceDetail = new ServiceDetail()
                {
                    ReservationId = reservation.Id,
                    ServiceId     = service.Id,
                    ServiceName   = service.ServiceName,
                    UnitPrice     = service.UnitPrice,
                };
                serviceDetail.Quantity    = (int)nudServiceQuantity.Value;
                serviceDetail.Reservation = reservation;
                reservation.ServiceDetails.Add(serviceDetail);
                decimal roomPrice = reservation.Room.Price;

                TimeSpan rentDate          = reservation.CheckOutDate.Value.Date - reservation.CheckInDate.Value.Date;
                decimal  totalRoomPrice    = decimal.Parse(rentDate.Days.ToString());
                decimal  totalServicePrice = 0;
                foreach (var item in reservation.ServiceDetails)
                {
                    totalServicePrice += item.TotalAmount;
                }
                totalServicePrice  += totalRoomPrice;
                lblTotalAmount.Text = "Services and Room Price:" + totalServicePrice + " $";
                db.ServiceDetails.Add(serviceDetail);
            }
            db.SaveChanges();
            WhenAnReservationIsEdit(EventArgs.Empty);
            dgvReservationInfo.DataSource         = db.Reservations.Where(x => x.Id == reservation.Id).ToList();
            lstReservationsOldServices.DataSource = reservation.ServiceDetails.Select(x => x.ServiceAndQuantity).ToList();
            cboRooms.SelectedIndex = -1;
        }
예제 #18
0
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            if (txtCustomerName.Text == "")
            {
                MessageBox.Show("Plase type Customer name");
                return;
            }
            if (txtPhoneNumber.Text != "")
            {
                if (txtPhoneNumber.Text.Length > 15)
                {
                    MessageBox.Show("Phone Number max length must be 15");
                    return;
                }
            }
            if (txtIdentityNumber.Text != "")
            {
                if (txtIdentityNumber.Text.Length > 11)
                {
                    MessageBox.Show("Identity Number  max length must be 11");
                    return;
                }
            }
            Customer customer = new Customer();

            customer.CustomerName   = txtCustomerName.Text.Trim();
            customer.PhoneNumber    = txtPhoneNumber.Text.Trim();
            customer.IdentityNumber = txtIdentityNumber.Text.Trim();
            customer.Description    = txtDescription.Text.Trim();
            if (rbMale.Checked == true)
            {
                customer.Gender = GenderResult.Erkek;
            }
            else if (rbFemale.Checked == true)
            {
                customer.Gender = GenderResult.Kadın;
            }
            DateTime dateTimeNow = DateTime.Now;

            if (DateTime.Compare(dateTimeNow, dtpBirthDate.Value) <= 0)
            {
                MessageBox.Show("Customer birth date cannot be entered beyond the current time");
                return;
            }
            else
            {
                customer.BirthDate = dtpBirthDate.Value;
            }
            if (db.Customers.Select(x => x.IdentityNumber).Contains(customer.IdentityNumber))
            {
                DialogResult dr = MessageBox.Show("Allready have customer for this Customer Identity are you want to create new Customer ? ", "İnfo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dr == DialogResult.Yes)
                {
                    txtCustomerName.Text               = "";
                    txtIdentityNumber.Text             = "";
                    txtPhoneNumber.Text                = "";
                    dtpBirthDate.Value                 = dateTimeNow;
                    rbMale.Checked                     = false;
                    rbFemale.Checked                   = false;
                    lstAvailableCustomer.SelectedIndex = -1;
                    txtCustomerName.Focus();
                    return;
                }
                else
                {
                    return;
                }
            }
            db.Customers.Add(customer);
            db.SaveChanges();
            ListCustomer();
            lstAvailableCustomer.SelectedIndex = lstAvailableCustomer.Items.Count - 1;
        }