Finalized the NamingConventionManager form, it can now insert/update and delete NamingConventions.
This commit is contained in:
Binary file not shown.
+42
-4
@@ -376,9 +376,48 @@ namespace DataOrganizer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InsertNamingConvention(string name, string regex, string exampleText)
|
||||||
|
{
|
||||||
|
var query = @"INSERT INTO main.naming_pattern (name, regex, example_text) VALUES (@Name, @Regex, @Example)";
|
||||||
|
|
||||||
|
using(var connection = new SqliteConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
using(var command = new SqliteCommand(query, connection))
|
||||||
|
{
|
||||||
|
command.Parameters.AddWithValue("Name", name);
|
||||||
|
command.Parameters.AddWithValue("Regex", regex);
|
||||||
|
command.Parameters.AddWithValue("Example", exampleText);
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateNamingConvention(int id, string name, string regex, string exampleText)
|
||||||
|
{
|
||||||
|
var query = @"UPDATE main.naming_pattern SET name = @Name, regex = @Regex, example_text = @Example WHERE pattern_id = @ID";
|
||||||
|
|
||||||
|
using (var connection = new SqliteConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
using (var command = new SqliteCommand(query, connection))
|
||||||
|
{
|
||||||
|
command.Parameters.AddWithValue("ID", id);
|
||||||
|
command.Parameters.AddWithValue("Name", name);
|
||||||
|
command.Parameters.AddWithValue("Regex", regex);
|
||||||
|
command.Parameters.AddWithValue("Example", exampleText);
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteNamingConvention(int id)
|
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";
|
var query = $"UPDATE main.file SET pattern_override_id = 0 WHERE pattern_override_id = {id}";
|
||||||
|
|
||||||
using (var connection = new SqliteConnection(ConnectionString))
|
using (var connection = new SqliteConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
@@ -387,13 +426,12 @@ namespace DataOrganizer
|
|||||||
{
|
{
|
||||||
using (var command = new SqliteCommand(query, connection, transaction))
|
using (var command = new SqliteCommand(query, connection, transaction))
|
||||||
{
|
{
|
||||||
command.Parameters.AddWithValue("ID", id);
|
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
query = @"UPDATE main.folder_root SET pattern_id = 0 WHERE pattern_id = @ID";
|
command.CommandText = $"UPDATE main.folder_root SET pattern_id = 0 WHERE pattern_id = {id}";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
query = @"DELETE FROM main.naming_pattern WHERE pattern_id = @ID";
|
command.CommandText = $"DELETE FROM main.naming_pattern WHERE pattern_id = {id}";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-6
@@ -136,7 +136,7 @@
|
|||||||
this.NameTextBox.Location = new System.Drawing.Point(13, 134);
|
this.NameTextBox.Location = new System.Drawing.Point(13, 134);
|
||||||
this.NameTextBox.Name = "NameTextBox";
|
this.NameTextBox.Name = "NameTextBox";
|
||||||
this.NameTextBox.Size = new System.Drawing.Size(182, 26);
|
this.NameTextBox.Size = new System.Drawing.Size(182, 26);
|
||||||
this.NameTextBox.TabIndex = 5;
|
this.NameTextBox.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// label4
|
// label4
|
||||||
//
|
//
|
||||||
@@ -152,7 +152,7 @@
|
|||||||
this.ExampleTextBox.Location = new System.Drawing.Point(13, 336);
|
this.ExampleTextBox.Location = new System.Drawing.Point(13, 336);
|
||||||
this.ExampleTextBox.Name = "ExampleTextBox";
|
this.ExampleTextBox.Name = "ExampleTextBox";
|
||||||
this.ExampleTextBox.Size = new System.Drawing.Size(357, 26);
|
this.ExampleTextBox.Size = new System.Drawing.Size(357, 26);
|
||||||
this.ExampleTextBox.TabIndex = 7;
|
this.ExampleTextBox.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// AddUpdateButton
|
// AddUpdateButton
|
||||||
//
|
//
|
||||||
@@ -160,9 +160,10 @@
|
|||||||
this.AddUpdateButton.Location = new System.Drawing.Point(612, 388);
|
this.AddUpdateButton.Location = new System.Drawing.Point(612, 388);
|
||||||
this.AddUpdateButton.Name = "AddUpdateButton";
|
this.AddUpdateButton.Name = "AddUpdateButton";
|
||||||
this.AddUpdateButton.Size = new System.Drawing.Size(173, 47);
|
this.AddUpdateButton.Size = new System.Drawing.Size(173, 47);
|
||||||
this.AddUpdateButton.TabIndex = 8;
|
this.AddUpdateButton.TabIndex = 7;
|
||||||
this.AddUpdateButton.Text = "Insert New Pattern";
|
this.AddUpdateButton.Text = "Insert New Pattern";
|
||||||
this.AddUpdateButton.UseVisualStyleBackColor = true;
|
this.AddUpdateButton.UseVisualStyleBackColor = true;
|
||||||
|
this.AddUpdateButton.Click += new System.EventHandler(this.AddUpdateButton_Click);
|
||||||
//
|
//
|
||||||
// PatternIdLabel
|
// PatternIdLabel
|
||||||
//
|
//
|
||||||
@@ -179,7 +180,7 @@
|
|||||||
this.DeleteButton.Location = new System.Drawing.Point(13, 388);
|
this.DeleteButton.Location = new System.Drawing.Point(13, 388);
|
||||||
this.DeleteButton.Name = "DeleteButton";
|
this.DeleteButton.Name = "DeleteButton";
|
||||||
this.DeleteButton.Size = new System.Drawing.Size(107, 47);
|
this.DeleteButton.Size = new System.Drawing.Size(107, 47);
|
||||||
this.DeleteButton.TabIndex = 10;
|
this.DeleteButton.TabIndex = 8;
|
||||||
this.DeleteButton.Text = "Delete";
|
this.DeleteButton.Text = "Delete";
|
||||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||||
@@ -192,6 +193,7 @@
|
|||||||
this.RegexResultsTextBox.ReadOnly = true;
|
this.RegexResultsTextBox.ReadOnly = true;
|
||||||
this.RegexResultsTextBox.Size = new System.Drawing.Size(565, 181);
|
this.RegexResultsTextBox.Size = new System.Drawing.Size(565, 181);
|
||||||
this.RegexResultsTextBox.TabIndex = 11;
|
this.RegexResultsTextBox.TabIndex = 11;
|
||||||
|
this.RegexResultsTextBox.TabStop = false;
|
||||||
//
|
//
|
||||||
// label5
|
// label5
|
||||||
//
|
//
|
||||||
@@ -207,14 +209,14 @@
|
|||||||
this.RegexTestTextBox.Location = new System.Drawing.Point(505, 303);
|
this.RegexTestTextBox.Location = new System.Drawing.Point(505, 303);
|
||||||
this.RegexTestTextBox.Name = "RegexTestTextBox";
|
this.RegexTestTextBox.Name = "RegexTestTextBox";
|
||||||
this.RegexTestTextBox.Size = new System.Drawing.Size(280, 26);
|
this.RegexTestTextBox.Size = new System.Drawing.Size(280, 26);
|
||||||
this.RegexTestTextBox.TabIndex = 13;
|
this.RegexTestTextBox.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// TestRegexButton
|
// TestRegexButton
|
||||||
//
|
//
|
||||||
this.TestRegexButton.Location = new System.Drawing.Point(681, 335);
|
this.TestRegexButton.Location = new System.Drawing.Point(681, 335);
|
||||||
this.TestRegexButton.Name = "TestRegexButton";
|
this.TestRegexButton.Name = "TestRegexButton";
|
||||||
this.TestRegexButton.Size = new System.Drawing.Size(104, 37);
|
this.TestRegexButton.Size = new System.Drawing.Size(104, 37);
|
||||||
this.TestRegexButton.TabIndex = 14;
|
this.TestRegexButton.TabIndex = 5;
|
||||||
this.TestRegexButton.Text = "Test";
|
this.TestRegexButton.Text = "Test";
|
||||||
this.TestRegexButton.UseVisualStyleBackColor = true;
|
this.TestRegexButton.UseVisualStyleBackColor = true;
|
||||||
this.TestRegexButton.Click += new System.EventHandler(this.TestRegexButton_Click);
|
this.TestRegexButton.Click += new System.EventHandler(this.TestRegexButton_Click);
|
||||||
|
|||||||
@@ -12,16 +12,8 @@ namespace DataOrganizer
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
var db = new DB();
|
RefreshNamingConventions();
|
||||||
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;
|
NameTextBox.TextChanged += TextChanged;
|
||||||
RegexTextBox.TextChanged += TextChanged;
|
RegexTextBox.TextChanged += TextChanged;
|
||||||
ExampleTextBox.TextChanged += TextChanged;
|
ExampleTextBox.TextChanged += TextChanged;
|
||||||
@@ -93,7 +85,9 @@ namespace DataOrganizer
|
|||||||
var db = new DB();
|
var db = new DB();
|
||||||
db.DeleteNamingConvention(ActivePatternId);
|
db.DeleteNamingConvention(ActivePatternId);
|
||||||
|
|
||||||
NamingConventionPatternsComboBox.SelectedIndex = 0;
|
ClearForm();
|
||||||
|
|
||||||
|
RefreshNamingConventions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,5 +123,39 @@ namespace DataOrganizer
|
|||||||
RegexResultsTextBox.Text = $"Error:{Environment.NewLine}{ex.Message}";
|
RegexResultsTextBox.Text = $"Error:{Environment.NewLine}{ex.Message}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddUpdateButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var db = new DB();
|
||||||
|
|
||||||
|
if(ActivePatternId == 0)
|
||||||
|
{
|
||||||
|
db.InsertNamingConvention(NameTextBox.Text, RegexTextBox.Text, ExampleTextBox.Text);
|
||||||
|
ClearForm();
|
||||||
|
RefreshNamingConventions();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
db.UpdateNamingConvention(ActivePatternId, NameTextBox.Text, RegexTextBox.Text, ExampleTextBox.Text);
|
||||||
|
PatternIdLabel.Text = $"Pattern ID: {ActivePatternId} (Updated)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshNamingConventions()
|
||||||
|
{
|
||||||
|
NamingConventionPatternsComboBox.SelectedIndexChanged -= NamingConventionPatternsComboBox_SelectedIndexChanged;
|
||||||
|
NamingConventionPatternsComboBox.Items.Clear();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user