.net - Binding to a quantity and a measurement unit -
i'm new wpf development , i'm looking advice regarding recurrent databinding pattern within application.
in database i'm working with, there's quite heavy usage of measurement units , associated values.
for sake of demonstration, here's stripped-down table structures might give clues on have work with:
sampletable
- (...)
- quantity
- measurementunitid
- (...)
sampletable2
- (...)
- speed
- distancemeasurementunitid
- timemeasurementunitid
- (...)
sampletable3
- (...)
- distance
- measurementunitid
- (...)
sampletablen (etc...)
- (...)
- weight
- weightmeasurementunitid
- volume
- volumemeasurementunitid
- (...)
measurementunits
- id
- measurementunittypeid
- shortname
- conversionfactor
- (...)
measurementunittypes
- id
- shortname
- (...)
i hope names speaks themselves. :)
the way system works, stored values must in default system unit. user writing 10 meters in ui won't make value stored 10, converted system value before. example, distance value, if distance unit type's default measurement unit centimeters, stored value 1 000, because 1 000 cm = 10 meters.
the measurement unit used user still stored in database, however. ensure next time opens record in ui again, sees 10 meters, not 1 000 cm. converstion must of course performed there too.
there 1 system unit per unit measurement type. it's 1 has conversionfactor set 1. other measurement units has conversionfactor relates that. taking distance exampler higher above:
- cm: 1
- m: 100
- km: 100 000
- (etc.)
in ui, i'd use textbox write number , combobox loaded measurement units filtered on unit type, according context. when user loads data, must appear entered (converted according associated measurement unit). when types in value, binding mechanism must write correct, converted value in entity class, according selected measurement unit's conversionfactor.
when chooses measurement unit, depending on personnal settings, 2 things may happen:
- the displayed number changes , stored number remains same
- the displayed number remains same , stored number converted
now question is... how of functionnality can encapsulate easy reusing? , what's best way of doing this?
please aware might need these fields displayed separately sometimes. in grid example, want column both numeric part , unit part. allowing filtering , sorting on unit alone.
i don't mind having recreate unit list/combo/whatever control everytime. i'm interested in reusing unit conversion part.
thanks reading far (whew!) , ideas can think of. :)
if new wpf, first thing should study model-view-viewmodel pattern.
if structure application way, can create common viewmodel type used of unit list/combo/whatever controls, encapsulates logic of doing unit conversions.
Comments
Post a Comment