Exemplo n.º 1
0
        public static IList<string> GetAuthorizedRolesForArea(Area area)
        {
            var authorizedRoles = new List<string>();
            var editRole = EDIT_AREA_ROLE_PREFIX + area.Number;

            authorizedRoles.Add(editRole);
            authorizedRoles.Add(MANAGE_ALL_AREAS_ROLE);

            return authorizedRoles;
        }
        private ExcelWorksheet WriteAreaData(ExcelWorksheet sheet, Area area)
        {
            int column = 0;

            #region Area Name
            Row++;
            ExcelRange range_areaName = sheet.Cells[Row, 1, Row, NUM_COLUMNS];
            range_areaName.Merge = true;
            range_areaName.Style.Font.SetFromFont(new Font("Calibri", 11, FontStyle.Italic));
            range_areaName.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
            range_areaName.Value = area.Name;
            #endregion

            #region Area Funds
            IEnumerable<Fund> areaFunds = Funds.Where(f => f.AreaId == area.Id);

            if (areaFunds.Count() == 0)
            {
                Row++;
                ExcelRange range_areaData = sheet.Cells[Row, 1, Row, NUM_COLUMNS];
                range_areaData.Merge = true;
                range_areaData.Style.Font.SetFromFont(new Font("Calibri", 11, FontStyle.Regular));
                range_areaData.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
                range_areaData.Value = "No records";
            }
            else
            {
                foreach (Fund fund in areaFunds)
                {
                    Row++;
                    column = 0;
                    sheet.Cells[Row, ++column].Value = fund.Number;
                    sheet.Cells[Row, ++column].Value = fund.Title;
                    sheet.Cells[Row, ++column].Value = fund.Description;
                    sheet.Cells[Row, ++column].Value = fund.BudgetAdjustmentNote;
                    sheet.Cells[Row, ++column].Value = fund.BudgetAdjustment * -1;
                }
            }
            #endregion

            return sheet;
        }
        private ExcelWorksheet WriteAreaData(ExcelWorksheet sheet, Area area)
        {
            int column = 0;

            #region Area Name
            Row++;
            ExcelRange range_areaName = sheet.Cells[Row, 1, Row, NUM_COLUMNS];
            range_areaName.Merge = true;
            range_areaName.Style.Font.SetFromFont(new Font("Calibri", 11, FontStyle.Italic));
            range_areaName.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
            range_areaName.Value = area.Name;
            #endregion

            #region Area Funds
            IEnumerable<Fund> areaFunds = Funds.Where(f => f.AreaId == area.Id);

            if (areaFunds.Count() == 0)
            {
                Row++;
                ExcelRange range_areaData = sheet.Cells[Row, 1, Row, NUM_COLUMNS];
                range_areaData.Merge = true;
                range_areaData.Style.Font.SetFromFont(new Font("Calibri", 11, FontStyle.Regular));
                range_areaData.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
                range_areaData.Value = "No records";
            }
            else
            {
                foreach (Fund fund in areaFunds)
                {
                    Row++;
                    column = 0;
                    sheet.Cells[Row, ++column].Value = fund.Number;
                    sheet.Cells[Row, ++column].Value = fund.Title;
                    sheet.Cells[Row, ++column].Value = fund.ResponsiblePerson;
                    sheet.Cells[Row, ++column].Value = fund.CurrentBudget;
                    sheet.Cells[Row, ++column].Value = fund.ProjectedExpenditures;
                    sheet.Cells[Row, ++column].Value = (fund.CurrentBudget + fund.BudgetAdjustment);
                    sheet.Cells[Row, ++column].Value = fund.BudgetAdjustment * -1;
                }
            }
            #endregion

            #region Area Summary
            Row++;
            column = 0;
            ExcelRange range_areaSummary = sheet.Cells[Row, 1, Row, NUM_COLUMNS];
            range_areaSummary.Style.Font.SetFromFont(new Font("Calibri", 11, FontStyle.Bold));
            range_areaSummary.Style.Font.Color.SetColor(Color.White);
            range_areaSummary.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
            range_areaSummary.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(107, 107, 107));

            ExcelRange range_areaSummaryTitle = sheet.Cells[Row, 1, Row, NUM_COLUMNS - SUMMARY_DATA_COLUMNS];
            range_areaSummaryTitle.Merge = true;
            range_areaSummaryTitle.Value = "Total for " + area.Name;

            sheet.Cells[Row, SUMMARY_DATA_COLUMNS].Value = areaFunds
                .Sum(f => f.CurrentBudget);
            sheet.Cells[Row, ++column + SUMMARY_DATA_COLUMNS].Value = areaFunds
                .Sum(f => f.ProjectedExpenditures);
            sheet.Cells[Row, ++column + SUMMARY_DATA_COLUMNS].Value = areaFunds
                .Sum(f => f.CurrentBudget + f.BudgetAdjustment);
            sheet.Cells[Row, ++column + SUMMARY_DATA_COLUMNS].Value = areaFunds
                .Sum(f => f.BudgetAdjustment * -1);
            #endregion

            return sheet;
        }