private void RenderAssociations() { if ((associationPanel == null) || (orderedAssociates == null)) { return; } associationPanel.Controls.Clear(); orderedAssociates.Clear(); int costBranchId = int.Parse(selectedNode.Value); CostBranch costBranch = tree.GetBranchById(costBranchId); FindAssociations(costBranch); foreach (CostCenterAssociate associate in orderedAssociates.Values) { Label associateName = new Label(); associateName.Text = associate.userName; associateName.CssClass = "itemStyle"; associationPanel.Controls.Add(associateName); associationPanel.Controls.Add(new LiteralControl("<br/>")); } }
// Agrupa os custos(impressões) dos usuários existentes no "branch" (ramo de centros de custo), todos os centros // de custo derivados são contabilizados e o próprio ramo é um centro de custo com seus usuários associados private GroupPrintingCost AssembleCosts(CostBranch costBranch, String branchQualifiedName) { GroupPrintingCost groupPrintingCost = new GroupPrintingCost(); groupPrintingCost.costCenterId = costBranch.Id; groupPrintingCost.costCenterName = branchQualifiedName; SearchAssociates(costBranch, true); foreach (int userId in associates) { comparisonValue = userId; UserPrintingCost userPrintingCost = (UserPrintingCost)userPrintingCosts.Find(CheckCostMethod); if (userPrintingCost != null) { groupPrintingCost.bwPageCount += userPrintingCost.bwPageCount; groupPrintingCost.colorPageCount += userPrintingCost.colorPageCount; groupPrintingCost.totalPageCount += userPrintingCost.totalPageCount; groupPrintingCost.bwCost += userPrintingCost.bwCost; groupPrintingCost.colorCost += userPrintingCost.colorCost; groupPrintingCost.totalCost += userPrintingCost.totalCost; } } return(groupPrintingCost); }
// Remove um centro de custo do banco e toda a sua hierarquia (ramo de árvore), os registros // são excluídos definitivamente das tabelas public void RemoveBranch(CostBranch costBranch) { CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection); CostCenterAssociateDAO associateDAO = new CostCenterAssociateDAO(sqlConnection); // Remove recursivamente todos os objetos dependentes Remove(costBranch, costCenterDAO, associateDAO); }
public CostTree(CostBranch root, List <CostBranch> branchList) { this.root = root; branchDictionary = new Dictionary <int, CostBranch>(); foreach (CostBranch branch in branchList) { branchDictionary.Add(branch.Id, branch); } }
// Busca os ramos derivados de "branch", lista eles em ordem alfabética através do nome // completo desde a raiz private void SearchBranches(CostTree tree, CostBranch branch) { orderedBranches.Add(tree.GetBranchQualifiedName(branch.Id), branch); foreach (CostBranch child in branch.Children) { SearchBranches(tree, child); } }
private void Remove(CostBranch costBranch, CostCenterDAO costCenterDAO, CostCenterAssociateDAO associateDAO) { foreach (CostBranch child in costBranch.Children) { Remove(child, costCenterDAO, associateDAO); } associateDAO.RemoveAllAssociates(costBranch.Id); costCenterDAO.RemoveCostCenter(costBranch.Id); }
private void FindAssociations(CostBranch costBranch) { foreach (CostCenterAssociate associate in costBranch.Associates) { orderedAssociates.Add(associate.userName, associate); } foreach (CostBranch child in costBranch.Children) { FindAssociations(child); } }
public CostTree BuildTree() { CostBranch root = GetRoot(); // Não foi possível localizar a raiz do organograma if (root == null) { return(null); } // Obtem a estrutura de árvore (centros de custo), monta os nós recursivamente root.Children = GetChildren(root); return(new CostTree(root, branchList)); }
// Busca os usuários associados a um ramo recursivamente private void SearchAssociates(CostBranch costBranch, Boolean clearList) { if (clearList) { associates.Clear(); } foreach (CostCenterAssociate associate in costBranch.Associates) { associates.Add(associate.userId); } foreach (CostBranch child in costBranch.Children) { SearchAssociates(child, false); } }
public String GetBranchQualifiedName(int costBranchId) { // Verifica se o branch está presente no dicionário if (!branchDictionary.ContainsKey(costBranchId)) { return(null); } CostBranch branch = branchDictionary[costBranchId]; String qualifiedName = branch.Name; while (branch.Parent != null) { branch = branch.Parent; qualifiedName = branch.Name + "/" + qualifiedName; } return(qualifiedName); }
/// <summary> /// Obtem a filiação recursivamente /// </summary> private List <CostBranch> GetChildren(CostBranch parent) { List <CostBranch> returnList = new List <CostBranch>(); comparisonValue = parent.Id; List <Object> children = costCenters.FindAll(CheckCostCenterMethod); foreach (CostCenter costCenter in children) { CostBranch branch = new CostBranch(costCenter); branch.Parent = parent; branch.Children = GetChildren(branch); comparisonValue = branch.Id; branch.Associates = associates.FindAll(CheckAssociateMethod); returnList.Add(branch); branchList.Add(branch); } return(returnList); }
private void RenderBranch(Object output, CostBranch branch) { if (branch == null) { return; } TreeNode child = new TreeNode(branch.Name); child.Value = branch.Id.ToString(); if (output is TreeNode) { TreeNode node = (TreeNode)output; node.ChildNodes.Add(child); } if (output is TreeView) { TreeView tree = (TreeView)output; tree.Nodes.Add(child); child.Selected = true; selectedNode.Value = child.Value; RenderAssociations(); } SortedList <String, CostBranch> orderedBranches = new SortedList <String, CostBranch>(); foreach (CostBranch costBranch in branch.Children) { orderedBranches.Add(costBranch.Name, costBranch); } foreach (CostBranch costBranch in orderedBranches.Values) { RenderBranch(child, costBranch); } }
private CostBranch GetRoot() { // Seta o valor de comparação, para verificar se o centro de custo faz parte // da raiz do organograma (parentId = null) comparisonValue = null; // Busca a raiz do organograma (centro de custo com parentId = null) CostCenter rootCC = (CostCenter)costCenters.Find(CheckCostCenterMethod); // Não foi possível localizar a raiz do organograma if (rootCC == null) { return(null); } CostBranch rootBranch = new CostBranch(rootCC); comparisonValue = rootBranch.Id; rootBranch.Associates = associates.FindAll(CheckAssociateMethod); branchList.Add(rootBranch); return(rootBranch); }
/// <summary> /// Retorna uma lista com os custos de impressão por usuário associado /// </summary> public List <Object> GetCostsOfAssociates(CostBranch branch) { List <Object> costsOfAssociates = new List <Object>(); // Caso não tenham sido passados os custos por usuário retorna a lista em branco if ((userPrintingCosts == null) || (userPrintingCosts.Count < 1)) { return(costsOfAssociates); } SearchAssociates(branch, true); foreach (int userId in associates) { comparisonValue = userId; UserPrintingCost userPrintingCost = (UserPrintingCost)userPrintingCosts.Find(CheckCostMethod); if (userPrintingCost != null) { costsOfAssociates.Add(userPrintingCost); } } return(costsOfAssociates); }