ProjetThe/ProjetTheAlone/ViewModel/EncodePlats.cs

170 lines
6.6 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;
2019-01-24 22:24:05 +01:00
using ProjetTheAlone.Config;
2019-01-20 11:46:45 +01:00
namespace ProjetTheAlone.ViewModel
{
public class VM_Plat : BasePropriete
{
#region Données Écran
2019-01-24 22:24:05 +01:00
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"*/;
2019-01-20 11:46:45 +01:00
private int nAjout;
2019-01-25 16:23:52 +01:00
private C_T_plat.TypePlat_E typeplat=0;
2019-01-20 11:46:45 +01:00
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;
2019-01-25 16:23:52 +01:00
Typeplat = C_T_plat.TypePlat_E.Soupe;
2019-01-20 11:46:45 +01:00
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; }
2019-01-25 16:23:52 +01:00
public C_T_plat.TypePlat_E Typeplat { get => typeplat; set =>AssignerChamp<C_T_plat.TypePlat_E>(ref typeplat, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
#endregion
2019-01-20 11:46:45 +01:00
2019-01-25 16:23:52 +01:00
private ObservableCollection<C_T_plat> ChargerPersonnes(string chConn)
2019-01-20 11:46:45 +01:00
{
ObservableCollection<C_T_plat> rep = new ObservableCollection<C_T_plat>();
2019-01-24 22:24:05 +01:00
List<C_T_plat> lTmp = new G_T_plat(chConn).Lire("P_nom");
2019-01-20 11:46:45 +01:00
foreach (C_T_plat Tmp in lTmp)
rep.Add(Tmp);
return rep;
}
public void Confirmer()
{
if (nAjout == -1)
{
2019-01-24 22:24:05 +01:00
UnPlat.ID = new G_T_plat(chConnexion).Ajouter(UnPlat.Nom, UnPlat.Img,(int)UnPlat.TypePlat);
BcpPlats.Add(new C_T_plat(UnPlat.ID, UnPlat.Nom, UnPlat.Img, (int)UnPlat.TypePlat));
2019-01-20 11:46:45 +01:00
}
else
{
2019-01-24 22:24:05 +01:00
new G_T_plat(chConnexion).Modifier(UnPlat.ID, UnPlat.Nom, UnPlat.Img, (int)UnPlat.TypePlat);
BcpPlats[nAjout] = new C_T_plat(UnPlat.ID, UnPlat.Nom, UnPlat.Img, (int)UnPlat.TypePlat);
2019-01-20 11:46:45 +01:00
}
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
{
2019-01-24 22:24:05 +01:00
private int _ID;
Classes.C_T_plat.TypePlat_E _TypePlat;
2019-01-20 11:46:45 +01:00
private string _Nom;
2019-01-24 22:24:05 +01:00
private byte?[] _Img;
2019-01-20 11:46:45 +01:00
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); }
}
2019-01-24 22:24:05 +01:00
public byte?[] Img
2019-01-20 11:46:45 +01:00
{
get { return _Img; }
2019-01-24 22:24:05 +01:00
set { AssignerChamp<byte?[]> (ref _Img, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
2019-01-20 11:46:45 +01:00
}
2019-01-24 22:24:05 +01:00
public Classes.C_T_plat.TypePlat_E TypePlat
2019-01-20 11:46:45 +01:00
{
get { return _TypePlat; }
2019-01-24 22:24:05 +01:00
set { AssignerChamp<Classes.C_T_plat.TypePlat_E>(ref _TypePlat, value, System.Reflection.MethodBase.GetCurrentMethod().Name); }
2019-01-20 11:46:45 +01:00
}
}
}