1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
[Table]
public class Contact : ViewModelBase, INotifyPropertyChanged, INotifyPropertyChanging
{
#region Constructeur
// Assign handlers for the add and remove operations, respectively.
public Contact()
{
_pret = new EntitySet<Pret>(
new Action<Pret>(this.attach_Pret),
new Action<Pret>(this.detach_Pret)
);
}
#endregion
#region Données
// Define ID: private field, public property, and database column.
private int _contactId;
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int ContactId
{
get { return _contactId; }
set { NotifyPropertyChanged(ref _contactId, value); }
}
private string _prenom;
[Column]
public string Prenom
{
get { return _prenom; }
set { NotifyPropertyChanged(ref _prenom, value); }
}
private string _nom;
[Column]
public string Nom
{
get { return _nom; }
set { NotifyPropertyChanged(ref _nom, value); }
}
private string _email;
[Column]
public string Email
{
get { return _email; }
set { NotifyPropertyChanged(ref _email, value); }
}
private int _montantPrete;
[Column]
public int MontantPrete
{
get { return _montantPrete; }
set { NotifyPropertyChanged(ref _montantPrete, value); }
}
private int _montantEmprunte;
[Column]
public int MontantEmprunte
{
get { return _montantEmprunte; }
set { NotifyPropertyChanged(ref _montantEmprunte, value); }
}
private int _objetsPretes;
[Column]
public int ObjetsPretes
{
get { return _objetsPretes; }
set { NotifyPropertyChanged(ref _objetsPretes, value); }
}
// Define completion value: private field, public property, and database column.
private int _objetsEmpruntes;
[Column]
public int ObjetsEmpruntes
{
get { return _objetsEmpruntes; }
set { NotifyPropertyChanged(ref _objetsEmpruntes, value); }
}
[Column]
internal int _fkutilisateurId;
#endregion
#region Mise en place de la fonction NotifyPropertyChanged<T>
private bool NotifyPropertyChanged<T>(ref T variable, T valeur, [CallerMemberName] string nomPropriete = null)
{
if (object.Equals(variable, valeur)) return false;
NotifyPropertyChanging(nomPropriete);
variable = valeur;
RaisePropertyChanged(nomPropriete);
return true;
}
#endregion
#region INotifyPropertyChanging Members
public event PropertyChangingEventHandler PropertyChanging;
// Used to notify that a property is about to change
private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}
#endregion
#region Relation avec l'utilisateur
// Entity reference, to identify the ToDoCategory "storage" table
private EntityRef<Utilisateur> _utilisateur;
// Association, to describe the relationship between this key and that "storage" table
[Association(Storage = "_utilisateur", ThisKey = "_fkutilisateurId", OtherKey = "UtilisateurId", IsForeignKey = true)]
public Utilisateur Utilisateur
{
get { return _utilisateur.Entity; }
set
{
NotifyPropertyChanging("Utilisateur");
_utilisateur.Entity = value;
if (value != null)
{
_fkutilisateurId = value.UtilisateurId;
}
NotifyPropertyChanging("Utilisateur");
}
}
#endregion
#region Relation avec les prêts
// Entity reference, to identify the Pret "storage" table
private EntitySet<Pret> _pret;
// Association, to describe the relationship between this key and that "storage" table
[Association(Storage = "_pret", OtherKey = "_fkcontactId", ThisKey = "ContactId")]
public EntitySet<Pret> Pret
{
get { return this._pret; }
set { this._pret.Assign(value); }
}
#endregion
#region Functions
// Called during an add operation
private void attach_Pret(Pret pret)
{
NotifyPropertyChanging("Pret");
pret.Contact = this;
}
// Called during a remove operation
private void detach_Pret(Pret pret)
{
NotifyPropertyChanging("Pret");
pret.Contact = null;
}
public void calculMontant(string typePret, int montant, string action)
{
if(action == "ajout")
{
if (typePret == "Prêt")
{
MontantPrete += montant;
}
else if(typePret == "Emprunt")
{
MontantEmprunte += montant;
}
}
else if (action == "suppression")
{
if (typePret == "Prêt")
{
MontantPrete -= montant;
}
else if (typePret == "Emprunt")
{
MontantEmprunte -= montant;
}
}
}
public void calculObjet(string typePret, string action)
{
if (action == "ajout")
{
if (typePret == "Prêt")
{
ObjetsPretes++;
}
else if (typePret == "Emprunt")
{
ObjetsEmpruntes++;
}
}
else if (action == "suppression")
{
if (typePret == "Prêt")
{
ObjetsPretes--;
}
else if (typePret == "Emprunt")
{
ObjetsEmpruntes--;
}
}
}
#endregion
} |
Partager