示例#1
0
        private void ReadTableDataSource(XmlNode node, StiReport report, string connectionName)
        {
            StiDataTableSource source = new StiDataTableSource();

            report.DataSources.Add(source);

            if (connectionName == null)
            {
                source.NameInSource = ReadString(node, "ReferenceName", source.Name);
            }
            else
            {
                source.NameInSource = connectionName;
            }

            source.Name = source.Alias = ReadString(node, "Name", source.Name);

            foreach (XmlNode elementNode in node.ChildNodes)
            {
                switch (elementNode.Name)
                {
                case "Column":
                    ReadColumn(elementNode, source);
                    break;
                }
            }
        }
示例#2
0
        private void ReadColumn(XmlNode node, StiDataTableSource source)
        {
            StiDataColumn column = new StiDataColumn();

            source.Columns.Add(column);

            column.Name = column.Alias = ReadString(node, "Name", column.Name);
            string type = ReadString(node, "DataType", string.Empty);

            column.Type = Type.GetType(type);
        }
示例#3
0
        public void Print()
        {
            DataTable dataTable = CreateDataTable();
            DataSet   dataSet   = new DataSet("DataSet");

            dataSet.Tables.Add(dataTable);

            StiReport report = new StiReport();
            string    path   = Path.GetDirectoryName(Application.ExecutablePath);

            path = Path.Combine(path, "Permit.mrt");
            report.Load(path);


            report.DataSources.Clear();
            StiDataTableSource sourceTable = new StiDataTableSource("PermitTable", "PermitTable", "PermitTable");

            report.Dictionary.DataSources.Add(sourceTable);
            report.RegData("PermitTable", "PermitTable", dataTable);
            sourceTable.SynchronizeColumns();

            report.Show();
        }
示例#4
0
 public StiTextValueFiller(object textContainer, StiDataTableSource dataTable, string[] fieldPrefix)
 {
     m_container   = textContainer;
     m_dataTable   = dataTable;
     m_fieldPrefix = fieldPrefix;
 }
示例#5
0
        private void CreateReport(DataTable table, DataGridView dgv, string title, string subtitle)
        {
            StiReport          report      = new StiReport();
            StiDataTableSource sourceTable = new StiDataTableSource("DS", "DS", "DS");

            report.Dictionary.DataSources.Add(sourceTable);
            report.RegData("DS", "DS", table);
            sourceTable.SynchronizeColumns();


            StiPage page = report.Pages.Items[0];

            page.Orientation = StiPageOrientation.Landscape;
            double pageW = page.Width;
            double pageH = page.Height;

            //============заголовок
            StiText headerReport = new StiText(new RectangleD(new PointD(0, 0), new SizeD(pageW, 0.6)),
                                               "Заголовок1");

            headerReport.Font         = new Font("Arial", 10, FontStyle.Bold);
            headerReport.HorAlignment = StiTextHorAlignment.Center;
            headerReport.Text         = "История обработок";

            StiText subtitleReport = new StiText(new RectangleD(new PointD(0, 0.6), new SizeD(pageW, 0.4)),
                                                 "Подзаголовок1");

            subtitleReport.Font         = new Font("Arial", 10, FontStyle.Regular);
            subtitleReport.HorAlignment = StiTextHorAlignment.Center;
            subtitleReport.Text         = subtitle;

            PointD BrandLoc = new PointD(0, 0.4);

            //хедер рапорта
            StiReportTitleBand headerPage = new StiReportTitleBand(new RectangleD(BrandLoc, new SizeD(pageW, 1.2)));

            page.Components.Add(headerPage);
            headerPage.Components.Add(headerReport);
            headerPage.Components.Add(subtitleReport);


            //хедер таблицы
            BrandLoc = new PointD(0, 1.2);
            StiHeaderBand headerTable = new StiHeaderBand(new RectangleD(BrandLoc, new SizeD(pageW, 0.6)));

            page.Components.Add(headerTable);

            //область данных
            PointD      BrandDataLoc = new PointD(0, 1.8);
            StiDataBand BrandData    = new StiDataBand(new RectangleD(BrandDataLoc, new SizeD(pageW, 0.4)));

            page.Components.Add(BrandData);
            BrandData.DataSourceName = "DS";

            StiPageFooterBand FooterBand = new StiPageFooterBand();

            page.Components.Add(FooterBand);
            FooterBand.Height = 0.6;

            StiText FooterNameTxt = new StiText(new RectangleD(0, 0, pageW, 0.6));

            FooterNameTxt.Text                       = title;
            FooterNameTxt.ShrinkFontToFit            = true;
            FooterNameTxt.HorAlignment               = StiTextHorAlignment.Right;
            FooterNameTxt.ShrinkFontToFitMinimumSize = 8;


            StiText FooterTxt = new StiText(new RectangleD(0, 0, 1, 0.6));

            FooterTxt.Text                       = "Лист {PageNumber}";
            FooterTxt.ShrinkFontToFit            = true;
            FooterTxt.ShrinkFontToFitMinimumSize = 8;
            FooterBand.Components.Add(FooterNameTxt);
            FooterBand.Components.Add(FooterTxt);

            StiText TimeText = new StiText(new RectangleD(-0.2, -0.4, 3, 0.6));

            TimeText.Text                       = "{Time}";
            TimeText.ShrinkFontToFit            = true;
            TimeText.ShrinkFontToFitMinimumSize = 8;
            page.Components.Add(TimeText);

            double numWidth = .5;

            double Wkoef = pageW / GetColumnWidth(table, dgv);
            double prevX = 0; //numWidth;

            //StiText headerNum = new StiText(new RectangleD(BrandLoc.X, 0, numWidth, 0.4));
            //headerNum.Border.Side = StiBorderSides.All;
            //headerNum.Border.Size = 1.5;
            //headerNum.Text = "N п/п";
            //headerNum.Font = new Font("Arial", 8, FontStyle.Bold);
            //headerNum.HorAlignment = StiTextHorAlignment.Center;
            //headerNum.ShrinkFontToFit = true;
            //headerNum.ShrinkFontToFitMinimumSize = 8;
            //headerTable.Components.Add(headerNum);

            //StiText dataNum = new StiText(new RectangleD(BrandLoc.X, 0, numWidth, 0.4));
            //dataNum.Border.Side = StiBorderSides.All;
            //dataNum.ShrinkFontToFit = true;
            //dataNum.ShrinkFontToFitMinimumSize = 8;
            //dataNum.Text = "{Line}";
            //dataNum.HorAlignment = StiTextHorAlignment.Right;
            //dataNum.Font = new Font("Arial", 8, FontStyle.Regular);
            //BrandData.Components.Add(dataNum);

            foreach (DataColumn column in table.Columns) //добалвляем в область заголовка и в область данных
            {
                string             colName   = column.ColumnName;
                DataGridViewColumn dgvColumn = dgv.Columns[colName];

                StiText headerTXT = new StiText(new RectangleD(BrandLoc.X + prevX, 0,
                                                               dgvColumn.Width * Wkoef, 0.4));
                headerTXT.Border.Side                = StiBorderSides.All;
                headerTXT.Border.Size                = 1.5;
                headerTXT.Text                       = dgvColumn.HeaderText;
                headerTXT.Font                       = new Font("Arial", 8, FontStyle.Bold);
                headerTXT.HorAlignment               = StiTextHorAlignment.Center;
                headerTXT.ShrinkFontToFit            = true;
                headerTXT.ShrinkFontToFitMinimumSize = 8;

                headerTable.Components.Add(headerTXT);
                StiText dataTXT = new StiText(new RectangleD(BrandLoc.X + prevX, 0,
                                                             dgvColumn.Width * Wkoef, 0.4));
                dataTXT.Border.Side                = StiBorderSides.All;
                dataTXT.ShrinkFontToFit            = true;
                dataTXT.ShrinkFontToFitMinimumSize = 8;
                dataTXT.Font = new Font("Arial", 8, FontStyle.Regular);

                if (column.DataType == typeof(bool))
                {
                    dataTXT.Text = "{IIF(DS." + colName + ", \"+\", \"\")}";
                }
                else
                {
                    dataTXT.Text = "{DS." + colName + "}";
                }

                if (column.DataType == typeof(DateTime))
                {
                    string dateFormat = "dd.MM.yyyy HH:mm";
                    dataTXT.TextFormat = new StiDateFormatService(dateFormat, "");
                }

                if (column.DataType == typeof(double))
                {
                    dataTXT.TextFormat = new StiNumberFormatService(1, ".", 1, ",", 3, true, true, " ");
                }


                switch (dgvColumn.DefaultCellStyle.Alignment)
                {
                case DataGridViewContentAlignment.BottomCenter:
                case DataGridViewContentAlignment.MiddleCenter:
                case DataGridViewContentAlignment.TopCenter:
                    dataTXT.HorAlignment = StiTextHorAlignment.Center;
                    break;

                case DataGridViewContentAlignment.BottomLeft:
                case DataGridViewContentAlignment.MiddleLeft:
                case DataGridViewContentAlignment.TopLeft:
                    dataTXT.HorAlignment = StiTextHorAlignment.Left;
                    break;

                case DataGridViewContentAlignment.BottomRight:
                case DataGridViewContentAlignment.MiddleRight:
                case DataGridViewContentAlignment.TopRight:
                    dataTXT.HorAlignment = StiTextHorAlignment.Right;
                    break;
                }

                BrandData.Components.Add(dataTXT);

                prevX += dgvColumn.Width * Wkoef;
            }

            report.Show();
        }
示例#6
0
        public StiReport Convert(string fileXtraReports)
        {
            CultureInfo currentCulture = Application.CurrentCulture;

            try
            {
                Application.CurrentCulture = new CultureInfo("en-US", false);

                report = new StiReport();
                report.Pages.Clear();

                XtraReport xtraReport = new XtraReport();
                xtraReport.LoadLayout(fileXtraReports);

                detailLevel           = 0;
                currentDataSourceName = xtraReport.DataMember;
                reportUnit            = xtraReport.ReportUnit;

                if (reportUnit == ReportUnit.TenthsOfAMillimeter)
                {
                    report.ReportUnit = StiReportUnitType.Millimeters;
                }
                else
                {
                    report.ReportUnit = StiReportUnitType.HundredthsOfInch;
                }

                ReadPage(xtraReport, report);

                foreach (StiPage page in report.Pages)
                {
                    StiComponentsCollection comps = page.GetComponents();
                    foreach (StiComponent comp in comps)
                    {
                        comp.Page = page;
                    }

                    page.LargeHeightFactor = 2;
                    page.LargeHeight       = true;
                }


                //create datasources and relations, variables
                foreach (DictionaryEntry de in fields)
                {
                    string[] parts = ((string)de.Key).Split(new char[] { '.' });
                    if (parts.Length >= 2)
                    {
                        StiDataSource ds = report.Dictionary.DataSources[parts[0]];
                        if (ds == null)
                        {
                            ds       = new StiDataTableSource();
                            ds.Name  = parts[0];
                            ds.Alias = parts[0];
                            (ds as StiDataTableSource).NameInSource = datasetName;
                            ds.Columns.Add(new StiDataColumn("id"));
                            report.Dictionary.DataSources.Add(ds);
                        }

                        int pos = 1;
                        while (pos < parts.Length - 1)
                        {
                            string dsName = parts[pos];
                            if (dsName.StartsWith(ds.Name))
                            {
                                dsName = dsName.Substring(ds.Name.Length);
                            }

                            StiDataSource childSource = report.Dictionary.DataSources[dsName];
                            if (childSource == null)
                            {
                                childSource       = new StiDataTableSource();
                                childSource.Name  = dsName;
                                childSource.Alias = dsName;
                                (childSource as StiDataTableSource).NameInSource = datasetName;
                                childSource.Columns.Add(new StiDataColumn("id"));
                                report.Dictionary.DataSources.Add(childSource);
                            }
                            StiDataRelation relation = ds.GetChildRelations()[parts[pos]];
                            if (relation == null)
                            {
                                relation = new StiDataRelation(parts[pos], ds, childSource, new string[1] {
                                    "id"
                                }, new string[1] {
                                    "id"
                                });
                                report.Dictionary.Relations.Add(relation);
                            }
                            ds = childSource;
                            pos++;
                        }

                        if (ds.Columns[parts[pos]] == null)
                        {
                            StiDataColumn column = new StiDataColumn();
                            column.Name = parts[pos];
                            ds.Columns.Add(column);
                        }
                    }
                    else if (parts.Length == 1)
                    {
                        StiVariable varr = report.Dictionary.Variables[parts[0]];
                        if (varr == null)
                        {
                            varr       = new StiVariable();
                            varr.Name  = parts[0];
                            varr.Alias = parts[0];
                            report.Dictionary.Variables.Add(varr);
                        }
                    }
                }

                return(report);
            }
            finally
            {
                Application.CurrentCulture = currentCulture;
            }
        }