コード例 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            errProvider.Clear();
            double newPrice;
            int    newUnits;
            string newDescription = txtDescription.Text;
            int    newIdNumber;

            if (!double.TryParse(txtPrice.Text, out newPrice) || newPrice < 0)
            {
                errProvider.SetError(txtPrice, "Price is not valid");
                return;
            }
            if (!int.TryParse(txtUnits.Text, out newUnits) || newUnits < 0)
            {
                errProvider.SetError(txtUnits, "Units not valid");
                return;
            }
            if (!int.TryParse(txtIdNumber.Text, out newIdNumber) || newIdNumber < 0)
            {
                errProvider.SetError(txtIdNumber, "Id Number not valid");
                return;
            }
            if (newDescription == "")
            {
                errProvider.SetError(txtDescription, "Description is blank");
                return;
            }

            Retalitem item = new Retalitem(newIdNumber, newDescription, newUnits, newPrice);

            _newItem = item;
            this.Close();
        }
コード例 #2
0
ファイル: Inventory.cs プロジェクト: rorystouder/Assingment9
        /* Add a method, DeleteItem, that uses an id number as a parameter. If the id number is in the list,
         * check if the units is 0. Only delete items that have 0 units (set last status to “Item deleted”).
         * Otherwise, set last status to “Item cannot be deleted”.
         */
        public void DeleteItem(int id)
        {
            Retalitem match = items.Find(x => x.IdNumber == id);

            if (match != null && match.Units == 0)
            {
                items.Remove(match);
                _lastStatus = "Item deleted";
            }
            else
            {
                _lastStatus = "item cannot be deleted";
            }
        }
コード例 #3
0
ファイル: Inventory.cs プロジェクト: rorystouder/Assingment9
        /* Add a method, UpdateItem, that uses a RetailItem parameter. The method updates the RetailItem in
         * the list with the matching parameter id number (set last status to “Item updated”. Otherwise, set last
         * status to “No matching item with ID Number xxxx” (where xxxx is the id parameter).
         */
        public void UpdateItem(Retalitem item)
        {
            Retalitem match = items.Find(x => x.IdNumber == item.IdNumber);

            if (match != null)
            {
                match.Price = item.Price;
                match.Units = item.Units;
                _lastStatus = "Item Updated";
            }
            else
            {
                _lastStatus = "No matching item with ID Number " + item.IdNumber;
            }
        }
コード例 #4
0
ファイル: Inventory.cs プロジェクト: rorystouder/Assingment9
        /*Add a method, AddItem, that uses a RetailItem as a parameter. The method should check if the id
         * number of the parameter is already in the list (set last status to “ID number already exists”).
         * Otherwise, add the item to the list and set last status to “Item added to inventory”.
         */
        public void AddItem(Retalitem item)
        {
            Retalitem match = items.Find(x => x.IdNumber == item.IdNumber);

            if (match != null)
            {
                // check out Project 2 override contains
                _lastStatus = "ID number already exists";
            }
            else
            {
                items.Add(item);
                _lastStatus = "Item added to inventory";
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: rorystouder/Assingment9
        private void Form1_Load(object sender, EventArgs e)
        {
            // In the form load event, add the following RetailItems:
            //Create RetailItem objects. Add to CurrentInventory
            Retalitem Item = new Retalitem(1, "Jacket", 12, 59.95);

            Program.CurrentInventory.AddItem(Item);

            Item = new Retalitem(2, "Jeans", 40, 34.95);
            Program.CurrentInventory.AddItem(Item);

            Item = new Retalitem(3, "Shirt", 20, 24.95);
            Program.CurrentInventory.AddItem(Item);

            DisplayInventory();
        }