Added details for program initialisation
This commit is contained in:
parent
637baf6e64
commit
f8f8e3ac9e
1 changed files with 22 additions and 2 deletions
|
@ -1,19 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Data.SqlServerCe;
|
using System.Data.SqlServerCe;
|
||||||
|
|
||||||
|
|
||||||
namespace Saviour_Backup_System
|
namespace Saviour_Backup_System
|
||||||
{
|
{
|
||||||
class setup
|
class setup
|
||||||
{
|
{
|
||||||
public static void initProgram()
|
public static void initProgram()
|
||||||
{
|
{
|
||||||
|
return; // Stops the code running while testing.
|
||||||
|
|
||||||
string databaseName = databaseTools.databaseName;
|
string databaseName = databaseTools.databaseName;
|
||||||
if (File.Exists(databaseName)) { return; } // If the program has been run before, then the database will exist, so use that to test it.
|
if (File.Exists(databaseName)) { return; } // If the program has been run before, then the database will exist, so use that to test it.
|
||||||
|
|
||||||
SqlCeEngine SQLEngine = new SqlCeEngine("Data Source = " + databaseName);
|
SqlCeEngine SQLEngine = new SqlCeEngine("Data Source = " + databaseName);
|
||||||
SQLEngine.CreateDatabase(); //Creates the database if it doesnt exist already
|
SQLEngine.CreateDatabase(); //Creates the database if it doesnt exist already
|
||||||
|
|
||||||
|
@ -24,10 +29,25 @@ namespace Saviour_Backup_System
|
||||||
cmd.CommandText = "CREATE TABLE Rules (%%);"; //Fill these in! (Before running)
|
cmd.CommandText = "CREATE TABLE Rules (%%);"; //Fill these in! (Before running)
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
cmd.CommandText = "CREATE TABLE Properties (%%);"; //Fill this one in too
|
cmd.CommandText = "CREATE TABLE Properties (Property NTEXT PRIMARY KEY, value NTEXT);"; //Fill this one in too
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
fillDatabase(cmd, conn);
|
||||||
|
}
|
||||||
|
private static void fillDatabase(SqlCeCommand cmd, SqlCeConnection conn)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO Properties VALUES (?,?);";
|
||||||
|
cmd.Parameters.Add(new SqlCeParameter("PROPERTY", SqlDbType.Int));
|
||||||
|
cmd.Parameters.Add(new SqlCeParameter("VALUE", SqlDbType.NText));
|
||||||
|
|
||||||
|
cmd.Parameters["PROPERTY"].Value = "Startup";
|
||||||
|
cmd.Parameters["VALUE"].Value = "FALSE";
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
cmd.Parameters["PROPERTY"].Value = "";
|
||||||
|
cmd.Parameters["VALUE"].Value = "";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
cmd.CommandText = "CREATE TABLE ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue