public override void SetDataSourceNames(StiData data, StiDataSource dataSource)
        {
            base.SetDataSourceNames(data, dataSource);

            dataSource.Name  = "PostgreSQLSource";
            dataSource.Alias = "PostgreSQLSource";
        }
        //private StiDataSource GetDataSourceByName(string name)
        //{
        //    foreach (StiDataSource ds in report.Dictionary.DataSources)
        //    {
        //        if (ds.Alias == name)
        //        {
        //            return ds;
        //        }
        //    }
        //    return null;
        //}

        private StiDataRelation GetDataRelationByName(string name, StiDataSource ds)
        {
            StiDataRelation dr = null;

            foreach (StiDataRelation drTemp in report.Dictionary.Relations)
            {
                if ((drTemp.Name == name || drTemp.NameInSource == name) && (drTemp.ChildSource == ds))
                {
                    dr = drTemp;
                    break;
                }
            }
            return(dr);
        }
        public override StiDataColumnsCollection GetColumnsFromData(StiData data, StiDataSource dataSource, CommandBehavior commandBehavior)
        {
            var dataColumns = new StiDataColumnsCollection();
            var sqlSource   = dataSource as StiSqlSource;

            try
            {
                if (sqlSource.SqlCommand != null && sqlSource.SqlCommand.Length > 0 && data.Data is NpgsqlConnection)
                {
                    var connection = data.Data as NpgsqlConnection;
                    OpenConnection(connection, data, dataSource.Dictionary);

                    using (var dataAdapter = new NpgsqlDataAdapter(sqlSource.SqlCommand, connection))
                        using (DataTable dataTable = new DataTable())
                        {
                            dataTable.TableName = sqlSource.Name;

                            dataAdapter.SelectCommand.CommandTimeout = sqlSource.CommandTimeout;
                            dataAdapter.SelectCommand.Prepare();
                            dataAdapter.Fill(dataTable);

                            foreach (DataColumn column in dataTable.Columns)
                            {
                                dataColumns.Add(new StiDataColumn(column.ColumnName, column.Caption, column.DataType));
                            }
                        }

                    CloseConnection(data, connection);
                }
            }
            catch (Exception e)
            {
                StiLogService.Write(this.GetType(), e);
                if (!StiOptions.Engine.HideExceptions)
                {
                    throw;
                }
            }

            return(dataColumns);
        }
		public override StiDataColumnsCollection GetColumnsFromData(StiData data, StiDataSource dataSource)
		{
			StiDataColumnsCollection dataColumns = new StiDataColumnsCollection();
			StiSqlSource sqlSource = dataSource as StiSqlSource;

			try
			{
				if (sqlSource.SqlCommand != null && sqlSource.SqlCommand.Length > 0)
				{
                    if (data.Data is SqlCeConnection)
					{
                        SqlCeConnection connection = data.Data as SqlCeConnection;
						OpenConnection(connection, data, dataSource.Dictionary);
                        using (SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(sqlSource.SqlCommand, connection))
						{
							DataTable dataTable = new DataTable();
							dataTable.TableName = sqlSource.Name;

							dataAdapter.SelectCommand.Prepare();							
														
							dataAdapter.FillSchema(dataTable, SchemaType.Source);
						
							foreach (DataColumn column in dataTable.Columns)
							{
								dataColumns.Add(new StiDataColumn(column.ColumnName, column.Caption, column.DataType));
							}

							dataTable.Dispose();
						}
						CloseConnection(data, connection);
					}
				}
			}
			catch (Exception e)
			{
				StiLogService.Write(this.GetType(), e);
			}
			
			return dataColumns;
		}
        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);
            }
        }
        private List <StiToken> PostProcessTokensList(List <StiToken> tokensList)
        {
            List <StiToken> newList = new List <StiToken>();

            tokenPos = 0;
            while (tokenPos < tokensList.Count)
            {
                StiToken token = tokensList[tokenPos];
                tokenPos++;
                if (token.Type == StiTokenType.Identifier)
                {
                    StiDataSource     ds  = report.Dictionary.DataSources[token.Value];
                    StiBusinessObject bos = report.Dictionary.BusinessObjects[token.Value];

                    #region check for DataSource field
                    if (ds != null)
                    {
                        StringBuilder fieldPath = new StringBuilder(StiNameValidator.CorrectName(token.Value));
                        while (tokenPos + 1 < tokensList.Count && tokensList[tokenPos].Type == StiTokenType.Dot)
                        {
                            token = tokensList[tokenPos + 1];
                            string nextName = StiNameValidator.CorrectName(token.Value);

                            StiDataRelation dr = GetDataRelationByName(nextName, ds);
                            if (dr != null)
                            {
                                ds        = dr.ParentSource;
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(dr.NameInSource);
                                continue;
                            }
                            if (ds.Columns.Contains(nextName))
                            {
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(nextName);
                                break;
                            }
                            foreach (StiDataColumn column in ds.Columns)
                            {
                                if (StiNameValidator.CorrectName(column.Name) == nextName)
                                {
                                    tokenPos += 2;
                                    fieldPath.Append(".");
                                    fieldPath.Append(column.NameInSource);
                                    break;
                                }
                            }

                            CheckDataSourceField(ds.Name, nextName);
                            tokenPos += 2;
                            fieldPath.Append(".");
                            fieldPath.Append(nextName);

                            //token = tokensList[tokenPos - 1];
                            break;
                        }
                        token.Type = StiTokenType.DataSourceField;
                        //надо оптимизировать и сохранять сразу массив строк !!!!!
                        token.Value = fieldPath.ToString();
                    }
                    #endregion

                    #region check for BusinessObject field
                    else if (bos != null)
                    {
                        StringBuilder fieldPath = new StringBuilder(token.Value);
                        while (tokenPos + 1 < tokensList.Count && tokensList[tokenPos].Type == StiTokenType.Dot)
                        //while (inputExpression[pos2] == '.')
                        {
                            token = tokensList[tokenPos + 1];
                            string nextName = token.Value;

                            if (bos.Columns.Contains(nextName))
                            {
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(nextName);
                                break;
                            }
                            bos = bos.BusinessObjects[nextName];
                            if (bos != null)
                            {
                                tokenPos += 2;
                                fieldPath.Append(".");
                                fieldPath.Append(bos.Name);
                                continue;
                            }
                            break;
                        }
                        token.Type = StiTokenType.BusinessObjectField;
                        //надо оптимизировать и сохранять сразу массив строк !!!!!
                        token.Value = fieldPath.ToString();
                    }
                    #endregion

                    else if ((newList.Count > 0) && (newList[newList.Count - 1].Type == StiTokenType.Dot))
                    {
                        if (MethodsList.Contains(token.Value))
                        {
                            token.Type = StiTokenType.Method;
                        }
                        else if (PropertiesList.Contains(token.Value))
                        {
                            token.Type = StiTokenType.Property;
                        }
                        else
                        {
                            ThrowError(ParserErrorCode.FieldMethodOrPropertyNotFound, token, token.Value);
                        }
                    }

                    else if (TypesList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Cast;

                        if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot))
                        {
                            string tempName = token.Value + "." + tokensList[tokenPos + 1].Value;
                            if (FunctionsList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.Function;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                            if (SystemVariablesList.Contains(tempName))
                            {
                                token.Type  = StiTokenType.SystemVariable;
                                token.Value = tempName;
                                tokenPos   += 2;
                            }
                        }
                    }

                    else if (ComponentsList.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Component;
                        if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Colon) && ComponentsList.Contains(tokensList[tokenPos + 1].Value))
                        {
                            StiComponent comp = (StiComponent)ComponentsList[tokensList[tokenPos + 1].Value];
                            if (comp != null && comp is StiDataBand)
                            {
                                token.Value = (comp as StiDataBand).DataSourceName;
                                token.Type  = StiTokenType.DataSourceField;
                                tokenPos   += 2;
                            }
                        }
                    }

                    else if (FunctionsList.Contains(token.Value))
                    {
                        while ((StiFunctionType)FunctionsList[token.Value] == StiFunctionType.NameSpace)
                        {
                            if (tokenPos + 1 >= tokensList.Count)
                            {
                                ThrowError(ParserErrorCode.UnexpectedEndOfExpression);
                            }
                            token.Value += "." + tokensList[tokenPos + 1].Value;
                            tokenPos    += 2;
                            if (!FunctionsList.Contains(token.Value))
                            {
                                ThrowError(ParserErrorCode.FunctionNotFound, token, token.Value);
                            }
                        }
                        token.Type = StiTokenType.Function;
                    }

                    else if (SystemVariablesList.Contains(token.Value) && (token.Value != "value" || component is Stimulsoft.Report.CrossTab.StiCrossCell))
                    {
                        token.Type = StiTokenType.SystemVariable;
                    }

                    //else if (token.Value.ToLowerInvariant() == "true" || token.Value.ToLowerInvariant() == "false")
                    //{
                    //    if (token.Value.ToLowerInvariant() == "true")
                    //        token.ValueObject = true;
                    //    else
                    //        token.ValueObject = false;
                    //    token.Type = StiTokenType.Number;
                    //}
                    //else if (token.Value.ToLowerInvariant() == "null")
                    //{
                    //    token.ValueObject = null;
                    //    token.Type = StiTokenType.Number;
                    //}

                    else if (ConstantsList.Contains(token.Value))
                    {
                        while (ConstantsList[token.Value] == namespaceObj)
                        {
                            if (tokenPos + 1 >= tokensList.Count)
                            {
                                ThrowError(ParserErrorCode.UnexpectedEndOfExpression);
                            }
                            string oldTokenValue = token.Value;
                            token.Value += "." + tokensList[tokenPos + 1].Value;
                            tokenPos    += 2;
                            if (!ConstantsList.Contains(token.Value))
                            {
                                ThrowError(ParserErrorCode.ItemDoesNotContainDefinition, token, oldTokenValue, tokensList[tokenPos + 1].Value);
                            }
                        }
                        token.ValueObject = ConstantsList[token.Value];
                        token.Type        = StiTokenType.Number;
                    }

                    else if (report.Dictionary.Variables.Contains(token.Value))
                    {
                        token.Type = StiTokenType.Variable;
                    }
                    else if (token.Value == "or" || token.Value == "and" || token.Value == "not")
                    {
                        if (token.Value == "or")
                        {
                            token.Type = StiTokenType.DoubleOr;
                        }
                        if (token.Value == "and")
                        {
                            token.Type = StiTokenType.DoubleAnd;
                        }
                        if (token.Value == "not")
                        {
                            token.Type = StiTokenType.Not;
                        }
                    }
                    else
                    {
                        if ((tokenPos < tokensList.Count) && (tokensList[tokenPos].Type != StiTokenType.Dot) || (tokenPos == tokensList.Count))
                        {
                            CheckDataSourceField(defaultDataSourceName, token.Value);

                            token.Type  = StiTokenType.DataSourceField;
                            token.Value = defaultDataSourceName + "." + token.Value;
                        }
                        else
                        {
                            if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot))
                            {
                                CheckDataSourceField(token.Value, tokensList[tokenPos + 1].Value);

                                token.Type  = StiTokenType.DataSourceField;
                                token.Value = token.Value + "." + tokensList[tokenPos + 1].Value;
                                tokenPos   += 2;
                            }
                            else
                            {
                                ThrowError(ParserErrorCode.NameDoesNotExistInCurrentContext, token, token.Value);
                            }
                        }
                    }
                }
                newList.Add(token);
            }
            return(newList);
        }
Пример #7
0
        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();
        }
Пример #8
0
        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();
        }
		public override void SetDataSourceNames(StiData data, StiDataSource dataSource)
		{
			base.SetDataSourceNames(data, dataSource);

            dataSource.Name = "SqlCeSource";
            dataSource.Alias = "SqlCeSource";
		}
		public override void ConnectDataSourceToData(StiDictionary dictionary, StiDataSource dataSource, bool loadData)
		{
			dataSource.Disconnect();
			if (!loadData)
			{
				dataSource.DataTable = new DataTable();
				return;
			}
			
			StiSqlSource sqlSource = dataSource as StiSqlSource;

			foreach (StiData data in dataSource.Dictionary.DataStore)
			{
				if (data.Name == sqlSource.NameInSource)
				{
					try
					{
                        if (data.Data is SqlCeConnection)
						{
                            SqlCeConnection connection = data.ViewData as SqlCeConnection;	
							OpenConnection(connection, data, dataSource.Dictionary);

                            sqlSource.DataAdapter = new SqlCeDataAdapter(sqlSource.SqlCommand, connection);

                            foreach (StiDataParameter parameter in sqlSource.Parameters)
                            {

                                ((SqlCeDataAdapter)sqlSource.DataAdapter).SelectCommand.Parameters.Add(
                                    parameter.Name, "");
                            }

							DataTable dataTable = new DataTable();
							dataTable.TableName = sqlSource.Name;
							dataSource.DataTable = dataTable;

							//sqlSource.DataAdapter.SelectCommand.CommandTimeout = sqlSource.CommandTimeout;								
							if (loadData && sqlSource.Parameters.Count > 0)
							{
								sqlSource.DataAdapter.SelectCommand.Prepare();
								sqlSource.UpdateParameters();
							}
							else
							{														
								if (loadData)
								{
                                    ((SqlCeDataAdapter)sqlSource.DataAdapter).Fill(dataTable);
									sqlSource.CheckColumnsIndexs();
								}
                                else ((SqlCeDataAdapter)sqlSource.DataAdapter).FillSchema(dataTable, SchemaType.Source);
							}						
							
							break;
						}
					}
					catch (Exception e)
					{
						StiLogService.Write(this.GetType(), e);
						if (!StiOptions.Engine.HideExceptions)throw;
					}
				}
			}
		}
Пример #11
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;
            }
        }
        public override void ConnectDataSourceToData(StiDictionary dictionary, StiDataSource dataSource, bool loadData)
        {
            dataSource.Disconnect();

            if (!loadData)
            {
                dataSource.DataTable = new DataTable();
                return;
            }

            StiSqlSource sqlSource = dataSource as StiSqlSource;

            foreach (StiData data in dataSource.Dictionary.DataStore)
            {
                if (data.Name != sqlSource.NameInSource)
                {
                    continue;
                }

                try
                {
                    if (!(data.Data is NpgsqlConnection))
                    {
                        continue;
                    }

                    var connection = data.ViewData as NpgsqlConnection;
                    OpenConnection(connection, data, dataSource.Dictionary);

                    sqlSource.DataAdapter = new NpgsqlDataAdapter(sqlSource.SqlCommand, connection);

                    foreach (StiDataParameter parameter in sqlSource.Parameters)
                    {
                        ((NpgsqlDataAdapter)sqlSource.DataAdapter).SelectCommand.Parameters.Add(
                            parameter.Name, (NpgsqlTypes.NpgsqlDbType)parameter.Type, parameter.Size);
                    }

                    var dataTable = new DataTable();
                    dataTable.TableName  = sqlSource.Name;
                    dataSource.DataTable = dataTable;

                    sqlSource.DataAdapter.SelectCommand.CommandTimeout = sqlSource.CommandTimeout;
                    if (loadData && sqlSource.Parameters.Count > 0)
                    {
                        sqlSource.DataAdapter.SelectCommand.Prepare();
                        sqlSource.UpdateParameters();
                    }
                    else
                    {
                        if (loadData)
                        {
                            ((NpgsqlDataAdapter)sqlSource.DataAdapter).Fill(dataTable);
                            sqlSource.CheckColumnsIndexs();
                        }
                        else
                        {
                            ((NpgsqlDataAdapter)sqlSource.DataAdapter).FillSchema(dataTable, SchemaType.Source);
                        }
                    }

                    break;
                }
                catch (Exception e)
                {
                    StiLogService.Write(this.GetType(), e);
                    if (!StiOptions.Engine.HideExceptions)
                    {
                        throw;
                    }
                }
            }
        }
Пример #13
0
 public void AddDataSources(StiDataSource dataSource)
 {
     Report.DataSources.Add(dataSource);
 }