public void Execute() { TenantDAO tenantDAO = new TenantDAO(sqlConnection); CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection); Tenant storedTenant = tenantDAO.GetTenant(tenant.id); // Se o tenant já existe no banco bem como sua massa de dados, então só altera alguns dados if (storedTenant != null) { // seta identificador e nome amigável tenantDAO.SetTenant(tenant); // seta departamento raiz com o nome do tenant CostCenter mainCostCenter = costCenterDAO.GetMainCostCenter(tenant.id); mainCostCenter.name = tenant.alias; costCenterDAO.SetCostCenter(mainCostCenter); return; } // Cria um novo tenant e sua massa de dados inicial int?tenantId = tenantDAO.SetTenant(tenant); tenant.id = tenantId.Value; SetTenantPreference(); SetTenantAccess(); SetTenantDefaultSmtp(); SetTenantRootCC(); }
// 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); }
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 SetTenantRootCC() { CostCenter rootCC = new CostCenter(); rootCC.tenantId = tenant.id; rootCC.name = tenant.alias; rootCC.parentId = null; CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection); costCenterDAO.SetCostCenter(rootCC); }
/// <summary> /// Recupera uma árvore de custo do banco /// </summary> public CostTree GetCostTree(int tenantId) { CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection); List <Object> costCenterList = costCenterDAO.GetAllCostCenters(tenantId); CostCenterAssociateDAO associateDAO = new CostCenterAssociateDAO(sqlConnection); List <Object> associateList = associateDAO.GetAllAssociates(tenantId); CostTreeBuilder costTreeBuilder = new CostTreeBuilder(costCenterList, associateList); CostTree tree = costTreeBuilder.BuildTree(); return(tree); }
protected void Page_Load(Object sender, EventArgs e) { accountingMasterPage = (AccountingMasterPage)Page.Master; accountingMasterPage.InitializeMasterPageComponents(); tenant = (Tenant)Session["tenant"]; if (!String.IsNullOrEmpty(Request["action"])) { action = Request["action"]; } if (!String.IsNullOrEmpty(Request["currPage"])) { currentPage = int.Parse(Request["currPage"]); } int costCenterId = 0; DateTime startDate = DateTime.Now; DateTime endDate = DateTime.Now; try { costCenterId = int.Parse(Request.QueryString["costCenterId"]); startDate = DateTime.Parse(Request.QueryString["startDate"]); endDate = DateTime.Parse(Request.QueryString["endDate"]); } catch (System.FormatException) { // Remove todos os controles da página reportSurface.Controls.Clear(); // Mostra aviso de inconsistência nos parâmetros WarningMessage.Show(reportSurface, ArgumentBuilder.GetWarning()); return; } lblTitle.Text = "Relatório de Custos de Impressão"; CostCenterDAO costCenterDAO = new CostCenterDAO(accountingMasterPage.dataAccess.GetConnection()); CostCenter costCenter = costCenterDAO.GetCostCenter(tenant.id, costCenterId); lblCostCenter.Text = "Centro de Custo: " + costCenter.name; GenerateReport(costCenterId, startDate, endDate); }
protected void btnSubmit_Click(object sender, EventArgs e) { String costCenterName = null; foreach (String fieldName in Request.Form) { if (fieldName.Contains("txtName")) { costCenterName = Request.Form[fieldName]; } } if (String.IsNullOrEmpty(costCenterName)) { EmbedClientScript.ShowErrorMessage(this, "Os valores informados não estão em um formato válido!"); return; } CostCenter costCenter = GetCostCenter(); costCenter.name = costCenterName; try { CostCenterDAO costCenterDAO = new CostCenterDAO(settingsMasterPage.dataAccess.GetConnection()); costCenterDAO.SetCostCenter(costCenter); } catch (Exception genericException) { if (genericException.Message.Contains("Violation of UNIQUE KEY")) { EmbedClientScript.ShowErrorMessage(this, "Este centro de custo já existe!"); return; } EmbedClientScript.ShowErrorMessage(this, genericException.Message); } EmbedClientScript.CloseWindow(this); }
private int?parentId = null; // recebe na QueryString // Constroi o centro de custo com os parametros recebidos na QueryString private CostCenter GetCostCenter() { CostCenter costCenter = null; Tenant tenant = (Tenant)Session["tenant"]; // Alteração de um centro de custo existente if (costCenterId != null) { CostCenterDAO costCenterDAO = new CostCenterDAO(settingsMasterPage.dataAccess.GetConnection()); costCenter = costCenterDAO.GetCostCenter(tenant.id, costCenterId.Value); } // Inclusão de um novo centro de custo if (parentId != null) { costCenter = new CostCenter(); costCenter.parentId = parentId.Value; costCenter.tenantId = tenant.id; } return(costCenter); }
public override void BuildReport() { TenantDAO tenantDAO = new TenantDAO(sqlConnection); Tenant tenant = tenantDAO.GetTenant(tenantId); CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection); CostCenter costCenter = costCenterDAO.GetCostCenter(tenantId, costCenterId); CostTreePersistence persistence = new CostTreePersistence(sqlConnection); CostTree tree = persistence.GetCostTree(tenantId); CostBranch branch = tree.GetBranchById(costCenterId); List <Object> detailedCosts = GetDetailedCosts(branch); reportBuilder.OpenMedia(reportMedia); // Abre a mídia para o output do relatório Dictionary <String, Object> reportFilter = new Dictionary <String, Object>(); reportFilter.Add("tenantId", tenantId); reportFilter.Add("costCenterId", costCenterId); reportFilter.Add("startDate", startDate); reportFilter.Add("endDate", endDate); reportBuilder.SetReportHeadings("Relatório de Custos de Impressão" + ". " + "Centro de Custo: " + costCenter.name, tenant.alias, reportFilter); String[] columnNames = new String[] { "Usuário", "Páginas Pb", "Páginas Cor", "Total Páginas", "Custo Pb", "Custo Cor", "Total Custo" }; int[] columnWidths = new int[] { 50, 15, 15, 15, 15, 15, 15 }; int rowCount = detailedCosts.Count; reportBuilder.CreateDataTable(columnNames, columnWidths, rowCount); if (reportBuilder.IsNavigable()) { Dictionary <String, Object> exportOptions = ExportFormatContext.GetExportOptions(tenantId, sqlConnection); reportBuilder.SetNavigationData(this.GetType().Name, rowCount, exportOptions); // neste caso recordCount = rowCount reportBuilder.SetReportPage(action, currentPage); } for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { UserPrintingCost userPrintingCost = (UserPrintingCost)detailedCosts[rowIndex]; ReportCell[] cells = new ReportCell[] { new ReportCell(userPrintingCost.userName), new ReportCell(userPrintingCost.bwPageCount), new ReportCell(userPrintingCost.colorPageCount), new ReportCell(userPrintingCost.totalPageCount), new ReportCell(userPrintingCost.bwCost), new ReportCell(userPrintingCost.colorCost), new ReportCell(userPrintingCost.totalCost) }; reportBuilder.InsertRow(rowIndex, cells); } ReportCell[] footerCells = new ReportCell[] { new ReportCell("TOTAL", Color.Red), new ReportCell("paginasPb", ReportCellType.Number), new ReportCell("paginasCor", ReportCellType.Number), new ReportCell("totalPaginas", ReportCellType.Number), new ReportCell("custoPb", ReportCellType.Money), new ReportCell("custoCor", ReportCellType.Money), new ReportCell("totalCusto", ReportCellType.Money) }; reportBuilder.InsertFooter(footerCells); reportBuilder.CloseMedia(); }