ProjetThe/ProjetTheAlone/ViewModel/PlatsEncode-PC-Bureau.cs

165 lines
6.2 KiB
C#
Raw Normal View History

2019-01-20 11:46:45 +01:00
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;
namespace ProjetTheAlone.ViewModel
{
public class VM_Plat : BasePropriete
{
#region Données Écran
private string chConnexion = Settings1.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 int typeplat=0;
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_plat _PlatSelectionnee;
public C_T_plat PlatSelectionnee
{
get { return _PlatSelectionnee; }
set { AssignerChamp<C_T_plat>(ref _PlatSelectionnee, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
}
#endregion
#region Données extérieures
private VM_UnPlat _UnPlat;
public VM_UnPlat UnPlat
{
get { return _UnPlat; }
set { AssignerChamp<VM_UnPlat>(ref _UnPlat, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
}
private ObservableCollection<C_T_plat> _BcpPlats = new ObservableCollection<C_T_plat>();
public ObservableCollection<C_T_plat> BcpPlats
{
get { return _BcpPlats; }
set { _BcpPlats = value; }
}
#endregion
public VM_Plat()
{
UnPlat = new VM_UnPlat();
UnPlat.ID = 0;
UnPlat.Nom = "Nom du plat";
BcpPlats = 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_plat> ChargerPersonnes(string chConn)
{
ObservableCollection<C_T_plat> rep = new ObservableCollection<C_T_plat>();
List<C_T_plat> lTmp = new G_T_plat(chConn).Lire("B_nom");
foreach (C_T_plat Tmp in lTmp)
rep.Add(Tmp);
return rep;
}
public void Confirmer()
{
if (nAjout == -1)
{
UnPlat.ID = new G_T_plat(chConnexion).Ajouter(UnPlat.Nom, UnPlat.Img,typeplat);
BcpPlats.Add(new C_T_plat(UnPlat.ID, UnPlat.Nom, UnPlat.Img,typeplat));
}
else
{
new G_T_plat(chConnexion).Modifier(UnPlat.ID, UnPlat.Nom, UnPlat.Img,typeplat);
BcpPlats[nAjout] = new C_T_plat(UnPlat.ID, UnPlat.Nom, UnPlat.Img, typeplat);
}
ActiverUneFiche = false;
}
public void Annuler()
{ ActiverUneFiche = false; }
public void Ajouter()
{
UnPlat = new VM_UnPlat();
nAjout = -1;
ActiverUneFiche = true;
}
public void Modifier()
{
if (PlatSelectionnee != null)
{
C_T_plat Tmp = new G_T_plat(chConnexion).Lire_ID(PlatSelectionnee.ID_plat);
UnPlat = new VM_UnPlat();
UnPlat.ID = Tmp.ID_plat;
UnPlat.Nom = Tmp.P_nom;
UnPlat.Img = Tmp.P_img;
nAjout = BcpPlats.IndexOf(PlatSelectionnee);
ActiverUneFiche = true;
}
}
public void Supprimer()
{
if (PlatSelectionnee != null)
{
new G_T_plat(chConnexion).Supprimer(PlatSelectionnee.ID_plat);
BcpPlats.Remove(PlatSelectionnee);
}
}
}
public class VM_UnPlat : BasePropriete
{
private int _ID,_TypePlat;
private string _Nom;
private byte[] _Img;
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); }
}
public byte[] Img
{
get { return _Img; }
set { AssignerChamp<byte[]> (ref _Img, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
}
public int TypePlat
{
get { return _TypePlat; }
set { AssignerChamp<int>(ref _TypePlat, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
}
}
}