/// <summary>
        /// Takes a variation code from the database and returns the proper variation item name from sitecore
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        private string GetVariationName(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return("Default");
            }

            if (TestComponentItem.IsNull())
            {
                return(string.Empty);
            }

            List <Item> variationItems = SitecoreItemFinder.GetSubItemsOfTemplate(TestComponentItem, Sitecore.SharedSource.Analytics.CustomItems.Testing.MultivariateTestValueItem.TemplateId, true);

            if (variationItems == null || variationItems.Count == 0)
            {
                return(string.Empty);
            }

            code = code.Substring(3, 1);

            int codeValue = 0;

            int.TryParse(code, out codeValue);
            if (variationItems[codeValue] == null)
            {
                return(string.Empty);
            }

            Sitecore.SharedSource.Analytics.CustomItems.Testing.MultivariateTestValueItem variationItem = variationItems[codeValue];
            return(variationItem.TestValue.Name.Text);
        }
        /// <summary>
        /// Returns a list of errors
        /// </summary>
        /// <returns></returns>
        private List <string> IsFormValid(bool phase1Only)
        {
            List <string> errorList = new List <string>();

            //test dropdown
            if (string.IsNullOrEmpty(ddlTest.SelectedValue))
            {
                errorList.Add("Select a test");
            }

            //test item
            if (!string.IsNullOrEmpty(ddlTest.SelectedValue) && (TestComponentItem.IsNull() || TestDefinitionItem.IsNull()))
            {
                errorList.Add("The test item is null");
            }

            if (phase1Only)
            {
                return(errorList);
            }

            //test dropdown
            if (string.IsNullOrEmpty(ddlGoal.SelectedValue))
            {
                errorList.Add("Select a goal");
            }

            //test item
            if (!string.IsNullOrEmpty(ddlGoal.SelectedValue) && Database.GetItem(ddlGoal.SelectedValue).IsNull())
            {
                errorList.Add("The goal item is null");
            }

            //start date
            if (beginDatePicker.SelectedDate == null || beginDatePicker.SelectedDate == DateTime.MinValue)
            {
                errorList.Add("Select a start date");
            }

            //enddate
            if (endDatePicker.SelectedDate == null || endDatePicker.SelectedDate == DateTime.MinValue)
            {
                errorList.Add("Select an end date");
            }

            if (beginDatePicker.SelectedDate != null &&
                endDatePicker.SelectedDate != null &&
                beginDatePicker.SelectedDate > endDatePicker.SelectedDate)
            {
                errorList.Add("Select a start date that is before the end date");
            }

            return(errorList);
        }
        /// <summary>
        /// Displays the Achieved Goals datatable
        /// </summary>
        private void LoadAchievedGoals()
        {
            if (TestComponentItem.IsNull() || TestDefinitionItem.IsNull() || GoalItem.IsNull())
            {
                return;
            }

            DateTime startTime = DateTime.MinValue;

            if (beginDatePicker.SelectedDate.HasValue)
            {
                startTime = beginDatePicker.SelectedDate.Value;
            }

            DateTime endTime = DateTime.MaxValue;

            if (endDatePicker.SelectedDate.HasValue)
            {
                endTime = endDatePicker.SelectedDate.Value;
            }

            List <VisitVariation> achievedGoals = PageStatistics.GetAchievedGoals(GoalItem, TestDefinitionItem, startTime,
                                                                                  endTime);

            if (achievedGoals == null || achievedGoals.Count == 0)
            {
                ShowErrors(new List <string> {
                    "No data available for the selected parameters"
                });
                return;
            }

            litAchievedGoal.Text        = TestComponentItem.Name;
            rptAchievedGoals.DataSource = achievedGoals;
            rptAchievedGoals.DataBind();
            plcAchievedGoalData.Visible = true;
            plcReport.Visible           = true;

            //set totals which are summed up during the databinding process
            litTotalVisitCount.Text    = TotalVisitCount.ToString("N0");
            litTotalAchievedCount.Text = TotalAchievedGoalCount.ToString("N0");
        }