Example #1
0
        internal FormPage(InformeResponse data, IEnumerable <LabeledImage> imgs, Size pgSize, Language language, bool useDpi = true)
        {
            InitializeComponent();

            if (data is null || data.serial == 0)
            {
                throw new ArgumentNullException();
            }

            _fltImages = (Floater)FindResource("FltImages");
            Lang       = language;
            switch (Lang)
            {
            case FormRender.Language.Spanish:
                LblTit.Text  = "Reporte de Histopatología";
                LblPac.Text  = "Paciente:";
                LblMed.Text  = "Médico:";
                LblAddr.Text = "Dirección:";
                LblDiag.Text = "Diag. Clínico:";
                LblMat.Text  = "Material Estudiado:";
                LblAge.Text  = "Edad:";
                LblSex.Text  = "  Género:";
                LblDte.Text  = "Fecha:";
                LblRec.Text  = "Recibido:";
                LblNb.Text   = "No. biopsia:";
                LblInf.Text  = "INFORME";
                LblIDt.Text  = "Fecha de informe:";
                _lblPg       = "Página";

                TxtFecha.Text    = data.fecha_biopcia?.ToString("dd/MM/yyyy") ?? string.Empty;
                TxtRecv.Text     = data.fecha_muestra?.ToString("dd/MM/yyyy") ?? string.Empty;
                TxtFechaInf.Text = data.fecha_informe?.ToString("dd/MM/yyyy") ?? string.Empty;

                break;

            case FormRender.Language.English:
                var ci = CultureInfo.CreateSpecificCulture("en-us");

                LblTit.Text  = "Histopathology Report";
                LblPac.Text  = "Patient:";
                LblMed.Text  = "Dr:";
                LblAddr.Text = "Address:";
                LblDiag.Text = "Clinical Diagnosis:";
                LblMat.Text  = "Specimen:";
                LblAge.Text  = "Age:";
                LblSex.Text  = "  Gender:";
                LblDte.Text  = "Date:";
                LblRec.Text  = "Received:";
                LblNb.Text   = "Biopsy N.:";
                LblInf.Text  = "REPORT";
                LblIDt.Text  = "Report date:";
                _lblPg       = "Page";

                TxtFecha.Text    = data.fecha_biopcia?.ToString("MMMM dd, yyyy", ci.DateTimeFormat) ?? string.Empty;
                TxtRecv.Text     = data.fecha_muestra?.ToString("MMMM dd, yyyy", ci.DateTimeFormat) ?? string.Empty;
                TxtFechaInf.Text = data.fecha_informe?.ToString("MMMM dd, yyyy", ci.DateTimeFormat) ?? string.Empty;

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Data = data;
            var labeledImages = imgs.ToList();

            Imgs = labeledImages;

            //Llenar header...
            TxtPaciente.Text  = data.facturas.nombre_completo_cliente;
            TxtMedico.Text    = data.facturas.medico;
            TxtDireccion.Text = data.facturas.direccion_entrega_sede;
            TxtDiag.Text      = data.diagnostico;
            TxtEstudiado.Text = data.muestra;
            TxtEdad.Text      = data.facturas.edad;
            TxtSexo.Text      = data.facturas.sexo;

            TxtBiop.Text    = $"{data.serial ?? 0} - {data.fecha_muestra?.Year.ToString() ?? "N/A"}";
            TxtFactNum.Text = $"C.I. {data.factura_id}";

            // Parsear y extraer texto desde html...
            var oo = XA.Parse(HTC.ConvertHtmlToXaml(data.informe, true)) as FlowDocument;

            while (oo?.Blocks.Any() ?? false)
            {
                oo.Blocks.FirstBlock.FontFamily = (FontFamily)FindResource("FntFmly");
                oo.Blocks.FirstBlock.FontSize   = (double)FindResource("FntSze");
                DocRoot.Blocks.Add(oo.Blocks.FirstBlock);
            }

            if (labeledImages.Any())
            {
                var fb = (Paragraph)DocRoot.Blocks.FirstBlock;
                fb.Inlines.InsertBefore(fb.Inlines.FirstInline, _fltImages);
            }

            _pageSize = pgSize;
            _ctrlSize = useDpi ? new Size(_pageSize.Width * UI.GetXDpi(), _pageSize.Height * UI.GetYDpi()) : pgSize;

            Rsze();

            foreach (var j in labeledImages)
            {
                GetImg(j);
            }
            switch (data.images.Length)
            {
            case 0:
            case 1: break;

            default:
                if (_imgAdjust > DocSize - GrdHead.ActualHeight)
                {
                    _fltImages.Width = 230 * ((DocSize) - GrdHead.ActualHeight) / _imgAdjust;
                }
                break;
            }

            RootContent.Width  = _ctrlSize.Width;
            RootContent.Height = _ctrlSize.Height;
            UpdateLayout();

            _firma             = data.firma;
            _firma2            = data.firma2;
            DocRoot.PageHeight =
                ActualHeight
                - ImgHeader.ActualHeight
                - GrdHead.ActualHeight
                - GrdFooter.ActualHeight
                - LblTit.ActualHeight
                - LblInf.ActualHeight
                - 25
                - GrdPager.ActualHeight;
        }
Example #2
0
        public async void Convert(InformeResponse data, IEnumerable <LabeledImage> imgs, Language language)
        {
            var doc = await OpenTemplate(language);

            doc.Variables["Biopsia"].Value     = $"{data.serial.ToString() ?? "N/A"} - {data.fecha_biopcia?.Year.ToString() ?? "N/A"}";
            doc.Variables["Diagnostico"].Value = data.diagnostico;
            doc.Variables["Direccion"].Value   = data.facturas.direccion_entrega_sede;
            doc.Variables["Doctor"].Value      = data.facturas.medico;
            doc.Variables["Edad"].Value        = data.facturas.edad;
            doc.Variables["Factura"].Value     = $"{data.factura_id.ToString() ?? "N/A"}";
            doc.Variables["Fecha"].Value       = $"{data.fecha_biopcia?.ToString("dd/MM/yyyy")}";
            doc.Variables["Material"].Value    = data.muestra;
            doc.Variables["Paciente"].Value    = data.facturas.nombre_completo_cliente;
            doc.Variables["Recibido"].Value    = $"{data.fecha_muestra?.ToString("dd/MM/yyyy")}";
            doc.Variables["Sexo"].Value        = data.facturas.sexo;
            UpdateFields(doc);

            string path = Path.GetTempFileName();

            File.WriteAllText(path, $"<html><p>{data.informe.Replace("<br/>", "</p><p>")}</p></html>");
            doc.Content.InsertFile(path, ConfirmConversions: false);
            doc.Content.Font.Name = "Calibri";
            File.Delete(path);

            doc.Content.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;

            float lastTop = 0;

            foreach (var j in data.images)
            {
                var shp = doc.Shapes.AddPicture($"{Config.imgPath}{j.image_url}", true, true);

                shp.Height          = shp.Height * 120 / shp.Width;
                shp.Width           = 120;
                shp.AlternativeText = j.descripcion;
                shp.Top             = lastTop;
                shp.Left            = 400;
                shp.WrapFormat.Type = WdWrapType.wdWrapSquare;
                lastTop            += shp.Height;
            }

            int   lp        = doc.Content.StoryLength - 1;
            Range endOfDoc  = doc.Range(lp, lp);
            Shape firmasBox = doc.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 200, 650.8346f, 373, 50, endOfDoc);
            Table firmas    = doc.Tables.Add(firmasBox.TextFrame.TextRange, 1, 2);

            firmasBox.Line.Visible             = MsoTriState.msoFalse;
            firmasBox.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
            if (!(data.firma is null))
            {
                var rng = firmas.Cell(1, 1).Range;
                rng.Text = $"{data.firma.name}\n{data.firma.collegiate}\n{data.firma.extra}";
                rng.ParagraphFormat.Alignment   = WdParagraphAlignment.wdAlignParagraphCenter;
                rng.ParagraphFormat.SpaceAfter  = 0;
                rng.ParagraphFormat.SpaceBefore = 0;
            }

            if (!(data.firma2 is null))
            {
                var rng = firmas.Cell(1, 2).Range;
                rng.Text = $"{data.firma2.name}\r{data.firma2.collegiate}\r{data.firma2.extra}";
                rng.ParagraphFormat.Alignment   = WdParagraphAlignment.wdAlignParagraphCenter;
                rng.ParagraphFormat.SpaceAfter  = 0;
                rng.ParagraphFormat.SpaceBefore = 0;
            }

            _wordApp.Visible = true;
        }