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:
Admin
2020-12-07 19:11:05 -06:00
parent 59725feeec
commit 27aa247c36
7 changed files with 347 additions and 239 deletions
+64 -38
View File
@@ -21,6 +21,7 @@ namespace DataOrganizer
private List<DB.Namingconvention> NamingConventions { get; }
private Dictionary<string, DB.Profile> Profiles { get; } = new Dictionary<string, DB.Profile>();
private Dictionary<string, DB.FolderGroup> FolderGroups { get; } = new Dictionary<string, DB.FolderGroup>();
private DB.FolderGroup ActiveFolderGroup { get; set; }
public ProfileManager()
{
@@ -43,6 +44,8 @@ namespace DataOrganizer
NewContentLocationTextBox.TextChanged += ToggleAddOrUpdateButton;
MachineNameTextBox.TextChanged += MachineNameTextBox_TextChanged;
FolderGroupPathTextBox.TextChanged += ToggleGroupInsertButton;
FolderNameTextBox.TextChanged += ToggleGroupInsertButton;
FolderGroupListView.SelectedIndexChanged += FolderGroupListView_SelectedIndexChanged;
FolderGroupListView.MouseClick += FolderGroupListView_MouseClick;
SelectNewContentLocationButton.Click += SelectNewContentLocationButton_Click1;
deleteMenuItem.Click += DeleteMenuItem_Click;
@@ -51,6 +54,23 @@ namespace DataOrganizer
SetupForNewProfile();
}
private void FolderGroupListView_SelectedIndexChanged(object sender, EventArgs e)
{
var db = new DB();
GetSelectedFolderGroup(out DB.FolderGroup folderGroup);
FolderGroupPathTextBox.Text = folderGroup.Path;
FolderNameTextBox.Text = folderGroup.Name;
var index = NamingConventions.FindIndex(x => x.Id == folderGroup.PatternId);
if (index != -1)
NamingConventionComboBox.SelectedIndex = index + 1;
else
NamingConventionComboBox.SelectedIndex = 0;
InsertGroupName.Text = "Update Folder Group";
}
private void SelectNewContentLocationButton_Click1(object sender, EventArgs e)
{
var dialog = new FolderBrowserDialog() { Description = "Select the folder where new content will be placed." };
@@ -124,7 +144,7 @@ namespace DataOrganizer
private void ToggleGroupInsertButton(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(FolderGroupPathTextBox.Text))
if (!string.IsNullOrEmpty(FolderGroupPathTextBox.Text) && !string.IsNullOrEmpty(FolderNameTextBox.Text))
InsertGroupName.Enabled = true;
else
InsertGroupName.Enabled = false;
@@ -181,16 +201,45 @@ namespace DataOrganizer
private void InsertGroupName_Click(object sender, EventArgs e)
{
if (FolderGroups.ContainsKey(FolderNameTextBox.Text))
{
MessageBox.Show($"'{FolderNameTextBox.Text}' already exists as a Folder Group. Duplicate names are not allowed.", "Duplication Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
FolderNameTextBox.Focus();
return;
}
FolderGroupPathTextBox.Text = FolderGroupPathTextBox.Text.TrimEnd(new char[] { '\\' });
var dir = new DirectoryInfo(FolderGroupPathTextBox.Text);
var groupName = dir.Name;
if (!FolderGroups.ContainsKey(groupName))
if(GetSelectedFolderGroup(out DB.FolderGroup folderGroup))
{
FolderGroups.Remove(folderGroup.Name);
folderGroup.Path = FolderGroupPathTextBox.Text;
folderGroup.Name = FolderNameTextBox.Text;
GetCurrentNamingConvention(out DB.Namingconvention convention);
folderGroup.PatternId = convention.Id;
InsertGroupName.Text = "Insert Folder Group";
if (IsUpdating)
{
var db = new DB();
db.UpdateFolderGroup(folderGroup);
FolderGroupListView.SelectedItems[0].Text = folderGroup.Name;
}
FolderGroups.Add(folderGroup.Name, folderGroup);
NamingConventionComboBox.SelectedIndex = 0;
FolderNameTextBox.Text = string.Empty;
FolderGroupPathTextBox.Text = string.Empty;
InsertGroupName.Enabled = false;
}
else
{
var groupName = FolderNameTextBox.Text;
GetCurrentNamingConvention(out DB.Namingconvention convention);
GetCurrentProfile(out DB.Profile profile);
var newFolder = new DB.FolderGroup { Name = groupName, Path = FolderGroupPathTextBox.Text, PatternId = convention.Id};
var newFolder = new DB.FolderGroup { Name = groupName, Path = FolderGroupPathTextBox.Text, PatternId = convention.Id };
FolderGroupListView.Items.Add(groupName);
@@ -212,28 +261,6 @@ namespace DataOrganizer
FolderGroupPathTextBox.Text = string.Empty;
InsertGroupName.Enabled = false;
}
else
{
var folderGroup = FolderGroups[groupName];//(DB.FolderGroup) FolderGroupListView.Items.Find(groupName, true)[0].Tag;
folderGroup.Path = FolderGroupPathTextBox.Text;
folderGroup.Name = groupName;
GetCurrentNamingConvention(out DB.Namingconvention convention);
folderGroup.PatternId = convention.Id;
InsertGroupName.Text = "Insert Folder Group";
if (IsUpdating)
{
var db = new DB();
db.UpdateFolderGroup(folderGroup);
}
FolderGroups[groupName] = folderGroup;
NamingConventionComboBox.SelectedIndex = 0;
FolderNameTextBox.Text = string.Empty;
FolderGroupPathTextBox.Text = string.Empty;
InsertGroupName.Enabled = false;
}
FolderGroupPathButton.Focus();
}
@@ -297,6 +324,8 @@ namespace DataOrganizer
{
FolderGroupPathTextBox.Text = dialog.SelectedPath;
InsertGroupName.Text = "Insert Folder Group";
var dir = new DirectoryInfo(dialog.SelectedPath);
FolderNameTextBox.Text = dir.Name;
}
}
@@ -413,6 +442,13 @@ namespace DataOrganizer
{
ClearForm();
IsUpdating = true;
Profiles.Clear();
var db = new DB();
foreach(var p in db.GetProfiles())
{
Profiles.Add(p.Name, p);
}
GetCurrentProfile(out DB.Profile profile);
@@ -435,15 +471,5 @@ namespace DataOrganizer
AddOrUpdateProfileButton.Enabled = true;
DeleteProfileButton.Enabled = true;
}
private void SelectNewContentLocationButton_Click(object sender, EventArgs e)
{
var dialog = new FolderBrowserDialog() { Description = "Select the default location to look for new content." };
if (dialog.ShowDialog() == DialogResult.OK)
{
NewContentLocationTextBox.Text = dialog.SelectedPath;
}
}
}
}