173 lines
6.8 KiB
C#
173 lines
6.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.ComponentModel;
|
|
using ProjetTheAlone.Classes;
|
|
using ProjetTheAlone.Gestion;
|
|
using System.Collections.ObjectModel;
|
|
using ProjetTheAlone.Config;
|
|
|
|
namespace ProjetTheAlone.ViewModel
|
|
{
|
|
public class VM_Beneficiaire : BasePropriete
|
|
{
|
|
#region Données Écran
|
|
private string chConnexion = Settings2.Default.schCon /*@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\Hugues\Haute Ecole de la ville de Liège\Adrien VAN DAMME - ProjetTheAlone\ProjetTheAlone\ProjetThe.mdf';Integrated Security = True"*/;
|
|
private int nAjout;
|
|
private bool _ActiverUneFiche;
|
|
public bool ActiverUneFiche
|
|
{
|
|
get { return _ActiverUneFiche; }
|
|
set
|
|
{
|
|
AssignerChamp<bool>(ref _ActiverUneFiche, value, System.Reflection.MethodBase.GetCurrentMethod().Name);
|
|
ActiverBcpFiche = !ActiverUneFiche;
|
|
}
|
|
}
|
|
private bool _ActiverBcpFiche;
|
|
public bool ActiverBcpFiche
|
|
{
|
|
get { return _ActiverBcpFiche; }
|
|
set { AssignerChamp<bool>(ref _ActiverBcpFiche, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
private C_T_beneficiaire _BeneficiaireSelectionnee;
|
|
public C_T_beneficiaire BeneficiaireSelectionnee
|
|
{
|
|
get { return _BeneficiaireSelectionnee; }
|
|
set { AssignerChamp<C_T_beneficiaire>(ref _BeneficiaireSelectionnee, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
#endregion
|
|
#region Données extérieures
|
|
private VM_UnBeneficiaire _UnBeneficiaire;
|
|
public VM_UnBeneficiaire UnBeneficiaire
|
|
{
|
|
get { return _UnBeneficiaire; }
|
|
set { AssignerChamp<VM_UnBeneficiaire>(ref _UnBeneficiaire, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
private ObservableCollection<C_T_beneficiaire> _BcpBeneficiaires= new ObservableCollection<C_T_beneficiaire>();
|
|
public ObservableCollection<C_T_beneficiaire> BcpBeneficiaires
|
|
{
|
|
get { return _BcpBeneficiaires; }
|
|
set { _BcpBeneficiaires = value; }
|
|
}
|
|
#endregion
|
|
|
|
public VM_Beneficiaire()
|
|
{
|
|
UnBeneficiaire = new VM_UnBeneficiaire();
|
|
UnBeneficiaire.ID = 0;
|
|
UnBeneficiaire.Pre = "Prenom";
|
|
UnBeneficiaire.Nom = "Nom";
|
|
UnBeneficiaire.Annif = DateTime.Now.Date;
|
|
BcpBeneficiaires = ChargerPersonnes(chConnexion);
|
|
ActiverUneFiche = false;
|
|
cConfirmer = new BaseCommande(Confirmer);
|
|
cAnnuler = new BaseCommande(Annuler);
|
|
cAjouter = new BaseCommande(Ajouter);
|
|
cModifier = new BaseCommande(Modifier);
|
|
cSupprimer = new BaseCommande(Supprimer);
|
|
}
|
|
|
|
#region Commandes
|
|
public BaseCommande cConfirmer { get; set; }
|
|
public BaseCommande cAnnuler { get; set; }
|
|
public BaseCommande cAjouter { get; set; }
|
|
public BaseCommande cModifier { get; set; }
|
|
public BaseCommande cSupprimer { get; set; }
|
|
#endregion
|
|
|
|
private ObservableCollection<C_T_beneficiaire> ChargerPersonnes(string chConn)
|
|
{
|
|
ObservableCollection<C_T_beneficiaire> rep = new ObservableCollection<C_T_beneficiaire>();
|
|
List<C_T_beneficiaire> lTmp = new G_T_beneficiaire(chConn).Lire("B_nom");
|
|
foreach (C_T_beneficiaire Tmp in lTmp)
|
|
rep.Add(Tmp);
|
|
return rep;
|
|
}
|
|
|
|
public void Confirmer()
|
|
{
|
|
if (nAjout == -1)
|
|
{
|
|
UnBeneficiaire.ID = new G_T_beneficiaire(chConnexion).Ajouter(UnBeneficiaire.Nom, UnBeneficiaire.Pre, UnBeneficiaire.Annif, UnBeneficiaire.Img);
|
|
BcpBeneficiaires.Add(new C_T_beneficiaire(UnBeneficiaire.ID, UnBeneficiaire.Nom, UnBeneficiaire.Pre, UnBeneficiaire.Annif, UnBeneficiaire.Img));
|
|
}
|
|
else
|
|
{
|
|
new G_T_beneficiaire(chConnexion).Modifier(UnBeneficiaire.ID, UnBeneficiaire.Nom, UnBeneficiaire.Pre, UnBeneficiaire.Annif, UnBeneficiaire.Img);
|
|
BcpBeneficiaires[nAjout] = new C_T_beneficiaire(UnBeneficiaire.ID, UnBeneficiaire.Nom, UnBeneficiaire.Pre, UnBeneficiaire.Annif, UnBeneficiaire.Img);
|
|
}
|
|
ActiverUneFiche = false;
|
|
}
|
|
public void Annuler()
|
|
{ ActiverUneFiche = false; }
|
|
public void Ajouter()
|
|
{
|
|
UnBeneficiaire = new VM_UnBeneficiaire();
|
|
UnBeneficiaire.Annif = DateTime.Now;
|
|
nAjout = -1;
|
|
ActiverUneFiche = true;
|
|
}
|
|
public void Modifier()
|
|
{
|
|
if (BeneficiaireSelectionnee != null)
|
|
{
|
|
C_T_beneficiaire Tmp = new G_T_beneficiaire(chConnexion).Lire_ID(BeneficiaireSelectionnee.ID_beneficiaire);
|
|
|
|
UnBeneficiaire = new VM_UnBeneficiaire();
|
|
UnBeneficiaire.ID = Tmp.ID_beneficiaire;
|
|
UnBeneficiaire.Pre = Tmp.B_prenom;
|
|
UnBeneficiaire.Nom = Tmp.B_nom;
|
|
UnBeneficiaire.Annif = Tmp.B_anniversaire.Value;
|
|
UnBeneficiaire.Img = Tmp.B_img;
|
|
nAjout = BcpBeneficiaires.IndexOf(BeneficiaireSelectionnee);
|
|
ActiverUneFiche = true;
|
|
}
|
|
}
|
|
public void Supprimer()
|
|
{
|
|
if (BeneficiaireSelectionnee != null)
|
|
{
|
|
new G_T_beneficiaire(chConnexion).Supprimer(BeneficiaireSelectionnee.ID_beneficiaire);
|
|
BcpBeneficiaires.Remove(BeneficiaireSelectionnee);
|
|
}
|
|
}
|
|
}
|
|
public class VM_UnBeneficiaire : BasePropriete
|
|
{
|
|
private int _ID;
|
|
private string _Nom, _Pre;
|
|
byte?[] _Img;
|
|
private DateTime _Annif;
|
|
|
|
public int ID
|
|
{
|
|
get { return _ID; }
|
|
set { AssignerChamp<int>(ref _ID, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
public string Pre
|
|
{
|
|
get { return _Pre; }
|
|
set { AssignerChamp<string>(ref _Pre, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
public string Nom
|
|
{
|
|
get { return _Nom; }
|
|
set { AssignerChamp<string>(ref _Nom, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
public DateTime Annif
|
|
{
|
|
get { return _Annif; }
|
|
set { AssignerChamp<DateTime>(ref _Annif, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
|
|
public byte?[] Img
|
|
{
|
|
get { return _Img; }
|
|
set { AssignerChamp<byte?[]>(ref _Img, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|
}
|
|
}
|
|
}
|