/// <summary> /// Shows the number table /// </summary> private void ShowNumberTable() { Task.Run(() => { CurrentDataTable = DatabaseControl.GetDataTable("SELECT * FROM NumberTable"); CurrentDataView = CurrentDataTable.DefaultView; }); }
/// <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); }
/// <summary> /// Inserts the required data into the tables /// </summary> public static void InsertTables() { var dataTable = DatabaseControl.GetDataTable("SELECT * FROM MainTable"); NumberAnalysis numberAnalysis = new NumberAnalysis(); // Calculate and instert each row in draw table foreach (DataRow row in dataTable.Rows) { numberAnalysis.Update(row); DrawAnalysis drawAnalysis = new DrawAnalysis(row); drawAnalysis.Analyze(); DatabaseControl.InsertRow("DrawTable", drawAnalysis.DrawRow); } // Insert the number table for (int number = 1; number < 50; number++) { object[] temp = new object[6]; // Id and frequency for (int idx = 0; idx < 2; idx++) { temp[idx] = numberAnalysis.NumberRow[number, idx]; } // Frequency % temp[2] = 100 * (double)numberAnalysis.NumberRow[number, 1] / numberAnalysis.LastDraw; // Last delay temp[3] = numberAnalysis.NumberRow[number, 2]; // Max delays temp[4] = numberAnalysis.NumberRow[number, 3]; // Average delay temp[5] = (double)numberAnalysis.NumberRow[number, 4] / (double)numberAnalysis.NumberRow[number, 5]; DatabaseControl.InsertRow("NumberTable", temp); } }
/// <summary> /// Shows the draw table /// </summary> private void ShowDrawTable() { Task.Run(() => { CurrentDataTable = DatabaseControl.GetDataTable("SELECT * FROM DrawTable ORDER BY 'Draw Number' DESC"); DataTable cloned = CurrentDataTable.Clone(); cloned.Columns[1].DataType = typeof(string); foreach (DataRow row in CurrentDataTable.Rows) { cloned.ImportRow(row); } foreach (DataRow row in cloned.Rows) { row[1] = ((string)row[1]).Remove(((string)row[1]).IndexOf(' ')); } CurrentDataView = cloned.DefaultView; }); }
/// <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(); }