1
Fork 0

Added information from database spreadsheet for tables and data

This commit is contained in:
Jake Howard 2014-11-07 00:39:42 +00:00
parent 6fc02d8f16
commit f37b56515a

View file

@ -4,29 +4,72 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlServerCe;
using System.Data;
using System.IO;
using System.Windows.Forms;
namespace Saviour_Backup_System
{
class databaseTools
class database
{
internal static string databaseName = "db.sdf";
private static SqlCeConnection conn = new SqlCeConnection("Data Source = " + databaseName);
public static string databaseName = "db.sdf";
private static SqlCeCommand cmd = conn.CreateCommand();
internal static void setup(){
SqlCeEngine SQLEngine = new SqlCeEngine("Data Source = " + databaseName);
SQLEngine.CreateDatabase(); //Creates the database if it doesnt exist already
SQLEngine.Dispose();
private static void executeSQL(string sqlCode)
{
createTables();
fillProperties();
}
private static void fillProperties() {
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = sqlCode;
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 = "Save_Location";
string saveLocation;
string username = Environment.UserName;
switch (OSInfo.Name)
{
case("Windows XP"):
saveLocation = @"C:\Documents and Settings\" + username + @"\Saviour Backup System\My Backups\";
break;
case("Windows Vista"):
saveLocation = @"C:\Users\" + username + @"\Saviour Backup System\My Backups\";
break;
default:
saveLocation = @"C:\";
break;
}
cmd.Parameters["VALUE"].Value = "";
cmd.ExecuteNonQuery();
cmd.Parameters["PROPERTY"].Value = "Window_Style";
cmd.Parameters["VALUE"].Value = "Office2010Black";
cmd.ExecuteNonQuery();
conn.Close();
}
internal static void clearBackups(string tableName)
private static void createTables()
{
executeSQL("DELETE FROM Rules;");
conn.Open();
cmd.CommandText = "CREATE TABLE RecordSet (ID NTEXT PRIMARY KEY, Drive_Name NTEXT, Capacity INTEGER, File_System NTEXT, Type NTEXT);";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE TABLE Properties (Property NTEXT PRIMARY KEY, value NTEXT);";
cmd.ExecuteNonQuery();
conn.Close();
}
}
}