예제 #1
0
        public static void FormatFechaDisponibilidad()
        {
            PreguntaExamenList preguntasexamen = PreguntaExamenList.GetList(false);
            PreguntaList       preguntas       = PreguntaList.GetList(false);
            ExamenList         examenes        = ExamenList.GetList(false);

            foreach (PreguntaInfo item in preguntas)
            {
                DateTime fecha_disponibilidad = DateTime.MaxValue;

                foreach (PreguntaExamenInfo pexamen in preguntasexamen)
                {
                    //la pregunta se encuentra en un examen emitido
                    if (item.Oid == pexamen.OidPregunta)
                    {
                        ExamenInfo examen = examenes.GetItem(pexamen.OidExamen);

                        DateTime fecha = examen.FechaExamen.AddMonths(6);

                        if (fecha_disponibilidad.Equals(DateTime.MaxValue) ||
                            (!fecha_disponibilidad.Equals(DateTime.MaxValue) &&
                             fecha.Date > fecha_disponibilidad.Date))
                        {
                            fecha_disponibilidad = fecha;
                        }
                    }
                }

                if (fecha_disponibilidad.Date.Equals(DateTime.MaxValue.Date))
                {
                    fecha_disponibilidad = item.FechaAlta;
                }

                if (!item.FechaDisponibilidad.Date.Equals(fecha_disponibilidad.Date))
                {
                    Pregunta.FormatDisponibilidad(item.Oid, fecha_disponibilidad);
                }
            }
        }
 public override void OpenViewForm()
 {
     try
     {
         PreguntaList plist = PreguntaList.GetList(ActiveList);
         AddForm(new PreguntasViewForm(ActiveOID, plist, true));
     }
     catch (Csla.DataPortalException ex)
     {
         MessageBox.Show(ex.BusinessException.ToString(),
                         moleQule.Face.Resources.Labels.ERROR_TITLE,
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(),
                         moleQule.Face.Resources.Labels.ERROR_TITLE,
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
 }
        private void ExportaDOC(CompanyInfo empresa)
        {
            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            try
            {
                WordExporter.InitWordExporter();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                moleQule.Face.Resources.Labels.ERROR_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }

            Word.Document oDoc = WordExporter.NewDocument();

            //Start Word and create a new document.

            /*Word._Application oWord;
             * Word._Document oDoc;
             * oWord = new Word.Application();
             * oWord.Visible = true;
             * oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing);*/

            foreach (Word.Section wordSection in oDoc.Sections)
            {
                wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = empresa.Name;
                wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.ShowFirstPageNumber = true;
                wordSection.Range.ParagraphFormat.SpaceAfter  = 0;
                wordSection.Range.ParagraphFormat.SpaceBefore = 0;
            }

            //Márgenes (1cm aprox.)
            oDoc.PageSetup.TopMargin    = 15;
            oDoc.PageSetup.BottomMargin = 0;
            oDoc.PageSetup.LeftMargin   = 30;
            oDoc.PageSetup.RightMargin  = 30;

            //Tabla de encabezado
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 5, 4, ref oMissing, ref oMissing);

            oTable.Range.ParagraphFormat.SpaceAfter  = 6;
            oTable.Range.ParagraphFormat.SpaceBefore = 6;

            oTable.Columns[1].Cells.Merge();
            oTable.Borders.Enable           = 1;
            oTable.Borders.InsideLineWidth  = Word.WdLineWidth.wdLineWidth150pt;
            oTable.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth150pt;

            oTable.Columns[2].Cells[1].Merge(oTable.Columns[2].Cells[2]);

            oTable.Columns[1].Width = 108.44F;
            oTable.Columns[3].Width = 81.33F;
            oTable.Columns[4].Width = 81.33F;
            oTable.Columns[2].Width = 271.1F;

            oTable.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;

            string logo = CompanyInfo.GetLogoPath(empresa.Oid);

            if (!File.Exists(logo))
            {
                MessageBox.Show("No se ha encontrado la imagen: " + logo);
            }
            else
            {
                oTable.Cell(1, 1).Range.InlineShapes.AddPicture(logo, ref oMissing, ref oMissing, ref oMissing);
            }
            oTable.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;

            ExamenPrint examen = Entity.GetPrintObject(empresa, string.Empty);

            oTable.Cell(1, 2).Range.Text                 = "HOJA DE PREGUNTAS";
            oTable.Cell(1, 2).Range.Font.Bold            = 1;
            oTable.Cell(1, 2).Range.Font.Size            = 16;
            oTable.Cell(1, 2).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[1].Range.Font.Name   = "Arial";

            oTable.Columns[2].Cells[2].Range.Text                 = examen.Modulo;
            oTable.Columns[2].Cells[2].Range.Font.Bold            = 1;
            oTable.Columns[2].Cells[2].Range.Font.Size            = 11;
            oTable.Columns[2].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[2].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[2].Range.Font.Name            = "Arial";

            oTable.Columns[2].Cells[3].Range.Text                 = "CURSO : " + examen.Promocion;
            oTable.Columns[2].Cells[3].Range.Font.Bold            = 1;
            oTable.Columns[2].Cells[3].Range.Font.Size            = 11;
            oTable.Columns[2].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[2].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[3].Range.Font.Name            = "Arial";

            oTable.Columns[2].Cells[4].Range.Text                 = "Deberá responder a las preguntas del examen a continuación de las mismas.";
            oTable.Columns[2].Cells[4].Range.Font.Size            = 11;
            oTable.Columns[2].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[2].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[4].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[1].Range.Text                 = "Nº EXAMEN";
            oTable.Columns[3].Cells[1].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[1].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[1].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[2].Range.Text                 = "FECHA";
            oTable.Columns[3].Cells[2].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[2].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[2].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[3].Range.Text                 = "TIPO EXAMEN";
            oTable.Columns[3].Cells[3].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[3].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[3].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[4].Range.Text                 = "Nº PREGUNTAS";
            oTable.Columns[3].Cells[4].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[4].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[4].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[5].Range.Text                 = "TIEMPO";
            oTable.Columns[3].Cells[5].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[5].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[5].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[1].Range.Text                 = examen.Numero.ToString().Trim();
            oTable.Columns[4].Cells[1].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[1].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[2].Range.Text                 = examen.FechaExamen.ToShortDateString().Trim();
            oTable.Columns[4].Cells[2].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[2].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[3].Range.Text                 = examen.Tipo.Trim();
            oTable.Columns[4].Cells[3].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[3].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[4].Range.Text                 = examen.NPreguntas.ToString().Trim();
            oTable.Columns[4].Cells[4].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[4].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[5].Range.Font.Name            = "Arial";
            oTable.Columns[4].Cells[5].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[5].Range.Text = examen.Duracion.ToShortTimeString().Trim();

            ////Add some text after the table.
            Word.Paragraph oParaAux;
            object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
            oParaAux.Range.Text = string.Empty;
            oParaAux.Range.InsertParagraph();

            //Nombre y apellidos
            Word.Paragraph oPara1;
            oPara1                 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text      = "NOMBRE Y APELLIDOS:";
            oPara1.Range.Font.Size = 12;
            oPara1.Range.Font.Name = "Arial";
            oPara1.Range.InsertParagraphAfter();
            oPara1.Range.InsertParagraphBefore();

            //DNI/NIE, FIRMA
            Word.Paragraph oPara2;
            oPara2                 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara2.Range.Text      = "DNI/NIE:                                                           FIRMA:";
            oPara2.Range.Font.Size = 12;
            oPara2.Range.Font.Name = "Arial";
            oPara2.Range.InsertParagraphAfter();
            oPara2.Range.InsertParagraphBefore();

            PreguntaList lista_preguntas = null;

            //Origen de las preguntas en función de si el examen está emitido o no
            if (_entity.Emitido)
            {
                lista_preguntas = PreguntaList.GetList(_entity.PreguntaExamenes);
            }
            else
            {
                lista_preguntas = _preguntas;
            }

            if (lista_preguntas != null)
            {
                int          i = 1;
                PreguntaInfo item;

                foreach (PreguntaExamenInfo pex in _entity.PreguntaExamenes)
                {
                    item = lista_preguntas.GetItem(pex.OidPregunta);

                    /*if (_preguntas_examen != null)
                     * {
                     *  int i = 1;
                     *
                     *  foreach (Pregunta_Examen preg in _preguntas_examen)
                     *  {
                     *      Pregunta item = _preguntas.GetItem(preg.OidPregunta);*/

                    //Para cada pregunta se inserta una tabla
                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    Word.Range newRng        = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    int        paginas_antes = (int)(oTable.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    oTable = oDoc.Tables.Add(wrdRng, 2, 3, ref oMissing, ref oMissing);

                    oTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAuto;

                    oTable.Columns[1].Width                      = 30;
                    oTable.Cell(1, 1).Range.Text                 = i.ToString();
                    oTable.Cell(1, 1).Range.Font.Size            = 10;
                    oTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    oTable.Cell(1, 1).Range.Font.Bold            = 1;
                    oTable.Cell(1, 1).Range.Font.Name            = "Arial";

                    oTable.Cell(1, 2).Merge(oTable.Columns[3].Cells[1]);
                    oTable.Cell(1, 2).Width                      = 510;
                    oTable.Cell(1, 2).Range.Text                 = item.Texto;
                    oTable.Cell(1, 2).Range.Font.Size            = 10;
                    oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                    oTable.Cell(1, 2).Range.Font.Bold            = 1;
                    oTable.Cell(1, 2).Range.Font.Name            = "Arial";

                    oTable.Cell(2, 2).Merge(oTable.Cell(2, 3));
                    oTable.Cell(2, 1).Merge(oTable.Cell(2, 2));
                    oTable.Cell(2, 1).Width = 540;

                    if (item.Imagen != string.Empty)
                    {
                        string path = item.ImagenWithPath;

                        if (File.Exists(path))
                        {
                            oTable.Cell(2, 1).Range.InlineShapes.AddPictureBullet(path, ref oMissing);
                            oTable.Cell(2, 1).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                            oTable.Cell(2, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        }
                        else
                        {
                            oTable.Rows[2].Delete();
                        }
                    }
                    else
                    {
                        oTable.Rows[2].Delete();
                    }

                    ////Add some text after the table.
                    oRng                = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                    oParaAux.Range.Text = string.Empty;
                    oParaAux.Range.InsertParagraph();

                    int paginas_despues = (int)(oParaAux.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    if (paginas_antes < paginas_despues)
                    {
                        newRng.InsertBreak(ref oMissing);
                    }

                    i++;
                }
            }
            else
            {
                foreach (PreguntaExamenInfo item in Entity.PreguntaExamenes)
                {
                    //Para cada pregunta se inserta una tabla
                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    Word.Range newRng        = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    int        paginas_antes = (int)(oTable.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    oTable = oDoc.Tables.Add(wrdRng, 2, 3, ref oMissing, ref oMissing);

                    oTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAuto;

                    oTable.Columns[1].Width                      = 30;
                    oTable.Cell(1, 1).Range.Text                 = item.Orden.ToString();
                    oTable.Cell(1, 1).Range.Font.Size            = 10;
                    oTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    oTable.Cell(1, 1).Range.Font.Bold            = 1;
                    oTable.Cell(1, 1).Range.Font.Name            = "Arial";

                    oTable.Cell(1, 2).Merge(oTable.Columns[3].Cells[1]);
                    oTable.Cell(1, 2).Width                      = 510;
                    oTable.Cell(1, 2).Range.Text                 = item.Texto;
                    oTable.Cell(1, 2).Range.Font.Size            = 10;
                    oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                    oTable.Cell(1, 2).Range.Font.Bold            = 1;
                    oTable.Cell(1, 2).Range.Font.Name            = "Arial";

                    oTable.Cell(2, 2).Merge(oTable.Cell(2, 3));
                    oTable.Cell(2, 1).Merge(oTable.Cell(2, 2));
                    oTable.Cell(2, 1).Width = 540;

                    if (item.Imagen != string.Empty)
                    {
                        /*string path = Images.GetRootPath() + PreguntaExamenInfo.GetImagenesPath() +
                         *  item.OidExamen.ToString("00000") + "\\" + item.Imagen;*/
                        string path = item.ImagenWithPath;

                        if (File.Exists(path))
                        {
                            oTable.Cell(2, 1).Range.InlineShapes.AddPictureBullet(path, ref oMissing);
                            oTable.Cell(2, 1).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                            oTable.Cell(2, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        }
                        else
                        {
                            oTable.Rows[2].Delete();
                        }
                    }
                    else
                    {
                        oTable.Rows[2].Delete();
                    }

                    ////Add some text after the table.
                    oRng                = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                    oParaAux.Range.Text = string.Empty;
                    oParaAux.Range.InsertParagraph();

                    int paginas_despues = (int)(oParaAux.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    if (paginas_antes < paginas_despues)
                    {
                        newRng.InsertBreak(ref oMissing);
                    }
                }
            }

            WordExporter.Close();
        }
        private void ExportaDOC(CompanyInfo empresa)
        {
            object      oMissing  = System.Reflection.Missing.Value;
            object      oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
            ExamenPrint examen    = null;

            try
            {
                WordExporter.InitWordExporter();

                examen = Entity.GetPrintObject(empresa, string.Empty);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                moleQule.Face.Resources.Labels.ERROR_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            PgMng.Reset(_entity.PreguntaExamenes.Count + 7, 1, Resources.Messages.LOADING_DATA, this);

            try
            {
                Word.Document oDoc = WordExporter.NewDocument();
                PgMng.Grow();

                foreach (Word.Section wordSection in oDoc.Sections)
                {
                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                    .Range.Text = empresa.Name;
                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                    .Range.Borders.DistanceFromTop = 10;
                    wordSection.Footers[
                        Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.ShowFirstPageNumber = true;
                    wordSection.Range.ParagraphFormat.SpaceAfter  = 0;
                    wordSection.Range.ParagraphFormat.SpaceBefore = 0;
                }
                PgMng.Grow();

                //Márgenes (1cm aprox.)
                oDoc.PageSetup.TopMargin    = 15;
                oDoc.PageSetup.BottomMargin = 0;
                oDoc.PageSetup.LeftMargin   = 30;
                oDoc.PageSetup.RightMargin  = 30;

                //Tabla de encabezado
                Word.Table oTable;
                Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oTable = oDoc.Tables.Add(wrdRng, 5, 4, ref oMissing, ref oMissing);

                oTable.Range.ParagraphFormat.SpaceAfter  = 6;
                oTable.Range.ParagraphFormat.SpaceBefore = 6;

                oTable.Columns[1].Cells.Merge();
                oTable.Borders.Enable           = 1;
                oTable.Borders.InsideLineWidth  = Word.WdLineWidth.wdLineWidth150pt;
                oTable.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth150pt;

                oTable.Columns[2].Cells[1].Merge(oTable.Columns[2].Cells[2]);

                oTable.Columns[1].Width = 108.44F;
                oTable.Columns[3].Width = 81.33F;
                oTable.Columns[4].Width = 81.33F;
                oTable.Columns[2].Width = 271.1F;

                oTable.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;
                PgMng.Grow();

                string logo = CompanyInfo.GetLogoPath(empresa.Oid);
                if (!File.Exists(logo))
                {
                    MessageBox.Show("No se ha encontrado la imagen: " + logo);
                }
                else
                {
                    oTable.Cell(1, 1).Range.InlineShapes.AddPicture(logo, ref oMissing, ref oMissing, ref oMissing);
                }
                oTable.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                PgMng.Grow();

                oTable.Cell(1, 2).Range.Text                 = "HOJA DE PREGUNTAS";
                oTable.Cell(1, 2).Range.Font.Bold            = 1;
                oTable.Cell(1, 2).Range.Font.Size            = 16;
                oTable.Cell(1, 2).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[1].Range.Font.Name   = "Arial";

                oTable.Columns[2].Cells[2].Range.Text                 = examen.Modulo;
                oTable.Columns[2].Cells[2].Range.Font.Bold            = 1;
                oTable.Columns[2].Cells[2].Range.Font.Size            = 11;
                oTable.Columns[2].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[2].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[2].Range.Font.Name            = "Arial";

                oTable.Columns[2].Cells[3].Range.Text                 = "CURSO : " + examen.Promocion;
                oTable.Columns[2].Cells[3].Range.Font.Bold            = 1;
                oTable.Columns[2].Cells[3].Range.Font.Size            = 11;
                oTable.Columns[2].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[2].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[3].Range.Font.Name            = "Arial";

                oTable.Columns[2].Cells[4].Range.Text =
                    "Deberá utilizar la plantilla que se le entregará para responder a las preguntas del examen.";
                oTable.Columns[2].Cells[4].Range.Font.Size            = 11;
                oTable.Columns[2].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[2].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[4].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[1].Range.Text                 = "Nº EXAMEN";
                oTable.Columns[3].Cells[1].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[1].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[1].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[2].Range.Text                 = "FECHA";
                oTable.Columns[3].Cells[2].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[2].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[2].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[3].Range.Text                 = "TIPO EXAMEN";
                oTable.Columns[3].Cells[3].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[3].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[3].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[4].Range.Text                 = "Nº PREGUNTAS";
                oTable.Columns[3].Cells[4].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[4].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[4].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[5].Range.Text                 = "TIEMPO";
                oTable.Columns[3].Cells[5].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[5].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[5].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[1].Range.Text                 = examen.Numero.ToString().Trim();
                oTable.Columns[4].Cells[1].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[1].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[2].Range.Text                 = examen.FechaExamen.ToShortDateString().Trim();
                oTable.Columns[4].Cells[2].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[2].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[3].Range.Text                 = examen.Tipo.Trim();
                oTable.Columns[4].Cells[3].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[3].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[4].Range.Text                 = examen.NPreguntas.ToString().Trim();
                oTable.Columns[4].Cells[4].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[4].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[5].Range.Font.Name            = "Arial";
                oTable.Columns[4].Cells[5].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[5].Range.Text = examen.Duracion.ToShortTimeString().Trim();
                PgMng.Grow();

                ////Add some text after the table.
                Word.Paragraph oParaAux;
                object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                oParaAux.Range.Text = string.Empty;
                oParaAux.Range.InsertParagraph();

                //Nombre y apellidos
                Word.Paragraph oPara1;
                oPara1                 = oDoc.Content.Paragraphs.Add(ref oMissing);
                oPara1.Range.Text      = "NOMBRE Y APELLIDOS:";
                oPara1.Range.Font.Size = 12;
                oPara1.Range.Font.Name = "Arial";
                oPara1.Range.InsertParagraphAfter();
                oPara1.Range.InsertParagraphBefore();

                //DNI/NIE, FIRMA
                Word.Paragraph oPara2;
                oPara2                 = oDoc.Content.Paragraphs.Add(ref oMissing);
                oPara2.Range.Text      = "DNI/NIE:                                                           FIRMA:";
                oPara2.Range.Font.Size = 12;
                oPara2.Range.Font.Name = "Arial";
                oPara2.Range.InsertParagraphAfter();
                oPara2.Range.InsertParagraphBefore();
                PgMng.Grow();

                PreguntaList lista_preguntas = null;

                //Origen de las preguntas en función de si el examen está emitido o no
                if (_entity.Emitido)
                {
                    lista_preguntas = PreguntaList.GetList(_entity.PreguntaExamenes);
                }
                else
                {
                    lista_preguntas = _preguntas;
                }

                if (lista_preguntas != null)
                {
                    int          i = 1;
                    PreguntaInfo item;

                    foreach (PreguntaExamenInfo pex in _entity.PreguntaExamenes)
                    {
                        item = lista_preguntas.GetItem(pex.OidPregunta);

                        //Para cada pregunta se inserta una tabla
                        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        Word.Range newRng        = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        int        paginas_antes = (int)(oTable.Range.get_Information(
                                                             Word.WdInformation.wdNumberOfPagesInDocument));
                        oTable = oDoc.Tables.Add(wrdRng, 5, 3, ref oMissing, ref oMissing);

                        oTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAuto;

                        oTable.Columns[1].Width                      = 30;
                        oTable.Cell(1, 1).Range.Text                 = i.ToString();
                        oTable.Cell(1, 1).Range.Font.Size            = 10;
                        oTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(1, 1).Range.Font.Bold            = 1;
                        oTable.Cell(1, 1).Range.Font.Name            = "Arial";

                        oTable.Cell(1, 2).Merge(oTable.Columns[3].Cells[1]);
                        oTable.Cell(1, 2).BottomPadding              = 8;
                        oTable.Cell(1, 2).Width                      = 510;
                        oTable.Cell(1, 2).Range.Text                 = item.Texto;
                        oTable.Cell(1, 2).Range.Font.Size            = 10;
                        oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                        oTable.Cell(1, 2).Range.Font.Bold            = 1;
                        oTable.Cell(1, 2).Range.Font.Name            = "Arial";

                        oTable.Cell(2, 2).Merge(oTable.Cell(2, 3));
                        oTable.Cell(2, 1).Merge(oTable.Cell(2, 2));
                        oTable.Cell(2, 1).Width = 540;

                        oTable.Cell(3, 2).Width                      = 20;
                        oTable.Cell(3, 2).Range.Text                 = "A";
                        oTable.Cell(3, 2).Range.Font.Size            = 10;
                        oTable.Cell(3, 2).Range.Paragraphs.Alignment =
                            Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(3, 2).Range.Font.Name = "Arial";

                        oTable.Cell(4, 2).Width                      = 20;
                        oTable.Cell(4, 2).Range.Text                 = "B";
                        oTable.Cell(4, 2).Range.Font.Size            = 10;
                        oTable.Cell(4, 2).Range.Paragraphs.Alignment =
                            Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(4, 2).Range.Font.Name = "Arial";

                        oTable.Cell(5, 2).Width                      = 20;
                        oTable.Cell(5, 2).Range.Text                 = "C";
                        oTable.Cell(5, 2).Range.Font.Size            = 10;
                        oTable.Cell(5, 2).Range.Paragraphs.Alignment =
                            Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(5, 2).Range.Font.Name = "Arial";

                        foreach (RespuestaInfo obj in item.Respuestas)
                        {
                            switch (obj.Opcion)
                            {
                            case "A":
                            {
                                oTable.Cell(3, 3).Width                      = 490;
                                oTable.Cell(3, 3).Range.Text                 = obj.Texto;
                                oTable.Cell(3, 3).Range.Font.Size            = 10;
                                oTable.Cell(3, 3).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                oTable.Cell(3, 3).Range.Font.Name = "Arial";
                                break;
                            }

                            case "B":
                            {
                                oTable.Cell(4, 3).Width                      = 490;
                                oTable.Cell(4, 3).Range.Text                 = obj.Texto;
                                oTable.Cell(4, 3).Range.Font.Size            = 10;
                                oTable.Cell(4, 3).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                oTable.Cell(4, 3).Range.Font.Name = "Arial";
                                break;
                            }

                            case "C":
                            {
                                oTable.Cell(5, 3).Width                      = 490;
                                oTable.Cell(5, 3).Range.Text                 = obj.Texto;
                                oTable.Cell(5, 3).Range.Font.Size            = 10;
                                oTable.Cell(5, 3).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                oTable.Cell(5, 3).Range.Font.Name = "Arial";
                                break;
                            }
                            }
                        }

                        if (item.Imagen != string.Empty)
                        {
                            string path = _entity.Emitido ?
                                          Library.Application.AppController.FOTOS_PREGUNTAS_EXAMEN_PATH + _entity.Oid.ToString("00000") + "\\" + item.Imagen :
                                          item.ImagenWithPath;

                            if (File.Exists(path))
                            {
                                oTable.Cell(2, 1).Range.InlineShapes.AddPictureBullet(path, ref oMissing);
                                oTable.Cell(2, 1).VerticalAlignment =
                                    Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                oTable.Cell(2, 1).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter;
                            }
                            else
                            {
                                MessageBox.Show("No se ha encontrado la imagen: " + path);
                                oTable.Rows[2].Delete();
                            }
                        }
                        else
                        {
                            oTable.Rows[2].Delete();
                        }

                        ////Add some text after the table.
                        oRng                = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                        oParaAux.Range.Text = string.Empty;
                        oParaAux.Range.InsertParagraph();

                        int paginas_despues = (int)(oParaAux.Range.get_Information(
                                                        Word.WdInformation.wdNumberOfPagesInDocument));
                        if (paginas_antes < paginas_despues)
                        {
                            newRng.InsertBreak(ref oMissing);
                        }

                        i++;
                    }
                    PgMng.Grow();
                    oDoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdPromptToSaveChanges,
                               Microsoft.Office.Interop.Word.WdOriginalFormat.wdPromptUser,
                               true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                moleQule.Face.Resources.Labels.ERROR_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            finally
            {
                WordExporter.Close();
                PgMng.FillUp();
            }
        }
        public override void PrintList()
        {
            //Separamos las preguntas tipo test de las de desarrollo
            //PreguntaList _all = null;
            SelectPreguntasReportForm select_report = new SelectPreguntasReportForm();

            DialogResult select_result = select_report.ShowDialog();

            if (select_result == DialogResult.OK)
            {
                if (select_report.Source == PrintSource.All)
                {
                    PreguntaList List = PreguntaList.GetList(Datos.List as IList <Pregunta>);
                    //_all = List;

                    //PreguntaList test = PreguntaList.SeparaPreguntasTest(_all);
                    //PreguntaList desarrollo = PreguntaList.SeparaPreguntasDesarrollo(_all);

                    //PreguntaExamens p_test = PreguntaExamens.NewChildList();
                    //PreguntaExamens p_desarrollo = PreguntaExamens.NewChildList();

                    //Preguntas preguntas = Preguntas.NewChildList();

                    //long orden = 1;

                    bool        defecto = moleQule.Library.Instruction.ModulePrincipal.GetImpresionEmpresaDefaultBoolSetting();
                    CompanyInfo empresa = null;

                    if (defecto)
                    {
                        empresa = CompanyInfo.Get(moleQule.Library.Instruction.ModulePrincipal.GetImpresionEmpresaDefaultOidSetting(), false);
                    }
                    while (empresa == null)
                    {
                        moleQule.Face.Common.CompanySelectForm form = new Common.CompanySelectForm(this);
                        DialogResult result = form.ShowDialog();

                        try
                        {
                            if (result == DialogResult.OK)
                            {
                                empresa = form.Selected as CompanyInfo;
                            }
                        }
                        catch
                        { empresa = null; }
                    }

                    //foreach (PreguntaInfo item in test)
                    //{
                    //    PreguntaExamen pexamen = PreguntaExamen.New();
                    //    Pregunta pregunta_examen = Pregunta.New();
                    //    pexamen.CopyValues(item);
                    //    pregunta_examen.Base.CopyValues(item);
                    //    pexamen.Orden = orden;
                    //    orden++;
                    //    p_test.AddItem(pexamen);
                    //    pregunta_examen.MarkItemChild();
                    //    preguntas.AddItem(pregunta_examen);
                    //    foreach (RespuestaInfo res in item.Respuestas)
                    //    {
                    //        if (res.OidPregunta == item.Oid)
                    //        {
                    //            RespuestaExamen rexamen = RespuestaExamen.NewChild(pexamen);
                    //            rexamen.CopyValues(res);
                    //            pexamen.RespuestaExamens.AddItem(rexamen);
                    //        }
                    //    }
                    //}

                    //foreach (PreguntaInfo item in desarrollo)
                    //{
                    //    PreguntaExamen pexamen = PreguntaExamen.New();
                    //    Pregunta pregunta_examen = Pregunta.New();
                    //    pexamen.CopyValues(item);
                    //    pregunta_examen.Base.CopyValues(item);
                    //    pexamen.Orden = orden;
                    //    orden++;
                    //    p_desarrollo.AddItem(pexamen);
                    //    pregunta_examen.MarkItemChild();
                    //    preguntas.AddItem(pregunta_examen);
                    //}

                    ExamenReportMng reportMng = new ExamenReportMng(AppContext.ActiveSchema);

                    if (List.Count > 0)
                    {
                        Library.Instruction.Reports.Preguntas.PreguntasListRpt report = reportMng.GetPreguntasListReport(List);
                        report.SetParameterValue("Empresa", empresa.Name);
                        if (empresa.Oid == 2)
                        {
                            ((CrystalDecisions.CrystalReports.Engine.TextObject)(report.Section5.ReportObjects["Text1"])).Color = System.Drawing.Color.FromArgb(13, 176, 46);
                        }
                        ReportViewer.SetReport(report);
                        ReportViewer.ShowDialog();
                    }

                    /*if (p_test.Count > 0)
                     * {
                     *  Library.Instruction.Reports.Examen.PreguntasTestRpt r_test = reportMng.GetDetailPreguntasTestReport(p_test, preguntas);
                     *  r_test.SetParameterValue("Empresa", empresa.Name);
                     *  if (empresa.Oid == 2) ((CrystalDecisions.CrystalReports.Engine.TextObject)(r_test.Section5.ReportObjects["Text1"])).Color = System.Drawing.Color.FromArgb(13, 176, 46);
                     *  ReportViewer.SetReport(r_test);
                     *  ReportViewer.ShowDialog();
                     * }
                     *
                     * if (p_desarrollo.Count > 0)
                     * {
                     *  Library.Instruction.Reports.Examen.PreguntasDesarrolloRpt r_desarrollo = reportMng.GetDetailPreguntasDesarrolloReport(p_desarrollo, preguntas);
                     *  r_desarrollo.SetParameterValue("Empresa", empresa.Name);
                     *  if (empresa.Oid == 2) ((CrystalDecisions.CrystalReports.Engine.TextObject)(r_desarrollo.Section5.ReportObjects["Text1"])).Color = System.Drawing.Color.FromArgb(13, 176, 46);
                     *  ReportViewer.SetReport(r_desarrollo);
                     *  ReportViewer.ShowDialog();
                     * }*/
                }
                else
                {
                    PreguntaList preguntas       = PreguntaList.GetList(Datos.List as IList <Pregunta>);
                    string       lista_preguntas = "(";
                    foreach (PreguntaInfo item in preguntas)
                    {
                        lista_preguntas += item.Oid.ToString() + ",";
                    }
                    if (lista_preguntas.IndexOf(",") > 0)
                    {
                        lista_preguntas = lista_preguntas.Substring(0, lista_preguntas.LastIndexOf(","));
                    }
                    lista_preguntas += ")";

                    InformePreguntasList List = InformePreguntasList.GetList(lista_preguntas);

                    ExamenReportMng reportMng = new ExamenReportMng(AppContext.ActiveSchema);

                    if (List.Count > 0)
                    {
                        bool        defecto = moleQule.Library.Instruction.ModulePrincipal.GetImpresionEmpresaDefaultBoolSetting();
                        CompanyInfo empresa = null;

                        if (defecto)
                        {
                            empresa = CompanyInfo.Get(moleQule.Library.Instruction.ModulePrincipal.GetImpresionEmpresaDefaultOidSetting(), false);
                        }
                        while (empresa == null)
                        {
                            moleQule.Face.Common.CompanySelectForm form = new Common.CompanySelectForm(this);
                            DialogResult result = form.ShowDialog();

                            try
                            {
                                if (result == DialogResult.OK)
                                {
                                    empresa = form.Selected as CompanyInfo;
                                }
                            }
                            catch
                            { empresa = null; }
                        }

                        moleQule.Library.Instruction.Reports.Preguntas.InformePreguntasRpt report = reportMng.GetInformePreguntasReport(List);
                        report.SetParameterValue("Empresa", empresa.Name);
                        if (empresa.Oid == 2)
                        {
                            ((CrystalDecisions.CrystalReports.Engine.TextObject)(report.Section5.ReportObjects["Text1"])).Color = System.Drawing.Color.FromArgb(13, 176, 46);
                        }
                        ReportViewer.SetReport(report);
                        ReportViewer.ShowDialog();
                    }
                }
            }
        }