ProjetThe/ProjetTheAlone/ViewModel/VM_FicGestionAlert.cs

96 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjetTheAlone.ViewModel
{
public class VM_FicGestionAlert : BasePropriete
{
private ObservableCollection<string> alerteList;
public ObservableCollection<string> AlerteList {
get {
if (Config.Settings1.Default.alerte == null) Config.Settings1.Default.alerte = new StringCollection();
if (alerteList == null) alerteList = new ObservableCollection<string>();
if (alerteList.Count <= Config.Settings1.Default.alerte.Count) {
this.alerteList = new ObservableCollection<string>();
for (int i = 0; i < Config.Settings1.Default.alerte.Count; i++)
alerteList.Add(Config.Settings1.Default.alerte[i]);
}
return alerteList; }
set {
Config.Settings1.Default.alerte.Add(value.Last());
Config.Settings1.Default.Save();
OnPropertyChanged("AlerteList"); } }
public BaseCommande cAjouter { get; set; }
public BaseCommande cEditer { get; set; }
public BaseCommande cDel { get; set; }
public string AlertSelect { get => alertSelect; set { alertSelect = value; OnPropertyChanged("AlertSelect"); } }
public string NouvelleAlert { get => nouvelleAlert; set { nouvelleAlert = value; OnPropertyChanged("NouvelleAlert"); } }
string nouvelleAlert = "";
bool edit = false;
public string btnConfirmtxt { get {if(Edit) return "Mettre à jour"; else return "Ajouter";} }
public bool Edit { get => edit; set { edit = value; OnPropertyChanged("btnConfirmtxt"); } }
public BaseCommande cSuprimer;
string alertSelect = "";
public VM_FicGestionAlert()
{
cAjouter = new BaseCommande(Ajouter);
cEditer = new BaseCommande(EditCMD);
cDel = new BaseCommande(Suprimer);
}
public void Ajouter()
{
if(nouvelleAlert != "")
if(!edit)
{
AlerteList.Add(nouvelleAlert);
Config.Settings1.Default.alerte.Add(nouvelleAlert);
Config.Settings1.Default.Save();
OnPropertyChanged("AlerteList");
}
else
{
int setingIndex = Config.Settings1.Default.alerte.IndexOf(AlertSelect);
int alertListIndex = AlerteList.IndexOf(AlertSelect);
AlerteList[alertListIndex] = NouvelleAlert;
Config.Settings1.Default.alerte[setingIndex] = nouvelleAlert;
Config.Settings1.Default.Save();
Edit = false;
OnPropertyChanged("AlerteList");
}
}
public void Suprimer()
{
int setingIndex = Config.Settings1.Default.alerte.IndexOf(AlertSelect);
int alertListIndex = AlerteList.IndexOf(AlertSelect);
if (setingIndex < 0 && alertListIndex <0)
return;
AlerteList.RemoveAt(alertListIndex);
Config.Settings1.Default.alerte.RemoveAt(setingIndex);
Config.Settings1.Default.Save();
Edit = false;
OnPropertyChanged("AlerteList");
}
public void EditCMD()
{
if (AlertSelect != "" || Edit)
{
Edit = (Edit ? false : true);
NouvelleAlert = AlertSelect;
}
}
}
}