Esempio n. 1
0
        /*==========================================
        * Given a lab, serialize it into a string
        *  ==========================================*/
        private string SerializeLab(Lab lab)
        {
            string        myLab      = "";
            XmlSerializer serializer = new XmlSerializer(lab.GetType());

            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, lab);
                myLab = writer.ToString();
            }
            return(myLab);
        }
Esempio n. 2
0
        private void ProcessCharForEachNutrient(Lab lab)
        {
            var properties               = lab.GetType().GetProperties();
            var horseName                = lab.Horse.Name;
            var labCharts                = new List <LabNutrientViewModel>();
            var propertyValues           = new List <double>();
            var allHorseNurtientAverages = new List <double>();

            foreach (var property in properties)
            {
                // Skip LabId, Horse, LabDate, LabNumber and SampleId
                if (property.Name == nameof(lab.LabId) ||
                    property.Name == nameof(lab.Horse) ||
                    property.Name == nameof(lab.LabDate) ||
                    property.Name == nameof(lab.LabNumber) ||
                    property.Name == nameof(lab.SampleId) ||
                    property.Name == nameof(lab.Zirconium) ||
                    property.Name == nameof(lab.Strontium) ||
                    property.Name == nameof(lab.Rubidium) ||
                    property.Name == nameof(lab.Platinum) ||
                    property.Name == nameof(lab.Thallium))
                {
                    continue;
                }

                var propertyValue = (double)property.GetValue(lab);
                propertyValues.Add(propertyValue);

                allHorseNurtientAverages.Add(_ppnRepo.NutrientAverage(property.Name));


                labCharts.Add(new LabNutrientViewModel
                {
                    LabChart = new LabChart(_ppnRepo, property.Name, propertyValue, horseName,
                                            bulletPoints: _ppnRepo.GetNutrientBulletPoints(property.Name))
                });
            }

            var droppedHightestAndLowest = allHorseNurtientAverages.OrderBy(x => x).ToList();

            droppedHightestAndLowest.RemoveAt(0);
            droppedHightestAndLowest.OrderByDescending(x => x).ToList();
            droppedHightestAndLowest.RemoveAt(0);

            var allHorsesOverallAverage = droppedHightestAndLowest.Average();

            // TODO : Take an average of all of the property values
            var horseaverage = propertyValues.Average();

            var printDialog   = new PrintDialog();
            var fixedDocument = new FixedDocument();

            fixedDocument.DocumentPaginator.PageSize =
                new Size(
                    printDialog.PrintableAreaWidth,
                    printDialog.PrintableAreaHeight
                    );

            var fixedPage = CreateFixedPage(
                fixedDocument.DocumentPaginator.PageSize.Width,
                fixedDocument.DocumentPaginator.PageSize.Height
                );

            // handle first page
            var pageContent = new PageContent();

            fixedPage.Children.Add(new LabReportCover(
                                       fixedDocument.DocumentPaginator.PageSize.Width,
                                       fixedDocument.DocumentPaginator.PageSize.Height,
                                       horseaverage,
                                       allHorsesOverallAverage,
                                       lab));

            ((IAddChild)pageContent).AddChild(fixedPage);
            fixedDocument.Pages.Add(pageContent);



            fixedPage = CreateFixedPage(
                fixedDocument.DocumentPaginator.PageSize.Width,
                fixedDocument.DocumentPaginator.PageSize.Height
                );

            pageContent = new PageContent();
            var stackPanel = new StackPanel
            {
                Width = fixedDocument.DocumentPaginator.PageSize.Width
            };



            foreach (var chart in labCharts)
            {
                // Addition of Heavy Metal Intro TODO : This is dirty. But, it gets the job done
                if (chart.LabChart.NutrientName == "Aluminum")
                {
                    stackPanel.Children.Add(CreateHeavyMetalsIntroTextBlock());
                }

                stackPanel.Children.Add(chart.LabChart);

                if (stackPanel.Children.Count == 3)
                {
                    fixedPage.Children.Add(stackPanel);
                    ((IAddChild)pageContent).AddChild(fixedPage);
                    fixedDocument.Pages.Add(pageContent);

                    // recreate pageContent and fixedPage
                    fixedPage = CreateFixedPage(
                        fixedDocument.DocumentPaginator.PageSize.Width,
                        fixedDocument.DocumentPaginator.PageSize.Height
                        );

                    pageContent = new PageContent();
                    stackPanel  = new StackPanel
                    {
                        Width = fixedDocument.DocumentPaginator.PageSize.Width
                    };
                }
            }


            // handle end of last page
            var textBlock = new TextBlock
            {
                //Text = "Thank you for trusting Prime Performance Nutrition to generate this report. Please use code HTA19 to receive 10% off your next order at www.primeperformancenutrition.com",
                TextAlignment = TextAlignment.Center,
                TextWrapping  = TextWrapping.Wrap,
                FontFamily    = new FontFamily("./Fonts/#Open Sans Condensed Light"),
            };

            textBlock.Inlines.Add("Thank you for trusting Prime Performance Nutrition to generate this report. Please use code ");
            textBlock.Inlines.Add(new Run("HTA19 ")
            {
                Foreground = Brushes.Red
            });
            textBlock.Inlines.Add("to ");
            textBlock.Inlines.Add(new Run("receive 10% off your next order ")
            {
                TextDecorations = TextDecorations.Underline
            });
            textBlock.Inlines.Add("at www.primeperformancenutrition.com");


            stackPanel.Children.Add(textBlock);

            // add the last remainder
            fixedPage.Children.Add(stackPanel);
            ((IAddChild)pageContent).AddChild(fixedPage);
            fixedDocument.Pages.Add(pageContent);

            DocViewer.Document = fixedDocument;
            _printableDocument = fixedDocument;
        }