Ejemplo n.º 1
0
 /// <summary>
 /// Override with specific connection string
 /// </summary>
 /// <param name="nameOrConnectionString"></param>
 /// <param name="providerName"></param>
 public EfCodeFirstContext(string connectionString)  : base(connectionString)
 {
     //if(!string.IsNullOrEmpty(providerName))
     //    Db = new SqlDataAccess(connectionString, providerName);
     //else
     Db = new SqlDataAccess(connectionString);
 }
Ejemplo n.º 2
0
 /// <summary>Initializes the query with the reference to the browser tree</summary>
 /// <param name="Browser">ViewModel of the browser tree</param>
 public QueryViewModel(ref ServerBrowserViewModel Browser)
 {
     _dab = DataAccessFactory.GetDataAccess(
         Browser.ActiveConnection.ConnectionType,
         Browser.ActiveConnection.DataSource,
         Browser.ActiveConnection.SelectedDatabase,
         Browser.ActiveConnection.Authentication,
         Browser.ActiveConnection.Username,
         Browser.ActiveConnection.Password
         );
     _dab.BuildKeywords();
     _browser = Browser;
 }
 /// <summary>Creates a connection on the browser</summary>
 public void CreateConnection()
 {
     ConnectDialog cd = new ConnectDialog();
     cd.ShowDialog();
     if (cd.DataAccess != null)
     {
         if (!this._tree.Cache.ContainsKey("ROOT") || this._tree.Cache["ROOT"].FirstOrDefault(d => d.Name == cd.DataAccess.DataSource) == null)
         {
             this.AddServer(cd.DataAccess);
             this._activeConnection = cd.DataAccess;
         }
         else
         {
             MessageBox.Show("This server is already added!");
         }
     }
 }
        /// <summary>Adds a server to the tree</summary>
        /// <param name="dataAccess">Data access object to associate with the server</param>
        private void AddServer(DataAccessBase dataAccess)
        {
            ServerItem item = new ServerItem(dataAccess.DataSource);
            item.DataAccess = dataAccess;
            if (_tree.Cache.ContainsKey("ROOT"))
            {
                _tree.Cache["ROOT"].Add(item);
            }
            else
            {
                List<BaseItem> items = new List<BaseItem>();
                items.Add(item);
                _tree.Cache.Add("ROOT", items);
            }

            _tree.OnNodesInserted(TreePath.Empty, new int[] { _tree.Cache["ROOT"].Count - 1 }, new object[] { item });
        }
 /// <summary>Updates the active connection with the selected database</summary>
 /// <param name="Node">Node that drives the update</param>
 public void UpdateActiveConnection(TreeNodeAdv Node)
 {
     TreePath path = GetNodePath(Node);
     if (path.IsEmpty() == false)
     {
         ServerItem server = path.FirstNode as ServerItem;
         BaseItem db = null;
         if (path.FullPath.GetLength(0) > 1)
         {
              db = path.FullPath[1] as BaseItem;
         }
         if (server != null && server.DataAccess != null)
         {
             if (server.DataAccess.DataSource != this._activeConnection.DataSource)
                 this._activeConnection = server.DataAccess;
             if (db != null)
                 this._activeConnection.SetDatabase(db.Name);
         }
     }
 }
Ejemplo n.º 6
0
        public IEnumerable<string> GetTasks(string conn, int id)
        {
            List<string> data = new List<string>();

            DataAccessBase dbReader = new DataAccessBase();
            SqlDataReader reader = dbReader.AccessDB(conn, "SELECT * FROM Employee");

            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    data.Add(reader.GetValue(i).ToString());
                    Console.WriteLine(reader.GetValue(i));
                }
                Console.WriteLine();
            }

            return data;
        }
Ejemplo n.º 7
0
 /// <summary>Sets the external data access object</summary>
 /// <param name="Query">ExternalQuery object holding all parameters</param>
 private void SetExternalDatabase(ExternalQueryInfo Query)
 {
     if (_browser.Tree.Cache.ContainsKey("ROOT"))
     {
         ServerItem si = _browser.Tree.Cache["ROOT"].FirstOrDefault(s => s.Name == Query.Server) as ServerItem;
         _externalDab =
             DataAccessFactory.GetDataAccess(si.DataAccess.ConnectionType, si.DataAccess.DataSource, si.DataAccess.SelectedDatabase, si.DataAccess.Authentication, si.DataAccess.Username, si.DataAccess.Password);
         string oldDb = _externalDab.SelectedDatabase;
         _externalDab.SetDatabase(Query.Database);
         if (_externalDab.SelectedDatabase.ToUpper() != Query.Database.ToUpper())
         {
             _externalDab.SetDatabase(oldDb);
             throw new Exception("Could not set the database context for the extraserver query.");
         }
     }
     else
     {
         throw new Exception("I'm sorry, I don't know what server that is.");
     }
 }
Ejemplo n.º 8
0
 public VodDLManager(DBNameType dbnametype)
 {
     oDataAccess = new DataAccessBase().New(dbnametype);  // 연결할 DB 선택
 }
Ejemplo n.º 9
0
 /// <summary>Creates the query</summary>
 /// <param name="Dab">Data Access object to run the queries</param>
 /// <param name="Browser">Server tree from the active browser</param>
 public DataAccessQuery(DataAccessBase Dab, ref ServerBrowserViewModel Browser)
 {
     _dab = Dab;
     _browser = Browser;
 }
Ejemplo n.º 10
0
        private void LoadResult(DataTable dt, IDataReader reader, DataAccessBase Dab, bool ReportProgress)
        {
            DataTable schema = reader.GetSchemaTable();
            foreach (DataRow row in schema.Rows)
            {
                Type t = (Type)row["DataType"];
                if (t == typeof(byte[]))
                {
                    t = typeof(string);
                }
                DataColumn col = new DataColumn(row["ColumnName"].ToString(), t);
                dt.Columns.Add(col);
            }

            int rowCount = 0;

            while (reader.Read())
            {
                object[] vals = new object[dt.Columns.Count];
                foreach (DataColumn col in dt.Columns)
                {
                    if (reader[col.Ordinal].GetType() == typeof(byte[]))
                        vals[col.Ordinal] = BitConverter.ToString((byte[])reader[col.Ordinal]);
                    else
                        vals[col.Ordinal] = reader[col.Ordinal];
                }

                dt.LoadDataRow(vals, false);

                if (ReportProgress && ++rowCount == 1000)
                    Dab.OnRunQueryRowCreated(dt.AsDataView().ToTable());
            }
        }
Ejemplo n.º 11
0
        /// <summary>Initialize the query</summary>
        /// <param name="OpenQuery">Whether or not to open an existing query</param>
        /// <returns>String representing the initial text of the query</returns>
        public string InitQuery(bool OpenQuery)
        {
            string queryText = string.Empty;

            if (OpenQuery)
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Multiselect = false;
                open.Filter = FILE_TYPES;

                if (open.ShowDialog() == DialogResult.OK)
                {
                    this._fileName = open.FileName;
                    this._safeFileName = open.SafeFileName;
                    FileStream query = new FileStream(this._fileName, FileMode.Open, FileAccess.Read);
                    StreamReader reader = new StreamReader(query);
                    queryText = reader.ReadToEnd();
                    reader.Close();
                    reader.Dispose();
                    query.Close();
                    query.Dispose();

                    this._isSaved = true;
                }
            }

            if (this._dab == null)
            {
                ConnectDialog cd = new ConnectDialog();
                cd.ShowDialog();
                this._dab = cd.DataAccess;
            }

            this._databases = this._dab.GetDatabases();

            return queryText;
        }
Ejemplo n.º 12
0
 /// <summary>Disconnects the query from a data source</summary>
 public void Disconnect()
 {
     if (this._dab != null)
     {
         this._dab.Dispose();
         this._dab = null;
     }
 }
Ejemplo n.º 13
0
 /// <summary>Clears out the info and closes the dialog when the Cancel button is clicked.</summary>
 private void btnCancel_Click(object sender, EventArgs e)
 {
     _dataAccess = null;
     this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
     this.Close();
 }
Ejemplo n.º 14
0
        /// <summary>Handles when Open is clicked. Creates the data connection from the supplied information</summary>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                this.Enabled = false;

                this._dataAccess =
                   DataAccessFactory.GetDataAccess(
                       this.SelectedConnectionType,
                       this.cbDataSource.Text,
                       this.tbDatabase.Text,
                       this.SelectedAuthType,
                       this.tbUsername.Text,
                       this.tbPassword.Text
                   );

                DataAccessConnection current = new DataAccessConnection(
                    this.SelectedConnectionType,
                    this.cbDataSource.Text,
                    this.tbDatabase.Text,
                    this.SelectedAuthType,
                    this.tbUsername.Text,
                    (this.cbxSavePassword.Enabled && this.cbxSavePassword.Checked ? this.tbPassword.Text : null)
                    );

                int currIndex = _settings.RecentConnections.IndexOf(
                    _settings.RecentConnections.FirstOrDefault(c => c.Connection == current.Connection && c.DataSource == current.DataSource)
                    );
                if (currIndex >= 0)
                {
                    _settings.RecentConnections.RemoveAt(currIndex);
                }

                _settings.RecentConnections.Insert(0, current);
                _settings.Save();

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not open the connection!\r\n" + ex.Message, "Invalid Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Enabled = true;
            }
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="DataAccessContext" /> class.
 /// </summary>
 /// <param name="efDataAccess">The ef data access.</param>
 public DataAccessContext(DataAccessBase efDataAccess)
 {
     this.entityFrameworkDataAccess = efDataAccess;
 }
Ejemplo n.º 16
0
        /// <summary>Processes an public query, relative to the data access object</summary>
        /// <param name="Dab">DataAccessBase object to execute the query against</param>
        /// <param name="Query">Query to run</param>
        /// <returns>ResultSet object containing data and messages as a result of the given query</returns>
        private ResultSet ProcessInternalQuery(DataAccessBase Dab, string Query, bool ReportProgress)
        {
            IDataReader reader = null;

            try
            {
                if (_cancelPending)
                {
                    throw new Exception("Operation cancelled");
                }
                reader = Dab.ExecuteReader(Query);
                ResultSet rs = new ResultSet();

                rs.Messages = reader.RecordsAffected + " rows affected";
                LoadResult(rs.Data, reader, Dab, ReportProgress);

                return rs;
            }
            catch
            {
                CheckCancel();
                throw;
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
        }
 /// <summary>
 /// Custom constructor that allows passing in of a custom IDbNative context
 /// to provide SQL interactivity.
 /// </summary>
 /// <param name="dbNative"></param>
 public EfCodeFirstContext(DataAccessBase dbNative)
 {
     Db = dbNative;
 }
Ejemplo n.º 18
0
        private DataAccessBase oDataAccess; // 연결할 DB 선택

        #endregion Fields

        #region Constructors

        public VodDLManager()
        {
            oDataAccess = new DataAccessBase().New(DBNameType.CMS);  // 연결할 DB 선택
        }