public void Add(DateNode <DateTime> node) { node.NodeRemoved += nodeRemove; if (_first == null) { _first = _last = node; } else { _last.Right = node; node.Left = _last; _last = node; } }
public void Add(double x, double y, int amount, out string message, DateTime date) { Box box = new Box(x, y, amount); box.LastTimeOrder = date; Node <Box> node = new Node <Box>(box); _boxCollection.Add(box.Key, node, out message, out bool isExist);//bool status if (!isExist) { DateNode <DateTime> nd = new DateNode <DateTime>(box.LastTimeOrder, box); box.DateNode = nd; _dateSearch.Add(nd); _sizeSearch.Add(box); } }
public void nodeRemove(object sender, NodeRemovedEventArgs e) { DateNode <DateTime> removed = sender as DateNode <DateTime>; if (removed == _first || removed == _last) { if (_first == removed) { if (removed.Right != null) { _first = removed.Right as DateNode <DateTime>; _first.Left = null; } else { _first = null; } } if (_last == removed) { if (removed.Left != null) { _last = removed.Left as DateNode <DateTime>; _last.Right = null; } else { _last = null; } } } else { if (removed.Left == null) { removed.Right.Left = null; } else { removed.Left.Right = removed.Right; removed.Right.Left = removed.Left; } } }
public List <Box> Remove() { List <Box> deleted = new List <Box>(); DateNode <DateTime> tmp = _first; while (tmp != null) { DateTime d = tmp.Data.AddDays(30); if (d < DateTime.Now) { deleted.Add(tmp.Box); tmp = (DateNode <DateTime>)tmp.Right; _first = tmp; } else { break; } } return(deleted); }
public Box Buy(double x, double y, out string message) { message = ""; double searchKey = ((x * y) - x) / ((x * y) + y); var box = _boxCollection.GetValue(searchKey, x, y); if (box == null) { Tuple <double, double, double> t = _sizeSearch.Find(x, y); if (t == null) { return(null); } box = _boxCollection.GetValue(t.Item3, t.Item1, t.Item2); } if (box == null) { throw new BoxException("we currentlly dont have any boxes"); } box.Data.Amount--; if (box.Data.Amount < box.Data.MinAmount) { message = ",you are about to run out of this box"; } if (box.Data.Amount == 0) { message = ",you ran out of this box"; _boxCollection.Remove(box.Data.Key, box.Data.X, box.Data.Y); } else { box.RemoveDate(); box.Data.LastTimeOrder = DateTime.Now; DateNode <DateTime> node = new DateNode <DateTime>(DateTime.Now, box.Data); _dateSearch.Add(node); box.Data.DateNode = node; } return(box.Data); }
public void Add(DateNode <DateTime> node) { _dates.Add(node); }