private static bool LoadFromBin(string fileName) { try { using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open))) { // Order: Changes,Master,Inventory,Sales,Texture,WiP Marker,WiP, int listLen = reader.ReadInt32(); InventoryChanges.Clear(); for (; listLen > 0; --listLen) { InventoryChanges.Add(InventoryChange.LoadFromBin(reader)); } //listLen = reader.ReadInt32(); //ProductMasterList.Clear(); //for(;listLen > 0; --listLen) //{ // ProductMasterList.Add(ProductMasterItem.Load(reader)); //} listLen = reader.ReadInt32(); WiPItems.Clear(); for (; listLen > 0; --listLen) { WiPItems.Add(InventoryItem.LoadItem(reader)); } } IsLoaded = true; } catch (Exception) { return(false); } return(true); }
public static bool AddInventory(InventoryItem item) { try { Int32 foundIndex = 0; if (item.ProductCode[0] == 'W') { foundIndex = WiPItems.ToList().FindIndex(x => item.MasterID != -1 && x.MasterID == item.MasterID); if (foundIndex == -1) { WiPItems.Add(item); // not found, add new } else { InventoryItem existingItem = WiPItems[foundIndex]; //update old inventory existingItem.SetValues(item); // WiP inventory should only occur once, so set to the most recent value since this is a overwrite load. } } else { foundIndex = InventoryItems.FindIndex(x => item.MasterID != -1 && x.MasterID == item.MasterID); if (foundIndex == -1) { AddInventoryItem(item); // not found, add new } else { InventoryItem existingItem = InventoryItems[foundIndex]; //update old inventory existingItem.Units += item.Units; // add the units, as } } } catch (Exception) { return(false); } return(true); }