private void InitializeDateRanges()
    {
        var dateRanges = DateRangeCalculator.GetValidDateRanges();

        ddlDateRange.Items.Add("- select date range -");
        foreach (var item in dateRanges)
        {
            ddlDateRange.Items.Add(new ListItem(item.Key, item.Value.ToString()));
        }
        ddlDateRange.SelectedIndex = 0;
        CalculateDateRanges(ddlDateRange.SelectedValue);
    }
    private void CalculateDateRanges()
    {
        var range = DateRangeCalculator.Calculate(DateTime.Today, ddlDateRange.SelectedValue);

        if (range != null)
        {
            txtStartDate.Text = range.Begin.ToShortDateString();
            txtEndDate.Text   = range.End.ToShortDateString();
            return;
        }

        txtStartDate.Text = "";
        txtEndDate.Text   = "";
    }
    protected override void LoadATMPage()
    {
        var ds    = ATMDB.GetDataSet("up_p_getFormCriteria", UserName);
        var count = ds.Tables[2].Rows.Count;

        if (IsPostBack)
        {
            return;
        }

        lbSygmaCenterNo.DataSource = ds.Tables[2].DefaultView;
        lbSygmaCenterNo.DataBind();
        if (count > 1)
        {
            lbSygmaCenterNo.Items.Insert(0, new ListItem("All", "0"));
            lbSygmaCenterNo.ClearSelection();
            lbSygmaCenterNo.Height        = 15 * (count + 2);
            lbSygmaCenterNo.SelectedIndex = 0;
        }
        else if (count == 1)
        {
            lbSygmaCenterNo.SelectedIndex = 0;
            lbSygmaCenterNo.Height        = 45;
        }
        else
        {
            lbSygmaCenterNo.Width = 100;
        }

        if (!Page.IsPostBack)
        {
            var today      = DateTime.Today;
            var lastMonday = today.AddDays(-(int)today.DayOfWeek - 7);

            txtStartDate.Text = lastMonday.ToShortDateString();
            txtEndDate.Text   = lastMonday.AddDays(6).ToShortDateString();

            var x = DateRangeCalculator.GetValidDateRanges();
            foreach (var item in x)
            {
                ddlDateRange.Items.Add(new ListItem(item.Key, item.Value.ToString()));
            }
            ddlDateRange.SelectedIndex = 0;
            CalculateDateRanges();
        }
    }
    private void CalculateDateRanges(string selectedValue)
    {
        if (selectedValue == DateRanges.Custom.ToString())
        {
            selectedValue = DateRanges.ThisWeek.ToString();
        }

        var range = DateRangeCalculator.Calculate(DateTime.Today, selectedValue);

        if (range != null)
        {
            txtFromDate.Text = range.Begin.ToShortDateString();
            txtToDate.Text   = range.End.ToShortDateString();
            ClearWeekendingDate();

            return;
        }

        ClearDateRangeValues();
    }