예제 #1
0
        private object Enqueue(IQuery query)
        {
            if (_currentBatch == null)
            {
                _currentBatch = new QueryBatch(_context);
            }

            return(_currentBatch.Add(query));
        }
예제 #2
0
        /// <summary>The get.</summary>
        /// <param name="viewOrTableName">The view or table name.</param>
        /// <returns></returns>
        public DataTable Get(string viewOrTableName)
        {
            DbDataAdapter adapter = null;
            DbCommand     cmd     = null;
            DataTable     dt      = null;
            QueryBatch    batch   = new QueryBatch();
            Query         query   = new Query("SELECT * FROM " + viewOrTableName);

            if (string.IsNullOrEmpty(viewOrTableName))
            {
                return(null);
            }

            if (_dataTables.ContainsKey(viewOrTableName))
            {
                return(_dataTables[viewOrTableName]);
            }

            try
            {
                if (_dbConnection == null || _dbConnection.State != ConnectionState.Open)
                {
                    _dbConnection = Services.Settings.GetOpenConnection();
                }

                query.Result = new DataSet(viewOrTableName + " View");
                batch.Clear();
                batch.Add(query);

                adapter               = Services.Settings.ProviderFactory.CreateDataAdapter();
                cmd                   = _dbConnection.CreateCommand();
                cmd.CommandText       = query.Sql;
                cmd.CommandType       = CommandType.Text;
                adapter.SelectCommand = cmd;
                adapter.Fill(query.Result);
            }

// catch (Exception exp)
            // {
            // throw;
            // }
            finally
            {
                if (adapter != null)
                {
                    adapter.Dispose();
                }

                if (cmd != null)
                {
                    cmd.Dispose();
                }
            }

            if (query.Result.Tables.Count > 0)
            {
                dt = query.Result.Tables[0];
                _dataTables[viewOrTableName] = dt;
            }

            return(dt);
        }
예제 #3
0
        /// <summary>The load table data.</summary>
        private void LoadTableData()
        {
            if (_services.Settings.ConnectionDefinition == null)
            {
                _services.HostWindow.DisplaySimpleMessageBox(this, "Please select a connection.", "Select a Connection");
                return;
            }

            GetTablesAndViews();

            DbDataAdapter adapter = null;
            DbCommand     cmd     = null;
            DataTable     dt      = null;
            Query         query   = new Query("SELECT * FROM " + Utility.MakeSqlFriendly(TableName));

            if (string.IsNullOrEmpty(TableName))
            {
                Text = Resources.Table_none;
                return;
            }

            try
            {
                IsBusy        = true;
                UseWaitCursor = true;
                dataGridViewResult.DataSource = null;
                Application.DoEvents();

                if (_dbConnection == null)
                {
                    _dbConnection = _services.Settings.GetOpenConnection();
                }

                query.Result = new DataSet(TableName + " View");
                _batch.Clear();
                _batch.Add(query);

                adapter         = _services.Settings.ProviderFactory.CreateDataAdapter();
                cmd             = _dbConnection.CreateCommand();
                cmd.CommandText = query.Sql;
                cmd.CommandType = CommandType.Text;
                SetCommandTimeout(cmd, _settings.CommandTimeout);
                adapter.SelectCommand = cmd;
                adapter.Fill(query.Result);
                SetStatus(string.Format("Loaded table '{0}'", TableName));
                Text = TableName;
            }
            catch (DbException dbExp)
            {
                // todo: improve!
                _services.HostWindow.DisplaySimpleMessageBox(this, dbExp.Message, "View Table Error");
                SetStatus(dbExp.Message);
                Text = Resources.ViewDataError;
            }
            finally
            {
                if (adapter != null)
                {
                    adapter.Dispose();
                }

                if (cmd != null)
                {
                    cmd.Dispose();
                }

                UseWaitCursor = false;
                IsBusy        = false;
            }

            if (query.Result != null && query.Result.Tables.Count > 0)
            {
                dt   = query.Result.Tables[0];
                Text = Resources.Table_colon + TableName;
            }

            dataGridViewResult.DefaultCellStyle.NullValue = _settings.NullText;
            dataGridViewResult.DataSource = dt;

            if (dt != null)
            {
                SetRowCount(dt.Rows.Count);
            }
        }