private void CustomMeasurementForm_ContentLoaded(object sender, DataFormContentLoadEventArgs e) { ComboBox measurementUnits = CustomMeasurementForm.FindNameInContent("MeasurementUnits") as ComboBox; DataField customUnitField = CustomMeasurementForm.FindNameInContent("CustomUnitField") as DataField; context.Load <MeasurementUnit>(context.GetMeasurementUnitsQuery(), LoadBehavior.RefreshCurrent, (MeasurementUnitsLoaded) => { if (!MeasurementUnitsLoaded.HasError) { measurementUnits.ItemsSource = MeasurementUnitsLoaded.Entities; measurementUnits.SelectedIndex = 0; } }, null); measurementUnits.SelectionChanged += (sev, eve) => { MeasurementUnit selected = measurementUnits.SelectedItem as MeasurementUnit; if (selected != null) { if (selected.id > 0) { customUnitField.Visibility = Visibility.Collapsed; selectedUnit = selected; } else { customUnitField.Visibility = Visibility.Visible; selectedUnit = null; } } }; }
private void LoadCurrentImage() { context.Load <MeasurementImage>(context.GetMeasurementImageQuery(Globals.CurrentUser.id, Globals.SelectedDate), LoadBehavior.RefreshCurrent, (ImageLoaded) => { if (!ImageLoaded.HasError) { IEnumerator <MeasurementImage> enumerator = ImageLoaded.Entities.GetEnumerator(); enumerator.MoveNext(); MeasurementImage image = enumerator.Current; if (image != null) { BitmapImage updatedImage = null; #if DEBUG updatedImage = new BitmapImage(new Uri(String.Format("http://localhost:22403/UploadedImages/{0}", image.file_name), UriKind.Absolute)); #else updatedImage = new BitmapImage(new Uri(String.Format("http://fitnesstrackerplus.com/UploadedImages/{0}", image.file_name), UriKind.Absolute)); #endif updatedImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache; CurrentImage.Source = updatedImage; } else { CurrentImage.Source = new BitmapImage(new Uri("/Images/image_unavailable.png", UriKind.Relative)); } } else { CurrentImage.Source = new BitmapImage(new Uri("/Images/image_unavailable.png", UriKind.Relative)); } }, null); }
private void LoadPublicJournal() { if (settings != null) { if (settings.share_foods) { foodContext.Load <FoodLogEntry>(foodContext.GetFoodLogEntriesQuery(settings.user_id, Calendar.SelectedDate.Value, false)); FoodLogGrid.Visibility = Visibility.Visible; } else { FoodLogGrid.Visibility = Visibility.Collapsed; } if (settings.share_exercises) { exerciseContext.Load <ExerciseLogEntry>(exerciseContext.GetExerciseLogEntriesQuery(Calendar.SelectedDate.Value, settings.user_id), LoadBehavior.RefreshCurrent, (EntriesLoaded) => { if (!EntriesLoaded.HasError) { CardioLogGrid.ItemsSource = EntriesLoaded.Entities.Where(ev => ev.Exercise.exercise_type == 1); WeightTrainingLogGrid.ItemsSource = EntriesLoaded.Entities.Where(ev => ev.Exercise.exercise_type == 2); ActivityLogGrid.ItemsSource = EntriesLoaded.Entities.Where(ev => ev.Exercise.exercise_type == 3); } }, null); CardioLogGrid.Visibility = Visibility.Visible; WeightTrainingLogGrid.Visibility = Visibility.Visible; ActivityLogGrid.Visibility = Visibility.Visible; } else { CardioLogGrid.Visibility = Visibility.Collapsed; WeightTrainingLogGrid.Visibility = Visibility.Collapsed; ActivityLogGrid.Visibility = Visibility.Collapsed; } if (settings.share_measurements) { measurementContext.Load <MeasurementLogEntry>(measurementContext.GetMeasurementLogEntriesQuery(settings.user_id, Calendar.SelectedDate.Value)); MeasurementLogGrid.Visibility = Visibility.Visible; } else { MeasurementLogGrid.Visibility = Visibility.Collapsed; } if (settings.share_images) { measurementContext.Load <MeasurementImage>(measurementContext.GetMeasurementImageQuery(settings.user_id, Calendar.SelectedDate.Value), LoadBehavior.RefreshCurrent, (ImageLoaded) => { if (!ImageLoaded.HasError) { BitmapImage updatedImage = null; MeasurementImage currentImage = ImageLoaded.Entities.FirstOrDefault <MeasurementImage>(); if (currentImage != null) { #if DEBUG updatedImage = new BitmapImage(new Uri(String.Format("http://localhost:32490/UploadedImages/{0}", ImageLoaded.Entities.First <MeasurementImage>()), UriKind.Absolute)); #else updatedImage = new BitmapImage(new Uri(String.Format("http://fitnesstrackerplus.com/UploadedImages/{0}", finalFileName), UriKind.Absolute)); #endif // This is necessary to ensure that Silverlight refreshes the image even though the file name remains the same updatedImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache; CurrentImage.Source = updatedImage; } else { CurrentImage.Source = new BitmapImage(new Uri("/Images/image_unavailable.png", UriKind.Relative)); } } }, null); CurrentImage.Visibility = Visibility.Visible; } else { CurrentImage.Visibility = Visibility.Collapsed; } if (settings.enable_comments) { HtmlPage.Document.GetElementById("comment_area").SetStyleAttribute("display", ""); HtmlPage.Document.GetElementById("comment_editor").SetStyleAttribute("display", ""); LoadComments(); CommentForm.Visibility = Visibility.Visible; } else { HtmlPage.Document.GetElementById("comment_area").SetStyleAttribute("display", "none"); HtmlPage.Document.GetElementById("comment_editor").SetStyleAttribute("display", "none"); CommentForm.Visibility = Visibility.Collapsed; } AboutText.Text = settings.about_text; } }
public MeasurementLog() { InitializeComponent(); Loaded += (s, e) => { // Setup control event handlers Calendar.SelectedDate = Globals.SelectedDate; Calendar.SelectedDatesChanged += (se, ev) => { if (Calendar.SelectedDate.HasValue) { Globals.SelectedDate = Calendar.SelectedDate.Value; LoadCurrentImage(); } }; MeasurementLogGrid.LayoutUpdated += (se, ev) => { DataGridHelper.ResizeGrid(0, MeasurementLogGrid); }; MeasurementLogGrid.RowEditEnded += new EventHandler <DataGridRowEditEndedEventArgs>(MeasurementLogGrid_RowEditEnded); MeasurementLogGrid.LoadingRow += new EventHandler <DataGridRowEventArgs>(MeasurementLogGrid_LoadingRow); CustomMeasurement.Click += new RoutedEventHandler(CustomMeasurement_Click); UpdateImage.Click += new RoutedEventHandler(UpdateImage_Click); DeleteSelected.Click += new RoutedEventHandler(DeleteSelected_Click); // Hold onto a copy of the MeasurementContext contained in the XAML context = this.Resources["MeasurementContext"] as MeasurementContext; Parameter user_id = new Parameter(); user_id.ParameterName = "user_id"; user_id.Value = Globals.CurrentUser.id; // Ensure that the user_id parameter is set for the DomainDataSource control before the query is executed MeasurementData.QueryParameters.Add(user_id); // Ensure that whenever data is being loaded into the DomainContext the ProgressBar control is visible // The ProgressBarVisibilityConverter will ensure that when IsLoading is true the Visibility is set to visible, false otherwise Binding binding = new Binding(); binding.Source = context; binding.Path = new PropertyPath("IsLoading"); binding.Converter = new ProgressBarVisibilityConverter(); ProgressBar.SetBinding(ProgressBar.VisibilityProperty, binding); // Setup the ComboBox control now that the MeasurementContext is available context.Load <FitnessTrackerPlus.Web.Data.Measurement>(context.GetMeasurementsQuery(Globals.CurrentUser.id), LoadBehavior.RefreshCurrent, (MeasurementsLoaded) => { if (!MeasurementsLoaded.HasError) { Measurements.ItemsSource = MeasurementsLoaded.Entities; Measurements.SelectedIndex = 0; } }, null); Measurements.SelectionChanged += (se, ev) => { FitnessTrackerPlus.Web.Data.Measurement selected = Measurements.SelectedItem as FitnessTrackerPlus.Web.Data.Measurement; if (selected.id > 0) { CreateMeasurementLogEntry(selected); } }; LoadCurrentImage(); }; }