private int formId = 0; // BizForm id

    #endregion Fields

    #region Methods

    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'ReadForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "ReadForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "ReadForm");
        }

        formId = QueryHelper.GetInteger("formid", 0);
        bfi = BizFormInfoProvider.GetBizFormInfo(formId);
        EditedObject = bfi;

        if (bfi == null)
        {
            lblError.Visible = true;
            lblError.Text = GetString("general.invalidid");
            return;
        }

        // Init alternative forms listing
        listElem.FormClassID = bfi.FormClassID;
        listElem.OnEdit += listElem_OnEdit;
        listElem.OnDelete += listElem_OnDelete;

        // New item link
        string[,] actions = new string[1, 6];
        actions[0, 0] = HeaderActions.TYPE_HYPERLINK;
        actions[0, 1] = GetString("altforms.newformlink");
        actions[0, 2] = null;
        actions[0, 3] = ResolveUrl("AlternativeForms_New.aspx?formid=" + formId.ToString());
        actions[0, 4] = null;
        actions[0, 5] = GetImageUrl("Objects/CMS_AlternativeForm/add.png");
        this.CurrentMaster.HeaderActions.Actions = actions;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'ReadForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "ReadForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "ReadForm");
        }

        int altFormId = QueryHelper.GetInteger("altformid", 0);
        int formId = QueryHelper.GetInteger("formid", 0);

        bfi = BizFormInfoProvider.GetBizFormInfo(formId);
        EditedObject = bfi;

        if (bfi == null)
        {
            ShowError(GetString("general.invalidid"));
            altFormFieldEditor.Visible = false;
            return;
        }

        CurrentMaster.BodyClass += " FieldEditorBody";
        altFormFieldEditor.AlternativeFormID = altFormId;
        altFormFieldEditor.Mode = FieldEditorModeEnum.BizFormDefinition;
        altFormFieldEditor.DisplayedControls = FieldEditorControlsEnum.Bizforms;
        altFormFieldEditor.OnBeforeSave += altFormFieldEditor_OnBeforeSave;
        altFormFieldEditor.OnAfterSave += altFormFieldEditor_OnAfterSave;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        rfvDisplayName.Text = GetString("BizFormGeneral.rfvDisplayName");
        bfi = EditedObject as BizFormInfo;

        if ((!RequestHelper.IsPostBack()) && (bfi != null))
        {
            LoadData();
        }
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        CurrentMaster.DisplayControlsPanel = true;

        // Check 'ReadData' permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "ReadData"))
        {
            RedirectToAccessDenied("cms.form", "ReadData");
        }
        // Check 'EditData' permission
        else if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditData"))
        {
            RedirectToAccessDenied("cms.form", "EditData");
        }

        // Get form id from url
        formId = QueryHelper.GetInteger("formid", 0);
        if (formId > 0)
        {
            // Get form record id
            formRecordId = QueryHelper.GetInteger("formrecordid", 0);

            if (!RequestHelper.IsPostBack())
            {
                chkSendNotification.Checked = (formRecordId <= 0);
                chkSendAutoresponder.Checked = (formRecordId <= 0);
            }

            bfi = BizFormInfoProvider.GetBizFormInfo(formId);
            EditedObject = bfi;

            if (!RequestHelper.IsPostBack())
            {
                // Get form info
                if (bfi != null)
                {
                    // Set form
                    formElem.FormName = bfi.FormName;
                    formElem.ItemID = formRecordId;
                    formElem.ShowPrivateFields = true;
                }
            }

            formElem.FormRedirectToUrl = String.Empty;
            formElem.FormDisplayText = String.Empty;
            formElem.FormClearAfterSave = false;
            // Submit image button is based on ImageButton which does not have implemented automatic registration of Save header action in UI.
            // Hide image button in UI even if path to image is configured
            formElem.ShowImageButton = false;

            formElem.OnBeforeSave += formElem_OnBeforeSave;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get needed IDs
        int formId = QueryHelper.GetInteger("formid", 0);
        bfi = BizFormInfoProvider.GetBizFormInfo(formId);

        altFormEdit.OnBeforeSave += (s, ea) => altFormEdit.EditedObject.FormClassID = bfi.FormClassID;
        altFormEdit.OnAfterSave += altFormEdit_OnAfterSave;

        altFormEdit.RedirectUrlAfterCreate = String.Empty;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get needed IDs
        int formId = QueryHelper.GetInteger("formid", 0);
        bfi = BizFormInfoProvider.GetBizFormInfo(formId);

        altFormEdit.OnBeforeSave += (s, ea) => ((AlternativeFormInfo)altFormEdit.EditedObject).FormClassID = bfi.FormClassID;
        altFormEdit.OnAfterSave += altFormEdit_OnAfterSave;

        altFormEdit.RedirectUrlAfterCreate = String.Empty;
        CurrentMaster.Title.Breadcrumbs[0, 1] += "?formid=" + bfi.FormID;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'ReadForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "ReadForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "ReadForm");
        }

        bizFormId = QueryHelper.GetInteger("formid", 0);
        layoutElem.FormType = CMSModules_AdminControls_Controls_Class_Layout.FORMTYPE_BIZFORM;
        layoutElem.ObjectID = bizFormId;
        layoutElem.OnBeforeSave += layoutElem_OnBeforeSave;
        layoutElem.OnAfterSave += layoutElem_OnAfterSave;

        // Load CSS style sheet to editor area
        if (CMSContext.CurrentSite != null)
        {
            int cssId = CMSContext.CurrentSite.SiteDefaultEditorStylesheet;
            if (cssId == 0) // Use default site CSS if none editor CSS is specified
            {
                cssId = CMSContext.CurrentSite.SiteDefaultStylesheetID;
            }
            layoutElem.CssStyleSheetID = cssId;
        }

        AttachmentTitle.TitleText = GetString("general.attachments");

        bfi = BizFormInfoProvider.GetBizFormInfo(bizFormId);
        EditedObject = bfi;
        if (!RequestHelper.IsPostBack())
        {
            if (bfi != null)
            {
                // Init file storage
                AttachmentList.SiteID = CMSContext.CurrentSiteID;
                AttachmentList.AllowPasteAttachments = true;
                AttachmentList.ObjectID = bfi.FormID;
                AttachmentList.ObjectType = FormObjectType.BIZFORM;
                AttachmentList.Category = MetaFileInfoProvider.OBJECT_CATEGORY_LAYOUT;
            }
        }
    }
    private DataSet uniGrid_OnAfterRetrieveData(DataSet ds)
    {
        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            int i = 0;
            while (i < ds.Tables[0].Rows.Count)
            {
                BizFormInfo form = new BizFormInfo(ds.Tables[0].Rows[i]);
                if (!form.IsFormAllowedForUser(currentUser, SiteContext.CurrentSiteName))
                {
                    ds.Tables[0].Rows.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }

        return ds;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'ReadForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "ReadForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "ReadForm");
        }

        formId = QueryHelper.GetInteger("formid", 0);
        bfi = BizFormInfoProvider.GetBizFormInfo(formId);
        EditedObject = bfi;

        if (bfi == null)
        {
            lblError.Visible = true;
            lblError.Text = GetString("general.invalidid");
            return;
        }

        classId = bfi.FormClassID;

        // Init breadcrumbs
        string[,] breadcrumbs = new string[2, 3];

        // Return to list item in breadcrumbs
        breadcrumbs[0, 0] = GetString("altforms.listlink");
        breadcrumbs[0, 1] = "~/CMSModules/BizForms/Tools/AlternativeForms/AlternativeForms_List.aspx?formid=" + formId;
        breadcrumbs[0, 2] = "";
        breadcrumbs[1, 0] = GetString("altform.newbread");
        breadcrumbs[1, 1] = "";
        breadcrumbs[1, 2] = "";

        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        nameElem.ShowSubmitButton = true;
        nameElem.Click += new EventHandler(nameElem_Click);
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (!BizFormInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.BizForms, ObjectActionEnum.Insert))
        {
            ShowError(GetString("LicenseVersion.BizForm"));
            return;
        }

        DataClassInfo dci = null;
        BizFormInfo bizFormObj = null;

        string errorMessage = new Validator().NotEmpty(txtFormDisplayName.Text, rfvFormDisplayName.ErrorMessage).
            NotEmpty(txtFormName.Text, rfvFormName.ErrorMessage).
            NotEmpty(txtTableName.Text, rfvTableName.ErrorMessage).
            IsIdentifier(txtFormName.Text, GetString("bizform_edit.errorformnameinidentifierformat")).
            IsIdentifier(txtTableName.Text, GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")).Result;

        if (String.IsNullOrEmpty(errorMessage))
        {
            using (var tr = new CMSTransactionScope())
            {
                // Prepare the values
                string formDisplayName = txtFormDisplayName.Text.Trim();

                bizFormObj = new BizFormInfo();
                bizFormObj.FormDisplayName = formDisplayName;
                bizFormObj.FormName = txtFormName.Text.Trim();
                bizFormObj.FormSiteID = SiteContext.CurrentSiteID;
                bizFormObj.FormEmailAttachUploadedDocs = true;
                bizFormObj.FormItems = 0;
                bizFormObj.FormClearAfterSave = false;
                bizFormObj.FormLogActivity = true;

                // Ensure the code name
                bizFormObj.Generalized.EnsureCodeName();

                // Table name is combined from prefix ('BizForm_<sitename>_') and custom table name
                string safeFormName = ValidationHelper.GetIdentifier(bizFormObj.FormName);
                bizFormObj.FormName = safeFormName;

                string className = bizFormNamespace + "." + safeFormName;

                // Generate the table name
                string tableName = txtTableName.Text.Trim();
                if (String.IsNullOrEmpty(tableName) || (tableName == InfoHelper.CODENAME_AUTOMATIC))
                {
                    tableName = safeFormName;
                }
                tableName = FormTablePrefix + tableName;

                TableManager tm = new TableManager(null);

                // TableName wont be longer than 60 letters and will be unique
                if (tableName.Length > 60)
                {
                    int x = 1;

                    while (tm.TableExists(tableName.Substring(0, 59) + x.ToString()))
                    {
                        x++;
                    }

                    tableName = tableName.Substring(0, 59) + x.ToString();
                }

                // If first letter of safeFormName is digit, add "PK" to beginning
                string primaryKey = BizFormInfoProvider.GenerateFormPrimaryKeyName(bizFormObj.FormName);

                try
                {
                    // Create new table in DB
                    tm.CreateTable(tableName, primaryKey);
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;

                    // Table with the same name already exists
                    ShowError(string.Format(GetString("bizform_edit.errortableexists"), tableName));
                    return;
                }

                // Change table owner
                try
                {
                    string owner = SqlHelper.GetDBSchema(SiteContext.CurrentSiteName);
                    if ((!String.IsNullOrEmpty(owner)) && (owner.ToLowerCSafe() != "dbo"))
                    {
                        tm.ChangeDBObjectOwner(tableName, owner);
                        tableName = owner + "." + tableName;
                    }
                }
                catch (Exception ex)
                {
                    EventLogProvider.LogException("BIZFORM_NEW", "E", ex);
                }

                // Convert default datetime to string in english format
                string defaultDateTime = DateTime.Now.ToString(CultureHelper.EnglishCulture.DateTimeFormat);

                try
                {
                    // Add FormInserted and FormUpdated columns to the table
                    tm.AddTableColumn(tableName, "FormInserted", "datetime", false, defaultDateTime);
                    tm.AddTableColumn(tableName, "FormUpdated", "datetime", false, defaultDateTime);
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;

                    // Column wasn't added successfully
                    ShowError(errorMessage);

                    return;
                }

                // Create the BizForm class
                dci = BizFormInfoProvider.CreateBizFormDataClass(className, formDisplayName, tableName, primaryKey);

                try
                {
                    // Create new bizform dataclass
                    using (CMSActionContext context = new CMSActionContext())
                    {
                        // Disable logging of tasks
                        context.DisableLogging();

                        // Set default search settings
                        dci.ClassSearchEnabled = true;

                        DataClassInfoProvider.SetDataClassInfo(dci);

                        // Create default search settings
                        dci.ClassSearchSettings = SearchHelper.GetDefaultSearchSettings(dci);
                        dci.ClassSearchCreationDateColumn = "FormInserted";
                        DataClassInfoProvider.SetDataClassInfo(dci);
                    }
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;

                    // Class with the same name already exists
                    ShowError(errorMessage);

                    return;
                }

                // Create new bizform
                bizFormObj.FormClassID = dci.ClassID;

                try
                {
                    // Create new bizform
                    BizFormInfoProvider.SetBizFormInfo(bizFormObj);
                }
                catch (Exception ex)
                {
                    errorMessage = ex.Message;

                    ShowError(errorMessage);

                    return;
                }

                tr.Commit();

                if (String.IsNullOrEmpty(errorMessage))
                {
                    // Redirect to Form builder tab
                    string url = UIContextHelper.GetElementUrl("CMS.Form", "Forms.Properties", false, bizFormObj.FormID);
                    url = URLHelper.AddParameterToUrl(url, "tabname", "Forms.FormBuldier");
                    URLHelper.Redirect(url);
                }
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        // Get edited object
        if (CMSContext.EditedObject != null)
        {
            bfi = (BizFormInfo)CMSContext.EditedObject;
            formId = bfi.FormID;
        }

        isDialog = QueryHelper.GetBoolean("dialogmode", false);
        InitHeaderActions();
    }
Exemple #12
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        DataClassInfo dci = null;
        BizFormInfo bizFormObj = null;

        string errorMessage = new Validator().NotEmpty(txtFormDisplayName.Text, rfvFormDisplayName.ErrorMessage).
                                               NotEmpty(txtFormName.Text, rfvFormName.ErrorMessage).
                                               NotEmpty(txtTableName.Text, rfvTableName.ErrorMessage).
                                               IsIdentificator(txtFormName.Text, GetString("BizForm_Edit.ErrorFormNameInIdentificatorFormat")).
                                               IsIdentificator(txtTableName.Text, GetString("BizForm_Edit.ErrorFormTableNameInIdentificatorFormat")).Result;
        if (String.IsNullOrEmpty(errorMessage))
        {
            string formCodeName = txtFormName.Text.Trim();

            // Form name must be unique
            BizFormInfo testObj = BizFormInfoProvider.GetBizFormInfo(formCodeName, CMSContext.CurrentSiteName);

            // If formName value is unique...
            if (testObj == null)
            {
                string primaryKey = formCodeName + "ID";
                string formDisplayName = txtFormDisplayName.Text.Trim();
                string className = bizFormNamespace + "." + formCodeName;
                // Table name is combined from prefix ('BizForm_<sitename>_') and custom table name
                string tableName = FormTablePrefix + txtTableName.Text.Trim();

                if (!BizFormInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.BizForms, VersionActionEnum.Insert))
                {
                    lblError.Visible = true;
                    lblError.Text = GetString("LicenseVersion.BizForm");
                }

                if (!lblError.Visible)
                {
                    try
                    {
                        // Create new table in DB
                        TableManager.CreateTable(tableName, primaryKey);
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;

                        // Table with the same name already exists
                        lblError.Visible = true;
                        lblError.Text = string.Format(GetString("bizform_edit.errortableexists"), tableName);
                    }

                    if (String.IsNullOrEmpty(errorMessage))
                    {
                        // Change table owner
                        try
                        {
                            string owner = SqlHelperClass.GetDBSchema(CMSContext.CurrentSiteName);
                            if ((!String.IsNullOrEmpty(owner)) && (owner.ToLower() != "dbo"))
                            {
                                TableManager.ChangeDBObjectOwner(tableName, owner);
                                tableName = owner + "." + tableName;
                            }
                        }
                        catch (Exception ex)
                        {
                            EventLogProvider.LogException("BIZFORM_NEW", "E", ex);
                        }

                        // Convert default datetime to string in english format
                        string defaultDateTime = DateTime.Now.ToString(CultureHelper.EnglishCulture.DateTimeFormat);

                        try
                        {
                            // Add FormInserted and FormUpdated columns to the table
                            TableManager.AddTableColumn(tableName, "FormInserted", "datetime", false, defaultDateTime);
                            TableManager.AddTableColumn(tableName, "FormUpdated", "datetime", false, defaultDateTime);
                        }
                        catch (Exception ex)
                        {
                            errorMessage = ex.Message;

                            // Column wasnt added successfuly
                            lblError.Visible = true;
                            lblError.Text = errorMessage;

                            // Delete created table
                            TableManager.DropTable(tableName);
                        }
                    }

                    if (String.IsNullOrEmpty(errorMessage))
                    {
                        dci = BizFormInfoProvider.CreateBizFormDataClass(className, formDisplayName, tableName, primaryKey);

                        try
                        {
                            // Create new bizform dataclass
                            using (CMSActionContext context = new CMSActionContext())
                            {
                                // Disable logging of tasks
                                context.DisableLogging();

                                DataClassInfoProvider.SetDataClass(dci);
                            }
                        }
                        catch (Exception ex)
                        {
                            errorMessage = ex.Message;

                            // Class with the same name already exists
                            lblError.Visible = true;
                            lblError.Text = errorMessage;

                            // Delete created table
                            TableManager.DropTable(tableName);
                        }
                    }

                    if (String.IsNullOrEmpty(errorMessage))
                    {
                        // Create new bizform
                        bizFormObj = new BizFormInfo();
                        bizFormObj.FormDisplayName = formDisplayName;
                        bizFormObj.FormName = formCodeName;
                        bizFormObj.FormClassID = dci.ClassID;
                        bizFormObj.FormSiteID = CMSContext.CurrentSiteID;
                        bizFormObj.FormEmailAttachUploadedDocs = true;
                        bizFormObj.FormItems = 0;
                        bizFormObj.FormClearAfterSave = false;
                        bizFormObj.FormLogActivity = true;

                        try
                        {
                            // Create new bizform
                            BizFormInfoProvider.SetBizFormInfo(bizFormObj);

                            // Generate basic queries
                            SqlGenerator.GenerateQuery(className, "selectall", SqlOperationTypeEnum.SelectAll, false);
                            SqlGenerator.GenerateQuery(className, "delete", SqlOperationTypeEnum.DeleteQuery, false);
                            SqlGenerator.GenerateQuery(className, "insert", SqlOperationTypeEnum.InsertQuery, true);
                            SqlGenerator.GenerateQuery(className, "update", SqlOperationTypeEnum.UpdateQuery, false);
                            SqlGenerator.GenerateQuery(className, "select", SqlOperationTypeEnum.SelectQuery, false);
                        }
                        catch (Exception ex)
                        {
                            errorMessage = ex.Message;

                            lblError.Visible = true;
                            lblError.Text = errorMessage;

                            // Delete created class (includes deleting its table)
                            if (dci != null)
                            {
                                using (CMSActionContext context = new CMSActionContext())
                                {
                                    // Disable logging of tasks
                                    context.DisableLogging();

                                    DataClassInfoProvider.DeleteDataClass(dci);
                                }
                            }
                        }

                        if (String.IsNullOrEmpty(errorMessage))
                        {
                            // Redirect to edit dialog
                            URLHelper.Redirect(string.Format("BizForm_Frameset.aspx?formId={0}&newform=1", bizFormObj.FormID));
                        }
                    }
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text = GetString("BizForm_Edit.FormNameExists");
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = errorMessage;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Add save action
        save = new SaveAction(Page);
        menu.AddAction(save);

        // Register for action
        ComponentEvents.RequestEvents.RegisterForEvent(ComponentEvents.SAVE, lnkSave_Click);

        // Control initialization
        ltlConfirmDelete.Text = "<input type=\"hidden\" id=\"confirmdelete\" value=\"" + GetString("Bizform_Edit_Notificationemail.ConfirmDelete") + "\">";

        chkSendToEmail.Text = GetString("BizFormGeneral.chkSendToEmail");

        chkCustomLayout.Text = GetString("BizForm_Edit_NotificationEmail.CustomLayout");

        // Initialize HTML editor
        InitHTMLEditor();

        formInfo = EditedObject as BizFormInfo;

        if (!RequestHelper.IsPostBack())
        {
            if (formInfo!= null)
            {
                // Get form class object
                formClassObj = DataClassInfoProvider.GetDataClassInfo(formInfo.FormClassID);

                // Fill list of available fields
                FillFieldsList();

                // Load email from/to address and email subject
                txtFromEmail.Text = ValidationHelper.GetString(formInfo.FormSendFromEmail, "");
                txtToEmail.Text = ValidationHelper.GetString(formInfo.FormSendToEmail, "");
                txtSubject.Text = ValidationHelper.GetString(formInfo.FormEmailSubject, "");
                chkAttachDocs.Checked = formInfo.FormEmailAttachUploadedDocs;
                chkSendToEmail.Checked = ((txtFromEmail.Text + txtToEmail.Text) != "");
                if (!chkSendToEmail.Checked)
                {
                    txtFromEmail.Enabled = false;
                    txtToEmail.Enabled = false;
                    txtSubject.Enabled = false;
                    chkAttachDocs.Enabled = false;
                    chkCustomLayout.Visible = false;
                    pnlCustomLayout.Visible = false;
                }
                else
                {
                    // Enable or disable form
                    EnableDisableForm(formInfo.FormEmailTemplate);
                }
            }
            else
            {
                // Disable form by default
                EnableDisableForm(null);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'ReadForm' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "ReadForm"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "ReadForm");
        }

        // Get form id from url
        int formId = QueryHelper.GetInteger("formid", 0);
        // Get form object
        bfi = BizFormInfoProvider.GetBizFormInfo(formId);
        EditedObject = bfi;

        rfvDisplayName.Text = GetString("BizFormGeneral.rfvDisplayName");

        if ((!RequestHelper.IsPostBack()) && (bfi != null))
        {
            LoadData();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (EditedObject == null)
        {
            RedirectToAccessDenied(GetString("general.invalidparameters"));
        }

        currentUser = MembershipContext.AuthenticatedUser;

        // Register for action
        ComponentEvents.RequestEvents.RegisterForEvent(ComponentEvents.SAVE, lnkSave_Click);

        formInfo = EditedObject as BizFormInfo;

        if (formInfo != null)
        {
            // Control initialization
            ltlConfirmDelete.Text = "<input type=\"hidden\" id=\"confirmdelete\" value=\"" + GetString("Bizform_Edit_Autoresponder.ConfirmDelete") + "\">";

            drpEmailField.SelectedIndexChanged += drpEmailField_SelectedIndexChanged;

            // Init header actions
            InitHeaderActions();

            // Initialize HTML editor
            InitHTMLEditor();

            if (!RequestHelper.IsPostBack())
            {
                // Get bizform class object
                formClassObj = DataClassInfoProvider.GetDataClassInfo(formInfo.FormClassID);
                if (formClassObj != null)
                {
                    // Enable or disable form
                    EnableDisableForm(formInfo.FormConfirmationTemplate);

                    // Fill list of available fields
                    FillFieldsList();

                    // Load dropdown list with form text fields
                    InitializeEmailDropdown();

                    // Load email subject and email from address
                    txtEmailFrom.Text = formInfo.FormConfirmationSendFromEmail;
                    txtEmailSubject.Text = formInfo.FormConfirmationEmailSubject;
                }
                else
                {
                    // Disable form by default
                    EnableDisableForm(null);
                }
            }
        }
    }
 private void CleanUpOnError(string tableName, TableManager tm, DataClassInfo dci = null, BizFormInfo bizForm = null)
 {
     if (tm.TableExists(tableName))
     {
         tm.DropTable(tableName);
     }
     if ((bizForm != null) && (bizForm.FormID > 0))
     {
         BizFormInfoProvider.DeleteBizFormInfo(bizForm);
     }
     if ((dci != null) && (dci.ClassID > 0))
     {
         DataClassInfoProvider.DeleteDataClassInfo(dci);
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        int formId = 0;
        int formRecordId = 0;

        // Check 'ReadData' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "ReadData"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "ReadData");
        }
        // Check 'EditData' permission
        else if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "EditData"))
        {
            RedirectToCMSDeskAccessDenied("cms.form", "EditData");
        }

        // Get form id from url
        formId = QueryHelper.GetInteger("formid", 0);

        if (formId > 0)
        {
            // Get form record id
            formRecordId = QueryHelper.GetInteger("formrecordid", 0);

            string currentRecord = "";

            // Edit record
            if (formRecordId > 0)
            {
                currentRecord = GetString("BizForm_Edit_EditRecord.EditRecord");
                if (!RequestHelper.IsPostBack())
                {
                    chkSendNotification.Checked = false;
                    chkSendAutoresponder.Checked = false;
                }
            }
            // New record
            else
            {
                currentRecord = GetString("BizForm_Edit_EditRecord.NewRecord");
                if (!RequestHelper.IsPostBack())
                {
                    chkSendNotification.Checked = true;
                    chkSendAutoresponder.Checked = true;
                }
            }

            // Initializes page title
            string[,] breadcrumbs = new string[2, 3];
            breadcrumbs[0, 0] = GetString("BizForm_Edit_EditRecord.Data");
            breadcrumbs[0, 1] = "~/CMSModules/BizForms/Tools/BizForm_Edit_Data.aspx?formid=" + formId;
            breadcrumbs[0, 2] = "";
            breadcrumbs[1, 0] = currentRecord;
            breadcrumbs[1, 1] = "";
            breadcrumbs[1, 2] = "";

            CurrentMaster.Title.Breadcrumbs = breadcrumbs;

            bfi = BizFormInfoProvider.GetBizFormInfo(formId);
            EditedObject = bfi;

            if (!RequestHelper.IsPostBack())
            {
                // Get form info
                if (bfi != null)
                {
                    // Set form
                    formElem.FormName = bfi.FormName;
                    formElem.ItemID = formRecordId;
                    formElem.ShowPrivateFields = true;
                }
            }

            formElem.OnBeforeSave += formElem_OnBeforeSave;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'ReadData' permission
        CheckPermissions("ReadData");

        // Get form ID from url
        formId = QueryHelper.GetInteger("formid", 0);

        // Register scripts
        ScriptHelper.RegisterDialogScript(this);
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "SelectFields", ScriptHelper.GetScript("function SelectFields() { modalDialog('" +
            ResolveUrl("~/CMSModules/BizForms/Tools/BizForm_Edit_Data_SelectFields.aspx") + "?formid=" + formId + "'  ,'BizFormFields', 500, 500); }"));
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Edit", ScriptHelper.GetScript(
           "function EditRecord(formId, recordId) { " +
           "  document.location.replace('BizForm_Edit_EditRecord.aspx?formID=' + formId + '&formRecordID=' + recordId); } "
           ));

        // Prepare header actions
        string[,] actions = new string[2, 6];
        // New record link
        actions[0, 0] = HeaderActions.TYPE_HYPERLINK;
        actions[0, 1] = GetString("bizform_edit_data.newrecord");
        actions[0, 2] = null;
        actions[0, 3] = ResolveUrl("BizForm_Edit_EditRecord.aspx?formid=" + formId.ToString());
        actions[0, 4] = null;
        actions[0, 5] = GetImageUrl("CMSModules/CMS_Form/newrecord.png");
        // Select fields link
        actions[1, 0] = HeaderActions.TYPE_HYPERLINK;
        actions[1, 1] = GetString("bizform_edit_data.selectdisplayedfields");
        actions[1, 2] = null;
        actions[1, 3] = "javascript:SelectFields();";
        actions[1, 4] = null;
        actions[1, 5] = GetImageUrl("CMSModules/CMS_Form/selectfields16.png");

        CurrentMaster.HeaderActions.Actions = actions;

        // Initialize unigrid
        gridData.OnExternalDataBound += gridData_OnExternalDataBound;
        gridData.OnLoadColumns += gridData_OnLoadColumns;
        gridData.OnAction += gridData_OnAction;

        // Get BizFormInfo object
        bfi = BizFormInfoProvider.GetBizFormInfo(formId);
        EditedObject = bfi;

        if (bfi != null)
        {
            dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);
            if (dci != null)
            {
                className = dci.ClassName;

                // Set alternative form and data container
                gridData.ObjectType = BizFormItemProvider.GetObjectType(className);
                gridData.FilterFormName = className + "." + "filter";
                gridData.FilterFormData = bfi;

                // Get primary column name
                gridData.OrderBy = primaryColumn = GetPrimaryColumn(FormInfo, bfi.FormName);
            }
        }
    }