From 09ef449909f7ea0594db1b4cadce6d8c6ae44c96 Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 9 Nov 2020 11:04:59 -0600 Subject: [PATCH] Finished up the profile manager for now and added some code to get the FileViewer started. --- .vs/DataOrganizer/v16/.suo | Bin 48128 -> 49152 bytes DataOrganizer/DB.cs | 151 ++++++++++++++++--- DataOrganizer/FileViewer.cs | 33 +++- DataOrganizer/ProfileManager.Designer.cs | 184 +++++++++++++++-------- DataOrganizer/ProfileManager.cs | 145 +++++++++++++++--- 5 files changed, 407 insertions(+), 106 deletions(-) diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index aebdf5215b44cff7ed17ad414e504ed5ebfd71cb..59fd2b4fc30fa8fe1d33ce4c6c989bbc33be5eda 100644 GIT binary patch delta 4257 zcmZqp!PL;eJi&%hdZVpA6JJBuzwlk#t}*H}FfcS|Pp)FBVq81F)%QwP2R|&&S*aQCX2L)AOiz~Jp%)S z0|NttBLf42AJ{zxF8&M*3;_%b41o*`3_(z{LKqkrVi_11!WbABVxVS%tN@t{!XP%t zPDKU=hET9MEt8mX_%7U$3I>IT9M15NY+ztu*aLDhlBrw_3=DrK8*+(f2rw`($S^Q4 z@G>wkh%qoQ@Gvkih%+!SurM$%$TBc6fWpofs#5|=i!d-Sa56A3@Il=UavKP9GcYhn zGB7a6GcYhHLDeQQFfgbyFfdH+;V@w|o_vtQn^ABwFQ>SO7Xt%>Hv7ED$2V>MJI3v2ZjoFfdF3*}=o5QQybFz|haYz%T)7 z?j(=|ls%P!fngd01H*I%28J073=A_F7#LnE2A)H7C1{wh$junM$gTqLfwpnlt}$&WHg^# zD)XPwY;vh+Gm`+@=3lZ^jEt6(OXcesEjE9ZuV-Xjv$<4}nNb3i2ox9?7(fXYlo&u6 z2b2LPPf!x!(PCg=0Ocl7?wY(oNo8`1l7NgAG!$(Z7#M6B7#Qr3vd<)C1s+h$gHjEM zo~)zn!2x1`@Z=ih6a^3ihHDrY7-|_980w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$qn3Ci~55oV;!-8>n=L1wI2PHbBL-3)lmbt0uk_ z)rU)p9WY>EU;tqkkS8}gOfF#((}YV4901iophC@M@8k=Oos+LMm`?7P_L55;8r?33 zV8WX%XDnr6WSA@%qC44Uz1ZZA+zLj<$&S_bn;llNFivi%v0;xm4=N-WCLfQtoP1!l zh6FR%9&2zVKJ>DrTLPL&oj0ec2Sh#dgc zd5#PW4B$YEB@hhaID%pF|J{z89WojiCp+wEnCzb+Fj-*#hE0_R7$+at?=YD=Gi`I) znkc5t2WB@gZa%Q1fpPJHRg9A_t&y5MH$!6br)6CNh75WP&_acQfngrQWXBAX%?I{4 xFm7^jV4Uo*+k~+JRL)P@<3O%8e2}J44TCd-6+;ZeX2vc5nHm32T3$n}-2g|02_pai diff --git a/DataOrganizer/DB.cs b/DataOrganizer/DB.cs index 0ded330..cb52d42 100644 --- a/DataOrganizer/DB.cs +++ b/DataOrganizer/DB.cs @@ -8,6 +8,7 @@ using Microsoft.Data.Sqlite; using System.Reflection; using System.Windows.Forms; using System.Configuration; +using System.Diagnostics; namespace DataOrganizer { @@ -67,18 +68,19 @@ namespace DataOrganizer Name = reader["profile_name"].ToString(), DefaultNewContentFolder = reader["default_new_content_folder_name"].ToString(), MachineName = reader["machine_name"].ToString(), - RowId = Convert.ToInt32(reader["profile_id"]) + Id = Convert.ToInt32(reader["profile_id"]), + FolderGroups = new List() }); } reader.Close(); - command.CommandText = "SELECT root_id, name FROM folder_root WHERE profile_id = @ID"; + command.CommandText = "SELECT root_id, name, path FROM folder_root WHERE profile_id = @ID ORDER BY name"; foreach(var profile in profiles) { command.Parameters.Clear(); - command.Parameters.AddWithValue("ID", profile.RowId); + command.Parameters.AddWithValue("ID", profile.Id); reader = command.ExecuteReader(); @@ -87,11 +89,12 @@ namespace DataOrganizer profile.FolderGroups.Add(new FolderGroup { Name = reader["name"].ToString(), - rowId = Convert.ToInt32(reader["root_id"]) + Id = Convert.ToInt32(reader["root_id"]), + Path = reader["path"].ToString() }); - - reader.Close(); } + + reader.Close(); } } } @@ -110,7 +113,7 @@ namespace DataOrganizer command.Parameters.AddWithValue("MachineName", profile.MachineName); command.Parameters.AddWithValue("DefaultPath", profile.DefaultNewContentFolder); command.Parameters.AddWithValue("Name", profile.Name); - command.Parameters.AddWithValue("ID", profile.RowId); + command.Parameters.AddWithValue("ID", profile.Id); connection.Open(); @@ -121,17 +124,88 @@ namespace DataOrganizer return true; } - public bool InsertNewProfile(Profile profile) + public int InsertNewProfile(Profile profile) { var query = @"INSERT INTO main.profile (machine_name, default_new_content_folder_name, profile_name) VALUES (@MachineName, @DefaultPath, @Name)"; + var id = -1; + + using (var connection = new SqliteConnection(ConnectionString)) + { + connection.Open(); + + using (var transaction = connection.BeginTransaction()) + { + using (var command = new SqliteCommand(query, connection, transaction)) + { + command.Parameters.AddWithValue("MachineName", profile.MachineName); + command.Parameters.AddWithValue("DefaultPath", profile.DefaultNewContentFolder); + command.Parameters.AddWithValue("Name", profile.Name); + + command.ExecuteNonQuery(); + + command.CommandText = "SELECT MAX(profile_id) FROM main.profile"; + + id = Convert.ToInt32(command.ExecuteScalar()); + + command.CommandText = "INSERT INTO main.folder_root (name, path, profile_id) VALUES (@Name, @Path, @ProfileID)"; + + if (profile.FolderGroups != null) + { + foreach(var group in profile.FolderGroups) + { + command.Parameters.Clear(); + command.Parameters.AddWithValue("Name", group.Name); + command.Parameters.AddWithValue("Path", group.Path); + command.Parameters.AddWithValue("ProfileID", id); + + command.ExecuteNonQuery(); + } + } + } + + transaction.Commit(); + } + } + + return id; + } + + public int InsertNewFolderGroup(Profile profile, string name, string path) + { + var query = @"INSERT INTO main.folder_root (name, path, profile_id) VALUES (@Name, @Path, @ProfileID)"; + var id = -1; using (var connection = new SqliteConnection(ConnectionString)) { using (var command = new SqliteCommand(query, connection)) { - command.Parameters.AddWithValue("MachineName", profile.MachineName); - command.Parameters.AddWithValue("DefaultPath", profile.DefaultNewContentFolder); - command.Parameters.AddWithValue("Name", profile.Name); + command.Parameters.AddWithValue("Name", name); + command.Parameters.AddWithValue("Path", path); + command.Parameters.AddWithValue("ProfileID", profile.Id); + + connection.Open(); + + command.ExecuteNonQuery(); + + command.CommandText = @"SELECT MAX(root_id) FROM main.folder_root"; + + id = Convert.ToInt32(command.ExecuteScalar()); + } + } + + return id; + } + + public bool UpdateFolderGroup(string newName, string path) + { + var query = @"UPDATE main.folder_root SET name = @Name, path = @Path"; + + using (var connection = new SqliteConnection(ConnectionString)) + { + using (var command = new SqliteCommand(query, connection)) + { + command.Parameters.AddWithValue("Name", newName); + command.Parameters.AddWithValue("Path", path); connection.Open(); @@ -142,20 +216,56 @@ namespace DataOrganizer return true; } - public bool InsertNewFolderGroup(Profile profile, string name) + public bool DeleteFolderGroup(FolderGroup folderGroup) { - var query = @"INSERT INTO main.folder_root (name, profile_id) VALUES (@Name, @ProfileID)"; + var query = string.Format("DELETE FROM main.file WHERE folder_root_id = {0}", folderGroup.Id); + + using(var connection = new SqliteConnection(ConnectionString)) + { + connection.Open(); + + using (var transaction = connection.BeginTransaction()) + { + using(var command = new SqliteCommand(query, connection, transaction)) + { + command.ExecuteNonQuery(); + + command.CommandText = string.Format("DELETE FROM main.folder_root WHERE root_id = {0}", folderGroup.Id); + + command.ExecuteNonQuery(); + } + + transaction.Commit(); + } + } + + return true; + } + + public bool DeleteProfile(Profile profile) + { + var query = string.Format("DELETE FROM main.file WHERE profile_id = {0}", profile.Id); using (var connection = new SqliteConnection(ConnectionString)) { - using (var command = new SqliteCommand(query, connection)) + connection.Open(); + + using (var transaction = connection.BeginTransaction()) { - command.Parameters.AddWithValue("ProfileID", profile.RowId); - command.Parameters.AddWithValue("Name", name); + using (var command = new SqliteCommand(query, connection, transaction)) + { + command.ExecuteNonQuery(); - connection.Open(); + command.CommandText = string.Format("DELETE FROM main.folder_root WHERE profile_id = {0}", profile.Id); - command.ExecuteNonQuery(); + command.ExecuteNonQuery(); + + command.CommandText = string.Format("DELETE FROM main.profile WHERE profile_id = {0}", profile.Id); + + command.ExecuteNonQuery(); + } + + transaction.Commit(); } } @@ -167,14 +277,15 @@ namespace DataOrganizer public string Name; public string DefaultNewContentFolder; public string MachineName; - public int RowId; + public int Id; public List FolderGroups; } public struct FolderGroup { - public int rowId; + public int Id; public string Name; + public string Path; } } } diff --git a/DataOrganizer/FileViewer.cs b/DataOrganizer/FileViewer.cs index 0888cb8..878e530 100644 --- a/DataOrganizer/FileViewer.cs +++ b/DataOrganizer/FileViewer.cs @@ -12,19 +12,42 @@ namespace DataOrganizer { public partial class FileViewer : Form { + private List Profiles { get; } = new List(); + public FileViewer() { InitializeComponent(); var db = new DB(); - var profiles = db.GetProfiles(); + Profiles = db.GetProfiles(); - if(profiles.Count == 0) + foreach(var profile in Profiles) { - // insert - var man = new ProfileManager(); - man.ShowDialog(); + ProfileComboBox.Items.Add(profile.Name); } + + ProfileComboBox.SelectedIndexChanged += ProfileComboBox_SelectedIndexChanged; + + ProfileComboBox.SelectedIndex = 0; + } + + private void ProfileComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + var profile = Profiles[ProfileComboBox.SelectedIndex]; + + RootFolderComboBox.Items.Clear(); + + if (profile.FolderGroups.Count > 0) + { + foreach (var folder in profile.FolderGroups) + { + RootFolderComboBox.Items.Add(folder.Name); + } + + RootFolderComboBox.SelectedIndex = 0; + } + + RootFolderComboBox.Enabled = true; } private void FolderSelectButton_Click(object sender, EventArgs e) diff --git a/DataOrganizer/ProfileManager.Designer.cs b/DataOrganizer/ProfileManager.Designer.cs index 447058c..78aa831 100644 --- a/DataOrganizer/ProfileManager.Designer.cs +++ b/DataOrganizer/ProfileManager.Designer.cs @@ -34,6 +34,10 @@ this.label3 = new System.Windows.Forms.Label(); this.ProfileInfoPanel = new System.Windows.Forms.Panel(); this.ProfileInfoGroupBox = new System.Windows.Forms.GroupBox(); + this.InsertGroupName = new System.Windows.Forms.Button(); + this.FolderGroupNameTextBox = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.DeleteProfileButton = new System.Windows.Forms.Button(); this.MachineNameTextBox = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.ProfileNameTextBox = new System.Windows.Forms.TextBox(); @@ -43,11 +47,12 @@ this.SelectNewContentLocationButton = new System.Windows.Forms.Button(); 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.label6 = new System.Windows.Forms.Label(); + this.FolderGroupPathTextBox = new System.Windows.Forms.TextBox(); + this.FolderGroupPathButton = new System.Windows.Forms.Button(); + this.FolderGroupListView = new System.Windows.Forms.ListView(); + this.NameColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.PathColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.MainLayoutPanel.SuspendLayout(); this.MainPanel.SuspendLayout(); this.ProfileInfoPanel.SuspendLayout(); @@ -66,7 +71,7 @@ this.MainLayoutPanel.RowCount = 2; 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.Size = new System.Drawing.Size(627, 809); this.MainLayoutPanel.TabIndex = 0; // // MainPanel @@ -76,14 +81,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(621, 102); + this.MainPanel.Size = new System.Drawing.Size(621, 115); this.MainPanel.TabIndex = 0; // // ProfilesComboBox // this.ProfilesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.ProfilesComboBox.FormattingEnabled = true; - this.ProfilesComboBox.Location = new System.Drawing.Point(201, 24); + this.ProfilesComboBox.Location = new System.Drawing.Point(201, 44); this.ProfilesComboBox.Name = "ProfilesComboBox"; this.ProfilesComboBox.Size = new System.Drawing.Size(311, 28); this.ProfilesComboBox.TabIndex = 0; @@ -91,7 +96,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(19, 24); + this.label3.Location = new System.Drawing.Point(23, 47); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(65, 20); this.label3.TabIndex = 7; @@ -101,14 +106,17 @@ // this.ProfileInfoPanel.Controls.Add(this.ProfileInfoGroupBox); this.ProfileInfoPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.ProfileInfoPanel.Location = new System.Drawing.Point(3, 111); + this.ProfileInfoPanel.Location = new System.Drawing.Point(3, 124); this.ProfileInfoPanel.Name = "ProfileInfoPanel"; - this.ProfileInfoPanel.Size = new System.Drawing.Size(621, 611); + this.ProfileInfoPanel.Size = new System.Drawing.Size(621, 682); this.ProfileInfoPanel.TabIndex = 1; // // ProfileInfoGroupBox // - this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupsTreeView); + this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupListView); + this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupPathButton); + this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupPathTextBox); + this.ProfileInfoGroupBox.Controls.Add(this.label6); this.ProfileInfoGroupBox.Controls.Add(this.InsertGroupName); this.ProfileInfoGroupBox.Controls.Add(this.FolderGroupNameTextBox); this.ProfileInfoGroupBox.Controls.Add(this.label5); @@ -125,14 +133,53 @@ 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(621, 611); + this.ProfileInfoGroupBox.Size = new System.Drawing.Size(621, 682); this.ProfileInfoGroupBox.TabIndex = 0; this.ProfileInfoGroupBox.TabStop = false; this.ProfileInfoGroupBox.Text = "Profile Information"; // + // InsertGroupName + // + this.InsertGroupName.Enabled = false; + this.InsertGroupName.Location = new System.Drawing.Point(518, 429); + this.InsertGroupName.Name = "InsertGroupName"; + this.InsertGroupName.Size = new System.Drawing.Size(86, 39); + this.InsertGroupName.TabIndex = 8; + this.InsertGroupName.Text = "Insert"; + this.InsertGroupName.UseVisualStyleBackColor = true; + this.InsertGroupName.Click += new System.EventHandler(this.InsertGroupName_Click); + // + // FolderGroupNameTextBox + // + this.FolderGroupNameTextBox.Location = new System.Drawing.Point(201, 286); + this.FolderGroupNameTextBox.Name = "FolderGroupNameTextBox"; + this.FolderGroupNameTextBox.Size = new System.Drawing.Size(311, 26); + this.FolderGroupNameTextBox.TabIndex = 5; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(16, 289); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(153, 20); + this.label5.TabIndex = 9; + this.label5.Text = "Folder Group Name:"; + // + // DeleteProfileButton + // + this.DeleteProfileButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.DeleteProfileButton.Location = new System.Drawing.Point(9, 633); + 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; + this.DeleteProfileButton.Click += new System.EventHandler(this.DeleteProfileButton_Click); + // // MachineNameTextBox // - this.MachineNameTextBox.Location = new System.Drawing.Point(201, 253); + this.MachineNameTextBox.Location = new System.Drawing.Point(201, 228); this.MachineNameTextBox.Name = "MachineNameTextBox"; this.MachineNameTextBox.Size = new System.Drawing.Size(311, 26); this.MachineNameTextBox.TabIndex = 4; @@ -140,7 +187,7 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(19, 256); + this.label4.Location = new System.Drawing.Point(16, 231); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(119, 20); this.label4.TabIndex = 7; @@ -148,7 +195,7 @@ // // ProfileNameTextBox // - this.ProfileNameTextBox.Location = new System.Drawing.Point(201, 51); + this.ProfileNameTextBox.Location = new System.Drawing.Point(201, 54); this.ProfileNameTextBox.Name = "ProfileNameTextBox"; this.ProfileNameTextBox.Size = new System.Drawing.Size(311, 26); this.ProfileNameTextBox.TabIndex = 1; @@ -156,7 +203,7 @@ // MachineNameLabel // this.MachineNameLabel.AutoSize = true; - this.MachineNameLabel.Location = new System.Drawing.Point(17, 185); + this.MachineNameLabel.Location = new System.Drawing.Point(16, 173); this.MachineNameLabel.Name = "MachineNameLabel"; this.MachineNameLabel.Size = new System.Drawing.Size(472, 20); this.MachineNameLabel.TabIndex = 5; @@ -165,10 +212,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(518, 562); + this.AddOrUpdateProfileButton.Location = new System.Drawing.Point(518, 633); this.AddOrUpdateProfileButton.Name = "AddOrUpdateProfileButton"; this.AddOrUpdateProfileButton.Size = new System.Drawing.Size(86, 40); - this.AddOrUpdateProfileButton.TabIndex = 7; + this.AddOrUpdateProfileButton.TabIndex = 9; this.AddOrUpdateProfileButton.Text = "button1"; this.AddOrUpdateProfileButton.UseVisualStyleBackColor = true; this.AddOrUpdateProfileButton.Click += new System.EventHandler(this.AddOrUpdateProfileButton_Click); @@ -176,7 +223,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(17, 57); + this.label1.Location = new System.Drawing.Point(16, 57); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(103, 20); this.label1.TabIndex = 0; @@ -184,7 +231,7 @@ // // SelectNewContentLocationButton // - this.SelectNewContentLocationButton.Location = new System.Drawing.Point(518, 113); + this.SelectNewContentLocationButton.Location = new System.Drawing.Point(518, 111); this.SelectNewContentLocationButton.Name = "SelectNewContentLocationButton"; this.SelectNewContentLocationButton.Size = new System.Drawing.Size(50, 30); this.SelectNewContentLocationButton.TabIndex = 3; @@ -194,7 +241,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(19, 119); + this.label2.Location = new System.Drawing.Point(16, 115); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(170, 20); this.label2.TabIndex = 2; @@ -207,64 +254,68 @@ this.NewContentLocationTextBox.Size = new System.Drawing.Size(311, 26); this.NewContentLocationTextBox.TabIndex = 2; // - // DeleteProfileButton + // label6 // - 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, 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; + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(16, 339); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(144, 20); + this.label6.TabIndex = 11; + this.label6.Text = "Folder Group Path:"; // - // label5 + // FolderGroupPathTextBox // - 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:"; + this.FolderGroupPathTextBox.Location = new System.Drawing.Point(201, 336); + this.FolderGroupPathTextBox.Name = "FolderGroupPathTextBox"; + this.FolderGroupPathTextBox.Size = new System.Drawing.Size(311, 26); + this.FolderGroupPathTextBox.TabIndex = 6; // - // FolderGroupNameTextBox + // FolderGroupPathButton // - 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; + this.FolderGroupPathButton.Location = new System.Drawing.Point(518, 334); + this.FolderGroupPathButton.Name = "FolderGroupPathButton"; + this.FolderGroupPathButton.Size = new System.Drawing.Size(50, 30); + this.FolderGroupPathButton.TabIndex = 7; + this.FolderGroupPathButton.Text = "..."; + this.FolderGroupPathButton.UseVisualStyleBackColor = true; + this.FolderGroupPathButton.Click += new System.EventHandler(this.FolderGroupPathButton_Click); // - // InsertGroupName + // FolderGroupListView // - 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); + this.FolderGroupListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.NameColumn, + this.PathColumn}); + this.FolderGroupListView.HideSelection = false; + this.FolderGroupListView.Location = new System.Drawing.Point(20, 407); + this.FolderGroupListView.MultiSelect = false; + this.FolderGroupListView.Name = "FolderGroupListView"; + this.FolderGroupListView.Size = new System.Drawing.Size(492, 220); + this.FolderGroupListView.TabIndex = 14; + this.FolderGroupListView.TabStop = false; + this.FolderGroupListView.UseCompatibleStateImageBehavior = false; + this.FolderGroupListView.View = System.Windows.Forms.View.Details; // - // FolderGroupsTreeView + // NameColumn // - 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; + this.NameColumn.Text = "Name"; + this.NameColumn.Width = 167; + // + // PathColumn + // + this.PathColumn.Text = "Path"; + this.PathColumn.Width = 312; // // ProfileManager // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(627, 725); + this.ClientSize = new System.Drawing.Size(627, 809); this.Controls.Add(this.MainLayoutPanel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; + this.MinimizeBox = false; this.Name = "ProfileManager"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.Text = "ProfileManager"; this.MainLayoutPanel.ResumeLayout(false); this.MainPanel.ResumeLayout(false); @@ -297,6 +348,11 @@ private System.Windows.Forms.Button InsertGroupName; private System.Windows.Forms.TextBox FolderGroupNameTextBox; private System.Windows.Forms.Label label5; - private System.Windows.Forms.TreeView FolderGroupsTreeView; + private System.Windows.Forms.Button FolderGroupPathButton; + private System.Windows.Forms.TextBox FolderGroupPathTextBox; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.ListView FolderGroupListView; + private System.Windows.Forms.ColumnHeader NameColumn; + private System.Windows.Forms.ColumnHeader PathColumn; } } \ No newline at end of file diff --git a/DataOrganizer/ProfileManager.cs b/DataOrganizer/ProfileManager.cs index 5e3f189..0640ed5 100644 --- a/DataOrganizer/ProfileManager.cs +++ b/DataOrganizer/ProfileManager.cs @@ -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(); + + 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)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)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)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; + } + } } }