예제 #1
0
        public CostBatch RemoveHardware(TECHardware hardware)
        {
            bool containsItem = hardwareDictionary.ContainsKey(hardware.Guid);

            if (containsItem)
            {
                CostBatch           deltas = new CostBatch();
                HardwareSummaryItem item   = hardwareDictionary[hardware.Guid];
                CostBatch           delta  = item.Decrement();
                deltas        += delta;
                HardwareCost  += delta.GetCost(hardware.Type);
                HardwareLabor += delta.GetLabor(hardware.Type);

                if (item.Quantity < 1)
                {
                    _hardwareItems.Remove(item);
                    hardwareDictionary.Remove(hardware.Guid);
                }
                foreach (ICost cost in hardware.AssociatedCosts)
                {
                    deltas += RemoveCost(cost);
                }
                return(deltas);
            }
            else
            {
                logger.Error("Hardware not present. Cannot remove hardware. Hardware: {0}", hardware.Name);
                return(new CostBatch());
            }
        }
예제 #2
0
        public CostBatch AddHardware(TECHardware hardware)
        {
            CostBatch deltas       = new CostBatch();
            bool      containsItem = hardwareDictionary.ContainsKey(hardware.Guid);

            if (containsItem)
            {
                HardwareSummaryItem item  = hardwareDictionary[hardware.Guid];
                CostBatch           delta = item.Increment();
                HardwareCost  += delta.GetCost(hardware.Type);
                HardwareLabor += delta.GetLabor(hardware.Type);
                deltas        += delta;
            }
            else
            {
                HardwareSummaryItem item = new HardwareSummaryItem(hardware);
                hardwareDictionary.Add(hardware.Guid, item);
                _hardwareItems.Add(item);
                HardwareCost  += item.TotalCost;
                HardwareLabor += item.TotalLabor;
                deltas        += new CostBatch(item.TotalCost, item.TotalLabor, hardware.Type);
            }
            foreach (ICost cost in hardware.AssociatedCosts)
            {
                deltas += AddCost(cost);
            }
            return(deltas);
        }
        private static int insertHardwareItem(this IXLWorksheet worksheet, HardwareSummaryItem item, int row)
        {
            IXLRow itemRow = worksheet.Row(row);

            itemRow.Cell("A").Value = item.Hardware.Name;
            itemRow.Cell("B").Value = item.Hardware.Description;
            itemRow.Cell("C").Value = item.Hardware.Manufacturer.Label;
            itemRow.Cell("D").Value = item.Quantity;
            itemRow.Cell("E").insertDollarDouble(item.Hardware.Price);
            itemRow.Cell("F").insertDollarDouble(item.Hardware.Cost);
            itemRow.Cell("G").insertDollarDouble(item.TotalCost);
            itemRow.Cell("H").insertDouble(item.Hardware.Labor);
            itemRow.Cell("I").insertDouble(item.TotalLabor);
            row++;
            return(row);
        }
        private static List <HardwareSummaryItem> consolidateHardware(IEnumerable <TECHardware> hardware)
        {
            Dictionary <TECHardware, HardwareSummaryItem> dictionary = new Dictionary <TECHardware, HardwareSummaryItem>();
            List <HardwareSummaryItem> items = new List <HardwareSummaryItem>();

            foreach (TECHardware hw in hardware)
            {
                if (dictionary.ContainsKey(hw))
                {
                    dictionary[hw].Increment();
                }
                else
                {
                    HardwareSummaryItem item = new HardwareSummaryItem(hw);
                    dictionary.Add(hw, item);
                    items.Add(item);
                }
            }

            return(items);
        }