/// <summary>
        ///  Deletes the selected row
        /// </summary>
        protected void DeleteHolidayBtn_Click(object sender, EventArgs e)
        {
            try
            {
                long     locationID;
                DateTime holidayStart;

                //Find the ID of the button clicked
                Button deleteBtn = (Button)sender;

                //Only gets numbers at the start of the button ID
                locationID   = Convert.ToInt32(deleteBtn.ID.Split('_')[0]);
                holidayStart = Convert.ToDateTime(deleteBtn.ID.Split('_')[1]);

                OpeningTime.DeleteHolidayOpeningTime(locationID, holidayStart);

                //Refresh the page without deleted record
                RefreshPage("LocationID=" + locationID.ToString());

                Session["InputFailed"]   = "";
                Session["HolidayStatus"] = "Holiday time deleted";
            }
            catch (Exception ex)
            {
                Session["GeneralError"] = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
Example #2
0
        /// <summary>
        /// Returns true if SharedAutomatedTellerMachinesAvailabilityStandards instances are equal
        /// </summary>
        /// <param name="other">Instance of SharedAutomatedTellerMachinesAvailabilityStandards to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(SharedAutomatedTellerMachinesAvailabilityStandards other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Weekday == other.Weekday ||
                     Weekday != null &&
                     Weekday.Equals(other.Weekday)
                     ) &&
                 (
                     OpeningTime == other.OpeningTime ||
                     OpeningTime != null &&
                     OpeningTime.Equals(other.OpeningTime)
                 ) &&
                 (
                     ClosingTime == other.ClosingTime ||
                     ClosingTime != null &&
                     ClosingTime.Equals(other.ClosingTime)
                 ));
        }
Example #3
0
        public static OpeningTime ReadAsOpeningTime(this JsonReader reader)
        {
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new JsonException();
            }

            var openingTimes = new OpeningTime();

            while (reader.TokenType != JsonToken.EndObject)
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    switch (reader.Value)
                    {
                    case "text":
                        openingTimes.Text = reader.ReadAsString();
                        break;

                    case "start":
                        openingTimes.Start = reader.ReadAsString();
                        break;

                    case "end":
                        openingTimes.End = reader.ReadAsString();
                        break;
                    }
                }

                reader.Read();
            }

            return(openingTimes);
        }
Example #4
0
        /// <summary>
        ///  Loads the locations, opening times and holidays opening times for use in javascript.
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                generalErrorLbl.Text = "";

                locations           = LocationManager.GetLocations().Where(x => x.Active == true).ToList();
                openingTimes        = OpeningTime.GetOpeningTimes();
                holidayOpeningTimes = OpeningTime.GetHolidayOpeningTimes();

                foreach (LocationManager location in locations)
                {
                    TableRow row = new TableRow();

                    TableCell cell = new TableCell();
                    cell.Text = "Phone No:";
                    row.Cells.Add(cell);

                    cell      = new TableCell();
                    cell.Text = location.PhoneNo;
                    row.Cells.Add(cell);

                    LocationsTbl.Rows.Add(row);
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
Example #5
0
 public IActionResult Post([FromBody] OpeningTime Time)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     repository.SaveTime(Time);
     return(CreatedAtAction(nameof(Get),
                            new { id = Time.ID }, Time));
 }
        public void EditTime(OpeningTime time, int id)
        {
            var exists = context.Times.Find(id);

            if (exists != null)
            {
                context.Update(time);
            }
            context.SaveChanges();
        }
        public OpeningTime DeleteTime(int ID)
        {
            OpeningTime DbEntry = context.Times
                                  .FirstOrDefault(t => t.ID == ID);

            if (DbEntry != null)
            {
                context.Times.Remove(DbEntry);
                context.SaveChanges();
            }
            return(DbEntry);
        }
        private List <DateTime> CheckDatesAndTimes()
        {
            DateTime        hireStartDate, hireEndDate, startTime, endTime, hireStartDateTime, hireEndDateTime;
            bool            validDates;
            List <DateTime> dates = new List <DateTime>();

            validDates = DateTime.TryParseExact(hireStartDateTxt.Text, "dd/MM/yyyy",
                                                CultureInfo.InvariantCulture,
                                                DateTimeStyles.None,
                                                out hireStartDate);

            validDates = DateTime.TryParseExact(hireEndDateTxt.Text, "dd/MM/yyyy",
                                                CultureInfo.InvariantCulture,
                                                DateTimeStyles.None,
                                                out hireEndDate);

            if (OpeningTime.CheckTimeValid(hireStartTimeTxt.Text) == true)
            {
                startTime = Convert.ToDateTime(hireStartTimeTxt.Text);
            }
            else
            {
                startTime          = DateTime.Now;
                validDates         = false;
                inputErrorLbl.Text = inputErrorLbl.Text + "Invalid start date entered <br />";
            }

            if (OpeningTime.CheckTimeValid(hireEndTimeTxt.Text) == true)
            {
                endTime = Convert.ToDateTime(hireEndTimeTxt.Text);
            }
            else
            {
                endTime            = DateTime.Now;
                validDates         = false;
                inputErrorLbl.Text = inputErrorLbl.Text + "Invalid end date entered <br />";
            }

            hireStartDateTime = hireStartDate.Date + startTime.TimeOfDay;
            hireEndDateTime   = hireEndDate.Date + endTime.TimeOfDay;

            //Check minimum amount of hours is 12 to continue
            if ((hireEndDateTime - hireStartDateTime).TotalHours <= 12)
            {
                validDates         = false;
                inputErrorLbl.Text = inputErrorLbl.Text + "End date must be after start date <br />";
            }

            dates.Add(hireStartDateTime);
            dates.Add(hireEndDateTime);
            return(dates);
        }
Example #9
0
        public WaitTimesViewModel GetWaitTimes(string parkInitials, Park park)
        {
            var rawTimes = GetCachedWaitTimes(parkInitials);
            var rawHours = GetCachedOpeningTimes(parkInitials);

            if (string.IsNullOrEmpty(rawTimes))
            {
                return(null);
            }
            List <Ride>        rides = JsonConvert.DeserializeObject <List <Ride> >(rawTimes);
            List <OpeningTime> times = JsonConvert.DeserializeObject <List <OpeningTime> >(rawHours);
            var outRides             =
                from r in rides
                orderby r.waitTime
                orderby r.active descending
                select new RideViewModel {
                name         = ReplaceEntities(r.name)
                , active     = r.active
                , location   = ReplaceEntities(r.meta.area)
                , status     = r.status
                , waitTime   = r.waitTime
                , lastUpdate = r.lastUpdate.ToLocalTime().AddHours(1).ToShortTimeString()
                , color      = r.active ? r.waitTime < 30 ? "green" : r.waitTime < 60 ? "orange" : "red" : "black"
            };
            var xx   = times.Where(x => x.date == DateTime.Now.Date).ToList();
            var time = new OpeningTime();

            if (xx.Count > 0)
            {
                time = xx.First();
            }

            WaitTimesViewModel waitTimesViewModel = new WaitTimesViewModel()
            {
                Rides                 = outRides
                , ParkName            = park.ToString()
                , ParkBackgroundClass = $"{parkInitials}_park"
                , ParkHours           = $"{time.openingTime.AddHours(1).ToShortTimeString()} - {time.closingTime.AddHours(1).ToShortTimeString()}"
                , MKActive            = park == Park.MagicKingdom ? "active-park" : ""
                , AKActive            = park == Park.AnimalKingdom ? "active-park" : ""
                , EPActive            = park == Park.Epcot ? "active-park" : ""
                , HSActive            = park == Park.HollywoodStudios ? "active-park" : ""
            };

            return(waitTimesViewModel);
        }
Example #10
0
        public IActionResult Put(int id, [FromBody] OpeningTime Time)
        {
            Debug.WriteLine(Time.Day);
            Debug.WriteLine(Time.TimeOpen);
            Debug.WriteLine(Time.TimeClose);
            Debug.WriteLine(id);
            Console.Write(id);
            if (Time == null)
            {
                return(BadRequest());
            }
            var time = repository.Times.SingleOrDefault(x => x.ID == id);

            if (time == null)
            {
                return(NotFound());
            }
            repository.EditTime(Time, id);
            return(Ok(Time));
        }
Example #11
0
        /// <summary>
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                generalErrorLbl.Text = "";

                //Load the locations and their opening times for using in the javascript
                locations           = LocationManager.GetLocations().Where(x => x.Active == true).ToList();
                openingTimes        = OpeningTime.GetOpeningTimes();
                holidayOpeningTimes = OpeningTime.GetHolidayOpeningTimes();

                if (!IsPostBack)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "CallhideMap", "hideMap()", true);
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
Example #12
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Weekday != null)
         {
             hashCode = hashCode * 59 + Weekday.GetHashCode();
         }
         if (OpeningTime != null)
         {
             hashCode = hashCode * 59 + OpeningTime.GetHashCode();
         }
         if (ClosingTime != null)
         {
             hashCode = hashCode * 59 + ClosingTime.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <summary>
        ///  Adds a new holiday opening time record to the selected location
        /// </summary>
        protected void HolidayTimeAddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                TextBox  holidayStartTxt;
                TextBox  altOpeningTimeTxt;
                TextBox  altClosingTimeTxt;
                CheckBox closedChk;
                DateTime?openTimeChk = null, closeTimeChk = null;
                DateTime openTime = DateTime.Now, closeTime = DateTime.Now;
                DateTime holidayStartDate;
                bool     validDates = true;

                holidayStartTxt   = (TextBox)holidayOpeningTimesTbl.FindControl("HolidayStartAdd");
                altOpeningTimeTxt = (TextBox)holidayOpeningTimesTbl.FindControl("altOpenTimeAdd");
                altClosingTimeTxt = (TextBox)holidayOpeningTimesTbl.FindControl("altCloseTimeAdd");
                closedChk         = (CheckBox)holidayOpeningTimesTbl.FindControl("ClosedAdd");

                //Checks the start date is in a dd/mm/yyyy format
                validDates = DateTime.TryParseExact(holidayStartTxt.Text, "dd/MM/yyyy",
                                                    CultureInfo.InvariantCulture,
                                                    DateTimeStyles.None,
                                                    out holidayStartDate);

                if (closedChk.Checked == false)
                {
                    if (OpeningTime.CheckTimeValid(altOpeningTimeTxt.Text) == true)
                    {
                        openTime    = Convert.ToDateTime(altOpeningTimeTxt.Text);
                        openTimeChk = openTime;
                    }
                    else if (altOpeningTimeTxt.Text == "")
                    {
                        openTimeChk = null;
                    }
                    else
                    {
                        validDates             = false;
                        Session["InputFailed"] = Session["InputFailed"] + "Invalid opening date entered <br />";
                    }

                    if (OpeningTime.CheckTimeValid(altClosingTimeTxt.Text) == true)
                    {
                        closeTime    = Convert.ToDateTime(altClosingTimeTxt.Text);
                        closeTimeChk = closeTime;
                    }
                    else if (altClosingTimeTxt.Text == "")
                    {
                        closeTimeChk = null;
                    }
                    else
                    {
                        validDates             = false;
                        Session["InputFailed"] = Session["InputFailed"] + "Invalid closing date entered <br />";
                    }

                    if (openTimeChk > closeTimeChk)
                    {
                        validDates             = false;
                        Session["InputFailed"] = Session["InputFailed"] + "End time must be after start time <br />";
                    }
                }

                if (validDates == true)
                {
                    Session["HolidayStatus"] = "Holiday time saved";
                    Session["InputFailed"]   = "";

                    if (closeTimeChk != null && openTimeChk != null)
                    {
                        OpeningTime.InsertHolidayOpeningTimes(Convert.ToInt32(Request.QueryString["LocationID"]), holidayStartDate, openTimeChk,
                                                              closeTimeChk, closedChk.Checked);
                    }
                    //No times entered so closed selected
                    else
                    {
                        OpeningTime.InsertHolidayOpeningTimes(Convert.ToInt32(Request.QueryString["LocationID"]), holidayStartDate, openTimeChk,
                                                              closeTimeChk, true);
                    }
                }
                else
                {
                    //Session["InputFailed"] = "Time or date entered was not in the correct format. Please try again.";
                    Session["HolidayStatus"] = "";
                }

                //Reload dates to include new holiday that has just been added
                RefreshPage("LocationID=" + Request.QueryString["LocationID"]);
            }
            catch (Exception ex)
            {
                Session["GeneralError"] = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
Example #14
0
        /// <summary>
        ///  Loads the opening times for this location.
        ///  If closed is set to true then no times will be displayed.
        /// </summary>
        private void LoadOpeningTimes()
        {
            List <OpeningTime> openingTimes, holidayOpeningTimes;
            long     locationID = 0;
            TextBox  openTimeTxt, closeTimeTxt;
            CheckBox timeSelectChk;

            if (locationDdl.SelectedValue != "")
            {
                locationID = Convert.ToInt32(Regex.Match(locationDdl.SelectedValue, @"\d+").Value);
                openingTimesTbl.Visible = true;
                updateTimesBtn.Visible  = true;
            }
            else
            {
                openingTimesTbl.Visible = false;
                updateTimesBtn.Visible  = false;
            }

            openingTimes        = OpeningTime.GetOpeningTimesByLocationID(locationID);
            holidayOpeningTimes = OpeningTime.GetHolidayOpeningTimesByLocationID(locationID);

            foreach (OpeningTime holidayOpeningTime in holidayOpeningTimes)
            {
                TableRow  row  = new TableRow();
                TableCell cell = new TableCell();
                cell.Text = holidayOpeningTime.HolidayStartDateStr;
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = holidayOpeningTime.HolidayEndDateStr;
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = holidayOpeningTime.OpenTimeStr;
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = holidayOpeningTime.CloseTimeStr;
                row.Cells.Add(cell);

                cell      = new TableCell();
                cell.Text = holidayOpeningTime.DayOfWeek;
                row.Cells.Add(cell);
                //holidayOpeningTimesTbl.Rows.Add(row);

                cell = new TableCell();
                if (holidayOpeningTime.Closed == true)
                {
                    cell.Text = "Closed";
                }
                else
                {
                    cell.Text = "Open";
                }
                row.Cells.Add(cell);
            }

            for (int i = 1; i <= 7; i++)
            {
                openTimeTxt   = (TextBox)openingTimesTbl.FindControl(i + "_open");
                closeTimeTxt  = (TextBox)openingTimesTbl.FindControl(i + "_close");
                timeSelectChk = (CheckBox)openingTimesTbl.FindControl(i + "_Chk");

                //Reset to default values if drop down changed
                openTimeTxt.Text      = "";
                closeTimeTxt.Text     = "";
                timeSelectChk.Checked = true;
            }

            if (openingTimes.Count > 0)
            {
                foreach (OpeningTime openingTime in openingTimes)
                {
                    //WHEN FINDING CONTROL ":" CANNOT BE USED OTHERWISE IT WON'T FIND IT
                    openTimeTxt   = (TextBox)openingTimesTbl.FindControl(openingTime.DayOfWeekNum + "_open");
                    closeTimeTxt  = (TextBox)openingTimesTbl.FindControl(openingTime.DayOfWeekNum + "_close");
                    timeSelectChk = (CheckBox)openingTimesTbl.FindControl(openingTime.DayOfWeekNum + "_Chk");

                    if (openingTime.Closed == false)
                    {
                        if (openingTime.OpenTimeStr != "00:00")
                        {
                            openTimeTxt.Text = openingTime.OpenTime.ToString("hh:mm tt");
                        }

                        if (openingTime.CloseTimeStr != "00:00")
                        {
                            closeTimeTxt.Text = openingTime.CloseTime.ToString("hh:mm tt");
                        }

                        timeSelectChk.Checked = false;
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        ///  Updates the database with all the times currently in the table for the selected location.
        /// </summary>
        protected void AddUpdateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                List <OpeningTime> openingTimes;
                long     locationID;
                TextBox  openTimeTxt, closeTimeTxt;
                CheckBox closedChk;
                DateTime?openTimeChk = null, closeTimeChk = null;
                DateTime openTime = DateTime.Now, closeTime = DateTime.Now;
                bool     validDates = true;

                openingTimesTbl.Visible = true;

                locationID = Convert.ToInt32(Regex.Match(locationDdl.SelectedValue, @"\d+").Value);

                openingTimes = OpeningTime.GetOpeningTimesByLocationID(locationID);

                foreach (OpeningTime openingTime in openingTimes)
                {
                    openTimeTxt  = (TextBox)openingTimesTbl.FindControl(openingTime.DayOfWeekNum + "_open");
                    closeTimeTxt = (TextBox)openingTimesTbl.FindControl(openingTime.DayOfWeekNum + "_close");
                    closedChk    = (CheckBox)openingTimesTbl.FindControl(openingTime.DayOfWeekNum + "_Chk");

                    validDates = true;
                    if (OpeningTime.CheckTimeValid(openTimeTxt.Text) == true)
                    {
                        openTime    = Convert.ToDateTime(openTimeTxt.Text);
                        openTimeChk = openTime;
                    }
                    else if (openTimeTxt.Text == "")
                    {
                        openTimeChk = null;
                    }
                    else
                    {
                        validDates         = false;
                        inputErrorLbl.Text = inputErrorLbl.Text + "Invalid opening date on " + openingTime.DayOfWeek + "<br />";
                    }

                    if (OpeningTime.CheckTimeValid(closeTimeTxt.Text) == true)
                    {
                        closeTime    = Convert.ToDateTime(closeTimeTxt.Text);
                        closeTimeChk = closeTime;
                    }
                    else if (closeTimeTxt.Text == "")
                    {
                        closeTimeChk = null;
                    }
                    else
                    {
                        validDates         = false;
                        inputErrorLbl.Text = inputErrorLbl.Text + "Invalid closing date on " + openingTime.DayOfWeek + "<br />";
                    }

                    if (openTimeChk > closeTimeChk)
                    {
                        validDates         = false;
                        inputErrorLbl.Text = inputErrorLbl.Text + "End time must be after start time for " + openingTime.DayOfWeek + "<br />";
                    }

                    if (validDates == true)
                    {
                        //Check if date has been updated and set this day to closed
                        if (closeTimeChk != null && openTimeChk != null)
                        {
                            OpeningTime.UpdateOpeningTimes(openingTime.LocationID, openingTime.DayOfWeekNum, openTime, closeTime, false);
                            closedChk.Checked = false;
                            timeSavedLbl.Text = timeSavedLbl.Text + "Save successful for " + openingTime.DayOfWeek + "<br />";
                        }
                        //If only closed date has been entered return error
                        else if (openTimeChk != null)
                        {
                            inputErrorLbl.Text = inputErrorLbl.Text + "Only opening date entered on " + openingTime.DayOfWeek + "<br />";
                        }
                        //If only open date has been entered return error
                        else if (closeTimeChk != null)
                        {
                            inputErrorLbl.Text = inputErrorLbl.Text + "Only closing date entered on " + openingTime.DayOfWeek + "<br />";
                        }
                        else
                        {
                            OpeningTime.UpdateOpeningTimes(openingTime.LocationID, openingTime.DayOfWeekNum, openTime, closeTime, true);
                            timeSavedLbl.Text = timeSavedLbl.Text + "Save successful for " + openingTime.DayOfWeek + "<br />";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }
Example #16
0
 public void UpdateOpeningTime(string bizId, string serviceId, [FromBody] OpeningTime bizTime)
 {
 }
 public void SaveTime(OpeningTime time)
 {
     context.Times.Add(time);
     context.SaveChanges();
 }
        /// <summary>
        ///  Load holiday opening times and dates for location in dropdown box
        /// </summary>
        private void LoadOpeningTimes()
        {
            List <OpeningTime> holidayOpeningTimes;
            long      locationID = 0;
            TableRow  row;
            TableCell cell;
            CheckBox  closedChk;
            Button    deleteBtn;

            //Put text into the status labels if there is a session variable saved
            if (Session["HolidayStatus"] != null)
            {
                timeSavedLbl.Text        = Session["HolidayStatus"].ToString();
                Session["HolidayStatus"] = null;
            }
            else
            {
                timeSavedLbl.Text = "";
            }

            if (Session["GeneralError"] != null)
            {
                generalErrorLbl.Text    = Session["GeneralError"].ToString();
                Session["GeneralError"] = null;
            }
            else
            {
                generalErrorLbl.Text = "";
            }

            if (Session["InputFailed"] != null)
            {
                inputErrorLbl.Text     = Session["InputFailed"].ToString();
                Session["InputFailed"] = null;
            }
            else
            {
                inputErrorLbl.Text = "";
            }


            if (locationDdl.SelectedValue != "")
            {
                //Gets the location id from the dropdown
                locationID = Convert.ToInt32(Regex.Match(locationDdl.SelectedValue, @"\d+").Value);
                holidayOpeningTimesTbl.Visible = true;

                holidayOpeningTimes = OpeningTime.GetHolidayOpeningTimesByLocationID(locationID);

                foreach (OpeningTime holidayOpeningTime in holidayOpeningTimes)
                {
                    //Add current holiday dates to disable in jquery datepicker
                    holidayDates.Add(holidayOpeningTime.HolidayStartDate.ToString("d-M-yyyy"));

                    row       = new TableRow();
                    cell      = new TableCell();
                    cell.ID   = holidayOpeningTime.LocationID + "_" + holidayOpeningTime.HolidayStartDate + "_StartDate";
                    cell.Text = holidayOpeningTime.HolidayStartDate.ToString("dd/MM/yyyy");
                    row.Cells.Add(cell);

                    cell = new TableCell();
                    //If there is a opening time in the database then display on holiday date record
                    if (holidayOpeningTime.Closed == false && holidayOpeningTime.HolidayOpenTime != null)
                    {
                        cell.Text = holidayOpeningTime.HolidayOpenTime.Value.ToString("HH:mm");
                    }
                    row.Cells.Add(cell);

                    cell = new TableCell();
                    //If there is a closing time in the database then display on holiday date record
                    if (holidayOpeningTime.Closed == false && holidayOpeningTime.HolidayCloseTime != null)
                    {
                        cell.Text = holidayOpeningTime.HolidayCloseTime.Value.ToString("HH:mm");
                    }
                    row.Cells.Add(cell);

                    closedChk = new CheckBox();
                    cell      = new TableCell();
                    if (holidayOpeningTime.Closed == true)
                    {
                        closedChk.Checked = true;
                    }
                    else
                    {
                        closedChk.Checked = false;
                    }
                    closedChk.Enabled = false;
                    cell.Controls.Add(closedChk);
                    row.Cells.Add(cell);

                    //Delete button to delete the row the delete button is on
                    deleteBtn          = new Button();
                    deleteBtn.ID       = holidayOpeningTime.LocationID + "_" + holidayOpeningTime.HolidayStartDate.ToString("dd.MM.yyyy") + "_DelBtn";
                    deleteBtn.Text     = "Delete";
                    deleteBtn.CssClass = "btn btn-primary";
                    deleteBtn.Click   += new EventHandler(DeleteHolidayBtn_Click);
                    cell = new TableCell();
                    cell.Controls.Add(deleteBtn);
                    row.Cells.Add(cell);
                    holidayOpeningTimesTbl.Rows.Add(row);
                }
            }
            else
            {
                holidayOpeningTimesTbl.Visible = false;
            }
        }
Example #19
0
        /// <summary>
        /// Checks the location is valid then adds it to the database.
        /// </summary>
        protected void LocationAddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string locationName, ownerName, addressLine1, addressLine2, city, zipOrPostcode,
                       countyStateProvince, countryCode, countryName, phoneNo, emailAddress;
                int    capacity = 0, tryParseNumber, userID = 0;
                double longitude = 0, latitude = 0;
                bool   insertLocation = true; //boolean to check all fields are entered correctly
                long   locationID;

                #region locationCheck

                if (locationNameTxt.Text != "")
                {
                    locationName = locationNameTxt.Text;
                }
                else
                {
                    locationName       = "";
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Please enter a location.";
                }

                if (ownerNameTxt.Text != "")
                {
                    ownerName = ownerNameTxt.Text;
                }
                else
                {
                    ownerName          = "";
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Please enter an owner.";
                }

                if (Int32.TryParse(capacityTxt.Text, out tryParseNumber) == true)
                {
                    capacity = Convert.ToInt32(capacityTxt.Text);
                }
                else
                {
                    capacity = 0;
                }

                addressLine1 = addressLine1Txt.Text;
                addressLine2 = addressLine2Txt.Text;

                if (Variables.CheckAlphaNumericCharacters(cityTxt.Text) && cityTxt.Text != "")
                {
                    city = cityTxt.Text;
                }
                else
                {
                    city               = "";
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Please enter a valid city.";
                }

                if (Variables.CheckAlphaNumericCharacters(zipOrPostcodeTxt.Text) == true && zipOrPostcodeTxt.Text != "")
                {
                    zipOrPostcode = zipOrPostcodeTxt.Text;
                }
                else
                {
                    zipOrPostcode      = "";
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Invalid zip or postcode.";
                }

                countyStateProvince = countyStateProvinceTxt.Text;

                //Get from this box as getting from dropdown when it is disabled returns null value
                countryCode = Request["countryTxtVal"];
                if (countryCode == "")
                {
                    //Otherwise if value is still enabled get value directly from dropdown
                    countryCode = Request["countryTxt"];
                }

                //If nothing on the dropdown is selected
                if (countryCode == "")
                {
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Please enter a country.";
                }

                phoneNo = Request["phoneNoTxt"];
                if (phoneNo == "")
                {
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Please enter a phone no.";
                }

                if (emailAddressTxt.Text != "")
                {
                    emailAddress = emailAddressTxt.Text;
                }
                else
                {
                    emailAddress       = "";
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Please enter a email address.";
                }

                if (LocationManager.CheckLongitudeOrLatitudeValid(longitudeTxt.Text))
                {
                    longitude = Convert.ToDouble(longitudeTxt.Text);
                }
                else
                {
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Invalid longitude.";
                }
                if (LocationManager.CheckLongitudeOrLatitudeValid(latitudeTxt.Text))
                {
                    latitude = Convert.ToDouble(latitudeTxt.Text);
                }
                else
                {
                    insertLocation     = false;
                    inputErrorLbl.Text = inputErrorLbl.Text + "<br />" + "Invalid latitude.";
                }

                userID = Variables.GetUser(Session["UserID"].ToString());
                if (userID == 0)
                {
                    insertLocation     = false;
                    inputErrorLbl.Text = "Not logged in. Please login to continue";
                }

                #endregion

                if (insertLocation == true)
                {
                    countryName = Variables.GetCountryByCode(countryCode);
                    LocationManager.AddNewLocation(locationName, ownerName, capacity, addressLine1, addressLine2,
                                                   city, zipOrPostcode, countyStateProvince, countryName, phoneNo, emailAddress, longitude, latitude,
                                                   userID, (int)UserAccess.UserType.company);
                    locationSavedLbl.Text = "Save successful";

                    locationID = LocationManager.GetLastAddedLocation();
                    OpeningTime.InsertDefaultOpeningTimes(locationID);

                    //Proceed on to opening times page
                    Response.Redirect("AddOpeningTime.aspx?LocationID=" + locationID, false);
                }
            }
            catch (Exception ex)
            {
                generalErrorLbl.Text = "An error has occured saying: " + ex.Message + " Please contact your system administrator.";
            }
        }