private static List <CostSummaryItem> consolidateCostInConnections(IEnumerable <IControllerConnection> connections) { Dictionary <ICost, CostSummaryItem> dictionary = new Dictionary <ICost, CostSummaryItem>(); List <CostSummaryItem> items = new List <CostSummaryItem>(); List <ICost> costs = new List <ICost>(); foreach (IControllerConnection connection in connections) { foreach (TECElectricalMaterial mat in connection.Protocol.ConnectionTypes) { costs.AddRange(mat.AssociatedCosts); } if (connection.ConduitType != null) { costs.AddRange(connection.ConduitType.AssociatedCosts); } } foreach (TECCost cost in costs) { if (dictionary.ContainsKey(cost)) { dictionary[cost].AddQuantity(1); } else { CostSummaryItem item = new CostSummaryItem(cost); dictionary.Add(cost, item); items.Add(item); } } return(items); }
protected CostBatch addAssocCost(ICost cost) { CostBatch deltas = new CostBatch(); bool containsItem = assocCostDictionary.ContainsKey(cost.Guid); if (containsItem) { CostSummaryItem item = assocCostDictionary[cost.Guid]; CostBatch delta = item.AddQuantity(1); AssocTECCostTotal += delta.GetCost(CostType.TEC); AssocTECLaborTotal += delta.GetLabor(CostType.TEC); AssocElecCostTotal += delta.GetCost(CostType.Electrical); AssocElecLaborTotal += delta.GetLabor(CostType.Electrical); deltas += delta; } else { CostSummaryItem item = new CostSummaryItem(cost); assocCostDictionary.Add(cost.Guid, item); if (cost.Type == CostType.TEC) { _assocTECItems.Add(item); AssocTECCostTotal += item.TotalCost; AssocTECLaborTotal += item.TotalLabor; } else if (cost.Type == CostType.Electrical) { _assocElecItems.Add(item); AssocElecCostTotal += item.TotalCost; AssocElecLaborTotal += item.TotalLabor; } deltas += new CostBatch(item.TotalCost, item.TotalLabor, cost.Type); } return(deltas); }
private static List <CostSummaryItem> consolidateMiscCosts(IEnumerable <ICost> costs) { Dictionary <ICost, CostSummaryItem> dictionary = new Dictionary <ICost, CostSummaryItem>(); List <CostSummaryItem> items = new List <CostSummaryItem>(); foreach (ICost cost in costs) { int quantity = 1; if (cost is TECMisc misc) { quantity = misc.Quantity; } if (dictionary.ContainsKey(cost)) { dictionary[cost].AddQuantity(1); } else { CostSummaryItem item = new CostSummaryItem(cost); dictionary.Add(cost, item); items.Add(item); } } return(items); }
private static List <CostSummaryItem> consolidateCostInValves(IEnumerable <TECValve> valves) { Dictionary <ICost, CostSummaryItem> dictionary = new Dictionary <ICost, CostSummaryItem>(); List <CostSummaryItem> items = new List <CostSummaryItem>(); List <ICost> costs = new List <ICost>(); foreach (TECValve valve in valves) { costs.AddRange(valve.AssociatedCosts); costs.AddRange(valve.Actuator.AssociatedCosts); } foreach (TECCost cost in costs) { if (dictionary.ContainsKey(cost)) { dictionary[cost].AddQuantity(1); } else { CostSummaryItem item = new CostSummaryItem(cost); dictionary.Add(cost, item); items.Add(item); } } return(items); }
private static List <CostSummaryItem> consolidateCostInPanels(IEnumerable <TECPanel> panels) { Dictionary <ICost, CostSummaryItem> dictionary = new Dictionary <ICost, CostSummaryItem>(); List <CostSummaryItem> items = new List <CostSummaryItem>(); List <ICost> costs = new List <ICost>(); foreach (TECPanel panel in panels) { costs.AddRange(panel.AssociatedCosts); costs.AddRange(panel.Type.AssociatedCosts); } foreach (TECCost cost in costs) { if (dictionary.ContainsKey(cost)) { dictionary[cost].AddQuantity(1); } else { CostSummaryItem item = new CostSummaryItem(cost); dictionary.Add(cost, item); items.Add(item); } } return(items); }
private static List <CostSummaryItem> consolidateCostInControllers(IEnumerable <TECController> controllers) { Dictionary <ICost, CostSummaryItem> dictionary = new Dictionary <ICost, CostSummaryItem>(); List <CostSummaryItem> items = new List <CostSummaryItem>(); List <ICost> costs = new List <ICost>(); foreach (TECController controller in controllers) { costs.AddRange(controller.AssociatedCosts); if (controller is TECProvidedController provided) { costs.AddRange(provided.Type.AssociatedCosts); } } foreach (TECCost cost in costs) { if (dictionary.ContainsKey(cost)) { dictionary[cost].AddQuantity(1); } else { CostSummaryItem item = new CostSummaryItem(cost); dictionary.Add(cost, item); items.Add(item); } } return(items); }
private static int insertCostItem(this IXLWorksheet worksheet, CostSummaryItem item, int row) { IXLRow itemRow = worksheet.Row(row); itemRow.Cell("A").Value = item.Cost.Name; itemRow.Cell("B").Value = item.Quantity; itemRow.Cell("C").Value = item.Cost.Type; itemRow.Cell("D").insertDollarDouble(item.Cost.Cost); itemRow.Cell("E").insertDollarDouble(item.TotalCost); itemRow.Cell("F").insertDouble(item.Cost.Labor); itemRow.Cell("G").insertDouble(item.TotalLabor); row++; return(row); }
public CostBatch ChangeQuantity(TECCost cost, int deltaQuantity) { bool containsItem = costDictionary.ContainsKey(cost.Guid); if (containsItem) { CostSummaryItem item = costDictionary[cost.Guid]; if (item.Quantity + deltaQuantity < 0) { logger.Error("Cannot remove more quantity than exists in CostSummaryItem. Removing all that exists." + "Cost: {0}", cost.Name); deltaQuantity = item.Quantity; } CostBatch delta = item.AddQuantity(deltaQuantity); if (cost is TECMisc) { if (cost.Type == CostType.TEC) { MiscTECCostTotal += delta.GetCost(CostType.TEC); MiscTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { MiscElecCostTotal += delta.GetCost(CostType.Electrical); MiscElecLaborTotal += delta.GetLabor(CostType.Electrical); } } else { if (cost.Type == CostType.TEC) { AssocTECCostTotal += delta.GetCost(CostType.TEC); AssocTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { AssocElecCostTotal += delta.GetCost(CostType.Electrical); AssocElecLaborTotal += delta.GetLabor(CostType.Electrical); } } return(delta); } else { logger.Error("Cost not found. Cannot change quantity. Cost: {0}", cost.Name); return(new CostBatch()); } }
public CostBatch UpdateCost(TECCost cost) { bool containsItem = costDictionary.ContainsKey(cost.Guid); if (containsItem) { CostSummaryItem item = costDictionary[cost.Guid]; CostBatch delta = item.Refresh(); if (cost is TECMisc) { if (cost.Type == CostType.TEC) { MiscTECCostTotal += delta.GetCost(CostType.TEC); MiscTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { MiscElecCostTotal += delta.GetCost(CostType.Electrical); MiscElecLaborTotal += delta.GetLabor(CostType.Electrical); } } else { if (cost.Type == CostType.TEC) { AssocTECCostTotal += delta.GetCost(CostType.TEC); AssocTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { AssocElecCostTotal += delta.GetCost(CostType.Electrical); AssocElecLaborTotal += delta.GetLabor(CostType.Electrical); } } return(delta); } else { logger.Error("Cost not found, cannot update. Cost: {0}", cost.Name); return(new CostBatch()); } }
public CostBatch RemoveCost(ICost cost) { bool containsItem = assocCostDictionary.ContainsKey(cost.Guid); if (containsItem) { CostSummaryItem item = assocCostDictionary[cost.Guid]; CostBatch delta = item.RemoveQuantity(1); if (cost.Type == CostType.TEC) { AssocTECCostTotal += delta.GetCost(CostType.TEC); AssocTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { AssocElecCostTotal += delta.GetCost(CostType.Electrical); AssocElecLaborTotal += delta.GetLabor(CostType.Electrical); } if (item.Quantity < 1) { assocCostDictionary.Remove(cost.Guid); if (cost.Type == CostType.TEC) { _assocTECItems.Remove(item); } else if (cost.Type == CostType.Electrical) { _assocElecItems.Remove(item); } } return(delta); } else { logger.Error("Cost not found. Cannot remove cost. Cost: {0}", cost.Name); return(new CostBatch()); } }
public CostBatch RemoveCost(ICost cost) { CostBatch delta; bool containsItem = costDictionary.ContainsKey(cost.Guid); if (containsItem) { CostSummaryItem item = costDictionary[cost.Guid]; if (cost is TECMisc misc) { delta = item.RemoveQuantity(misc.Quantity); if (cost.Type == CostType.TEC) { MiscTECCostTotal += delta.GetCost(CostType.TEC); MiscTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { MiscElecCostTotal += delta.GetCost(CostType.Electrical); MiscElecLaborTotal += delta.GetLabor(CostType.Electrical); } foreach (TECAssociatedCost assocCost in misc.AssociatedCosts) { for (int i = 0; i < misc.Quantity; i++) { delta += RemoveCost(assocCost); } } } else { delta = item.RemoveQuantity(1); if (cost.Type == CostType.TEC) { AssocTECCostTotal += delta.GetCost(CostType.TEC); AssocTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { AssocElecCostTotal += delta.GetCost(CostType.Electrical); AssocElecLaborTotal += delta.GetLabor(CostType.Electrical); } } if (item.Quantity < 1) { costDictionary.Remove(cost.Guid); if (cost is TECMisc miscToRemove) { if (cost.Type == CostType.TEC) { _miscTECItems.Remove(item); } else if (cost.Type == CostType.Electrical) { _miscElecItems.Remove(item); } } else { if (cost.Type == CostType.TEC) { _assocTECItems.Remove(item); } else if (cost.Type == CostType.Electrical) { _assocElecItems.Remove(item); } } } return(delta); } else { logger.Error("Cost not found. Cannot remove cost. Cost: {0}", cost.Name); return(new CostBatch()); } }
public CostBatch AddCost(ICost cost) { bool containsItem = costDictionary.ContainsKey(cost.Guid); if (containsItem) { CostSummaryItem item = costDictionary[cost.Guid]; if (cost is TECMisc misc) { CostBatch delta = item.AddQuantity(misc.Quantity); if (cost.Type == CostType.TEC) { MiscTECCostTotal += delta.GetCost(CostType.TEC); MiscTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { MiscElecCostTotal += delta.GetCost(CostType.Electrical); MiscElecLaborTotal += delta.GetLabor(CostType.Electrical); } foreach (TECAssociatedCost extraCost in misc.AssociatedCosts) { for (int i = 0; i < misc.Quantity; i++) { delta += AddCost(extraCost); } } return(delta); } else { CostBatch delta = item.AddQuantity(1); if (cost.Type == CostType.TEC) { AssocTECCostTotal += delta.GetCost(CostType.TEC); AssocTECLaborTotal += delta.GetLabor(CostType.TEC); } else if (cost.Type == CostType.Electrical) { AssocElecCostTotal += delta.GetCost(CostType.Electrical); AssocElecLaborTotal += delta.GetLabor(CostType.Electrical); } return(delta); } } else { CostSummaryItem item = new CostSummaryItem(cost); CostBatch delta = new CostBatch(item.TotalCost, item.TotalLabor, cost.Type); costDictionary.Add(cost.Guid, item); if (cost is TECMisc misc) { if (cost.Type == CostType.TEC) { _miscTECItems.Add(item); MiscTECCostTotal += item.TotalCost; MiscTECLaborTotal += item.TotalLabor; } else if (cost.Type == CostType.Electrical) { _miscElecItems.Add(item); MiscElecCostTotal += item.TotalCost; MiscElecLaborTotal += item.TotalLabor; } foreach (TECAssociatedCost assocCost in misc.AssociatedCosts) { for (int i = 0; i < misc.Quantity; i++) { delta += AddCost(assocCost); } } } else { if (cost.Type == CostType.TEC) { _assocTECItems.Add(item); AssocTECCostTotal += item.TotalCost; AssocTECLaborTotal += item.TotalLabor; } else if (cost.Type == CostType.Electrical) { _assocElecItems.Add(item); AssocElecCostTotal += item.TotalCost; AssocElecLaborTotal += item.TotalLabor; } } return(delta); } }
internal static void AddControllersSheet(XLWorkbook workbook, TECBid bid, TECEstimator estimate, string sheetName = "Controllers") { List <TECController> controllers = getAllControllers(bid); List <TECProvidedController> providedControllers = new List <TECProvidedController>(); foreach (TECController controller in controllers) { if (controller is TECProvidedController provided) { providedControllers.Add(provided); } } List <TECIOModule> modules = getAllIOModules(bid); List <HardwareSummaryItem> controllerItems = consolidateHardware(providedControllers.Select(provided => provided.Type)); List <CostSummaryItem> costItems = consolidateCostInControllers(controllers); List <HardwareSummaryItem> modulesItems = consolidateHardware(modules); IXLWorksheet worksheet = workbook.Worksheets.Add(sheetName); int row = 1; row = worksheet.insertTitleRow(sheetName, row); row++; row = worksheet.insertHardwareHeaders(row); foreach (HardwareSummaryItem item in controllerItems) { row = worksheet.insertHardwareItem(item, row); } row++; row = worksheet.insertTitleRow("IO Modules", row); row++; row = worksheet.insertHardwareHeaders(row); foreach (HardwareSummaryItem item in modulesItems) { row = worksheet.insertHardwareItem(item, row); } row++; row = worksheet.insertTitleRow("Associated Costs", row); row++; row = worksheet.insertCostHeaders(row); foreach (CostSummaryItem item in costItems) { row = worksheet.insertCostItem(item, row); } row++; row = worksheet.insertCostHeaders(row); TECAssociatedCost softwareCost = new TECAssociatedCost(CostType.TEC); softwareCost.Name = "Software Point License"; softwareCost.Cost = estimate.TECSoftwareCost; CostSummaryItem softwareSummary = new CostSummaryItem(softwareCost); row = worksheet.insertCostItem(softwareSummary, row); row++; worksheet.formatFinal(); }