Пример #1
0
        /// <summary>
        /// Retrieves the list of all databases tables from the SQL server.
        /// </summary>
        /// <param name="server">server</param>
        /// <param name="databases">an ArrayList of databases</param>
        public void DatabasesTablesInfoRequested(string server, ArrayList databases)
        {
            try
            {
                if (server == null || databases == null)
                {
                    throw new ArgumentNullException();
                }

                DataSet databasesTables = new DataSet(server);
                databasesTables.Locale = CultureInfo.InvariantCulture;

                foreach (string database in databases)
                {
                    // gets user name and password.
                    UserCredentials credentials = DBViewerCache.Instance().GetCredentials(server);
                    // sets sql connection to the sql server.
                    DBViewerDAL.Instance().SetConnection(server, database, credentials.User, credentials.Password);
                    // gets the tables for the database.
                    DataTable databaseTable = DBViewerDAL.Instance().GetData(DatabasesTablesQuery);
                    // constructs the answer.
                    databaseTable.TableName = database;
                    databasesTables.Tables.Add(databaseTable);
                }

                // represents the data in the DatabaseTreeView.
                DBViewerGui.Instance().ShowDatabasesTablesInfo(databasesTables);
            }
            catch (Exception e)
            {
                // all exception catched.
                Log.WriteErrorToLogAndNotifyUser(e.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieves the list of databases from the SQL server.
        /// </summary>
        /// <param name="server">server</param>
        /// <param name="user">user</param>
        /// <param name="password">password</param>
        public void DatabasesInfoRequested(string server, string user, string password)
        {
            try
            {
                if (server == null || user == null || password == null)
                {
                    throw new ArgumentNullException();
                }

                // gets the list of all databases in the given sql server.
                DBViewerDAL.Instance().SetConnection(server, user, password);
                DataTable data = DBViewerDAL.Instance().GetData(DatabasesQuery);
                data.TableName = server;

                // saves user's credentials.
                DBViewerCache.Instance().AddCredentials(server, user, password);

                // represents the data in the DatabaseTreeView.
                DBViewerGui.Instance().ShowDatabasesInfo(data);
            }
            catch (Exception e)
            {
                // all exception catched.
                Log.WriteErrorToLogAndNotifyUser(e.Message);
            }
        }
Пример #3
0
 /// <summary>
 /// DBViewerCache Instance.
 /// </summary>
 /// <returns>DBViewerCache</returns>
 public static DBViewerCache Instance()
 {
     if (instance == null)
     {
         instance = new DBViewerCache();
     }
     return(instance);
 }
Пример #4
0
 /// <summary>
 /// Saves changed DataTable.
 /// </summary>
 /// <param name="server">server</param>
 /// <param name="database">database</param>
 /// <param name="table">table</param>
 /// <param name="data">data (actual DataTable)</param>
 public void SaveDatabaseTableRequested(string server, string database, string table, DataTable data)
 {
     try
     {
         UserCredentials credentials = DBViewerCache.Instance().GetCredentials(server);
         // sets sql connection to the sql server.
         DBViewerDAL.Instance().SetConnection(server, database, credentials.User, credentials.Password);
         DBViewerDAL.Instance().Save(data);
         // if the cache requested - resets the cache
         //if(DBViewerCache.Instance().IsCacheRequested())
         DBViewerCache.Instance().RemoveData(server, database, ConstructDataTableFullName(server, database, table));
     }
     catch (Exception e)
     {
         // all exception catched.
         Log.WriteErrorToLogAndNotifyUser(e.Message);
     }
 }
Пример #5
0
        /// <summary>
        /// Retrieves the table's data from the SQL server's database and table.
        /// </summary>
        /// <param name="server">server</param>
        /// <param name="database">database</param>
        /// <param name="table">table</param>
        public void DatabaseTableRequested(string server, string database, string table)
        {
            try
            {
                DataTable data          = null;
                string    datatableName = ConstructDataTableFullName(server, database, table);

                // if cache requested - checks whether the table was fetched already.
                if (DBViewerCache.Instance().IsCacheRequested())
                {
                    data = DBViewerCache.Instance().GetData(server, database, datatableName);
                    if (data != null)
                    {
                        DBViewerGui.Instance().ShowDatabaseTableInfo(data);
                    }
                }

                // if(data == null) or the cache isn't requested.
                // if the cache isn't requested the data will be always null.
                if (data == null)
                {
                    // gets user name and password.
                    UserCredentials credentials = DBViewerCache.Instance().GetCredentials(server);

                    // sets sql connection to the sql server.
                    DBViewerDAL.Instance().SetConnection(server, database, credentials.User, credentials.Password);

                    // constructs a query
                    StringBuilder dataQuery = new StringBuilder(QueryLength);
                    dataQuery.Append(DatabaseTableQuery);
                    dataQuery.Append("dbo.[");
                    dataQuery.Append(table);
                    dataQuery.Append("]");

                    // gets database data.
                    data           = DBViewerDAL.Instance().GetData(dataQuery.ToString());
                    data.TableName = datatableName;

                    // retrieves the sql datatypes info for the fetched table.
                    StringBuilder typesQuery = new StringBuilder(QueryLength);
                    typesQuery.Append(DatabaseTableTypesQuery);
                    typesQuery.Append("'");
                    typesQuery.Append(table);
                    typesQuery.Append("'");
                    DataTable databaseTypes = DBViewerDAL.Instance().GetData(typesQuery.ToString());

                    // updates the answer with sql datatypes info.
                    ConstructDataTablesTypes(data, databaseTypes);

                    // if cache requested - saves the data in the cache.
                    if (DBViewerCache.Instance().IsCacheRequested())
                    {
                        DBViewerCache.Instance().AddData(server, database, credentials.User, credentials.Password, data);
                    }

                    // represents the data in the DatabaseTreeView.
                    DBViewerGui.Instance().ShowDatabaseTableInfo(data);
                }
            }
            catch (Exception e)
            {
                // all exception catched.
                Log.WriteErrorToLogAndNotifyUser(e.Message);
            }
        }