Exemplo n.º 1
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);
        }
        private void CheckDataSourceField(string dataSourceName, string fieldName)
        {
            StiDataSource ds = report.Dictionary.DataSources[dataSourceName];

            if (ds == null)
            {
                ds = new StiSqlSource();
                (ds as StiSqlSource).NameInSource = string.Format("Connection1.{0}", dataSourceName);
                ds.Name  = dataSourceName;
                ds.Alias = dataSourceName;
                (ds as StiSqlSource).SqlCommand = string.Format("select * from {0}", dataSourceName);

                report.Dictionary.DataSources.Add(ds);
            }
            StiDataColumn dc = ds.Columns[fieldName];

            if (dc == null)
            {
                dc = new StiDataColumn(fieldName, fieldName, fieldName, typeof(string));
                ds.Columns.Add(dc);
            }
        }
Exemplo n.º 3
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;
            }
        }