Exemplo n.º 1
0
 protected void lstMODULE_Changed(Object sender, EventArgs e)
 {
     lblMODULE.Text = lstMODULE.SelectedValue;
     // 05/26/2006 Paul.  If the module changes, then throw away everything.
     // The display columns don't count, the group columns don't count, etc.
     rdl = new RdlDocument(txtNAME.Text, txtASSIGNED_TO.Text);
     rdl.SetCustomProperty("Module"        , lstMODULE.SelectedValue );
     rdl.SetCustomProperty("Related"       , String.Empty);
     rdl.SetCustomProperty("RelatedModules", String.Empty);
     rdl.SetCustomProperty("Relationships" , String.Empty);
     rdl.SetCustomProperty("Filters"       , String.Empty);
     lstRELATED_Bind();
     lblRELATED.Text = lstRELATED.SelectedValue;
     dgFilters.DataSource = ReportFilters();
     dgFilters.DataBind();
     BuildReportSQL();
     // 07/13/2006 Paul.  The DisplayColumns List must be bound after the ReportSQL is built.
     lstLeftListBox_Bind();
     ctlReportView.ClearReport();
 }
Exemplo n.º 2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if ( !this.Visible )
                return;

            reqNAME.DataBind();
            lblDisplayColumnsRequired.DataBind();
            lblDisplayColumnsRequired.Visible = false;

            rdl = new RdlDocument();
            #if DEBUG
            bDebug = true;
            #endif
            lblMODULE              .Visible = bDebug;
            lblRELATED             .Visible = bDebug;
            lblMODULE_COLUMN_SOURCE.Visible = bDebug;
            lblFILTER_COLUMN_SOURCE.Visible = bDebug;
            lblFILTER_COLUMN       .Visible = bDebug;
            lblFILTER_OPERATOR_TYPE.Visible = bDebug;
            lblFILTER_OPERATOR     .Visible = bDebug;
            lblFILTER_ID           .Visible = bDebug;
            try
            {
                gID = Sql.ToGuid(Request["ID"]);

                bRun = Sql.ToBoolean(Request["Run"]);
                string sRdl = Sql.ToString(Session["rdl"]);
                // 07/09/2006 Paul.  The ReportViewer has a bug that prevents it from reloading a previous RDL.
                // The only solution is to create a new ReportViewer object.
                if ( bRun && sRdl.Length > 0 )
                {
                    // 07/13/2006 Paul.  We don't store the SHOW_QUERY value in the RDL, so we must retrieve it from the session.
                    chkSHOW_QUERY.Checked = Sql.ToBoolean(Session["Reports.SHOW_QUERY"]);
                    // 07/09/2006 Paul.  Clear the Run parameter on the command line.
                    Page.RegisterClientScriptBlock("frmRedirect", "<script>document.forms[0].action='edit.aspx?ID=" + gID.ToString() + "';</script>");
                    // 07/09/2006 Paul.  Clear the session variable as soon as we are done loading it.
                    //Session.Remove("rdl");
                    rdl.LoadRdl(sRdl);

                    txtNAME.Text              = rdl.SelectNodeAttribute(String.Empty, "Name");
                    txtACTIVE_TAB.Value       = "1";
                    radREPORT_TYPE_TABULAR.Checked = true;
                    txtASSIGNED_USER_ID.Value = rdl.GetCustomPropertyValue("AssignedUserID");
                    txtASSIGNED_TO.Text       = rdl.SelectNodeValue("Author");

                    SetReportType(rdl.GetCustomPropertyValue("ReportType"));
                    ctlModuleHeader.Title = rdl.SelectNodeAttribute(String.Empty, "Name");
                    Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                    ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;
                    ViewState["ASSIGNED_USER_ID"     ] = txtASSIGNED_USER_ID.Value;

                    try
                    {
                        lstMODULE.DataSource = SplendidCache.ReportingModules();
                        lstMODULE.DataBind();
                        lstMODULE.SelectedValue = rdl.GetCustomPropertyValue("Module");
                    }
                    catch(Exception ex)
                    {
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                    }
                    lstRELATED_Bind();
                    try
                    {
                        lstRELATED.SelectedValue = rdl.GetCustomPropertyValue("Related");
                    }
                    catch
                    {
                    }
                    ctlDisplayColumnsChooser_Bind();
                    BuildReportSQL();
                    // 07/13/2006 Paul.  The DisplayColumns List must be bound after the ReportSQL is built.
                    lstLeftListBox_Bind();

                    dgFilters.DataSource = ReportFilters();
                    dgFilters.DataBind();

                    ctlReportView.RunReport(rdl.OuterXml);
                }
                else if ( !IsPostBack )
                {
                    txtNAME.Text              = "untitled";
                    txtACTIVE_TAB.Value       = "1";
                    radREPORT_TYPE_TABULAR.Checked = true;
                    txtASSIGNED_TO.Text       = Security.USER_NAME;
                    txtASSIGNED_USER_ID.Value = Security.USER_ID.ToString();
                    ViewState["ASSIGNED_USER_ID"] = txtASSIGNED_USER_ID.Value;
                    lstMODULE.DataSource = SplendidCache.ReportingModules();
                    lstMODULE.DataBind();
                    lblMODULE.Text = lstMODULE.SelectedValue;

                    // 07/13/2006 Paul.  We don't store the SHOW_QUERY value in the RDL, so we must retrieve it from the session.
                    chkSHOW_QUERY.Checked = Sql.ToBoolean(Session["Reports.SHOW_QUERY"]);

                    Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                    if ( !Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID) )
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using ( IDbConnection con = dbf.CreateConnection() )
                        {
                            string sSQL;
                            sSQL = "select *             " + ControlChars.CrLf
                                 + "  from vwREPORTS_Edit" + ControlChars.CrLf
                                 + " where ID = @ID      " + ControlChars.CrLf;
                            using ( IDbCommand cmd = con.CreateCommand() )
                            {
                                cmd.CommandText = sSQL;
                                if ( !Sql.IsEmptyGuid(gDuplicateID) )
                                {
                                    Sql.AddParameter(cmd, "@ID", gDuplicateID);
                                    gID = Guid.Empty;
                                }
                                else
                                {
                                    Sql.AddParameter(cmd, "@ID", gID);
                                }
                                con.Open();
            #if DEBUG
                                Page.RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
            #endif
                                using ( IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow) )
                                {
                                    if ( rdr.Read() )
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["NAME"]);
                                        Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;

                                        txtNAME.Text              = Sql.ToString(rdr["NAME"            ]);
                                        txtASSIGNED_USER_ID.Value = Sql.ToString(rdr["ASSIGNED_USER_ID"]);
                                        txtASSIGNED_TO.Text       = Sql.ToString(rdr["ASSIGNED_TO"     ]);
                                        ViewState["ASSIGNED_USER_ID"] = txtASSIGNED_USER_ID.Value;

                                        string sXML = Sql.ToString(rdr["RDL"]);
                                        try
                                        {
                                            if ( !Sql.IsEmptyString(sXML) )
                                            {
                                                rdl.LoadRdl(Sql.ToString(rdr["RDL"]));

                                                SetReportType(rdl.GetCustomPropertyValue("ReportType"));
                                                // 07/09/2006 Paul.  Update Assigned values as they may have changed externally.
                                                rdl.SetCustomProperty("AssignedUserID", txtASSIGNED_USER_ID.Value);
                                                rdl.SetSingleNode("Author", txtASSIGNED_TO.Text);
                                                lstMODULE.SelectedValue = rdl.GetCustomPropertyValue("Module");
                                                lblMODULE.Text = lstMODULE.SelectedValue;
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // 05/27/2006 Paul.  This is a catch-all statement to create a new report if all else fails.
                    if ( rdl.DocumentElement == null )
                    {
                        rdl = new RdlDocument(txtNAME.Text, txtASSIGNED_TO.Text);
                        rdl.SetCustomProperty("Module"        , lstMODULE.SelectedValue  );
                        rdl.SetCustomProperty("Related"       , lstRELATED.SelectedValue );
                        rdl.SetCustomProperty("ReportType"    , GetReportType()          );
                        rdl.SetCustomProperty("AssignedUserID", txtASSIGNED_USER_ID.Value);
                    }
                    lstRELATED_Bind();
                    lblRELATED.Text = lstRELATED.SelectedValue;
                    try
                    {
                        lstRELATED.SelectedValue = rdl.GetCustomPropertyValue("Related");
                    }
                    catch
                    {
                    }
                    BuildReportSQL();
                    // 07/13/2006 Paul.  The DisplayColumns List must be bound after the ReportSQL is built.
                    lstLeftListBox_Bind();

                    dgFilters.DataSource = ReportFilters();
                    dgFilters.DataBind();
                }
                else
                {
                    // 07/13/2006 Paul.  Save the SHOW_QUERY flag in the Session so that it will be available across redirects.
                    Session["Reports.SHOW_QUERY"] = chkSHOW_QUERY.Checked;

                    sRdl = Sql.ToString(ViewState["rdl"]);
                    rdl.LoadRdl(sRdl);
                    rdl.SetSingleNodeAttribute(rdl.DocumentElement, "Name", txtNAME.Text);
                    if ( Sql.ToString(ViewState["ASSIGNED_USER_ID"]) != txtASSIGNED_USER_ID.Value )
                    {
                        txtASSIGNED_TO.Text = Crm.Users.USER_NAME(Sql.ToGuid(txtASSIGNED_USER_ID.Value));
                        ViewState["ASSIGNED_USER_ID"] = txtASSIGNED_USER_ID.Value;
                    }
                    rdl.SetCustomProperty("ReportType"    , GetReportType()          );
                    rdl.SetCustomProperty("AssignedUserID", txtASSIGNED_USER_ID.Value);
                    rdl.SetSingleNode("Author", txtASSIGNED_TO.Text);
                    // 07/15/2006 Paul.  The DisplayColumns custom node will not be the primary location of the column data.
                    // Always just push to the RDL Headers instead of trying to read from them.
                    DisplayColumnsUpdate();
                    XmlDocument xmlDisplayColumns = rdl.GetCustomProperty("DisplayColumns");
                    DataTable dtDisplayColumns = XmlUtil.CreateDataTable(xmlDisplayColumns.DocumentElement, "DisplayColumn", new string[] { "Label", "Field"});
                    rdl.UpdateDataTable(dtDisplayColumns);
                    xmlDisplayColumns = null;

                    ctlDisplayColumnsChooser_Bind();
                    BuildReportSQL();
                    // 07/13/2006 Paul.  The DisplayColumns List must be bound after the ReportSQL is built.
                    lstLeftListBox_Bind();

                    dgFilters.DataSource = ReportFilters();
                    dgFilters.DataBind();

                    // 12/02/2005 Paul.  When validation fails, the header title does not retain its value.  Update manually.
                    ctlModuleHeader.Title = Sql.ToString(ViewState["ctlModuleHeader.Title"]);
                    Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                }
            #if DEBUG
                //Page.RegisterClientScriptBlock("ReportSQL", "<script type=\"text/javascript\">sDebugSQL += '" + Sql.EscapeJavaScript("\r" + sReportSQL) + "';</script>");
            #endif
            }
            catch(Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                ctlReportButtons.ErrorText = ex.Message;
            }
        }