Ejemplo n.º 1
0
    /// <summary>
    /// Combines widget info with default XML system propertiers.
    /// </summary>
    /// <param name="fi">Widget form info</param>
    /// <param name="wi">Widget info object</param>
    public DataRow CombineWithDefaultValues(FormInfo fi, WidgetInfo wi)
    {
        if ((!String.IsNullOrEmpty(wi.WidgetDefaultValues)) && (String.Compare(wi.WidgetDefaultValues, "<form></form>", false) != 0))
        {
            // Apply changed values
            DataRow dr = fi.GetDataRow();
            fi.LoadDefaultValues(dr, wi.WidgetDefaultValues);

            return(dr);
        }

        return(fi.GetDataRow());
    }
    /// <summary>
    /// Returns the form definition for the webpart zone properties.
    /// </summary>
    private FormInfo BuildFormInfo(WebPartZoneInstance webPartZone)
    {
        FormInfo fi = null;

        string formDefinition = String.Empty;

        // Dashboard zone properties
        if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.Dashboard))
        {
            formDefinition = File.ReadAllText(Server.MapPath("~/CMSModules/PortalEngine/Controls/WebParts/WebPartZone_Dashboard_Properties.xml"));
        }
        // Classic webpart/widget properties
        else
        {
            formDefinition = File.ReadAllText(Server.MapPath("~/CMSModules/PortalEngine/Controls/WebParts/WebPartZone_Properties.xml"));
        }

        if (!String.IsNullOrEmpty(formDefinition))
        {
            // Load properties
            fi = new FormInfo(formDefinition);
            fi.UpdateExistingFields(fi);

            DataRow dr = fi.GetDataRow();
            LoadDataRowFromWebPartZone(dr, webPartZone);
        }

        return(fi);
    }
    /// <summary>
    /// Loads DataRow for BasicForm with data from FormFieldInfo settings and optionally with form control's default values.
    /// </summary>
    /// <param name="loadDefaultValues">Indicates if data container should be initialized with form control's default data</param>
    private DataRowContainer GetData(bool loadDefaultValues)
    {
        DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow(loadDefaultValues));

        if (loadDefaultValues)
        {
            // Load default values for visible properties (values of hidden form control properties shouldn't be stored in form definition)
            FormInfo.LoadDefaultValues(result, FormResolveTypeEnum.None, true);
        }

        if (Settings != null)
        {
            // Load settings of the existing field
            foreach (string columnName in Settings.Keys)
            {
                if (result.ContainsColumn(columnName))
                {
                    object value        = Settings[columnName];
                    var    settingField = FormInfo.GetFormField(columnName);

                    if (!String.IsNullOrEmpty(Convert.ToString(value)) && IsDataTypeValid(value, settingField))
                    {
                        result[columnName] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, settingField.DataType, value, SystemContext.EnglishCulture);
                    }
                }
            }
        }
        return(result);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Load parameters from data form.
    /// </summary>
    protected void LoadParameters()
    {
        if (ReportInfo != null)
        {
            // Set the form
            FormInfo fi = new FormInfo(ReportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();
            if ((!RequestHelper.IsPostBack()) || (ForceLoadDefaultValues))
            {
                fi.LoadDefaultValues(dr, true);
            }
            else
            {
                if ((!ForceLoadDefaultValues) && (formElem.DataRow != null))
                {
                    dr = formElem.DataRow;
                }
            }

            // show filter - based on DisplayFilter and number of visible elements
            mDisplayFilterResult = DisplayFilter && (fi.GetFormElements(true, false).Count > 0);

            formElem.DataRow = dr;
            formElem.SubmitButton.Visible = mDisplayFilterResult;
            formElem.FormInformation      = fi;
            formElem.SubmitButton.Text    = GetString("Report_View.btnUpdate");
            formElem.SiteName             = CMSContext.CurrentSiteName;
            formElem.ShowPrivateFields    = true;
            formElem.Mode    = FormModeEnum.Insert;
            formElem.Visible = mDisplayFilterResult;
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Show preview
    /// </summary>
    private void ShowPreview()
    {
        divPanelHolder.Visible = false;
        categoryList.Visible   = false;
        pnlVersions.Visible    = false;

        if (reportInfo != null)
        {
            pnlPreview.Visible = true;

            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();

            fi.LoadDefaultValues(dr, true);

            // ReportGraph.ContextParameters
            ctrlReportTable.ReportParameters = dr;

            // Prepare fully qualified graph name = with reportname
            if (tableInfo != null)
            {
                string fullReportGraphName = reportInfo.ReportName + "." + tableInfo.TableName;
                ctrlReportTable.Parameter = fullReportGraphName;
            }
            ctrlReportTable.TableInfo = tableInfo;


            ctrlReportTable.ReloadData(true);
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Returns the form definition for the web part zone properties.
    /// </summary>
    private FormInfo BuildFormInfo(WebPartZoneInstance webPartZone)
    {
        FormInfo fi = null;

        string formDefinition = String.Empty;

        // Dashboard zone properties
        if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.Dashboard))
        {
            formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "Dashboard.xml");
        }
        // UI page template properties
        else if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.UI))
        {
            formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "UI.xml");
        }
        // Classic web part/widget properties
        else
        {
            formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "Standard.xml");
        }

        if (!String.IsNullOrEmpty(formDefinition))
        {
            // Load properties
            fi = new FormInfo(formDefinition);
            fi.UpdateExistingFields(fi);

            DataRow dr = fi.GetDataRow();
            LoadDataRowFromWebPartZone(dr, webPartZone);
        }

        return(fi);
    }
    /// <summary>
    /// Show graph in preview mode
    /// </summary>
    private void ShowPreview()
    {
        FormPanelHolder.Visible = false;
        pnlVersions.Visible     = false;

        if (mReportInfo != null)
        {
            pnlPreview.Visible = true;

            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow defaultValues = fi.GetDataRow(false);

            fi.LoadDefaultValues(defaultValues, true);

            ctrlReportGraph.ReportParameters = defaultValues;
            ctrlReportGraph.Visible          = true;

            // Prepare fully qualified graph name = with reportname
            string fullReportGraphName = mReportInfo.ReportName + "." + mReportGraphInfo.GraphName;
            ctrlReportGraph.ReportGraphInfo = mReportGraphInfo;
            ctrlReportGraph.Parameter       = fullReportGraphName;

            ctrlReportGraph.ReloadData(true);
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Load parameters from data form.
    /// </summary>
    private void LoadParameters()
    {
        if (ReportInfo != null)
        {
            // Set the form
            FormInfo fi = new FormInfo(ReportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow(false);
            if (!RequestHelper.IsPostBack() || ForceLoadDefaultValues || !DisplayFilter)
            {
                fi.LoadDefaultValues(dr, true);
            }
            else if ((!ForceLoadDefaultValues) && (formParameters.DataRow != null))
            {
                dr = formParameters.DataRow;
            }

            // Show filter - based on DisplayFilter and number of visible elements
            mDisplayFilterResult = DisplayFilter && (fi.GetFormElements(true, false).Any());

            formParameters.DataRow = dr;
            formParameters.SubmitButton.Visible = mDisplayFilterResult;
            formParameters.SubmitButton.RegisterHeaderAction = false;
            formParameters.FormInformation             = fi;
            formParameters.SubmitButton.ResourceString = "report_view.btnupdate";
            formParameters.SiteName = SiteContext.CurrentSiteName;
            formParameters.Mode     = FormModeEnum.Insert;
            formParameters.Visible  = mDisplayFilterResult;

            wasInit = true;
        }
    }
Ejemplo n.º 9
0
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        SetCulture();

        IFormatProvider culture        = DateTimeHelper.DefaultIFormatProvider;
        IFormatProvider currentCulture = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.IetfLanguageTag);

        reportId = ValidationHelper.GetInteger(Request.QueryString["reportid"], 0);
        ReportInfo ri = ReportInfoProvider.GetReportInfo(reportId);

        if (ri != null)
        {
            string[] httpParameters = ValidationHelper.GetString(Request.QueryString["parameters"], "").Split(";".ToCharArray());

            FormInfo fi = new FormInfo(ri.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();

            if (httpParameters.Length > 1)
            {
                string[] parameters = new string[httpParameters.Length / 2];

                // Put values to given data row
                for (int i = 0; i < httpParameters.Length; i = i + 2)
                {
                    if (dr.Table.Columns.Contains(httpParameters[i]))
                    {
                        if (dr.Table.Columns[httpParameters[i]].DataType != typeof(DateTime))
                        {
                            dr[httpParameters[i]] = httpParameters[i + 1];
                        }
                        else
                        {
                            if (httpParameters[i + 1] != String.Empty)
                            {
                                dr[httpParameters[i]] = Convert.ToDateTime(httpParameters[i + 1], culture).ToString(currentCulture);
                            }
                        }
                    }
                }

                dr.AcceptChanges();

                DisplayReport1.LoadFormParameters = false;
                DisplayReport1.ReportName         = ri.ReportName;
                DisplayReport1.DisplayFilter      = false;
                DisplayReport1.ReportParameters   = dr;
            }
            else
            {
                DisplayReport1.ReportName    = ri.ReportName;
                DisplayReport1.DisplayFilter = false;
            }
            this.Page.Title = GetString("Report_Print.lblPrintReport") + " " + ri.ReportDisplayName;
        }
    }
Ejemplo n.º 10
0
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        SetCulture();

        IFormatProvider culture = DateTimeHelper.DefaultIFormatProvider;
        IFormatProvider currentCulture = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.IetfLanguageTag);

        reportId = ValidationHelper.GetInteger(Request.QueryString["reportid"], 0);
        ReportInfo ri = ReportInfoProvider.GetReportInfo(reportId);
        if (ri != null)
        {
            string[] httpParameters = ValidationHelper.GetString(Request.QueryString["parameters"], "").Split(";".ToCharArray());

            FormInfo fi = new FormInfo(ri.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();

            if (httpParameters.Length > 1)
            {
                string[] parameters = new string[httpParameters.Length / 2];

                // Put values to given data row
                for (int i = 0; i < httpParameters.Length; i = i + 2)
                {
                    if (dr.Table.Columns.Contains(httpParameters[i]))
                    {
                        if (dr.Table.Columns[httpParameters[i]].DataType != typeof(DateTime))
                        {
                            dr[httpParameters[i]] = httpParameters[i + 1];
                        }
                        else
                        {
                            if (httpParameters[i + 1] != String.Empty)
                            {
                                dr[httpParameters[i]] = Convert.ToDateTime(httpParameters[i + 1], culture).ToString(currentCulture);
                            }
                        }
                    }
                }

                dr.AcceptChanges();

                DisplayReport1.LoadFormParameters = false;
                DisplayReport1.ReportName = ri.ReportName;
                DisplayReport1.DisplayFilter = false;
                DisplayReport1.ReportParameters = dr;
            }
            else
            {
                DisplayReport1.ReportName = ri.ReportName;
                DisplayReport1.DisplayFilter = false;
            }
            this.Page.Title = GetString("Report_Print.lblPrintReport") + " " + ri.ReportDisplayName;
        }
    }
    /// <summary>
    /// Loads the from definition from selected parameter into a BasicForm control.
    /// </summary>
    /// <param name="actual">If true, data from actual hiddens are loaded</param>
    private void LoadFormDefinition(bool actual)
    {
        MacroRuleTree selected = GetSelected((actual ? hdnParamSelected.Value : hdnLastSelected.Value));

        if (selected != null)
        {
            string             paramName = (actual ? hdnParam.Value.ToLowerCSafe() : hdnLastParam.Value.ToLowerCSafe());
            MacroRuleParameter param     = selected.Parameters[paramName];
            if (param != null)
            {
                FormInfo      fi  = new FormInfo(selected.RuleParameters);
                FormFieldInfo ffi = fi.GetFormField(paramName);
                if (ffi != null)
                {
                    fi = new FormInfo();
                    fi.AddFormItem(ffi);

                    // Add fake DisplayName field
                    FormFieldInfo displayName = new FormFieldInfo();
                    displayName.Visible  = false;
                    displayName.Name     = "DisplayName";
                    displayName.DataType = FieldDataType.Text;
                    fi.AddFormItem(displayName);

                    DataRow row = fi.GetDataRow().Table.NewRow();

                    if (ffi.AllowEmpty && String.IsNullOrEmpty(param.Value))
                    {
                        if (!DataTypeManager.IsString(TypeEnum.Field, ffi.DataType))
                        {
                            row[paramName] = DBNull.Value;
                        }
                    }
                    else
                    {
                        // Convert to a proper type
                        var val = DataTypeManager.ConvertToSystemType(TypeEnum.Field, ffi.DataType, param.Value, CultureHelper.EnglishCulture);
                        if (val != null)
                        {
                            row[paramName] = val;
                        }
                    }

                    formElem.DataRow         = row;
                    formElem.FormInformation = fi;
                    formElem.ReloadData();
                }
            }
        }
    }
    /// <summary>
    /// Loads DataRow container for BasicForm with widget properties.
    /// </summary>
    private DataRowContainer GetWidgetProperties()
    {
        var result = new DataRowContainer(widgetTypeFormInfo.GetDataRow());

        foreach (var property in widgetInstance.Properties)
        {
            if (!String.IsNullOrEmpty(property.Value))
            {
                result[property.Name] = property.Value;
            }
        }

        return(result);
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Loads basicform with filter controls.
    /// </summary>
    /// <param name="bf">BasicForm control</param>
    /// <param name="fi">Form definition</param>
    /// <param name="activityType">Activity type in case the rule type is activity</param>
    private void LoadForm(BasicForm bf, FormInfo fi, string activityType = null)
    {
        bf.FormInformation      = fi;
        bf.Data                 = RuleHelper.GetDataFromCondition(Rule, fi.GetDataRow().Table, ref activityType);
        bf.SubmitButton.Visible = false;
        bf.SiteName             = SiteContext.CurrentSiteName;

        if (Rule != null)
        {
            bf.Mode = FormModeEnum.Update;
        }

        bf.ReloadData();
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Populates the form with data to be displayed
    /// </summary>
    /// <param name="formInfo">FormInfo that will be used in the form</param>
    /// <param name="metadata">Metadata of the package</param>
    private void FillFormWithData(FormInfo formInfo, ModulePackageMetadata metadata)
    {
        DataRow row = formInfo.GetDataRow();

        row["moduleDisplayName"] = HTMLHelper.HTMLEncode(metadata.Title);
        row["moduleName"]        = HTMLHelper.HTMLEncode(metadata.Id);
        row["moduleDescription"] = HTMLHelper.HTMLEncode(metadata.Description);
        row["moduleVersion"]     = HTMLHelper.HTMLEncode(metadata.Version);
        row["moduleAuthor"]      = HTMLHelper.HTMLEncode(metadata.Authors);

        dataForm.DataRow         = row;
        dataForm.FormInformation = formInfo;
        dataForm.ReloadData();
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Loads basicform with filter controls.
    /// </summary>
    /// <param name="bf">BasicForm control</param>
    /// <param name="fi">Form definition</param>
    /// <param name="activityType">Activity type in case the rule type is activity</param>
    private void LoadForm(BasicForm bf, FormInfo fi, string activityType)
    {
        bf.FormInformation        = fi;
        bf.Data                   = RuleHelper.GetDataFromCondition((RuleInfo)rule, fi.GetDataRow().Table, ref activityType);
        bf.SubmitButton.Visible   = false;
        bf.SiteName               = CMSContext.CurrentSiteName;
        bf.FieldLabelCellCssClass = "RuleSettingsLabel";
        bf.FieldLabelCssClass     = null;

        if (rule != null)
        {
            bf.Mode = FormModeEnum.Update;
        }

        bf.ReloadData();
    }
    /// <summary>
    /// Loads DataRow for BasicForm with data from FormFieldInfo settings.
    /// </summary>
    private DataRowContainer GetData()
    {
        DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow());

        if (Settings != null)
        {
            foreach (string columnName in result.ColumnNames)
            {
                if (Settings.ContainsKey(columnName) && !String.IsNullOrEmpty(Convert.ToString(Settings[columnName])))
                {
                    result[columnName] = Settings[columnName];
                }
            }
        }
        return(result);
    }
    /// <summary>
    /// Initializes inner controls.
    /// </summary>
    /// <param name="forceReload">Indicates if form with parameters should be reloaded</param>
    private void InitializeControl(bool forceReload = false)
    {
        // Init rule selector
        uniSelector.Value = mSelectedRuleName;

        MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName);

        if (mri != null)
        {
            // Show rule description
            ltlDescription.Text       = mri.MacroRuleDescription;
            txtErrorMsg.Value         = string.Empty;
            txtErrorMsg.WatermarkText = String.IsNullOrEmpty(DefaultErrorMessage) ? ResHelper.GetString("basicform.invalidinput") : DefaultErrorMessage;

            // Prepare form for rule parameters
            FormInfo fi = new FormInfo(mri.MacroRuleParameters);
            formProperties.FormInformation = fi;
            DataRow data = fi.GetDataRow();
            formProperties.DataRow = data;

            fi.LoadDefaultValues(formProperties.DataRow, FormResolveTypeEnum.AllFields);
            if ((mMacroRule != null) && (mMacroRuleTree != null) && mMacroRuleTree.RuleName.EqualsCSafe(mSelectedRuleName, true))
            {
                // Set params from rule given by Value property
                foreach (DictionaryEntry entry in mMacroRuleTree.Parameters)
                {
                    string             paramName = ValidationHelper.GetString(entry.Key, String.Empty);
                    MacroRuleParameter param     = entry.Value as MacroRuleParameter;

                    if ((param != null) && data.Table.Columns.Contains(paramName))
                    {
                        data[paramName] = param.Value;
                    }
                }

                txtErrorMsg.Value = mMacroRule.ErrorMessage;
            }

            if (forceReload)
            {
                // Reload params
                formProperties.ReloadData();
            }

            mParamsInitialized = true;
        }
    }
Ejemplo n.º 18
0
    protected void lnkLoadDefaults_Click(object sender, EventArgs e)
    {
        // Get the web part form info
        FormInfo fi = GetWebPartFormInfo();

        if (fi != null)
        {
            // Create DataRow with default data
            var dr = fi.GetDataRow();

            // Load default values
            fi.LoadDefaultValues(dr);

            // Load to the form
            form.LoadData(dr);
        }
    }
Ejemplo n.º 19
0
    /// <summary>
    /// Loads DataRow for BasicForm with data from Parameters property.
    /// </summary>
    private DataRowContainer GetData()
    {
        DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow());

        if (Parameters != null)
        {
            foreach (DataColumn column in result.DataRow.Table.Columns)
            {
                string columnName = column.ColumnName;
                if (!String.IsNullOrEmpty(Convert.ToString(Parameters[columnName])) && ValidationHelper.IsType(column.DataType, Parameters[columnName]))
                {
                    result[columnName] = Parameters[columnName];
                }
            }
        }
        return(result);
    }
Ejemplo n.º 20
0
    protected override void OnPreRender(EventArgs e)
    {
        //apply reportid condition if report was selected wia uniselector
        string     reportName = ValidationHelper.GetString(usReports.Value, String.Empty);
        ReportInfo ri         = ReportInfoProvider.GetReportInfo(reportName);

        if (ri != null)
        {
            FormInfo fi = new FormInfo(ri.ReportParameters);
            DataRow  dr = fi.GetDataRow();
            DataSet  ds = this.CurrentDataSet;

            this.ViewState["ParametersXmlData"]   = null;
            this.ViewState["ParametersXmlSchema"] = null;

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                this.ViewState["ParametersXmlData"]   = ds.GetXml();
                this.ViewState["ParametersXmlSchema"] = ds.GetXmlSchema();
            }

            if (!keepDataInWindowsHelper)
            {
                WindowHelper.Remove(CurrentGuid().ToString());
            }

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                ds = DataHelper.DataSetPivot(ds, new string[] { "ParameterName", "ParameterValue" });
                ugParameters.DataSource = ds;
                ugParameters.ReloadData();
                pnlParameters.Visible = true;
            }
            else
            {
                pnlParameters.Visible = false;
            }
        }
        else
        {
            pnlParameters.Visible = false;
        }

        base.OnPreRender(e);
    }
Ejemplo n.º 21
0
    /// <summary>
    /// Adds widget.
    /// </summary>
    private void AddWidget()
    {
        int widgetID = ValidationHelper.GetInteger(WidgetId, 0);

        // Add web part to the currently selected zone under currently selected page
        if ((widgetID > 0) && !String.IsNullOrEmpty(ZoneId))
        {
            if (wi != null)
            {
                // Ensure layout zone flag
                if (QueryHelper.GetBoolean("layoutzone", false))
                {
                    WebPartZoneInstance zone = pti.EnsureZone(ZoneId);
                    zone.LayoutZone     = true;
                    zone.WidgetZoneType = zoneType;

                    // Ensure the layout zone flag in the original page template instance
                    WebPartZoneInstance zoneInstance = templateInstance.GetZone(ZoneId);
                    if (zoneInstance != null)
                    {
                        zoneInstance.LayoutZone = true;
                        zone.WidgetZoneType     = zoneType;
                    }
                }

                // Add the widget
                WebPartInstance newWidget = templateInstance.AddWidget(ZoneId, widgetID);
                if (newWidget != null)
                {
                    // Prepare the form info to get the default properties
                    FormInfo fi = new FormInfo(wi.WidgetProperties);

                    DataRow dr = fi.GetDataRow();
                    fi.LoadDefaultValues(dr);

                    newWidget.LoadProperties(dr);

                    // Add webpart to user's last recently used
                    CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName);

                    widgetInstance = newWidget;
                }
            }
        }
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Load form info
        FormInfo = FormHelper.GetFormInfo(ClassName, true);
        if (FormInfo != null)
        {
            ScriptHelper.RegisterJQueryUI(Page);
            ScriptHelper.RegisterScriptFile(Page, "~/CMSModules/AdminControls/Controls/Class/FormBuilder/FormBuilder.js");

            // Set up callback script
            String cbReference    = Page.ClientScript.GetCallbackEventReference(this, "arg", "FormBuilder.receiveServerData", String.Empty);
            String callbackScript = "function doFieldAction(arg) {" + cbReference + "; }";
            ScriptHelper.RegisterClientScriptBlock(Page, GetType(), "FormBuilderCallback", callbackScript, true);

            // Prepare Submit button
            formElem.SubmitButton.RegisterHeaderAction = false;
            formElem.SubmitButton.OnClientClick        = formElem.SubmitImageButton.OnClientClick = "return false;";

            formElem.FormInformation = FormInfo;
            formElem.Data            = new DataRowContainer(FormInfo.GetDataRow());

            // Load form
            formElem.ReloadData();

            // Prepare error message label
            MessagesPlaceHolder.ErrorLabel.CssClass += " form-builder-error-hidden";
            MessagesPlaceHolder.ErrorText            = GetString("FormBuilder.GeneralError");

            InitUIContext(FormInfo);
        }
        else
        {
            formElem.StopProcessing = true;
            ShowError(GetString("FormBuilder.ErrorLoadingForm"));
        }

        if (RequestHelper.IsPostBack())
        {
            ProcessAjaxPostBack();
        }
    }
Ejemplo n.º 23
0
    /// <summary>
    /// Show preview.
    /// </summary>
    private void ShowPreview()
    {
        if (mReportInfo != null)
        {
            pnlPreview.Visible     = true;
            divPanelHolder.Visible = false;
            pnlVersions.Visible    = false;

            FormInfo fi            = new FormInfo(mReportInfo.ReportParameters);
            DataRow  defaultValues = fi.GetDataRow(false);

            fi.LoadDefaultValues(defaultValues, true);

            //reportGraph.ContextParameters
            ctrlReportValue.ReportParameters = defaultValues;

            ctrlReportValue.Visible   = true;
            ctrlReportValue.ValueInfo = mReportValueInfo;

            ctrlReportValue.ReloadData(true);
        }
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Loads DataRow container for BasicForm with widget properties.
    /// </summary>
    private DataRowContainer GetWidgetProperties()
    {
        var result = new DataRowContainer(widgetTypeFormInfo.GetDataRow());

        foreach (var property in widgetInstance.Properties)
        {
            if (property.Value == null)
            {
                continue;
            }

            var formField = widgetTypeFormInfo.GetFormField(property.Name);
            if (formField == null)
            {
                continue;
            }

            result[property.Name] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, formField.DataType, property.Value, CultureHelper.EnglishCulture);
        }

        return(result);
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // If data are valid
        if (bfParameters.ValidateData())
        {
            // Fill BasicForm with user data
            bfParameters.SaveData(null);
            if (bfParameters.DataRow != null)
            {

                int reportID = QueryHelper.GetInteger("ReportID", 0);
                ReportInfo ri = ReportInfoProvider.GetReportInfo(reportID);
                if (ri == null)
                {
                    return;
                }

                FormInfo fi = new FormInfo(ri.ReportParameters);
                DataRow defaultRow = fi.GetDataRow();
                fi.LoadDefaultValues(defaultRow);

                // Load default parameters to items ,where displayed in edit form not checked
                List<FormItem> items = fi.ItemsList;
                foreach (FormItem item in items)
                {
                    FormFieldInfo ffi = item as FormFieldInfo;
                    if ((ffi != null) && (!ffi.Visible))
                    {
                        bfParameters.DataRow[ffi.Name] = defaultRow[ffi.Name];
                    }
                }

                WindowHelper.Add(hdnGuid.Value, bfParameters.DataRow.Table.DataSet);
            }
            // Refreshh opener update panel script
            ltlScript.Text = ScriptHelper.GetScript("wopener.refresh (); window.close ()");
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // If data are valid
        if (bfParameters.ValidateData())
        {
            // Fill BasicForm with user data
            bfParameters.SaveData(null);
            if (bfParameters.DataRow != null)
            {
                int        reportID = QueryHelper.GetInteger("ReportID", 0);
                ReportInfo ri       = ReportInfoProvider.GetReportInfo(reportID);
                if (ri == null)
                {
                    return;
                }

                FormInfo fi         = new FormInfo(ri.ReportParameters);
                DataRow  defaultRow = fi.GetDataRow(false);
                fi.LoadDefaultValues(defaultRow, true);

                // Load default parameters to items ,where displayed in edit form not checked
                List <IField> items = fi.ItemsList;
                foreach (IField item in items)
                {
                    FormFieldInfo ffi = item as FormFieldInfo;
                    if ((ffi != null) && (!ffi.Visible))
                    {
                        bfParameters.DataRow[ffi.Name] = defaultRow[ffi.Name];
                    }
                }

                WindowHelper.Add(hdnGuid.Value, bfParameters.DataRow.Table.DataSet);
            }
            // Refreshh opener update panel script
            ltlScript.Text = ScriptHelper.GetScript("wopener.refresh (); CloseDialog()");
        }
    }
Ejemplo n.º 27
0
    /// <summary>
    /// Show preview.
    /// </summary>
    private void ShowPreview()
    {
        if (reportInfo != null)
        {
            pnlPreview.Visible     = true;
            divPanelHolder.Visible = false;
            categoryList.Visible   = false;
            pnlVersions.Visible    = false;

            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();

            fi.LoadDefaultValues(dr, true);

            //reportGraph.ContextParameters
            ctrlReportValue.ReportParameters = dr;

            ctrlReportValue.Visible   = true;
            ctrlReportValue.ValueInfo = valueInfo;

            ctrlReportValue.ReloadData(true);
        }
    }
    /// <summary>
    /// Loads the from definition from selected parameter into a BasicForm control.
    /// </summary>
    /// <param name="actual">If true, data from actual hiddens are loaded</param>
    private void LoadFormDefinition(bool actual)
    {
        MacroRuleTree selected = GetSelected((actual ? hdnParamSelected.Value : hdnLastSelected.Value));
        if (selected != null)
        {
            string paramName = (actual ? hdnParam.Value.ToLowerCSafe() : hdnLastParam.Value.ToLowerCSafe());
            MacroRuleParameter param = (MacroRuleParameter)selected.Parameters[paramName];
            if (param != null)
            {
                FormInfo fi = new FormInfo(selected.RuleParameters);
                FormFieldInfo ffi = fi.GetFormField(paramName);
                if (ffi != null)
                {
                    fi = new FormInfo(null);
                    fi.AddFormField(ffi);

                    // Add fake DisplayName field
                    FormFieldInfo displayName = new FormFieldInfo();
                    displayName.Visible = false;
                    displayName.Name = "DisplayName";
                    displayName.DataType = FormFieldDataTypeEnum.Text;
                    fi.AddFormField(displayName);

                    DataRow row = fi.GetDataRow().Table.NewRow();

                    if (ffi.AllowEmpty && string.IsNullOrEmpty(param.Value))
                    {
                        if ((ffi.DataType != FormFieldDataTypeEnum.Text) && (ffi.DataType != FormFieldDataTypeEnum.LongText))
                        {
                            row[paramName] = DBNull.Value;
                        }
                    }
                    else
                    {
                        switch (ffi.DataType)
                        {
                            case FormFieldDataTypeEnum.Decimal:
                                row[paramName] = ValidationHelper.GetDouble(param.Value, 0, CultureHelper.EnglishCulture);
                                break;

                            case FormFieldDataTypeEnum.Boolean:
                                row[paramName] = ValidationHelper.GetBoolean(param.Value, false);
                                break;

                            case FormFieldDataTypeEnum.Integer:
                                row[paramName] = ValidationHelper.GetInteger(param.Value, 0);
                                break;

                            case FormFieldDataTypeEnum.DateTime:
                                row[paramName] = ValidationHelper.GetDateTime(param.Value, DataHelper.DATETIME_NOT_SELECTED, CultureHelper.EnglishCulture);
                                break;

                            case FormFieldDataTypeEnum.GUID:
                                Guid guid = ValidationHelper.GetGuid(param.Value, Guid.Empty);
                                if (guid != Guid.Empty)
                                {
                                    row[paramName] = guid;
                                }
                                break;

                            default:
                                row[paramName] = param.Value;
                                break;
                        }
                    }

                    formElem.DataRow = row;
                    formElem.FormInformation = fi;
                    formElem.ReloadData();
                }
            }
        }
    }
    /// <summary>
    /// Returns the form definition for the web part zone properties.
    /// </summary>
    private FormInfo BuildFormInfo(WebPartZoneInstance webPartZone)
    {
        FormInfo fi = null;

        string formDefinition = String.Empty;

        // Dashboard zone properties
        if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.Dashboard))
        {
            formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "Dashboard.xml");
        }
        // UI page template properties
        else if ((pti != null) && (pti.PageTemplateType == PageTemplateTypeEnum.UI))
        {
            formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "UI.xml");
        }
        // Classic web part/widget properties
        else
        {
            formDefinition = PortalFormHelper.LoadProperties("WebPartZone", "Standard.xml");
        }

        if (!String.IsNullOrEmpty(formDefinition))
        {
            // Load properties
            fi = new FormInfo(formDefinition);
            fi.UpdateExistingFields(fi);

            DataRow dr = fi.GetDataRow();
            LoadDataRowFromWebPartZone(dr, webPartZone);
        }

        return fi;
    }
    /// <summary>
    /// Loads the from definition from selected parameter into a BasicForm control.
    /// </summary>
    /// <param name="actual">If true, data from actual hiddens are loaded</param>
    private void LoadFormDefinition(bool actual)
    {
        MacroRuleTree selected = GetSelected((actual ? hdnParamSelected.Value : hdnLastSelected.Value));
        if (selected != null)
        {
            string paramName = (actual ? hdnParam.Value.ToLowerCSafe() : hdnLastParam.Value.ToLowerCSafe());
            MacroRuleParameter param = selected.Parameters[paramName];
            if (param != null)
            {
                FormInfo fi = new FormInfo(selected.RuleParameters);
                FormFieldInfo ffi = fi.GetFormField(paramName);
                if (ffi != null)
                {
                    fi = new FormInfo();
                    fi.AddFormItem(ffi);

                    // Add fake DisplayName field
                    FormFieldInfo displayName = new FormFieldInfo();
                    displayName.Visible = false;
                    displayName.Name = "DisplayName";
                    displayName.DataType = FieldDataType.Text;
                    fi.AddFormItem(displayName);

                    DataRow row = fi.GetDataRow().Table.NewRow();

                    if (ffi.AllowEmpty && String.IsNullOrEmpty(param.Value))
                    {
                        if (!DataTypeManager.IsString(TypeEnum.Field, ffi.DataType))
                        {
                            row[paramName] = DBNull.Value;
                        }
                    }
                    else
                    {
                        // Convert to a proper type
                        var val = DataTypeManager.ConvertToSystemType(TypeEnum.Field, ffi.DataType, param.Value, CultureHelper.EnglishCulture);
                        if (val != null)
                        {
                            row[paramName] = val;
                        }
                    }

                    formElem.DataRow = row;
                    formElem.FormInformation = fi;
                    formElem.ReloadData();
                }
            }
        }
    }
    /// <summary>
    /// Show graph in preview mode
    /// </summary>
    private void ShowPreview()
    {
        FormPanelHolder.Visible = false;
        categoryList.Visible = false;
        pnlVersions.Visible = false;

        if (reportInfo != null)
        {
            pnlPreview.Visible = true;

            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();

            fi.LoadDefaultValues(dr);

            ctrlReportGraph.ReportParameters = dr;
            ctrlReportGraph.Visible = true;

            // Prepare fully qualified graph name = with reportname
            string fullReportGraphName = reportInfo.ReportName + "." + graphInfo.GraphName;
            ctrlReportGraph.ReportGraphInfo = graphInfo;
            ctrlReportGraph.Parameter = fullReportGraphName;

            ctrlReportGraph.ReloadData(true);
        }
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        if ((GraphImageWidth != 0) && (ComputedWidth == 0))
        {
            // Graph width is computed no need to create graph
            return;
        }

        Visible = true;

        errorOccurred = false;

        try
        {
            ReportTableName = Parameter;

            EnsureTableInfo();
            EnsureChildControls();

            //Test security
            if (TableInfo != null)
            {
                ri = ReportInfoProvider.GetReportInfo(TableInfo.TableReportID);
                if (ri != null)
                {
                    if (ri.ReportAccess != ReportAccessEnum.All)
                    {
                        if (!CMSContext.CurrentUser.IsAuthenticated())
                        {
                            Visible = false;
                            return;
                        }
                    }

                    EnableSubscription = EnableSubscription && (ValidationHelper.GetBoolean(TableInfo.TableSettings["SubscriptionEnabled"], true) && ri.ReportEnableSubscription);
                    if (EmailMode && !EnableSubscription)
                    {
                        this.Visible = false;
                        return;
                    }

                    //Set default parametrs directly if not set
                    if (ReportParameters == null)
                    {
                        FormInfo fi = new FormInfo(ri.ReportParameters);
                        // Get datarow with required columns
                        ReportParameters = fi.GetDataRow(false);
                        fi.LoadDefaultValues(ReportParameters, true);
                    }

                    ApplyTimeParameters();
                }
            }

            // Only use base parameters in case of stored procedure
            if (QueryIsStoredProcedure)
            {
                AllParameters = SpecialFunctions.ConvertDataRowToParams(ReportParameters, null);
            }

            // Load data
            DataSet ds = LoadData();

            // If no data load, set empty dataset
            if (DataHelper.DataSourceIsEmpty(ds))
            {
                if (EmailMode && SendOnlyNonEmptyDataSource)
                {
                    Visible = false;
                    return;
                }

                string noRecordText = ValidationHelper.GetString(TableInfo.TableSettings["QueryNoRecordText"], String.Empty);
                if (noRecordText != String.Empty)
                {
                    GridViewObject.Visible = false;
                    lblInfo.Text = CMSContext.ResolveMacros(noRecordText);
                    plcInfo.Visible = true;
                    EnableExport = false;
                    return;
                }

                if (!EmailMode)
                {
                    Visible = false;
                }
            }
            else
            {
                GridViewObject.Visible = true;
                // Resolve macros in column names
                int i = 0;
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    if (dc.ColumnName == "Column" + ((int)(i + 1)).ToString())
                    {
                        dc.ColumnName = ResolveMacros(ds.Tables[0].Rows[0][i].ToString());
                    }
                    else
                    {
                        dc.ColumnName = ResolveMacros(dc.ColumnName);
                    }
                    i++;
                }

                // Resolve macros in dataset
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foreach (DataColumn dc in ds.Tables[0].Columns)
                    {
                        if (dc.DataType.FullName.ToLowerCSafe() == "system.string")
                        {
                            dr[dc.ColumnName] = ResolveMacros(ValidationHelper.GetString(dr[dc.ColumnName], ""));
                        }
                    }
                }

                if (EmailMode)
                {
                    // For some email formats, export data in csv format
                    EmailFormatEnum format = EmailHelper.GetEmailFormat(ReportSubscriptionSiteID);

                    if ((format == EmailFormatEnum.Both) || (format == EmailFormatEnum.PlainText))
                    {
                        using (MemoryStream ms = MemoryStream.New())
                        {
                            DataExportHelper deh = new DataExportHelper(ds);
                            byte[] data = deh.ExportToCSV(ds, 0, ms, true);
                            ReportSubscriptionSender.AddToRequest(ri.ReportName, "t" + TableInfo.TableName, data);
                        }
                    }

                    // For plain text email show table only as attachment
                    if (format == EmailFormatEnum.PlainText)
                    {
                        menuCont.Visible = false;
                        ltlEmail.Visible = true;
                        ltlEmail.Text = String.Format(GetString("reportsubscription.attachment"), TableInfo.TableName);
                        return;
                    }

                    GenerateTableForEmail(ds);
                    menuCont.Visible = false;
                    return;
                }
            }

            ApplyStyles();

            // Databind to gridview control
            GridViewObject.DataSource = ds;
            EnsurePageIndex();
            GridViewObject.DataBind();

            if ((TableFirstColumnWidth != Unit.Empty) && (GridViewObject.Rows.Count > 0))
            {
                GridViewObject.Rows[0].Cells[0].Width = TableFirstColumnWidth;
            }
        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text = "[ReportTable.ascx] Error loading the data: " + ex.Message;
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Report table", "E", ex);
            errorOccurred = true;
        }
    }
Ejemplo n.º 33
0
    protected void Page_Load(object sender, EventArgs e)
    {
        usReports.OnSelectionChanged += usReports_OnSelectionChanged;
        string [,]specialFields = new string [1,2];

        pnlReports.Attributes.Add("style", "margin-bottom:3px");

        string reportName = ValidationHelper.GetString(usReports.Value, String.Empty);
        ReportInfo ri = ReportInfoProvider.GetReportInfo(reportName);
        if (ri != null)
        {
            usItems.Enabled = true;
            //test if there is any item visible in report parameters
            FormInfo fi = new FormInfo(ri.ReportParameters);

            //Get dataset from cache
            DataSet ds = (DataSet)WindowHelper.GetItem(hdnGuid.Value);
            DataRow dr = fi.GetDataRow();
            fi.LoadDefaultValues(dr);
            bool itemVisible = false;
            List<FormItem> items = fi.ItemsList;
            foreach (FormItem item in items)
            {
                FormFieldInfo ffi = item as FormFieldInfo;
                if (ffi != null)
                {
                    if (ffi.Visible)
                    {
                        itemVisible = true;
                        break;
                    }
                }
            }

            ReportID = ri.ReportID;

            if (!itemVisible)
            {
                plcParametersButtons.Visible = false;
            }
            else
            {
                plcParametersButtons.Visible = true;
            }
        }
        else
        {
            plcParametersButtons.Visible = false;
            usItems.Enabled = false;
        }

        ltlScript.Text = ScriptHelper.GetScript("function refresh () {" + ControlsHelper.GetPostBackEventReference(pnlUpdate, String.Empty) + "}");
        usReports.DropDownSingleSelect.AutoPostBack = true;

        if (!mDisplay)
        {
            pnlReports.Visible = false;
            plcParametersButtons.Visible = false;
            usItems.Enabled = true;
        }

        if (!ShowItemSelector)
        {
            pnlItems.Visible = false;
        }

        usItems.IsLiveSite = IsLiveSite;
        usReports.IsLiveSite = IsLiveSite;
        ugParameters.GridName = "~/CMSModules/Reporting/FormControls/ReportParametersList.xml";
        ugParameters.ZeroRowsText = String.Empty;
        ugParameters.PageSize = "##ALL##";
        ugParameters.Pager.DefaultPageSize = -1;

        BuildConditions();

        // First item as "please select string" - not default "none"
        usItems.AllowEmpty = false;
        usReports.AllowEmpty = false;
        specialFields[0, 0] = "(" + GetString("rep.pleaseselect") + ")";
        specialFields[0, 1] = "0";
        usReports.SpecialFields = specialFields;

        if (ri == null)
        {
            string[,] itemSpecialFields = new string[1, 2];
            itemSpecialFields[0, 0] = "(" + firstItemText + ")";
            itemSpecialFields[0, 1] = "0";
            usItems.SpecialFields = itemSpecialFields;
        }

        if (ShowItemSelector)
        {
            ReloadItems();
        }
    }
    /// <summary>
    /// Show preview.
    /// </summary>
    private void ShowPreview()
    {
        if (mReportInfo != null)
        {
            pnlPreview.Visible = true;
            divPanelHolder.Visible = false;
            pnlVersions.Visible = false;

            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);
            DataRow defaultValues = fi.GetDataRow(false);

            fi.LoadDefaultValues(defaultValues, true);

            //reportGraph.ContextParameters
            ctrlReportValue.ReportParameters = defaultValues;

            ctrlReportValue.Visible = true;
            ctrlReportValue.ValueInfo = mReportValueInfo;

            ctrlReportValue.ReloadData(true);
        }
    }
Ejemplo n.º 35
0
    /// <summary>
    /// Loads basicform with filter controls.
    /// </summary>
    /// <param name="bf">BasicForm control</param>
    /// <param name="fi">Form definition</param>
    /// <param name="activityType">Activity type in case the rule type is activity</param>
    private void LoadForm(BasicForm bf, FormInfo fi, string activityType)
    {
        bf.FormInformation = fi;
        bf.Data = RuleHelper.GetDataFromCondition((RuleInfo)rule, fi.GetDataRow().Table, ref activityType);
        bf.SubmitButton.Visible = false;
        bf.SiteName = CMSContext.CurrentSiteName;
        bf.FieldLabelCellCssClass = "ContactLabel";
        bf.FieldLabelCssClass = null;

        if (rule != null)
        {
            bf.Mode = FormModeEnum.Update;
        }

        bf.ReloadData();
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible = true;
        ucChart.Visible = true;

        int correctWidth = 0;
        if (ComputedWidth != 0)
        {
            correctWidth = ModifyGraphInfo();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph();
        graph.ChartControl = ucChart;

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        // Set default parametrs directly if not set
        if (ReportParameters == null)
        {
            // Load ReportInfo
            if (report != null)
            {
                FormInfo fi = new FormInfo(report.ReportParameters);

                // Get datarow with required columns
                ReportParameters = fi.GetDataRow(false);
                fi.LoadDefaultValues(ReportParameters, true);
            }
        }

        // If used via widget - this function ensure showing specific interval from actual time (f.e. last 6 weeks)
        ApplyTimeParameters();

        // Only use base parameters in case of stored procedure
        if (QueryIsStoredProcedure)
        {
            AllParameters = SpecialFunctions.ConvertDataRowToParams(ReportParameters, null);
        }

        ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();

        errorOccurred = false;

        // Create graph image
        try
        {
            // Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

            // Resolve dynamic data macros
            if (DynamicMacros != null)
            {
                for (int i = 0; i <= DynamicMacros.GetUpperBound(0); i++)
                {
                    resolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]);
                }
            }

            // Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // LoadData
            DataSet dsGraphData = LoadData();

            // Empty dataset, and flag not send empty dataset is set
            if (SendOnlyNonEmptyDataSource && EmailMode && DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                Visible = false;
                return;
            }

            // Test if dataset is empty
            if (DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                string noRecordText = CMSContext.ResolveMacros(ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty));
                if (noRecordText != String.Empty)
                {
                    ltlEmail.Text = noRecordText;
                    lblInfo.Text = noRecordText;
                    ucChart.Visible = false;
                    menuCont.MenuID = String.Empty;
                    EnableExport = false;
                    plcInfo.Visible = true;
                }
                else
                {
                    Visible = false;
                }
            }
            else
            {
                // Create Chart
                graph.CorrectWidth = correctWidth;
                if (EmailMode)
                {
                    byte[] data = graph.CreateChart(reportGraph, dsGraphData, resolver, true);
                    ltlEmail.Text = "##InlineImage##" + reportGraph.GraphName + "##InlineImage##";
                    ReportSubscriptionSender.AddToRequest(report.ReportName, "g" + reportGraph.GraphName, data);
                }
                else
                {
                    graph.CreateChart(reportGraph, dsGraphData, resolver);
                }
            }

            // Check if subscription is allowed
            EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
            if (EmailMode && !EnableSubscription)
            {
                this.Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            errorOccurred = true;
        }
    }
    /// <summary>
    /// Loads data for advanced mode
    /// </summary>
    private void LoadData()
    {
        if (!RequestHelper.IsPostBack())
        {
            if (mReportSubscriptionInfo.ReportSubscriptionID > 0)
            {
                // Initial settings
                ucInterval.ScheduleInterval = mReportSubscriptionInfo.ReportSubscriptionInterval;
                chkEnabled.Checked = mReportSubscriptionInfo.ReportSubscriptionEnabled;
                txtEmail.Text = mReportSubscriptionInfo.ReportSubscriptionEmail;
                txtSubject.Text = mReportSubscriptionInfo.ReportSubscriptionSubject;
                chkNonEmpty.Checked = mReportSubscriptionInfo.ReportSubscriptionOnlyNonEmpty;
                ucMacroEditor.Text = mReportSubscriptionInfo.ReportSubscriptionCondition;
            }
            else
            {
                // New item
                chkEnabled.Checked = true;
                txtEmail.Text = MembershipContext.AuthenticatedUser.Email;
                txtSubject.Text = ResHelper.LocalizeString(Report.ReportDisplayName);
                chkNonEmpty.Checked = true;
                ucInterval.DefaultPeriod = SchedulingHelper.PERIOD_DAY;
            }

            FillItems();
        }

        if ((Report != null) && !String.IsNullOrEmpty(Report.ReportParameters) && (Report.ReportParameters != "<form></form>"))
        {
            // Convert field "DateFrom" and "DateTo" to string to be able to display macros
            FormInfo fi = new FormInfo(Report.ReportParameters);
            FormFieldInfo ffi = fi.GetFormField("FromDate");

            if (ffi != null)
            {
                ffi.DataType = FieldDataType.Text;
                ffi.FieldType = FormFieldControlTypeEnum.CalendarControl;
                ffi.Settings["AllowMacros"] = true;
                ffi.Size = 400;
                ffi.AllowEmpty = true;
                ffi.Visible = false;
            }

            ffi = fi.GetFormField("ToDate");
            if (ffi != null)
            {
                ffi.DataType = FieldDataType.Text;
                ffi.FieldType = FormFieldControlTypeEnum.CalendarControl;
                ffi.Settings["AllowMacros"] = true;
                ffi.Size = 400;
                ffi.AllowEmpty = true;
                ffi.Visible = false;
            }

            // Get datarow from forminfo (it contains report parameters passed by querystring)
            DataRow defaultValues = fi.GetDataRow(false);

            // Load default values
            fi.LoadDefaultValues(defaultValues, true);

            // Display basic form, only if any item is visible
            bool display = false;
            foreach (FormFieldInfo field in fi.ItemsList)
            {
                if (field.Visible)
                {
                    display = true;
                    break;
                }
            }

            pnlParametersEnvelope.Visible = display;

            // Loop through all nodes is subscription's XML parameters and replace report's value with current subscription's ones.
            if (mReportSubscriptionInfo.ReportSubscriptionID > 0)
            {
                if (!String.IsNullOrEmpty(mReportSubscriptionInfo.ReportSubscriptionParameters))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(mReportSubscriptionInfo.ReportSubscriptionParameters);
                    foreach (DataColumn col in defaultValues.Table.Columns)
                    {
                        XmlNode node = xml.SelectSingleNode("/Root/" + col.ColumnName);
                        if (node != null)
                        {
                            // In case of different data types use try catch block
                            try
                            {
                                defaultValues[col.ColumnName] = DataHelper.ConvertValue(node.InnerText, col.DataType);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }

            mParameters = defaultValues;
            pnlFromToParams.Visible = !SetTimeControls();

            // Set basic form parameters
            formElem.DataRow = defaultValues;
            formElem.SubmitButton.Visible = false;
            formElem.SubmitButton.RegisterHeaderAction = false;
            formElem.FormInformation = fi;
            formElem.SiteName = SiteContext.CurrentSiteName;
            formElem.Mode = FormModeEnum.Update;
            formElem.Visible = true;
        }
        else
        {
            pnlParametersEnvelope.Visible = false;
            pnlFromToParams.Visible = false;
        }
    }
Ejemplo n.º 38
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQuery.Enabled = false;
        }
        else
        {
            txtQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

        // Own javascript tab change handling -> because tab control raises changetab after prerender - too late
        // Own selected tab change handling
        RegisterTabScript(hdnSelectedTab.ClientID, tabControlElem);

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

        string[,] tabs = new string[4, 4];
        tabs[0, 0] = GetString("general.general");
        tabs[0, 1] = "SetHelpTopic('helpTopic', 'report_table_properties')";
        tabs[1, 0] = GetString("general.preview");
        tabs[0, 1] = "SetHelpTopic('helpTopic', 'report_table_properties')";

        tabControlElem.Tabs = tabs;
        tabControlElem.UsePostback = true;
        CurrentMaster.Title.HelpName = "helpTopic";
        CurrentMaster.Title.HelpTopicName = "report_table_properties";
        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";

        rfvCodeName.ErrorMessage = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        btnApply.Text = GetString("General.apply");
        btnOk.Text = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");

        int reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview = QueryHelper.GetBoolean("preview", false);
        if (reportId > 0)
        {
            reportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);
        if (isPreview && !RequestHelper.IsPostBack())
        {
            SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (reportInfo != null) // Must be valid reportid parameter
            {
                string tableName = ValidationHelper.GetString(Request.QueryString["itemname"], "");

                // Try to load tableName from hidden field (adding new graph & preview)
                if (tableName == String.Empty)
                {
                    tableName = txtNewTableHidden.Value;
                }

                if (ValidationHelper.IsIdentifier(tableName))
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(reportInfo.ReportName + "." + tableName);
                    tableInfo = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            tableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (reportInfo != null)
        {
            // Control text initializations
            if (tableInfo != null)
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportTable_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/object.png");

                tableId = tableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(tableInfo))
                {
                    tabs[2, 0] = GetString("objectversioning.tabtitle");
                    tabs[2, 1] = "SetHelpTopic('helpTopic', 'objectversioning_general');";

                    versionList.Object = tableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                CurrentMaster.Title.TitleText = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/new.png");

                if (!RequestHelper.IsPostBack())
                {
                    txtPageSize.Text = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked = true;
                }

                newTable = true;
            }

            // Set help key
            CurrentMaster.Title.HelpTopicName = "report_table_properties";

            if (!RequestHelper.IsPostBack())
            {
                DataHelper.FillListControlWithEnum(typeof(PagerButtons), drpPageMode, "PagerButtons.", null);
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload deafult parameters
            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow();
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Colect data and put them in talbe info
            Save(false);
            ctrlReportTable.TableInfo = tableInfo;
        }
    }
    /// <summary>
    /// Adds widget.
    /// </summary>
    private void AddWidget()
    {
        int widgetID = ValidationHelper.GetInteger(WidgetId, 0);

        // Add web part to the currently selected zone under currently selected page
        if ((widgetID > 0) && !String.IsNullOrEmpty(ZoneId))
        {
            if (wi != null)
            {
                // Ensure layout zone flag
                if (QueryHelper.GetBoolean("layoutzone", false))
                {
                    WebPartZoneInstance zone = pti.EnsureZone(ZoneId);
                    zone.LayoutZone = true;
                    zone.WidgetZoneType = zoneType;

                    // Ensure the layout zone flag in the original page template instance
                    WebPartZoneInstance zoneInstance = templateInstance.GetZone(ZoneId);
                    if (zoneInstance != null)
                    {
                        zoneInstance.LayoutZone = true;
                        zone.WidgetZoneType = zoneType;
                    }
                }

                // Add the widget
                WebPartInstance newWidget = templateInstance.AddWidget(ZoneId, widgetID);
                if (newWidget != null)
                {
                    // Prepare the form info to get the default properties
                    FormInfo fi = new FormInfo(wi.WidgetProperties);

                    DataRow dr = fi.GetDataRow();
                    fi.LoadDefaultValues(dr);

                    newWidget.LoadProperties(dr);

                    // Add webpart to user's last recently used
                    CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName);

                    widgetInstance = newWidget;
                }
            }
        }
    }
    /// <summary>
    /// OnInit.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        ScriptHelper.RegisterWOpenerScript(Page);
        PageTitle.TitleText = ResHelper.GetString("rep.webparts.reportparameterstitle");
        // Load data for this form
        int reportID = QueryHelper.GetInteger("ReportID", 0);
        hdnGuid.Value = QueryHelper.GetString("GUID", String.Empty);
        ReportInfo ri = ReportInfoProvider.GetReportInfo(reportID);
        if (ri == null)
        {
            return;
        }

        FormInfo fi = new FormInfo(ri.ReportParameters);
        bfParameters.FormInformation = fi;
        bfParameters.SubmitButton.Visible = false;
        bfParameters.Mode = FormModeEnum.Update;

        // Get dataset from cache
        DataSet ds = (DataSet)WindowHelper.GetItem(hdnGuid.Value);
        DataRow dr = fi.GetDataRow(false);
        fi.LoadDefaultValues(dr, true);

        if (ds == null)
        {
            if (dr.ItemArray.Length > 0)
            {
                // Set up grid
                bfParameters.DataRow = RequestHelper.IsPostBack() ? fi.GetDataRow(false) : dr;
            }
        }

        // Set data set given from cache
        if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
        {
            //Merge with default data from report
            MergeDefaultValuesWithData(dr, ds.Tables[0].Rows[0]);
            //Set row to basic form
            bfParameters.DataRow = dr;
        }

        // Test if there is any item visible in report parameters
        bool itemVisible = false;
        List<IDataDefinitionItem> items = fi.ItemsList;
        foreach (IDataDefinitionItem item in items)
        {
            FormFieldInfo ffi = item as FormFieldInfo;
            if (ffi != null && ffi.Visible)
            {
                itemVisible = true;
                break;
            }
        }

        if (!itemVisible)
        {
            ShowInformation(GetString("rep.parameters.noparameters"));
        }

        base.OnInit(e);
    }
    /// <summary>
    /// Load parameters from data form.
    /// </summary>
    private void LoadParameters()
    {
        if (ReportInfo != null)
        {
            // Set the form
            FormInfo fi = new FormInfo(ReportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow(false);
            if (!RequestHelper.IsPostBack() || ForceLoadDefaultValues || !DisplayFilter)
            {
                fi.LoadDefaultValues(dr, true);
            }
            else if ((!ForceLoadDefaultValues) && (formParameters.DataRow != null))
            {
                dr = formParameters.DataRow;
            }

            // Show filter - based on DisplayFilter and number of visible elements
            mDisplayFilterResult = DisplayFilter && (fi.GetFormElements(true, false).Any());

            formParameters.DataRow = dr;
            formParameters.SubmitButton.Visible = mDisplayFilterResult;
            formParameters.SubmitButton.RegisterHeaderAction = false;
            formParameters.FormInformation = fi;
            formParameters.SubmitButton.ResourceString = "report_view.btnupdate";
            formParameters.SiteName = SiteContext.CurrentSiteName;
            formParameters.Mode = FormModeEnum.Insert;
            formParameters.Visible = mDisplayFilterResult;

            wasInit = true;
        }
    }
    /// <summary>
    /// Load parameters from data form.
    /// </summary>
    protected void LoadParameters()
    {
        if (ReportInfo != null)
        {
            // Set the form
            FormInfo fi = new FormInfo(ReportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();
            if (!RequestHelper.IsPostBack() || ForceLoadDefaultValues || !DisplayFilter)
            {
                fi.LoadDefaultValues(dr, true);
            }
            else
            {
                if ((!ForceLoadDefaultValues) && (formElem.DataRow != null))
                {
                    dr = formElem.DataRow;
                }
            }

            // show filter - based on DisplayFilter and number of visible elements
            mDisplayFilterResult = DisplayFilter && (fi.GetFormElements(true, false).Any());

            formElem.DataRow = dr;
            formElem.SubmitButton.Visible = mDisplayFilterResult;
            formElem.SubmitButton.RegisterHeaderAction = false;
            formElem.FormInformation = fi;
            formElem.SubmitButton.Text = GetString("Report_View.btnUpdate");
            formElem.SiteName = CMSContext.CurrentSiteName;
            formElem.ShowPrivateFields = true;
            formElem.Mode = FormModeEnum.Insert;
            formElem.Visible = mDisplayFilterResult;
        }
    }
Ejemplo n.º 43
0
    protected override void OnPreRender(EventArgs e)
    {
        //apply reportid condition if report was selected wia uniselector
        string reportName = ValidationHelper.GetString(usReports.Value, String.Empty);
        ReportInfo ri = ReportInfoProvider.GetReportInfo(reportName);
        if (ri != null)
        {
            FormInfo fi = new FormInfo(ri.ReportParameters);
            DataRow dr = fi.GetDataRow();
            DataSet ds = this.CurrentDataSet;

            this.ViewState["ParametersXmlData"] = null;
            this.ViewState["ParametersXmlSchema"] = null;

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                this.ViewState["ParametersXmlData"] = ds.GetXml();
                this.ViewState["ParametersXmlSchema"] = ds.GetXmlSchema();
            }

            if (!keepDataInWindowsHelper)
            {
                WindowHelper.Remove(CurrentGuid().ToString());
            }

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                ds = DataHelper.DataSetPivot(ds, new string[] { "ParameterName", "ParameterValue" });
                ugParameters.DataSource = ds;
                ugParameters.ReloadData();
                pnlParameters.Visible = true;
            }
            else
            {
                pnlParameters.Visible = false;
            }
        }
        else
        {
            pnlParameters.Visible = false;
        }

        base.OnPreRender(e);
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        // Check whether report graph is defined
        if (reportGraph == null)
        {
            return;
        }

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        //check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
        if (EmailMode && !EnableSubscription)
        {
            this.Visible = false;
            return;
        }

        //Set default parametrs directly if not set
        if (ReportParameters == null)
        {
            //Load ReportInfo
            if (report != null)
            {
                FormInfo fi = new FormInfo(report.ReportParameters);
                // Get datarow with required columns
                ReportParameters = fi.GetDataRow(false);
                fi.LoadDefaultValues(ReportParameters, true);
            }
        }

        // Only use base parameters in case of stored procedure
        if (QueryIsStoredProcedure)
        {
            AllParameters = SpecialFunctions.ConvertDataRowToParams(ReportParameters, null);
        }

        // Indicaates whether exception was throw during data loading
        errorOccurred = false;

        // Create graph data
        try
        {
            ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();
            //Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

            // Resolve dynamic data macros
            if (DynamicMacros != null)
            {
                for (int i = 0; i <= DynamicMacros.GetUpperBound(0); i++)
                {
                    resolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]);
                }
            }

            //Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // Load data
            DataSource = LoadData();

            if (DataHelper.DataSourceIsEmpty(DataSource) && EmailMode && SendOnlyNonEmptyDataSource)
            {
                Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            lblError.Text = ex.Message;
            lblError.Visible = true;
            errorOccurred = true;
        }
    }
    /// <summary>
    /// Loads basicform with filter controls.
    /// </summary>
    /// <param name="bf">BasicForm control</param>
    /// <param name="fi">Form definition</param>
    /// <param name="activityType">Activity type in case the rule type is activity</param>
    private void LoadForm(BasicForm bf, FormInfo fi, string activityType = null)
    {
        bf.FormInformation = fi;
        bf.Data = RuleHelper.GetDataFromCondition(Rule, fi.GetDataRow().Table, ref activityType);
        bf.SubmitButton.Visible = false;
        bf.SiteName = SiteContext.CurrentSiteName;

        if (Rule != null)
        {
            bf.Mode = FormModeEnum.Update;
        }

        bf.ReloadData();
    }
    /// <summary>
    /// Show graph
    /// </summary>
    private void ShowPreview()
    {
        // Color picker preview issue
        DisplayEditControls(false);

        pnlVersions.Visible = false;
        if (mReportInfo != null)
        {
            pnlPreview.Visible = true;

            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);
            // Get DataRow with required columns
            DataRow dr = fi.GetDataRow(false);

            fi.LoadDefaultValues(dr, true);

            ctrlReportGraph.ReportParameters = dr;

            ctrlReportGraph.Visible = true;

            // Prepare fully qualified graph name = with ReportName
            string fullReportGraphName = mReportInfo.ReportName + "." + mReportGraphInfo.GraphName;
            ctrlReportGraph.GraphInfo = mReportGraphInfo;
            ctrlReportGraph.Parameter = fullReportGraphName;

            ctrlReportGraph.ReloadData(true);
        }
    }
Ejemplo n.º 47
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope               = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible        = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

        // Test permission for query
        txtQuery.Enabled = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries");

        versionList.OnAfterRollback += versionList_onAfterRollback;

        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript("divFooter", divScrolable.ClientID);

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.general")
        });

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.preview")
        });

        tabControlElem.UsePostback = true;

        rfvCodeName.ErrorMessage    = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");

        Save += (s, ea) =>
        {
            if (SetData(true))
            {
                ltlScript.Text += ScriptHelper.GetScript("window.RefreshContent();CloseDialog();");
            }
        };

        int  reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview  = QueryHelper.GetBoolean("preview", false);

        if (reportId > 0)
        {
            mReportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);

        if (isPreview && !RequestHelper.IsPostBack())
        {
            tabControlElem.SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (mReportInfo != null) // Must be valid reportid parameter
            {
                int id = QueryHelper.GetInteger("objectid", 0);

                // Try to load tableName from hidden field (adding new graph & preview)
                if (id == 0)
                {
                    id = ValidationHelper.GetInteger(txtNewTableHidden.Value, 0);
                }

                if (id > 0)
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(id);
                    mReportTableInfo       = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            mReportTableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (mReportInfo != null)
        {
            ucSelectString.DefaultConnectionString = mReportInfo.ReportConnectionString;

            // Control text initializations
            if (mReportTableInfo != null)
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.TitleText");
                mTableId            = mReportTableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(mReportTableInfo))
                {
                    tabControlElem.TabItems.Add(new UITabItem
                    {
                        Text = GetString("objectversioning.tabtitle")
                    });

                    versionList.Object     = mReportTableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value      = String.Empty;
                    txtPageSize.Text          = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked   = true;
                    chkSubscription.Checked   = true;
                }
            }

            if (!RequestHelper.IsPostBack())
            {
                ControlsHelper.FillListControlWithEnum <PagerButtons>(drpPageMode, "PagerButtons");
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload default parameters
            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);

            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow(false);
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Collect data and put them in table info
            SetData();
            ctrlReportTable.TableInfo = mReportTableInfo;
        }

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
        CurrentMaster.PanelContent.RemoveCssClass("ModalDialogContent");
    }
    protected override void OnPreRender(EventArgs e)
    {
        pnlReports.Attributes.Add("style", "margin-bottom:3px");

        string reportName = ValidationHelper.GetString(usReports.Value, String.Empty);
        ri = ReportInfoProvider.GetReportInfo(reportName);
        if (ri != null)
        {
            usItems.Enabled = true;

            // Test if there is any item visible in report parameters
            FormInfo fi = new FormInfo(ri.ReportParameters);

            // Get dataset from cache
            DataSet ds = (DataSet)WindowHelper.GetItem(CurrentGuid());
            DataRow dr = fi.GetDataRow();
            fi.LoadDefaultValues(dr);
            bool itemVisible = false;
            List<IFormItem> items = fi.ItemsList;
            foreach (IFormItem item in items)
            {
                FormFieldInfo ffi = item as FormFieldInfo;
                if (ffi != null)
                {
                    if (ffi.Visible)
                    {
                        itemVisible = true;
                        break;
                    }
                }
            }

            ReportID = ri.ReportID;

            if (!itemVisible)
            {
                plcParametersButtons.Visible = false;
            }
            else
            {
                plcParametersButtons.Visible = true;
            }
        }
        else
        {
            if (ReportID == 0)
            {
                plcParametersButtons.Visible = false;
                usItems.Enabled = false;
            }
        }

        ltlScript.Text = ScriptHelper.GetScript("function refresh () {" + ControlsHelper.GetPostBackEventReference(pnlUpdate, String.Empty) + "}");
        usReports.DropDownSingleSelect.AutoPostBack = true;

        if (!mDisplay)
        {
            pnlReports.Visible = false;
            plcParametersButtons.Visible = false;
            usItems.Enabled = true;
        }

        if (!ShowItemSelector)
        {
            pnlItems.Visible = false;
        }

        usItems.IsLiveSite = IsLiveSite;
        usReports.IsLiveSite = IsLiveSite;
        ugParameters.GridName = "~/CMSModules/Reporting/FormControls/ReportParametersList.xml";
        ugParameters.ZeroRowsText = String.Empty;
        ugParameters.PageSize = "##ALL##";
        ugParameters.Pager.DefaultPageSize = -1;

        BuildConditions();

        if (ri == null)
        {
            string[,] itemSpecialFields = new string[1, 2];
            itemSpecialFields[0, 0] = "(" + firstItemText + ")";
            itemSpecialFields[0, 1] = "0";
            usItems.SpecialFields = itemSpecialFields;
        }

        if (ShowItemSelector)
        {
            ReloadItems();
        }

        if (setValues)
        {
            WindowHelper.Add(CurrentGuid(), CurrentDataSet);
            ScriptHelper.RegisterStartupScript(Page, typeof(Page), "OpenModalWindowReportItem", ScriptHelper.GetScript("modalDialog('" + ResolveUrl("~/CMSModules/Reporting/Dialogs/ReportParametersSelector.aspx?ReportID=" + ReportID + "&guid=" + CurrentGuid().ToString()) + "','ReportParametersDialog', 700, 500);"));
            keepDataInWindowsHelper = true;
        }

        // Apply reportid condition if report was selected via uniselector
        if (ri != null)
        {
            FormInfo fi = new FormInfo(ri.ReportParameters);
            DataRow dr = fi.GetDataRow();
            DataSet ds = CurrentDataSet;

            ViewState["ParametersXmlData"] = null;
            ViewState["ParametersXmlSchema"] = null;

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                ViewState["ParametersXmlData"] = ds.GetXml();
                ViewState["ParametersXmlSchema"] = ds.GetXmlSchema();
            }

            if (!keepDataInWindowsHelper)
            {
                WindowHelper.Remove(CurrentGuid().ToString());
            }

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                ds = DataHelper.DataSetPivot(ds, new string[] { "ParameterName", "ParameterValue" });
                ugParameters.DataSource = ds;
                ugParameters.ReloadData();
                pnlParameters.Visible = true;
            }
            else
            {
                pnlParameters.Visible = false;
            }
        }
        else
        {
            pnlParameters.Visible = false;
        }

        base.OnPreRender(e);
    }
    /// <summary>
    /// Show preview
    /// </summary>
    private void ShowPreview()
    {
        divPanelHolder.Visible = false;
        pnlVersions.Visible = false;

        if (mReportInfo != null)
        {
            pnlPreview.Visible = true;

            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow defaultValues = fi.GetDataRow(false);

            fi.LoadDefaultValues(defaultValues, true);

            // ReportGraph.ContextParameters
            ctrlReportTable.ReportParameters = defaultValues;

            // Prepare fully qualified graph name = with reportname
            if (mReportTableInfo != null)
            {
                string fullReportGraphName = mReportInfo.ReportName + "." + mReportTableInfo.TableName;
                ctrlReportTable.Parameter = fullReportGraphName;
            }
            ctrlReportTable.TableInfo = mReportTableInfo;

            ctrlReportTable.ReloadData(true);
        }
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        try
        {
            // Load value info object
            ReportValueInfo rvi = ValueInfo;

            if (rvi != null)
            {
                //Test security
                ReportInfo ri = ReportInfoProvider.GetReportInfo(rvi.ValueReportID);
                if (ri.ReportAccess != ReportAccessEnum.All)
                {
                    if (!CMSContext.CurrentUser.IsAuthenticated())
                    {
                        this.Visible = false;
                        return;
                    }
                }

                ContextResolver resolver = CMSContext.CurrentResolver;
                // Resolve dynamic data macros
                if (DynamicMacros != null)
                {
                    for (int i = 0; i <= this.DynamicMacros.GetUpperBound(0); i++)
                    {
                        resolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]);
                    }
                }

                this.QueryIsStoredProcedure = rvi.ValueQueryIsStoredProcedure;
                this.QueryText = resolver.ResolveMacros(rvi.ValueQuery);

                //Set default parametrs directly if not set
                if (this.ReportParameters == null)
                {
                    if (ri != null)
                    {
                        FormInfo fi = new FormInfo(ri.ReportParameters);
                        // Get datarow with required columns
                        this.ReportParameters = fi.GetDataRow();
                        fi.LoadDefaultValues(this.ReportParameters);
                    }
                }
            }

            // Only use base parameters in case of stored procedure
            if (this.QueryIsStoredProcedure)
            {
                this.AllParameters = SpecialFunctions.ConvertDataRowToParams(this.ReportParameters, null);
            }

            // Load data
            DataSet ds = this.LoadData();

            // If datasource is emptry, create empty dataset
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                // Set literal text
                string value = rvi.ValueFormatString;
                if ((value == null) || (value == ""))
                {
                    value = ValidationHelper.GetString(ds.Tables[0].Rows[0][0], "");
                }
                else
                {
                    value = string.Format(value, ds.Tables[0].Rows[0].ItemArray);
                }

                lblValue.Text = HTMLHelper.HTMLEncode(ResolveMacros(value));
            }
        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text = "[ReportValue.ascx] Error loading the data: " + ex.Message;
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Report value", "E", ex);
        }
    }
Ejemplo n.º 51
0
    /// <summary>
    /// Loads the web part form.
    /// </summary>
    protected void LoadForm()
    {
        // Load settings
        if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID]))
        {
            IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false);
        }
        if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID]))
        {
            InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty);
        }

        // Indicates whether the new variant should be chosen when closing this dialog
        selectNewVariant = IsNewVariant;

        // Try to find the web part variant in the database and set its VariantID
        if (IsNewVariant)
        {
            Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable;
            if (varProperties != null)
            {
                // Get the variant code name from the WindowHelper
                string variantName = ValidationHelper.GetString(varProperties["codename"], string.Empty);

                // Check if the variant exists in the database
                int variantIdFromDB = VariantHelper.GetVariantID(VariantMode, PageTemplateID, variantName, true);

                // Set the variant id from the database
                if (variantIdFromDB > 0)
                {
                    VariantID    = variantIdFromDB;
                    IsNewVariant = false;
                }
            }
        }

        if (!String.IsNullOrEmpty(WebPartID))
        {
            // Get the page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode);

            if (pi == null)
            {
                ShowError(GetString("general.pagenotfound"));
                pnlExport.Visible = false;
                return;
            }

            // Get template
            pti = pi.UsedPageTemplateInfo;

            // Get template instance
            templateInstance = pti.TemplateInstance;

            if (!IsNewWebPart)
            {
                // Standard zone
                webPartInstance = templateInstance.GetWebPart(InstanceGUID, WebPartID);

                // If the web part not found, try to find it among the MVT/CP variants
                if (webPartInstance == null)
                {
                    // MVT/CP variant

                    // Clone templateInstance to avoid caching of the temporary template instance loaded with CP/MVT variants
                    var tempTemplateInstance = templateInstance.Clone();
                    tempTemplateInstance.LoadVariants(false, VariantModeEnum.None);

                    webPartInstance = tempTemplateInstance.GetWebPart(InstanceGUID, -1);

                    // Set the VariantMode according to the selected web part/zone variant
                    if (webPartInstance?.ParentZone != null)
                    {
                        VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode;
                    }
                    else
                    {
                        VariantMode = VariantModeEnum.None;
                    }
                }
                else
                {
                    // Ensure that the ZoneVariantID is not set when the web part was found in a regular zone
                    ZoneVariantID = 0;
                }

                if ((VariantID > 0) && webPartInstance?.PartInstanceVariants != null)
                {
                    // Check OnlineMarketing permissions.
                    if (CheckPermissions("Read"))
                    {
                        webPartInstance = webPartInstance.FindVariant(VariantID);
                    }
                    else
                    {
                        // Not authorized for OnlineMarketing - Manage.
                        RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest"));
                    }
                }

                if (webPartInstance == null)
                {
                    UIContext.EditedObject = null;
                    return;
                }
            }

            // Keep xml version
            if (webPartInstance != null)
            {
                xmlVersion = webPartInstance.XMLVersion;
            }

            // Get the form info
            FormInfo fi = GetWebPartFormInfo();

            // Get the form definition
            if (fi != null)
            {
                fi.ContextResolver.Settings.RelatedObject = templateInstance;
                form.AllowMacroEditing = true;

                // Get data row with required columns
                DataRow dr = fi.GetDataRow();

                if (IsNewWebPart || (xmlVersion > 0))
                {
                    fi.LoadDefaultValues(dr);
                }

                // Load values from existing web part
                LoadDataRowFromWebPart(dr, webPartInstance, fi);

                // Set a unique WebPartControlID for the new variant
                if (IsNewVariant || IsNewWebPart)
                {
                    dr["WebPartControlID"] = GetUniqueWebPartId();
                }

                // Init the form
                InitForm(form, dr, fi);

                DisplayExportPropertiesButton();
            }
            else
            {
                UIContext.EditedObject = null;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ucSelectString.Scope = ReportInfo.OBJECT_TYPE;
        ConnectionStringRow.Visible = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.reporting", "SetConnectionString");
        txtQuery.FullScreenParentElementID = pnlWebPartForm_Properties.ClientID;

        // Test permission for query
        txtQuery.Enabled = MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries");

        versionList.OnAfterRollback += versionList_onAfterRollback;

        PageTitle.HelpTopicName = HELP_TOPIC_LINK;

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript("divFooter", divScrolable.ClientID);

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.general")
        });

        tabControlElem.TabItems.Add(new UITabItem
        {
            Text = GetString("general.preview")
        });

        tabControlElem.UsePostback = true;

        rfvCodeName.ErrorMessage = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");

        Save += (s, ea) =>
        {
            if (SetData(true))
            {
                ltlScript.Text += ScriptHelper.GetScript("window.RefreshContent();CloseDialog();");
            }
        };

        int reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview = QueryHelper.GetBoolean("preview", false);
        if (reportId > 0)
        {
            mReportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);
        if (isPreview && !RequestHelper.IsPostBack())
        {
            tabControlElem.SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (mReportInfo != null) // Must be valid reportid parameter
            {
                int id = QueryHelper.GetInteger("objectid", 0);

                // Try to load tableName from hidden field (adding new graph & preview)
                if (id == 0)
                {
                    id = ValidationHelper.GetInteger(txtNewTableHidden.Value, 0);
                }

                if (id > 0)
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(id);
                    mReportTableInfo = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            mReportTableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (mReportInfo != null)
        {
            ucSelectString.DefaultConnectionString = mReportInfo.ReportConnectionString;

            // Control text initializations
            if (mReportTableInfo != null)
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.TitleText");
                mTableId = mReportTableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(mReportTableInfo))
                {
                    tabControlElem.TabItems.Add(new UITabItem
                    {
                        Text = GetString("objectversioning.tabtitle")
                    });

                    versionList.Object = mReportTableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                PageTitle.TitleText = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                if (!RequestHelper.IsPostBack())
                {
                    ucSelectString.Value = String.Empty;
                    txtPageSize.Text = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked = true;
                    chkSubscription.Checked = true;
                }
            }

            if (!RequestHelper.IsPostBack())
            {
                ControlsHelper.FillListControlWithEnum<PagerButtons>(drpPageMode, "PagerButtons");
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload default parameters
            FormInfo fi = new FormInfo(mReportInfo.ReportParameters);

            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow(false);
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Collect data and put them in table info
            SetData();
            ctrlReportTable.TableInfo = mReportTableInfo;
        }

        CurrentMaster.PanelContent.RemoveCssClass("dialog-content");
    }
    /// <summary>
    /// Combines widget info with default XML system propertiers.
    /// </summary>
    /// <param name="fi">Widget form info</param>
    /// <param name="wi">Widget info object</param>
    public DataRow CombineWithDefaultValues(FormInfo fi, WidgetInfo wi)
    {
        if ((!String.IsNullOrEmpty(wi.WidgetDefaultValues)) && (String.Compare(wi.WidgetDefaultValues, "<form></form>", false) != 0))
        {
            // Apply changed values
            DataRow dr = fi.GetDataRow();
            fi.LoadDefaultValues(dr, wi.WidgetDefaultValues);

            return dr;
        }

        return fi.GetDataRow();
    }
    /// <summary>
    /// Initializes inner controls.
    /// </summary>
    /// <param name="forceReload">Indicates if form with parameters should be reloaded</param>
    private void InitializeControl(bool forceReload = false)
    {
        // Init rule selector
        uniSelector.Value = mSelectedRuleName;

        MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName);
        if (mri != null)
        {
            // Show rule description
            ltlDescription.Text = mri.MacroRuleDescription;
            txtErrorMsg.Value = string.Empty;
            txtErrorMsg.WatermarkText = string.IsNullOrEmpty(DefaultErrorMessage) ? ResHelper.GetString("basicform.invalidinput") : DefaultErrorMessage;

            // Prepare form for rule parameters
            FormInfo fi = new FormInfo(mri.MacroRuleParameters);
            formProperties.FormInformation = fi;
            DataRow data = fi.GetDataRow();
            formProperties.DataRow = data;

            fi.LoadDefaultValues(formProperties.DataRow, FormResolveTypeEnum.AllFields);
            if ((mMacroRule != null) && (mMacroRuleTree != null) && mMacroRuleTree.RuleName.EqualsCSafe(mSelectedRuleName, true))
            {
                // Set params from rule given by Value property
                foreach (DictionaryEntry entry in mMacroRuleTree.Parameters)
                {
                    string paramName = ValidationHelper.GetString(entry.Key, string.Empty);
                    MacroRuleParameter param = entry.Value as MacroRuleParameter;

                    if ((param != null) && data.Table.Columns.Contains(paramName))
                    {
                        data[paramName] = param.Value;
                    }
                }

                txtErrorMsg.Value = mMacroRule.ErrorMessage;
            }

            if (forceReload)
            {
                // Reload params
                formProperties.ReloadData();
            }

            mParamsInitialized = true;
        }
    }
Ejemplo n.º 55
0
    /// <summary>
    /// Loads data for advanced mode
    /// </summary>
    private void LoadData()
    {
        if (!RequestHelper.IsPostBack())
        {
            if (mReportSubscriptionInfo.ReportSubscriptionID > 0)
            {
                // Initial settings
                ucInterval.ScheduleInterval = mReportSubscriptionInfo.ReportSubscriptionInterval;
                chkEnabled.Checked          = mReportSubscriptionInfo.ReportSubscriptionEnabled;
                txtEmail.Text       = mReportSubscriptionInfo.ReportSubscriptionEmail;
                txtSubject.Text     = mReportSubscriptionInfo.ReportSubscriptionSubject;
                chkNonEmpty.Checked = mReportSubscriptionInfo.ReportSubscriptionOnlyNonEmpty;
                ucMacroEditor.Text  = mReportSubscriptionInfo.ReportSubscriptionCondition;
            }
            else
            {
                // New item
                chkEnabled.Checked       = true;
                txtEmail.Text            = MembershipContext.AuthenticatedUser.Email;
                txtSubject.Text          = ResHelper.LocalizeString(Report.ReportDisplayName);
                chkNonEmpty.Checked      = true;
                ucInterval.DefaultPeriod = SchedulingHelper.PERIOD_DAY;
            }

            FillItems();
        }

        if ((Report != null) && !String.IsNullOrEmpty(Report.ReportParameters) && (Report.ReportParameters != "<form></form>"))
        {
            // Convert field "DateFrom" and "DateTo" to string to be able to display macros
            FormInfo      fi  = new FormInfo(Report.ReportParameters);
            FormFieldInfo ffi = fi.GetFormField("FromDate");

            if (ffi != null)
            {
                ffi.DataType  = FieldDataType.Text;
                ffi.FieldType = FormFieldControlTypeEnum.CalendarControl;
                ffi.Settings["AllowMacros"] = true;
                ffi.Size       = 400;
                ffi.AllowEmpty = true;
                ffi.Visible    = false;
            }

            ffi = fi.GetFormField("ToDate");
            if (ffi != null)
            {
                ffi.DataType  = FieldDataType.Text;
                ffi.FieldType = FormFieldControlTypeEnum.CalendarControl;
                ffi.Settings["AllowMacros"] = true;
                ffi.Size       = 400;
                ffi.AllowEmpty = true;
                ffi.Visible    = false;
            }

            // Get datarow from forminfo (it contains report parameters passed by querystring)
            DataRow defaultValues = fi.GetDataRow(false);

            // Load default values
            fi.LoadDefaultValues(defaultValues, true);

            // Display basic form, only if any item is visible
            bool display = false;
            foreach (FormFieldInfo field in fi.ItemsList)
            {
                if (field.Visible)
                {
                    display = true;
                    break;
                }
            }

            pnlParametersEnvelope.Visible = display;

            // Loop through all nodes is subscription's XML parameters and replace report's value with current subscription's ones.
            if (mReportSubscriptionInfo.ReportSubscriptionID > 0)
            {
                if (!String.IsNullOrEmpty(mReportSubscriptionInfo.ReportSubscriptionParameters))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(mReportSubscriptionInfo.ReportSubscriptionParameters);
                    foreach (DataColumn col in defaultValues.Table.Columns)
                    {
                        XmlNode node = xml.SelectSingleNode("/Root/" + col.ColumnName);
                        if (node != null)
                        {
                            // In case of different data types use try catch block
                            try
                            {
                                defaultValues[col.ColumnName] = DataHelper.ConvertValue(node.InnerText, col.DataType);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }


            mParameters             = defaultValues;
            pnlFromToParams.Visible = !SetTimeControls();

            // Set basic form parameters
            formElem.DataRow = defaultValues;
            formElem.SubmitButton.Visible = false;
            formElem.SubmitButton.RegisterHeaderAction = false;
            formElem.FormInformation = fi;
            formElem.SiteName        = SiteContext.CurrentSiteName;
            formElem.Mode            = FormModeEnum.Update;
            formElem.Visible         = true;
        }
        else
        {
            pnlParametersEnvelope.Visible = false;
            pnlFromToParams.Visible       = false;
        }
    }
    /// <summary>
    /// Show preview.
    /// </summary>
    private void ShowPreview()
    {
        if (reportInfo != null)
        {
            pnlPreview.Visible = true;
            divPanelHolder.Visible = false;
            categoryList.Visible = false;
            pnlVersions.Visible = false;

            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            DataRow dr = fi.GetDataRow();

            fi.LoadDefaultValues(dr);

            //reportGraph.ContextParameters
            ctrlReportValue.ReportParameters = dr;

            ctrlReportValue.Visible = true;
            ctrlReportValue.ValueInfo = valueInfo;

            ctrlReportValue.ReloadData(true);
        }
    }
Ejemplo n.º 57
0
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        // Check whether report graph is defined
        if (reportGraph == null)
        {
            return;
        }

        report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        //check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        EnableSubscription = (EnableSubscription && ValidationHelper.GetBoolean(ReportGraphInfo.GraphSettings["SubscriptionEnabled"], true) && report.ReportEnableSubscription);
        if (EmailMode && !EnableSubscription)
        {
            this.Visible = false;
            return;
        }

        //Set default parametrs directly if not set
        if (ReportParameters == null)
        {
            //Load ReportInfo
            if (report != null)
            {
                FormInfo fi = new FormInfo(report.ReportParameters);
                // Get datarow with required columns
                ReportParameters = fi.GetDataRow(false);
                fi.LoadDefaultValues(ReportParameters, true);
            }
        }

        // Only use base parameters in case of stored procedure
        if (QueryIsStoredProcedure)
        {
            AllParameters = SpecialFunctions.ConvertDataRowToParams(ReportParameters, null);
        }

        // Indicaates whether exception was throw during data loading
        errorOccurred = false;

        // Create graph data
        try
        {
            ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();
            //Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

            // Resolve dynamic data macros
            if (DynamicMacros != null)
            {
                for (int i = 0; i <= DynamicMacros.GetUpperBound(0); i++)
                {
                    resolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]);
                }
            }

            //Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // Load data
            DataSource = LoadData();

            if (DataHelper.DataSourceIsEmpty(DataSource) && EmailMode && SendOnlyNonEmptyDataSource)
            {
                Visible = false;
                return;
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            errorOccurred    = true;
        }
    }
    /// <summary>
    /// Returns report graph.
    /// </summary>
    private void GetReportGraph(ReportGraphInfo reportGraph)
    {
        Visible = true;
        ucChart.Visible = true;

        int correctWidth = 0;
        if (ComputedWidth != 0)
        {
            correctWidth = ModifyGraphInfo();
        }

        if (Width != String.Empty)
        {
            int graphWidth = ValidationHelper.GetInteger(Width, 0);
            if (graphWidth != 0)
            {
                reportGraph.GraphWidth = graphWidth;
            }
        }

        if (Height != 0)
        {
            reportGraph.GraphHeight = Height;
        }

        ReportGraph graph = new ReportGraph();
        graph.ChartControl = ucChart;

        ReportInfo report = ReportInfoProvider.GetReportInfo(reportGraph.GraphReportID);
        if (report == null)
        {
            return;
        }

        // Check graph security settings
        if (report.ReportAccess != ReportAccessEnum.All)
        {
            if (!CMSContext.CurrentUser.IsAuthenticated())
            {
                Visible = false;
                return;
            }
        }

        // Set default parametrs directly if not set
        if (ReportParameters == null)
        {
            // Load ReportInfo
            if (report != null)
            {
                FormInfo fi = new FormInfo(report.ReportParameters);
                // Get datarow with required columns
                ReportParameters = fi.GetDataRow();
                fi.LoadDefaultValues(ReportParameters);
            }
        }

        // If used via widget - this function ensure showing specific interval from actual time (f.e. last 6 weeks)
        ApplyTimeParameters();

        // Only use base parameters in case of stored procedure
        if (QueryIsStoredProcedure)
        {
            AllParameters = SpecialFunctions.ConvertDataRowToParams(ReportParameters, null);
        }

        ContextResolver resolver = CMSContext.CurrentResolver.CreateContextChild();

        // Indicaates whether exception was throw during data loading
        bool errorOccurred = false;

        // Create graph image
        try
        {
            // Resolve parameters in query
            resolver.SourceParameters = AllParameters.ToArray();

            // Resolve dynamic data macros
            if (DynamicMacros != null)
            {
                for (int i = 0; i <= DynamicMacros.GetUpperBound(0); i++)
                {
                    resolver.AddDynamicParameter(DynamicMacros[i, 0], DynamicMacros[i, 1]);
                }
            }

            // Prepare query attributes
            QueryText = resolver.ResolveMacros(reportGraph.GraphQuery);
            QueryIsStoredProcedure = reportGraph.GraphQueryIsStoredProcedure;

            // LoadData
            DataSet dsGraphData = LoadData();

            // Test if dataset is empty
            if (DataHelper.DataSourceIsEmpty(dsGraphData))
            {
                string noRecordText = ValidationHelper.GetString(reportGraph.GraphSettings["QueryNoRecordText"], String.Empty);
                if (noRecordText != String.Empty)
                {
                    lblInfo.Text = noRecordText;
                    lblInfo.Visible = true;
                    ucChart.Visible = false;
                    menuCont.MenuID = String.Empty;
                    return;
                }
                Visible = false;
            }
            else
            {
                // Create Chart
                graph.CorrectWidth = correctWidth;
                graph.CreateChart(reportGraph, dsGraphData, resolver);
            }
        }
        catch (Exception ex)
        {
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Get report graph", "E", ex);
            graph.CorrectWidth = correctWidth;
            graph.CreateInvalidDataGraph(reportGraph, "Reporting.Graph.InvalidDataGraph", false);
            errorOccurred = true;
        }

        // Export data
        if ((report != null) && (!errorOccurred))
        {
            ProcessExport(ValidationHelper.GetCodeName(report.ReportDisplayName));
        }
    }
Ejemplo n.º 59
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Test permission for query
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Reporting", "EditSQLQueries"))
        {
            txtQuery.Enabled = false;
        }
        else
        {
            txtQuery.Enabled = true;
        }

        versionList.OnAfterRollback += new EventHandler(versionList_onAfterRollback);

        // Own javascript tab change handling -> because tab control raises changetab after prerender - too late
        // Own selected tab change handling
        RegisterTabScript(hdnSelectedTab.ClientID, tabControlElem);

        // Register common resize and refresh scripts
        RegisterResizeAndRollbackScript(divFooter.ClientID, divScrolable.ClientID);

        string[,] tabs = new string[4, 4];
        tabs[0, 0]     = GetString("general.general");
        tabs[0, 1]     = "SetHelpTopic('helpTopic', 'report_table_properties')";
        tabs[1, 0]     = GetString("general.preview");
        tabs[0, 1]     = "SetHelpTopic('helpTopic', 'report_table_properties')";

        tabControlElem.Tabs               = tabs;
        tabControlElem.UsePostback        = true;
        CurrentMaster.Title.HelpName      = "helpTopic";
        CurrentMaster.Title.HelpTopicName = "report_table_properties";
        CurrentMaster.Title.TitleCssClass = "PageTitleHeader";

        rfvCodeName.ErrorMessage    = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        btnApply.Text  = GetString("General.apply");
        btnOk.Text     = GetString("General.OK");
        btnCancel.Text = GetString("General.Cancel");

        int  reportId = QueryHelper.GetInteger("reportid", 0);
        bool preview  = QueryHelper.GetBoolean("preview", false);

        if (reportId > 0)
        {
            reportInfo = ReportInfoProvider.GetReportInfo(reportId);
        }

        // If preview by URL -> select preview tab
        bool isPreview = QueryHelper.GetBoolean("preview", false);

        if (isPreview && !RequestHelper.IsPostBack())
        {
            SelectedTab = 1;
        }

        if (PersistentEditedObject == null)
        {
            if (reportInfo != null) // Must be valid reportid parameter
            {
                string tableName = ValidationHelper.GetString(Request.QueryString["itemname"], "");

                // Try to load tableName from hidden field (adding new graph & preview)
                if (tableName == String.Empty)
                {
                    tableName = txtNewTableHidden.Value;
                }

                if (ValidationHelper.IsIdentifier(tableName))
                {
                    PersistentEditedObject = ReportTableInfoProvider.GetReportTableInfo(reportInfo.ReportName + "." + tableName);
                    tableInfo = PersistentEditedObject as ReportTableInfo;
                }
            }
        }
        else
        {
            tableInfo = PersistentEditedObject as ReportTableInfo;
        }

        if (reportInfo != null)
        {
            // Control text initializations
            if (tableInfo != null)
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportTable_Edit.TitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/object.png");

                tableId = tableInfo.TableID;

                if (ObjectVersionManager.DisplayVersionsTab(tableInfo))
                {
                    tabs[2, 0] = GetString("objectversioning.tabtitle");
                    tabs[2, 1] = "SetHelpTopic('helpTopic', 'objectversioning_general');";

                    versionList.Object     = tableInfo;
                    versionList.IsLiveSite = false;
                }
            }
            else // New item
            {
                CurrentMaster.Title.TitleText  = GetString("Reporting_ReportTable_Edit.NewItemTitleText");
                CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Reporting_ReportTable/new.png");

                if (!RequestHelper.IsPostBack())
                {
                    txtPageSize.Text          = "15";
                    txtQueryNoRecordText.Text = GetString("attachmentswebpart.nodatafound");
                    chkExportEnable.Checked   = true;
                }

                newTable = true;
            }

            // Set help key
            CurrentMaster.Title.HelpTopicName = "report_table_properties";

            if (!RequestHelper.IsPostBack())
            {
                DataHelper.FillListControlWithEnum(typeof(PagerButtons), drpPageMode, "PagerButtons.", null);
                // Preselect page numbers paging
                drpPageMode.SelectedValue = ((int)PagerButtons.Numeric).ToString();

                LoadData();
            }
        }

        if ((preview) && (!RequestHelper.IsPostBack()))
        {
            tabControlElem.SelectedTab = 1;
            ShowPreview();
        }

        // In case of preview paging without saving table
        if (RequestHelper.IsPostBack() && tabControlElem.SelectedTab == 1)
        {
            // Reload deafult parameters
            FormInfo fi = new FormInfo(reportInfo.ReportParameters);
            // Get datarow with required columns
            ctrlReportTable.ReportParameters = fi.GetDataRow();
            fi.LoadDefaultValues(ctrlReportTable.ReportParameters, true);

            // Colect data and put them in talbe info
            Save(false);
            ctrlReportTable.TableInfo = tableInfo;
        }
    }
    /// <summary>
    /// Reload data.
    /// </summary>
    public override void ReloadData(bool forceLoad)
    {
        if ((GraphImageWidth != 0) && (ComputedWidth == 0))
        {
            // Graph width is computed no need to create graph
            return;
        }

        this.Visible = true;

        // Indicaates whether exception was throw during data loading
        bool errorOccurred = false;
        ReportInfo ri = null;

        try
        {
            this.ReportTableName = this.Parameter;

            this.EnsureTableInfo();
            this.EnsureChildControls();

            //Test security
            if (TableInfo != null)
            {
                ri = ReportInfoProvider.GetReportInfo(TableInfo.TableReportID);
                if (ri != null)
                {
                    if (ri.ReportAccess != ReportAccessEnum.All)
                    {
                        if (!CMSContext.CurrentUser.IsAuthenticated())
                        {
                            this.Visible = false;
                            return;
                        }
                    }

                    //Set default parametrs directly if not set
                    if (this.ReportParameters == null)
                    {
                        FormInfo fi = new FormInfo(ri.ReportParameters);
                        // Get datarow with required columns
                        this.ReportParameters = fi.GetDataRow();
                        fi.LoadDefaultValues(this.ReportParameters);
                    }

                    ApplyTimeParameters();
                }
            }

            // Only use base parameters in case of stored procedure
            if (this.QueryIsStoredProcedure)
            {
                this.AllParameters = SpecialFunctions.ConvertDataRowToParams(this.ReportParameters, null);
            }

            // Load data
            DataSet ds = this.LoadData();

            // If no data load, set empty dataset
            if (DataHelper.DataSourceIsEmpty(ds))
            {
                string noRecordText = ValidationHelper.GetString(TableInfo.TableSettings["QueryNoRecordText"], String.Empty);
                if (noRecordText != String.Empty)
                {
                    GridViewObject.Visible = false;
                    lblInfo.Text = noRecordText;
                    lblInfo.Visible = true;
                    return;
                }

                this.Visible = false;
            }
            else
            {
                GridViewObject.Visible = true;
                // Resolve macros in column names
                int i = 0;
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    if (dc.ColumnName == "Column" + ((int)(i + 1)).ToString())
                    {
                        dc.ColumnName = ResolveMacros(ds.Tables[0].Rows[0][i].ToString());
                    }
                    else
                    {
                        dc.ColumnName = ResolveMacros(dc.ColumnName);
                    }
                    i++;
                }

                // Resolve macros in dataset
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foreach (DataColumn dc in ds.Tables[0].Columns)
                    {
                        if (dc.DataType.FullName.ToLower() == "system.string")
                        {
                            dr[dc.ColumnName] = ResolveMacros(ValidationHelper.GetString(dr[dc.ColumnName], ""));
                        }
                    }
                }
            }

            ApplyStyles();

            // Databind to gridview control
            GridViewObject.DataSource = ds;
            this.EnsurePageIndex();
            GridViewObject.DataBind();

            if ((TableFirstColumnWidth != Unit.Empty) && (GridViewObject.Rows.Count > 0))
            {
                GridViewObject.Rows[0].Cells[0].Width = TableFirstColumnWidth;
            }

        }
        catch (Exception ex)
        {
            // Display error message, if data load fail
            lblError.Visible = true;
            lblError.Text = "[ReportTable.ascx] Error loading the data: " + ex.Message;
            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent("Report table", "E", ex);
            errorOccurred = true;
        }

        // Export data
        if ((ri != null) && (!errorOccurred))
        {
            ProcessExport(ValidationHelper.GetCodeName(ri.ReportDisplayName));
        }
    }