Added support for updating category properties.

This commit is contained in:
2021-04-13 18:18:44 -05:00
parent 6838635c78
commit f014f22ecf
3 changed files with 368 additions and 8 deletions
Binary file not shown.
+218 -1
View File
@@ -41,6 +41,8 @@ namespace InventoryTest
this.NewCategoryNameTextBox = new System.Windows.Forms.TextBox(); this.NewCategoryNameTextBox = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.groupBox6 = new System.Windows.Forms.GroupBox(); this.groupBox6 = new System.Windows.Forms.GroupBox();
this.SubCategoryPropertyTypeComboBox = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.DeleteSubCategoryPropertyButton = new System.Windows.Forms.Button(); this.DeleteSubCategoryPropertyButton = new System.Windows.Forms.Button();
this.CreateSubCategoryButton = new System.Windows.Forms.Button(); this.CreateSubCategoryButton = new System.Windows.Forms.Button();
this.SubCategoryPropertyNameTextBox = new System.Windows.Forms.TextBox(); this.SubCategoryPropertyNameTextBox = new System.Windows.Forms.TextBox();
@@ -57,10 +59,25 @@ namespace InventoryTest
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox();
this.CategoryPropertiesListBox = new System.Windows.Forms.ListBox(); this.CategoryPropertiesListBox = new System.Windows.Forms.ListBox();
this.groupBox5 = new System.Windows.Forms.GroupBox(); this.groupBox5 = new System.Windows.Forms.GroupBox();
this.CategoryPropertyTypeComboBox = new System.Windows.Forms.ComboBox();
this.label7 = new System.Windows.Forms.Label();
this.DeleteCategoryPropertyButton = new System.Windows.Forms.Button(); this.DeleteCategoryPropertyButton = new System.Windows.Forms.Button();
this.CategoryPropertyNameTextBox = new System.Windows.Forms.TextBox(); this.CategoryPropertyNameTextBox = new System.Windows.Forms.TextBox();
this.CreateCategoryPropertyButton = new System.Windows.Forms.Button(); this.CreateCategoryPropertyButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.groupBox8 = new System.Windows.Forms.GroupBox();
this.CategoryPropertyInfoUpdateButton = new System.Windows.Forms.Button();
this.CategoryPropertyInfoTypeComboBox = new System.Windows.Forms.ComboBox();
this.label9 = new System.Windows.Forms.Label();
this.CategoryPropertyInfoNameTextBox = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.CategoryPropertyIdLabel = new System.Windows.Forms.Label();
this.groupBox9 = new System.Windows.Forms.GroupBox();
this.SubCategoryPropertyInfoUpdateButton = new System.Windows.Forms.Button();
this.label11 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.SubCategoryPropertyInfoNameTextBox = new System.Windows.Forms.TextBox();
this.SubCategoryTypeInfoComboBox = new System.Windows.Forms.ComboBox();
this.MainLayoutPanel.SuspendLayout(); this.MainLayoutPanel.SuspendLayout();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
@@ -70,6 +87,8 @@ namespace InventoryTest
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout(); this.groupBox3.SuspendLayout();
this.groupBox5.SuspendLayout(); this.groupBox5.SuspendLayout();
this.groupBox8.SuspendLayout();
this.groupBox9.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// MainLayoutPanel // MainLayoutPanel
@@ -131,6 +150,8 @@ namespace InventoryTest
this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 1); this.tableLayoutPanel1.Controls.Add(this.groupBox2, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.groupBox3, 2, 1); this.tableLayoutPanel1.Controls.Add(this.groupBox3, 2, 1);
this.tableLayoutPanel1.Controls.Add(this.groupBox5, 1, 1); this.tableLayoutPanel1.Controls.Add(this.groupBox5, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.groupBox8, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.groupBox9, 2, 3);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.Name = "tableLayoutPanel1";
@@ -196,6 +217,8 @@ namespace InventoryTest
// //
// groupBox6 // groupBox6
// //
this.groupBox6.Controls.Add(this.SubCategoryPropertyTypeComboBox);
this.groupBox6.Controls.Add(this.label6);
this.groupBox6.Controls.Add(this.DeleteSubCategoryPropertyButton); this.groupBox6.Controls.Add(this.DeleteSubCategoryPropertyButton);
this.groupBox6.Controls.Add(this.CreateSubCategoryButton); this.groupBox6.Controls.Add(this.CreateSubCategoryButton);
this.groupBox6.Controls.Add(this.SubCategoryPropertyNameTextBox); this.groupBox6.Controls.Add(this.SubCategoryPropertyNameTextBox);
@@ -208,6 +231,25 @@ namespace InventoryTest
this.groupBox6.TabStop = false; this.groupBox6.TabStop = false;
this.groupBox6.Text = "Sub-Category Property"; this.groupBox6.Text = "Sub-Category Property";
// //
// SubCategoryPropertyTypeComboBox
//
this.SubCategoryPropertyTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.SubCategoryPropertyTypeComboBox.FormattingEnabled = true;
this.SubCategoryPropertyTypeComboBox.Location = new System.Drawing.Point(47, 67);
this.SubCategoryPropertyTypeComboBox.Name = "SubCategoryPropertyTypeComboBox";
this.SubCategoryPropertyTypeComboBox.Size = new System.Drawing.Size(213, 23);
this.SubCategoryPropertyTypeComboBox.Sorted = true;
this.SubCategoryPropertyTypeComboBox.TabIndex = 5;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(6, 70);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(34, 15);
this.label6.TabIndex = 4;
this.label6.Text = "Type:";
//
// DeleteSubCategoryPropertyButton // DeleteSubCategoryPropertyButton
// //
this.DeleteSubCategoryPropertyButton.Enabled = false; this.DeleteSubCategoryPropertyButton.Enabled = false;
@@ -217,6 +259,7 @@ namespace InventoryTest
this.DeleteSubCategoryPropertyButton.TabIndex = 3; this.DeleteSubCategoryPropertyButton.TabIndex = 3;
this.DeleteSubCategoryPropertyButton.Text = "Delete"; this.DeleteSubCategoryPropertyButton.Text = "Delete";
this.DeleteSubCategoryPropertyButton.UseVisualStyleBackColor = true; this.DeleteSubCategoryPropertyButton.UseVisualStyleBackColor = true;
this.DeleteSubCategoryPropertyButton.Click += new System.EventHandler(this.DeleteSubCategoryPropertyButton_Click);
// //
// CreateSubCategoryButton // CreateSubCategoryButton
// //
@@ -227,7 +270,7 @@ namespace InventoryTest
this.CreateSubCategoryButton.TabIndex = 2; this.CreateSubCategoryButton.TabIndex = 2;
this.CreateSubCategoryButton.Text = "Add"; this.CreateSubCategoryButton.Text = "Add";
this.CreateSubCategoryButton.UseVisualStyleBackColor = true; this.CreateSubCategoryButton.UseVisualStyleBackColor = true;
this.CreateSubCategoryButton.Click += new System.EventHandler(this.CreateSubCategoryButton_Click); this.CreateSubCategoryButton.Click += new System.EventHandler(this.CreateSubCategoryPropertyButton_Click);
// //
// SubCategoryPropertyNameTextBox // SubCategoryPropertyNameTextBox
// //
@@ -363,6 +406,8 @@ namespace InventoryTest
// //
// groupBox5 // groupBox5
// //
this.groupBox5.Controls.Add(this.CategoryPropertyTypeComboBox);
this.groupBox5.Controls.Add(this.label7);
this.groupBox5.Controls.Add(this.DeleteCategoryPropertyButton); this.groupBox5.Controls.Add(this.DeleteCategoryPropertyButton);
this.groupBox5.Controls.Add(this.CategoryPropertyNameTextBox); this.groupBox5.Controls.Add(this.CategoryPropertyNameTextBox);
this.groupBox5.Controls.Add(this.CreateCategoryPropertyButton); this.groupBox5.Controls.Add(this.CreateCategoryPropertyButton);
@@ -375,6 +420,25 @@ namespace InventoryTest
this.groupBox5.TabStop = false; this.groupBox5.TabStop = false;
this.groupBox5.Text = "Category Property"; this.groupBox5.Text = "Category Property";
// //
// CategoryPropertyTypeComboBox
//
this.CategoryPropertyTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CategoryPropertyTypeComboBox.FormattingEnabled = true;
this.CategoryPropertyTypeComboBox.Location = new System.Drawing.Point(47, 70);
this.CategoryPropertyTypeComboBox.Name = "CategoryPropertyTypeComboBox";
this.CategoryPropertyTypeComboBox.Size = new System.Drawing.Size(213, 23);
this.CategoryPropertyTypeComboBox.Sorted = true;
this.CategoryPropertyTypeComboBox.TabIndex = 8;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(6, 73);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(34, 15);
this.label7.TabIndex = 7;
this.label7.Text = "Type:";
//
// DeleteCategoryPropertyButton // DeleteCategoryPropertyButton
// //
this.DeleteCategoryPropertyButton.Enabled = false; this.DeleteCategoryPropertyButton.Enabled = false;
@@ -413,6 +477,138 @@ namespace InventoryTest
this.label3.TabIndex = 0; this.label3.TabIndex = 0;
this.label3.Text = "Property Name:"; this.label3.Text = "Property Name:";
// //
// groupBox8
//
this.groupBox8.Controls.Add(this.CategoryPropertyInfoUpdateButton);
this.groupBox8.Controls.Add(this.CategoryPropertyInfoTypeComboBox);
this.groupBox8.Controls.Add(this.label9);
this.groupBox8.Controls.Add(this.CategoryPropertyInfoNameTextBox);
this.groupBox8.Controls.Add(this.label8);
this.groupBox8.Controls.Add(this.CategoryPropertyIdLabel);
this.groupBox8.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox8.Location = new System.Drawing.Point(267, 312);
this.groupBox8.Name = "groupBox8";
this.groupBox8.Size = new System.Drawing.Size(266, 135);
this.groupBox8.TabIndex = 7;
this.groupBox8.TabStop = false;
this.groupBox8.Text = "Category Property Info";
//
// CategoryPropertyInfoUpdateButton
//
this.CategoryPropertyInfoUpdateButton.Enabled = false;
this.CategoryPropertyInfoUpdateButton.Location = new System.Drawing.Point(185, 106);
this.CategoryPropertyInfoUpdateButton.Name = "CategoryPropertyInfoUpdateButton";
this.CategoryPropertyInfoUpdateButton.Size = new System.Drawing.Size(75, 23);
this.CategoryPropertyInfoUpdateButton.TabIndex = 5;
this.CategoryPropertyInfoUpdateButton.Text = "Update";
this.CategoryPropertyInfoUpdateButton.UseVisualStyleBackColor = true;
this.CategoryPropertyInfoUpdateButton.Click += new System.EventHandler(this.CategoryPropertyInfoUpdateButton_Click);
//
// CategoryPropertyInfoTypeComboBox
//
this.CategoryPropertyInfoTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CategoryPropertyInfoTypeComboBox.FormattingEnabled = true;
this.CategoryPropertyInfoTypeComboBox.Location = new System.Drawing.Point(54, 71);
this.CategoryPropertyInfoTypeComboBox.Name = "CategoryPropertyInfoTypeComboBox";
this.CategoryPropertyInfoTypeComboBox.Size = new System.Drawing.Size(206, 23);
this.CategoryPropertyInfoTypeComboBox.Sorted = true;
this.CategoryPropertyInfoTypeComboBox.TabIndex = 4;
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(6, 74);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(34, 15);
this.label9.TabIndex = 3;
this.label9.Text = "Type:";
//
// CategoryPropertyInfoNameTextBox
//
this.CategoryPropertyInfoNameTextBox.Location = new System.Drawing.Point(54, 40);
this.CategoryPropertyInfoNameTextBox.Name = "CategoryPropertyInfoNameTextBox";
this.CategoryPropertyInfoNameTextBox.Size = new System.Drawing.Size(206, 23);
this.CategoryPropertyInfoNameTextBox.TabIndex = 2;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(6, 43);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(42, 15);
this.label8.TabIndex = 1;
this.label8.Text = "Name:";
//
// CategoryPropertyIdLabel
//
this.CategoryPropertyIdLabel.AutoSize = true;
this.CategoryPropertyIdLabel.Location = new System.Drawing.Point(6, 19);
this.CategoryPropertyIdLabel.Name = "CategoryPropertyIdLabel";
this.CategoryPropertyIdLabel.Size = new System.Drawing.Size(21, 15);
this.CategoryPropertyIdLabel.TabIndex = 0;
this.CategoryPropertyIdLabel.Text = "ID:";
//
// groupBox9
//
this.groupBox9.Controls.Add(this.SubCategoryPropertyInfoUpdateButton);
this.groupBox9.Controls.Add(this.label11);
this.groupBox9.Controls.Add(this.label10);
this.groupBox9.Controls.Add(this.SubCategoryPropertyInfoNameTextBox);
this.groupBox9.Controls.Add(this.SubCategoryTypeInfoComboBox);
this.groupBox9.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox9.Location = new System.Drawing.Point(539, 312);
this.groupBox9.Name = "groupBox9";
this.groupBox9.Size = new System.Drawing.Size(258, 135);
this.groupBox9.TabIndex = 8;
this.groupBox9.TabStop = false;
this.groupBox9.Text = "Sub Category Property Info";
//
// SubCategoryPropertyInfoUpdateButton
//
this.SubCategoryPropertyInfoUpdateButton.Enabled = false;
this.SubCategoryPropertyInfoUpdateButton.Location = new System.Drawing.Point(177, 106);
this.SubCategoryPropertyInfoUpdateButton.Name = "SubCategoryPropertyInfoUpdateButton";
this.SubCategoryPropertyInfoUpdateButton.Size = new System.Drawing.Size(75, 23);
this.SubCategoryPropertyInfoUpdateButton.TabIndex = 9;
this.SubCategoryPropertyInfoUpdateButton.Text = "Update";
this.SubCategoryPropertyInfoUpdateButton.UseVisualStyleBackColor = true;
this.SubCategoryPropertyInfoUpdateButton.Click += new System.EventHandler(this.SubCategoryPropertyInfoUpdateButton_Click);
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(3, 74);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(34, 15);
this.label11.TabIndex = 8;
this.label11.Text = "Type:";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(0, 43);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(42, 15);
this.label10.TabIndex = 7;
this.label10.Text = "Name:";
//
// SubCategoryPropertyInfoNameTextBox
//
this.SubCategoryPropertyInfoNameTextBox.Location = new System.Drawing.Point(46, 40);
this.SubCategoryPropertyInfoNameTextBox.Name = "SubCategoryPropertyInfoNameTextBox";
this.SubCategoryPropertyInfoNameTextBox.Size = new System.Drawing.Size(203, 23);
this.SubCategoryPropertyInfoNameTextBox.TabIndex = 6;
//
// SubCategoryTypeInfoComboBox
//
this.SubCategoryTypeInfoComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.SubCategoryTypeInfoComboBox.FormattingEnabled = true;
this.SubCategoryTypeInfoComboBox.Location = new System.Drawing.Point(46, 71);
this.SubCategoryTypeInfoComboBox.Name = "SubCategoryTypeInfoComboBox";
this.SubCategoryTypeInfoComboBox.Size = new System.Drawing.Size(206, 23);
this.SubCategoryTypeInfoComboBox.Sorted = true;
this.SubCategoryTypeInfoComboBox.TabIndex = 5;
//
// CategoryManager // CategoryManager
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -435,6 +631,10 @@ namespace InventoryTest
this.groupBox3.ResumeLayout(false); this.groupBox3.ResumeLayout(false);
this.groupBox5.ResumeLayout(false); this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout(); this.groupBox5.PerformLayout();
this.groupBox8.ResumeLayout(false);
this.groupBox8.PerformLayout();
this.groupBox9.ResumeLayout(false);
this.groupBox9.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -473,5 +673,22 @@ namespace InventoryTest
private System.Windows.Forms.Button DeleteCategoryButton; private System.Windows.Forms.Button DeleteCategoryButton;
private System.Windows.Forms.Button DeleteSubCategoryPropertyButton; private System.Windows.Forms.Button DeleteSubCategoryPropertyButton;
private System.Windows.Forms.Button DeleteCategoryPropertyButton; private System.Windows.Forms.Button DeleteCategoryPropertyButton;
private System.Windows.Forms.ComboBox SubCategoryPropertyTypeComboBox;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.ComboBox CategoryPropertyTypeComboBox;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.GroupBox groupBox8;
private System.Windows.Forms.ComboBox CategoryPropertyInfoTypeComboBox;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox CategoryPropertyInfoNameTextBox;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label CategoryPropertyIdLabel;
private System.Windows.Forms.GroupBox groupBox9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox SubCategoryPropertyInfoNameTextBox;
private System.Windows.Forms.ComboBox SubCategoryTypeInfoComboBox;
private System.Windows.Forms.Button CategoryPropertyInfoUpdateButton;
private System.Windows.Forms.Button SubCategoryPropertyInfoUpdateButton;
} }
} }
+150 -7
View File
@@ -13,9 +13,12 @@ namespace InventoryTest
{ {
public partial class CategoryManager : Form public partial class CategoryManager : Form
{ {
private static string ConnectionString { get; set; } private string ConnectionString { get; set; }
private static Dictionary<string, int> CategoryIds { get; } = new(); private Dictionary<string, int> CategoryIds { get; } = new();
private static Dictionary<string, int> SubCategoryIds { get; } = new(); private Dictionary<string, int> SubCategoryIds { get; } = new();
private Dictionary<string, Property> CategoryPropertyIds { get; } = new();
private Dictionary<string, Property> SubCategoryPropertyIds { get; } = new();
private Dictionary<string, int> PropertyTypeIds { get; } = new();
public CategoryManager(string connectionString) public CategoryManager(string connectionString)
{ {
@@ -30,18 +33,62 @@ namespace InventoryTest
NewCategoryNameTextBox.TextChanged += NewCategoryNameTextBox_TextChanged; NewCategoryNameTextBox.TextChanged += NewCategoryNameTextBox_TextChanged;
CategoryPropertiesListBox.SelectedIndexChanged += CategoryPropertiesListBox_SelectedIndexChanged; CategoryPropertiesListBox.SelectedIndexChanged += CategoryPropertiesListBox_SelectedIndexChanged;
SubCategoryPropertiesListBox.SelectedIndexChanged += SubCategoryPropertiesListBox_SelectedIndexChanged; SubCategoryPropertiesListBox.SelectedIndexChanged += SubCategoryPropertiesListBox_SelectedIndexChanged;
CategoryPropertyInfoNameTextBox.TextChanged += CategoryPropertyInfoNameTextBox_TextChanged;
SubCategoryPropertyInfoNameTextBox.TextChanged += SubCategoryPropertyInfoNameTextBox_TextChanged;
LoadPropertyTypes();
LoadCategories(); LoadCategories();
} }
private void SubCategoryPropertyInfoNameTextBox_TextChanged(object sender, EventArgs e)
{
SubCategoryPropertyInfoUpdateButton.Enabled = SubCategoryPropertyInfoNameTextBox.TextLength > 0 && (SubCategoryPropertiesListBox.SelectedIndex != -1 && SubCategoryPropertiesListBox.SelectedItem.ToString() != SubCategoryPropertyInfoNameTextBox.Text.Trim());
}
private void CategoryPropertyInfoNameTextBox_TextChanged(object sender, EventArgs e)
{
CategoryPropertyInfoUpdateButton.Enabled = CategoryPropertyInfoNameTextBox.TextLength > 0 && (CategoryPropertiesListBox.SelectedIndex != -1 && CategoryPropertiesListBox.SelectedItem.ToString() != CategoryPropertyInfoNameTextBox.Text.Trim()); ;
}
private void LoadPropertyTypes()
{
using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("SELECT * FROM dbo.GetPropertyTypes()", connection);
connection.Open();
var reader = command.ExecuteReader();
while (reader.Read())
{
CategoryPropertyTypeComboBox.Items.Add(reader["Property Type"]);
CategoryPropertyInfoTypeComboBox.Items.Add(reader["Property type"]);
SubCategoryPropertyTypeComboBox.Items.Add(reader["Property Type"]);
SubCategoryTypeInfoComboBox.Items.Add(reader["Property Type"]);
PropertyTypeIds.Add(reader["Property Type"].ToString(), Convert.ToInt32(reader["Property Type ID"]));
}
CategoryPropertyTypeComboBox.SelectedIndex = CategoryPropertyInfoTypeComboBox.SelectedIndex = SubCategoryPropertyTypeComboBox.SelectedIndex = SubCategoryTypeInfoComboBox.SelectedIndex = 3;
}
private void SubCategoryPropertiesListBox_SelectedIndexChanged(object sender, EventArgs e) private void SubCategoryPropertiesListBox_SelectedIndexChanged(object sender, EventArgs e)
{ {
DeleteSubCategoryPropertyButton.Enabled = SubCategoryPropertiesListBox.SelectedIndex >= 0; DeleteSubCategoryPropertyButton.Enabled = SubCategoryPropertiesListBox.SelectedIndex >= 0;
SubCategoryPropertyInfoNameTextBox.Enabled = SubCategoryPropertiesListBox.SelectedIndex >= 0;
SubCategoryTypeInfoComboBox.Enabled = SubCategoryPropertiesListBox.SelectedIndex >= 0;
if (SubCategoryPropertyInfoNameTextBox.Enabled) SubCategoryPropertyInfoNameTextBox.Text = SubCategoryPropertiesListBox.SelectedItem.ToString();
else SubCategoryPropertyInfoNameTextBox.Text = string.Empty;
} }
private void CategoryPropertiesListBox_SelectedIndexChanged(object sender, EventArgs e) private void CategoryPropertiesListBox_SelectedIndexChanged(object sender, EventArgs e)
{ {
DeleteCategoryPropertyButton.Enabled = CategoryPropertiesListBox.SelectedIndex >= 0; DeleteCategoryPropertyButton.Enabled = CategoryPropertiesListBox.SelectedIndex >= 0;
CategoryPropertyInfoNameTextBox.Enabled = CategoryPropertiesListBox.SelectedIndex >= 0;
CategoryPropertyInfoTypeComboBox.Enabled = CategoryPropertiesListBox.SelectedIndex >= 0;
if (CategoryPropertyInfoNameTextBox.Enabled) CategoryPropertyInfoNameTextBox.Text = CategoryPropertiesListBox.SelectedItem.ToString();
else CategoryPropertyInfoNameTextBox.Text = string.Empty;
} }
private void NewCategoryNameTextBox_TextChanged(object sender, EventArgs e) private void NewCategoryNameTextBox_TextChanged(object sender, EventArgs e)
@@ -57,7 +104,7 @@ namespace InventoryTest
private void CategoryPropertyNameTextBox_TextChanged(object sender, EventArgs e) private void CategoryPropertyNameTextBox_TextChanged(object sender, EventArgs e)
{ {
CreateCategoryPropertyButton.Enabled = !string.IsNullOrEmpty(CategoryPropertyNameTextBox.Text); CreateCategoryPropertyButton.Enabled = CategoryComboBoxManager.Items.Count > 0 && !string.IsNullOrEmpty(CategoryPropertyNameTextBox.Text);
} }
private void SubCategoryComboBoxManager_SelectedIndexChanged(object sender, EventArgs e) private void SubCategoryComboBoxManager_SelectedIndexChanged(object sender, EventArgs e)
@@ -74,6 +121,7 @@ namespace InventoryTest
DeleteSubCategoryPropertyButton.Enabled = false; DeleteSubCategoryPropertyButton.Enabled = false;
var id = CategoryIds[CategoryComboBoxManager.Text]; var id = CategoryIds[CategoryComboBoxManager.Text];
SubCategoryIds.Clear(); SubCategoryIds.Clear();
SubCategoryPropertyIds.Clear();
using var connection = new SqlConnection(ConnectionString); using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("SELECT * FROM dbo.GetCategorySubCategories(@ID)", connection); using var command = new SqlCommand("SELECT * FROM dbo.GetCategorySubCategories(@ID)", connection);
@@ -138,6 +186,7 @@ namespace InventoryTest
private void LoadCategoryProperties() private void LoadCategoryProperties()
{ {
CategoryPropertiesListBox.Items.Clear(); CategoryPropertiesListBox.Items.Clear();
CategoryPropertyIds.Clear();
using var connection = new SqlConnection(ConnectionString); using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("SELECT * FROM GetCategoryProperties(@CategoryID)", connection); using var command = new SqlCommand("SELECT * FROM GetCategoryProperties(@CategoryID)", connection);
@@ -148,12 +197,23 @@ namespace InventoryTest
var reader = command.ExecuteReader(); var reader = command.ExecuteReader();
while (reader.Read()) while (reader.Read())
{
CategoryPropertyIds.Add(reader["Name"].ToString(), new Property
{
PropertyName = reader["Name"].ToString(),
PropertyId = Convert.ToInt32(reader["Property ID"]),
CategoryPropertyId = Convert.ToInt32(reader["Category Property ID"]),
PropertyType = reader["Property Type"].ToString(),
PropertyTypeId = Convert.ToInt32(reader["Property Type ID"])
});
CategoryPropertiesListBox.Items.Add(reader["Name"]); CategoryPropertiesListBox.Items.Add(reader["Name"]);
}
} }
private void LoadSubCategoryProperties() private void LoadSubCategoryProperties()
{ {
SubCategoryPropertiesListBox.Items.Clear(); SubCategoryPropertiesListBox.Items.Clear();
SubCategoryPropertyIds.Clear();
DeleteSubCategoryPropertyButton.Enabled = false; DeleteSubCategoryPropertyButton.Enabled = false;
using var connection = new SqlConnection(ConnectionString); using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("SELECT * FROM GetSubCategoryProperties(@ID)", connection); using var command = new SqlCommand("SELECT * FROM GetSubCategoryProperties(@ID)", connection);
@@ -164,25 +224,38 @@ namespace InventoryTest
var reader = command.ExecuteReader(); var reader = command.ExecuteReader();
while (reader.Read()) while (reader.Read())
{
SubCategoryPropertyIds.Add(reader["Name"].ToString(), new Property
{
PropertyName = reader["Name"].ToString(),
PropertyId = Convert.ToInt32(reader["Property ID"]),
CategoryPropertyId = Convert.ToInt32(reader["Sub Category Property ID"]),
PropertyType = reader["Property Type"].ToString(),
PropertyTypeId = Convert.ToInt32(reader["Property Type ID"])
});
SubCategoryPropertiesListBox.Items.Add(reader["Name"]); SubCategoryPropertiesListBox.Items.Add(reader["Name"]);
}
} }
private void ToggleSubCategoryProperty(bool enabled) private void ToggleSubCategoryProperty(bool enabled)
{ {
SubCategoryPropertyNameTextBox.Enabled = enabled; SubCategoryPropertyNameTextBox.Enabled = enabled;
SubCategoryPropertyTypeComboBox.Enabled = enabled;
DeleteSubCategoryButton.Enabled = enabled; DeleteSubCategoryButton.Enabled = enabled;
} }
private void ToggleCategoryProperty(bool enabled) private void ToggleCategoryProperty(bool enabled)
{ {
CategoryPropertyNameTextBox.Enabled = enabled; CategoryPropertyNameTextBox.Enabled = enabled;
CategoryPropertyTypeComboBox.Enabled = enabled;
} }
private void CreateCategoryPropertyButton_Click(object sender, EventArgs e) private void CreateCategoryPropertyButton_Click(object sender, EventArgs e)
{ {
using var connection = new SqlConnection(ConnectionString); using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("CreateCategoryPropertyByName", connection) { CommandType = CommandType.StoredProcedure }; using var command = new SqlCommand("CreateCategoryProperty", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("PropertyName", CategoryPropertyNameTextBox.Text); command.Parameters.AddWithValue("PropertyName", CategoryPropertyNameTextBox.Text);
command.Parameters.AddWithValue("PropertyTypeID", PropertyTypeIds[CategoryPropertyTypeComboBox.Text]);
command.Parameters.AddWithValue("CategoryID", CategoryIds[CategoryComboBoxManager.Text]); command.Parameters.AddWithValue("CategoryID", CategoryIds[CategoryComboBoxManager.Text]);
connection.Open(); connection.Open();
@@ -195,11 +268,12 @@ namespace InventoryTest
CategoryPropertyNameTextBox.Focus(); CategoryPropertyNameTextBox.Focus();
} }
private void CreateSubCategoryButton_Click(object sender, EventArgs e) private void CreateSubCategoryPropertyButton_Click(object sender, EventArgs e)
{ {
using var connection = new SqlConnection(ConnectionString); using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("CreateSubCategoryPropertyByName", connection) { CommandType = CommandType.StoredProcedure }; using var command = new SqlCommand("CreateSubCategoryProperty", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("PropertyName", SubCategoryPropertyNameTextBox.Text); command.Parameters.AddWithValue("PropertyName", SubCategoryPropertyNameTextBox.Text);
command.Parameters.AddWithValue("PropertyTypeID", PropertyTypeIds[SubCategoryPropertyTypeComboBox.Text]);
command.Parameters.AddWithValue("SubCategoryID", SubCategoryIds[SubCategoryComboBoxManager.Text]); command.Parameters.AddWithValue("SubCategoryID", SubCategoryIds[SubCategoryComboBoxManager.Text]);
connection.Open(); connection.Open();
@@ -216,6 +290,7 @@ namespace InventoryTest
{ {
using var connection = new SqlConnection(ConnectionString); using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("CreateCategory", connection) { CommandType = CommandType.StoredProcedure }; using var command = new SqlCommand("CreateCategory", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("PropertyTypeID", PropertyTypeIds[CategoryPropertyTypeComboBox.Text]);
command.Parameters.AddWithValue("Category", NewCategoryNameTextBox.Text); command.Parameters.AddWithValue("Category", NewCategoryNameTextBox.Text);
connection.Open(); connection.Open();
@@ -283,7 +358,75 @@ namespace InventoryTest
private void DeleteCategoryPropertyButton_Click(object sender, EventArgs e) private void DeleteCategoryPropertyButton_Click(object sender, EventArgs e)
{ {
using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("DeleteCategoryProperty", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("CategoryPropertyID", CategoryPropertyIds[CategoryPropertiesListBox.SelectedItem.ToString()].CategoryPropertyId);
connection.Open();
command.ExecuteNonQuery();
CategoryPropertyIds.Remove(CategoryPropertiesListBox.SelectedItem.ToString());
CategoryPropertiesListBox.Items.RemoveAt(CategoryPropertiesListBox.SelectedIndex);
}
private void DeleteSubCategoryPropertyButton_Click(object sender, EventArgs e)
{
using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("DeleteSubCategoryProperty", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("SubCategoryPropertyID", SubCategoryPropertyIds[SubCategoryPropertiesListBox.SelectedItem.ToString()].CategoryPropertyId);
connection.Open();
command.ExecuteNonQuery();
SubCategoryPropertyIds.Remove(SubCategoryPropertiesListBox.SelectedItem.ToString());
SubCategoryPropertiesListBox.Items.RemoveAt(SubCategoryPropertiesListBox.SelectedIndex);
}
private struct Property
{
public string PropertyName;
public int PropertyId;
public int CategoryPropertyId;
public int PropertyTypeId;
public string PropertyType;
}
private void CategoryPropertyInfoUpdateButton_Click(object sender, EventArgs e)
{
using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("UpdateProperty", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("PropertyID", CategoryPropertyIds[CategoryPropertiesListBox.SelectedItem.ToString()].PropertyId);
command.Parameters.AddWithValue("PropertyName", CategoryPropertyInfoNameTextBox.Text);
command.Parameters.AddWithValue("PropertyTypeID", PropertyTypeIds[CategoryPropertyInfoTypeComboBox.Text]);
connection.Open();
command.ExecuteNonQuery();
LoadCategoryProperties();
CategoryPropertyInfoNameTextBox.Text = string.Empty;
}
private void SubCategoryPropertyInfoUpdateButton_Click(object sender, EventArgs e)
{
using var connection = new SqlConnection(ConnectionString);
using var command = new SqlCommand("UpdateProperty", connection) { CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("PropertyID", SubCategoryPropertyIds[SubCategoryPropertiesListBox.SelectedItem.ToString()].PropertyId);
command.Parameters.AddWithValue("PropertyName", SubCategoryPropertyInfoNameTextBox.Text);
command.Parameters.AddWithValue("PropertyTypeID", PropertyTypeIds[SubCategoryTypeInfoComboBox.Text]);
connection.Open();
command.ExecuteNonQuery();
LoadSubCategoryProperties();
SubCategoryPropertyInfoNameTextBox.Text = string.Empty;
} }
} }
} }