Пример #1
0
        public FacilityBookingConfirmed(FacilityBookingRequest fbr, 
            FacilityBookingRequestDetails fbrd, string remarks, string purpose)
        {
            this.eventID = fbr.EventID;
            this.requestid = fbr.RequestID;
            this.RequestorID = fbr.RequestorID;

            this.Faculty = fbrd.Faculty;
            this.facilityID = fbrd.FacilityID;

            this.requestDetailID = fbrd.RequestDetailsID;

            this.requestStartDateTime = fbr.RequestStartDateTime;
            this.requestEndDateTime = fbr.RequestEndDateTime;

            this.remarks = remarks;
            this.purpose = purpose;
        }
        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;
        }