示例#1
0
        private bool Connect(ProductDbType dbType, DatabaseProperties databaseProperties)
        {
            IDatabaseFunctions databaseFunctions;

            if (dbType == ProductDbType.Oracle)
            {
                databaseFunctions = new OracleOperationFunctions(databaseProperties);
            }
            else
            {
                databaseFunctions = new SqlServerOperationFunctions(databaseProperties);
            }

            try
            {
                _isConnectionDefined = databaseFunctions.TestConnection();
                DatabaseFunctions    = databaseFunctions;
                return(_isConnectionDefined);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                throw ex;
            }
        }
示例#2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="strTableName">Database table name</param>
        /// <param name="functions">Database functions object</param>
        public DataTableInformation(string strTableName, IDatabaseFunctions functions)
        {
            string strError = "";

            // Validation
            if (TableName == "" || functions == null)
            {
                return;
            }

            // Instantiate Column List
            this.m_Columns = new DataColumnInformationList();

            this.m_TableName = strTableName;

            // Get Table Exists
            this.m_TableExists = DatabaseInformation.CheckDataBaseTableExists(this.m_TableName, functions, ref strError);

            // Validation
            if (this.m_TableExists == false)
            {
                return;
            }

            // Load Table Information
            this.LoadTableInformationFromDatabase(strTableName, functions);
        }
 public void Constructor_setWithUnitOfWork_()
 {
     _unitWork = Substitute.For<IUnitOfWork>();
     _uut = new DatabaseFunctions(_unitWork);
     _uut.ConnectToDb();
     _unitWork.Products.Received(1).ConnectToDb();
 }
 public void SetUp()
 {
     _context = new DataContext();
     _unit = new UnitOfWork(_context);
     _databaseFunctions = new DatabaseFunctions(_unit);
     _context.Database.Connection.ConnectionString = "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;";
     _context.Database.ExecuteSqlCommand("dbo.TestCleanTable");
 }
        /// <summary>
        /// Database Constructor
        /// </summary>
        /// <param name="strTableName">Database table name</param>
        /// <param name="functions">IDatabaseFunctions object</param>
        public DataColumnInformationList(string strTableName, IDatabaseFunctions functions)
        {
            // Create New DataTableInformation
            DataTableInformation dataTableInformation = new DataTableInformation(strTableName, functions);

            // Add Columns To List
            this.AddRange(dataTableInformation.Columns.ToArray());
        }
示例#6
0
 private Bookstore(/*IMainFormNavigation imfn,*/ IDatabaseFunctions idbfuns, IRecommendationsComponent irecComp)
 {
     //BookstoreNavigation = new BookstoreNavFunctions(imfn);
     registerHelper = new RegisterHelper(this);
     //BookstoreFunctions = new BookstoreUIFunctions(this);
     recommendationsFunctions = irecComp;
     databaseFunctions        = idbfuns;
     User = new CurrentUser();
     recommendationsGenerator = new RecommendationsGenerator(irecComp /*, listOfModules()*/);
 }
        public void SetUp()
        {
            _logIn = Substitute.For<ILogIn>();
            _autocomplete = Substitute.For<IAutocomplete>();
            _storemanager = Substitute.For<IStoremanager>();
            _admin = Substitute.For<IAdmin>();
            _databaseFunctions = Substitute.For<IDatabaseFunctions>();

            _databaseFunctions.ConnectToDb().Returns(true);
            _uut = new LogInViewModel(_autocomplete, _logIn, _databaseFunctions, _storemanager, _admin);
        }
        public void SetUp()
        {
            _context = new DataContext();
            _unit = new UnitOfWork(_context);

            _context.Database.Connection.ConnectionString =
                "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;MultipleActiveResultSets=True;";
            _context.Database.ExecuteSqlCommand("dbo.TestCleanTable");

            _databaseFunctions = new DatabaseFunctions(_unit);

            _consumerView = new ConsumerViewModel(new global::Consumer.Consumer(_unit), new Autocomplete(_unit), _databaseFunctions  );
        }
示例#9
0
 public static Bookstore initialize(/*IMainFormNavigation imfn,*/ IDatabaseFunctions idbfuns, IRecommendationsComponent irecComp)
 {
     if (_instance == null)
     {
         lock (_mutex)
         {
             if (_instance == null)
             {
                 _instance = new Bookstore(/*imfn,*/ idbfuns, irecComp);
             }
         }
     }
     return(_instance);
 }
示例#10
0
        /// <summary>
        /// Check to ensure a database table has a specific column
        /// </summary>
        /// <param name="strTableName">Name of the table to check</param>
        /// <param name="functions">IDatabaseFunctions object</param>
        /// <param name="strColumnName">Column name</param>
        /// <param name="strError">Error string containing any Error message encountered</param>
        /// <returns></returns>
        public static bool CheckDataBaseTableHasColumn(string strTableName, IDatabaseFunctions functions, string strColumnName, ref string strError)
        {
            try
            {
                // Sanitize Table Name
                strTableName = strTableName.Trim();

                // Validation
                if (strTableName == "" || strColumnName == "")
                {
                    return(false);
                }

                // Create Query
                string strQuery = @"
								SELECT                                    
                                    COUNT(sc.name)
                                FROM 
                                    sysobjects so
                                INNER JOIN syscolumns sc ON sc.id = so.id
                                INNER JOIN systypes st on st.usertype = sc.usertype 
                                WHERE 
                                    so.name         = '" + strTableName + @"'
                                    AND sc.name     = '" + strColumnName + "'";

                // Get Table Column Count
                int intTableColumns = functions.ExecuteScalar <int>(strQuery, ref strError);

                // Validation
                if (intTableColumns == 0 || strError != "")
                {
                    return(false);
                }

                // Check Table Exists
                bool boolTableExists = intTableColumns > 0;

                return(boolTableExists);
            }
            catch (Exception ex)
            {
                strError = ex.ToString();

                return(false);
            }
        }
        /// <summary>
        ///     ConsumerViewModel constructor creates a Consumer, adds the user controlls to a list and connects to the database 
        /// </summary>
        public ConsumerViewModel(IConsumer user, IAutocomplete autocomplete, IDatabaseFunctions databaseFunctions)
        {
            // Add available pages
            PageViewModels.Add(new HomeModel());
            PageViewModels.Add(new FindProductModel(user, autocomplete));
            PageViewModels.Add(new ShoppingListModel(user, autocomplete));
            PageViewModels.Add(new GeneratedShoppingListModel(user,
                new Mail(new SmtpClientWrapper("Smtp.gmail.com", 587,
                    new NetworkCredential("*****@*****.**", "pristjek"), true))));

            if (!databaseFunctions.ConnectToDb())
                //Force database to connect at startup, and close application if it cant connect
            {
                MessageBox.Show("Der kan ikke tilsluttes til serveren", "ERROR", MessageBoxButton.OK);
                Application.Current.MainWindow.Close();
            }

            // Set starting page
            MainWindowTekst = "Pristjek220 - Forbruger - Startside";
            CurrentPageViewModel = PageViewModels[0];
        }
示例#12
0
        /// <summary>
        /// Check to ensure a database table has a specific list of columns
        /// </summary>
        /// <param name="strTableName">Name of the table to check</param>
        /// <param name="listColumnNames">Column name list</param>
        /// <param name="functions">IDatabaseFunctions object</param>
        /// <param name="strError">Error string containing any Error message encountered</param>
        /// <returns></returns>
        public static bool CheckDataBaseTableHasColumnList(string strTableName, List <string> listColumnNames, IDatabaseFunctions functions, ref string strError)
        {
            try
            {
                // Validation
                if (listColumnNames == null || listColumnNames.Count == 0)
                {
                    return(false);
                }

                foreach (string strColumnName in listColumnNames)
                {
                    // Check Table Exists
                    bool boolTableExists = CheckDataBaseTableHasColumn(strTableName, functions, strColumnName, ref strError);

                    // Validation
                    if (boolTableExists == false || strError != "")
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                strError = ex.ToString();

                return(false);
            }
        }
示例#13
0
        /// <summary>
        /// Load table information from the database
        /// </summary>
        /// <param name="strTableName">Database table name to load information from</param>
        /// <param name="functions">IDatabaseFunctions object</param>
        private void LoadTableInformationFromDatabase(string strTableName, IDatabaseFunctions functions)
        {
            try
            {
                string strError = "";

                // Get Query String
                string strQuery = SQL_GET_TABLE_INFO_QUERY + "'" + strTableName + "'";

                // Get DataTable
                DataTable dt = functions.GetDataTable(strQuery, ref strError);

                // Validation
                if (dt == null || strError != "")
                {
                    this.m_IsValid = false;

                    return;
                }

                // Sanitize Rows Into String Lists
                List <List <string> > listRowLists = dt.AsEnumerable().Select(row => row.ItemArray.Select(v => (v == null || v == DBNull.Value) ? "" : v.ToString()).ToList()).ToList();

                // Loop DataRows
                foreach (List <string> listRowValues in listRowLists)
                {
                    // Validation
                    if (listRowLists.Count < 4)
                    {
                        this.m_IsValid = false;

                        return;
                    }

                    // Get Column Name
                    string strColumnName = listRowValues[0];

                    // Get Sql Data Type
                    SqlDbType dataType = DatabaseInformation.GetSqlTypeFromString(listRowValues[1]);

                    // Get Field Length
                    int intFieldLength = (int.TryParse(listRowValues[2], out intFieldLength) == true) ? int.Parse(listRowValues[2]) : 255;

                    // Get Nullable
                    bool boolIsNullable = (bool.TryParse(listRowValues[3], out boolIsNullable) == true) ? bool.Parse(listRowValues[3]) : true;

                    // Create New Column
                    DataColumnInformation column = new DataColumnInformation(strColumnName, dataType, intFieldLength, boolIsNullable);

                    // Add Column To List
                    this.m_Columns.Add(column);
                }

                this.m_IsValid = true;
            }
            catch (Exception ex)
            {
                // To Be Implemented: Throw Custom Exception...
                Console.WriteLine(ex.ToString());
                this.m_IsValid = false;
            }
        }
示例#14
0
 public BankAccountFunctions(IDatabaseFunctions databaseFunctions)
 {
     _databaseFunctions = databaseFunctions;
     _documentFunctions = new DocumentFunctions(_databaseFunctions);
 }
 public void SetUp()
 {
     _consumer = Substitute.For<IConsumer>();
     _autocomplete = Substitute.For<IAutocomplete>();
     _databaseFunctions = Substitute.For<IDatabaseFunctions>();
     _databaseFunctions.ConnectToDb().Returns(true);
     _uut = new ConsumerViewModel(_consumer, _autocomplete, _databaseFunctions);
 }
示例#16
0
 public DocumentFunctions(IDatabaseFunctions databaseFunctions)
 {
     _databaseFunctions = databaseFunctions;
 }