//Inhouse part constructor

        public AddPartForm(Inhouse inhouse)
        {
            InitializeComponent();

            textBoxAddPartID        = inhouse.PartID;
            textBoxAddPartName      = inhouse.Name;
            textBoxAddPartInventory = inhouse.InStock;
            textBoxAddPartPriceCost = inhouse.Price;
            textBoxAddPartMax       = inhouse.Max;
            textBoxAddPartMin       = inhouse.Min;
            textBoxAddPartMachineID = inhouse.MachineID.ToString();

            if (Inventory.CurrentPart is Inhouse)
            {
                Inhouse temp = (Inhouse)Inventory.CurrentPart;
                addPartMachineIDTextBox.Text = temp.MachineID.ToString();
                isInhouse = true;
                addPartInHouseRadioBtn.Checked = true;
            }
            else
            {
                Outsourced temp = (Outsourced)Inventory.CurrentPart;
                addPartMachineIDTextBox.Text = temp.CompanyName;
                isInhouse = false;
                addPartOutSourcedRadioBtn.Checked = true;
            }
        }
        //Outsourced part constructor

        public ModifyPartForm(Outsourced outsourced)
        {
            InitializeComponent();

            textBoxModifyPartID                  = outsourced.PartID;
            textBoxModifyPartName                = outsourced.Name;
            textBoxModifyPartInventory           = outsourced.InStock;
            textBoxModifyPartPriceCost           = outsourced.Price;
            textBoxModifyPartMax                 = outsourced.Max;
            textBoxModifyPartMin                 = outsourced.Min;
            textBoxModifyPartMachineID           = outsourced.CompanyName;
            modifyPartOutSourcedRadioBtn.Checked = true;
        }
 private void mainPartsModifyBtn_Click(object sender, EventArgs e)
 {
     this.Hide();
     if (mainPartsDataGridView.CurrentRow.DataBoundItem.GetType() == typeof(John_Davis_Inventory_App.Inhouse))
     {
         Inhouse inhouse = (Inhouse)mainPartsDataGridView.CurrentRow.DataBoundItem;
         new ModifyPartForm(inhouse).ShowDialog();
     }
     else
     {
         Outsourced outsourced = (Outsourced)mainPartsDataGridView.CurrentRow.DataBoundItem;
         new ModifyPartForm(outsourced).ShowDialog();
     }
 }
Esempio n. 4
0
        public static void UpdateOutsourced(int partID, Outsourced outsourced)
        {
            for (int i = 0; i < AllParts.Count; i++)
            {
                if (AllParts[i].GetType() == typeof(John_Davis_Inventory_App.Outsourced))
                {
                    Outsourced newPart = (Outsourced)AllParts[i];

                    if (newPart.PartID == partID)
                    {
                        newPart.Name        = outsourced.Name;
                        newPart.InStock     = outsourced.InStock;
                        newPart.Price       = outsourced.Price;
                        newPart.Min         = outsourced.Min;
                        newPart.Max         = outsourced.Max;
                        newPart.CompanyName = outsourced.CompanyName;
                    }
                }
            }
        }
        private void modifyPartSaveBtn_Click(object sender, EventArgs e)
        {
            //Exception message boxes working great!

            //try
            //{
            //    if (!Decimal.TryParse(modifyPartPriceCostTextBox.Text, out _))
            //    {
            //        MessageBox.Show("Price should be a decimal value.");
            //        return;
            //    }
            //}
            //catch
            //{

            //}

            //try
            //{
            //    if (Int32.TryParse(modifyPartNameTextBox.Text, out _))
            //    {
            //        MessageBox.Show("Name should be a string value");
            //        return;
            //    }
            //}
            //catch
            //{

            //}

            if (textBoxModifyPartMax < textBoxModifyPartMin)
            {
                MessageBox.Show("Minimum should be less than maximum.");
                return;
            }
            if (textBoxModifyPartInventory < textBoxModifyPartMin || textBoxModifyPartInventory > textBoxModifyPartMax)
            {
                MessageBox.Show("Inventory should be between minimum and maximum.");
                return;
            }

            Part newPart;

            if (modifyPartInHouseRadioBtn.Checked)
            {
                newPart = new Inhouse(Convert.ToInt32(modifyPartIDTextBox.Text), modifyPartNameTextBox.Text, Convert.ToDecimal(modifyPartPriceCostTextBox.Text),
                                      Convert.ToInt32(modifyPartInventoryTextBox.Text), Convert.ToInt32(modifyPartMinTextBox.Text), Convert.ToInt32(modifyPartMaxTextBox.Text),
                                      Convert.ToInt32(modifyPartMachineIDTextBox.Text));
                Inventory.UpdateInHouse(Convert.ToInt32(modifyPartIDTextBox.Text), (Inhouse)newPart);
                //modifyPartInHouseRadioBtn.Checked = true;
            }
            else
            {
                newPart = new Outsourced(Convert.ToInt32(modifyPartIDTextBox.Text), modifyPartNameTextBox.Text, Convert.ToDecimal(modifyPartPriceCostTextBox.Text),
                                         Convert.ToInt32(modifyPartInventoryTextBox.Text), Convert.ToInt32(modifyPartMinTextBox.Text), Convert.ToInt32(modifyPartMaxTextBox.Text),
                                         modifyPartMachineIDTextBox.Text);
                Inventory.UpdateOutsourced(Convert.ToInt32(modifyPartIDTextBox.Text), (Outsourced)newPart);
                //modifyPartOutSourcedRadioBtn.Checked = true;
            }
            for (int index = 0; index < Inventory.AllParts.Count; index++)
            {
                if (Inventory.AllParts.ElementAt(index).PartID == newPart.PartID)
                {
                    Inventory.AllParts.Insert(index, newPart);
                    Inventory.AllParts.RemoveAt(index + 1);
                    break;
                }
            }

            this.Hide();
            MainForm f1 = new MainForm();

            f1.Show();
        }
        private void addPartSaveBtn_Click(object sender, EventArgs e)
        {
            //Exception message boxes working great!

            //try
            //{
            //    if (!Decimal.TryParse(addPartPriceCostTextBox.Text, out _))
            //    {
            //        MessageBox.Show("Price should be a decimal value.");
            //        return;
            //    }
            //}
            //catch
            //{

            //}

            //try
            //{
            //    if (Int32.TryParse(addPartNameTextBox.Text, out _))
            //    {
            //        MessageBox.Show("Name should be a string value");
            //        return;
            //    }
            //}
            //catch
            //{

            //}


            try
            {
                if (textBoxAddPartMax < textBoxAddPartMin)
                {
                    MessageBox.Show("Minimum should be less than maximum.");
                    return;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Enter an integer value for both minimum and maximum.");
            }
            try
            {
                if (textBoxAddPartInventory < textBoxAddPartMin || textBoxAddPartInventory > textBoxAddPartMax)
                {
                    MessageBox.Show("Inventory should be between minimum and maximum.");
                    return;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Enter an integer value for inventory.");
            }
            try
            {
                if (addPartInHouseRadioBtn.Checked)
                {
                    Inhouse inHouse = new Inhouse((Inventory.AllParts.Count + 1), textBoxAddPartName, textBoxAddPartPriceCost, textBoxAddPartInventory,
                                                  textBoxAddPartMin, textBoxAddPartMax, int.Parse(textBoxAddPartMachineID));
                    Inventory.AddPart(inHouse);
                }
                else
                {
                    if (textBoxAddPartMax < textBoxAddPartMin)
                    {
                        MessageBox.Show("Minimum should be less than maximum.");
                        return;
                    }
                    if (textBoxAddPartInventory < textBoxAddPartMin || textBoxAddPartInventory > textBoxAddPartMax)
                    {
                        MessageBox.Show("Inventory should be between minimum and maximum.");
                        return;
                    }
                    Outsourced outsourced = new Outsourced((Inventory.AllParts.Count), textBoxAddPartName, textBoxAddPartPriceCost, textBoxAddPartInventory,
                                                           textBoxAddPartMin, textBoxAddPartMax, textBoxAddPartMachineID);
                    Inventory.AddPart(outsourced);
                }
            }

            catch (FormatException)
            {
                MessageBox.Show("Name should be a string and price/inventory/min/max/machineID should be numbers.");
            }
            this.Hide();
            MainForm f1 = new MainForm();

            f1.Show();
        }