private void PrintDataGrid(DataGrid sender) { DataView dataView = (DataView)sender.DataSource; StiReport report = new StiReport(); report.ScriptLanguage = StiReportLanguageType.CSharp; //Add data to datastore report.RegData("view", dataView); //Fill dictionary report.Dictionary.Synchronize(); StiPage page = report.Pages.Items[0]; //Create HeaderBand StiHeaderBand headerBand = new StiHeaderBand(); headerBand.Height = 0.5f; headerBand.Name = "HeaderBand"; page.Components.Add(headerBand); //Create Dataaband StiDataBand dataBand = new StiDataBand(); dataBand.DataSourceName = "view" + dataView.Table.TableName; dataBand.Height = 0.5f; dataBand.Name = "DataBand"; page.Components.Add(dataBand); //Create texts Double pos = 0; Double columnWidth = StiAlignValue.AlignToMinGrid(page.Width / dataView.Table.Columns.Count, 0.1, true); int nameIndex = 1; foreach (DataColumn column in dataView.Table.Columns) { //Create text on header StiText headerText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); headerText.Text.Value = column.Caption; headerText.HorAlignment = StiTextHorAlignment.Center; headerText.Name = "HeaderText" + nameIndex.ToString(); headerText.Brush = new StiSolidBrush(Color.LightGreen); headerText.Border.Side = StiBorderSides.All; headerBand.Components.Add(headerText); //Create text on Data Band StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); dataText.Text.Value = "{view" + dataView.Table.TableName + "." + Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName) + "}"; dataText.Name = "DataText" + nameIndex.ToString(); dataText.Border.Side = StiBorderSides.All; //Add highlight StiCondition condition = new StiCondition(); condition.BackColor = Color.CornflowerBlue; condition.TextColor = Color.Black; condition.Expression = "(Line & 1) == 1"; condition.Item = StiFilterItem.Expression; dataText.Conditions.Add(condition); dataBand.Components.Add(dataText); pos += columnWidth; nameIndex++; } //Create FooterBand StiFooterBand footerBand = new StiFooterBand(); footerBand.Height = 0.5f; footerBand.Name = "FooterBand"; page.Components.Add(footerBand); //Create text on footer StiText footerText = new StiText(new RectangleD(0, 0, page.Width, 0.5f)); footerText.Text.Value = "Count - {Count()}"; footerText.HorAlignment = StiTextHorAlignment.Right; footerText.Name = "FooterText"; footerText.Brush = new StiSolidBrush(Color.LightGreen); footerBand.Components.Add(footerText); //Render without progress bar report.Render(false); report.Show(); }
private void print_Click(object sender, EventArgs e) { StiReport report = new StiReport(); report.ScriptLanguage = StiReportLanguageType.CSharp; //Add data to datastore report.RegData("MyList", model); //Fill dictionary report.Dictionary.Synchronize(); StiPage page = report.Pages.Items[0]; page.Orientation = StiPageOrientation.Landscape; //Create HeaderBand StiHeaderBand headerBand = new StiHeaderBand(); headerBand.Name = "HeaderBand"; page.Components.Add(headerBand); //Create Dataaband StiDataBand dataBand = new StiDataBand(); dataBand.DataSourceName = "MyList"; dataBand.Height = 0.5f; dataBand.Name = "DataBand"; page.Components.Add(dataBand); StiDataSource dataSource = report.Dictionary.DataSources[0]; //Create texts Double pos = 0; Double columnWidth = StiAlignValue.AlignToMinGrid((page.Width * 3 * 1.1) / 44, 0.1, true); Double AddressWidth = StiAlignValue.AlignToMinGrid((page.Width) / 4, 0.1, true); int nameIndex = 1; foreach (StiDataColumn column in dataSource.Columns) { if (column.Name == "mantagheName" || column.Name == "Senn" || column.Name == "_ID" || column.Name == "_Current" || column.Name == "checkbox" || column.Name == "codegrid" || column.Name == "datetime" || column.Name == "Address1" || column.Name == "Address2" || column.Name == "Address3") { continue; } //Create text on header StiText headerText = null; if (column.Name == "Address") { headerText = new StiText(new RectangleD(pos, 0, AddressWidth, 0.5f)); } else { headerText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); } headerText.WordWrap = false; string val = bringPersionName(column.Name); headerText.Text.Value = val;// headerText.HorAlignment = StiTextHorAlignment.Center; headerText.VertAlignment = StiVertAlignment.Center; headerText.Name = "HeaderText" + nameIndex.ToString(); headerText.Brush = new StiSolidBrush(Color.LightGreen); headerText.Border.Side = StiBorderSides.All; headerBand.Components.Add(headerText); //Create text on Data Band StiText dataText = null; if (column.Name == "Address") { dataText = new StiText(new RectangleD(pos, 0, AddressWidth, 0.5f)); } else { dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); } dataText.WordWrap = false; if (column.Name != "Address" || column.Name != "phones") { dataText.HorAlignment = StiTextHorAlignment.Center; } dataText.VertAlignment = StiVertAlignment.Center; dataText.Text.Value = "{MyList." + column.Name + "}"; dataText.Name = "DataText" + nameIndex.ToString(); dataText.Border.Side = StiBorderSides.All; dataText.RightToLeft = true; //Add highlight //dataText.HighlightCondition.Brush = new StiSolidBrush(Color.CornflowerBlue); //dataText.HighlightCondition.TextBrush = new StiSolidBrush(Color.Black); //dataText.HighlightCondition.Condition.Value = "(Line & 1) == 1"; //uncomment this line for VB.Net //dataText.HighlightCondition.Condition.Value = "(Line And 1) = 1"; dataBand.Components.Add(dataText); pos += columnWidth; nameIndex++; } //Create FooterBand StiFooterBand footerBand = new StiFooterBand(); footerBand.Height = 0.5f; footerBand.Name = "FooterBand"; page.Components.Add(footerBand); //Create text on footer StiText footerText = new StiText(new RectangleD(0, 0, page.Width, 0.5f)); footerText.Text.Value = "Count - {Count()}"; footerText.HorAlignment = StiTextHorAlignment.Right; footerText.Name = "FooterText"; footerText.Brush = new StiSolidBrush(Color.LightGreen); footerBand.Components.Add(footerText); //Render without progress bar report.Render(false); report.Show(); //For checking created report you can uncomment this line //report.Design(); }
private void PrintDataGrid(DataGrid sender) { StiReport report = new StiReport(); report.ScriptLanguage = StiReportLanguageType.CSharp; //Add data to datastore report.RegData("MyList", list); //Fill dictionary report.Dictionary.Synchronize(); StiPage page = report.Pages.Items[0]; //Create HeaderBand StiHeaderBand headerBand = new StiHeaderBand(); headerBand.Name = "HeaderBand"; page.Components.Add(headerBand); //Create Dataaband StiDataBand dataBand = new StiDataBand(); dataBand.DataSourceName = "MyList"; dataBand.Height = 0.5f; dataBand.Name = "DataBand"; page.Components.Add(dataBand); StiDataSource dataSource = report.Dictionary.DataSources[0]; //Create texts Double pos = 0; Double columnWidth = StiAlignValue.AlignToMinGrid(page.Width / dataSource.Columns.Count, 0.1, true); int nameIndex = 1; foreach (StiDataColumn column in dataSource.Columns) { if (column.Name == "_ID" || column.Name == "_Current") { continue; } //Create text on header StiText headerText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); headerText.Text.Value = column.Name; headerText.HorAlignment = StiTextHorAlignment.Center; headerText.Name = "HeaderText" + nameIndex.ToString(); headerText.Brush = new StiSolidBrush(Color.LightGreen); headerText.Border.Side = StiBorderSides.All; headerBand.Components.Add(headerText); //Create text on Data Band StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); dataText.Text.Value = "{MyList." + column.Name + "}"; dataText.Name = "DataText" + nameIndex.ToString(); dataText.Border.Side = StiBorderSides.All; dataBand.Components.Add(dataText); pos += columnWidth; nameIndex++; } //Create FooterBand StiFooterBand footerBand = new StiFooterBand(); footerBand.Height = 0.5f; footerBand.Name = "FooterBand"; page.Components.Add(footerBand); //Create text on footer StiText footerText = new StiText(new RectangleD(0, 0, page.Width, 0.5f)); footerText.Text.Value = "Count - {Count()}"; footerText.HorAlignment = StiTextHorAlignment.Right; footerText.Name = "FooterText"; footerText.Brush = new StiSolidBrush(Color.LightGreen); footerBand.Components.Add(footerText); //Render without progress bar report.Render(false); report.Show(); //For checking created report you can uncomment this line //report.Design(); }
static StiReport MakeReport(DBGrid grid, ReportCreateParam param) { JMXSchema schema = grid.Schema; DataTable dt = grid.BaseTable; double top = 0; float fontSize = param.FontSize; string tableName = TableAliasDefault;; StiReport report = new StiReport { ScriptLanguage = StiReportLanguageType.CSharp, ReportName = schema.Name }; //report.RegData(tableName, dt); report.RegData(tableName, grid.GetBindingSource()); report.Dictionary.Synchronize(); report.Dictionary.DataSources[0].Name = tableName; report.Dictionary.DataSources[0].Alias = tableName; StiPage page = report.Pages.Items[0]; page.Margins.Left = 1; page.Margins.Right = 1; page.AlignToGrid(); //ReportTitle bool titleOnPage = param.TitleOnPage; StiReportTitleBand titleBand = new StiReportTitleBand { Height = 0.5f, CanGrow = true, Name = "TitleBand" }; page.Components.Add(titleBand); //Period bool period = param.Period; if (period) { StiText periodText = new StiText(new RectangleD(0, 0, page.Width, 0.5f)); periodText.Text.Value = rth.Za(); periodText.HorAlignment = StiTextHorAlignment.Right; periodText.Name = "periodText"; periodText.Border.Side = StiBorderSides.None; //periodText.DockStyle = StiDockStyle.Right; periodText.Font = new Font(grid.Font.FontFamily.Name, fontSize, FontStyle.Bold); titleBand.Components.Add(periodText); top += periodText.Height; } //Title StiText titleText = new StiText(new RectangleD(0, period ? 0.5f : 0, page.Width, 1f)); titleText.Text.Value = grid.Schema.Name; titleText.HorAlignment = StiTextHorAlignment.Center; titleText.Name = "titleText"; titleText.Border.Side = StiBorderSides.None; titleText.Font = new Font(grid.Font.FontFamily.Name, 12f, FontStyle.Bold); titleText.WordWrap = true; titleText.CanGrow = true; titleBand.Components.Add(titleText); top += titleText.Height; //Create HeaderBand StiBand headBand; StiHeaderBand headerBand = new StiHeaderBand { Height = 0.5f, Name = "HeaderBand" }; if (titleOnPage) { page.Components.Add(headerBand); headBand = headerBand; } else { headBand = titleBand; } //Create Databand StiDataBand dataBand = new StiDataBand { DataSourceName = tableName, Height = 0.5f, Name = "DataBand" }; page.Components.Add(dataBand); //Create FooterBand StiFooterBand footerBand = new StiFooterBand { Height = 0.5f, CanGrow = true, Name = "FooterBand", CanBreak = false }; page.Components.Add(footerBand); Double pos = 0; int nameIndex = 1; int i = 0; bool multiLine = param.MultiLine; int border = param.Border; bool totals = false; List <StiText> footerList = new List <StiText>(); foreach (DataGridViewColumn column in grid.Columns) { bool visible = (column.Visible && column.Width > 1); if (visible) { Double columnWidth = StiAlignValue.AlignToMinGrid(column.Width / 33, 0.03, true); //Create text on header StiText headerText = new StiText(new RectangleD(pos, titleOnPage ? 0: top, columnWidth, 0.5f)); headerText.Text.Value = column.HeaderText; headerText.HorAlignment = StiTextHorAlignment.Center; headerText.Name = "HeaderText" + nameIndex.ToString(); if (border == 0) { headerText.Border.Side = StiBorderSides.Top | StiBorderSides.Bottom; } else { headerText.Border.Side = StiBorderSides.All; } headerText.CanGrow = true; headerText.GrowToHeight = true; headerText.WordWrap = multiLine; headerText.Font = new Font(grid.ColumnHeadersDefaultCellStyle.Font.FontFamily.Name, fontSize); headBand.Components.Add(headerText); MacroType tt = DBGridBase.GetMacroType(schema.Attributes[i].DataType); string format = column.DefaultCellStyle.Format; if (string.IsNullOrEmpty(format) && tt == MacroType.date) { format = vbo.DateFormat; } StiTextHorAlignment horAlign; switch (column.DefaultCellStyle.Alignment) { case DataGridViewContentAlignment.MiddleRight: horAlign = StiTextHorAlignment.Right; break; case DataGridViewContentAlignment.MiddleLeft: horAlign = StiTextHorAlignment.Left; break; default: horAlign = StiTextHorAlignment.Center; break; } //Create text on Data Band StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); string field = tableName + "." + Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.DataPropertyName); if (AccntFormat.ValidFormat(format)) { dataText.Text.Value = "{Substring(" + field + ",0,5)+" + "-".Qt() + "+Substring(" + field + ",5,3)+" + "-".Qt() + "+Substring(" + field + ",8,1)+" + "-".Qt() + "+Substring(" + field + ",9,4)+" + "-".Qt() + "+Substring(" + field + ",13,7)" + "}"; } else { dataText.Text.Value = "{" + field + "}"; } dataText.Name = "DataText" + nameIndex.ToString(); dataText.CanGrow = true; dataText.GrowToHeight = true; dataText.WordWrap = multiLine; dataText.HorAlignment = horAlign; //dataText.VertAlignment = StiVertAlignment.Center; if (border == 0) { dataText.Border.Side = StiBorderSides.None; } else if (border == 1) { dataText.Border.Side = StiBorderSides.Bottom; } else { dataText.Border.Side = StiBorderSides.All; } if (grid.RowsDefaultCellStyle.Font == null) { dataText.Font = new Font(grid.Font.FontFamily.Name, fontSize); } else { dataText.Font = new Font(grid.RowsDefaultCellStyle.Font.FontFamily.Name, fontSize); } dataText.TextFormat = ParseFormat(format); if (tt == MacroType.num) { dataText.ExcelValue.Value = "{" + field + "}"; } dataBand.Components.Add(dataText); //Create text on footer string summary = schema.Attributes[i].Agregate.ToLower(); if (summary == "sum") { summary = "Sum(" + field + ")"; } else if (summary == "rcnt") { summary = "Count()"; } else if (summary == "ave") { summary = "Avg(" + field + ")"; } else if (summary == "min") { summary = "Min(" + field + ")"; } else if (summary == "max") { summary = "Max(" + field + ")"; } else { summary = string.Empty; } bool summaryEmpty = string.IsNullOrEmpty(summary); int footerIndex = i; //if (!string.IsNullOrEmpty(grid.FooterText(footerIndex))) if (!summaryEmpty) { totals = true; } StiText footerText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); if (footerIndex == 0 && summaryEmpty) { footerText.Text.Value = grid.FooterCaption; } else if (footerIndex == 0) { footerText.Text.Value = "{" + (grid.FooterCaption + vbo.vbTab).Qt() + "+" + summary + "}"; } else if (!summaryEmpty) { footerText.Text.Value = "{" + summary + "}"; footerText.ExcelValue.Value = "{" + summary + "}"; } else { footerText.Text.Value = grid.FooterText(footerIndex); } footerText.Name = "FooterText" + nameIndex.ToString(); if (border == 0) { footerText.Border.Side = StiBorderSides.Top | StiBorderSides.Bottom; } else { footerText.Border.Side = StiBorderSides.All; } if (!summaryEmpty && summary != "Count()") { footerText.TextFormat = (StiFormatService)dataText.TextFormat.Clone(); } footerText.HorAlignment = horAlign; //footerText.VertAlignment = StiVertAlignment.Center; footerText.Font = new Font(grid.Font.FontFamily.Name, fontSize); footerList.Add(footerText); pos += columnWidth; nameIndex++; } i++; } if (totals) { footerBand.Components.AddRange(footerList.ToArray()); } if ((pos - page.Width) < 1.6f) { page.Margins.Right = 0; page.Margins.Left /= 2; } else if (pos > page.Width) { page.Orientation = StiPageOrientation.Landscape; titleText.Width = page.Width; if (period) { titleBand.Components[titleBand.Components.IndexOf("periodText")].Width = page.Width; } if (pos > page.Width) { page.Margins.Right = 0; page.Margins.Left /= 2; } if (pos > page.Width) { page.Width = pos; } } if (param.Sign) { footerList.Clear(); //StiText footerText = new StiText(new RectangleD(0, 0.5f, page.Width, 0.5f)); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(0, 1f, page.Width / 2, 0.5f)); //footerText.Text.Value = "{CSetup.Setup.Properties(" + vbo.Qt("President") + ", " + vbo.Qt("") + ")}"; //footerText.HorAlignment = StiTextHorAlignment.Right; //footerText.Font = new Font(grid.ColumnHeadersDefaultCellStyle.Font.FontFamily.Name, 10); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(page.Width / 2, 1f, page.Width / 4, 0.5f)); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(page.Width * 3 / 4, 1f, page.Width / 4, 0.5f)); //footerText.Text.Value = "{CSetup.Setup.Properties(" + vbo.Qt("PresidentName") + ", " + vbo.Qt("") + ")}"; //footerText.HorAlignment = StiTextHorAlignment.Left; //footerText.Font = new Font(grid.ColumnHeadersDefaultCellStyle.Font.FontFamily.Name, 10); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(0, 1.5f, page.Width, 0.5f)); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(0, 2f, page.Width / 2, 0.5f)); //footerText.Text.Value = "{CSetup.Setup.Properties(" + vbo.Qt("ChifAccount") + ", " + vbo.Qt("") + ")}"; //footerText.HorAlignment = StiTextHorAlignment.Right; //footerText.Font = new Font(grid.ColumnHeadersDefaultCellStyle.Font.FontFamily.Name, 10); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(page.Width / 2, 2f, page.Width / 4, 0.5f)); //footerList.Add(footerText); //footerText = new StiText(new RectangleD(page.Width * 3 / 4, 2f, page.Width / 4, 0.5f)); //footerText.Text.Value = "{CSetup.Setup.Properties(" + vbo.Qt("ChifAccountName") + ", " + vbo.Qt("") + ")}"; //footerText.HorAlignment = StiTextHorAlignment.Left; //footerText.Font = new Font(grid.ColumnHeadersDefaultCellStyle.Font.FontFamily.Name, 10); //footerList.Add(footerText); //footerBand.Height = 2.5f; //footerBand.Components.AddRange(footerList.ToArray()); } return(report); }