Example #1
0
        protected List <tour> fetchTours()
        {
            List <tour>   availableTours = new List <tour>();
            SqlConnection conn           = null;
            SqlCommand    cmd            = null;
            SqlDataReader reader         = null;

            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString());

            conn.Open();

            string query = "SELECT * FROM tours WHERE startDate >= GETDATE();";

            cmd    = new SqlCommand(query, conn);
            reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                tour temp = new tour(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetInt32(3), reader.GetString(4), reader.GetString(5), reader.GetDateTime(6), reader.GetDateTime(7), (double)Decimal.Round(reader.GetDecimal(8), 2),
                                     reader.GetString(9));
                availableTours.Add(temp);
            }
            reader.Close();
            conn.Close();
            return(availableTours);
        }
Example #2
0
        protected tour fetchTourObject(int tourID)
        {
            SqlConnection conn   = null;
            SqlCommand    cmd    = null;
            SqlDataReader reader = null;

            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString());

            conn.Open();

            string query = "SELECT * FROM tours WHERE tourID='" + tourID + "';";

            cmd    = new SqlCommand(query, conn);
            reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                tour temp = new tour(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetInt32(3), reader.GetString(4), reader.GetString(5), reader.GetDateTime(6), reader.GetDateTime(7), (double)Decimal.Round(reader.GetDecimal(8), 2),
                                     reader.GetString(9));

                reader.Close();
                conn.Close();
                return(temp);
            }
            conn.Close();
            return(null);
        }
Example #3
0
        // Edit Tour
        protected void tourEditingController(object sender, EventArgs e)
        {
            TourErrorHandler tourHandler = new TourErrorHandler();
            string           tempStart   = editStartDate.Text;
            string           tempEnd     = editEndDate.Text;
            double           test;
            int  intTest;
            bool tryDouble = double.TryParse(editPrice.Text, out test);
            bool tryInt    = int.TryParse(editID.Text, out intTest);

            if (editID.Text == "")
            {
                tourHandler.emptyTourID();
            }
            else if (tryInt == false)
            {
                tourHandler.invalidTourID();
            }
            if (editName.Text == "")
            {
                tourHandler.emptyTourName();
            }
            if (editCapacity.Text == "")
            {
                tourHandler.emptyCapacity();
            }
            if (!editCapacity.Text.All(char.IsDigit))
            {
                tourHandler.invalidCapacity();
            }
            if (editLocation.Text == "")
            {
                tourHandler.emptyLocation();
            }
            if (editDescription.Text == "")
            {
                tourHandler.emptyDescription();
            }

            if (editStartDate.Text == "")
            {
                tourHandler.emptyStartDate();
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(tempStart, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
            {
                tourHandler.invalidStartDate();
            }

            if (editEndDate.Text == "")
            {
                tourHandler.emptyEndDate();
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(tempEnd, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
            {
                tourHandler.invalidEndDate();
            }

            if (editPrice.Text == "")
            {
                tourHandler.emptyPrice();
            }
            if (tryDouble == false)
            {
                tourHandler.invalidPrice();
            }



            if (tourHandler.error == "")
            {
                DateTime startDate = DateTime.ParseExact(tempStart, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                DateTime endDate   = DateTime.ParseExact(tempEnd, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

                if (endDate <= startDate)
                {
                    tourHandler.endBeforeStart();
                }

                int  tourID   = int.Parse(editID.Text);
                tour editTour = fetchTourObject(tourID);

                if (editTour == null)
                {
                    tourHandler.noSuchTourName();
                }

                if (tourHandler.error == "")
                {
                    // Tweak Class variables using the mutator
                    editTour.setTourName(editName.Text);
                    editTour.setCapacity(int.Parse(editCapacity.Text));
                    editTour.setLocation(editLocation.Text);
                    editTour.setTourDescription(editDescription.Text);
                    editTour.setStartDate(DateTime.Parse(editStartDate.Text));
                    editTour.setEndDate(DateTime.Parse(editEndDate.Text));
                    editTour.setPrice(double.Parse(editPrice.Text));
                    editTour.setStatus(ddEditStatus.SelectedValue);

                    // Execute class function to modify tour
                    editTour.modifyTour();
                    general_dialog.Visible = false;
                    Session["success"]     = "tourEdited";
                    Response.Redirect("main.aspx");
                }

                else
                {
                    general_dialog.InnerHtml = tourHandler.error;
                    general_dialog.Visible   = true;
                }
            }

            else
            {
                general_dialog.InnerHtml = tourHandler.error;
                general_dialog.Visible   = true;
            }
        }
Example #4
0
        protected void bookingController(object sender, EventArgs e)
        {
            bookingErrorHandler bookingHandler = new bookingErrorHandler();
            int  intTest;
            bool tryInt = int.TryParse(createBooking.Text, out intTest);

            if (createBooking.Text == "")
            {
                bookingHandler.emptyTourID();
            }
            else if (tryInt == false)
            {
                bookingHandler.invalidTourID();
            }

            if (bookingHandler.error == "")
            {
                int  tourID     = int.Parse(createBooking.Text);
                tour targetTour = fetchTourObject(tourID);

                if (targetTour != null)
                {
                    if (targetTour.getStatus() == "closed")
                    {
                        bookingHandler.tourClosed();
                    }

                    if (targetTour.getStatus() == "suspended")
                    {
                        bookingHandler.tourSuspended();
                    }

                    if (targetTour.getCapacity() < 1)
                    {
                        bookingHandler.fullyBooked();
                    }

                    if (bookingHandler.error == "")
                    {
                        int currCapacity = targetTour.getCapacity() - 1;
                        targetTour.setCapacity(currCapacity);
                        targetTour.modifyTour();
                        booking newBooking = new booking(currUser.getUserID(), tourID);
                        newBooking.createBooking();
                        general_dialog.Visible = false;
                        Response.Redirect("main.aspx");
                    }

                    else
                    {
                        general_dialog.InnerHtml = bookingHandler.error;
                        general_dialog.Visible   = true;
                    }
                }

                else
                {
                    bookingHandler.invalidTourID();
                    general_dialog.InnerHtml = bookingHandler.error;
                    general_dialog.Visible   = true;
                }
            }
            else
            {
                general_dialog.InnerHtml = bookingHandler.error;
                general_dialog.Visible   = true;
            }
        }
Example #5
0
        // Create tour
        protected void tourCreationController(object sender, EventArgs e)
        {
            TourErrorHandler tourHandler = new TourErrorHandler();
            string           tempStart   = createStartDate.Text;
            string           tempEnd     = createEndDate.Text;
            double           test;
            bool             tryDouble = double.TryParse(createPrice.Text, out test);

            if (createTourName.Text == "")
            {
                tourHandler.emptyTourName();
            }
            if (createCapacity.Text == "")
            {
                tourHandler.emptyCapacity();
            }
            if (!createCapacity.Text.All(char.IsDigit))
            {
                tourHandler.invalidCapacity();
            }
            if (createLocation.Text == "")
            {
                tourHandler.emptyLocation();
            }
            if (createDescription.Text == "")
            {
                tourHandler.emptyDescription();
            }

            if (createStartDate.Text == "")
            {
                tourHandler.emptyStartDate();
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(tempStart, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
            {
                tourHandler.invalidStartDate();
            }

            if (createEndDate.Text == "")
            {
                tourHandler.emptyEndDate();
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(tempEnd, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
            {
                tourHandler.invalidEndDate();
            }

            if (createPrice.Text == "")
            {
                tourHandler.emptyPrice();
            }
            if (tryDouble == false)
            {
                tourHandler.invalidPrice();
            }

            if (tourHandler.error == "")
            {
                DateTime startDate = DateTime.ParseExact(tempStart, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                DateTime endDate   = DateTime.ParseExact(tempEnd, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

                if (endDate <= startDate)
                {
                    tourHandler.endBeforeStart();
                }

                if (tourHandler.error == "")
                {
                    tour newTour = new tour(currUser.getUserID(), createTourName.Text, int.Parse(createCapacity.Text), createLocation.Text, createDescription.Text, startDate, endDate, double.Parse(createPrice.Text), ddCreateStatus.SelectedValue);
                    newTour.createTour();
                    general_dialog.Visible = false;
                    Session["success"]     = "tourCreated";
                    Response.Redirect("main.aspx");
                }

                else
                {
                    general_dialog.InnerHtml = tourHandler.error;
                    general_dialog.Visible   = true;
                }
            }

            else
            {
                general_dialog.InnerHtml = tourHandler.error;
                general_dialog.Visible   = true;
            }
        }