예제 #1
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;
                    }
                }
            }
        }
        /// <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;
            }
        }