Пример #1
0
        private void FormatearReporte(crActaTitulacion rep)
        {
            SubreportObject subrep = rep.ReportDefinition.ReportObjects["subrepTitulados"] as SubreportObject;
            ReportDocument  srTitulados = subrep.OpenSubreport("srTitulados");
            ReportObjects   objSecEncabezado = srTitulados.ReportDefinition.Sections["Section6"].ReportObjects;
            ReportObjects   objSecDetalle = srTitulados.ReportDefinition.Sections["Section5"].ReportObjects;
            int             x_ini = objSecEncabezado["lnv01"].Left, x_fin = objSecEncabezado["lnv02"].Left;
            int             n_distancia = (x_fin - x_ini) / v_nRequisitosCalificados;


            /*Response.Write(objSecEncabezado["lnv11"].GetType().ToString());
             * Response.Flush();*/

            LineObject linea = objSecEncabezado["lnv11"] as LineObject;

            /*Response.Write("<br>"+linea.Left.ToString());
             * Response.Flush();*/
            //objSecEncabezado["lnv11"].Left = 11000;



            //objSecEncabezado["lnv11"].Left = 8000;
            //objSecEncabezado["lnv12"].Left = n_distancia * 2;



            //objSecEncabezado["Text37"].Left = 0;
        }
Пример #2
0
        private static void SetLocation(ReportDocument report)
        {
            ConnectionInfo targetConnection = new ConnectionInfo();

            targetConnection.DatabaseName = "Sakila2";

            foreach (Table table in report.Database.Tables)
            {
                ConnectionInfo connectionInfo = table.LogOnInfo.ConnectionInfo;

                table.LogOnInfo.ConnectionInfo = targetConnection;

                table.ApplyLogOnInfo(table.LogOnInfo);

                if (table.TestConnectivity())
                {
                }
            }

            foreach (ReportObject reportObject in report.ReportDefinition.ReportObjects)
            {
                if (reportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject subreportObject = (SubreportObject)reportObject;

                    ReportDocument subreport = subreportObject.OpenSubreport(subreportObject.SubreportName);

                    SetLocation(subreport);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// iterate though subReports to populate list of documents and fieldnames
        /// </summary>
        /// <param name="sections">Sections of document to walk</param>
        /// <param name="reportDocList">list of inner subreport docs to populate</param>
        /// <param name="fieldNames">hashset of fieldNames to populate</param>
        private void WalkSubReports(Sections sections, List <ReportDocument> reportDocList, HashSet <string> fieldNames)
        {
            foreach (CrystalDecisions.CrystalReports.Engine.Section section in sections)
            {
                // In each section we need to loop through all the reporting objects
                foreach (ReportObject reportObject in section.ReportObjects)
                {
                    if (reportObject is CrystalDecisions.CrystalReports.Engine.FieldObject)
                    {
                        DatabaseFieldDefinition fieldDefn = ((FieldObject)reportObject).DataSource as DatabaseFieldDefinition;

                        if (fieldDefn != null)
                        {
                            fieldNames.Add(string.Format("{0}.{1}", fieldDefn.TableName, fieldDefn.Name));
                        }
                    }

                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subReport   = (SubreportObject)reportObject;
                        ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);
                        reportDocList.Add(subDocument);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Assign the DataSet to the report.
        /// </summary>
        private void AssignDataSet()
        {
            DataSet reportData = _reportData.Copy();

            // Remove primary key info. CR9 does not appreciate this information!!!
            foreach (DataTable dataTable in reportData.Tables)
            {
                foreach (DataColumn dataColumn in dataTable.PrimaryKey)
                {
                    dataColumn.AutoIncrement = false;
                }
                dataTable.PrimaryKey = null;
            }

            // Now assign the dataset to all tables in the main report
            //
            _reportDocument.SetDataSource(reportData);

            // Now loop through all the sections and its objects to do the same for the subreports
            //
            foreach (CrystalDecisions.CrystalReports.Engine.Section section in _reportDocument.ReportDefinition.Sections)
            {
                // In each section we need to loop through all the reporting objects
                foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
                {
                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subReport   = (SubreportObject)reportObject;
                        ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);

                        subDocument.SetDataSource(reportData);
                    }
                }
            }
        }
Пример #5
0
        public void Dispose()
        {
            if (this.report != null)
            {
                try
                {
                    Sections sections = this.report.ReportDefinition.Sections;
                    foreach (Section section in sections)
                    {
                        ReportObjects reportObjects = section.ReportObjects;
                        foreach (ReportObject reportObject in reportObjects)
                        {
                            if (reportObject.Kind == ReportObjectKind.SubreportObject)
                            {
                                SubreportObject subreportObject   = (SubreportObject)reportObject;
                                ReportDocument  subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
                                subReportDocument.Close();
                            }
                        }
                    }
                    this.report.Close();
                }
                catch
                {
                }

                this.report.Dispose();
            }
        }
Пример #6
0
        private bool Logon(
            ReportDocument cr,
            string server,
            string database,
            string user_id,
            string password)
        {
            ConnectionInfo ci = new ConnectionInfo();

            ci.ServerName         = server;
            ci.DatabaseName       = database;
            ci.IntegratedSecurity = true;
            if (!this.ApplyLogon(cr, ci))
            {
                return(false);
            }
            foreach (ReportObject reportObject in (SCRCollection)cr.ReportDefinition.ReportObjects)
            {
                if (reportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject subreportObject = (SubreportObject)reportObject;
                    if (!this.ApplyLogon(cr.OpenSubreport(subreportObject.SubreportName), ci))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 private void RenderSubreport(SubreportObject subreport)
 {
     if (subreport.ReportPage != null)
     {
         RunBands(subreport.ReportPage.Bands);
     }
 }
Пример #8
0
        /// <summary>
        /// Creates a SubreportObject instance with specified name and parent.
        /// </summary>
        /// <param name="name">The name of the SubreportObject instance.</param>
        /// <param name="parent">The parent of the SubreportObject instance.</param>
        /// <returns>The SubreportObject instance.</returns>
        public static SubreportObject CreateSubreportObject(string name, Base parent)
        {
            SubreportObject subreport = new SubreportObject();

            subreport.Name   = name;
            subreport.Parent = parent;
            return(subreport);
        }
        private void RenderOuterSubreports(BandBase parentBand)
        {
            float saveCurX    = CurX;
            float saveCurY    = CurY;
            float saveOriginX = originX;
            int   saveCurPage = CurPage;

            float maxY          = 0;
            int   maxPage       = CurPage;
            bool  hasSubreports = false;

            try
            {
                for (int i = 0; i < parentBand.Objects.Count; i++)
                {
                    if ((parentBand.Objects[i] is SubreportObject) && (parentBand.Objects[i] as SubreportObject).Visible &&
                        !(parentBand.Objects[i] as SubreportObject).PrintOnParent)
                    {
                        SubreportObject subreport = parentBand.Objects[i] as SubreportObject;
                        hasSubreports = true;
                        // restore start position
                        CurPage = saveCurPage;
                        CurY    = saveCurY - subreport.Height;
                        originX = saveOriginX + subreport.Left;
                        // do not upload generated pages to the file cache
                        PreparedPages.CanUploadToCache = false;

                        RenderSubreport(subreport);

                        // find maxY. We will continue from maxY when all subreports finished.
                        if (CurPage == maxPage)
                        {
                            if (CurY > maxY)
                            {
                                maxY = CurY;
                            }
                        }
                        else if (CurPage > maxPage)
                        {
                            maxPage = CurPage;
                            maxY    = CurY;
                        }
                    }
                }
            }
            finally
            {
                if (hasSubreports)
                {
                    CurPage = maxPage;
                    CurY    = maxY;
                }
                originX = saveOriginX;
                PreparedPages.CanUploadToCache = true;
            }
        }
Пример #10
0
    public void ApplyInfo(ref ReportDocument _oRpt)
    {
        Database       oCRDb     = _oRpt.Database;
        Tables         oCRTables = oCRDb.Tables;
        TableLogOnInfo oCRTableLogonInfo;
        ConnectionInfo oCRConnectionInfo = new ConnectionInfo();

        oCRConnectionInfo.ServerName = serverName;
        oCRConnectionInfo.UserID     = userID;
        oCRConnectionInfo.Password   = passWord;

        foreach (CrystalDecisions.CrystalReports.Engine.Table oCRTable in oCRTables)
        {
            oCRTableLogonInfo = oCRTable.LogOnInfo;
            oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
            oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);
            oCRTable.Location = oCRTable.Location.Substring(oCRTable.Location.LastIndexOf('.') + 1);
        }

        //set the sections collection with report sections
        Sections crSections = _oRpt.ReportDefinition.Sections;

        //loop through each section and find all report objects
        //loop through all the report objects to find all subreport objects
        //and set the logoninfo to the subreport
        foreach (Section crSection in crSections)
        {
            ReportObjects crReportObjects = crSection.ReportObjects;
            foreach (ReportObject crReportObject in crReportObjects)
            {
                if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    //if its a subreport, typecast the reportobject to a subreport object
                    SubreportObject crSubreportObject = (SubreportObject)crReportObject;

                    //open the subreport
                    ReportDocument subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

                    oCRDb     = subRepDoc.Database;
                    oCRTables = oCRDb.Tables;

                    //loop through each table and set the connection info
                    //pass the connection info to the logoninfo object then apply the logoninfo to the subreport
                    foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in oCRTables)
                    {
                        TableLogOnInfo crLogOnInfo = crTable.LogOnInfo;
                        crLogOnInfo.ConnectionInfo = oCRConnectionInfo;
                        crTable.ApplyLogOnInfo(crLogOnInfo);
                        crTable.Location = crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);
                    }
                }
            }
        }
    }
        /// <summary>
        /// Creates a SubreportObject instance with specified name and parent.
        /// </summary>
        /// <param name="name">The name of the SubreportObject instance.</param>
        /// <param name="parent">The parent of the SubreportObject instance.</param>
        /// <returns>The SubreportObject instance.</returns>
        public static SubreportObject CreateSubreportObject(string name, Base parent)
        {
            SubreportObject subreport = new SubreportObject();

            subreport.Name = name;
            if ((parent as IParent).CanContain(subreport))
            {
                subreport.Parent = parent;
            }
            return(subreport);
        }
Пример #12
0
        private void MauBaocao()
        {
            try
            {
                oRpt = new ReportDocument();
                try
                {
                    oRpt.Load(s_dirreport, OpenReportMethod.OpenReportByTempCopy);
                }
                catch (Exception ex)
                {
                    s_bien1 = ex.Message;
                    s_mess(s_bien1);
                    return;
                }
                foreach (CrystalDecisions.CrystalReports.Engine.Section section in oRpt.ReportDefinition.Sections)
                {
                    foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
                    {
                        if (reportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                            SubreportObject subReport   = (SubreportObject)reportObject;
                            ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);
                            subDocument.SetDataSource(dt);
                        }
                    }
                }
                oRpt.SetDataSource(dt);
                s_bien = "soyte";
                oRpt.DataDefinition.FormulaFields["soyte"].Text = "'" + d.Syte + "'";
                s_bien = "benhvien";
                oRpt.DataDefinition.FormulaFields["benhvien"].Text = "'" + d.Tenbv + "'";
                s_bien = "c1";
                oRpt.DataDefinition.FormulaFields["c1"].Text = "'" + c1 + "'";
                s_bien = "c2";
                oRpt.DataDefinition.FormulaFields["c2"].Text = "'" + c2 + "'";
                s_bien = "c3";
                oRpt.DataDefinition.FormulaFields["c3"].Text = "'" + c3 + "'";
                s_bien = "c4";
                oRpt.DataDefinition.FormulaFields["c4"].Text = "'" + c4 + "'";
                s_bien = "c5";
                oRpt.DataDefinition.FormulaFields["c5"].Text = "'" + c5 + "'";
                s_bien = "c6";
                oRpt.DataDefinition.FormulaFields["c6"].Text = "'" + c6 + "'";

                Report.ReportSource = oRpt;
            }
            catch (Exception e)
            {
                s_bien1 = e.Message;
                //s_mess(e.Message);
                MessageBox.Show("Thiếu fomular '" + s_bien + "'");
            }
        }
Пример #13
0
        private void RenderInnerSubreports(BandBase parentBand)
        {
            int originalObjectsCount = parentBand.Objects.Count;

            for (int i = 0; i < originalObjectsCount; i++)
            {
                SubreportObject subreport = parentBand.Objects[i] as SubreportObject;
                if (subreport != null && subreport.Visible && subreport.PrintOnParent)
                {
                    RenderInnerSubreport(parentBand, subreport);
                }
            }
        }
Пример #14
0
    private ReportDocument OpenSubreport(ReportDocument Reporte, string reportObjectName)
    {
        ReportDocument  reportDocument  = new ReportDocument();
        SubreportObject subreportObject = Reporte.ReportDefinition.ReportObjects[reportObjectName] as SubreportObject;

        if (subreportObject == null)
        {
            return((ReportDocument)null);
        }
        string subreportName = subreportObject.SubreportName;

        return(Reporte.OpenSubreport(subreportName));
    }
    private void Logon()
    {
        ConnectionInfo connection = new ConnectionInfo();

        connection.DatabaseName = "posco_test";
        //connection.ServerName = "posco_test";
        connection.UserID   = "hr";
        connection.Password = "******";

        // First we assign the connection to all tables in the main report
        //
        foreach (CrystalDecisions.CrystalReports.Engine.Table
                 table in rpt1.Database.Tables)
        {
            // Cache the logon info block
            TableLogOnInfo logOnInfo = table.LogOnInfo;

            // Set the connection
            logOnInfo.ConnectionInfo = connection;

            // Apply the connection to the table!
            table.ApplyLogOnInfo(logOnInfo);
        }

        foreach (CrystalDecisions.CrystalReports.Engine.Section section in rpt1.ReportDefinition.Sections)
        {
            // In each section we need to loop through all the reporting objects
            foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
            {
                if (reportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject subReport   = (SubreportObject)reportObject;
                    ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);

                    foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
                    {
                        // Cache the logon info block
                        TableLogOnInfo logOnInfo = table.LogOnInfo;

                        // Set the connection
                        logOnInfo.ConnectionInfo = connection;

                        // Apply the connection to the table!
                        table.ApplyLogOnInfo(logOnInfo);
                        subDocument.SetDataSource(ds);
                    }
                }
            }
        }
    }
Пример #16
0
 private static void SetDBLogonForSubreports(ConnectionInfo connectionInfo, ReportDocument reportDocument)
 {
     foreach (CrystalDecisions.CrystalReports.Engine.Section section in reportDocument.ReportDefinition.Sections)
     {
         foreach (ReportObject reportObject in section.ReportObjects)
         {
             if (reportObject.Kind == ReportObjectKind.SubreportObject)
             {
                 SubreportObject subreportObject   = (SubreportObject)reportObject;
                 ReportDocument  subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
                 SetDBLogonForReport(connectionInfo, subReportDocument);
             }
         }
     }
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="reportDocument"></param>
 /// <param name="connectionInfo"></param>
 private void ApplyLogOnInfoForSubreports(ReportDocument reportDocument, ConnectionInfo connectionInfo)
 {
     foreach (Section sectionTemp in reportDocument.ReportDefinition.Sections)
     {
         foreach (ReportObject reportObjectTemp in sectionTemp.ReportObjects)
         {
             if (reportObjectTemp.Kind == ReportObjectKind.SubreportObject)
             {
                 SubreportObject subreportObject   = (SubreportObject)reportObjectTemp;
                 ReportDocument  subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
                 this.ApplyLogOnInfo(subReportDocument, connectionInfo);
             }
         }
     }
 }
Пример #18
0
        public ReportDocument Reporte(ReportDocument reporte, ref string msj)
        {
            ReportDocument result           = new ReportDocument();
            ConnectionInfo crConnectioninfo = new ConnectionInfo();
            Conexion       cnn = new Conexion();

            msj = string.Empty;

            try
            {
                crConnectioninfo.ServerName = cnn._sb.DataSource;
                crConnectioninfo.UserID     = cnn._sb.UserID;
                crConnectioninfo.Password   = cnn._sb.Password;
                result = reporte;

                foreach (Table crTable in result.Database.Tables)
                {
                    crConnectioninfo.DatabaseName       = crTable.LogOnInfo.ConnectionInfo.DatabaseName;
                    crConnectioninfo.IntegratedSecurity = crTable.LogOnInfo.ConnectionInfo.IntegratedSecurity;

                    crTable.LogOnInfo.ConnectionInfo = crConnectioninfo;
                }

                foreach (Section crSection in result.ReportDefinition.Sections)
                {
                    foreach (ReportObject crReportObject in crSection.ReportObjects)
                    {
                        if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                            SubreportObject crSubreportObject   = (crReportObject as SubreportObject);
                            ReportDocument  crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

                            foreach (Table crTable in crSubreportDocument.Database.Tables)
                            {
                                crTable.LogOnInfo.ConnectionInfo = crConnectioninfo;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msj = ex.Message;
            }
            return(result);
        }
Пример #19
0
        private void pmOpenSubReport(Report.LocalDataSet.DTSSALESUM01 inData, ReportDocument inMasterReport)
        {
            Sections sections = inMasterReport.ReportDefinition.Sections;

            foreach (Section section in sections)
            {
                ReportObjects reportObjects = section.ReportObjects;
                foreach (ReportObject reportObject in reportObjects)
                {
                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subreportObject   = (SubreportObject)reportObject;
                        ReportDocument  subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
                        subReportDocument.SetDataSource(inData);
                    }
                }
            }
        }
Пример #20
0
    private void SetDBLogonForSubreports(ConnectionInfo myConnectionInfo, ReportDocument myReportDocument)
    {
        Sections mySections = myReportDocument.ReportDefinition.Sections;

        foreach (Section mySection in mySections)
        {
            ReportObjects myReportObjects = mySection.ReportObjects;
            foreach (ReportObject myReportObject in myReportObjects)
            {
                if (myReportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject mySubreportObject = (SubreportObject)myReportObject;
                    ReportDocument  subReportDocument = mySubreportObject.OpenSubreport(mySubreportObject.SubreportName);
                    SetDBLogonForReport(myConnectionInfo, subReportDocument);
                }
            }
        }
    }
Пример #21
0
        /// <summary>
        /// Assign the database connection to the table in all the report sections.
        /// </summary>
        private void AssignConnection()
        {
            ConnectionInfo connection = new ConnectionInfo();

            connection.DatabaseName = _datebaseName;
            connection.ServerName   = _serverName;
            if (_integratedSecurity)
            {
                connection.IntegratedSecurity = _integratedSecurity;
            }
            else
            {
                connection.UserID   = _userId;
                connection.Password = _password;
            }

            // First we assign the connection to all tables in the main report
            //
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in _reportDocument.Database.Tables)
            {
                AssignTableConnection(table, connection);
            }

            // Now loop through all the sections and its objects to do the same for the subreports
            //
            foreach (CrystalDecisions.CrystalReports.Engine.Section section in _reportDocument.ReportDefinition.Sections)
            {
                // In each section we need to loop through all the reporting objects
                foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
                {
                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subReport   = (SubreportObject)reportObject;
                        ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);

                        foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
                        {
                            AssignTableConnection(table, connection);
                        }
                    }
                }
            }
        }
Пример #22
0
        public void LogonSubReport(ReportDocument rptDoc, string cSubQuery)
        {
            Sections sections = rptDoc.ReportDefinition.Sections;

            foreach (Section section in sections)
            {
                ReportObjects reportObjects = section.ReportObjects;
                foreach (ReportObject reportObject in reportObjects)
                {
                    if (reportObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subreportObject = (SubreportObject)reportObject;
                        rptDoc = subreportObject.OpenSubreport(subreportObject.SubreportName);
                        SetDBForLogon(rptDoc, cSubQuery);
                        return;
                    }
                }
            }
        }
Пример #23
0
        }//end page load

        private void CloseReports(ReportDocument reportDocument)
        {
            Sections sections = reportDocument.ReportDefinition.Sections;

            foreach (Section section in sections)
            {
                ReportObjects reportObjects = section.ReportObjects;
                foreach (ReportObject reportObject in reportObjects)
                {
                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subreportObject   = (SubreportObject)reportObject;
                        ReportDocument  subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
                        subReportDocument.Close();
                    }
                }
            }
            reportDocument.Close();
        }
Пример #24
0
        private bool Logon()
        {
            // Declare and instantiate a new connection info object.
            ConnectionInfo ci = new ConnectionInfo();

            ci.Type = ConnectionInfoType.SQL;
            ci.AllowCustomConnection = true;
            ci.IntegratedSecurity    = false;
            ci.ServerName            = reportBase.DBServerName;
            ci.DatabaseName          = reportBase.DBName;
            ci.UserID   = reportBase.DBUserId;
            ci.Password = reportBase.DBPassword;
            //ci.Password = LSBuDbPasswordCrypto.verifyPassword(reportBase.DBPassword);
            //_crReportDocument.SetDatabaseLogon(reportBase.DBUserId,reportBase.DBPassword);
            // If the ApplyLogon function fails then return a false for this function.
            // Now applying logon information to the main report at this stage.
            // Though a Member variable we need to send the ReportDocument as param
            // bcz later on this ApplyLogon() will call itself for each subreport
            //if (!ApplyLogon(_crReportDocument, ci))
            //{
            //    return false;
            //}
            _crReportDocument.SetDatabaseLogon(reportBase.DBUserId, reportBase.DBPassword);

            // Loop through all the report objects and locate subreports.
            // If a subreport is found then apply logon information to the subreport.
            foreach (ReportObject obj in _crReportDocument.ReportDefinition.ReportObjects)
            {
                if (obj.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject subObj = (SubreportObject)obj;
                    // Check Apply LogOn for all subreports, if any one fail then entire report will fail
                    //if (!ApplyLogon(_crReportDocument.OpenSubreport(subObj.SubreportName), ci))
                    //{
                    //    return false;
                    //}
                }
            }

            // Return True if the code runs to this stage.
            return(true);
        }
Пример #25
0
        void AssignDataSet(ReportDocument oReport, DataSet dsData)
        {
            DataSet dsNew = dsData.Copy();

            // Remove primary key info. CR9 does not appreciate this information!!!
            foreach (DataTable dataTable in dsNew.Tables)
            {
                foreach (DataColumn dataCol in dataTable.PrimaryKey)
                {
                    dataCol.AutoIncrement = false;
                }

                dataTable.PrimaryKey = null;
            }

            // Now assign the dataset to all tables in the main report
            foreach (Table oTable in myReport.Database.Tables)              //oReport.Database.Tables)
            {
                oTable.SetDataSource(dsNew);
            }

            // Now loop through all the sections and its objects to do the same for the subreports
            foreach (Section crSection in myReport.ReportDefinition.Sections)                // oReport.ReportDefinition.Sections)
            {
                // In each section we need to loop through all the reporting objects
                foreach (ReportObject crObject in crSection.ReportObjects)
                {
                    if (crObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject crSubReport = (SubreportObject)crObject;
                        ReportDocument  crSubDoc    = crSubReport.OpenSubreport(crSubReport.SubreportName);

                        foreach (Table oTable in crSubDoc.Database.Tables)
                        {
                            oTable.SetDataSource(dsNew);
                        }
                    }
                }
            }

            //crystalReportViewer.ReportSource = oReport;
        }
        private void RenderInnerSubreports(BandBase parentBand)
        {
            int originalObjectsCount = parentBand.Objects.Count;

            for (int i = 0; i < originalObjectsCount; i++)
            {
                SubreportObject subreport = parentBand.Objects[i] as SubreportObject;

                // Apply visible expression if needed.
                if (subreport != null && !String.IsNullOrEmpty(subreport.VisibleExpression))
                {
                    subreport.Visible = CalcVisibleExpression(subreport.VisibleExpression);
                }

                if (subreport != null && subreport.Visible && subreport.PrintOnParent)
                {
                    RenderInnerSubreport(parentBand, subreport);
                }
            }
        }
Пример #27
0
        private void RenderInnerSubreport(BandBase parentBand, SubreportObject subreport)
        {
            BandBase saveOutputBand = outputBand;
            float    saveCurX       = CurX;
            float    saveCurY       = CurY;

            try
            {
                outputBand = parentBand;
                CurX       = subreport.Left;
                CurY       = subreport.Top;

                RenderSubreport(subreport);
            }
            finally
            {
                outputBand = saveOutputBand;
                CurX       = saveCurX;
                CurY       = saveCurY;
            }
        }
Пример #28
0
        //GET: Home
        public ActionResult ReportViewer()
        {
            var    rptDoc     = new ReportDocument();
            string sessionId  = this.Request.QueryString["sessionId"];
            var    tes        = System.Web.HttpContext.Current.Session[sessionId + "_reportId"];
            string instanDb   = System.Configuration.ConfigurationManager.AppSettings["InstanDB"].ToString();
            string serverDb   = System.Configuration.ConfigurationManager.AppSettings["ServerDb"].ToString();
            string userDB     = System.Configuration.ConfigurationManager.AppSettings["userDB"].ToString();
            string paswwordDb = System.Configuration.ConfigurationManager.AppSettings["paswwordDb"].ToString();

            //hdnSession.Value = sessionId;

            #region Test
            if (System.Web.HttpContext.Current.Session[sessionId + "_reportId"] != null)
            {
                string reportId = System.Web.HttpContext.Current.Session[sessionId + "_reportId"].ToString();
                var    param    = System.Web.HttpContext.Current.Session[sessionId + "_param"];

                //Func.sessionReport(reportId);

                //string sSql = HttpContext.Current.Session[sessionId + "_sql"].ToString();
                //string tabel = HttpContext.Current.Session[sessionId + "_tabel"].ToString();
                //string mode = HttpContext.Current.Session[sessionId + "_mode"].ToString();
                //string con = HttpContext.Current.Session[sessionId + "_con"].ToString();

                //if (con == null)
                //{
                //    con = "0";
                //}

                GetDataReportViewerByIdRequest request = new GetDataReportViewerByIdRequest();
                request.ReportViewerId = reportId;

                GetDataReportViewerByIdResponse response = _reportService.GetDataReportViewerById(request);

                var report = response.ReportViewer;

                string reportFile = "../Reports/" + report.ReportFile.ToString();
                string query      = report.SqlQuery.ToString();
                string useSp      = report.UseSp.ToString();
                bool   isSp       = false;
                if (!(useSp == "" || useSp == "0"))
                {
                    isSp = true;
                }

                int count     = 0;
                var listParam = new List <Dictionary <string, string> >();

                if (System.Web.HttpContext.Current.Session[sessionId + "_param"] != null)
                {
                    foreach (Dictionary <string, string> x in (List <Dictionary <string, string> >)param)
                    {
                        var tmp = new Dictionary <string, string>();

                        string fldName   = x["fldName"];
                        string fldOpr    = x["fldOpr"];
                        string fldValue1 = x["fldValue1"];
                        string fldValue2 = x["fldValue2"];
                        string isParam   = x["isParameter"];

                        string conditionExp = "";
                        if (isParam == "0")
                        {
                            switch (fldOpr)
                            {
                            case "eq":
                                conditionExp = fldName + " = " + "'" + fldValue1 + "'";
                                break;

                            case "ne":
                                conditionExp = fldName + " <> " + "'" + fldValue1 + "'";
                                break;

                            case "bw":
                                conditionExp = fldName + " LIKE " + "'" + fldValue1 + "%'";
                                break;

                            case "bn":
                                conditionExp = fldName + " NOT LIKE " + "'" + fldValue1 + "%'";
                                break;

                            case "ew":
                                conditionExp = fldName + " LIKE " + "'" + "%" + fldValue1 + "'";
                                break;

                            case "en":
                                conditionExp = fldName + " NOT LIKE " + "'" + "%" + fldValue1 + "'";
                                break;

                            case "cn":
                                conditionExp = " CONTAINS " + "(" + fldName + "," + fldValue1 + ")";
                                break;

                            case "nc":
                                conditionExp = " NOT CONTAINS " + "(" + fldName + "," + fldValue1 + ")";
                                break;

                            case "lt":
                                conditionExp = fldName + " < " + "'" + fldValue1 + "'";
                                break;

                            case "le":
                                conditionExp = fldName + " <= " + "'" + fldValue1 + "'";
                                break;

                            case "gt":
                                conditionExp = fldName + " > " + "'" + fldValue1 + "'";
                                break;

                            case "ge":
                                conditionExp = fldName + " >= " + "'" + fldValue1 + "'";
                                break;

                            case "bt":
                                conditionExp = fldName + " BETWEEN " + "'" + fldValue1 + "'" + " AND " + "'" + fldValue2 + "'";
                                break;
                            }
                            string whereExp = count == 0 ? " WHERE " : " AND ";
                            query += whereExp + conditionExp;
                            count++;
                        }
                        else
                        {
                            // Untuk menampung paramater
                            tmp.Add("fldName", fldName);
                            tmp.Add("fldOpr", fldOpr);
                            tmp.Add("fldValue1", fldValue1);
                            tmp.Add("fldValue2", fldValue2);
                            tmp.Add("isParamater", isParam);
                            listParam.Add(tmp);
                        }
                    }
                }

                DataSet ds = new DataSet();
                ds.ReadXmlSchema(Server.MapPath("~/DatasetReport") + "/DataSet1.xsd");
                ds.EnforceConstraints = false;

                DataTable dt = new DataTable();
                dt.TableName = reportId;

                if (isSp)
                {
                    var paramSp = new Dictionary <string, string>();
                    if (listParam.Count > 0)
                    {
                        foreach (var x in listParam)
                        {
                            string fldName = x["fldName"];
                            string value   = x["fldValue1"];
                            paramSp.Add(fldName, value);
                        }
                    }
                    //throw new Exception("ok");
                    dt = Library.ExecGetMultiDataBySPtoDatatable(query, paramSp);
                }
                else
                {
                    dt = Library.QueryToDataTable(query);
                }

                rptDoc.Load(Server.MapPath(reportFile));
                ds.Tables[rptDoc.Database.Tables[0].Name].Merge(dt);

                rptDoc.SetDatabaseLogon(userDB, paswwordDb, instanDb, serverDb);
                rptDoc.SetDataSource(ds);
                rptDoc.Refresh();
                rptDoc.VerifyDatabase();

                SubreportObject subreport = null;
                foreach (Section section in rptDoc.ReportDefinition.Sections)
                {
                    foreach (object item in section.ReportObjects)
                    {
                        subreport = item as SubreportObject;
                        if (subreport != null)
                        {
                            if (subreport.SubreportName != "")
                            {
                                dt = new DataTable();
                                String tblname =
                                    ds.Tables[rptDoc.Subreports[subreport.SubreportName].Database.Tables[0].Name].TableName;
                                dt.TableName = subreport.Name;
                                dt           = Library.QueryToDataTable("select * from " + tblname);
                                ds.Tables[tblname].Merge(dt);
                                rptDoc.Subreports[subreport.SubreportName].SetDataSource(ds);
                                rptDoc.Subreports[subreport.SubreportName].VerifyDatabase();
                            }
                        }
                    }

                    //Jika Terdapat Field Paramter (Otomatis digunakan untuk menyimpan info parameter filter)
                    CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions crParameterdef;
                    crParameterdef = rptDoc.DataDefinition.ParameterFields;
                    int i = 0;
                    foreach (CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition def in crParameterdef)
                    {
                        var test = def.ReportName;
                        if (def.ReportName == "Company.rpt")
                        {
                            if (def.Name == "baseURL")
                            {
                                rptDoc.SetParameterValue(def.Name, Conf.Folder);
                            }
                        }
                        else if (def.ReportName == "")
                        {
                            //var d = listParam[i]["fldValue1"];
                            if (def.Name == "basePath")
                            {
                                rptDoc.SetParameterValue(def.Name, Conf.EmployeeFolder);
                            }
                            else if (def.Name == "baseURL")
                            {
                                rptDoc.SetParameterValue(def.Name, Conf.Folder);
                            }
                            else
                            {
                                foreach (var x in listParam)
                                {
                                    string fldName = x["fldName"];
                                    string value   = x["fldValue1"];
                                    if (String.Equals(def.Name, fldName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        rptDoc.SetParameterValue(def.Name, value);
                                    }
                                }
                            }

                            //rptDoc.SetParameterValue(def.Name, listParam[i]["fldValue1"]);
                        }
                        i++;
                    }

                    CrystalReportViewer crReport = new CrystalReportViewer();
                    crReport.ReportSource                  = rptDoc;
                    crReport.HasToggleGroupTreeButton      = false;
                    crReport.ToolPanelView                 = CrystalDecisions.Web.ToolPanelViewType.None;
                    crReport.HasToggleParameterPanelButton = false;
                    crReport.HasPrintButton                = true;
                    crReport.DocumentView                  = DocumentViewType.WebLayout;

                    //Func.AuditFunction();
                }
            }
            #endregion

            return(View());
        }
        private void AdjustLayout(ReportDocument icryRptDoc)
        {
            if (icryRptDoc == null)
            {
                return;
            }

            bool bAdjust1 = false, bAdjust2 = false, bAdjust3 = false;
            Font theFont;
            int  refWidth = 0;

            for (int i = 0; i < icryRptDoc.ReportDefinition.Sections.Count; i++)
            {
                ReportObjects robjs = icryRptDoc.ReportDefinition.ReportObjects;
                if (robjs == null || robjs.Count == 0)
                {
                    continue;
                }

                for (int j = 0; j < robjs.Count; j++)
                {
                    ReportObject robj = robjs[j];
                    if (robj == null)
                    {
                        continue;
                    }

                    ReportObjectKind robkKind = robj.Kind;
                    if (robkKind == ReportObjectKind.FieldObject && !string.IsNullOrEmpty(robj.Name))
                    {
                        FieldObject fieldObj = (FieldObject)robj;
                        if (fieldObj == null)
                        {
                            continue;
                        }

                        int nIndex = lstRunDetailsDisplayElements.FindIndex(x =>
                        {
                            if ((!string.IsNullOrEmpty(x.DisplayFieldName) && x.DisplayFieldName == fieldObj.Name))
                            {
                                return(true);
                            }
                            return(false);
                        });

                        if (0 <= nIndex)
                        {
                            DisplayElement2 d2 = lstRunDetailsDisplayElements[nIndex];
                            if (d2 != null && !string.IsNullOrEmpty(d2.Name))
                            {
                                float fontSize = d2.EstimateFontSize(d2.Name, new Size(fieldObj.Width / conversionFactor, fieldObj.Height / conversionFactor), fieldObj.Font);
                                if (fontSize > 0.0f && fontSize < fieldObj.Font.Size)
                                {
                                    theFont = new Font(fieldObj.Font.Name, fontSize, fieldObj.Font.Style, fieldObj.Font.Unit);
                                    fieldObj.ApplyFont(theFont);
                                    theFont.Dispose();
                                }
                            }
                            d2.FontSizeAdjusted = true;

                            bool bAllAdjusted = true;
                            foreach (DisplayElement2 de in lstRunDetailsDisplayElements)
                            {
                                if (de == null)
                                {
                                    continue;
                                }

                                bAllAdjusted &= de.FontSizeAdjusted;
                            }

                            bAdjust1 = bAllAdjusted;
                        }
                    }

                    if (robkKind == ReportObjectKind.TextObject && !string.IsNullOrEmpty(robj.Name))
                    {
                        TextObject textObj = (TextObject)robj;
                        if (textObj == null)
                        {
                            continue;
                        }

                        if ((!string.IsNullOrEmpty(textObj.Name) && textObj.Name == "TB_PageFooterCopyright"))
                        {
                            theFont = new Font(textObj.Font.Name, 6.0f, textObj.Font.Style, textObj.Font.Unit);
                            textObj.ApplyFont(theFont);
                            bAdjust2 = true;
                            theFont.Dispose();
                        }
                    }

                    if (robkKind == ReportObjectKind.SubreportObject && !string.IsNullOrEmpty(robj.Name) && robj.Name == "Subreport_RunSummary")
                    {
                        SubreportObject subReportObj = (SubreportObject)robj;
                        ReportDocument  subReportDoc = subReportObj.OpenSubreport(subReportObj.SubreportName);

                        if (subReportDoc == null)
                        {
                            break;
                        }

                        ReportObjects subrobjs = subReportDoc.ReportDefinition.ReportObjects;
                        if (subrobjs == null || subrobjs.Count == 0)
                        {
                            continue;
                        }

                        // Estimate heights
                        for (int m = 0; m < subrobjs.Count; m++)
                        {
                            ReportObject subrobj = subrobjs[m];
                            if (subrobj == null)
                            {
                                continue;
                            }

                            Font font;
                            switch (subrobj.Name)
                            {
                            case "FO_RS_SampleNumber":
                            case "FO_RS_SampleID":
                            case "FO_RS_Protocol":
                            case "FO_RS_SampleVol_mL":
                            case "FO_RS_MagneticParticles":
                            case "FO_RS_Selection_Cocktail":
                            case "FO_RS_Antibody_Cocktail":
                            case "FO_RS_TipRack":
                            case "FO_RS_BufferLotID":
                            case "FO_RS_SampleTube":
                            case "FO_RS_SeparationTube":
                            case "FO_RS_NegativeFractionTube":
                            case "FO_RS_WasteTube":
                                FieldObject fb = (FieldObject)subrobj;
                                font = fb.Font;
                                EstimateHeight(subrobj, font, subrobj.Name);
                                break;
                            }
                        }

                        // Set heights of cells
                        for (int n = 0; n < subrobjs.Count; n++)
                        {
                            ReportObject subrobj = subrobjs[n];
                            if (subrobj == null)
                            {
                                continue;
                            }

                            switch (subrobj.Name)
                            {
                            case "TB_RS_SampleNumber":
                            case "TB_RS_SampleID":
                            case "TB_RS_Protocol":
                            case "TB_RS_SampleVol_mL":
                            case "TB_RS_MagneticParticles":
                            case "TB_RS_Selection_Cocktail":
                            case "TB_RS_Antibody_Cocktail":
                            case "TB_RS_TipRack":
                            case "TB_RS_BufferLotID":
                            case "TB_RS_SampleTube":
                            case "TB_RS_SeparationTube":
                            case "TB_RS_NegativeFractionTube":
                            case "TB_RS_WasteTube":

                                SetHeight(subrobj, subrobj.Name);
                                break;
                            }
                        } // end for
                        for (int n = 0; n < subrobjs.Count; n++)
                        {
                            ReportObject subrobj = subrobjs[n];
                            if (subrobj == null)
                            {
                                continue;
                            }

                            switch (subrobj.Name)
                            {
                            case "TB_RS_SampleVol_mL":
                                refWidth = subrobj.Width;
                                break;

                            case "TB_RS_MagneticParticles":
                            case "TB_RS_Selection_Cocktail":
                            case "TB_RS_Antibody_Cocktail":
                                subrobj.Width = refWidth;
                                break;
                            }
                        } // end for

                        bAdjust3 = true;
                    } // end if sub report

                    if (bAdjust1 && bAdjust2 && bAdjust3)
                    {
                        break;
                    }
                }// end for section object
            }
        }
Пример #30
0
        public bool PrintReport()
        {
            try
            {
                TitleName = "";

                int i, cnt = 0;
                if (report.FileName == "")
                {
                    for (i = report.ToString().Length - 1; i >= 0; i--)
                    {
                        if (Convert.ToChar(report.ToString()[i]) == 46)
                        {
                            break;
                        }
                        cnt++;
                    }
                    ReportName = report.ToString().Substring(report.ToString().Length - cnt, cnt);
                }
                else
                {
                    for (i = report.FileName.Length - 1; i >= 0; i--)
                    {
                        if (Convert.ToChar(report.FileName[i]) == '\\')
                        {
                            break;
                        }
                        cnt++;
                    }
                    ReportName = report.FileName.Substring(report.FileName.Length - cnt, cnt).Replace(".rpt", "");
                }
                LIF.ServerName = CommonFunctions.ServerName;

                LIF.IntegratedSecurity = true;
                LIF.DatabaseName       = CommonFunctions.DatabaseName;
                LIF.UserID             = "Logicall";
                LIF.Password           = "******";
                LIF.IntegratedSecurity = false;

                foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
                {
                    logoninfo = table.LogOnInfo;
                    logoninfo.ConnectionInfo = LIF;
                    table.ApplyLogOnInfo(logoninfo);
                }


                foreach (Section sec in report.ReportDefinition.Sections)
                {
                    ReportObjects myReportObjects = sec.ReportObjects;
                    foreach (ReportObject myReportObject in myReportObjects)
                    {
                        if (myReportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                            SubreportObject mySubreportObject = (SubreportObject)myReportObject;
                            ReportDocument  subReportDocument = mySubreportObject.OpenSubreport(mySubreportObject.SubreportName);
                            foreach (Table tab in subReportDocument.Database.Tables)
                            {
                                // Get the TableLogOnInfo object.
                                logoninfo = tab.LogOnInfo;
                                logoninfo.ConnectionInfo = LIF;
                                tab.ApplyLogOnInfo(logoninfo);
                            }
                        }
                    }
                }

                ReportObject reportObject = report.ReportDefinition.ReportObjects["txtRegName"];
                if (reportObject != null)
                {
                    TextObject textObject = (TextObject)reportObject;
                    textObject.Text = DBGetVal.RegCompName;
                }


                //To set parameters for report
                GetParaMeters();
                if (OwnPrinterName == "")
                {
                    System.Drawing.Printing.PrinterSettings objPrint = new System.Drawing.Printing.PrinterSettings();
                    SetPrinterSize();
                    //report.PrintOptions.PrinterName = objPrint.PrinterName;
                }
                else
                {
                    report.PrintOptions.PrinterName = OwnPrinterName;
                }

                if (PrintCount <= 0)
                {
                    PrintCount = 1;
                }
                if (ReportType == false)//======for pdf export condition added 08-01-2019
                {
                    report.PrintToPrinter(PrintCount, true, 1, 1);
                    report.PrintToPrinter(PrintCount, true, 2, 2);
                    report.PrintToPrinter(PrintCount, true, 3, 3);
                    report.PrintToPrinter(PrintCount, true, 4, 0);
                    report.Close();
                }
                return(true);
            }
            catch (Exception e)
            {
                report.Close();
                CommonFunctions.ErrorMessge = e.Message;
                return(false);
            }
        }