private void FormatReport(DocumentacionRpt rpt)
        {
            string path = CompanyInfo.GetLogoPath(Schema.Oid);

            if (File.Exists(path))
            {
                Image image  = Image.FromFile(path);
                int   width  = rpt.Section1.ReportObjects["Logo"].Width;
                int   height = rpt.Section1.ReportObjects["Logo"].Height;

                rpt.Section1.ReportObjects["Logo"].Width  = 15 * image.Width;
                rpt.Section1.ReportObjects["Logo"].Height = 15 * image.Height;
                rpt.Section1.ReportObjects["Logo"].Left  += (width - 15 * image.Width) / 2;
                rpt.Section1.ReportObjects["Logo"].Top   += (height - 15 * image.Height) / 2;
            }
        }
        private void FormatReport(CertificadoNotasRpt rpt, CompanyInfo empresa)
        {
            string path = CompanyInfo.GetLogoPath(empresa.Oid);

            if (File.Exists(path))
            {
                Image image  = Image.FromFile(path);
                int   width  = rpt.Section1.ReportObjects["Logo"].Width;
                int   height = rpt.Section1.ReportObjects["Logo"].Height;

                rpt.Section1.ReportObjects["Logo"].Width  = 15 * image.Width;
                rpt.Section1.ReportObjects["Logo"].Height = 15 * image.Height;
                rpt.Section1.ReportObjects["Logo"].Left  += (width - 15 * image.Width) / 2;
                rpt.Section1.ReportObjects["Logo"].Top   += (height - 15 * image.Height) / 2;
            }
        }
Example #3
0
        /// <summary>
        /// Copia los atributos del objeto
        /// </summary>
        /// <param name="source">Objeto origen</param>
        protected void CopyValues(CronogramaInfo source, CompanyInfo empresa, PlanEstudiosInfo plan, PromocionInfo promocion)
        {
            if (source == null)
            {
                return;
            }

            Oid = source.Oid;
            _base.Record.OidPlan       = source.OidPlan;
            _base.Record.OidPromocion  = source.OidPromocion;
            _base.Record.FechaCreacion = source.FechaCreacion;
            _base.Record.Observaciones = source.Observaciones;

            if (plan != null)
            {
                _plan = plan.Nombre;
            }
            if (promocion != null)
            {
                _promocion = promocion.Nombre;
            }

            if (empresa == null)
            {
                return;
            }

            string path = CompanyInfo.GetLogoPath(AppContext.ActiveSchema.Oid);

            // Cargamos la imagen en el buffer
            if (File.Exists(path))
            {
                //Declaramos fs para poder abrir la imagen.
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

                // Declaramos un lector binario para pasar la imagen a bytes
                BinaryReader br = new BinaryReader(fs);
                _logo_emp = new byte[(int)fs.Length];
                br.Read(LogoEmp, 0, (int)fs.Length);
                br.Close();
                fs.Close();
            }
        }
Example #4
0
        /// <summary>
        /// Copia los atributos del objeto
        /// </summary>
        /// <param name="source">Objeto origen</param>
        protected void CopyValues(ExamenInfo source, CompanyInfo empresa, string promocion, string observaciones)
        {
            if (source == null)
            {
                return;
            }

            Oid = source.Oid;
            _base.Record.OidPromocion  = source.OidPromocion;
            _base.Record.OidProfesor   = source.OidProfesor;
            _base.Record.OidModulo     = source.OidModulo;
            _base.Record.FechaExamen   = source.FechaExamen;
            _base.Record.FechaCreacion = source.FechaCreacion;
            _base.Record.FechaEmision  = source.FechaEmision;
            _base.Record.Tipo          = source.Tipo;
            _base.Record.Desarrollo    = source.Desarrollo;
            _base.Record.Titulo        = source.Titulo;
            _base.Record.Duracion      = source.Duracion;
            _tiempo = Duracion.ToShortTimeString();
            _base.Record.MemoPreguntas = source.MemoPreguntas;
            _base.Record.Numero        = source.Numero;
            _dia           = _base.Record.FechaExamen.Day.ToString("00");
            _mes           = _base.Record.FechaExamen.Month.ToString("00");
            _año           = _base.Record.FechaExamen.Year.ToString();
            _observaciones = observaciones;

            _base.Promocion  = source.Promocion;
            _base.Modulo     = source.Modulo;
            _n_modulo        = ModuloInfo.Get(source.OidModulo, false).NumeroModulo;
            _base.Instructor = source.Instructor;

            _n_preguntas = source.PreguntaExamenes != null ? source.PreguntaExamenes.Count : 0;

            if (promocion != null)
            {
                //_oid_promocion_alumno = promocion.Oid;
                _base.Promocion = promocion;
            }
            else
            {
                if (source.Promociones != null && source.Promociones.Count > 0)
                {
                    _base.Promocion = string.Empty;

                    foreach (ExamenPromocionInfo ep in source.Promociones)
                    {
                        PromocionInfo pinfo = PromocionInfo.Get(ep.OidPromocion, false);
                        _base.Promocion += pinfo.Nombre + " ";
                    }
                }
            }

            if (empresa == null)
            {
                return;
            }

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

            //Z:\.\Recursos\Logos\Empresas\0002.jpg

            // Cargamos la imagen en el buffer
            if (File.Exists(path))
            {
                //Declaramos fs para poder abrir la imagen.
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

                // Declaramos un lector binario para pasar la imagen a bytes
                BinaryReader br = new BinaryReader(fs);
                _logo_emp = new byte[(int)fs.Length];
                br.Read(LogoEmp, 0, (int)fs.Length);
                br.Close();
                fs.Close();
            }
        }
        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();
            }
        }