Finished up the profile manager for now and added some code to get the FileViewer started.
This commit is contained in:
+131
-20
@@ -8,6 +8,7 @@ using Microsoft.Data.Sqlite;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace DataOrganizer
|
||||
{
|
||||
@@ -67,18 +68,19 @@ namespace DataOrganizer
|
||||
Name = reader["profile_name"].ToString(),
|
||||
DefaultNewContentFolder = reader["default_new_content_folder_name"].ToString(),
|
||||
MachineName = reader["machine_name"].ToString(),
|
||||
RowId = Convert.ToInt32(reader["profile_id"])
|
||||
Id = Convert.ToInt32(reader["profile_id"]),
|
||||
FolderGroups = new List<FolderGroup>()
|
||||
});
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
|
||||
command.CommandText = "SELECT root_id, name FROM folder_root WHERE profile_id = @ID";
|
||||
command.CommandText = "SELECT root_id, name, path FROM folder_root WHERE profile_id = @ID ORDER BY name";
|
||||
|
||||
foreach(var profile in profiles)
|
||||
{
|
||||
command.Parameters.Clear();
|
||||
command.Parameters.AddWithValue("ID", profile.RowId);
|
||||
command.Parameters.AddWithValue("ID", profile.Id);
|
||||
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
@@ -87,11 +89,12 @@ namespace DataOrganizer
|
||||
profile.FolderGroups.Add(new FolderGroup
|
||||
{
|
||||
Name = reader["name"].ToString(),
|
||||
rowId = Convert.ToInt32(reader["root_id"])
|
||||
Id = Convert.ToInt32(reader["root_id"]),
|
||||
Path = reader["path"].ToString()
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +113,7 @@ namespace DataOrganizer
|
||||
command.Parameters.AddWithValue("MachineName", profile.MachineName);
|
||||
command.Parameters.AddWithValue("DefaultPath", profile.DefaultNewContentFolder);
|
||||
command.Parameters.AddWithValue("Name", profile.Name);
|
||||
command.Parameters.AddWithValue("ID", profile.RowId);
|
||||
command.Parameters.AddWithValue("ID", profile.Id);
|
||||
|
||||
connection.Open();
|
||||
|
||||
@@ -121,17 +124,88 @@ namespace DataOrganizer
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InsertNewProfile(Profile profile)
|
||||
public int InsertNewProfile(Profile profile)
|
||||
{
|
||||
var query = @"INSERT INTO main.profile (machine_name, default_new_content_folder_name, profile_name) VALUES (@MachineName, @DefaultPath, @Name)";
|
||||
var id = -1;
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
using (var command = new SqliteCommand(query, connection, transaction))
|
||||
{
|
||||
command.Parameters.AddWithValue("MachineName", profile.MachineName);
|
||||
command.Parameters.AddWithValue("DefaultPath", profile.DefaultNewContentFolder);
|
||||
command.Parameters.AddWithValue("Name", profile.Name);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = "SELECT MAX(profile_id) FROM main.profile";
|
||||
|
||||
id = Convert.ToInt32(command.ExecuteScalar());
|
||||
|
||||
command.CommandText = "INSERT INTO main.folder_root (name, path, profile_id) VALUES (@Name, @Path, @ProfileID)";
|
||||
|
||||
if (profile.FolderGroups != null)
|
||||
{
|
||||
foreach(var group in profile.FolderGroups)
|
||||
{
|
||||
command.Parameters.Clear();
|
||||
command.Parameters.AddWithValue("Name", group.Name);
|
||||
command.Parameters.AddWithValue("Path", group.Path);
|
||||
command.Parameters.AddWithValue("ProfileID", id);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public int InsertNewFolderGroup(Profile profile, string name, string path)
|
||||
{
|
||||
var query = @"INSERT INTO main.folder_root (name, path, profile_id) VALUES (@Name, @Path, @ProfileID)";
|
||||
var id = -1;
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
using (var command = new SqliteCommand(query, connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("MachineName", profile.MachineName);
|
||||
command.Parameters.AddWithValue("DefaultPath", profile.DefaultNewContentFolder);
|
||||
command.Parameters.AddWithValue("Name", profile.Name);
|
||||
command.Parameters.AddWithValue("Name", name);
|
||||
command.Parameters.AddWithValue("Path", path);
|
||||
command.Parameters.AddWithValue("ProfileID", profile.Id);
|
||||
|
||||
connection.Open();
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = @"SELECT MAX(root_id) FROM main.folder_root";
|
||||
|
||||
id = Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public bool UpdateFolderGroup(string newName, string path)
|
||||
{
|
||||
var query = @"UPDATE main.folder_root SET name = @Name, path = @Path";
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
using (var command = new SqliteCommand(query, connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("Name", newName);
|
||||
command.Parameters.AddWithValue("Path", path);
|
||||
|
||||
connection.Open();
|
||||
|
||||
@@ -142,20 +216,56 @@ namespace DataOrganizer
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InsertNewFolderGroup(Profile profile, string name)
|
||||
public bool DeleteFolderGroup(FolderGroup folderGroup)
|
||||
{
|
||||
var query = @"INSERT INTO main.folder_root (name, profile_id) VALUES (@Name, @ProfileID)";
|
||||
var query = string.Format("DELETE FROM main.file WHERE folder_root_id = {0}", folderGroup.Id);
|
||||
|
||||
using(var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
using(var command = new SqliteCommand(query, connection, transaction))
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = string.Format("DELETE FROM main.folder_root WHERE root_id = {0}", folderGroup.Id);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteProfile(Profile profile)
|
||||
{
|
||||
var query = string.Format("DELETE FROM main.file WHERE profile_id = {0}", profile.Id);
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
using (var command = new SqliteCommand(query, connection))
|
||||
connection.Open();
|
||||
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
command.Parameters.AddWithValue("ProfileID", profile.RowId);
|
||||
command.Parameters.AddWithValue("Name", name);
|
||||
using (var command = new SqliteCommand(query, connection, transaction))
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
connection.Open();
|
||||
command.CommandText = string.Format("DELETE FROM main.folder_root WHERE profile_id = {0}", profile.Id);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = string.Format("DELETE FROM main.profile WHERE profile_id = {0}", profile.Id);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,14 +277,15 @@ namespace DataOrganizer
|
||||
public string Name;
|
||||
public string DefaultNewContentFolder;
|
||||
public string MachineName;
|
||||
public int RowId;
|
||||
public int Id;
|
||||
public List<FolderGroup> FolderGroups;
|
||||
}
|
||||
|
||||
public struct FolderGroup
|
||||
{
|
||||
public int rowId;
|
||||
public int Id;
|
||||
public string Name;
|
||||
public string Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user