コード例 #1
0
        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();
                        }
                    }
                }
            }
        }
コード例 #2
0
        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();
                }
            }
        }