Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!QueryHelper.ValidateHash("hash") || Parameters == null)
        {
            return;
        }

        txtText.Editor.Language = LanguageEnum.HTMLMixed;
        txtText.Editor.FullScreenParentElementID = "divContent";

        // Set window title and image
        PageTitle.TitleText = GetString("EditingFormControl.TitleText");
        // Set macro options using the querystring argument
        bool allowMacros = ValidationHelper.GetBoolean(Parameters["allowmacros"], true);

        txtText.Editor.ShowInsertMacro = allowMacros;
        if (allowMacros)
        {
            string        resolverName = ValidationHelper.GetString(Parameters["resolvername"], string.Empty);
            MacroResolver resolver     = MacroResolverStorage.GetRegisteredResolver(resolverName);
            txtText.Resolver = resolver;
        }

        // Register macro scripts
        RegisterModalPageScripts();
        RegisterEscScript();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CustomTableItem != null)
        {
            DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(CustomTableItem.CustomTableClassName);
            if (dci != null)
            {
                // Get class form definition
                FormInfo fi = FormHelper.GetFormInfo(dci.ClassName, false);

                string         fieldCaption;
                FormFieldInfo  ffi;
                IDataContainer item = CustomTableItem;

                StringBuilder sb = new StringBuilder();
                sb.Append("<table class=\"table table-hover\">");
                // Table header
                sb.AppendFormat("<thead><tr class=\"unigrid-head\"><th>{0}</th><th class=\"main-column-100\">{1}</th></tr></thead><tbody>", GetString("customtable.data.nametitle"), GetString("customtable.data.namevalue"));

                // Get macro resolver
                MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + dci.ClassName);

                // Go through the columns
                foreach (string columnName in item.ColumnNames)
                {
                    // Get field caption
                    ffi = fi.GetFormField(columnName);
                    if (ffi == null)
                    {
                        fieldCaption = columnName;
                    }
                    else
                    {
                        string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);
                        if (string.IsNullOrEmpty(caption))
                        {
                            fieldCaption = columnName;
                        }
                        else
                        {
                            fieldCaption = ResHelper.LocalizeString(caption);
                        }
                    }

                    sb.AppendFormat("<tr><td><strong>{0}</strong></td><td class=\"wrap-normal\">{1}</td></tr>", fieldCaption, HTMLHelper.HTMLEncode(ValidationHelper.GetString(item.GetValue(columnName), String.Empty)));
                }
                sb.Append("</tbody></table>");

                ltlContent.Text = sb.ToString();
            }
            else
            {
                ltlContent.Text = GetString("editedobject.notexists");
            }
        }
        else
        {
            ltlContent.Text = GetString("editedobject.notexists");
        }
    }
    /// <summary>
    /// Page load.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Set control style and css class
        if (!string.IsNullOrEmpty(ControlStyle))
        {
            txtMacro.Editor.Attributes.Add("style", ControlStyle);
        }
        if (!string.IsNullOrEmpty(CssClass))
        {
            txtMacro.Editor.CssClass = CssClass;
        }

        txtMacro.ShowAutoCompletionAbove = ShowAutoCompletionAbove;
        txtMacro.Editor.UseSmallFonts    = true;
        txtMacro.MixedMode = false;

        MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(ResolverName);

        if (resolver != null)
        {
            resolver.Settings.VirtualMode = true;
            txtMacro.Resolver             = resolver;
        }

        var ed = txtMacro.Editor;

        ed.ShowToolbar     = false;
        ed.ShowLineNumbers = false;
        ed.DynamicHeight   = false;

        string script = @"
function InsertMacroCondition" + ClientID + @"(text) {
    var hidden = document.getElementById('" + hdnValue.ClientID + @"');
    hidden.value = text;
    " + ControlsHelper.GetPostBackEventReference(btnRefresh) + @";
}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "InsertMacroCondition" + ClientID, script, true);
        ScriptHelper.RegisterDialogScript(Page);

        btnEdit.Click    += btnEdit_Click;
        btnRefresh.Click += btnRefresh_Click;

        if (txtMacro.ReadOnly)
        {
            txtMacro.Editor.Language = LanguageEnum.Text;
        }

        if (MaxWidth > 0)
        {
            pnlConditionBuilder.Attributes["style"] += " max-width: " + MaxWidth + "px;";
        }

        txtMacro.DataBind();
    }
Beispiel #4
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (!String.IsNullOrEmpty(Width))
        {
            ucEditor.Width = new Unit(Width);
        }

        if (!String.IsNullOrEmpty(Height))
        {
            ucEditor.Height = new Unit(Height);
        }

        Editor.EditorMode           = EditorModeEnum.Advanced;
        Editor.AutoSize             = AutoSize;
        Editor.Language             = Language;
        Editor.ShowBookmarks        = ShowBookmarks;
        Editor.EnableSections       = EnableSections;
        Editor.EnablePositionMember = EnablePositionMember;
        Editor.RegularExpression    = RegularExpression;
        Editor.ShowLineNumbers      = ShowLineNumbers;

        ucEditor.SingleLineMode  = SingleLineMode;
        ucEditor.MixedMode       = !SingleMacroMode;
        ucEditor.ResolverName    = ResolverName;
        ucEditor.EnableViewState = EnableViewState;

        // Initialize insert macro button
        btnInsertMacro.OnClientClick = ucEditor.Editor.EditorID + ".createInsertMacroWindow(); return false;";
        btnInsertMacro.ToolTip       = GetString("macroeditor.insertmacro");
        if (SingleLineMode)
        {
            plcInsertMacro.Visible = true;
        }

        if (ShowMacroSelector)
        {
            plcMacroSelector.Visible = true;

            ucMacroSelector.Resolver             = MacroResolverStorage.GetRegisteredResolver(ResolverName);
            ucMacroSelector.ExtendedTextAreaElem = Editor.EditorID;
            ucMacroSelector.TextAreaID           = Editor.ClientID;
            ucMacroSelector.ShowMacroTreeAbove   = true;
        }

        if (SupportPasteImages)
        {
            RegisterPasteScript();
        }
    }
Beispiel #5
0
    private void AddRules(InfoDataSet <MacroRuleInfo> ds)
    {
        var resolver = MacroResolverStorage.GetRegisteredResolver(ResolverName);

        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            bool add = true;
            if (resolver != null)
            {
                // Check the required data, all specified data have to be present in the resolver
                string requiredData = ValidationHelper.GetString(dr["MacroRuleRequiredData"], "");
                if (!string.IsNullOrEmpty(requiredData))
                {
                    var required = requiredData.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var req in required)
                    {
                        if (!resolver.IsDataItemAvailable(req))
                        {
                            add = false;
                            break;
                        }
                        else if (!IsRuleApplicableForSite(req))
                        {
                            add = false;
                            break;
                        }
                    }
                }
            }

            if (add)
            {
                var      ruleId = dr["MacroRuleID"].ToString();
                ListItem item   = new ListItem(dr["MacroRuleDisplayName"].ToString(), ruleId);
                lstRules.Items.Add(item);

                // Save the tooltip
                RulesTooltips[ruleId] = ResHelper.LocalizeString(ValidationHelper.GetString(dr["MacroRuleDescription"], ""));
            }
        }
    }
Beispiel #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get custom table id from url
        customTableId = QueryHelper.GetInteger("customtableid", 0);

        dci = DataClassInfoProvider.GetDataClassInfo(customTableId);

        // Set edited object
        EditedObject = dci;

        // If class exists and is custom table
        if ((dci != null) && dci.ClassIsCustomTable)
        {
            // Ensure that object belongs to current site or user has access to site manager
            if (!CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) && (dci.AssignedSites[SiteContext.CurrentSiteName] == null))
            {
                RedirectToInformation(GetString("general.notassigned"));
            }

            PageTitle.TitleText = GetString("customtable.data.selectdisplayedfields");
            CurrentMaster.DisplayActionsPanel = true;

            // Check 'Read' permission
            if (!dci.CheckPermissions(PermissionsEnum.Read, SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser))
            {
                ShowError(String.Format(GetString("customtable.permissiondenied.read"), dci.ClassName));
                plcContent.Visible = false;
                return;
            }

            HeaderActions.AddAction(new HeaderAction
            {
                Text          = GetString("UniSelector.SelectAll"),
                OnClientClick = "ChangeFields(true); return false;",
                ButtonStyle   = ButtonStyle.Default,
            });

            HeaderActions.AddAction(new HeaderAction
            {
                Text          = GetString("UniSelector.DeselectAll"),
                OnClientClick = "ChangeFields(false); return false;",
                ButtonStyle   = ButtonStyle.Default,
            });

            if (!RequestHelper.IsPostBack())
            {
                Hashtable reportFields = new Hashtable();

                // Get report fields
                if (!String.IsNullOrEmpty(dci.ClassShowColumns))
                {
                    reportFields.Clear();

                    foreach (string field in dci.ClassShowColumns.Split(';'))
                    {
                        // Add field key to hastable
                        reportFields[field] = null;
                    }
                }

                // Get columns names
                FormInfo fi          = FormHelper.GetFormInfo(dci.ClassName, false);
                var      columnNames = fi.GetColumnNames(false);

                if (columnNames != null)
                {
                    MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + dci.ClassName);
                    FormFieldInfo ffi;
                    ListItem      item;
                    foreach (string name in columnNames)
                    {
                        ffi = fi.GetFormField(name);

                        // Add checkboxes to the list
                        item = new ListItem(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(GetFieldCaption(ffi, name, resolver))), name);
                        if (reportFields.Contains(name))
                        {
                            // Select checkbox if field is reported
                            item.Selected = true;
                        }
                        chkListFields.Items.Add(item);
                    }
                }
            }
        }
        else
        {
            ShowError(GetString("customtable.notcustomtable"));
            CurrentMaster.FooterContainer.Visible = false;
        }
    }
Beispiel #7
0
    protected void gridData_OnLoadColumns()
    {
        if ((bfi != null) && (FormInfo != null))
        {
            // Update the actions command argument
            foreach (var action in gridData.GridActions.Actions)
            {
                ((Action)action).CommandArgument = primaryColumn;
            }

            // Get existing columns names
            var columnList = GetExistingColumns();

            string columns = bfi.FormReportFields;
            if (!string.IsNullOrEmpty(columns))
            {
                var selectedColumns = GetSelectedColumns(columns);

                columnList = columnList.Intersect(selectedColumns, StringComparer.InvariantCultureIgnoreCase).ToList();

                // Set columns which should be retrieved in query and ensure primary column
                gridData.Columns = (!columnList.Contains(primaryColumn, StringComparer.InvariantCultureIgnoreCase) ? "[" + primaryColumn + "],[" : "[") + columnList.Join("],[") + "]";
            }

            // Get macro resolver for current form
            MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + dci.ClassName);

            // Loop trough all columns
            int lastIndex = columnList.Count - 1;
            for (int i = 0; i <= lastIndex; i++)
            {
                string column = columnList[i];

                // Get field caption
                FormFieldInfo ffi = FormInfo.GetFormField(column);

                string fieldCaption;
                if (ffi == null)
                {
                    fieldCaption = column;
                }
                else
                {
                    string caption = ffi.GetDisplayName(resolver);
                    fieldCaption = (String.IsNullOrEmpty(caption)) ? column : ResHelper.LocalizeString(caption);
                }

                Column columnDefinition = new Column
                {
                    Caption            = fieldCaption,
                    Source             = column,
                    ExternalSourceName = ((ffi != null) && ffi.DataType.Equals(FieldDataType.Date, StringComparison.OrdinalIgnoreCase)) ? DATE_TRANSFORMATION : null,
                    AllowSorting       = true,
                    Wrap = false
                };

                if (i == lastIndex)
                {
                    // Stretch last column
                    columnDefinition.Width = "100%";
                }

                gridData.GridColumns.Columns.Add(columnDefinition);
            }
        }
    }
    protected void gridData_OnLoadColumns()
    {
        if ((CustomTableClassInfo != null) && (FormInfo != null))
        {
            // Update the actions command argument
            foreach (Action action in gridData.GridActions.Actions)
            {
                action.CommandArgument = ti.IDColumn;
            }

            string        columnNames = null;
            List <string> columnList;

            string columns = CustomTableClassInfo.ClassShowColumns;
            if (string.IsNullOrEmpty(columns))
            {
                columnList = new List <string>();
                columnList.AddRange(GetExistingColumns(false).Take(5));

                // Show info message
                ShowInformation(GetString("customtable.columnscount.default"));
            }
            else
            {
                // Get existing columns names
                List <string> existingColumns = GetExistingColumns(true);

                // Get selected columns
                List <string> selectedColumns = GetSelectedColumns(columns);

                columnList = new List <string>();
                StringBuilder sb = new StringBuilder();

                // Remove non-existing columns
                foreach (string col in selectedColumns)
                {
                    int index = existingColumns.BinarySearch(col, StringComparer.InvariantCultureIgnoreCase);
                    if (index >= 0)
                    {
                        string colName = existingColumns[index];
                        columnList.Add(colName);
                        sb.Append(",[", colName, "]");
                    }
                }

                // Ensure item order column
                selectedColumns.Sort();
                if ((selectedColumns.BinarySearch("ItemOrder", StringComparer.InvariantCultureIgnoreCase) < 0) && HasItemOrderField)
                {
                    sb.Append(",[ItemOrder]");
                }

                // Ensure itemid column
                if (selectedColumns.BinarySearch(ti.IDColumn, StringComparer.InvariantCultureIgnoreCase) < 0)
                {
                    sb.Insert(0, ",[" + ti.IDColumn + "]");
                }

                columnNames = sb.ToString().TrimStart(',');
            }

            // Get macro resolver
            MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + CustomTableClassInfo.ClassName);

            // Loop trough all columns
            for (int i = 0; i < columnList.Count; i++)
            {
                string column = columnList[i];

                // Get field caption
                FormFieldInfo ffi          = FormInfo.GetFormField(column);
                string        fieldCaption = string.Empty;
                if (ffi == null)
                {
                    fieldCaption = column;
                }
                else
                {
                    string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);
                    fieldCaption = (caption == string.Empty) ? column : ResHelper.LocalizeString(caption);
                }

                Column columnDefinition = new Column
                {
                    Caption            = fieldCaption,
                    Source             = column,
                    ExternalSourceName = column,
                    AllowSorting       = true,
                    Wrap = false
                };

                if (i == columnList.Count - 1)
                {
                    // Stretch last column
                    columnDefinition.Width = "100%";
                }

                gridData.GridColumns.Columns.Add(columnDefinition);
            }

            // Set column names
            gridData.Columns = columnNames;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (EditedObject == null)
        {
            RedirectToAccessDenied(GetString("general.invalidparameters"));
        }

        Save += btnOK_Click;

        var user = MembershipContext.AuthenticatedUser;

        // Check permissions for Forms application
        if (!user.IsAuthorizedPerUIElement("cms.form", "Form"))
        {
            RedirectToUIElementAccessDenied("cms.form", "Form");
        }

        // Check 'ReadData' permission
        if (!user.IsAuthorizedPerResource("cms.form", "ReadData", SiteInfoProvider.GetSiteName(FormInfo.FormSiteID)))
        {
            RedirectToAccessDenied("cms.form", "ReadData");
        }

        // Check authorized roles for this form
        if (!FormInfo.IsFormAllowedForUser(MembershipContext.AuthenticatedUser.UserName, SiteContext.CurrentSiteName))
        {
            RedirectToAccessDenied(GetString("Bizforms.FormNotAllowedForUserRoles"));
        }

        List <String> columnNames  = null;
        DataClassInfo dci          = null;
        Hashtable     reportFields = new Hashtable();
        FormInfo      fi           = null;

        // Initialize controls
        PageTitle.TitleText = GetString("BizForm_Edit_Data_SelectFields.Title");
        CurrentMaster.DisplayActionsPanel = true;

        HeaderActions.AddAction(new HeaderAction
        {
            Text          = GetString("UniSelector.SelectAll"),
            OnClientClick = "ChangeFields(true); return false;",
            ButtonStyle   = ButtonStyle.Default,
        });

        HeaderActions.AddAction(new HeaderAction
        {
            Text          = GetString("UniSelector.DeselectAll"),
            OnClientClick = "ChangeFields(false); return false;",
            ButtonStyle   = ButtonStyle.Default,
        });

        if (!RequestHelper.IsPostBack())
        {
            if (FormInfo != null)
            {
                // Get dataclass info
                dci = DataClassInfoProvider.GetDataClassInfo(FormInfo.FormClassID);

                if (dci != null)
                {
                    // Get columns names
                    fi = FormHelper.GetFormInfo(dci.ClassName, false);

                    columnNames = fi.GetColumnNames(false, i => i.System);
                }

                // Get report fields
                if (String.IsNullOrEmpty(FormInfo.FormReportFields))
                {
                    reportFields = LoadReportFields(columnNames);
                }
                else
                {
                    reportFields.Clear();

                    foreach (string field in FormInfo.FormReportFields.Split(';'))
                    {
                        // Add field key to hastable
                        reportFields[field] = null;
                    }
                }

                if (columnNames != null)
                {
                    FormFieldInfo ffi  = null;
                    ListItem      item = null;

                    MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + FormInfo.ClassName);

                    foreach (string name in columnNames)
                    {
                        ffi = fi.GetFormField(name);

                        // Add checkboxes to the list
                        item = new ListItem(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(GetFieldCaption(ffi, name, resolver))), name);
                        if (reportFields.Contains(name))
                        {
                            // Select checkbox if field is reported
                            item.Selected = true;
                        }
                        chkListFields.Items.Add(item);
                    }
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Attach events
        btnAutoIndent.Click      += btnAutoIndent_Click;
        btnDelete.Click          += (btnDelete_Click);
        btnIndent.Click          += btnIndent_Click;
        btnUnindent.Click        += btnUnindent_Click;
        btnChangeOperator.Click  += new EventHandler(btnChangeOperator_Click);
        btnChangeParameter.Click += new EventHandler(btnChangeParameter_Click);
        btnMove.Click            += new EventHandler(btnMove_Click);
        btnCancel.Click          += new EventHandler(btnCancel_Click);
        btnSetParameter.Click    += new EventHandler(btnSetParameter_Click);
        btnViewCode.Click        += btnViewCode_Click;
        btnAddClause.Click       += new EventHandler(btnAddClause_Click);
        btnClearAll.Click        += btnClearAll_Click;
        txtFilter.TextChanged    += new EventHandler(btnFilter_Click);

        btnFilter.Text       = GetString("general.filter");
        btnSetParameter.Text = GetString("general.ok");
        btnCodeOK.Text       = GetString("general.ok");
        btnCancel.Text       = GetString("general.cancel");
        btnIndent.ScreenReaderDescription     = btnIndent.ToolTip = GetString("macros.macrorule.indent");
        btnUnindent.ScreenReaderDescription   = btnUnindent.ToolTip = GetString("macros.macrorule.unindent");
        btnAutoIndent.ScreenReaderDescription = btnAutoIndent.ToolTip = GetString("macros.macrorule.autoindent");
        btnDelete.ScreenReaderDescription     = btnDelete.ToolTip = GetString("general.delete");
        btnClearAll.ScreenReaderDescription   = btnClearAll.ToolTip = GetString("macro.macrorule.clearall");
        btnViewCode.ScreenReaderDescription   = btnViewCode.ToolTip = GetString("macros.macrorule.viewcode");

        btnIndent.OnClientClick     = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnUnindent.OnClientClick   = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnDelete.OnClientClick     = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; } else { if (!confirm('" + GetString("macros.macrorule.deleteconfirmation") + "')) { return false; }}";
        btnAutoIndent.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.deleteautoindent")) + ")) { return false; }";
        btnClearAll.OnClientClick   = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.clearall.confirmation")) + ")) { return false; }";

        lstRules.Attributes.Add("ondblclick", ControlsHelper.GetPostBackEventReference(btnAddClause, null));

        pnlViewCode.Visible = false;

        // Basic form
        formElem.SubmitButton.Visible = false;
        formElem.SiteName             = SiteContext.CurrentSiteName;

        titleElem.TitleText   = GetString("macros.macrorule.changeparameter");
        btnAddaClause.ToolTip = GetString("macros.macrorule.addclause");
        btnAddaClause.Click  += btnAddClause_Click;

        // Drop cue
        Panel pnlCue = new Panel();

        pnlCue.ID       = "pnlCue";
        pnlCue.CssClass = "MacroRuleCue";
        pnlCondtion.Controls.Add(pnlCue);

        pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
        pnlCue.Style.Add("display", "none");

        // Create drag and drop extender
        extDragDrop    = new DragAndDropExtender();
        extDragDrop.ID = "extDragDrop";
        extDragDrop.TargetControlID     = pnlCondtion.ID;
        extDragDrop.DragItemClass       = "MacroRule";
        extDragDrop.DragItemHandleClass = "MacroRuleHandle";
        extDragDrop.DropCueID           = pnlCue.ID;
        extDragDrop.OnClientDrop        = "OnDropRule";
        pnlCondtion.Controls.Add(extDragDrop);

        // Load the rule set
        if (!RequestHelper.IsPostBack())
        {
            if (ShowGlobalRules || !string.IsNullOrEmpty(RuleCategoryNames))
            {
                string where = (ShowGlobalRules ? "MacroRuleResourceName IS NULL OR MacroRuleResourceName = ''" : "");

                // Append rules module name condition
                if (!string.IsNullOrEmpty(RuleCategoryNames))
                {
                    bool          appendComma = false;
                    StringBuilder sb          = new StringBuilder();
                    string[]      names       = RuleCategoryNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string n in names)
                    {
                        string name = "'" + SqlHelper.GetSafeQueryString(n.Trim(), false) + "'";
                        if (appendComma)
                        {
                            sb.Append(",");
                        }
                        sb.Append(name);
                        appendComma = true;
                    }
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleResourceName IN (" + sb.ToString() + ")", "OR");
                }

                // Append require context condition
                switch (DisplayRuleType)
                {
                case 1:
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleRequiresContext = 0", "AND");
                    break;

                case 2:
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleRequiresContext = 1", "AND");
                    break;
                }

                // Select only enabled rules
                where = SqlHelper.AddWhereCondition(where, "MacroRuleEnabled = 1");

                DataSet ds = MacroRuleInfoProvider.GetMacroRules(where, "MacroRuleDisplayName", 0, "MacroRuleID, MacroRuleDisplayName, MacroRuleDescription, MacroRuleRequiredData");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(ResolverName);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        bool add = true;
                        if (resolver != null)
                        {
                            // Check the required data, all specified data have to be present in the resolver
                            string requiredData = ValidationHelper.GetString(dr["MacroRuleRequiredData"], "");
                            if (!string.IsNullOrEmpty(requiredData))
                            {
                                string[] required = requiredData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var req in required)
                                {
                                    if (!resolver.IsDataItemAvailable(req))
                                    {
                                        add = false;
                                        break;
                                    }
                                }
                            }
                        }

                        if (add)
                        {
                            var      ruleId = dr["MacroRuleID"].ToString();
                            ListItem item   = new ListItem(dr["MacroRuleDisplayName"].ToString(), ruleId);
                            lstRules.Items.Add(item);

                            // Save the tooltip
                            RulesTooltips[ruleId] = ResHelper.LocalizeString(ValidationHelper.GetString(dr["MacroRuleDescription"], ""));
                        }
                    }
                }
                if (lstRules.Items.Count > 0)
                {
                    lstRules.SelectedIndex = 0;
                }
            }
        }

        // Make sure that one user click somewhere else than to any rule, selection will disappear
        pnlCondtion.Attributes["onclick"] = "if (!doNotDeselect && !isCTRL) { jQuery('.RuleSelected').removeClass('RuleSelected'); document.getElementById('" + hdnSelected.ClientID + "').value = ';'; }; doNotDeselect = false;";

        LoadFormDefinition(false);

        // Set the default button for parameter edit dialog so that ENTER key works to submit the parameter value
        pnlParameterPopup.DefaultButton = btnSetParameter.ID;

        // Ensure correct edit dialog show/hide (because of form controls which cause postback)
        btnSetParameter.OnClientClick = "HideParamEdit();";
        btnCancel.OnClientClick       = "HideParamEdit();";
        if (ShowParameterEdit)
        {
            mdlDialog.Show();
        }

        if (!string.IsNullOrEmpty(hdnScroll.Value))
        {
            // Preserve scroll position
            ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "MacroRulesScroll", "setTimeout('setScrollPosition()', 100);", true);
        }

        // Add tooltips to the rules in the list
        foreach (ListItem item in lstRules.Items)
        {
            if (RulesTooltips.ContainsKey(item.Value))
            {
                item.Attributes.Add("title", RulesTooltips[item.Value]);
            }
        }
    }
    protected void gridData_OnLoadColumns()
    {
        if ((bfi != null) && (FormInfo != null))
        {
            var    columnList = new List <string>();
            string columns    = bfi.FormReportFields;
            if (string.IsNullOrEmpty(columns))
            {
                columnList = GetExistingColumns();
            }
            else
            {
                // Get existing columns names
                var existingColumns = GetExistingColumns();

                // Get selected columns
                var selectedColumns = GetSelectedColumns(columns);

                columns     = string.Empty;
                columnNames = string.Empty;
                StringBuilder sb = new StringBuilder();

                // Remove nonexisting columns
                foreach (string col in selectedColumns)
                {
                    if (existingColumns.Contains(col))
                    {
                        columnList.Add(col);
                        sb.Append(",[").Append(col).Append("]");
                    }
                }
                columnNames = sb.ToString();

                // Ensure primary key
                if (!(columnNames.Contains(primaryColumn) || columnNames.Contains(primaryColumn)))
                {
                    columnNames = ",[" + primaryColumn + "]" + columnNames;
                }

                columnNames = columnNames.TrimStart(',');
            }

            // Get macro resolver for current form
            MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + dci.ClassName);

            // Loop trough all columns
            for (int i = 0; i < columnList.Count; i++)
            {
                string column = columnList[i];

                // Get field caption
                FormFieldInfo ffi = FormInfo.GetFormField(column);

                string fieldCaption = null;
                if (ffi == null)
                {
                    fieldCaption = column;
                }
                else
                {
                    string caption = ffi.GetDisplayName(resolver);
                    fieldCaption = (string.IsNullOrEmpty(caption)) ? column : ResHelper.LocalizeString(caption);
                }

                Column columnDefinition = new Column
                {
                    Caption      = fieldCaption,
                    Source       = column,
                    AllowSorting = true,
                    Wrap         = false
                };

                if (i == columnList.Count - 1)
                {
                    // Stretch last column
                    columnDefinition.Width = "100%";
                }

                gridData.GridColumns.Columns.Add(columnDefinition);
            }
        }
    }