diff --git a/C968Project/Inventory.cs b/C968Project/Inventory.cs index a3c959e..b590598 100644 --- a/C968Project/Inventory.cs +++ b/C968Project/Inventory.cs @@ -5,8 +5,8 @@ namespace C968Project; public class Inventory { - public BindingList Products { get; set; } - public BindingList Parts { get; set; } + public BindingList Products { get; set; } = new(); + public BindingList Parts { get; set; } = new(); public void AddProduct(Product product) { diff --git a/C968Project/Part.cs b/C968Project/Part.cs index e2fe568..6855a1f 100644 --- a/C968Project/Part.cs +++ b/C968Project/Part.cs @@ -8,4 +8,5 @@ public abstract class Part public int InStock { get; set; } public int Min { get; set; } public int Max { get; set; } + } \ No newline at end of file diff --git a/C968Project/Program.cs b/C968Project/Program.cs index 9207d58..fa80987 100644 --- a/C968Project/Program.cs +++ b/C968Project/Program.cs @@ -1,3 +1,4 @@ +using System.Runtime.CompilerServices; using C968Project.Views; namespace C968Project; @@ -6,6 +7,40 @@ static class Program { public static Inventory Inventory = new(); + public static int PartIdCounter = 2; + public static int ProductIdCounter = 1; + + private static Part _testInhousePart = new Inhouse() + { + Name = "Inhouse part", + Min = 0, + Max = 100, + Price = 10, + InStock = 50, + PartID = 0, + MachineID = 2 + }; + private static Part _testOutsourcedPart = new Outsourced() + { + Name = "Outsourced part", + Min = 10, + Max = 100, + Price = 5, + InStock = 21, + PartID = 1, + CompanyName = "Chem Inc." + }; + + private static Product _testProduct = new Product() + { + Name = "Product", + AssociatedParts = new(){_testInhousePart, _testOutsourcedPart}, + InStock = 500, + Max = 4000, + Min = 2, + Price = 5.45f, + ProductId = 0, + }; /// /// The main entry point for the application. @@ -13,9 +48,19 @@ static class Program [STAThread] static void Main() { + Inventory.AddPart(_testOutsourcedPart); + Inventory.AddPart(_testInhousePart); + Inventory.AddProduct(_testProduct); + // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); Application.Run(new MainScreen()); } +} + +public enum ScreenOption +{ + ADD, + MODIFY } \ No newline at end of file diff --git a/C968Project/Views/AddModifyPartScreen.Designer.cs b/C968Project/Views/AddModifyPartScreen.Designer.cs index bcee08c..5ae12f3 100644 --- a/C968Project/Views/AddModifyPartScreen.Designer.cs +++ b/C968Project/Views/AddModifyPartScreen.Designer.cs @@ -34,7 +34,7 @@ idLabel = new Label(); idTextBox = new TextBox(); nameLabel = new Label(); - textBox2 = new TextBox(); + nameTextBox = new TextBox(); inventoryLabel = new Label(); inventoryTextBox = new TextBox(); priceCostLabel = new Label(); @@ -69,6 +69,7 @@ inHouseRadioButton.TabStop = true; inHouseRadioButton.Text = "In-House"; inHouseRadioButton.UseVisualStyleBackColor = true; + inHouseRadioButton.Click += inHouseRadioButton_Click; // // outsourcedRadioButton // @@ -80,6 +81,7 @@ outsourcedRadioButton.TabStop = true; outsourcedRadioButton.Text = "Outsourced"; outsourcedRadioButton.UseVisualStyleBackColor = true; + outsourcedRadioButton.Click += outsourcedRadioButton_Click; // // idLabel // @@ -107,12 +109,12 @@ nameLabel.TabIndex = 3; nameLabel.Text = "Name"; // - // textBox2 + // nameTextBox // - textBox2.Location = new Point(234, 127); - textBox2.Name = "textBox2"; - textBox2.Size = new Size(153, 23); - textBox2.TabIndex = 4; + nameTextBox.Location = new Point(234, 127); + nameTextBox.Name = "nameTextBox"; + nameTextBox.Size = new Size(153, 23); + nameTextBox.TabIndex = 4; // // inventoryLabel // @@ -202,6 +204,7 @@ saveButton.TabIndex = 15; saveButton.Text = "Save"; saveButton.UseVisualStyleBackColor = true; + saveButton.Click += saveButton_Click; // // cancelButton // @@ -211,6 +214,7 @@ cancelButton.TabIndex = 16; cancelButton.Text = "Cancel"; cancelButton.UseVisualStyleBackColor = true; + cancelButton.Click += cancelButton_Click; // // AddModifyPartScreen // @@ -230,7 +234,7 @@ Controls.Add(inventoryLabel); Controls.Add(inventoryTextBox); Controls.Add(nameLabel); - Controls.Add(textBox2); + Controls.Add(nameTextBox); Controls.Add(idLabel); Controls.Add(idTextBox); Controls.Add(outsourcedRadioButton); @@ -252,7 +256,7 @@ private TextBox idTextBox; private Label idLabel; private Label nameLabel; - private TextBox textBox2; + private TextBox nameTextBox; private Label inventoryLabel; private TextBox inventoryTextBox; private Label priceCostLabel; diff --git a/C968Project/Views/AddModifyPartScreen.cs b/C968Project/Views/AddModifyPartScreen.cs index 3c36dac..e909937 100644 --- a/C968Project/Views/AddModifyPartScreen.cs +++ b/C968Project/Views/AddModifyPartScreen.cs @@ -12,9 +12,163 @@ namespace C968Project.Views { public partial class AddModifyPartScreen : Form { - public AddModifyPartScreen() + + private ScreenOption _screenOption; + private Part? _selectedPart = null; + private Mode _mode = Mode.INHOUSE; + + public AddModifyPartScreen(ScreenOption screenOption, Part? part = null) { InitializeComponent(); + + _screenOption = screenOption; + _selectedPart = part; + + if (screenOption == ScreenOption.ADD) + { + screenLabel.Text = "Add Part"; + ChangeMode(Mode.INHOUSE); + } + else if (screenOption == ScreenOption.MODIFY) + { + screenLabel.Text = "Modify Part"; + PopulatePartData(_selectedPart); + } + } + + private void PopulatePartData(Part part) + { + idTextBox.Text = part.PartID.ToString(); + nameTextBox.Text = part.Name; + inventoryTextBox.Text = part.InStock.ToString(); + priceCostTextBox.Text = part.Price.ToString(); + maxTextBox.Text = part.Max.ToString(); + minTextBox.Text = part.Min.ToString(); + + if (part is Outsourced op) + { + ChangeMode(Mode.OUTSOURCED); + machineCompanyTextBox.Text = op.CompanyName; + } + + if (part is Inhouse ip) + { + ChangeMode(Mode.INHOUSE); + machineCompanyTextBox.Text = ip.MachineID.ToString(); + } + + } + + private void ModifyPart() + { + int partIndex; + if (_selectedPart != null && Program.Inventory.Parts.Contains(_selectedPart)) + { + partIndex = Program.Inventory.Parts.IndexOf(_selectedPart); + } + else + { + MessageBox.Show("Error modifying part: Could not find part index", "Error", MessageBoxButtons.OK); + return; + } + + var part = Program.Inventory.Parts[partIndex]; + var partId = part.PartID; + Program.Inventory.Parts[partIndex] = CreatePart(partId); + } + + private void AddPart() + { + int newId = Program.PartIdCounter; + Program.PartIdCounter++; + + Program.Inventory.AddPart(CreatePart(newId)); + } + + private Part CreatePart(int partId) + { + Part part; + + if (_mode is Mode.INHOUSE) + { + var inhouse = new Inhouse(); + inhouse.MachineID = int.Parse(machineCompanyTextBox.Text); + part = inhouse; + } + else if (_mode is Mode.OUTSOURCED) + { + var outsourced = new Outsourced(); + outsourced.CompanyName = machineCompanyTextBox.Text; + part = outsourced; + } + else + { + throw new InvalidOperationException("No part mode selected somehow"); + } + + part.PartID = partId; + part.Name = nameTextBox.Text; + part.InStock = int.Parse(inventoryTextBox.Text); + part.Price = float.Parse(priceCostTextBox.Text); + part.Max = int.Parse(maxTextBox.Text); + part.Min = int.Parse(minTextBox.Text); + + return part; + } + + + + private void saveButton_Click(object sender, EventArgs e) + { + if (_screenOption is ScreenOption.ADD) + { + AddPart(); + } + + if (_screenOption is ScreenOption.MODIFY) + { + ModifyPart(); + } + + Close(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void inHouseRadioButton_Click(object sender, EventArgs e) + { + ChangeMode(Mode.INHOUSE); + } + + private void outsourcedRadioButton_Click(object sender, EventArgs e) + { + ChangeMode(Mode.OUTSOURCED); + } + + private void ChangeMode(Mode mode) + { + _mode = mode; + if (mode is Mode.INHOUSE) + { + outsourcedRadioButton.Checked = false; + inHouseRadioButton.Checked = true; + machineCompanyLabel.Text = "Machine ID"; + } + if (mode is Mode.OUTSOURCED) + { + inHouseRadioButton.Checked = false; + outsourcedRadioButton.Checked = true; + machineCompanyLabel.Text = "Company Name"; + } + } + + enum Mode + { + INHOUSE, + OUTSOURCED } } } diff --git a/C968Project/Views/MainScreen.Designer.cs b/C968Project/Views/MainScreen.Designer.cs index 0f9e006..7d0aea4 100644 --- a/C968Project/Views/MainScreen.Designer.cs +++ b/C968Project/Views/MainScreen.Designer.cs @@ -32,6 +32,7 @@ partial class MainScreen private void InitializeComponent() { panel1 = new Panel(); + exitButton = new Button(); productsDeleteButton = new Button(); productsModifyButton = new Button(); productsAddButton = new Button(); @@ -47,7 +48,6 @@ partial class MainScreen label2 = new Label(); mainScreenLabel = new Label(); partsDataGridView = new DataGridView(); - exitButton = new Button(); panel1.SuspendLayout(); ((ISupportInitialize)productsDataGridView).BeginInit(); ((ISupportInitialize)partsDataGridView).BeginInit(); @@ -80,6 +80,17 @@ partial class MainScreen panel1.Size = new Size(929, 450); panel1.TabIndex = 0; // + // exitButton + // + exitButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + exitButton.Location = new Point(842, 415); + exitButton.Name = "exitButton"; + exitButton.Size = new Size(75, 23); + exitButton.TabIndex = 16; + exitButton.Text = "Exit"; + exitButton.UseVisualStyleBackColor = true; + exitButton.Click += exitButton_Click; + // // productsDeleteButton // productsDeleteButton.Anchor = AnchorStyles.Right; @@ -89,6 +100,7 @@ partial class MainScreen productsDeleteButton.TabIndex = 15; productsDeleteButton.Text = "Delete"; productsDeleteButton.UseVisualStyleBackColor = true; + productsDeleteButton.Click += productsDeleteButton_Click; // // productsModifyButton // @@ -99,6 +111,7 @@ partial class MainScreen productsModifyButton.TabIndex = 14; productsModifyButton.Text = "Modify"; productsModifyButton.UseVisualStyleBackColor = true; + productsModifyButton.Click += productsModifyButton_Click; // // productsAddButton // @@ -109,6 +122,7 @@ partial class MainScreen productsAddButton.TabIndex = 13; productsAddButton.Text = "Add"; productsAddButton.UseVisualStyleBackColor = true; + productsAddButton.Click += productsAddButton_Click; // // productsSearchButton // @@ -120,6 +134,7 @@ partial class MainScreen productsSearchButton.Text = "Search"; productsSearchButton.TextImageRelation = TextImageRelation.ImageAboveText; productsSearchButton.UseVisualStyleBackColor = true; + productsSearchButton.Click += productsSearchButton_Click; // // productsSearchTextBox // @@ -157,6 +172,7 @@ partial class MainScreen partsDeleteButton.TabIndex = 8; partsDeleteButton.Text = "Delete"; partsDeleteButton.UseVisualStyleBackColor = true; + partsDeleteButton.Click += partsDeleteButton_Click; // // partsModifyButton // @@ -167,6 +183,7 @@ partial class MainScreen partsModifyButton.TabIndex = 7; partsModifyButton.Text = "Modify"; partsModifyButton.UseVisualStyleBackColor = true; + partsModifyButton.Click += partsModifyButton_Click; // // partsAddButton // @@ -177,6 +194,7 @@ partial class MainScreen partsAddButton.TabIndex = 6; partsAddButton.Text = "Add"; partsAddButton.UseVisualStyleBackColor = true; + partsAddButton.Click += partsAddButton_Click; // // partsSearchButton // @@ -188,6 +206,7 @@ partial class MainScreen partsSearchButton.Text = "Search"; partsSearchButton.TextImageRelation = TextImageRelation.ImageAboveText; partsSearchButton.UseVisualStyleBackColor = true; + partsSearchButton.Click += partsSearchButton_Click; // // partsSearchTextBox // @@ -225,16 +244,6 @@ partial class MainScreen partsDataGridView.Size = new Size(440, 162); partsDataGridView.TabIndex = 0; // - // exitButton - // - exitButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - exitButton.Location = new Point(842, 415); - exitButton.Name = "exitButton"; - exitButton.Size = new Size(75, 23); - exitButton.TabIndex = 16; - exitButton.Text = "Exit"; - exitButton.UseVisualStyleBackColor = true; - // // MainScreen // AutoScaleDimensions = new SizeF(7F, 15F); diff --git a/C968Project/Views/MainScreen.cs b/C968Project/Views/MainScreen.cs index 8ca5f03..afc8503 100644 --- a/C968Project/Views/MainScreen.cs +++ b/C968Project/Views/MainScreen.cs @@ -9,4 +9,58 @@ public partial class MainScreen : Form productsDataGridView.DataSource = Program.Inventory.Products; partsDataGridView.DataSource = Program.Inventory.Parts; } + + private void exitButton_Click(object sender, EventArgs e) + { + Application.Exit(); + } + + // --- Parts + private void partsAddButton_Click(object sender, EventArgs e) + { + AddModifyPartScreen partScreen = new AddModifyPartScreen(ScreenOption.ADD); + partScreen.Show(); + } + + private void partsModifyButton_Click(object sender, EventArgs e) + { + Part part = Program.Inventory.LookupPart(partsDataGridView.CurrentCell.RowIndex); + if (part is null) return; + AddModifyPartScreen partScreen = new AddModifyPartScreen(ScreenOption.MODIFY, part); + partScreen.Show(); + } + + private void partsDeleteButton_Click(object sender, EventArgs e) + { + Part part = Program.Inventory.LookupPart(partsDataGridView.CurrentCell.RowIndex); + Program.Inventory.DeletePart(part); + } + + private void partsSearchButton_Click(object sender, EventArgs e) + { + // TODO: Search functionality + } + + // --- Products + private void productsAddButton_Click(object sender, EventArgs e) + { + AddModifyProductScreen productScreen = new AddModifyProductScreen(); + productScreen.Show(); + } + + private void productsModifyButton_Click(object sender, EventArgs e) + { + AddModifyProductScreen productScreen = new AddModifyProductScreen(); + productScreen.Show(); + } + + private void productsDeleteButton_Click(object sender, EventArgs e) + { + + } + + private void productsSearchButton_Click(object sender, EventArgs e) + { + // TODO: Search functionality + } } \ No newline at end of file