private void MeasurementLogGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            MeasurementLogEntry entry = e.Row.DataContext as MeasurementLogEntry;

            // If this entry has a valid calculator associated then change the TextBlock to a HyperlinkButton
            // that when clicked will use the Acivator object to dynamically create the appropriate calculator

            if (entry.Measurement.Calculator != null)
            {
                TextBlock measurementName = MeasurementLogGrid.Columns[0].GetCellContent(e.Row) as TextBlock;

                if (measurementName != null)
                {
                    DataGridCell    cell           = measurementName.Parent as DataGridCell;
                    HyperlinkButton calculatorLink = new HyperlinkButton();

                    calculatorLink.Content             = entry.Measurement.measurement_name;
                    calculatorLink.Margin              = new Thickness(5);
                    calculatorLink.HorizontalAlignment = HorizontalAlignment.Center;
                    calculatorLink.Click += (s, ev) =>
                    {
                        // Create an instance of the calculator using IMeasurementCalculator interface so that we have
                        // access to the calculated value and can update the selected row value

                        ChildWindow            modalWindow = new ChildWindow();
                        IMeasurementCalculator calc        = Activator.CreateInstance(Type.GetType(String.Format("FitnessTrackerPlus.Views.Measurement.Calculators.{0}",
                                                                                                                 entry.Measurement.Calculator.type_name))) as IMeasurementCalculator;

                        calc.CalculationCancelled += (se, eve) => { modalWindow.Close(); };
                        calc.CalculationComplete  += (se, eve) =>
                        {
                            modalWindow.Close();

                            entry.value = calc.CalculatedValue;
                            context.SubmitChanges();
                        };

                        modalWindow.Title   = String.Format("{0} Calculator", entry.Measurement.measurement_name);
                        modalWindow.Content = calc;
                        modalWindow.Show();
                    };

                    // Repace the TextBlock with the HyperlinkButton control

                    cell.Content = calculatorLink;
                }
            }
        }
Example #2
0
        private void AlgoritmComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string text = AlgoritmComboBox.SelectedItem.ToString();

            if (text.Equals("Metoda Trapezow"))
            {
                algoritm = new TrapezoidalIntegratingModule();
            }
            else if (text.Equals("Metoda Simpsona"))
            {
                algoritm = new SimpsonsIntegratingModule();
            }

            if (measurement != null)
            {
                calculator = new MeasurementCalculator(measurement, algoritm);
            }
        }
Example #3
0
        private void MeasurementComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int id = 0;

            if (MeasurementComboBox.SelectedItem != null)
            {
                id = int.Parse(MeasurementComboBox.SelectedItem.ToString());
            }
            foreach (Measurement meas in measurements)
            {
                if (id == meas.Id)
                {
                    measurement = meas;
                    break;
                }
            }

            SaveMeasurementButton.IsEnabled = true;

            if (algoritm == null)
            {
                calculator = new MeasurementCalculator(measurement);
            }
            else
            {
                calculator = new MeasurementCalculator(measurement, algoritm);
            }
            this.calculator.InitializeBoundaries();
            minSlicer     = this.calculator.CurveBeginning;
            maxSlicer     = this.calculator.CurveEnd;
            Slicer1.Value = this.calculator.CurveBeginning;
            Slicer2.Value = this.calculator.CurveEnd;

            Console.WriteLine(maxSlicer);
            Console.WriteLine(minSlicer);
        }