Blogs

Gary's Blog

Keeping Fit With XAF #2

     

In the first post in this series we looked at creating a WeightRecord. Today, we are going to look at adding TrainingProgrammes and TrainingRecords. First, however, we are going to tidy up the WeightRecord from last time and implement a suggestion from Chris Royle, to add BMI to the class.

So once we’ve added BMI and take input of height in metres and weight in kilos, our class now looks like this:

using System;
using DevExpress.Xpo;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;

namespace Solution12.Module
{
    [DefaultClassOptions]
    public class WeightRecord : BaseObject
    {
        public WeightRecord(Session session) : base(session) { }

        private DateTime _Date;
        public DateTime Date
        {
            get
            {
                return _Date;
            }
            set
            {
                SetPropertyValue("Date", ref _Date, value);
            }
        }

        private double _HeightInMetres;
        public double HeightInMetres
        {
            get
            {
                return _HeightInMetres;
            }
            set
            {
                SetPropertyValue("HeightInMetres", ref _HeightInMetres, value);
            }
        }

        private int _WeightInKilos;
        public int WeightInKilos
        {
            get
            {
                return _WeightInKilos;
            }
            set
            {
                SetPropertyValue("WeightInKilos", ref _WeightInKilos, value);
            }
        }
        
        [Persistent]
        public double BMI
        {
            get
            {
                return (WeightInKilos == 0 || HeightInMetres == 0) ? 0 :
                    WeightInKilos / (HeightInMetres * HeightInMetres);
            }
        }
    }
}

Now we want to add two more classes. TrainingProgramme which will record activity on a particular exercise machine and TrainingRecord, which will record the date on which a particular TrainingProgramme was executed. These two classes look like this:

using System;
using DevExpress.Xpo;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;

namespace Solution12.Module
{
    [DefaultClassOptions]
    public class TrainingProgramme : BaseObject
    {
        public TrainingProgramme(Session session) : base(session) { }

        private string _Machine;
        public string Machine
        {
            get
            {
                return _Machine;
            }
            set
            {
                SetPropertyValue("Machine", ref _Machine, value);
            }
        }

        private int _Level;
        public int Level
        {
            get
            {
                return _Level;
            }
            set
            {
                SetPropertyValue("Level", ref _Level, value);
            }
        }

        private int _DurationInMinutes;
        public int DurationInMinutes
        {
            get
            {
                return _DurationInMinutes;
            }
            set
            {
                SetPropertyValue("DurationInMinutes", ref _DurationInMinutes, value);
            }
        }

        private TrainingRecord _TrainingRecord;
        [Association("TrainingRecord-TrainingProgrammes")]
        public TrainingRecord TrainingRecord
        {
            get
            {
                return _TrainingRecord;
            }
            set
            {
                SetPropertyValue("TrainingRecord", ref _TrainingRecord, value);
            }
        }
    }
}
using System;
using DevExpress.Xpo;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;

namespace Solution12.Module
{
    [DefaultClassOptions]
    public class TrainingRecord : BaseObject
    {
        public TrainingRecord(Session session) : base(session) { }

        private DateTime _Date;
        public DateTime Date
        {
            get
            {
                return _Date;
            }
            set
            {
                SetPropertyValue("Date", ref _Date, value);
            }
        }

        [Association("TrainingRecord-TrainingProgrammes")]
        public XPCollection<TrainingProgramme> TrainingProgrammes
        {
            get
            {
                return GetCollection<TrainingProgramme>("TrainingProgrammes");
            }
        }
    }

}

Giving us the following UI:

image

image

So, that about wraps it up for today. Next time we’ll tidy up the UI and add reporting to our fitness application. Until then happy XAFing! :-)

Published Feb 22 2010, 01:48 PM by Gary Short (DevExpress)
Filed under:
Technorati tags: XAF
Bookmark and Share

Comments

 

Chloe Anfield said:

Thanks for the name mention Gary, but .... :D I think you'll find that I mentioned body fat % rather than BMI. BMI is a somewhat useless measure if you're losing fat and gaining muscle.

Also, am I being daft, but by adding height to your weight record are you suggesting that you're expecting to be growing / shrinking over the course of your fitness regime ? ;)

You could extend your TrainingRecord class to make use of the conditional editors to capture distance / total weight as well, depending on machine type. Also, total kilo-calories and average heart rate will be worthwhile additions - most cardio machines will estimate and report these.

February 22, 2010 9:23 AM
 

Adam Leffert said:

Gary,

For your "BMI" property, you calculate a value.  You then mark the property as persistent, so it is stored in the db.  So far so good.

Will this property work with filtering in list views with ServerMode=true?

If not, what is the simplest way to get this feature to work?

Thanks,

Adam

March 7, 2010 12:46 PM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.