Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update Fields
Message
De
13/01/2010 10:05:20
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
13/01/2010 08:49:20
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Network:
Windows 2008 Server
Database:
VistaDB
Application:
Desktop
Divers
Thread ID:
01443663
Message ID:
01443683
Vues:
39
Hi Antonio,

>Hi all,
>
>I have an MM .NET 3.5 Entity with some fields. I need one of them to be updated from the value of two others, a division. I have created this code:
>
>	public partial class MuestrasEntity : ABusinessEntity
>	{
>		/// <summary>
>		/// MuestrasPK
>		/// </summary>
>		public int MuestrasPK
>		{
>			get
>			{
>				if (this.Row != null)
>					return (int)mmType.GetNonNullableDbValue(this.Row["MuestrasPK"], "System.Int32");
>				else
>					return this._muestrasPK;
>			}
>			set
>			{
>				if (this.Row != null)
>					this.Row["MuestrasPK"] = value; 
>				this._muestrasPK = value;
>				this.OnPropertyChanged(new PropertyChangedEventArgs("MuestrasPK"));
>			}
>		}
>		private int _muestrasPK;
>
>		/// <summary>
>		/// ValorTotal
>		/// </summary>
>		public decimal ValorTotal
>		{
>			get
>			{
>				if (this.Row != null)
>					return (decimal)mmType.GetNonNullableDbValue(this.Row["ValorTotal"], "System.Decimal");
>				else
>					return this._valorTotal;
>			}
>			set
>			{
>				if (this.Row != null)
>					this.Row["ValorTotal"] = value; 
>				this._valorTotal = value;
>				this.OnPropertyChanged(new PropertyChangedEventArgs("ValorTotal"));
>                this.SetValorUnitario();
>			}
>		}
>		private decimal _valorTotal;
>
>		/// <summary>
>		/// Superficie
>		/// </summary>
>		public Single Superficie
>		{
>			get
>			{
>				if (this.Row != null)
>					return (Single)mmType.GetNonNullableDbValue(this.Row["Superficie"], "System.Single");
>				else
>					return this._superficie;
>			}
>			set
>			{
>				if (this.Row != null)
>					this.Row["Superficie"] = value; 
>				this._superficie = value;
>				this.OnPropertyChanged(new PropertyChangedEventArgs("Superficie"));
>                                                                                      this.SetValorUnitario();
>			}
>		}
>		private Single _superficie;
>
>		/// <summary>
>		/// ValorUnitario
>		/// </summary>
>		public decimal ValorUnitario
>		{
>			get
>			{
>				if (this.Row != null)
>					return (decimal)mmType.GetNonNullableDbValue(this.Row["ValorUnitario"], "System.Decimal");
>				else
>					return this._valorUnitario;
>			}
>			set
>			{
>				if (this.Row != null)
>					this.Row["ValorUnitario"] = value; 
>				this._valorUnitario = value;
>				this.OnPropertyChanged(new PropertyChangedEventArgs("ValorUnitario"));
>                                                                                     this.SetValorHomogeneo();
>			}
>		}
>		private decimal _valorUnitario;
>
>                                           private void SetValorUnitario()
>                                           {
>                                                      if (this.Superficie != 0) this.ValorUnitario = this.ValorTotal / (decimal)this.Superficie;
>                                           }
>
>                }
>
>
>
>I have created a SetValorUnitario Method in the entity class in order to make a division whenever the two other two fields are updated, and added the method after the onPropertyChanged() method.
>
>I feel that I can do it using events properly.
>
>Is there any proper way to do this?
>
>Thanks in advance

Other ideas to consider. You could add a validate method that does this and also verifes the two fields involved for proper values. If rules are not an issue and the two fields would always be valid, then you could add to the PreSave Hook method.
Tim
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform