private void _c1r_PrintSection(object sender, C1.C1Report.ReportEventArgs e) { // get the field we want Field theField = _c1r.Fields["SalesChart"]; // make sure this is the section we want if (e.Section != theField.Section) { return; } // create chart image for this section using (DataView chartData = new DataView(_dataTable)) { // filter chart data for the current category chartData.RowFilter = "CategoryName = '" + _c1r.Evaluate("CategoryName") + "'"; // create chart Image img = BuildChart(chartData); // add chart image to field theField.Picture = img; theField.Text = string.Empty; } }
// apply custom filter if one wasn't provided private void _StartReport(object sender, System.EventArgs e) { // get subreport field Field srField = _c1r.Fields["SubreportField"]; // if the filter is set, nothing to do if (srField.Text.Length > 0) { return; } // build custom filter // (add 5 to current ID just to show that it works) int currentID = (int)_c1r.Evaluate("CategoryID"); string filter = string.Format("CategoryID = '{0}'", currentID + 5); // apply custom filter DataView dv = _dataTable.DefaultView; dv.RowFilter = filter; // and apply data source to the report C1Report rptSubreport = srField.Subreport; rptSubreport.DataSource.Recordset = dv; }
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { // load a new report if (e.Button == tbOpen) { OpenReportDefinitionFile(); return; } // save current report to a file if (e.Button == tbSave) { SaveReportDefinitionFile(false); return; } // preview report if (e.Button == tbPreview) { PreviewReport(); return; } // print report if (e.Button == tbPrint) { PrintReport(); return; } // show report info if (e.Button == tbInfo) { if (!LoadReport()) { return; } // build report info string string info = string.Format("Report [{0}]: {1} Groups, {2} Sections, {3} Fields\r\n", c1Report1.ReportName, c1Report1.Groups.Count, c1Report1.Sections.Count, c1Report1.Fields.Count); info += "** Groups\r\n"; for (int group = 0; group < c1Report1.Groups.Count; group++) { Group g = c1Report1.Groups[group] as Group; info += string.Format(" Group {0}: '{1}'\r\n", group, g.Name); } info += "** Sections\r\n"; for (int sec = 0; sec < c1Report1.Sections.Count; sec++) { Section s = c1Report1.Sections[sec] as Section; info += string.Format(" Section {0}: '{1}'\r\n", sec, s.Name); } // show report info MessageBox.Show(info, c1Report1.ReportName); return; } // try script engine if (e.Button == tbScript) { if (!LoadReport()) { return; } MessageBox.Show("This option writes to the Console. The results can be seen only if you are tracing through the code."); Console.WriteLine("*** Testing C1Report script engine"); string exp = "2 + 2"; Console.WriteLine(" {0} = {1}", exp, c1Report1.Evaluate(exp)); exp = "Report.ReportName"; Console.WriteLine(" {0} = {1}", exp, c1Report1.Evaluate(exp)); exp = "report.reportname"; Console.WriteLine(" {0} = {1}", exp, c1Report1.Evaluate(exp)); exp = "Page"; Console.WriteLine(" {0} = {1}", exp, c1Report1.Evaluate(exp)); exp = "Report.Layout.MarginLeft"; Console.WriteLine(" {0} = {1}", exp, c1Report1.Evaluate(exp)); exp = ((Field)c1Report1.Fields[0]).Name + ".BackColor"; Console.WriteLine(" {0} = {1}", exp, c1Report1.Evaluate(exp)); return; } // handle preview buttons int cnt = c1Report1.PageImages.Count; if (e.Button == tbFirst) { ppv.StartPageIdx = 0; } if (e.Button == tbLast) { ppv.StartPageIdx = cnt; } if (e.Button == tbPrev) { ppv.StartPageIdx--; } if (e.Button == tbNext) { ppv.StartPageIdx++; } if (e.Button == tbActual) { ppv.Cols = 1; ppv.ZoomFactor = 1; } if (e.Button == tbPage) { ppv.ZoomMode = C1.Win.C1Preview.ZoomModeEnum.WholePage; ppv.Cols = 1; } if (e.Button == tbTwo) { ppv.ZoomMode = C1.Win.C1Preview.ZoomModeEnum.WholePage; ppv.Cols = 2; } ShowStatus(string.Format("Page {0} of {1}", ppv.StartPageIdx + 1, cnt)); }