The main form now pulls in category and sub category options for the user to select from. Removed some controls from the CategoryManager form that VS 2019 seems to have failed to clear from the designer's code.
This commit is contained in:
+111
-1
@@ -13,7 +13,12 @@ namespace InventoryTest
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private static string ConnectionString { get; } = "Server=DESKTOP-HJES64T;Database=Inventory;Integrated Security=true;";
|
||||
private string ConnectionString { get; } = "Server=DESKTOP-HJES64T;Database=Inventory;Integrated Security=true;";
|
||||
private int CommentsMaxLength { get; } = 3072;
|
||||
private int NotesMaxLength { get; } = 3072;
|
||||
private Dictionary<string, int> CategoryIds { get; } = new();
|
||||
private Dictionary<string, int> SubCategoryIds { get; } = new();
|
||||
private Dictionary<string, int> PropertyTypeIds { get; } = new();
|
||||
|
||||
public Form1()
|
||||
{
|
||||
@@ -21,6 +26,103 @@ namespace InventoryTest
|
||||
|
||||
ManageCategoriesToolStripMenuItem.Click += ShowCategoryManagerForm;
|
||||
exitToolStripMenuItem.Click += ExitToolStripMenuItem_Click;
|
||||
CorePropertyCommentTextBox.TextChanged += CorePropertyCommentTextBox_TextChanged;
|
||||
CorePropertyCommentTextBox.MaxLength = CommentsMaxLength;
|
||||
CorePropertyCommentGroupBox.Text = $"Comments (Remaing Characters: {CorePropertyCommentTextBox.MaxLength - CorePropertyCommentTextBox.TextLength})";
|
||||
CorePropertyNotesTextBox.TextChanged += CorePropertyNotesTextBox_TextChanged;
|
||||
CorePropertyNotesTextBox.MaxLength = NotesMaxLength;
|
||||
CorePropertyNotesGroupBox.Text = $"Notes (Remaing Characters: {CorePropertyNotesTextBox.MaxLength - CorePropertyNotesTextBox.TextLength})";
|
||||
CorePropertyNameTextBox.TextChanged += ToggleCreateItemButton;
|
||||
CorePropertyBoughtForTextBox.TextChanged += ToggleCreateItemButton;
|
||||
CorePropertySoldForTextBox.TextChanged += ToggleCreateItemButton;
|
||||
CorePropertyValueTextBox.TextChanged += ToggleCreateItemButton;
|
||||
|
||||
CategorySelectionComboBox.SelectedIndexChanged += CategorySelectionComboBox_SelectedIndexChanged;
|
||||
SubCategorySelectionComboBox.SelectedIndexChanged += SubCategorySelectionComboBox_SelectedIndexChanged;
|
||||
|
||||
LoadCategories();
|
||||
}
|
||||
|
||||
private void SubCategorySelectionComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void CategorySelectionComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
SubCategoryIds.Clear();
|
||||
SubCategorySelectionComboBox.Items.Clear();
|
||||
|
||||
using var connection = new SqlConnection(ConnectionString);
|
||||
using var command = new SqlCommand("SELECT ID, Name FROM dbo.GetCategorySubCategories(@ID)", connection);
|
||||
command.Parameters.AddWithValue("ID", CategoryIds[CategorySelectionComboBox.Text]);
|
||||
|
||||
connection.Open();
|
||||
|
||||
var reader = command.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
SubCategoryIds.Add(reader["Name"].ToString(), Convert.ToInt32(reader["ID"]));
|
||||
SubCategorySelectionComboBox.Items.Add(reader["Name"].ToString());
|
||||
}
|
||||
|
||||
if (SubCategorySelectionComboBox.Items.Count > 0)
|
||||
{
|
||||
SubCategorySelectionComboBox.Enabled = true;
|
||||
SubCategorySelectionComboBox.SelectedIndex = 0;
|
||||
}
|
||||
else SubCategorySelectionComboBox.Enabled = false;
|
||||
}
|
||||
|
||||
private void LoadCategories()
|
||||
{
|
||||
CategoryIds.Clear();
|
||||
|
||||
using var connection = new SqlConnection(ConnectionString);
|
||||
using var command = new SqlCommand("SELECT [Category ID], [Category Name] FROM Category", connection);
|
||||
|
||||
connection.Open();
|
||||
|
||||
var reader = command.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
CategoryIds.Add(reader["Category Name"].ToString(), Convert.ToInt32(reader["Category ID"]));
|
||||
CategorySelectionComboBox.Items.Add(reader["Category Name"]);
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
|
||||
if (CategorySelectionComboBox.Items.Count > 0)
|
||||
{
|
||||
CategorySelectionComboBox.SelectedIndex = 0;
|
||||
CorePropertyNameTextBox.Enabled = true;
|
||||
}
|
||||
else CorePropertyNameTextBox.Enabled = false;
|
||||
}
|
||||
|
||||
private void ToggleCreateItemButton(object sender, EventArgs e)
|
||||
{
|
||||
var valueValid = CorePropertyValueTextBox.Text.Trim().Length == 0;
|
||||
var boughtForValid = CorePropertyBoughtForTextBox.Text.Trim().Length == 0;
|
||||
var soldForValid = CorePropertySoldForTextBox.Text.Trim().Length == 0;
|
||||
|
||||
if (!valueValid) valueValid = decimal.TryParse(CorePropertyValueTextBox.Text, out decimal _);
|
||||
if (!boughtForValid) boughtForValid = decimal.TryParse(CorePropertyBoughtForTextBox.Text, out decimal _);
|
||||
if (!soldForValid) soldForValid = decimal.TryParse(CorePropertySoldForTextBox.Text, out decimal _);
|
||||
|
||||
CreateItemButton.Enabled = CorePropertyNameTextBox.Text.Trim().Length > 0 && valueValid && boughtForValid && soldForValid;
|
||||
}
|
||||
|
||||
private void CorePropertyNotesTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CorePropertyNotesGroupBox.Text = $"Notes (Remaing Characters: {CorePropertyNotesTextBox.MaxLength - CorePropertyNotesTextBox.TextLength})";
|
||||
}
|
||||
|
||||
private void CorePropertyCommentTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CorePropertyCommentGroupBox.Text = $"Comments (Remaing Characters: {CorePropertyCommentTextBox.MaxLength - CorePropertyCommentTextBox.TextLength})";
|
||||
}
|
||||
|
||||
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -33,5 +135,13 @@ namespace InventoryTest
|
||||
var form = new CategoryManager(ConnectionString);
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private struct ItemPropertyPairing
|
||||
{
|
||||
public int PropertyID;
|
||||
public int ItemID;
|
||||
public int PropertyTypeID;
|
||||
public string Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user