Exemplo n.º 1
0
        /// <summary>
        /// Illustrates using a GrapeCity OleDb object as a data source
        ///
        /// </summary>
        private void btnOleDb_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            //OleDb Data Source object to use.
            //
            Data.OleDBDataSource oleDb = new Data.OleDBDataSource();

            //Assign the database connection string from the sample Northwind access database
            //
            oleDb.ConnectionString = Properties.Resources.ConnectionString;

            //Run the SQL command.
            //
            oleDb.SQL = "SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID";

            //Create the report and assign the data source
            //
            var rpt = new ActiveReports.SectionReport();

            rpt.LoadLayout(XmlReader.Create(System.IO.Path.Combine("..\\..\\", Properties.Resources.ReportName)));
            rpt.DataSource = oleDb;
            //Run and view the report
            //
            arvMain.LoadDocument(rpt);

            Cursor = Cursors.Arrow;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Illustrates using a DataView as a data source
        ///
        /// </summary>
        private void btnDataView_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            //Verify that a value Company Name is selected
            //
            if (cbCompanyName.SelectedItem == null)
            {
                MessageBox.Show(Properties.Resources.SelectCompanyName);
                Cursor = Cursors.Arrow;
                return;
            }

            //DataTable to hold the data.
            //
            DataTable invoiceData = new DataTable("Invoices");

            invoiceData.Locale = CultureInfo.InvariantCulture;

            //Database connection populated from the sample Northwind access database
            //
            OleDbConnection nwindConn = new OleDbConnection();

            nwindConn.ConnectionString = Properties.Resources.ConnectionString;

            //Run the SQL command.
            //
            OleDbCommand selectCMD = new OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", nwindConn);

            selectCMD.CommandTimeout = 30;

            //Data adapter used to run the select command
            //
            OleDbDataAdapter invoicesDA = new OleDbDataAdapter();

            invoicesDA.SelectCommand = selectCMD;

            //Fill the DataSet.
            //
            invoicesDA.Fill(invoiceData);
            nwindConn.Close();

            //Create a DataView and assign the selected CompanyName RowFilter.
            //
            DataView invoiceDataView = new DataView(invoiceData);

            invoiceDataView.RowFilter = "Customers.CompanyName='" + Convert.ToString(cbCompanyName.SelectedItem).Replace("'", "''") + "'";

            //Create the report and assign the data source
            //
            var rpt = new ActiveReports.SectionReport();

            rpt.LoadLayout(XmlReader.Create(System.IO.Path.Combine("..\\..\\", Properties.Resources.ReportName)));
            rpt.DataSource = invoiceDataView;
            //Run and view the report
            //
            arvMain.LoadDocument(rpt);

            Cursor = Cursors.Arrow;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Illustrates using a DataTable as a data source
        ///
        /// </summary>
        private void btnDataTable_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            //DataTable to hold the data.
            //
            DataTable invoiceData = new DataTable("Invoices");

            invoiceData.Locale = CultureInfo.InvariantCulture;

            //Database connection populated from the sample Northwind access database
            //
            OleDbConnection nwindConn = new OleDbConnection();

            nwindConn.ConnectionString = Properties.Resources.ConnectionString;

            //Run the SQL command.
            //
            OleDbCommand selectCMD = new OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", nwindConn);

            selectCMD.CommandTimeout = 30;

            //Data adapter used to run the select command
            //
            OleDbDataAdapter invoicesDA = new OleDbDataAdapter();

            invoicesDA.SelectCommand = selectCMD;

            //Fill the DataSet.
            //
            invoicesDA.Fill(invoiceData);
            nwindConn.Close();

            //Create the report and assign the data source.
            //
            var rpt = new ActiveReports.SectionReport();

            rpt.LoadLayout(XmlReader.Create(System.IO.Path.Combine("..\\..\\", Properties.Resources.ReportName)));
            rpt.DataSource = invoiceData;
            //Run and view the report.
            //
            arvMain.LoadDocument(rpt);

            Cursor = Cursors.Arrow;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Illustrates using a GrapeCity SqlServer object as a data source.
        ///
        /// </summary>
        private void btnSqlServer_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            //Verify that a SQL Server has been selected
            //
            if (cbSqlServerList.SelectedItem == null)
            {
                MessageBox.Show(Properties.Resources.SelectSQLServer);
                Cursor = Cursors.Arrow;
                return;
            }

            //SqlServer Data Source object to use
            //
            Data.SqlDBDataSource sql = new Data.SqlDBDataSource();

            //Assign the database connection string based on the SQL Server selected
            //
            sql.ConnectionString = "Data Source=" + cbSqlServerList.SelectedItem + ";Initial Catalog=Northwind;Integrated Security=SSPI";
            //Run the SQL command.
            //
            sql.SQL = "SELECT * FROM invoices ORDER BY CustomerID, OrderID";

            //Create the report and assign the data source.
            //
            var rpt = new ActiveReports.SectionReport();

            rpt.LoadLayout(XmlReader.Create(System.IO.Path.Combine("..\\..\\", Properties.Resources.ReportName)));
            rpt.DataSource = sql;
            //Run and view the report
            //
            try
            {
                arvMain.LoadDocument(rpt);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

            Cursor = Cursors.Arrow;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Illustrates using a DataReader as a data source.
        ///
        /// </summary>
        private void btnDataReader_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            //Database connection populated from the sample Northwind access database
            //
            OleDbConnection nwindConn = new OleDbConnection();

            nwindConn.ConnectionString = Properties.Resources.ConnectionString;

            //Run the SQL command.
            //
            OleDbCommand selectCMD = new OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", nwindConn);

            selectCMD.CommandTimeout = 30;

            //DataReader used to read the data
            //
            OleDbDataReader invoiceDataReader;

            //Open the database connection and execute the reader
            //
            nwindConn.Open();
            invoiceDataReader = selectCMD.ExecuteReader();

            //Create the report and assign the data source.
            //
            var rpt = new ActiveReports.SectionReport();

            rpt.LoadLayout(XmlReader.Create(System.IO.Path.Combine("..\\..\\", Properties.Resources.ReportName)));
            rpt.DataSource = invoiceDataReader;
            //Run and view the report
            //
            arvMain.Document = rpt.Document;
            rpt.Run(false);

            //Close the database connection
            //
            nwindConn.Close();

            Cursor = Cursors.Arrow;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Illustrates using a GrapeCity XML object as a data source.
        ///
        /// </summary>
        private void btnXML_Click(object sender, EventArgs e)
        {
            //Initialize the Open Dialog Box
            //

            dlgOpen.Title    = Properties.Resources.OpenDataFile;
            dlgOpen.FileName = dlgSave.FileName;
            dlgOpen.Filter   = Properties.Resources.Filter;

            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                //If valid name is returned, open the data and run the report
                //
                if (dlgOpen.FileName.Length != 0)
                {
                    Cursor = Cursors.WaitCursor;

                    //XML Data Source object to use
                    Data.XMLDataSource xml = new Data.XMLDataSource();

                    //Assign the FileName for the selected XML data file
                    xml.FileURL = dlgOpen.FileName;
                    //Assign the Recordset Pattern
                    xml.RecordsetPattern = @"//Northwind/Invoices";

                    //Create the report and assign the data source
                    var rpt = new ActiveReports.SectionReport();
                    rpt.LoadLayout(XmlReader.Create(System.IO.Path.Combine("..\\..\\", Properties.Resources.ReportName)));
                    rpt.DataSource = xml;
                    //Run and view the report
                    arvMain.LoadDocument(rpt);

                    Cursor = Cursors.Arrow;
                }
            }
        }