Exemple #1
0
        public void exportarAExcel(Evaluacion ev, DataGridView TuDataGrid, FolderBrowserDialog ubicacion)
        {
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                MessageBox.Show("Excel is not properly installed!!");
                return;
            }


            Microsoft.Office.Interop.Excel.Workbook  xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlWorkBook  = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            int ColumnIndex = 0;

            foreach (DataGridViewColumn col in TuDataGrid.Columns)
            {
                ColumnIndex++;
                xlApp.Cells[1, ColumnIndex] = col.HeaderText;
            }
            int rowIndex = 0;

            foreach (DataGridViewRow row in TuDataGrid.Rows)
            {
                rowIndex++;
                ColumnIndex = 0;
                foreach (DataGridViewColumn col in TuDataGrid.Columns)
                {
                    ColumnIndex++;

                    xlApp.Cells[rowIndex + 1, ColumnIndex] = row.Cells[col.Name].Value;
                }
            }

            GestorDePuestos clogPues  = new GestorDePuestos();
            Puesto          puesto    = clogPues.getPuestos(ev.id_puesto);
            string          fecha     = DateTime.Now.ToString("yyyy-M-dd-H-mm-");
            string          funcion   = puesto.nombre;
            string          archivo   = ubicacion.SelectedPath + "\\" + fecha + funcion + ".xlsx";
            Worksheet       workSheet = xlApp.ActiveSheet;

            workSheet.Columns[1].AutoFit();
            workSheet.Columns[2].AutoFit();
            workSheet.Columns[3].AutoFit();
            workSheet.Columns[4].AutoFit();
            workSheet.Columns[5].AutoFit();
            xlWorkBook.SaveCopyAs(archivo);
            xlWorkBook.Close(false);
            xlApp.Quit();
            Marshal.ReleaseComObject(xlWorkSheet);
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlApp);
        }
Exemple #2
0
        private void generarBloquesCuestionario(Cuestionario cuest)
        {
            try
            {
                GestorDePuestos    clogPuestos = new GestorDePuestos();
                Puesto             puesto      = clogPuestos.getPuestos(evaluacion.id_puesto);
                List <Competencia> lcomp       = new List <Competencia>();
                puesto.Puntaje_Requerido.ToList().ForEach(pr => lcomp.Add(pr.Competencia));
                List <Factor> lfac = new List <Factor>();
                lcomp.ForEach(comp => comp.Factor.ToList().ForEach(fac => lfac.Add(fac)));
                List <Pregunta> preguntas = new List <Pregunta>();

                ItemBloque rel = new ItemBloque();

                foreach (Factor fac in lfac)
                {
                    Random rnd       = new Random(Guid.NewGuid().GetHashCode());
                    int    aleatorio = rnd.Next(0, fac.Pregunta.Count - 1);
                    preguntas.Add(fac.Pregunta.ToList()[aleatorio]);
                    int aleatorio1;
                    do
                    {
                        aleatorio1 = rnd.Next(0, fac.Pregunta.Count);
                    }while (aleatorio1 == aleatorio);
                    preguntas.Add(fac.Pregunta.ToList()[aleatorio1]);
                }

                int nroBloque = 0;

                List <Bloque> bloques = new List <Bloque>();

                Bloque bloq = new Bloque();
                bloq.id_cuestionario = cuest.id_cuestionario;
                bloq.num_bloque      = nroBloque + 1;
                bloques.Add(bloq);

                int i = 0;

                GestorTablaDeParametros clogTablaPar = new GestorTablaDeParametros();

                int cantidadPreguntasBloque = clogTablaPar.obtenerParametroEntero("PreguntasPorBloque");
                foreach (Pregunta preg in preguntas)
                {
                    if (i < cantidadPreguntasBloque)
                    {
                        ItemBloque resp = new ItemBloque();
                        resp.id_pregunta = preg.id_pregunta;
                        bloques[nroBloque].ItemBloque.Add(resp);
                    }
                    else
                    {
                        i = 0;
                        cuest.Bloque.Add(bloques[nroBloque]);
                        nroBloque++;
                        Bloque bloque = new Bloque();
                        bloque.id_cuestionario = cuest.id_cuestionario;
                        bloque.num_bloque      = nroBloque + 1;
                        bloques.Add(bloque);
                        ItemBloque resp = new ItemBloque();
                        resp.id_pregunta = preg.id_pregunta;
                        bloques[nroBloque].ItemBloque.Add(resp);
                    }
                    i++;
                }
                cuest.Bloque = bloques;
                this.agregarBloques(cuest, bloques);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }