diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index 99fcc70..bc8617d 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 c59793a..82c8595 100644 --- a/DataOrganizer/DB.cs +++ b/DataOrganizer/DB.cs @@ -328,6 +328,32 @@ namespace DataOrganizer return conventions; } + public Namingconvention GetNamingConventionByName(string name) + { + var query = @"SELECT name, example_text, pattern_id, regex FROM main.naming_pattern WHERE name = @Name"; + + using (var connection = new SqliteConnection(ConnectionString)) + { + using (var command = new SqliteCommand(query, connection)) + { + command.Parameters.AddWithValue("Name", name); + connection.Open(); + + var reader = command.ExecuteReader(); + + reader.Read(); + + return new Namingconvention + { + Regex = reader["regex"].ToString(), + Name = reader["name"].ToString(), + ExampleText = reader["example_text"].ToString(), + Id = Convert.ToInt32(reader["pattern_id"]) + }; + } + } + } + public string GetNamingPatternById(int id) { if (id == 0) return string.Empty; @@ -350,6 +376,32 @@ namespace DataOrganizer } } + public void DeleteNamingConvention(int id) + { + var query = @"UPDATE main.file SET pattern_override_id = 0 WHERE pattern_override_id = @ID";//@"DELETE FROM main.naming_pattern WHERE pattern_id = @Id"; + + using (var connection = new SqliteConnection(ConnectionString)) + { + connection.Open(); + using (var transaction = connection.BeginTransaction()) + { + using (var command = new SqliteCommand(query, connection, transaction)) + { + command.Parameters.AddWithValue("ID", id); + command.ExecuteNonQuery(); + + query = @"UPDATE main.folder_root SET pattern_id = 0 WHERE pattern_id = @ID"; + command.ExecuteNonQuery(); + + query = @"DELETE FROM main.naming_pattern WHERE pattern_id = @ID"; + command.ExecuteNonQuery(); + } + + transaction.Commit(); + } + } + } + public string GetRootPathById(int id) { var query = @"SELECT path FROM folder_root WHERE root_id = @ID"; diff --git a/DataOrganizer/DataOrganizer.csproj b/DataOrganizer/DataOrganizer.csproj index 88a67ca..110b378 100644 --- a/DataOrganizer/DataOrganizer.csproj +++ b/DataOrganizer/DataOrganizer.csproj @@ -91,6 +91,12 @@ MainForm.cs + + Form + + + NamingConventionManager.cs + Form @@ -106,6 +112,9 @@ MainForm.cs + + NamingConventionManager.cs + ProfileManager.cs diff --git a/DataOrganizer/FileViewer.Designer.cs b/DataOrganizer/FileViewer.Designer.cs index 4183c38..1f853ce 100644 --- a/DataOrganizer/FileViewer.Designer.cs +++ b/DataOrganizer/FileViewer.Designer.cs @@ -327,6 +327,7 @@ // // MoveModifiedFilesButton // + this.MoveModifiedFilesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.MoveModifiedFilesButton.Enabled = false; this.MoveModifiedFilesButton.Location = new System.Drawing.Point(10, 216); this.MoveModifiedFilesButton.Name = "MoveModifiedFilesButton"; diff --git a/DataOrganizer/FileViewer.cs b/DataOrganizer/FileViewer.cs index 9ec7f00..d285047 100644 --- a/DataOrganizer/FileViewer.cs +++ b/DataOrganizer/FileViewer.cs @@ -61,6 +61,8 @@ namespace DataOrganizer UpdateStatusStrip($"Moving {file.Name} to default location '{profile.DefaultNewContentFolder}'."); if(!File.Exists(newFilePath)) File.Copy(file.FullPath, newFilePath); } + + UpdateStatusStrip($"Finished copying file(s) Copied {files.Count} file(s)."); } private void CommitScanResultsButton_Click(object sender, EventArgs e) diff --git a/DataOrganizer/MainForm.Designer.cs b/DataOrganizer/MainForm.Designer.cs index f6833c8..46d971a 100644 --- a/DataOrganizer/MainForm.Designer.cs +++ b/DataOrganizer/MainForm.Designer.cs @@ -35,6 +35,7 @@ this.MainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.deleteDBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.manageNamingPatternsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MainMenu.SuspendLayout(); this.SuspendLayout(); // @@ -55,7 +56,8 @@ // this.FileMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ManageProfilesFileMainMenu, - this.FileManagerFileMainMenu}); + this.FileManagerFileMainMenu, + this.manageNamingPatternsToolStripMenuItem}); this.FileMainMenu.Name = "FileMainMenu"; this.FileMainMenu.Size = new System.Drawing.Size(54, 29); this.FileMainMenu.Text = "&File"; @@ -103,6 +105,13 @@ this.deleteDBToolStripMenuItem.Text = "&Delete DB"; this.deleteDBToolStripMenuItem.Click += new System.EventHandler(this.deleteDBToolStripMenuItem_Click); // + // manageNamingPatternsToolStripMenuItem + // + this.manageNamingPatternsToolStripMenuItem.Name = "manageNamingPatternsToolStripMenuItem"; + this.manageNamingPatternsToolStripMenuItem.Size = new System.Drawing.Size(314, 34); + this.manageNamingPatternsToolStripMenuItem.Text = "Manage &Naming Patterns"; + this.manageNamingPatternsToolStripMenuItem.Click += new System.EventHandler(this.manageNamingPatternsToolStripMenuItem_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); @@ -130,6 +139,7 @@ private System.Windows.Forms.ToolStripMenuItem FileManagerFileMainMenu; private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem deleteDBToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem manageNamingPatternsToolStripMenuItem; } } diff --git a/DataOrganizer/MainForm.cs b/DataOrganizer/MainForm.cs index 13e08a1..3cd25a1 100644 --- a/DataOrganizer/MainForm.cs +++ b/DataOrganizer/MainForm.cs @@ -34,5 +34,11 @@ namespace DataOrganizer var db = new DB(); db.DeleteDatabase(); } + + private void manageNamingPatternsToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = new NamingConventionManager(); + form.ShowDialog(); + } } } diff --git a/DataOrganizer/NamingConventionManager.Designer.cs b/DataOrganizer/NamingConventionManager.Designer.cs new file mode 100644 index 0000000..585a965 --- /dev/null +++ b/DataOrganizer/NamingConventionManager.Designer.cs @@ -0,0 +1,261 @@ +namespace DataOrganizer +{ + partial class NamingConventionManager + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.MainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.MainPanel = new System.Windows.Forms.Panel(); + this.label1 = new System.Windows.Forms.Label(); + this.NamingConventionPatternsComboBox = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.RegexTextBox = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.NameTextBox = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.ExampleTextBox = new System.Windows.Forms.TextBox(); + this.AddUpdateButton = new System.Windows.Forms.Button(); + this.PatternIdLabel = new System.Windows.Forms.Label(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.RegexResultsTextBox = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.RegexTestTextBox = new System.Windows.Forms.TextBox(); + this.TestRegexButton = new System.Windows.Forms.Button(); + this.MainLayoutPanel.SuspendLayout(); + this.MainPanel.SuspendLayout(); + this.SuspendLayout(); + // + // MainLayoutPanel + // + 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.Dock = System.Windows.Forms.DockStyle.Fill; + this.MainLayoutPanel.Location = new System.Drawing.Point(0, 0); + this.MainLayoutPanel.Name = "MainLayoutPanel"; + this.MainLayoutPanel.RowCount = 1; + this.MainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.MainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.MainLayoutPanel.Size = new System.Drawing.Size(800, 450); + this.MainLayoutPanel.TabIndex = 0; + // + // MainPanel + // + this.MainPanel.Controls.Add(this.TestRegexButton); + this.MainPanel.Controls.Add(this.RegexTestTextBox); + this.MainPanel.Controls.Add(this.label5); + this.MainPanel.Controls.Add(this.RegexResultsTextBox); + this.MainPanel.Controls.Add(this.DeleteButton); + this.MainPanel.Controls.Add(this.PatternIdLabel); + this.MainPanel.Controls.Add(this.AddUpdateButton); + this.MainPanel.Controls.Add(this.ExampleTextBox); + this.MainPanel.Controls.Add(this.label4); + this.MainPanel.Controls.Add(this.NameTextBox); + this.MainPanel.Controls.Add(this.label3); + this.MainPanel.Controls.Add(this.RegexTextBox); + this.MainPanel.Controls.Add(this.label2); + this.MainPanel.Controls.Add(this.NamingConventionPatternsComboBox); + this.MainPanel.Controls.Add(this.label1); + 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(794, 444); + this.MainPanel.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(15, 6); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(114, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select Pattern:"; + // + // NamingConventionPatternsComboBox + // + this.NamingConventionPatternsComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.NamingConventionPatternsComboBox.FormattingEnabled = true; + this.NamingConventionPatternsComboBox.Location = new System.Drawing.Point(13, 36); + this.NamingConventionPatternsComboBox.Name = "NamingConventionPatternsComboBox"; + this.NamingConventionPatternsComboBox.Size = new System.Drawing.Size(182, 28); + this.NamingConventionPatternsComboBox.TabIndex = 1; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 170); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(59, 20); + this.label2.TabIndex = 2; + this.label2.Text = "Regex:"; + // + // RegexTextBox + // + this.RegexTextBox.Location = new System.Drawing.Point(13, 200); + this.RegexTextBox.Multiline = true; + this.RegexTextBox.Name = "RegexTextBox"; + this.RegexTextBox.Size = new System.Drawing.Size(776, 96); + this.RegexTextBox.TabIndex = 3; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(13, 104); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(111, 20); + this.label3.TabIndex = 4; + this.label3.Text = "Pattern Name:"; + // + // NameTextBox + // + this.NameTextBox.Location = new System.Drawing.Point(13, 134); + this.NameTextBox.Name = "NameTextBox"; + this.NameTextBox.Size = new System.Drawing.Size(182, 26); + this.NameTextBox.TabIndex = 5; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(13, 306); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(361, 20); + this.label4.TabIndex = 6; + this.label4.Text = "Example Text (I.E. What the Pattern Matches On):"; + // + // ExampleTextBox + // + this.ExampleTextBox.Location = new System.Drawing.Point(13, 336); + this.ExampleTextBox.Name = "ExampleTextBox"; + this.ExampleTextBox.Size = new System.Drawing.Size(357, 26); + this.ExampleTextBox.TabIndex = 7; + // + // AddUpdateButton + // + this.AddUpdateButton.Enabled = false; + this.AddUpdateButton.Location = new System.Drawing.Point(612, 388); + this.AddUpdateButton.Name = "AddUpdateButton"; + this.AddUpdateButton.Size = new System.Drawing.Size(173, 47); + this.AddUpdateButton.TabIndex = 8; + this.AddUpdateButton.Text = "Insert New Pattern"; + this.AddUpdateButton.UseVisualStyleBackColor = true; + // + // PatternIdLabel + // + this.PatternIdLabel.AutoSize = true; + this.PatternIdLabel.Location = new System.Drawing.Point(13, 74); + this.PatternIdLabel.Name = "PatternIdLabel"; + this.PatternIdLabel.Size = new System.Drawing.Size(116, 20); + this.PatternIdLabel.TabIndex = 9; + this.PatternIdLabel.Text = "Pattern ID: N/A"; + // + // DeleteButton + // + this.DeleteButton.Enabled = false; + this.DeleteButton.Location = new System.Drawing.Point(13, 388); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(107, 47); + this.DeleteButton.TabIndex = 10; + this.DeleteButton.Text = "Delete"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // RegexResultsTextBox + // + this.RegexResultsTextBox.Location = new System.Drawing.Point(220, 9); + this.RegexResultsTextBox.Multiline = true; + this.RegexResultsTextBox.Name = "RegexResultsTextBox"; + this.RegexResultsTextBox.ReadOnly = true; + this.RegexResultsTextBox.Size = new System.Drawing.Size(565, 181); + this.RegexResultsTextBox.TabIndex = 11; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(405, 306); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(94, 20); + this.label5.TabIndex = 12; + this.label5.Text = "Regex Test:"; + // + // RegexTestTextBox + // + this.RegexTestTextBox.Location = new System.Drawing.Point(505, 303); + this.RegexTestTextBox.Name = "RegexTestTextBox"; + this.RegexTestTextBox.Size = new System.Drawing.Size(280, 26); + this.RegexTestTextBox.TabIndex = 13; + // + // TestRegexButton + // + this.TestRegexButton.Location = new System.Drawing.Point(681, 335); + this.TestRegexButton.Name = "TestRegexButton"; + this.TestRegexButton.Size = new System.Drawing.Size(104, 37); + this.TestRegexButton.TabIndex = 14; + this.TestRegexButton.Text = "Test"; + this.TestRegexButton.UseVisualStyleBackColor = true; + this.TestRegexButton.Click += new System.EventHandler(this.TestRegexButton_Click); + // + // NamingConventionManager + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.MainLayoutPanel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "NamingConventionManager"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Manage Naming Convention Patterns"; + this.MainLayoutPanel.ResumeLayout(false); + this.MainPanel.ResumeLayout(false); + this.MainPanel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel MainLayoutPanel; + private System.Windows.Forms.Panel MainPanel; + private System.Windows.Forms.ComboBox NamingConventionPatternsComboBox; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox RegexTextBox; + private System.Windows.Forms.TextBox NameTextBox; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox ExampleTextBox; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button AddUpdateButton; + private System.Windows.Forms.Label PatternIdLabel; + private System.Windows.Forms.Button DeleteButton; + private System.Windows.Forms.TextBox RegexResultsTextBox; + private System.Windows.Forms.Button TestRegexButton; + private System.Windows.Forms.TextBox RegexTestTextBox; + private System.Windows.Forms.Label label5; + } +} \ No newline at end of file diff --git a/DataOrganizer/NamingConventionManager.cs b/DataOrganizer/NamingConventionManager.cs new file mode 100644 index 0000000..1a0fce7 --- /dev/null +++ b/DataOrganizer/NamingConventionManager.cs @@ -0,0 +1,133 @@ +using System; +using System.Windows.Forms; +using System.Text.RegularExpressions; + +namespace DataOrganizer +{ + public partial class NamingConventionManager : Form + { + private int ActivePatternId { get; set; } + + public NamingConventionManager() + { + InitializeComponent(); + + var db = new DB(); + NamingConventionPatternsComboBox.Items.Add("Add New Pattern"); + NamingConventionPatternsComboBox.SelectedIndex = 0; + + foreach(var pattern in db.GetNamingConventions()) + { + NamingConventionPatternsComboBox.Items.Add(pattern.Name); + } + + NamingConventionPatternsComboBox.SelectedIndexChanged += NamingConventionPatternsComboBox_SelectedIndexChanged; + NameTextBox.TextChanged += TextChanged; + RegexTextBox.TextChanged += TextChanged; + ExampleTextBox.TextChanged += TextChanged; + RegexTestTextBox.TextChanged += RegexTestTextBox_TextChanged; + ActivePatternId = 0; + } + + private void RegexTestTextBox_TextChanged(object sender, EventArgs e) + { + if (RegexTestTextBox.Text.Length > 0 && RegexTextBox.Text.Length > 0) TestRegexButton.Enabled = true; + else TestRegexButton.Enabled = false; + } + + private new void TextChanged(object sender, EventArgs e) + { + if (RegexTestTextBox.Text.Length > 0 && RegexTextBox.Text.Length > 0) TestRegexButton.Enabled = true; + else TestRegexButton.Enabled = false; + + if (NameTextBox.Text.Length > 0 && RegexTextBox.Text.Length > 0 && ExampleTextBox.Text.Length > 0) + { + AddUpdateButton.Enabled = true; + } + else + { + AddUpdateButton.Enabled = false; + } + } + + private void NamingConventionPatternsComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + if (NamingConventionPatternsComboBox.SelectedIndex == 0) + { + ClearForm(); + return; + } + else AddUpdateButton.Text = $"Update Convention"; + + var db = new DB(); + var convention = db.GetNamingConventionByName(NamingConventionPatternsComboBox.Text); + + NameTextBox.Text = convention.Name; + RegexTextBox.Text = convention.Regex; + ExampleTextBox.Text = convention.ExampleText; + ActivePatternId = convention.Id; + + PatternIdLabel.Text = $"Pattern ID: {ActivePatternId}"; + DeleteButton.Enabled = true; + } + + private void ClearForm() + { + NameTextBox.Text = string.Empty; + RegexTextBox.Text = string.Empty; + ExampleTextBox.Text = string.Empty; + ActivePatternId = 0; + AddUpdateButton.Enabled = false; + AddUpdateButton.Text = "Insert Pattern"; + PatternIdLabel.Text = "Pattern ID: N/A"; + DeleteButton.Enabled = false; + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + var result = MessageBox.Show($"Are you sure you want to delete the '{NamingConventionPatternsComboBox.Text}'? This will reset all folder groups and files that use this pattern to 'None'.", + $"Delete '{NamingConventionPatternsComboBox.Text}'", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); + + if(result == DialogResult.Yes) + { + var db = new DB(); + db.DeleteNamingConvention(ActivePatternId); + + NamingConventionPatternsComboBox.SelectedIndex = 0; + } + } + + private void TestRegexButton_Click(object sender, EventArgs e) + { + try + { + var regex = new Regex(RegexTextBox.Text); + var testString = RegexTestTextBox.Text; + + var match = regex.Match(testString); + + if (!match.Success) + { + RegexResultsTextBox.Text = $"Input: {testString}{Environment.NewLine}No matches found."; + return; + } + + RegexResultsTextBox.Text = string.Empty; + + foreach (Group m in match.Groups) + { + if(m.Name == "0") + { + RegexResultsTextBox.Text += $"Input: {m.Value}{Environment.NewLine}"; + continue; + } + RegexResultsTextBox.Text += $"{m.Name}: {m.Value}{Environment.NewLine}"; + } + } + catch(Exception ex) + { + RegexResultsTextBox.Text = $"Error:{Environment.NewLine}{ex.Message}"; + } + } + } +} diff --git a/DataOrganizer/NamingConventionManager.resx b/DataOrganizer/NamingConventionManager.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DataOrganizer/NamingConventionManager.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file