/// <summary>
    /// Fills alternative form list according to selection in class CMSDropDownList.
    /// </summary>
    protected void LoadAltFormsList()
    {
        int     formClassId = ValidationHelper.GetInteger(drpClass.SelectedValue, 0);
        DataSet ds          = AlternativeFormInfoProvider.GetAlternativeForms("FormClassID=" + formClassId, "FormName");

        lstAlternativeForms.Items.Clear();

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                AlternativeFormInfo afi = new AlternativeFormInfo(dr);
                if (afi != null)
                {
                    if ((afi.FormDisplayName != String.Empty) && (afi.FormName != String.Empty))
                    {
                        lstAlternativeForms.Items.Add(new ListItem(ResHelper.LocalizeString(afi.FormDisplayName), afi.FullName));
                    }
                }
            }
            lstAlternativeForms.SelectedValue = null;
            lstAlternativeForms.DataBind();
        }

        ds.Dispose();
    }
Exemplo n.º 2
0
    /// <summary>
    /// Upgrades form category properties.
    /// </summary>
    private static void UpgradeFormCategories()
    {
        try
        {
            var resourceStringRegex       = new Regex(@"(?<tag><cms:FormCategory[^>]*\s)(GroupingText)?ResourceString\s*=");
            var resourceStringReplacement = "${tag}CategoryTitleResourceString=";

            var groupingTextRegex       = new Regex(@"(?<tag><cms:FormCategory[^>]*\s)GroupingText\s*=");
            var groupingTextReplacement = "${tag}CategoryTitle=";

            var classes = DataClassInfoProvider.GetClasses().Where("[ClassFormLayout] != '' AND [ClassFormLayout] LIKE '%cms:FormCategory%'");
            foreach (var dci in classes)
            {
                dci.ClassFormLayout = resourceStringRegex.Replace(dci.ClassFormLayout, resourceStringReplacement);
                dci.ClassFormLayout = groupingTextRegex.Replace(dci.ClassFormLayout, groupingTextReplacement);

                DataClassInfoProvider.SetDataClassInfo(dci);
            }

            var altForms = AlternativeFormInfoProvider.GetAlternativeForms("[FormLayout] != '' AND [FormLayout] LIKE '%cms:FormCategory%'", null);
            foreach (var afi in altForms)
            {
                afi.FormLayout = resourceStringRegex.Replace(afi.FormLayout, resourceStringReplacement);
                afi.FormLayout = groupingTextRegex.Replace(afi.FormLayout, groupingTextReplacement);

                AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Upgrade - Form categories", "Upgrade", ex);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Click event - updates new values.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Params</param>
    protected void nameElem_Click(object sender, EventArgs e)
    {
        // Check 'EditForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "EditForm");
        }

        // Code name validation
        string err = new Validator().IsIdentificator(nameElem.CodeName, GetString("general.erroridentificatorformat")).Result;

        if (err != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = err;
            lblInfo.Visible  = false;
            return;
        }

        // Validate form id
        AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(altFormId);

        EditedObject = afi;
        if (afi == null)
        {
            return;
        }

        // Checking for duplicate items
        DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(nameElem.CodeName, false) +
                                                                     "' AND FormClassID=" + afi.FormClassID, null);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            if (!((ds.Tables.Count == 1) && (ds.Tables[0].Rows.Count == 1) && (
                      ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["FormID"], 0) == altFormId)))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("general.codenameexists");
                lblInfo.Visible  = false;
                return;
            }
        }

        afi.FormDisplayName = nameElem.DisplayName;
        afi.FormName        = nameElem.CodeName;
        AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);

        // Required to log staging task, alternative form is not binded to bizform as child
        using (CMSActionContext context = new CMSActionContext())
        {
            context.CreateVersion = false;

            // Log synchronization
            BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(formId);
            SynchronizationHelper.LogObjectChange(bfi, TaskTypeEnum.UpdateObject);
        }

        URLHelper.Redirect("AlternativeForms_Edit_General.aspx?altformid=" + altFormId + "&formid=" + formId + "&saved=1");
    }
Exemplo n.º 4
0
    void nameElem_Click(object sender, EventArgs e)
    {
        // Check 'EditForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "EditForm");
        }

        // Code name validation
        string err = new Validator().IsIdentificator(nameElem.CodeName, GetString("general.erroridentificatorformat")).Result;

        if (err != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = err;
            return;
        }

        // Checking for duplicate items
        DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + nameElem.CodeName +
                                                                     "' AND FormClassID=" + classId, null);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("general.codenameexists");
            return;
        }

        // Create new info object
        AlternativeFormInfo afi = new AlternativeFormInfo();

        afi.FormID          = 0;
        afi.FormGUID        = Guid.NewGuid();
        afi.FormClassID     = classId;
        afi.FormName        = nameElem.CodeName;
        afi.FormDisplayName = nameElem.DisplayName;

        AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);

        // Required to log staging task, alternative form is not binded to bizform as child
        using (CMSActionContext context = new CMSActionContext())
        {
            context.CreateVersion = false;

            // Log synchronization
            SynchronizationHelper.LogObjectChange(bfi, TaskTypeEnum.UpdateObject);
        }

        URLHelper.Redirect("AlternativeForms_Frameset.aspx?formid=" + formId.ToString() +
                           "&altformid=" + afi.FormID + "&saved=1");
    }
Exemplo n.º 5
0
    /// <summary>
    /// Click event - updates new values.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Params</param>
    void btnOK_Click(object sender, EventArgs e)
    {
        // Code name validation
        string err = new Validator().IsIdentificator(txtCodeName.Text, GetString("general.erroridentificatorformat")).Result;

        if (err != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = err;
            lblInfo.Visible  = false;
            return;
        }

        // Validate form id
        AlternativeFormInfo afi = AlternativeFormInfoProvider.GetAlternativeFormInfo(altFormId);

        EditedObject = afi;
        if (afi == null)
        {
            return;
        }

        // Checking for duplicate items
        DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(txtCodeName.Text, false) +
                                                                     "' AND FormClassID=" + afi.FormClassID, null);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            if (!((ds.Tables.Count == 1) && (ds.Tables[0].Rows.Count == 1) && (
                      ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["FormID"], 0) == altFormId)))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("general.codenameexists");
                lblInfo.Visible  = false;
                return;
            }
        }

        afi.FormDisplayName = txtDisplayName.Text;
        afi.FormName        = txtCodeName.Text;
        AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("general.changessaved");

        // Reload header if changes were saved
        ScriptHelper.RefreshTabHeader(Page, null);
    }
    protected void nameElem_Click(object sender, EventArgs e)
    {
        // Code name validation
        string err = new Validator().IsIdentificator(nameElem.CodeName, GetString("general.erroridentificatorformat")).Result;

        if (err != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = err;
            return;
        }

        // Checking for duplicate items
        DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(nameElem.CodeName, false) +
                                                                     "' AND FormClassID=" + classId, null);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("general.codenameexists");
            return;
        }

        // Create new info object
        AlternativeFormInfo alternativeFormInfo = new AlternativeFormInfo();

        alternativeFormInfo.FormID          = 0;
        alternativeFormInfo.FormGUID        = Guid.NewGuid();
        alternativeFormInfo.FormClassID     = classId;
        alternativeFormInfo.FormName        = nameElem.CodeName;
        alternativeFormInfo.FormDisplayName = nameElem.DisplayName;

        try
        {
            AlternativeFormInfoProvider.SetAlternativeFormInfo(alternativeFormInfo);
            URLHelper.Redirect("AlternativeForms_Frameset.aspx?classid=" + classId + "&altformid=" + alternativeFormInfo.FormID + "&saved=1");
        }
        catch (Exception ex)
        {
            lblError.Visible = true;
            lblError.Text    = ex.Message;
        }
    }
Exemplo n.º 7
0
    void btnOK_Click(object sender, EventArgs e)
    {
        // Code name validation
        string err = new Validator().IsIdentificator(this.txtCodeName.Text, GetString("general.erroridentificatorformat")).Result;

        if (err != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = err;
            return;
        }

        // Checking for duplicate items
        DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(this.txtCodeName.Text, false) +
                                                                     "' AND FormClassID=" + classId, null);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("general.codenameexists");
            return;
        }

        // Create new info object
        AlternativeFormInfo afi = new AlternativeFormInfo();

        afi.FormID          = 0;
        afi.FormGUID        = Guid.NewGuid();
        afi.FormClassID     = classId;
        afi.FormName        = this.txtCodeName.Text;
        afi.FormDisplayName = this.txtDisplayName.Text;

        DataClassInfo dci = DataClassInfoProvider.GetDataClass(SiteObjectType.USERSETTINGS);

        if (dci != null)
        {
            afi.FormCoupledClassID = (this.chkCombineUserSettings.Checked) ? dci.ClassID : 0;
        }

        AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);

        URLHelper.Redirect("Frameset.aspx?classid=" + classId + "&altformid=" + afi.FormID + "&saved=1");
    }
Exemplo n.º 8
0
    /// <summary>
    /// Fills alternative form list according to selection in class selector.
    /// </summary>
    private void LoadAltFormsList()
    {
        int formClassId = ValidationHelper.GetInteger(drpClass.Value, 0);
        var altForms    = AlternativeFormInfoProvider.GetAlternativeForms()
                          .Columns("FormName", "FormDisplayName", "FormClassID")
                          .WhereEquals("FormClassID", formClassId)
                          .OrderBy("FormName");

        lstAlternativeForms.Items.Clear();

        foreach (var alternativeForm in altForms)
        {
            if ((alternativeForm.FormDisplayName != String.Empty) && (alternativeForm.FormName != String.Empty))
            {
                lstAlternativeForms.Items.Add(new ListItem(ResHelper.LocalizeString(alternativeForm.FormDisplayName), alternativeForm.FullName));
            }
        }

        lstAlternativeForms.SelectedValue = null;
        lstAlternativeForms.DataBind();
    }
    /// <summary>
    /// Adds form field info to the form to the specified position.
    /// </summary>
    /// <param name="ffi">Form field info which will be added</param>
    /// <param name="category">Category name</param>
    /// <param name="position">Field position in the category</param>
    private string AddField(FormFieldInfo ffi, string category, int position)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            RedirectToAccessDenied("cms.form", "EditForm");
        }

        var dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

        if (dci != null)
        {
            // Ensure the transaction
            using (var tr = new CMSLateBoundTransaction())
            {
                string tableName  = dci.ClassTableName;
                string columnType = DataTypeManager.GetSqlType(ffi.DataType, ffi.Size, ffi.Precision);

                TableManager tm = new TableManager(dci.ClassConnectionString);
                tr.BeginTransaction();

                // Add new column
                tm.AddTableColumn(tableName, ffi.Name, columnType, true, null);

                // Add field to form
                mFormInfo.AddFormItem(ffi);
                if (!String.IsNullOrEmpty(category) || position >= 0)
                {
                    mFormInfo.MoveFormFieldToPositionInCategory(ffi.Name, category, position);
                }

                // Update form definition
                dci.ClassFormDefinition = mFormInfo.GetXmlDefinition();

                // Update class schema
                dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);

                try
                {
                    // Save the class data
                    DataClassInfoProvider.SetDataClassInfo(dci);
                }
                catch (Exception)
                {
                    return(GetString("FormBuilder.ErrorSavingForm"));
                }

                // Generate default view
                SqlGenerator.GenerateDefaultView(dci, SiteContext.CurrentSiteName);
                QueryInfoProvider.ClearDefaultQueries(dci, true, true);

                // Hide field for alternative forms that require it
                string where = "FormClassID=" + dci.ClassID;
                where        = SqlHelper.AddWhereCondition(where, "FormHideNewParentFields=1");

                var altforms = AlternativeFormInfoProvider.GetAlternativeForms(where, null);
                foreach (AlternativeFormInfo afi in altforms)
                {
                    afi.HideField(ffi);
                    AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);
                }


                // Commit the transaction
                tr.Commit();
            }

            ClearHashtables();

            // Update inherited classes with new fields
            FormHelper.UpdateInheritedClasses(dci);
        }
        else
        {
            return(GetString("FormBuilder.ErrorSavingForm"));
        }

        return(string.Empty);
    }