diff --git a/.gitignore b/.gitignore index 54739db..9ca95eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ DataOrganizer/obj/Debug/ -DataOrganizer/bin/ \ No newline at end of file +DataOrganizer/bin/ +packages/ \ No newline at end of file diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index 49509af..aebdf52 100644 Binary files a/.vs/DataOrganizer/v16/.suo and b/.vs/DataOrganizer/v16/.suo differ diff --git a/DataOrganizer/DB.cs b/DataOrganizer/DB.cs index 6370c07..0ded330 100644 --- a/DataOrganizer/DB.cs +++ b/DataOrganizer/DB.cs @@ -7,6 +7,7 @@ using System.IO; using Microsoft.Data.Sqlite; using System.Reflection; using System.Windows.Forms; +using System.Configuration; namespace DataOrganizer { @@ -48,6 +49,7 @@ namespace DataOrganizer public List GetProfiles() { var query = "SELECT * FROM profile"; + var profiles = new List(); using (var connection = new SqliteConnection(ConnectionString)) @@ -68,6 +70,29 @@ namespace DataOrganizer RowId = Convert.ToInt32(reader["profile_id"]) }); } + + reader.Close(); + + command.CommandText = "SELECT root_id, name FROM folder_root WHERE profile_id = @ID"; + + foreach(var profile in profiles) + { + command.Parameters.Clear(); + command.Parameters.AddWithValue("ID", profile.RowId); + + reader = command.ExecuteReader(); + + while(reader.Read()) + { + profile.FolderGroups.Add(new FolderGroup + { + Name = reader["name"].ToString(), + rowId = Convert.ToInt32(reader["root_id"]) + }); + + reader.Close(); + } + } } } @@ -77,6 +102,7 @@ namespace DataOrganizer public bool UpdateProfile(Profile profile) { var query = @"UPDATE main.profile SET machine_name = @MachineName, default_new_content_folder_name = @DefaultPath, profile_name = @Name WHERE profile_id = @ID"; + using (var connection = new SqliteConnection(ConnectionString)) { using (var command = new SqliteCommand(query, connection)) @@ -98,6 +124,7 @@ namespace DataOrganizer public bool InsertNewProfile(Profile profile) { var query = @"INSERT INTO main.profile (machine_name, default_new_content_folder_name, profile_name) VALUES (@MachineName, @DefaultPath, @Name)"; + using (var connection = new SqliteConnection(ConnectionString)) { using (var command = new SqliteCommand(query, connection)) @@ -115,12 +142,39 @@ namespace DataOrganizer return true; } + public bool InsertNewFolderGroup(Profile profile, string name) + { + var query = @"INSERT INTO main.folder_root (name, profile_id) VALUES (@Name, @ProfileID)"; + + using (var connection = new SqliteConnection(ConnectionString)) + { + using (var command = new SqliteCommand(query, connection)) + { + command.Parameters.AddWithValue("ProfileID", profile.RowId); + command.Parameters.AddWithValue("Name", name); + + connection.Open(); + + command.ExecuteNonQuery(); + } + } + + return true; + } + public struct Profile { public string Name; public string DefaultNewContentFolder; public string MachineName; public int RowId; + public List FolderGroups; + } + + public struct FolderGroup + { + public int rowId; + public string Name; } } } diff --git a/DataOrganizer/FileViewer.cs b/DataOrganizer/FileViewer.cs index 1578a0e..0888cb8 100644 --- a/DataOrganizer/FileViewer.cs +++ b/DataOrganizer/FileViewer.cs @@ -29,8 +29,7 @@ namespace DataOrganizer private void FolderSelectButton_Click(object sender, EventArgs e) { - var form = new ProfileManager(); - form.ShowDialog(); + } } } diff --git a/DataOrganizer/ProfileManager.Designer.cs b/DataOrganizer/ProfileManager.Designer.cs index dbc8f37..447058c 100644 --- a/DataOrganizer/ProfileManager.Designer.cs +++ b/DataOrganizer/ProfileManager.Designer.cs @@ -44,6 +44,10 @@ this.label2 = new System.Windows.Forms.Label(); this.NewContentLocationTextBox = new System.Windows.Forms.TextBox(); this.DeleteProfileButton = new System.Windows.Forms.Button(); + this.label5 = new System.Windows.Forms.Label(); + this.FolderGroupNameTextBox = new System.Windows.Forms.TextBox(); + this.InsertGroupName = new System.Windows.Forms.Button(); + this.FolderGroupsTreeView = new System.Windows.Forms.TreeView(); this.MainLayoutPanel.SuspendLayout(); this.MainPanel.SuspendLayout(); this.ProfileInfoPanel.SuspendLayout(); @@ -54,16 +58,15 @@ // this.MainLayoutPanel.ColumnCount = 1; this.MainLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.MainLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.MainLayoutPanel.Controls.Add(this.MainPanel, 0, 0); this.MainLayoutPanel.Controls.Add(this.ProfileInfoPanel, 0, 1); this.MainLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.MainLayoutPanel.Location = new System.Drawing.Point(0, 0); this.MainLayoutPanel.Name = "MainLayoutPanel"; this.MainLayoutPanel.RowCount = 2; - this.MainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); - this.MainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 75F)); - this.MainLayoutPanel.Size = new System.Drawing.Size(718, 383); + this.MainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 15F)); + this.MainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 85F)); + this.MainLayoutPanel.Size = new System.Drawing.Size(627, 725); this.MainLayoutPanel.TabIndex = 0; // // MainPanel @@ -73,14 +76,14 @@ this.MainPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.MainPanel.Location = new System.Drawing.Point(3, 3); this.MainPanel.Name = "MainPanel"; - this.MainPanel.Size = new System.Drawing.Size(712, 89); + this.MainPanel.Size = new System.Drawing.Size(621, 102); this.MainPanel.TabIndex = 0; // // ProfilesComboBox // this.ProfilesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.ProfilesComboBox.FormattingEnabled = true; - this.ProfilesComboBox.Location = new System.Drawing.Point(190, 24); + this.ProfilesComboBox.Location = new System.Drawing.Point(201, 24); this.ProfilesComboBox.Name = "ProfilesComboBox"; this.ProfilesComboBox.Size = new System.Drawing.Size(311, 28); this.ProfilesComboBox.TabIndex = 0; @@ -98,13 +101,17 @@ // this.ProfileInfoPanel.Controls.Add(this.ProfileInfoGroupBox); this.ProfileInfoPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.ProfileInfoPanel.Location = new System.Drawing.Point(3, 98); + this.ProfileInfoPanel.Location = new System.Drawing.Point(3, 111); this.ProfileInfoPanel.Name = "ProfileInfoPanel"; - this.ProfileInfoPanel.Size = new System.Drawing.Size(712, 282); + this.ProfileInfoPanel.Size = new System.Drawing.Size(621, 611); this.ProfileInfoPanel.TabIndex = 1; // // ProfileInfoGroupBox // + this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupsTreeView); + this.ProfileInfoGroupBox.Controls.Add(this.InsertGroupName); + this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupNameTextBox); + this.ProfileInfoGroupBox.Controls.Add(this.label5); this.ProfileInfoGroupBox.Controls.Add(this.DeleteProfileButton); this.ProfileInfoGroupBox.Controls.Add(this.MachineNameTextBox); this.ProfileInfoGroupBox.Controls.Add(this.label4); @@ -118,14 +125,14 @@ this.ProfileInfoGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; this.ProfileInfoGroupBox.Location = new System.Drawing.Point(0, 0); this.ProfileInfoGroupBox.Name = "ProfileInfoGroupBox"; - this.ProfileInfoGroupBox.Size = new System.Drawing.Size(712, 282); + this.ProfileInfoGroupBox.Size = new System.Drawing.Size(621, 611); this.ProfileInfoGroupBox.TabIndex = 0; this.ProfileInfoGroupBox.TabStop = false; this.ProfileInfoGroupBox.Text = "Profile Information"; // // MachineNameTextBox // - this.MachineNameTextBox.Location = new System.Drawing.Point(190, 127); + this.MachineNameTextBox.Location = new System.Drawing.Point(201, 253); this.MachineNameTextBox.Name = "MachineNameTextBox"; this.MachineNameTextBox.Size = new System.Drawing.Size(311, 26); this.MachineNameTextBox.TabIndex = 4; @@ -133,7 +140,7 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(17, 130); + this.label4.Location = new System.Drawing.Point(19, 256); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(119, 20); this.label4.TabIndex = 7; @@ -141,7 +148,7 @@ // // ProfileNameTextBox // - this.ProfileNameTextBox.Location = new System.Drawing.Point(190, 41); + this.ProfileNameTextBox.Location = new System.Drawing.Point(201, 51); this.ProfileNameTextBox.Name = "ProfileNameTextBox"; this.ProfileNameTextBox.Size = new System.Drawing.Size(311, 26); this.ProfileNameTextBox.TabIndex = 1; @@ -149,7 +156,7 @@ // MachineNameLabel // this.MachineNameLabel.AutoSize = true; - this.MachineNameLabel.Location = new System.Drawing.Point(17, 178); + this.MachineNameLabel.Location = new System.Drawing.Point(17, 185); this.MachineNameLabel.Name = "MachineNameLabel"; this.MachineNameLabel.Size = new System.Drawing.Size(472, 20); this.MachineNameLabel.TabIndex = 5; @@ -158,10 +165,10 @@ // AddOrUpdateProfileButton // this.AddOrUpdateProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.AddOrUpdateProfileButton.Location = new System.Drawing.Point(625, 233); + this.AddOrUpdateProfileButton.Location = new System.Drawing.Point(518, 562); this.AddOrUpdateProfileButton.Name = "AddOrUpdateProfileButton"; - this.AddOrUpdateProfileButton.Size = new System.Drawing.Size(81, 40); - this.AddOrUpdateProfileButton.TabIndex = 5; + this.AddOrUpdateProfileButton.Size = new System.Drawing.Size(86, 40); + this.AddOrUpdateProfileButton.TabIndex = 7; this.AddOrUpdateProfileButton.Text = "button1"; this.AddOrUpdateProfileButton.UseVisualStyleBackColor = true; this.AddOrUpdateProfileButton.Click += new System.EventHandler(this.AddOrUpdateProfileButton_Click); @@ -169,7 +176,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(17, 44); + this.label1.Location = new System.Drawing.Point(17, 57); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(103, 20); this.label1.TabIndex = 0; @@ -177,7 +184,7 @@ // // SelectNewContentLocationButton // - this.SelectNewContentLocationButton.Location = new System.Drawing.Point(507, 82); + this.SelectNewContentLocationButton.Location = new System.Drawing.Point(518, 113); this.SelectNewContentLocationButton.Name = "SelectNewContentLocationButton"; this.SelectNewContentLocationButton.Size = new System.Drawing.Size(50, 30); this.SelectNewContentLocationButton.TabIndex = 3; @@ -187,7 +194,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(17, 85); + this.label2.Location = new System.Drawing.Point(19, 119); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(170, 20); this.label2.TabIndex = 2; @@ -195,7 +202,7 @@ // // NewContentLocationTextBox // - this.NewContentLocationTextBox.Location = new System.Drawing.Point(190, 82); + this.NewContentLocationTextBox.Location = new System.Drawing.Point(201, 113); this.NewContentLocationTextBox.Name = "NewContentLocationTextBox"; this.NewContentLocationTextBox.Size = new System.Drawing.Size(311, 26); this.NewContentLocationTextBox.TabIndex = 2; @@ -204,18 +211,57 @@ // this.DeleteProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.DeleteProfileButton.Enabled = false; - this.DeleteProfileButton.Location = new System.Drawing.Point(9, 233); + this.DeleteProfileButton.Location = new System.Drawing.Point(9, 562); this.DeleteProfileButton.Name = "DeleteProfileButton"; this.DeleteProfileButton.Size = new System.Drawing.Size(75, 40); this.DeleteProfileButton.TabIndex = 8; + this.DeleteProfileButton.TabStop = false; this.DeleteProfileButton.Text = "Delete"; this.DeleteProfileButton.UseVisualStyleBackColor = true; // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(19, 308); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(153, 20); + this.label5.TabIndex = 9; + this.label5.Text = "Folder Group Name:"; + // + // FolderGroupNameTextBox + // + this.FolderGroupNameTextBox.Location = new System.Drawing.Point(201, 305); + this.FolderGroupNameTextBox.Name = "FolderGroupNameTextBox"; + this.FolderGroupNameTextBox.Size = new System.Drawing.Size(311, 26); + this.FolderGroupNameTextBox.TabIndex = 5; + // + // InsertGroupName + // + this.InsertGroupName.Location = new System.Drawing.Point(518, 299); + this.InsertGroupName.Name = "InsertGroupName"; + this.InsertGroupName.Size = new System.Drawing.Size(86, 39); + this.InsertGroupName.TabIndex = 6; + this.InsertGroupName.Text = "Insert"; + this.InsertGroupName.UseVisualStyleBackColor = true; + this.InsertGroupName.Click += new System.EventHandler(this.InsertGroupName_Click); + // + // FolderGroupsTreeView + // + this.FolderGroupsTreeView.FullRowSelect = true; + this.FolderGroupsTreeView.LabelEdit = true; + this.FolderGroupsTreeView.Location = new System.Drawing.Point(23, 349); + this.FolderGroupsTreeView.Name = "FolderGroupsTreeView"; + this.FolderGroupsTreeView.ShowPlusMinus = false; + this.FolderGroupsTreeView.ShowRootLines = false; + this.FolderGroupsTreeView.Size = new System.Drawing.Size(489, 188); + this.FolderGroupsTreeView.TabIndex = 10; + this.FolderGroupsTreeView.TabStop = false; + // // ProfileManager // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(718, 383); + this.ClientSize = new System.Drawing.Size(627, 725); this.Controls.Add(this.MainLayoutPanel); this.MaximizeBox = false; this.Name = "ProfileManager"; @@ -248,5 +294,9 @@ private System.Windows.Forms.TextBox MachineNameTextBox; private System.Windows.Forms.Label label4; private System.Windows.Forms.Button DeleteProfileButton; + private System.Windows.Forms.Button InsertGroupName; + private System.Windows.Forms.TextBox FolderGroupNameTextBox; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TreeView FolderGroupsTreeView; } } \ No newline at end of file diff --git a/DataOrganizer/ProfileManager.cs b/DataOrganizer/ProfileManager.cs index 591490c..5e3f189 100644 --- a/DataOrganizer/ProfileManager.cs +++ b/DataOrganizer/ProfileManager.cs @@ -14,19 +14,46 @@ 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(); 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) @@ -122,5 +149,17 @@ namespace DataOrganizer 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(); + } } }