/// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        ReloadData(false);

        if (PostbackOnChange)
        {
            ucUniSelector.DropDownSingleSelect.AutoPostBack = true;
            ScriptManager scr = ScriptManager.GetCurrent(Page);
            scr.RegisterPostBackControl(ucUniSelector.DropDownSingleSelect);
        }

        if (!URLHelper.IsPostback())
        {
            // If some test belongs to node give by NodeID - preselect it in MVTest selector
            if (NodeID != 0)
            {
                TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
                TreeNode     node = tree.SelectSingleNode(NodeID, CMSContext.PreferredCultureCode, tree.CombineWithDefaultCulture);

                if (node != null)
                {
                    DataSet ds = ABTestInfoProvider.GetABTests("MVTestSiteID = " + CMSContext.CurrentSiteID + " AND MVTestPage = '" + SqlHelperClass.GetSafeQueryString(node.NodeAliasPath, false) + "'", String.Empty, 1, "MVTestID", null);
                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        int abTestID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["MVTestID"], 0);
                        if (abTestID != 0)
                        {
                            ucUniSelector.Value = abTestID;
                        }
                    }
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (PostbackOnChange)
        {
            ucUniSelector.DropDownSingleSelect.AutoPostBack = true;
            ScriptManager scr = ScriptManager.GetCurrent(Page);
            scr.RegisterPostBackControl(ucUniSelector.DropDownSingleSelect);
        }

        if (!URLHelper.IsPostback())
        {
            // If some test belongs to node give by NodeID - preselect it in ABTest selector
            if (NodeID != 0)
            {
                TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
                TreeNode     node = tree.SelectSingleNode(NodeID, CMSContext.PreferredCultureCode, tree.CombineWithDefaultCulture);

                if (node != null)
                {
                    DataSet ds = ABTestInfoProvider.GetABTests("ABTestSiteID = " + CMSContext.CurrentSiteID + " AND ABTestOriginalPage = '" + SqlHelperClass.GetSafeQueryString(node.NodeAliasPath, false) + "'", "ABTestName", -1, null, null);
                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        // Preselect running test
                        bool runningTestFound = false;
                        foreach (DataRow row in ds.Tables[0].Rows)
                        {
                            ABTestInfo abTestObj = new ABTestInfo(row);
                            if (ABTestInfoProvider.ABTestIsRunning(abTestObj))
                            {
                                runningTestFound    = true;
                                ucUniSelector.Value = abTestObj.ABTestID;
                            }
                        }

                        // If no running test found for the page, preselect the first test (alphabetically)
                        if (!runningTestFound)
                        {
                            int abTestID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["ABTestID"], 0);
                            if (abTestID != 0)
                            {
                                ucUniSelector.Value = abTestID;
                            }
                        }
                    }
                }
            }
        }

        ReloadData(false);
    }
    /// <summary>
    /// Loads data into Unigrid.
    /// </summary>
    private void LoadData()
    {
        var whereCondition = new WhereCondition();

        if (!String.IsNullOrEmpty(AliasPath))
        {
            whereCondition.WhereEquals("ABTestOriginalPage", AliasPath);
        }

        DataSet abTests = ABTestInfoProvider.GetABTests().OnSite(SiteContext.CurrentSiteID).Where(whereCondition);

        abTests.Tables[0].Columns.Add("ABTestStatus", typeof(int));

        foreach (DataRow abTestDataRow in abTests.Tables[0].Rows)
        {
            abTestDataRow["ABTestStatus"] = (int)ABTestStatusEvaluator.GetStatus(new ABTestInfo(abTestDataRow));
        }

        gridElem.DataSource = abTests;
    }
Exemple #4
0
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        string codename = this.txtABTestName.Text.Trim();

        // Validate required fields
        string errorMessage = new Validator()
                              .NotEmpty(txtABTestDisplayName.Text.Trim(), this.rfvABTestDisplayName.ErrorMessage)
                              .NotEmpty(codename, this.rfvABTestName.ErrorMessage)
                              .IsCodeName(codename, GetString("general.invalidcodename")).Result;

        if (!dtpABTestOpenFrom.IsValidRange() || !dtpABTestOpenTo.IsValidRange())
        {
            errorMessage = GetString("general.errorinvaliddatetimerange");
        }

        if ((dtpABTestOpenFrom.SelectedDateTime != DateTimeHelper.ZERO_TIME) &&
            (dtpABTestOpenTo.SelectedDateTime != DateTimeHelper.ZERO_TIME) &&
            (dtpABTestOpenFrom.SelectedDateTime > dtpABTestOpenTo.SelectedDateTime))
        {
            errorMessage = GetString("om.wrongtimeinterval");
        }

        string maxConversions = txtABTestMaxConversions.Text.Trim();

        if (!String.IsNullOrEmpty(maxConversions) && (String.IsNullOrEmpty(errorMessage)))
        {
            errorMessage = new Validator().IsInteger(maxConversions, GetString("om.targetconversionrequiresinteger")).IsPositiveNumber(maxConversions, GetString("om.targetconversionrequiresinteger")).Result;
        }

        // Check the uniqueness of the codename
        ABTestInfo info = ABTestInfoProvider.GetABTestInfo(txtABTestName.Text.Trim(), CMSContext.CurrentSiteName);

        if ((info != null) && ((this.AbTestObj == null) || (info.ABTestID != this.AbTestObj.ABTestID)))
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (String.IsNullOrEmpty(ucPath.Value.ToString()) && (AliasPath == String.Empty))
        {
            errorMessage = GetString("abtesting.enteroriginalpage");
        }

        // Test if there is no enabled test for same page
        if (chkABTestEnabled.Checked && TestToValidate())
        {
            QueryDataParameters parameters = null;
            string testPage = ((AliasPath != String.Empty) && !ShowAliasPath) ? AliasPath : ucPath.Value.ToString();
            string where = ABTestInfoProvider.GetRunningCondition(ABTestID, testPage, CMSContext.CurrentSiteID, ucCultureSelector.Value.ToString(), dtpABTestOpenFrom.SelectedDateTime, dtpABTestOpenTo.SelectedDateTime, out parameters);
            DataSet ds = ABTestInfoProvider.GetABTests(where, null, -1, null, parameters);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                errorMessage = GetString("om.twotestsonepageerror");
            }
        }

        // Set the error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            this.lblError.Text = errorMessage;
            return(false);
        }

        return(true);
    }