コード例 #1
0
        private void SaveWeight(object sender, RoutedEventArgs e)
        {
            try
            {
                var weightDataRepository = new WeightDataRepository(EHealthCareDesktopApp.Properties.Settings.Default.UniqueIdentifier);
                weightDataRepository.SaveWeight(new Weight
                {
                    PatientId = EHealthCareDesktopApp.Properties.Settings.Default.PatientID,
                    Date = dtPicker.SelectedDate.Value,
                    Weight1 = double.Parse(txtWeight.Text.Trim()),
                    WeightGoal = double.Parse(txtWeightGoal.Text.Trim()),
                    UniqueIdentifier = EHealthCareDesktopApp.Properties.Settings.Default.UniqueIdentifier
                });

                if(WeightAddedEvent != null)
                    WeightAddedEvent("Success");
            }
            catch(Exception ex)
            {
                if (WeightAddedEvent != null)
                    WeightAddedEvent(string.Format("Problem in adding Weight: {0}",ex.Message));
            }
        }
コード例 #2
0
        public WeightDataViewModel GetViewModel()
        {
            var weightDataRepository = new WeightDataRepository(Guid.Parse(uniqueGuid));
            var weightDataList = weightDataRepository.GetAllWeightData(patientId);
            double minWeight = 0;
            int prevMonth = DateTime.Now.Date.Month - 1;
            double prevMonthWeight = 0;

            foreach (var item in weightDataList)
            {
                weightDataViewModel.WeightDataEntity.Add(new WeightDataViewEntity
                {
                    Date = item.Date.ToShortDateString(),
                    Weight = item.Weight1
                });

                if(minWeight == 0)
                   minWeight = item.Weight1;

                if (item.Weight1 < minWeight)
                {
                    minWeight = item.Weight1;
                }

                if (item.Date.Month == prevMonth)
                    prevMonthWeight = item.Weight1;
            }

            if (weightDataViewModel.WeightDataEntity.Count > 0)
            {
                weightDataViewModel.WeightRelatedItem.MostRecentWeight = weightDataViewModel.WeightDataEntity[0].Weight;
                weightDataViewModel.WeightRelatedItem.MinWeight = minWeight;
                weightDataViewModel.WeightRelatedItem.LastMonthsChange = Math.Round(weightDataViewModel.WeightRelatedItem.MostRecentWeight - prevMonthWeight, 2);
            }

            // Get Labels
            string lables = "[";
            foreach (var item in weightDataList)
            {
                lables = lables + PutIntoQuotes(item.Date.ToShortDateString()) + ",";
            }
            lables = lables.Substring(0, lables.Length - 1) + "]";

            weightDataViewModel.WeightDataChart.Labels = lables.Replace(@"\", " ");

            // Weight Data
            string weightData = "[";
            string weightGoalData = "[";

            foreach (var item in weightDataList)
            {
                weightData = weightData + item.Weight1.ToString() + ",";
                weightGoalData = weightGoalData + item.WeightGoal.ToString() + ",";
            }

            weightData = weightData.Substring(0, weightData.Length - 1) + "]";
            weightGoalData = weightGoalData.Substring(0, weightGoalData.Length - 1) + "]";

            weightDataViewModel.WeightDataChart.WeightData = weightData;
            weightDataViewModel.WeightDataChart.WeightGoalData = weightGoalData;

            return weightDataViewModel;
        }