Пример #1
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;
            }
        }