1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
namespace Demo
{
public class ViewModel : ViewModelBase
{
public List<string> ToutLesDroits;
public List<string> ToutLesProfils;
private List<Lot> _lots;
public List<Lot> Lots
{
get
{
return _lots;
}
set
{
SetProperty(ref _lots, value);
}
}
private DataTable data;
public DataTable Data
{
get { return data;}
set { SetProperty(ref data, value);}
}
public ViewModel()
{
//Initialisation
ToutLesProfils = new List<string>();
ToutLesProfils.Add("Maintenance1");
ToutLesProfils.Add("Maintenance2");
ToutLesProfils.Add("Maintenance3");
ToutLesProfils.Add("ADMIN");
ToutLesDroits = new List<string>();
ToutLesDroits.Add("LectureSeule");
ToutLesDroits.Add("Copier");
ToutLesDroits.Add("Modifier");
ToutLesDroits.Add("Supprimer");
Lots = new List<Lot>();
List<Profil> listeProfils = new List<Profil>();
List<string> listeDroits = new List<string>();
listeDroits.Add("LectureSeule");
foreach(string profil in ToutLesProfils)
{
listeProfils.Add(new Profil(profil,listeDroits));
}
Lots.Add(new Lot("Lot1", listeProfils, false));
listeDroits.Add("Copier");
foreach (string profil in ToutLesProfils)
{
listeProfils.Add(new Profil(profil, listeDroits));
}
Lots.Add(new Lot("Lot2", listeProfils, true));
CreerTableau();
}
public void CreerTableau()
{
//initialisation du tableau
Data = new DataTable();
Data.Columns.Add("Nom Lot", typeof(string));
Data.Columns.Add("Est Local", typeof(bool));
DataRow ligne;
List<DroitSelect> droitsSelectionnee;
foreach (string p in ToutLesProfils)
{
Data.Columns.Add(p, typeof(List<DroitSelect>)); //Quel type ?
}
foreach (Lot lot in Lots)
{
ligne = data.NewRow();
ligne[0] = lot.Nom;
ligne[1] = lot.Localisation;
for (int i = 2; i < Data.Columns.Count; i++)
{
droitsSelectionnee = new List<DroitSelect>();
foreach (string droit in ToutLesDroits)
{
// ajoute tout les droits dans la liste avec bool = true si droit est dans la liste du profil
droitsSelectionnee.Add(new DroitSelect(droit, lot.Profils.First(p => p.Nom == Data.Columns[i].ColumnName).Droits.FirstOrDefault(d => d == droit) != null));
}
ligne[i] = droitsSelectionnee; //Bloquer -> liste de checkbox
}
Data.Rows.Add(ligne);
}
}
}
public class Profil
{
private List<string> _droits;
private string _nom;
public string Nom
{
get { return _nom; }
set { _nom = value; }
}
public List<string> Droits
{
get { return _droits; }
set { _droits = value; }
}
public Profil(string nom, List<string> droits)
{
Nom = nom;
Droits = new List<string>(droits);
}
}
public class Lot
{
private List<Profil> _profils;
public List<Profil> Profils
{
get { return _profils; }
set { _profils = value; }
}
private string _nom;
public string Nom
{
get { return _nom; }
set { _nom = value; }
}
private bool _localisation;
public bool Localisation
{
get { return _localisation; }
set { _localisation = value; }
}
public Lot(string nom, List<Profil> profils, bool local)
{
Nom = nom;
Profils = new List<Profil>(profils);
Localisation = local;
}
}
public class DroitSelect : BindableBase
{
private string _nom;
public string Nom
{
get { return _nom; }
set { SetProperty(ref _nom, value); }
}
private bool _selectionnee;
public bool Selectionnee
{
get { return _selectionnee; }
set { SetProperty(ref _selectionnee, value); }
}
public DroitSelect(string n, bool select)
{
Nom = n;
Selectionnee = select;
}
}
} |
Partager