public override void CreateConnectionInDataStore(StiDictionary dictionary, StiSqlDatabase database)
        {
            try
            {
                #region Remove all old data from datastore
                int index = 0;
                foreach (StiData data in dictionary.DataStore)
                {
                    if (data.Name == database.Name)
                    {
                        dictionary.DataStore.RemoveAt(index);
                        break;
                    }
                    index++;
                }
                #endregion

                var sqlConnection = new NpgsqlConnection(database.ConnectionString);
                var data2         = new StiData(database.Name, sqlConnection);
                data2.IsReportData = true;
                dictionary.DataStore.Add(data2);
            }
            catch (Exception e)
            {
                StiLogService.Write(this.GetType(), e);
                if (!StiOptions.Engine.HideExceptions)
                {
                    throw;
                }
            }
        }
示例#2
0
        public override void RegData(StiDictionary dictionary, bool loadData)
        {
            var adapter = GetDataAdapter();

            if (adapter == null)
            {
                throw new Exception($"Database {GetType()} not found");
            }

            adapter.CreateConnectionInDataStore(dictionary, this);
        }
		public override void CreateConnectionInDataStore(StiDictionary dictionary, StiSqlDatabase database)
		{
			try
			{
				#region remove all old data from datastore
				int index = 0;
				foreach (StiData oldData in dictionary.DataStore)
				{
					if (oldData.Name == database.Name)
					{
						dictionary.DataStore.RemoveAt(index);
						break;
					}
					index++;
				}
				#endregion

                SqlCeConnection sqlConnection = new SqlCeConnection(database.ConnectionString);
				
				StiData data = new StiData(database.Name, sqlConnection);
				data.IsReportData = true;
				dictionary.DataStore.Add(data);
				
			}
			catch (Exception e)
			{
                if (!StiOptions.Engine.HideMessages) Stimulsoft.Base.StiExceptionProvider.Show(e);
			}
		}
		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;
					}
				}
			}
		}
        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;
                    }
                }
            }
        }