예제 #1
0
        /// <summary>
        /// Creates a table
        /// </summary>
        /// <param name="TableName">The table to create; specify the full name as in the database (MainTable, DrawTable, ...)</param>
        private static void CreateTable(string TableName)
        {
            // The file name containing the relative file path from the base app directory
            string fileName = "Resources\\Database\\SQL scripts\\Create" + TableName + ".sql";

            // The query to be executed
            string query = DatabaseScripts.LoadScript(fileName);

            // If the query couldn't be loaded from the file, throw an exception
            if (query == null)
            {
                throw new FileNotFoundException($"File not found : {fileName}");
            }

            // Execute the query
            DatabaseControl.ExecuteQuery(query);
        }
예제 #2
0
        /// <summary>
        /// Perfoms a full reset on the database, deleting all the tables and creating them from scratch;
        /// be very careful when using this!
        /// </summary>
        public static void FullReset()
        {
            // Delete and re-create each base table
            foreach (var table in TableList)
            {
                DeleteTable(table);
                CreateTable(table);
            }

            // Set the file path to the raw text file containing the main table
            string bulkDataFile = System.AppDomain.CurrentDomain.BaseDirectory + "Resources\\Raw text files\\MainTable.txt";

            // Check if the file is there
            if (File.Exists(bulkDataFile) == false)
            {
                throw new FileNotFoundException($"File not found : {bulkDataFile}");
            }

            // Insert the whole file into the main table
            DatabaseControl.ExecuteQuery("SET DATEFORMAT DMY; BULK INSERT dbo.MainTable FROM '" + bulkDataFile + "' WITH(FIELDTERMINATOR = ' ')");

            // Calculate the DrawTable and NumberTable
            InsertTables();
        }