private void btnDrop_Click(object sender, RoutedEventArgs e)
        {
            if (lstRequest.SelectedIndex == -1)
            {
                MessageBox.Show("Please Select a request!", "Invalid input",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            else
            {
                FacilityBookingRequest fbr = (FacilityBookingRequest)lstRequest.SelectedItem;
                FacilityBookingsHelper client = new FacilityBookingsHelper();
                if (fbr.Status == BookingStatus.Approved)
                {
                    if (MessageBox.Show("Are you sure you want to drop this confirmed booking?, It Cannot be undone!",
                        "Confirm Drop Request", MessageBoxButton.YesNo, MessageBoxImage.Question)
                        == MessageBoxResult.Yes)
                    {
                        string remarks = Microsoft.VisualBasic.Interaction.InputBox("Please Enter Remarks for dropping", "Remarks", "");
                        client.DropConfirmedRequest(user, fbr.RequestID, fbr.EventID, remarks);
                        ClearDetail();
                    }
                }
                else if (fbr.Status == BookingStatus.Pending)
                {
                    if (MessageBox.Show("Are you sure you want to cancel this pending booking?, It Cannot be undone!",
                        "Confirm Cancel Request", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        string remarks = Microsoft.VisualBasic.Interaction.InputBox("Please Enter Remarks for cancelling", "Remarks", "");
                        try
                        {
                            client.CancelFacilityBooking(user, fbr.RequestID, fbr.EventID, remarks);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Cancel Booking!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                        ClearDetail();
                        retreiveBookingInformation();
                    }
                }
                client.Close();

            }
        }
        private void btnApprove_Click(object sender, RoutedEventArgs e)
        {
            if (this.dgLocation.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a booking request", "No request selected",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (!lvTimeslot.CanApproved())
            {
                MessageBox.Show("There is a clash for this timeslot", "Timeslot Clash",
                   MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            FacilityBookingsHelper client = new FacilityBookingsHelper();
            FacilityBookingRequest fbr = (FacilityBookingRequest)lstRequestor.SelectedItem;

            try
            {
                FacilityBookingRequestDetails fbrd = (FacilityBookingRequestDetails)dgLocation.SelectedItem;
                client.ApproveFacilityBooking(user, fbr.RequestID, fbr.EventID, fbrd.RequestDetailsID,
                    txtRemarks.Text.Trim(), txtEventName.Text.Trim());
                MessageBox.Show("Request have been approved!", "Approved",
                    MessageBoxButton.OK, MessageBoxImage.Information);
                loadRequests();
                dgLocation.ItemsSource = null;
                lvTimeslot.Reset();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error have occured with the following message: " + ex.Message,
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                client.Close();
            }
        }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (dtpStart.SelectedDateTime == default(DateTime))
            {
                MessageBox.Show("Please select the Dates", "Validation Error",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            DateTime start = dtpStart.SelectedDateTime;
            DateTime end = getEndDateTime();

            FacilityBookingsHelper client = new FacilityBookingsHelper();
            bool exist = client.CheckRequestExist(event_.EventID, start ,end);
            client.Close();

            if (exist)
            {
                Mouse.OverrideCursor = Cursors.Arrow;
                MessageBox.Show("The event already have a pending or confirmed request at the selected time frame!",
                    "Request already Exist", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            try
            {
                bool success = saveRequest(start, end);
                if (success)
                    this.Close();
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = Cursors.Arrow;
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 4
0
        public void loadFacilityBookings(EventDay day)
        {
            FacilityBookingsHelper client = new FacilityBookingsHelper();
            List<FacilityBookingConfirmed> fbc = client.GetConfirmedFacBookings(day.EventID,
                day.StartDateTime.Date).ToList<FacilityBookingConfirmed>();

            if (fbc.Count == 0)
            {
                txtLocationMsg.Text = "The venue to hold the event is not confirmed yet";
            }
            else
            {
                txtLocationMsg.Text = "The venue to hold this event are (is) " + Environment.NewLine;
                foreach (FacilityBookingConfirmed confirmedReq in fbc)
                {
                    txtLocationMsg.Text += confirmedReq.Faculty.ToString().Replace('_', ' ') + " " + " at " + confirmedReq.Venue
                        + "  booked from " + confirmedReq.RequestStartDateTime.ToString("HH:mm")
                        + " to " + confirmedReq.RequestEndDateTime.ToString("HH:mm") + Environment.NewLine
                        ;

                }
            }
            client.Close();
        }
        private void btnReject_Click(object sender, RoutedEventArgs e)
        {
            if (lstRequestor.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a booking request", "No request selected",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            FacilityBookingsHelper client = new FacilityBookingsHelper();
            FacilityBookingRequest fbr = (FacilityBookingRequest)lstRequestor.SelectedItem;

            try
            {
                client.RejectFacilityBooking(user, fbr.RequestID, fbr.EventID, txtRemarks.Text.Trim());
                MessageBox.Show("Request have been rejected!", "Rejected",
                    MessageBoxButton.OK, MessageBoxImage.Information);
                loadRequests();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error have occured with the following message: " + ex.Message,
                   "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                client.Close();
            }
        }
 private void loadRequests()
 {
     FacilityBookingsHelper client = new FacilityBookingsHelper();
     lstRequestor.ItemsSource = client.GetFacBookingRequestList(user);
     client.Close();
     txtEventName.Text = "";
     txtRemarks.Text = "";
     txtRequestor.Text = "";
 }
        private void dgLocation_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dgLocation.SelectedIndex == -1)
            {
                return;
            }

            FacilityBookingRequest fbr = (FacilityBookingRequest)lstRequestor.SelectedItem;
            FacilityBookingRequestDetails fbrDetails = (FacilityBookingRequestDetails)dgLocation.SelectedItem;
            DateTime day = fbr.RequestStartDateTime;
            day = day.AddHours(-day.Hour).AddMinutes(-day.Minute);

            List<FacilityBookingConfirmed> fbcList;
            FacilityBookingsHelper client = new FacilityBookingsHelper();
            try
            {
                fbcList = client.GetActivitiesForDay(user, day,
                     fbrDetails.Faculty, fbrDetails.FacilityID).ToList<FacilityBookingConfirmed>();
                lvTimeslot.SetBookingTimeRange(fbr.RequestStartDateTime, fbr.RequestEndDateTime);
                lvTimeslot.SetSource(fbcList);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occured: " + ex.Message, "Error",
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                client.Close();
            }
        }
        private bool saveRequest(DateTime start, DateTime end)
        {
            //Use threading to stop system from "Hanging" as it may take a long time to save
            //as a list of objects are sent over via SOAP
            bool success = false;
            System.Threading.Thread thread = new System.Threading.Thread(
                new System.Threading.ThreadStart(
                delegate()
                {
                    System.Windows.Threading.DispatcherOperation
                    dispatcherOp = this.Dispatcher.BeginInvoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(delegate()
                    {
                        try
                        {
                            Mouse.OverrideCursor = Cursors.Wait;
                            MessageBox.Show("Please wait while we process your request...");

                            List<int> priorityList = new List<int>();

                            //To grab cbo selected value in datagrid
                            List<FacilityBookingRequestDetails> list = new List<FacilityBookingRequestDetails>();
                            for (int i = 0; i < dgFacility.Items.Count; i++)
                            {
                                Facility f = (Facility)dgFacility.Items[i];
                                DataGridRow row = dgFacility.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
                                ComboBox cbo = dgFacility.Columns[0].GetCellContent(row) as ComboBox;

                                if (cbo.SelectedIndex == -1)
                                {
                                    MessageBox.Show("Please select the priority in all your selected venues!",
                                        "Invalid Input!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                    return;
                                }

                                if (priorityList.Contains(cbo.SelectedIndex + 1))
                                {
                                    MessageBox.Show("You have facilities with the same priority!",
                                        "1 priority per facility", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                    return;
                                }

                                FacilityBookingRequestDetails fbreqDetails = new FacilityBookingRequestDetails();
                                fbreqDetails.EventID = event_.EventID;
                                fbreqDetails.FacilityID = f.FacilityID;
                                fbreqDetails.Faculty = f.Faculty;
                                fbreqDetails.Priority = cbo.SelectedIndex + 1;
                                priorityList.Add(cbo.SelectedIndex + 1);

                                list.Add(fbreqDetails);
                            }

                            FacilityBookingsHelper client = new FacilityBookingsHelper();
                            success = client.AddFacilityBookingRequest(user, eventDay_, list[0].Faculty, start, end, list.ToArray());
                            client.Close();

                            if (success)
                            {
                                MessageBox.Show("Your request for the facilities booking is submitted,"
                                    + "please wait for an administrator to respond to your request",
                                    "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);

                        }
                    }
                ));

                    //dispatcherOp.Completed += new EventHandler(dispatcherOp_Completed);
                    dispatcherOp.Completed += (s, e) =>
                    {
                        if (success)
                        {
                            Mouse.OverrideCursor = Cursors.Arrow;
                            this.Close();
                        }
                    };

                }
            ));

            thread.Start();
            return success;
        }
        private void retreiveBookingInformation()
        {
            FacilityBookingsHelper client = new FacilityBookingsHelper();

            if (cboEventList.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a event!", "Invalid input",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (chkAllStatus.IsChecked.Value == false && cboStatus.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a status!", "Invalid input",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (chkAllEventDay.IsChecked.Value == false && cboEventDay.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a day!", "Invalid input",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            EventDay evDay = (EventDay)cboEventDay.SelectedItem;
            try
            {
                this.lstRequest.ItemsSource = client.ViewFacilityBookingRequestsByEventDay(user, int.Parse(cboEventList.SelectedValue.ToString()), (BookingStatus)cboStatus.SelectedIndex,
                 chkAllStatus.IsChecked.Value, chkAllEventDay.IsChecked.Value, evDay.StartDateTime);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }
        }
        private void loadEvents()
        {
            List<Events> elist;
            if (user.isFacilityAdmin || user.isSystemAdmin)
            {
                EventHelper client = new EventHelper();
                elist = client.ViewAllEvents(user).ToList<Events>();
                client.Close();
            }
            else
            {
                FacilityBookingsHelper client = new FacilityBookingsHelper();
                elist = client.ViewAuthorizedEventsForFacBookings(user).ToList<Events>();
                client.Close();
            }

            this.cboEventList.ItemsSource = elist;

            cboEventList.SelectedValuePath = "EventID";
            cboEventList.DisplayMemberPath = "Name";
            cboEventList.SelectedIndex = 0;
        }