예제 #1
0
        public ViewReport(string titleReport, string rptFile, string querySql, string[] paramName, object[] paramValues, bool staticPrinter)
        {
            InitializeComponent();
            this.Text = titleReport;
            CRAXDDRT.Application crxApp = new CRAXDDRT.Application();
            CRAXDDRT.Report      report = new CRAXDDRT.Report();
            ADODB.Connection     conn   = new ADODB.Connection();
            ADODB.Recordset      rs     = new ADODB.Recordset();
            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            string connstr    = "Provider=SQLOLEDB;Data Source=" + SqlHelper.IPAddress + ";Initial Catalog=" + SqlHelper.DatabaseName + ";User Id=" + SqlHelper.UserID + ";Password="******";";
            string reportFile = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "/Report/" + rptFile;

            try
            {
                conn.Open(connstr, null, null, 0);
                report = crxApp.OpenReport(reportFile, OpenReportMethod.OpenReportByDefault);
                report.DiscardSavedData();
                if (paramName != null)
                {
                    for (int i = 0; i < paramName.Length; i++)
                    {
                        report.ParameterFields.GetItemByName(paramName[i], null).AddCurrentValue(paramValues[i]);
                    }
                }
                rs.Open(
                    querySql,
                    // SQL statement / table,view name /
                    // stored procedure call / file name
                    conn,                                               // Connection / connection string
                    ADODB.CursorTypeEnum.adOpenForwardOnly,             // Cursor type. (forward-only cursor)
                    ADODB.LockTypeEnum.adLockOptimistic,                // Lock type. (locking records only
                    // when you call the Update method.
                    (int)ADODB.CommandTypeEnum.adCmdText);

                /* For Execute StoreProcedure */
                //    rs.Open(querySql, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
                report.Database.SetDataSource(rs, 3, 1);
                if (staticPrinter)
                {
                    string printerName = Configurations.getPrinter();
                    report.SelectPrinter("", printerName, "");
                    //report.PrintOut(false, 1, true, 1, 200);
                }
                this.axCrystalActiveXReportViewer1.ReportSource = report;
                this.axCrystalActiveXReportViewer1.ViewReport();
            }
            catch (Exception ex)
            {
                //this.Dispose();
                //this.Close();
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        public ViewReport
        (
            string titleReport,
            string rptFile,
            string procedureName,
            string procedureParam,
            string[] rptParamName,
            object[] rptParamValues,
            bool staticPrinter

        )
        {
            InitializeComponent();
            this.Text = titleReport;
            CRAXDDRT.Application crxApp = new CRAXDDRT.Application();
            CRAXDDRT.Report      report = new CRAXDDRT.Report();
            ADODB.Connection     conn   = new ADODB.Connection();

            ADODB.Recordset rs = new ADODB.Recordset();
            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
            string connstr    = "Provider=SQLOLEDB;Data Source=" + SqlHelper.IPAddress + ";Initial Catalog=" + SqlHelper.DatabaseName + ";User Id=" + SqlHelper.UserID + ";Password="******";";
            string reportFile = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "/Report/" + rptFile;

            try
            {
                conn.Open(connstr, null, null, 0);
                report = crxApp.OpenReport(reportFile, OpenReportMethod.OpenReportByDefault);
                report.DiscardSavedData();
                if (rptParamName != null)
                {
                    for (int i = 0; i < rptParamName.Length; i++)
                    {
                        report.ParameterFields.GetItemByName(rptParamName[i], null).AddCurrentValue(rptParamValues[i]);
                    }
                }

                rs.Open(procedureName, conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
                report.Database.SetDataSource(rs, 3, 1);
                if (staticPrinter)
                {
                    string printerName = Configurations.getPrinter();
                    report.SelectPrinter("", printerName, "");
                    //report.PrintOut(false, 1, true, 1, 200);
                }
                this.axCrystalActiveXReportViewer1.ReportSource = report;
                this.axCrystalActiveXReportViewer1.ViewReport();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }