sicpaconnexions / SICPA_Connexions / ViewModel / SettingsViewModel.cs @ 03682d21
Historique | Voir | Annoter | Télécharger (3,021 ko)
1 |
using SICPA_Connexions.Model; |
---|---|
2 |
using SICPA_Connexions.ViewModel.Base; |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
using System.Windows.Input; |
9 |
|
10 |
namespace SICPA_Connexions.ViewModel |
11 |
{ |
12 |
public class SettingsViewModel : BaseViewModel |
13 |
{ |
14 |
#region Attributs |
15 |
private bool connexionOK; |
16 |
private bool connexionNOK; |
17 |
private string nomBLE; |
18 |
|
19 |
#endregion |
20 |
|
21 |
#region Propriétés |
22 |
public bool ConnexionOK |
23 |
{ |
24 |
get { return connexionOK; } |
25 |
set |
26 |
{ |
27 |
if (connexionOK != value) |
28 |
{ |
29 |
connexionOK = value; |
30 |
OnPropertyChanged(nameof(ConnexionOK)); |
31 |
} |
32 |
} |
33 |
} |
34 |
|
35 |
public bool ConnexionNOK |
36 |
{ |
37 |
get { return connexionNOK; } |
38 |
set |
39 |
{ |
40 |
if (connexionNOK != value) |
41 |
{ |
42 |
connexionNOK = value; |
43 |
OnPropertyChanged(nameof(ConnexionNOK)); |
44 |
} |
45 |
} |
46 |
} |
47 |
|
48 |
public string NomBLE |
49 |
{ |
50 |
get { return nomBLE; } |
51 |
set |
52 |
{ |
53 |
if (nomBLE != value) |
54 |
{ |
55 |
nomBLE = value; |
56 |
OnPropertyChanged(nameof(NomBLE)); |
57 |
} |
58 |
} |
59 |
} |
60 |
|
61 |
#endregion |
62 |
|
63 |
#region Commandes |
64 |
public ICommand ConnexionBLECommand { get; private set; } |
65 |
#endregion |
66 |
|
67 |
#region Constructeurs |
68 |
public SettingsViewModel() |
69 |
{ |
70 |
if (GlobalApplication.GestionnaireBLE == null) |
71 |
{ |
72 |
GlobalApplication.GestionnaireBLE = new GestionnaireBLE(); |
73 |
ChangeConnexion(false); |
74 |
NomBLE = ""; |
75 |
} |
76 |
if (GlobalApplication.GestionnaireBLE.DeviceConnected != null) |
77 |
{ |
78 |
ChangeConnexion(true); |
79 |
NomBLE = GlobalApplication.GestionnaireBLE.DeviceConnected.Name; |
80 |
} |
81 |
ConnexionBLECommand = new Command(async () => await ConnexionBLE()); |
82 |
} |
83 |
#endregion |
84 |
|
85 |
#region Méthodes |
86 |
private async Task ConnexionBLE() |
87 |
{ |
88 |
IsBusy = true; |
89 |
if (GlobalApplication.GestionnaireBLE.DeviceConnected == null) |
90 |
{ |
91 |
//Scan des BLE |
92 |
await GlobalApplication.GestionnaireBLE.ScanBLE(); |
93 |
ChangeConnexion(GlobalApplication.GestionnaireBLE.DeviceConnected != null); |
94 |
if (GlobalApplication.GestionnaireBLE.DeviceConnected != null) |
95 |
{ |
96 |
NomBLE = GlobalApplication.GestionnaireBLE.DeviceConnected.Name; |
97 |
} |
98 |
} |
99 |
IsBusy = false; |
100 |
} |
101 |
|
102 |
private void ChangeConnexion(bool ok) |
103 |
{ |
104 |
ConnexionOK = ok; |
105 |
ConnexionNOK = !ok; |
106 |
} |
107 |
|
108 |
#endregion |
109 |
} |
110 |
} |