166 lines
6.0 KiB
C#
166 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DataOrganizer
|
|
{
|
|
public partial class ProfileManager : Form
|
|
{
|
|
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();
|
|
|
|
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;
|
|
deleteMenuItem.Click += DeleteMenuItem_Click;
|
|
|
|
UpdateProfileComboBox();
|
|
}
|
|
|
|
private void FolderGroupsTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Right)
|
|
{
|
|
FolderGroupListContextMenu.Show(FolderGroupsTreeView, e.Location);
|
|
}
|
|
}
|
|
|
|
private void DeleteMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void RenameMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void MachineNameTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (MachineNameTextBox.Text.Length > 0)
|
|
MachineNameLabel.Text = string.Format(MachineNameLabelText, MachineNameTextBox.Text);
|
|
else
|
|
MachineNameLabel.Text = string.Format(MachineNameLabelText, Environment.MachineName);
|
|
}
|
|
|
|
private void ToggleAddOrUpdateButton(object sender, EventArgs e)
|
|
{
|
|
if (ProfileNameTextBox.Text != string.Empty && NewContentLocationTextBox.Text != string.Empty)
|
|
AddOrUpdateProfileButton.Enabled = true;
|
|
else
|
|
AddOrUpdateProfileButton.Enabled = false;
|
|
}
|
|
|
|
private void UpdateProfileComboBox()
|
|
{
|
|
var db = new DB();
|
|
|
|
var profiles = db.GetProfiles();
|
|
ProfilesComboBox.Items.Clear();
|
|
ProfilesComboBox.Tag = null;
|
|
ProfilesComboBox.Items.Add("Add New Profile");
|
|
ProfilesComboBox.SelectedIndex = 0;
|
|
|
|
if (profiles.Count == 0)
|
|
{
|
|
ProfilesComboBox.Enabled = false;
|
|
return;
|
|
}
|
|
|
|
ProfilesComboBox.Enabled = true;
|
|
|
|
foreach (var profile in profiles)
|
|
{
|
|
ProfilesComboBox.Items.Add(profile.Name);
|
|
}
|
|
|
|
ProfilesComboBox.Tag = profiles;
|
|
}
|
|
|
|
private void AddOrUpdateProfileButton_Click(object sender, EventArgs e)
|
|
{
|
|
var machineName = Environment.MachineName;
|
|
var db = new DB();
|
|
|
|
if(!string.IsNullOrWhiteSpace(MachineNameTextBox.Text))
|
|
{
|
|
machineName = MachineNameTextBox.Text;
|
|
}
|
|
|
|
if (!IsUpdating)
|
|
{
|
|
db.InsertNewProfile(new DB.Profile { Name = ProfileNameTextBox.Text, DefaultNewContentFolder = NewContentLocationTextBox.Text, MachineName = machineName });
|
|
|
|
UpdateProfileComboBox();
|
|
}
|
|
else
|
|
{
|
|
var profile = ((List<DB.Profile>)ProfilesComboBox.Tag)[ProfilesComboBox.SelectedIndex - 1];
|
|
profile.Name = ProfileNameTextBox.Text;
|
|
profile.DefaultNewContentFolder = NewContentLocationTextBox.Text;
|
|
profile.MachineName = MachineNameTextBox.Text;
|
|
db.UpdateProfile(profile);
|
|
}
|
|
|
|
UpdateProfileComboBox();
|
|
}
|
|
|
|
private void ProfilesComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (ProfilesComboBox.SelectedIndex == 0)
|
|
{
|
|
ProfileNameTextBox.Text = string.Empty;
|
|
NewContentLocationTextBox.Text = string.Empty;
|
|
MachineNameTextBox.Text = string.Empty;
|
|
AddOrUpdateProfileButton.Text = "Add";
|
|
AddOrUpdateProfileButton.Enabled = false;
|
|
MachineNameLabel.Text = string.Format(MachineNameLabelText, Environment.MachineName);
|
|
IsUpdating = false;
|
|
return;
|
|
}
|
|
|
|
var profile = ((List<DB.Profile>)ProfilesComboBox.Tag)[ProfilesComboBox.SelectedIndex - 1];
|
|
|
|
ProfileNameTextBox.Text = profile.Name;
|
|
NewContentLocationTextBox.Text = profile.DefaultNewContentFolder;
|
|
MachineNameTextBox.Text = profile.MachineName;
|
|
|
|
MachineNameLabel.Text = string.Format(MachineNameLabelText, profile.MachineName);
|
|
|
|
AddOrUpdateProfileButton.Text = "Update";
|
|
IsUpdating = true;
|
|
}
|
|
|
|
private void InsertGroupName_Click(object sender, EventArgs e)
|
|
{
|
|
if(!string.IsNullOrEmpty(FolderGroupNameTextBox.Text))
|
|
{
|
|
if (!FolderGroupsTreeView.Nodes.ContainsKey(FolderGroupNameTextBox.Text))
|
|
FolderGroupsTreeView.Nodes.Add(FolderGroupNameTextBox.Text);
|
|
}
|
|
|
|
FolderGroupNameTextBox.Text = string.Empty;
|
|
FolderGroupNameTextBox.Focus();
|
|
}
|
|
}
|
|
}
|