Updated the ProfileManager so that users can change the FolderGroup's name (a very hacky job but it'll do). Hooked up the FileViewers 'Update Databse' button so new files can be commited to the database.
This commit is contained in:
+86
-5
@@ -147,6 +147,34 @@ namespace DataOrganizer
|
||||
return true;
|
||||
}
|
||||
|
||||
public FolderGroup GetFolderGroupByName(string name, int profileId)
|
||||
{
|
||||
var query = @"SELECT root_id, name, path, pattern_id, profile_id FROM main.folder_root WHERE profile_id = @ProfileId AND name = @Name";
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
using (var command = new SqliteCommand(query, connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("ProfileId", profileId);
|
||||
command.Parameters.AddWithValue("Name", name);
|
||||
|
||||
connection.Open();
|
||||
|
||||
var reader = command.ExecuteReader();
|
||||
|
||||
reader.Read();
|
||||
|
||||
return new FolderGroup
|
||||
{
|
||||
Id = Convert.ToInt32(reader["root_id"]),
|
||||
Name = reader["name"].ToString(),
|
||||
Path = reader["path"].ToString(),
|
||||
PatternId = Convert.ToInt32(reader["pattern_id"])
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int InsertNewProfile(Profile profile)
|
||||
{
|
||||
var query = @"INSERT INTO main.profile (machine_name, default_new_content_folder_name, profile_name) VALUES (@MachineName, @DefaultPath, @Name)";
|
||||
@@ -440,6 +468,24 @@ namespace DataOrganizer
|
||||
}
|
||||
}
|
||||
|
||||
public int GetPatternIdByName(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return 0;
|
||||
|
||||
var query = @"SELECT pattern_id FROM main.naming_pattern WHERE name = @Name";
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
using (var command = new SqliteCommand(query, connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("Name", name);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRootPathById(int id)
|
||||
{
|
||||
var query = @"SELECT path FROM folder_root WHERE root_id = @ID";
|
||||
@@ -479,9 +525,9 @@ namespace DataOrganizer
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<FileSnapshot> GetFilesForProfileByFolderGroup(int profileId, int folderGroupId)
|
||||
public List<DBFileSnapshot> GetFilesForProfileByFolderGroup(int profileId, int folderGroupId)
|
||||
{
|
||||
var files = new List<FileSnapshot>();
|
||||
var files = new List<DBFileSnapshot>();
|
||||
|
||||
var query = @"SELECT * FROM main.file INNER JOIN main.folder_root ON main.file.folder_root_id = main.folder_root.root_id WHERE main.file.profile_id = @ProfileId AND folder_root_id = @GroupId ORDER BY main.file.full_path ASC";
|
||||
|
||||
@@ -497,7 +543,7 @@ namespace DataOrganizer
|
||||
|
||||
while(reader.Read())
|
||||
{
|
||||
files.Add(new FileSnapshot
|
||||
files.Add(new DBFileSnapshot
|
||||
{
|
||||
Id = Convert.ToInt32(reader["file_id"]),
|
||||
PathNoRoot = reader["full_path"].ToString(),
|
||||
@@ -517,7 +563,7 @@ namespace DataOrganizer
|
||||
return files;
|
||||
}
|
||||
|
||||
public void InsertNewFileRecord(List<FileSnapshot> files, int profileId, int folderGroupId, string root)
|
||||
public void InsertNewFileRecord(List<DBFileSnapshot> files, int profileId, int folderGroupId, string root)
|
||||
{
|
||||
var query = @"INSERT INTO main.file (full_path, name, size, date_created, date_modified, folder_root_id, profile_id, pattern_override_id) VALUES (@FullPath, @Name, @Size, @DateCreated, @DateModified, @FolderId, @ProfileId, @PatternId)";
|
||||
var rootLength = root.Length;
|
||||
@@ -552,6 +598,41 @@ namespace DataOrganizer
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertNewFileRecord(List<FileSnapshot> files, int profileId, int folderGroupId, string root)
|
||||
{
|
||||
var query = @"INSERT INTO main.file (full_path, name, size, date_created, date_modified, folder_root_id, profile_id, pattern_override_id) VALUES (@FullPath, @Name, @Size, @DateCreated, @DateModified, @FolderId, @ProfileId, @PatternId)";
|
||||
var rootLength = root.Length;
|
||||
|
||||
using (var connection = new SqliteConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
using (var transaction = connection.BeginTransaction())
|
||||
{
|
||||
|
||||
using (var command = new SqliteCommand(query, connection, transaction))
|
||||
{
|
||||
foreach (var file in files)
|
||||
{
|
||||
command.Parameters.AddWithValue("FullPath", file.PathNoRoot);
|
||||
command.Parameters.AddWithValue("Name", file.Name);
|
||||
command.Parameters.AddWithValue("Size", file.Size);
|
||||
command.Parameters.AddWithValue("DateCreated", file.CreatedDate);
|
||||
command.Parameters.AddWithValue("DateModified", file.ModifiedDate);
|
||||
command.Parameters.AddWithValue("FolderId", folderGroupId);
|
||||
command.Parameters.AddWithValue("ProfileId", profileId);
|
||||
command.Parameters.AddWithValue("PatternId", GetPatternIdByName(file.NamingPattern));
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.Parameters.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Profile
|
||||
{
|
||||
public string Name;
|
||||
@@ -578,7 +659,7 @@ namespace DataOrganizer
|
||||
public string Regex;
|
||||
}
|
||||
|
||||
public struct FileSnapshot
|
||||
public struct DBFileSnapshot
|
||||
{
|
||||
public int Id;
|
||||
public string PathNoRoot;
|
||||
|
||||
Reference in New Issue
Block a user