public SPE_OBTIENE_FYD_PERIODO_EVALUACION_Result ObtienePeriodoEvaluacion(int pIdPeriodo) { PeriodoOperaciones oPeriodo = new PeriodoOperaciones(); return(oPeriodo.ObtenerPeriodoEvaluacion(pIdPeriodo)); }
public UDTT_ARCHIVO ExportarDatosExcel(int?ID_PERIODO, int?ID_DEPARTAMENTO, string NB_DEPARTAMENTO, string DS_PRIORIDADES, int?vIdRol) { NecesidadesCapacitacionOperaciones op = new NecesidadesCapacitacionOperaciones(); PeriodoOperaciones neg = new PeriodoOperaciones(); List <SPE_OBTIENE_NECESIDADES_CAPACITACION_Result> lista = new List <SPE_OBTIENE_NECESIDADES_CAPACITACION_Result>(); SPE_OBTIENE_FYD_PERIODO_EVALUACION_Result periodo = new SPE_OBTIENE_FYD_PERIODO_EVALUACION_Result(); UDTT_ARCHIVO excelNecesidadCapacitacion = new UDTT_ARCHIVO(); int i = 11; int col = 0; int row = 0; bool FinalListaEmpleados = false; bool CompetenciaEncontrada = false; string vDsNotas = ""; string vNbFirstRadEditorTagName = "p"; periodo = neg.ObtenerPeriodoEvaluacion(ID_PERIODO.Value); lista = op.obtenerNecesidadesCapacitacion(ID_PERIODO, ID_DEPARTAMENTO, DS_PRIORIDADES, vIdRol); Stream newStream = new MemoryStream(); using (ExcelPackage pck = new ExcelPackage(newStream)) { var ws = pck.Workbook.Worksheets.Add("Reporte"); ws.View.ShowGridLines = false; //ponemos los encabezados con los datos del periodo ws.Cells["A1"].Value = "Periodo:"; ws.Cells["B1"].Value = periodo.NB_PERIODO; ws.Cells["A2"].Value = "Notas:"; if (periodo.DS_NOTAS != null) { XElement vNota = XElement.Parse(periodo.DS_NOTAS); if (vNota != null) { if (vNota.Element("DS_NOTAS") != null) { vDsNotas = vNota.Element("DS_NOTAS").Value; } } } ws.Cells["B2"].Value = vDsNotas; ws.Cells["A3"].Value = "Tipo de evaluacion:"; ws.Cells["A4"].Value = "Departamento:"; ws.Cells["B4"].Value = NB_DEPARTAMENTO; //Leyendas de colores del archivo de excel ws.Cells["D1:F1"].Merge = true; ws.Cells["D1"].Value = "Prioridades de Capacitación"; ws.Cells["D2"].Value = "Alta:"; ws.Cells["D3"].Value = "Intermedia:"; ws.Cells["D4"].Value = "No necesaria:"; ws.Cells["D5"].Value = "No Aplica:"; ws.Cells["F2"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F3"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F4"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F5"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F2"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red); ws.Cells["F3"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Gold); ws.Cells["F4"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.White); ws.Cells["F5"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); //formato de encabezados ws.Cells["A7:A10"].Merge = true; ws.Cells["B7:B10"].Merge = true; ws.Cells["C7:C10"].Merge = true; ws.Cells["A7"].Value = "CATEGORIA"; ws.Cells["B7"].Value = "CLASIFICACION"; ws.Cells["C7"].Value = "COMPETENCIA"; ws.Cells["A7"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; ws.Cells["A7"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; ws.Cells["A7"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["A7"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); ws.Cells["B7"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; ws.Cells["B7"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; ws.Cells["B7"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["B7"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); ws.Cells["C7"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; ws.Cells["C7"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; ws.Cells["C7"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["C7"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); //Obtenemos las distintas competencias que se generan en la DNC. var competencias = (from a in lista select new { a.NB_CLASIFICACION_COMPETENCIA, a.CL_TIPO_COMPETENCIA, a.NB_COMPETENCIA, a.CL_COLOR }).Distinct(); foreach (var item in competencias) { ws.Cells["A" + i.ToString()].Value = item.CL_TIPO_COMPETENCIA; ws.Cells["B" + i.ToString()].Value = item.NB_CLASIFICACION_COMPETENCIA; ws.Cells["C" + i.ToString()].Value = item.NB_COMPETENCIA; ws.Cells["A" + i.ToString() + ":C" + i.ToString()].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin, System.Drawing.Color.FromName(item.CL_COLOR)); i++; } ws.Column(1).AutoFit(); ws.Column(2).AutoFit(); ws.Column(3).AutoFit(); //obtenemos todos los empleados var empleados = (from a in lista select new { a.CL_DEPARTAMENTO, a.NB_DEPARTAMENTO, a.CL_EVALUADO, a.NB_EVALUADO }).Distinct(); col = 4; foreach (var item in empleados) { ws.Cells[7, col].Value = item.CL_DEPARTAMENTO; ws.Cells[8, col].Value = item.NB_DEPARTAMENTO; ws.Cells[9, col].Value = item.CL_EVALUADO; ws.Cells[10, col].Value = item.NB_EVALUADO; col++; } col = 4; row = 11; string empleado = ""; while (!FinalListaEmpleados) { var valor = ws.Cells[10, col].Value; if (valor != null) { empleado = valor.ToString(); var listaEmpleado = (from a in lista where a.NB_EVALUADO == empleado select new { a.NB_COMPETENCIA, a.PR_RESULTADO, a.NB_PRIORIDAD }); foreach (var item in listaEmpleado) { while (!CompetenciaEncontrada) { if (ws.Cells[row, 3].Value.ToString() == item.NB_COMPETENCIA) { ws.Cells[row, col].Value = item.PR_RESULTADO; ws.Cells[row, col].Style.Numberformat.Format = "0.00"; ws.Cells[row, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; switch (item.NB_PRIORIDAD) { case "Alta": ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red); break; case "Intermedia": ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Gold); break; case "No Necesaria": ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.White); break; default: break; } } else { if (ws.Cells[row, col].Value == null) { ws.Cells[row, col].Value = "N/A"; ws.Cells[row, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); } else { if (ws.Cells[row, col].Value.ToString() == "N/A") { ws.Cells[row, col].Value = "N/A"; ws.Cells[row, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); } } } if (ws.Cells[row + 1, 3].Value == null) { CompetenciaEncontrada = true; } row++; } row = 11; CompetenciaEncontrada = false; } ws.Column(col).AutoFit(); col++; } else { FinalListaEmpleados = true; } } pck.Save(); newStream = pck.Stream; } excelNecesidadCapacitacion.NB_ARCHIVO = "ReporteDNC.xlsx"; excelNecesidadCapacitacion.FI_ARCHIVO = ((MemoryStream)newStream).ToArray(); return(excelNecesidadCapacitacion); }