Beispiel #1
0
 public PartForm(Part partToModify)
 {
     InitializeComponent();
     partFormLabel.Text  = "Modify Part";
     this.Text           = "Modify Part";
     IDTextBox.Text      = partToModify.GetPartID().ToString();
     nameTextBox.Text    = partToModify.GetName();
     inStockTextBox.Text = partToModify.GetInStock().ToString();
     priceTextBox.Text   = partToModify.GetPrice().ToString();
     maxTextBox.Text     = partToModify.GetMax().ToString();
     minTextBox.Text     = partToModify.GetMin().ToString();
     if (partToModify.GetType() == typeof(InHouse))
     {
         InHouse tempPart = partToModify as InHouse;
         inHouseRadio.Checked = true;
         specialLabel.Text    = "Machine ID";
         specialTextBox.Text  = tempPart.GetMachineID().ToString();
     }
     else
     {
         Outsourced tempPart = partToModify as Outsourced;
         outsourcedRadio.Checked = true;
         specialLabel.Text       = "Company Name";
         specialTextBox.Text     = tempPart.GetCompanyName();
     }
 }
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            Welcome welcome = new Welcome();

            InHouse    inHouse;
            Outsourced outsourced;

            if (errorFound == false)
            {
                if (Convert.ToInt32(PartMaxText.Text) < Convert.ToInt32(PartMinText.Text))
                {
                    MessageBox.Show("Your Min Qty is greater than the Max Qty value");
                }
                else
                {
                    if (InHouseRadio.Checked)
                    {
                        inHouse = new InHouse();

                        inHouse.setName(PartNameText.Text);
                        inHouse.setPartPrice(Convert.ToDouble(PartPriceText.Text));
                        inHouse.setInStock(Convert.ToInt32(PartInvText.Text));
                        inHouse.setPartQtyMin(Convert.ToInt32(PartMinText.Text));
                        inHouse.setPartQtyMax(Convert.ToInt32(PartMaxText.Text));
                        inHouse.setMachineID(Convert.ToInt32(MachineIDText.Text));

                        Inventory.addPart(inHouse);
                    }

                    else if (OutSourceRadio.Checked)
                    {
                        outsourced = new Outsourced();

                        outsourced.setPartID(Convert.ToInt32(PartIDText.Text));
                        outsourced.setName(PartNameText.Text.ToString());
                        outsourced.setPartPrice(Convert.ToDouble(PartPriceText.Text));
                        outsourced.setInStock(Convert.ToInt32(PartInvText.Text));
                        outsourced.setPartQtyMin(Convert.ToInt32(PartMinText.Text));
                        outsourced.setPartQtyMax(Convert.ToInt32(PartMaxText.Text));
                        outsourced.setCompanyName(MachineIDText.Text);

                        Inventory.addPart(outsourced);
                    }

                    this.Hide();

                    welcome.ShowDialog();
                }
            }
        }
        private void modifyPartButton_Click(object sender, EventArgs e)
        {
            int             index       = partsTable.SelectedCells[0].RowIndex;
            DataGridViewRow selectedRow = partsTable.Rows[index];
            int             partID      = int.Parse(Convert.ToString(selectedRow.Cells[0].Value));

            for (int i = 0; i < currentInventory.GetPartList().Count; i++)
            {
                Part part = currentInventory.GetPartList()[i] as Part;
                if (part.GetPartID() == partID)
                {
                    PartForm modifyPartForm = new PartForm(part);
                    if (modifyPartForm.ShowDialog(this) == DialogResult.OK)
                    {
                        if (modifyPartForm.NewPartType == PartForm.PartType.InHouse)
                        {
                            InHouse newPart = new InHouse();
                            newPart.SetPartID(partID);
                            newPart.SetName(modifyPartForm.NewName);
                            newPart.SetInStock(modifyPartForm.NewInStock);
                            newPart.SetPrice(modifyPartForm.NewPrice);
                            newPart.SetMax(modifyPartForm.NewMax);
                            newPart.SetMin(modifyPartForm.NewMin);
                            newPart.SetMachineID(int.Parse(modifyPartForm.NewSpecial));
                            currentInventory.UpdatePart(partID, newPart);

                            RenderPartsToTable();
                        }
                        else
                        {
                            Outsourced newPart = new Outsourced();
                            newPart.SetPartID(partID);
                            newPart.SetName(modifyPartForm.NewName);
                            newPart.SetInStock(modifyPartForm.NewInStock);
                            newPart.SetPrice(modifyPartForm.NewPrice);
                            newPart.SetMax(modifyPartForm.NewMax);
                            newPart.SetMin(modifyPartForm.NewMin);
                            newPart.SetCompanyName(modifyPartForm.NewSpecial);
                            currentInventory.UpdatePart(partID, newPart);

                            RenderPartsToTable();
                        }
                    }
                }
            }
        }
        private void saveBtn_Click(object sender, EventArgs e)
        {
            Welcome    welcome = new Welcome();
            InHouse    inhouse;
            Outsourced outsourced;

            if (errorFound == false)
            {
                if (inHouse.Checked)
                {
                    inhouse = new InHouse();
                    inhouse.setPartID(part);
                    inhouse.setName(PartNameText.Text.ToString());
                    inhouse.setPartPrice(Convert.ToDouble(PartPriceText.Text));
                    inhouse.setInStock(Convert.ToInt32(PartInvText.Text));
                    inhouse.setPartQtyMin(Convert.ToInt32(PartMinText.Text));
                    inhouse.setPartQtyMax(Convert.ToInt32(PartMaxText.Text));
                    inhouse.setMachineID(Convert.ToInt32(MachineIDText.Text));

                    Inventory.updatePart(part, inhouse);
                }

                else if (outsource.Checked)
                {
                    outsourced = new Outsourced();
                    outsourced.setPartID(part);
                    outsourced.setName(PartNameText.Text.ToString());
                    outsourced.setPartPrice(Convert.ToDouble(PartPriceText.Text));
                    outsourced.setInStock(Convert.ToInt32(PartInvText.Text));
                    outsourced.setPartQtyMin(Convert.ToInt32(PartMinText.Text));
                    outsourced.setPartQtyMax(Convert.ToInt32(PartMaxText.Text));
                    outsourced.setCompanyName(MachineIDText.Text);

                    Inventory.updatePart(part, outsourced);
                }
            }

            this.Hide();
            welcome.ShowDialog();
        }
        private void addPartButton_Click(object sender, EventArgs e)
        {
            PartForm addPartForm = new PartForm();

            if (addPartForm.ShowDialog(this) == DialogResult.OK)
            {
                if (addPartForm.NewPartType == PartForm.PartType.InHouse)
                {
                    InHouse newPart = new InHouse();
                    newPart.SetPartID(nextPartID);
                    nextPartID++;
                    newPart.SetName(addPartForm.NewName);
                    newPart.SetInStock(addPartForm.NewInStock);
                    newPart.SetPrice(addPartForm.NewPrice);
                    newPart.SetMax(addPartForm.NewMax);
                    newPart.SetMin(addPartForm.NewMin);
                    newPart.SetMachineID(int.Parse(addPartForm.NewSpecial));
                    currentInventory.AddPart(newPart);
                    RenderPartsToTable();
                }
                else
                {
                    Outsourced newPart = new Outsourced();
                    newPart.SetPartID(nextPartID);
                    nextPartID++;
                    newPart.SetName(addPartForm.NewName);
                    newPart.SetInStock(addPartForm.NewInStock);
                    newPart.SetPrice(addPartForm.NewPrice);
                    newPart.SetMax(addPartForm.NewMax);
                    newPart.SetMin(addPartForm.NewMin);
                    newPart.SetCompanyName(addPartForm.NewSpecial);
                    currentInventory.AddPart(newPart);
                    RenderPartsToTable();
                }
            }
        }