/// <summary> /// Fills HistoryRangeModelItem with the information from HistoryRangeModel /// </summary> /// <param name="binCount">binCount in HistoryRangeModel</param> /// <param name="model">HistoryRangeModel itself</param> /// <param name="row">HistoryRangeModelItem to add to UI</param> /// <param name="type">Type of teh hisotry session</param> /// <param name="icon">icon to show for this row</param> /// <param name="titleFormat">format for the title</param> /// <param name="amountFormat">amount format</param> /// <returns></returns> HistoryRangeModelItem FillRow(int binCount, HistoryRangeModel model, HistoryRangeModelItem row, SessionType type, string icon, string titleFormat, string amountFormat, string amountText = null) { if (!String.IsNullOrEmpty(icon)) { row.Icon = icon; } if (!String.IsNullOrEmpty(titleFormat)) { double totalValue = model.Total[(int)type]; if (SessionType.Nurse == type) { //totalValue *= 60; // To minutes totalValue /= (0 < binCount ? binCount : 7); // Per day in week row.Title = String.Format(titleFormat, new object[] { totalValue }); } else { totalValue /= (0 < binCount ? binCount : 7); row.Title = String.Format(titleFormat, new object[] { totalValue }); // Per day in week } } if (null != model) { double maxValue = model.MaxRangeValue[(int)type]; maxValue = Math.Max(1.0, maxValue); for (int i = 0; i < binCount; i++) { row.BinsInfo.Add(model.RangeNames[i]); double amount = model.RangeValues[(int)type, i]; row.BinsAmountValue.Add(String.Format(amountFormat, amount)); row.BinsAmountText.Add(String.IsNullOrEmpty(amountText) ? String.Empty : amountText); row.BarHeights.Add(Math.Max(0.0, (row.MaxBarHeight * amount) / maxValue)); } } else { // Fill with default empty values for (int i = 0; i < binCount; i++) { row.BinsInfo.Add(String.Empty); row.BinsAmountValue.Add(String.Empty); row.BinsAmountText.Add(String.Empty); row.BarHeights.Add(0.0); } } return(row); }
/// <summary> /// Updates the week Model for the Week tab /// </summary> void UpdateWeekModel() { var model = ViewModel.WeeklyHistoryRangeModel; if (null == ListWeek.Header && ListWeek.Header != ViewModel) { ListWeek.Header = ViewModel; } HistoryRangeModelItem rangeItem = ViewModel.ListWeeklySource.FirstOrDefault(); rangeItem.Clear(); if (null != model) { switch (ViewModel.SelectedSession) { case SessionType.Pump: //ViewModel.ListWeeklySource.Add(FillRow(7, model, new HistoryRangeModelItem(), SessionType.Pump, "", String.Format("{0} {1}", AppResource.AverageOuncesPerDay, "{0:F1}\noz"), "{0:F1}\noz")); FillRow(7, model, rangeItem, SessionType.Pump, "", String.Format("{0} {1}", AppResource.AverageOuncesPerDay, "{0:F1}\noz"), "{0:F1}\noz"); break; case SessionType.Nurse: //ViewModel.ListWeeklySource.Add(FillRow(7, model, new HistoryRangeModelItem(), SessionType.Nurse, "", String.Format("{0} {1} {2}", AppResource.AverageNursedPerDay, "{0:F1}", AppResource.MinutesLower), "{0:F2}", AppResource.MinutesLower)); FillRow(7, model, rangeItem, SessionType.Nurse, "", String.Format("{0} {1} {2}", AppResource.AverageNursedPerDay, "{0:F1}", AppResource.MinutesLower), "{0:F2}", AppResource.MinutesLower); break; case SessionType.BottleFeed: { if (SessionType.Breastmilk == ViewModel.SelectedBottleType) { //ViewModel.ListWeeklySource.Add(FillRow(7, model, new HistoryRangeModelItem(), SessionType.Breastmilk, "", String.Format("{0} {1}", AppResource.AverageBottlePerDay, "{0:F1}\noz"), "{0:F1}\noz")); FillRow(7, model, rangeItem, SessionType.Breastmilk, "", String.Format("{0} {1}", AppResource.AverageBottlePerDay, "{0:F1}\noz"), "{0:F1}\noz"); } else if (SessionType.Formula == ViewModel.SelectedBottleType) { //ViewModel.ListWeeklySource.Add(FillRow(7, model, new HistoryRangeModelItem(), SessionType.Formula, "", String.Format("{0} {1}", AppResource.AverageBottlePerDay, "{0:F1}\noz"), "{0:F1}\noz")); FillRow(7, model, rangeItem, SessionType.Formula, "", String.Format("{0} {1}", AppResource.AverageBottlePerDay, "{0:F1}\noz"), "{0:F1}\noz"); } else { //ViewModel.ListWeeklySource.Add(FillRow(7, model, new HistoryRangeModelItem(), SessionType.BottleFeed, "", String.Format("{0} {1}", AppResource.AverageBottlePerDay, "{0:F1}\noz"), "{0:F1}\noz")); FillRow(7, model, rangeItem, SessionType.BottleFeed, "", String.Format("{0} {1}", AppResource.AverageBottlePerDay, "{0:F1}\noz"), "{0:F1}\noz"); } } break; default: { FillRow(7, null, rangeItem, SessionType.Max, null, null, null, null); } break; // default: TODO: Add No data cell } LblNoWeeklyRecords.IsVisible = false; ListWeek.IsVisible = true; if (null == ListWeek.ItemsSource) { ListWeek.ItemsSource = ViewModel.ListWeeklySource; } rangeItem.ToggleRangeModelItem = true; ViewModel.ToggleListViewSource = true; } else { ListWeek.IsVisible = false; ListWeek.ItemsSource = null; LblNoWeeklyRecords.IsVisible = true; } }