private void bXMLData_Click(object sender, System.EventArgs e) { if (this.rdlViewer.SourceRdl == null) { MessageBox.Show("Hit the Set Report button first!"); return; } string xmlData = @"<?xml version='1.0' encoding='UTF-8'?> <Rows> <Row><ContactName>Alejandra Camino</ContactName><Phone>(91) 745 6200</Phone></Row> <Row><ContactName>Alexander Feuer</ContactName><Phone>0342-023176</Phone></Row> <Row><ContactName>Ana Trujillo</ContactName><Phone>(5) 555-4729</Phone></Row> <Row><ContactName>Anabela Domingues</ContactName><Phone>(11) 555-2167</Phone></Row> <Row><ContactName>André Fonseca</ContactName><Phone>(11) 555-9482</Phone></Row> </Rows>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlData); // Tell the report to use the data Report rpt = this.rdlViewer.Report; // Get the report fyiReporting.RDL.DataSet ds = rpt.DataSets["Data"]; // get the data set ds.SetData(doc); rdlViewer.Rebuild(); // force report to get rebuilt }
private void bEnumerable_Click(object sender, System.EventArgs e) { if (this.rdlViewer.SourceRdl == null) { MessageBox.Show("Hit the Set Report button first!"); return; } try { ArrayList ar = new ArrayList(); ar.Add(new Contact("Contact Object", "(555) 712 1234")); ar.Add(new Contact("Alejandra Camino", "(91) 745 6200")); ar.Add(new Contact("Alexander Feuer", "0342-023176")); ar.Add(new Contact("Ana Trujillo", "(5) 555-4729")); ar.Add(new Contact("Anabela Domingues", "(11) 555-2167")); // Tell the report to use this IEnumerable Report rpt = this.rdlViewer.Report; // Get the report // reset call to set user data (if made) fyiReporting.RDL.DataSet dts = rpt.DataSets["Data"]; // get the data set dts.SetData(ar); // reset the data rdlViewer.Rebuild(); // force report to get rebuilt } catch (Exception ge) { MessageBox.Show(ge.Message, "Error"); } }
private void ManualDataTable_Click(object sender, System.EventArgs e) { if (this.rdlViewer.SourceRdl == null) { MessageBox.Show("Hit the Set Report button first!"); return; } // Create a DataTable and manually populate it. DataTable dt = new DataTable(); // The column names need to match the Field DataField element dt.Columns.Add(new DataColumn("ContactName", typeof(string))); dt.Columns.Add(new DataColumn("Phone", typeof(string))); // Create some data and add it to the data table string[] rowValues = new string[2]; rowValues[0] = "Lily"; rowValues[1] = "617-555-1234"; dt.Rows.Add(rowValues); rowValues[0] = "Daisy"; rowValues[1] = "617-555-8324"; dt.Rows.Add(rowValues); // Tell the report to use the data Report rpt = this.rdlViewer.Report; // Get the report fyiReporting.RDL.DataSet ds = rpt.DataSets["Data"]; // get the data set ds.SetData(dt); // set the data for the dataset rdlViewer.Rebuild(); // force report to get rebuilt }
private void bIDataReader_Click(object sender, System.EventArgs e) { if (this.rdlViewer.SourceRdl == null) { MessageBox.Show("Hit the Set Report button first!"); return; } Cursor saveCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; IDbConnection cnSQL = null; IDbCommand cmSQL = null; IDataReader dr = null; try { cnSQL = new SqlConnection(this.tbConnectionString.Text); cnSQL.Open(); cmSQL = new SqlCommand("SELECT ContactName, Phone FROM Customers ORDER BY 1", (SqlConnection)cnSQL); dr = cmSQL.ExecuteReader(CommandBehavior.SequentialAccess); // Tell the report to use the data Report rpt = this.rdlViewer.Report; // Get the report fyiReporting.RDL.DataSet ds = rpt.DataSets["Data"]; // get the data set ds.SetData(dr); rdlViewer.Rebuild(); // force report to get rebuilt } catch (SqlException sqle) { MessageBox.Show(sqle.Message, "SQL Error"); } catch (Exception ge) { MessageBox.Show(ge.Message, "Error"); } finally { if (cnSQL != null) { cnSQL.Close(); cnSQL.Dispose(); if (cmSQL != null) { cmSQL.Dispose(); if (dr != null) { dr.Close(); } } } Cursor.Current = saveCursor; } }
IDictionary _Items; // list of report items internal DataSets(Report rpt, DataSetsDefn dsn) { _rpt = rpt; if (dsn.Items.Count < 10) _Items = new ListDictionary(); // Hashtable is overkill for small lists else _Items = new Hashtable(dsn.Items.Count); // Loop thru all the child nodes foreach(DataSetDefn dsd in dsn.Items.Values) { DataSet ds = new DataSet(rpt, dsd); _Items.Add(dsd.Name.Nm, ds); } }
private void bDataSource_Click(object sender, System.EventArgs e) { if (this.rdlViewer.SourceRdl == null) { MessageBox.Show("Hit the Set Report button first!"); return; } Cursor saveCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; IDbConnection cnSQL = null; try { cnSQL = new SqlConnection(this.tbConnectionString.Text); cnSQL.Open(); // Tell the report to use this connection Report rpt = this.rdlViewer.Report; // Get the report fyiReporting.RDL.DataSource ds = rpt.DataSources["DS1"]; // get the data source ds.UserConnection = cnSQL; // reset call to set user data (if made) fyiReporting.RDL.DataSet dts = rpt.DataSets["Data"]; // get the data set dts.SetData((XmlDocument)null); // this will clear out user data (if any); otherwise userdata would override rdlViewer.Rebuild(); // force report to get rebuilt ds.UserConnection = null; // clear it out } catch (SqlException sqle) { MessageBox.Show(sqle.Message, "SQL Error"); } catch (Exception ge) { MessageBox.Show(ge.Message, "Error"); } finally { if (cnSQL != null) { cnSQL.Close(); cnSQL.Dispose(); } Cursor.Current = saveCursor; } }
private bool DoReportPreview() { if (tbReportSyntax.Text.Length < 1) { if (!DoReportSyntax()) { return(false); } } rdlViewer1.SourceRdl = tbReportSyntax.Text; fyiReporting.RDL.Report rpt = rdlViewer1.Report; fyiReporting.RDL.DataSet ds = rpt.DataSets["Data"]; ds.SetData(DataTableConvert.ToDataTable(this.DataEntity)); rdlViewer1.Rebuild(); return(true); }
IDictionary _Items; // list of report items internal DataSets(Report r, ReportLink p, XmlNode xNode) : base(r, p) { if (xNode.ChildNodes.Count < 10) _Items = new ListDictionary(); // Hashtable is overkill for small lists else _Items = new Hashtable(); // Loop thru all the child nodes foreach(XmlNode xNodeLoop in xNode.ChildNodes) { if (xNodeLoop.NodeType != XmlNodeType.Element) continue; if (xNodeLoop.Name == "DataSet") { DataSet ds = new DataSet(r, this, xNodeLoop); if (ds != null && ds.Name != null) _Items.Add(ds.Name.Nm, ds); } } }
private void tcEHP_SelectedIndexChanged(object sender, System.EventArgs e) { TabControl tc = (TabControl)sender; string tag = (string)tc.TabPages[tc.SelectedIndex].Tag; // Sync up the various pane whenever they switch so the editor is always accurate switch (_DesignChanged) { // Sync up the editor in every case case "design": // sync up the editor tbEditor.Text = dcDesign.ReportSource; tbEditor.Modified = true; break; case "edit": case "preview": break; default: // this can happen the first time if (tbEditor.Text.Length <= 0) { tbEditor.Text = dcDesign.ReportSource; } break; } // Below sync up the changed item if (tag == "preview") { if (rdlPreview.SourceRdl != tbEditor.Text) // sync up preview { this.rdlPreview.SourceRdl = this.tbEditor.Text; } if (tbEditor.Text.IndexOf("Component") > -1) { int len = ("<ConnectString>").Length; int iStart = tbEditor.Text.IndexOf("<ConnectString>"); int iEnd = tbEditor.Text.IndexOf("</ConnectString>"); try { string text = tbEditor.Text.Substring(iStart + len, iEnd - iStart - len); string[] sv = text.Split(','); string t = sv[0]; string f = sv[1]; Assembly assembly = Assembly.LoadFrom(f); if (assembly != null) { BaseDataEntity dataEntity = assembly.CreateInstance(t) as BaseDataEntity; DataTable dt = DataTableConvert.ToDataTable2(dataEntity); fyiReporting.RDL.Report rpt = this.rdlPreview.Report; fyiReporting.RDL.DataSet ds = rpt.DataSets["Data"]; ds.SetData(dt); this.rdlPreview.Rebuild(); } } catch { } } } else if (tag == "design") { if (_DesignChanged != "design" && _DesignChanged != null) { try { dcDesign.ReportSource = tbEditor.Text; } catch (Exception ge) { MessageBox.Show(ge.Message, "Report"); tc.SelectedIndex = 1; // Force current tab to edit syntax return; } } } _CurrentTab = tag; if (OnDesignTabChanged != null) { OnDesignTabChanged(this, e); } }