private void addPartSaveButton_Click(object sender, EventArgs e)
        {
            Part newPart;

            if (addPartOutsourcedRadioButton.Checked)
            {
                newPart = new Outsourced();
                (newPart as Outsourced).CompanyName = addPartIdentityTextBox.Text;
            }
            else
            {
                newPart = new InHouse();
                (newPart as InHouse).MachineID = int.Parse(addPartIdentityTextBox.Text);
            }
            newPart.PartID  = int.Parse(addPartIDTextBox.Text);
            newPart.Name    = addPartNameTextBox.Text;
            newPart.Price   = decimal.Parse(addPartPriceCostTextBox.Text);
            newPart.InStock = int.Parse(addPartInventoryTextBox.Text);
            newPart.Min     = int.Parse(addPartMinTextBox.Text);
            newPart.Max     = int.Parse(addPartMaxTextBox.Text);

            if (newPart.Max < newPart.Min)
            {
                MessageBox.Show("Max must be greater than or equal to Min");
            }
            else if (!(newPart.InStock >= newPart.Min) || !(newPart.InStock <= newPart.Max))
            {
                MessageBox.Show("Inventory must fall with Min and Max.");
            }
            else
            {
                EventManager.FireAddPart(newPart);
                Close();
            }
        }
        public Inventory()
        {
            products = new BindingList <Product>();
            allParts = new BindingList <Part>();

            // If true, adds a test entry in both AllParts and Products.
            if (debug)
            {
                Outsourced newPart = new Outsourced();
                newPart.Name        = "Test";
                newPart.InStock     = 1;
                newPart.Min         = 1;
                newPart.Max         = 1;
                newPart.PartID      = 123;
                newPart.CompanyName = "Test Company";
                newPart.Price       = 10.00M;

                allParts.Add(newPart);

                Product newProduct = new Product();
                newProduct.AssociatedParts = new BindingList <Part>();
                newProduct.InStock         = 1;
                newProduct.Max             = 1;
                newProduct.Min             = 1;
                newProduct.Name            = "Test Product";
                newProduct.ProductID       = 123;
                newProduct.Price           = 10.00M;

                products.Add(newProduct);
            }
        }
Exemplo n.º 3
0
        //Use variable for current part selected
        public ModifyParts()
        {
            InitializeComponent();

            //Adds textboxes to list and disables save at load
            mpcontrols.Add(textBoxModifyID);
            mpcontrols.Add(textBoxModifyName);
            mpcontrols.Add(textBoxModifyPriceCost);
            mpcontrols.Add(textBoxModifyInventory);
            mpcontrols.Add(textBoxModifyMax);
            mpcontrols.Add(textBoxModifyMin);
            mpcontrols.Add(textBoxModifyMachineID);
            buttonModifySave.Enabled = false;


            //Delete this try/catch once program open auto select is completed.
            try
            {
                //Populates text boxes with current part information
                textBoxModifyID.Text        = currentPart.PartID.ToString();
                textBoxModifyName.Text      = currentPart.Name;
                textBoxModifyInventory.Text = currentPart.InStock.ToString();
                textBoxModifyPriceCost.Text = currentPart.Price.ToString();
                textBoxModifyMax.Text       = currentPart.Max.ToString();
                textBoxModifyMin.Text       = currentPart.Min.ToString();

                //Checks if part is inhouse/outsourced.
                //Creates temporary part that cast current part as derived type to access the derived type properties.
                if (currentPart is Inhouse)
                {
                    Inhouse tempPart = (Inhouse)currentPart;
                    textBoxModifyMachineID.Text      = tempPart.MachineID.ToString();
                    radioButtonModifyInHouse.Checked = true;
                }
                else
                {
                    Outsourced tempPart = (Outsourced)currentPart;
                    textBoxModifyMachineID.Text         = tempPart.CompanyName;
                    radioButtonModifyOutsourced.Checked = true;
                    labelModifyMacIDComNA.Text          = "Company Name";
                }
            }
            catch (NullReferenceException ex)
            {
                string            message = "Please click on a part to edit from the list./n" + ex.Message;
                string            caption = "No Part Selected";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;
                result = MessageBox.Show(message, caption, buttons);
            }
        }
Exemplo n.º 4
0
 //Checks part type, creates new part, calls fx to exchange parts.
 private void buttonModifySave_Click(object sender, EventArgs e)
 {
     if (currentPart is Inhouse)
     {
         currentPart = new Inhouse(Convert.ToInt32(textBoxModifyID.Text), textBoxModifyName.Text, Convert.ToDecimal(textBoxModifyPriceCost.Text), Convert.ToInt32(textBoxModifyInventory.Text), Convert.ToInt32(textBoxModifyMax.Text), Convert.ToInt32(textBoxModifyMin.Text), Convert.ToInt32(textBoxModifyMachineID.Text));
         Inventory.updatePart(currentModIdx, currentPart);
         this.Close();
     }
     else
     {
         currentPart = new Outsourced(Convert.ToInt32(textBoxModifyID.Text), textBoxModifyName.Text, Convert.ToDecimal(textBoxModifyPriceCost.Text), Convert.ToInt32(textBoxModifyInventory.Text), Convert.ToInt32(textBoxModifyMax.Text), Convert.ToInt32(textBoxModifyMin.Text), textBoxModifyMachineID.Text);
         Inventory.updatePart(currentModIdx, currentPart);
         this.Close();
     }
 }
Exemplo n.º 5
0
        private void addPartSave_Click(object sender, EventArgs e)
        {
            int     partID  = Int32.Parse(addPartID.Text);
            int     inStock = Int32.Parse(addPartInventory.Text);
            decimal price   = decimal.Parse(addPartPrice.Text);
            int     min     = Int32.Parse(addPartMin.Text);
            int     max     = Int32.Parse(addPartMax.Text);

            if (addPartInHouse.Checked)
            {
                int     machineID = Int32.Parse(addPartMachineID.Text);
                InHouse savePart  = new InHouse(partID, addPartName.Text, price, inStock, min, max, machineID);
                Inventory.addPart(savePart);
            }
            else
            {
                string     companyName = addPartMachineID.Text;
                Outsourced savePart    = new Outsourced(partID, addPartName.Text, price, inStock, min, max, companyName);
                Inventory.addPart(savePart);
            }
            Close();
        }