void AddUPCItem(string key, int index) { if (!string.IsNullOrEmpty(key)) { key = key.ToUpperInvariant(); if (!UPCDictionary.ContainsKey(key)) { UPCDictionary.Add(key, index); } } }
protected override void RemoveItem(int index) { ActiveInventoryObject item = this[index]; UPCDictionary.Remove(item.UPC.ToUpperInvariant()); SKUDictionary.Remove(item.SKU.ToUpperInvariant()); ProductIDDictionary.Remove(item.ProductID); item.UnSubscribeToChangeEvents(item_UPCChanged, item_SKUChanged); base.RemoveItem(index); TotalInvested -= (item.WholeSalePrice + item.AdditionalOverhead) * item.Quantity; }
//public void Save(string file) //{ // List<byte> FullData = new List<byte>(); // foreach (ActiveInventoryObject obj in this) // { // List<byte> data = new List<byte>(); // data.AddRange(obj.GetByteArray()); // FullData.AddRange(BitConverter.GetBytes(data.Count)); // FullData.AddRange(data); // } // using (System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write)) // { // fs.Write(FullData.ToArray(), 0, FullData.Count); // } //} //public void Load(string file) //{ // List<byte> FullData = new List<byte>(); // if (System.IO.File.Exists(file)) // { // using (System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) // { // byte[] buffer = new byte[32768]; // int byteRead = 0; // do // { // byteRead = fs.Read(buffer, 0, buffer.Length); // if (byteRead > 0) // { // for (int i = 0; i < byteRead; i++) // { // FullData.Add(buffer[i]); // } // } // } while (byteRead > 0); // } // int pos = 0; // byte[] data = FullData.ToArray(); // while (pos < data.Length) // { // int objectLength = BitConverter.ToInt32(data, pos); // pos += 4; // List<byte> work = new List<byte>(); // for (int i = pos; i < objectLength + pos; i++) // { // work.Add(data[i]); // } // ActiveInventoryObject aio = new ActiveInventoryObject(); // aio.LoadProperties(work.ToArray()); // this.Add(aio); // pos += objectLength; // } // } //} protected override void ClearItems() { foreach (ActiveInventoryObject item in Items) { item.UnSubscribeToChangeEvents(item_UPCChanged, item_SKUChanged); } base.ClearItems(); UPCDictionary.Clear(); SKUDictionary.Clear(); ProductIDDictionary.Clear(); TotalInvested = 0; }
void item_UPCChanged(object sender, ItemChangedEventArgs e) { string key = e.OldValue as string; if (!string.IsNullOrEmpty(key)) { key = key.ToUpperInvariant(); int index = UPCDictionary[key]; UPCDictionary.Remove(key); key = e.NewValue as string; AddUPCItem(key, index); } }
public List <ActiveInventoryObject> GetByUPCorSKU(string key) { List <ActiveInventoryObject> retVal = new List <ActiveInventoryObject>(); if (key != null) { key = key.ToUpperInvariant(); if (UPCDictionary.ContainsKey(key)) { retVal.Add(Items[UPCDictionary[key]]); } if (SKUDictionary.ContainsKey(key)) { retVal.Add(Items[SKUDictionary[key]]); } } return(retVal); }