private static List <LengthSummaryItem> consolidateConduit(IEnumerable <IControllerConnection> connections)
        {
            Dictionary <TECElectricalMaterial, LengthSummaryItem> dictionary = new Dictionary <TECElectricalMaterial, LengthSummaryItem>();
            List <LengthSummaryItem> items = new List <LengthSummaryItem>();

            foreach (IControllerConnection connection in connections)
            {
                TECElectricalMaterial type = connection.ConduitType;
                if (type != null)
                {
                    if (dictionary.ContainsKey(type))
                    {
                        dictionary[type].AddLength(connection.ConduitLength);
                    }
                    else
                    {
                        LengthSummaryItem item = new LengthSummaryItem(type, connection.ConduitLength);
                        dictionary.Add(type, item);
                        items.Add(item);
                    }
                }
            }

            return(items);
        }
        public CostBatch AddLength(TECElectricalMaterial material, double length)
        {
            if (length < 0)
            {
                logger.Error("Length needs to be greater than 0 when adding to length summary. " +
                             "Failed to add length. Obj: {0}", material.Name);
                return(new CostBatch());
            }

            CostBatch deltas       = new CostBatch();
            bool      containsItem = lengthDictionary.ContainsKey(material.Guid);

            if (containsItem)
            {
                LengthSummaryItem item  = lengthDictionary[material.Guid];
                CostBatch         delta = item.AddLength(length);
                LengthCostTotal  += delta.GetCost(CostType.Electrical);
                LengthLaborTotal += delta.GetLabor(CostType.Electrical);
                deltas           += delta;
            }
            else
            {
                LengthSummaryItem item = new LengthSummaryItem(material, length);
                lengthDictionary.Add(material.Guid, item);
                _lengthSummaryItems.Add(item);
                LengthCostTotal  += item.TotalCost;
                LengthLaborTotal += item.TotalLabor;
                deltas           += new CostBatch(item.TotalCost, item.TotalLabor, CostType.Electrical);
            }
            foreach (ICost cost in material.RatedCosts)
            {
                deltas += addRatedCost(cost, length);
            }
            return(deltas);
        }
        private static int insertLengthItem(this IXLWorksheet worksheet, LengthSummaryItem item, int row)
        {
            IXLRow itemRow = worksheet.Row(row);

            itemRow.Cell("A").Value = item.Material.Name;
            itemRow.Cell("B").insertDouble(item.Length);
            itemRow.Cell("C").insertDollarDouble(item.Material.Cost);
            itemRow.Cell("D").insertDollarDouble(item.TotalCost);
            itemRow.Cell("E").insertDouble(item.Material.Labor);
            itemRow.Cell("F").insertDouble(item.TotalLabor);
            row++;
            return(row);
        }
        public CostBatch RemoveLength(TECElectricalMaterial material, double length)
        {
            if (length < 0)
            {
                logger.Error("Length needs to be greater than 0 when removing from length summary. " +
                             "Failed to remove length. Obj: {0}", material.Name);
                return(new CostBatch());
            }

            bool containsItem = lengthDictionary.ContainsKey(material.Guid);

            if (containsItem)
            {
                CostBatch         deltas = new CostBatch();
                LengthSummaryItem item   = lengthDictionary[material.Guid];
                CostBatch         delta  = item.RemoveLength(length);
                LengthCostTotal  += delta.GetCost(CostType.Electrical);
                LengthLaborTotal += delta.GetLabor(CostType.Electrical);
                deltas           += delta;

                if (item.Length <= 0)
                {
                    _lengthSummaryItems.Remove(item);
                    lengthDictionary.Remove(material.Guid);
                }
                foreach (ICost cost in material.RatedCosts)
                {
                    deltas += removeRatedCost(cost, length);
                }
                return(deltas);
            }
            else
            {
                logger.Error("Electrical Material not found. Cannot remove length. Material: {0}",
                             material.Name);
                return(new CostBatch());
            }
        }