// Adds Candidate Part to Associated Parts List private void EditedAssociationAdder_Click(object sender, RoutedEventArgs e) {// Fix Me for (int i = 0; i < EditCandidateData.Rows.Count; i++) { if ((bool)EditCandidateData.Rows[i].ItemArray[0] == true) { src.Part.BasePart TemplateAssociation_e = new src.Part.BasePart(); TemplateAssociation_e.basePartID = (int)EditCandidateData.Rows[i].ItemArray[1]; TemplateAssociation_e.basePartName = (string)EditCandidateData.Rows[i].ItemArray[2]; TemplateAssociation_e.basePartPrice = (decimal)EditCandidateData.Rows[i].ItemArray[3]; TemplateAssociation_e.basePartQty = (int)EditCandidateData.Rows[i].ItemArray[4]; TemplateAssociation_e.basePartMin = (int)EditCandidateData.Rows[i].ItemArray[5]; TemplateAssociation_e.basePartMax = (int)EditCandidateData.Rows[i].ItemArray[6]; DataRow addedRow = EditAssociatedData.NewRow(); addedRow[0] = false; addedRow[1] = (int)EditCandidateData.Rows[i].ItemArray[1]; addedRow[2] = (string)EditCandidateData.Rows[i].ItemArray[2]; addedRow[3] = (decimal)EditCandidateData.Rows[i].ItemArray[3]; addedRow[4] = (int)EditCandidateData.Rows[i].ItemArray[4]; addedRow[5] = (int)EditCandidateData.Rows[i].ItemArray[5]; addedRow[6] = (int)EditCandidateData.Rows[i].ItemArray[6]; EditAssociatedData.Rows.Add(addedRow); src.InHouse AddAssoc_e = new src.InHouse(TemplateAssociation_e, 99); EditWorkingProduct.AddAssociatedPart((src.Part)AddAssoc_e); Console.WriteLine("Added Part"); } } }
// Adds Candidate Part to Associated Parts List private void NewAssociationAdder_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < NewCandidateData.Rows.Count; i++) { if ((bool)NewCandidateData.Rows[i].ItemArray[0] == true) { src.Part.BasePart TemplateAssociation = new src.Part.BasePart(); TemplateAssociation.basePartID = (int)NewCandidateData.Rows[i].ItemArray[1]; TemplateAssociation.basePartName = (string)NewCandidateData.Rows[i].ItemArray[2]; TemplateAssociation.basePartPrice = (decimal)NewCandidateData.Rows[i].ItemArray[3]; TemplateAssociation.basePartQty = (int)NewCandidateData.Rows[i].ItemArray[4]; TemplateAssociation.basePartMin = (int)NewCandidateData.Rows[i].ItemArray[5]; TemplateAssociation.basePartMax = (int)NewCandidateData.Rows[i].ItemArray[6]; DataRow addedRow = NewAssociatedData.NewRow(); addedRow[0] = false; addedRow[1] = (int)NewCandidateData.Rows[i].ItemArray[1]; addedRow[2] = (string)NewCandidateData.Rows[i].ItemArray[2]; addedRow[3] = (decimal)NewCandidateData.Rows[i].ItemArray[3]; addedRow[4] = (int)NewCandidateData.Rows[i].ItemArray[4]; addedRow[5] = (int)NewCandidateData.Rows[i].ItemArray[5]; addedRow[6] = (int)NewCandidateData.Rows[i].ItemArray[6]; NewAssociatedData.Rows.Add(addedRow); src.InHouse AddAssoc = new src.InHouse(TemplateAssociation, 99); NewWorkingProduct.AddAssociatedPart((src.Part)AddAssoc); Console.WriteLine("Added Part"); } } NewAssociatedProdDataGrid.ItemsSource = NewAssociatedData.DefaultView; }
/* * Table Builder Methods */ // Builds Parts Data Table public void PrtDataBuilder() { // Creates Columns DataColumn prtId = new DataColumn("Part ID", typeof(int)); DataColumn prtName = new DataColumn("Part Name", typeof(string)); DataColumn prtPrice = new DataColumn("Part Price Per Unit", typeof(decimal)); DataColumn prtQty = new DataColumn("Quantity In Stock", typeof(int)); DataColumn prtMin = new DataColumn("Min", typeof(int)); DataColumn prtMax = new DataColumn("Max", typeof(int)); DataColumn prtMachineID = new DataColumn("Machine ID", typeof(int)); DataColumn prtCompanyName = new DataColumn("Company Name", typeof(string)); // Adds Columns to Data Table partsData.Columns.Add(new DataColumn("Selected", typeof(bool))); partsData.Columns.Add(prtId); partsData.Columns.Add(prtName); partsData.Columns.Add(prtPrice); partsData.Columns.Add(prtQty); partsData.Columns.Add(prtMin); partsData.Columns.Add(prtMax); partsData.Columns.Add(prtMachineID); partsData.Columns.Add(prtCompanyName); for (int i = 0; i < mainInventory.AllParts.Count; i++) { DataRow addedRow_init = partsData.NewRow(); src.Part initPart = mainInventory.LookupPart(i); addedRow_init[0] = false; addedRow_init[1] = initPart.partID; addedRow_init[2] = initPart.partName; addedRow_init[3] = initPart.partPrice; addedRow_init[4] = initPart.partsInStock; addedRow_init[5] = initPart.partMin; addedRow_init[6] = initPart.partMax; try { src.Outsourced conversionOS = (src.Outsourced)initPart; if (conversionOS.companyName != "") { addedRow_init[8] = conversionOS.companyName; } } catch { src.InHouse conversionIH = (src.InHouse)initPart; addedRow_init[7] = conversionIH.machineID; addedRow_init[8] = ""; } partsData.Rows.Add(addedRow_init); } partsData.DefaultView.Sort = "Part ID asc"; PrtDataGrid.ItemsSource = partsData.DefaultView; }
// Constructor public Inventory() { Part.BasePart templateIH = new Part.BasePart(); templateIH.basePartID = 1; templateIH.basePartName = "Test Part 1"; templateIH.basePartPrice = 1.45M; templateIH.basePartQty = 15; templateIH.basePartMin = 12; templateIH.basePartMax = 21; InHouse testIH = new InHouse(templateIH, 4); AllIHParts.Add(testIH); Part.BasePart templateOS = new Part.BasePart(); templateOS.basePartID = 2; templateOS.basePartName = "Test Part 2"; templateOS.basePartPrice = 4.15M; templateOS.basePartQty = 77; templateOS.basePartMin = 55; templateOS.basePartMax = 88; Outsourced testOS = new Outsourced(templateOS, "Test Company Name"); AllOSParts.Add(testOS); Product testProduct = new Product(); testProduct.productID = 1; testProduct.productName = "Test Product 1"; testProduct.productPrice = 12.55M; testProduct.productsInStock = 5; testProduct.productMin = 1; testProduct.productMax = 25; testProduct.associatedParts.Add(testIH); AllProducts.Add(testProduct); Product testProduct2 = new Product(); testProduct2.productID = 2; testProduct2.productName = "Test Product 2"; testProduct2.productPrice = 2.55M; testProduct2.productsInStock = 115; testProduct2.productMin = 105; testProduct2.productMax = 252; testProduct2.associatedParts.Add(testOS); AllProducts.Add(testProduct2); }
/* * Part Methods */ // Add New Part to Inventory public void AddPart(Part addedPart) { try { Outsourced convertOS = (Outsourced)addedPart; AllOSParts.Add(convertOS); Console.WriteLine("New Outsourced Part Added"); } catch { InHouse convertIH = (InHouse)addedPart; AllIHParts.Add(convertIH); Console.WriteLine("New In House Part Added"); } _partCount++; }
// Builds New Part and Passes to Inventory private bool NewPartBuilder() { if (AddIHSelect.IsChecked == true) { localPart = true; } else { localPart = false; } string[] inputFormTxt = { AddPartNameInput.Text, AddPartPriceInput.Text, AddPartQtyInput.Text, AddMinInput.Text, AddMaxInput.Text, AddSwitcherInput.Text }; NewPartValidator.isLocalPart = localPart; bool isValidPartInput = NewPartValidator.IsValidForm(false, inputFormTxt); if (isValidPartInput == false) { MessageBox.Show("Error Invalid Form Data"); } else { src.Part.BasePart AddedNewPart = new src.Part.BasePart(); AddedNewPart.basePartID = NewWorkingInventory.partCount + 1; AddedNewPart.basePartName = AddPartNameInput.Text; AddedNewPart.basePartPrice = Decimal.Parse(AddPartPriceInput.Text) + 0.00M; AddedNewPart.basePartQty = Int32.Parse(AddPartQtyInput.Text); AddedNewPart.basePartMin = Int32.Parse(AddMinInput.Text); AddedNewPart.basePartMax = Int32.Parse(AddMaxInput.Text); if (localPart == true) { src.InHouse addedIH = new src.InHouse(AddedNewPart, Int32.Parse(AddSwitcherInput.Text)); NewWorkingInventory.AddPart((src.Part)addedIH); } else { src.Outsourced addedOS = new src.Outsourced(AddedNewPart, AddSwitcherInput.Text); NewWorkingInventory.AddPart((src.Part)addedOS); } Console.WriteLine("Build Finished"); } return(isValidPartInput); }
/* * Button Methods */ // Save Edited Part private void SaveEditBtn_Click(object sender, RoutedEventArgs e) { bool finalLocal = false; if (EditIHInput.IsChecked == true) { finalLocal = true; } string[] inputFormTxt = { EditNameInput.Text, EditPriceInput.Text, EditQtyInput.Text, EditMinInput.Text, EditMaxInput.Text, EditSwitcherInput.Text }; EditPrtValidator.isLocalPart = finalLocal; bool isValidInput_e = EditPrtValidator.IsValidForm(false, inputFormTxt); if (isValidInput_e == false) { MessageBox.Show("Error Invalid Form Data"); } else { src.Part.BasePart EditedPart = new src.Part.BasePart(); EditedPart.basePartID = editID; EditedPart.basePartName = EditNameInput.Text; EditedPart.basePartPrice = Decimal.Parse(EditPriceInput.Text) + 0.00M; EditedPart.basePartQty = Int32.Parse(EditQtyInput.Text); EditedPart.basePartMin = Int32.Parse(EditMinInput.Text); EditedPart.basePartMax = Int32.Parse(EditMaxInput.Text); if (finalLocal == true) { src.InHouse editIH = new src.InHouse(EditedPart, Int32.Parse(EditSwitcherInput.Text)); EditWorkingInventory.UpdatePart((src.Part)editIH, editID); } else { src.Outsourced editOS = new src.Outsourced(EditedPart, EditSwitcherInput.Text); EditWorkingInventory.UpdatePart((src.Part)editOS, editID); } MainWindow EditPartSaved = new MainWindow(); EditPartSaved.mainInventory = EditWorkingInventory; EditPartSaved.Show(); Close(); } }
// Edit Existing Part public void UpdatePart(Part editedPart, int partID) { bool editComplete = false; int partIndex = 0; for (int i = 0; i < AllIHParts.Count; i++) { if (partID == AllIHParts[i].partID) { partIndex = AllIHParts.IndexOf(AllIHParts[i]); editComplete = true; } } if (editComplete == false) { for (int i = 0; i < AllOSParts.Count; i++) { if (partID == AllOSParts[i].partID) { partIndex = AllOSParts.IndexOf(AllOSParts[i]); } } AllOSParts.Remove(AllOSParts[partIndex]); editComplete = true; } else { AllIHParts.Remove(AllIHParts[partIndex]); editComplete = true; } try { InHouse updatedIH = (InHouse)editedPart; AllIHParts.Add(updatedIH); } catch { Outsourced updatedOS = (Outsourced)editedPart; AllOSParts.Add(updatedOS); } Console.WriteLine($"Edited Part: {editedPart.partID}"); }