public void LoadFromXml(XElement xmlElement)
        {
            IdManager idManager = IdManager.GetIdManager();

            InventoryItems = new List<InventoryItem>();

            foreach (XElement inventoryItemsElement in xmlElement.Elements("InventoryItems"))
            {
                foreach (XElement inventoryItemElement in inventoryItemsElement.Elements("InventoryItem"))
                {
                    InventoryItem inventoryItem = new InventoryItem();

                    inventoryItem.LoadFromXml(inventoryItemElement);

                    InventoryItems.Add(inventoryItem);
                }
            }

            foreach (var locationsElement in xmlElement.Elements("Locations"))
            {
                foreach (var locationElement in locationsElement.Elements("Location"))
                {
                    Location location = new Location();

                    location.LoadFromXml(locationElement);

                    Locations.Add(location);

                    idManager.RegisterId(location, location.Id);
                }
            }

            MerryUpLocationsWithInventoryItems();
        }
 public void RemoveInventoryItem(InventoryItem inventoryItem)
 {
     DeleteInventory(new List<InventoryItem>{inventoryItem});
 }
        void SetSelectedInventoryItem()
        {
            if(_currentInventoryItem != null)
            {
                lbxInventory.SelectedItem = _currentInventoryItem;
            }

            if (lbxInventory.Items.Count > 0 && lbxInventory.SelectedIndex < 0)
            {
                lbxInventory.SelectedIndex = 0;
            }

            if (lbxInventory.SelectedIndex > -1)
            {
                InventoryItem inventoryItem = lbxInventory.SelectedItem as InventoryItem;

                SetSelectedLocation(inventoryItem == null ? null : inventoryItem.Location);

                cbxInventoryCatalogItem.SelectedItem = inventoryItem.CatalogItem;
                txtInventoryDescription.Text = inventoryItem.CatalogItem.ToString();
                txtInventoryId.Text = inventoryItem.ToString();

                txtInventoryQtyOnHand.Text = inventoryItem.QtyOnHand.ToString();
                txtInventoryROPoint.Text = inventoryItem.ReOrderPoint.ToString();
                txtInventoryROQty.Text = inventoryItem.ReOrderQuantity.ToString();
                txtInventoryId.Text = inventoryItem.Id;
                txtInventoryComments.Text = inventoryItem.Comments;
            }

            _currentInventoryItem = null;

            SetInventoryDescription();
        }
        void SaveInventory()
        {
            SaveLocation();

            InventoryItem inventoryItem = FindInventoryItem(txtInventoryId.Text);

            if (inventoryItem == null)
            {
                inventoryItem = CreateInventoryItem();

                AddInventoryItem(inventoryItem);
            }

            _currentInventoryItem = inventoryItem;

            FillInventoryFromForm(inventoryItem);

            _currentInventoryItem.Location = _currentLocation;

            LoadInventory();
        }
 void AddInventoryItem(InventoryItem inventoryItem)
 {
     lbxInventory.Items.Add(inventoryItem);
     _productGraph.Inventory.InventoryItems.Add(inventoryItem);
 }
 void FillInventoryFromForm(InventoryItem inventoryItem)
 {
     inventoryItem.CatalogItem = cbxInventoryCatalogItem.SelectedItem as CatalogItem;
     inventoryItem.Location = cbxLocation.SelectedItem as Location;
     inventoryItem.QtyOnHand = int.Parse(txtInventoryQtyOnHand.Text);
     inventoryItem.ReOrderPoint = int.Parse(txtInventoryROPoint.Text);
     inventoryItem.ReOrderQuantity = int.Parse(txtInventoryROQty.Text);
     inventoryItem.Comments = txtInventoryComments.Text;
 }