155 lines
5.2 KiB
C#
155 lines
5.2 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using ProjetTheAlone.Classes;
|
|||
|
using ProjetTheAlone.Gestion;
|
|||
|
using System.Collections.ObjectModel;
|
|||
|
using System.IO;
|
|||
|
using ProjetTheAlone.Config;
|
|||
|
|
|||
|
namespace ProjetTheAlone.ViewModel
|
|||
|
{
|
|||
|
public class VM_Lieu : 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_lieu _LieuSelectionnee;
|
|||
|
public C_T_lieu LieuSelectionnee
|
|||
|
{
|
|||
|
get { return _LieuSelectionnee; }
|
|||
|
set { AssignerChamp<C_T_lieu>(ref _LieuSelectionnee, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|||
|
}
|
|||
|
#endregion
|
|||
|
#region Données extérieures
|
|||
|
private VM_UnLieu _UnLieu;
|
|||
|
public VM_UnLieu UnLieu
|
|||
|
{
|
|||
|
get { return _UnLieu; }
|
|||
|
set { AssignerChamp<VM_UnLieu>(ref _UnLieu, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|||
|
}
|
|||
|
private ObservableCollection<C_T_lieu> _BcpLieux = new ObservableCollection<C_T_lieu>();
|
|||
|
public ObservableCollection<C_T_lieu> BcpLieux
|
|||
|
{
|
|||
|
get { return _BcpLieux; }
|
|||
|
set { AssignerChamp <ObservableCollection<C_T_lieu>>(ref _BcpLieux, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
public VM_Lieu()
|
|||
|
{
|
|||
|
UnLieu = new VM_UnLieu();
|
|||
|
UnLieu.ID = 0;
|
|||
|
UnLieu.Nom = "Nom du Lieu";
|
|||
|
BcpLieux = 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
|
|||
|
|
|||
|
public ObservableCollection<C_T_lieu> ChargerPersonnes(string chConn)
|
|||
|
{
|
|||
|
ObservableCollection<C_T_lieu> rep = new ObservableCollection<C_T_lieu>();
|
|||
|
List<C_T_lieu> lTmp = new G_T_lieu(chConn).Lire("L_nom");
|
|||
|
foreach (C_T_lieu Tmp in lTmp)
|
|||
|
rep.Add(Tmp);
|
|||
|
return rep;
|
|||
|
}
|
|||
|
|
|||
|
public void Confirmer()
|
|||
|
{
|
|||
|
if (nAjout == -1)
|
|||
|
{
|
|||
|
UnLieu.ID = new G_T_lieu(chConnexion).Ajouter(UnLieu.Nom);
|
|||
|
BcpLieux.Add(new C_T_lieu(UnLieu.ID, UnLieu.Nom));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
new G_T_lieu(chConnexion).Modifier(UnLieu.ID, UnLieu.Nom);
|
|||
|
BcpLieux[nAjout] = new C_T_lieu(UnLieu.ID, UnLieu.Nom);
|
|||
|
}
|
|||
|
ActiverUneFiche = false;
|
|||
|
}
|
|||
|
public void Annuler()
|
|||
|
{ ActiverUneFiche = false; }
|
|||
|
public void Ajouter()
|
|||
|
{
|
|||
|
UnLieu = new VM_UnLieu();
|
|||
|
nAjout = -1;
|
|||
|
ActiverUneFiche = true;
|
|||
|
}
|
|||
|
public void Modifier()
|
|||
|
{
|
|||
|
if (LieuSelectionnee != null)
|
|||
|
{
|
|||
|
C_T_lieu Tmp = new G_T_lieu(chConnexion).Lire_ID(LieuSelectionnee.ID_lieu);
|
|||
|
|
|||
|
UnLieu = new VM_UnLieu();
|
|||
|
UnLieu.ID = Tmp.ID_lieu;
|
|||
|
UnLieu.Nom = Tmp.L_nom;
|
|||
|
|
|||
|
nAjout = BcpLieux.IndexOf(LieuSelectionnee);
|
|||
|
ActiverUneFiche = true;
|
|||
|
}
|
|||
|
}
|
|||
|
public void Supprimer()
|
|||
|
{
|
|||
|
if (LieuSelectionnee != null)
|
|||
|
{
|
|||
|
new G_T_lieu(chConnexion).Supprimer(LieuSelectionnee.ID_lieu);
|
|||
|
BcpLieux.Remove(LieuSelectionnee);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
public class VM_UnLieu : BasePropriete
|
|||
|
{
|
|||
|
private int _ID;
|
|||
|
private string _Nom;
|
|||
|
|
|||
|
|
|||
|
public int ID
|
|||
|
{
|
|||
|
get { return _ID; }
|
|||
|
set { AssignerChamp<int>(ref _ID, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|||
|
}
|
|||
|
|
|||
|
public string Nom
|
|||
|
{
|
|||
|
get { return _Nom; }
|
|||
|
set { AssignerChamp<string>(ref _Nom, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|