コード例 #1
0
        /// <summary>
        /// 1) Authenticates the user
        /// 2) Sets the viewmodel. Navigates to MainPage if medicine not found
        /// 3) Sets the image of the medicine if any
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            App.VerifyUserAuthenticity(this);
            base.OnNavigatedTo(e);

            string medicineId = "";
            if (NavigationContext.QueryString.TryGetValue("medicineId", out medicineId))
            {
                int id = int.Parse(medicineId);
                viewmodel = new MedicineViewModel(id);
            }
            else
            {
                NavigationService.Navigate(new Uri(ApplicationHelper.GetUrlFor(ApplicationHelper.URLs.MainPage), UriKind.Relative));
                return;
            }

            // Check if medicine is found
            if (viewmodel.Medicine == null)
            {
                NavigationService.Navigate(new Uri(ApplicationHelper.GetUrlFor(ApplicationHelper.URLs.MainPage), UriKind.Relative));
                return;
            }
            else
                DataContext = viewmodel.Medicine;

            AlarmsListBox.ItemsSource = viewmodel.Medicine.Reminders;
            if (viewmodel.Medicine.Reminders.Count == 0)
                AlarmsEmpty.Visibility = Visibility.Visible;
            else
                AlarmsEmpty.Visibility = Visibility.Collapsed;
        }
コード例 #2
0
 /// <summary>
 /// Gets the content of the reminder which shows Dosage (if present and valid), Dosage Type (if present and valid) and Medicine Name
 /// </summary>
 /// <param name="medicineId">MedicineID for which content is requried</param>
 /// <returns>Medicine Content string</returns>
 private string GetReminderContent(int medicineId)
 {
     var medicine = new MedicineViewModel(medicineId).Medicine;
     string dosageString = medicine.Dosage;
     double dosageDouble;
     if (String.IsNullOrWhiteSpace(dosageString) || !double.TryParse(dosageString, out dosageDouble))
         return String.Format("Take {0}\r\nAdd Dosage to get that info also here!\r\n[Click here to know more details]",
             medicine.Name);
     else
         return String.Format("Take {0} {1} of {2}\r\n\r\n[Click here to know more details]",
             dosageDouble, medicine.DosageType, medicine.Name);
 }