Ejemplo n.º 1
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        int reportId = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName)
        {
        case "delete":
            // Check 'Modify' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                RedirectToAccessDenied("cms.reporting", "Modify");
            }

            // Delete ReportInfo object from database
            ReportInfoProvider.DeleteReportInfo(reportId);

            // Refresh tree after delete
            ltlScript.Text += ScriptHelper.GetScript("RefreshAdditionalContent();");
            break;

        case "clone":
            Clone(reportId);
            break;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Handles delete action.
    /// </summary>
    /// <param name="eventArgument">Objecttype(report or reportcategory);objectid</param>
    public void RaisePostBackEvent(string eventArgument)
    {
        string[] values = eventArgument.Split(';');
        if ((values != null) && (values.Length == 3))
        {
            int id                 = ValidationHelper.GetInteger(values[1], 0);
            int parentId           = ValidationHelper.GetInteger(values[2], 0);
            ReportCategoryInfo rci = ReportCategoryInfoProvider.GetReportCategoryInfo(parentId);

            //Test permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
            {
                String denyScript = @"var redirected = false;if (!redirected) {if ((window.parent != null) && (window.parent.frames['reportcategorytree'] != null)) {
                parent.frames['reportedit'].location = '" + ResolveUrl(AccessDeniedPage) + @"?resource=cms.reporting&permission=Modify';redirected = true;         
                }}";
                if (rci != null)
                {
                    denyScript = SelectAtferLoad(rci.CategoryPath + "/", id, values[0], parentId, false) + denyScript;
                }
                ltlScript.Text += ScriptHelper.GetScript(denyScript);
                return;
            }

            string script = String.Empty;

            switch (values[0])
            {
            case "report":
                ReportInfoProvider.DeleteReportInfo(id);
                break;

            case "reportcategory":
                try
                {
                    ReportCategoryInfoProvider.DeleteReportCategoryInfo(id);
                }
                catch (Exception ex)
                {
                    // Make alert with exception message, most probable cause is deleting category with subcategories
                    script = String.Format("alert('{0}');\n", ex.Message);

                    // Current node stays selected
                    parentId = id;
                }
                break;
            }

            // Select parent node after delete
            if (rci != null)
            {
                script          = SelectAtferLoad(rci.CategoryPath + "/", parentId, "reportcategory", rci.CategoryParentID, true) + script;
                ltlScript.Text += ScriptHelper.GetScript(script);
            }

            treeElem.ReloadData();
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Deletes report. Called when the "Delete report" button is pressed.
    /// Expects the CreateReport method to be run first.
    /// </summary>
    private bool DeleteReport()
    {
        // Get the report
        ReportInfo deleteReport = ReportInfoProvider.GetReportInfo("MyNewReport");

        // Delete the report
        ReportInfoProvider.DeleteReportInfo(deleteReport);

        return(deleteReport != null);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Clones the given report (including attachment files).
    /// </summary>
    /// <param name="reportId">Report id</param>
    protected void Clone(int reportId)
    {
        // Check 'Modify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
        {
            RedirectToAccessDenied("cms.reporting", "Modify");
        }

        // Try to get report info
        ReportInfo oldri = ReportInfoProvider.GetReportInfo(reportId);

        if (oldri == null)
        {
            return;
        }

        DataSet graph_ds = ReportGraphInfoProvider.GetGraphs(reportId);
        DataSet table_ds = ReportTableInfoProvider.GetTables(reportId);
        DataSet value_ds = ReportValueInfoProvider.GetValues(reportId);

        // Duplicate report info object
        ReportInfo ri = new ReportInfo(oldri, false);

        ri.ReportID   = 0;
        ri.ReportGUID = Guid.NewGuid();

        // Duplicate report info
        string reportName    = ri.ReportName;
        string oldReportName = ri.ReportName;

        string reportDispName = ri.ReportDisplayName;

        while (ReportInfoProvider.GetReportInfo(reportName) != null)
        {
            reportName     = Increment(reportName, "_", "", 100);
            reportDispName = Increment(reportDispName, "(", ")", 450);
        }

        ri.ReportName        = reportName;
        ri.ReportDisplayName = reportDispName;

        // Used to eliminate version from create object task
        using (CMSActionContext context = new CMSActionContext())
        {
            context.CreateVersion = false;
            ReportInfoProvider.SetReportInfo(ri);
        }

        string name;

        // Duplicate graph data
        if (!DataHelper.DataSourceIsEmpty(graph_ds))
        {
            foreach (DataRow dr in graph_ds.Tables[0].Rows)
            {
                // Duplicate the graph
                ReportGraphInfo rgi = new ReportGraphInfo(dr);
                rgi.GraphID       = 0;
                rgi.GraphGUID     = Guid.NewGuid();
                rgi.GraphReportID = ri.ReportID;
                name = rgi.GraphName;

                // Replace layout based on HTML or regular graph type
                ri.ReportLayout = ReplaceMacro(ri.ReportLayout, rgi.GraphIsHtml ? REP_HTMLGRAPH_MACRO : REP_GRAPH_MACRO, rgi.GraphName, name, oldReportName, reportName);
                rgi.GraphName   = name;

                ReportGraphInfoProvider.SetReportGraphInfo(rgi);
            }
        }

        // Duplicate table data
        if (!DataHelper.DataSourceIsEmpty(table_ds))
        {
            foreach (DataRow dr in table_ds.Tables[0].Rows)
            {
                // Duplicate the table
                ReportTableInfo rti = new ReportTableInfo(dr);
                rti.TableID       = 0;
                rti.TableGUID     = Guid.NewGuid();
                rti.TableReportID = ri.ReportID;
                name = rti.TableName;

                ri.ReportLayout = ReplaceMacro(ri.ReportLayout, REP_TABLE_MACRO, rti.TableName, name, oldReportName, reportName);
                rti.TableName   = name;

                ReportTableInfoProvider.SetReportTableInfo(rti);
            }
        }

        // Duplicate value data
        if (!DataHelper.DataSourceIsEmpty(value_ds))
        {
            foreach (DataRow dr in value_ds.Tables[0].Rows)
            {
                // Duplicate the value
                ReportValueInfo rvi = new ReportValueInfo(dr);
                rvi.ValueID       = 0;
                rvi.ValueGUID     = Guid.NewGuid();
                rvi.ValueReportID = ri.ReportID;
                name = rvi.ValueName;

                ri.ReportLayout = ReplaceMacro(ri.ReportLayout, REP_VALUE_MACRO, rvi.ValueName, name, oldReportName, reportName);
                rvi.ValueName   = name;

                ReportValueInfoProvider.SetReportValueInfo(rvi);
            }
        }

        List <Guid> convTable = new List <Guid>();

        try
        {
            MetaFileInfoProvider.CopyMetaFiles(reportId, ri.ReportID, ReportingObjectType.REPORT, MetaFileInfoProvider.OBJECT_CATEGORY_LAYOUT, convTable);
        }
        catch (Exception e)
        {
            lblError.Visible = true;
            lblError.Text    = e.Message;
            ReportInfoProvider.DeleteReportInfo(ri);
            return;
        }

        for (int i = 0; i < convTable.Count; i += 2)
        {
            Guid oldGuid = convTable[i];
            Guid newGuid = convTable[i + 1];
            ri.ReportLayout = ri.ReportLayout.Replace(oldGuid.ToString(), newGuid.ToString());
        }

        ReportInfoProvider.SetReportInfo(ri);

        // Refresh tree
        ltlScript.Text += "<script type=\"text/javascript\">";
        ltlScript.Text += @"if (parent.frames['reportcategorytree'])
                                {
                                    parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"';
                                }    
                                if (parent.parent.frames['reportcategorytree'])
                                {
                                    parent.parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"';
                                }                           
                 this.location.href = 'Report_Edit.aspx?reportId=" + Convert.ToString(ri.ReportID) + @"&saved=1&categoryID=" + categoryId + @"'
                </script>";
    }