Finished up the profile manager for now and added some code to get the FileViewer started.

This commit is contained in:
Admin
2020-11-09 11:04:59 -06:00
parent 5468c1ad97
commit 09ef449909
5 changed files with 407 additions and 106 deletions
+128 -17
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -15,22 +16,22 @@ namespace DataOrganizer
private string MachineNameLabelText { get; } = "The Machine Name property determines what\r\nprofile will be loaded automatically (Currently: '{0}').";
private bool IsUpdating { get; set; }
private ContextMenu FolderGroupListContextMenu { get; set; } = new ContextMenu();
private TreeNode ClickedNode { get; set; }
public ProfileManager()
{
InitializeComponent();
var renameMenuItem = new MenuItem("Rename");
var deleteMenuItem = new MenuItem("Delete");
FolderGroupListContextMenu.MenuItems.Add(renameMenuItem);
FolderGroupListContextMenu.MenuItems.Add(deleteMenuItem);
ProfilesComboBox.SelectedIndexChanged += ProfilesComboBox_SelectedIndexChanged;
ProfileNameTextBox.TextChanged += ToggleAddOrUpdateButton;
NewContentLocationTextBox.TextChanged += ToggleAddOrUpdateButton;
MachineNameTextBox.TextChanged += MachineNameTextBox_TextChanged;
FolderGroupsTreeView.NodeMouseClick += FolderGroupsTreeView_NodeMouseClick;
renameMenuItem.Click += RenameMenuItem_Click;
//FolderGroupsTreeView.NodeMouseClick += FolderGroupsTreeView_NodeMouseClick;
FolderGroupPathTextBox.TextChanged += ToggleGroupInsertButton;
FolderGroupNameTextBox.TextChanged += ToggleGroupInsertButton;
deleteMenuItem.Click += DeleteMenuItem_Click;
UpdateProfileComboBox();
@@ -40,18 +41,36 @@ namespace DataOrganizer
{
if (e.Button == MouseButtons.Right)
{
FolderGroupListContextMenu.Show(FolderGroupsTreeView, e.Location);
ClickedNode = e.Node;
//FolderGroupListContextMenu.Show(FolderGroupsTreeView, e.Location);
}
}
private void DeleteMenuItem_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
if(IsUpdating)
{
var result = MessageBox.Show("Are you sure you want to delete this group? Doing so will delete all records associated with it?", "Confirm Group Deletion", MessageBoxButtons.YesNo);
private void RenameMenuItem_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
if(result == DialogResult.Yes)
{
var db = new DB();
var currentIndex = ProfilesComboBox.SelectedIndex;
db.DeleteFolderGroup((DB.FolderGroup) ClickedNode.Tag);
UpdateProfileComboBox();
ProfilesComboBox.SelectedIndex = currentIndex;
}
}
else
{
FolderGroupListView.Items.Remove(FolderGroupListView.SelectedItems[0]);
//FolderGroupsTreeView.Nodes.Remove(ClickedNode);
}
ClickedNode = null;
}
private void MachineNameTextBox_TextChanged(object sender, EventArgs e)
@@ -70,6 +89,14 @@ namespace DataOrganizer
AddOrUpdateProfileButton.Enabled = false;
}
private void ToggleGroupInsertButton(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(FolderGroupNameTextBox.Text) && !string.IsNullOrEmpty(FolderGroupPathTextBox.Text))
InsertGroupName.Enabled = true;
else
InsertGroupName.Enabled = false;
}
private void UpdateProfileComboBox()
{
var db = new DB();
@@ -79,6 +106,7 @@ namespace DataOrganizer
ProfilesComboBox.Tag = null;
ProfilesComboBox.Items.Add("Add New Profile");
ProfilesComboBox.SelectedIndex = 0;
FolderGroupListView.Items.Clear();
if (profiles.Count == 0)
{
@@ -108,13 +136,24 @@ namespace DataOrganizer
if (!IsUpdating)
{
db.InsertNewProfile(new DB.Profile { Name = ProfileNameTextBox.Text, DefaultNewContentFolder = NewContentLocationTextBox.Text, MachineName = machineName });
var folders = new List<DB.FolderGroup>();
foreach(ListViewItem node in FolderGroupListView.Items)
{
folders.Add(new DB.FolderGroup
{
Name = node.SubItems[0].Text,
Path = node.SubItems[1].Text
});
}
db.InsertNewProfile(new DB.Profile { Name = ProfileNameTextBox.Text, DefaultNewContentFolder = NewContentLocationTextBox.Text, MachineName = machineName, FolderGroups = folders });
UpdateProfileComboBox();
}
else
{
var profile = ((List<DB.Profile>)ProfilesComboBox.Tag)[ProfilesComboBox.SelectedIndex - 1];
GetCurrentProfile(out DB.Profile profile);
profile.Name = ProfileNameTextBox.Text;
profile.DefaultNewContentFolder = NewContentLocationTextBox.Text;
profile.MachineName = MachineNameTextBox.Text;
@@ -126,6 +165,8 @@ namespace DataOrganizer
private void ProfilesComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
FolderGroupListView.Items.Clear();
if (ProfilesComboBox.SelectedIndex == 0)
{
ProfileNameTextBox.Text = string.Empty;
@@ -135,31 +176,101 @@ namespace DataOrganizer
AddOrUpdateProfileButton.Enabled = false;
MachineNameLabel.Text = string.Format(MachineNameLabelText, Environment.MachineName);
IsUpdating = false;
DeleteProfileButton.Enabled = false;
return;
}
var profile = ((List<DB.Profile>)ProfilesComboBox.Tag)[ProfilesComboBox.SelectedIndex - 1];
IsUpdating = true;
GetCurrentProfile(out DB.Profile profile);
ProfileNameTextBox.Text = profile.Name;
NewContentLocationTextBox.Text = profile.DefaultNewContentFolder;
MachineNameTextBox.Text = profile.MachineName;
DeleteProfileButton.Enabled = true;
MachineNameLabel.Text = string.Format(MachineNameLabelText, profile.MachineName);
AddOrUpdateProfileButton.Text = "Update";
IsUpdating = true;
if(profile.FolderGroups != null)
{
foreach(var group in profile.FolderGroups)
{
var item = new ListViewItem(group.Name);
item.SubItems.Add(group.Path);
FolderGroupListView.Items.Add(item);
}
}
}
private void InsertGroupName_Click(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(FolderGroupNameTextBox.Text))
var groupName = FolderGroupNameTextBox.Text.Trim();
if(!string.IsNullOrEmpty(groupName))
{
if (!FolderGroupsTreeView.Nodes.ContainsKey(FolderGroupNameTextBox.Text))
FolderGroupsTreeView.Nodes.Add(FolderGroupNameTextBox.Text);
if (!FolderGroupListView.Items.ContainsKey(groupName))//!FolderGroupsTreeView.Nodes.ContainsKey(groupName))
{
var item = new ListViewItem(groupName);
item.SubItems.Add(FolderGroupPathTextBox.Text);
FolderGroupListView.Items.Add(item);
if (IsUpdating)
{
var db = new DB();
GetCurrentProfile(out DB.Profile profile);
var newId = db.InsertNewFolderGroup(profile, groupName, FolderGroupPathTextBox.Text);
profile.FolderGroups.Add(new DB.FolderGroup { Name = groupName, Id = newId, Path = FolderGroupPathTextBox.Text });
}
}
}
FolderGroupNameTextBox.Text = string.Empty;
FolderGroupPathTextBox.Text = string.Empty;
FolderGroupNameTextBox.Focus();
}
private bool GetCurrentProfile(out DB.Profile profile)
{
profile = new DB.Profile();
if (!IsUpdating) return false;
profile = ((List<DB.Profile>)ProfilesComboBox.Tag)[ProfilesComboBox.SelectedIndex - 1];
return true;
}
private void DeleteProfileButton_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Are you sure? This will delete all file records (not files on disk), groups and any customization data set in this profile.", "Wipe Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if(result == DialogResult.Yes)
{
var db = new DB();
GetCurrentProfile(out DB.Profile profile);
db.DeleteProfile(profile);
UpdateProfileComboBox();
}
}
private void FolderGroupPathButton_Click(object sender, EventArgs e)
{
var dialog = new FolderBrowserDialog();
if(dialog.ShowDialog() == DialogResult.OK)
{
FolderGroupPathTextBox.Text = dialog.SelectedPath;
}
}
}
}