Settings.cs
2.99 KB
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
using MoyaAdminLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
namespace Cloakroom
{
public partial class Settings : Form
{
public Settings()
{
InitializeComponent();
}
private void Settings_Load(object sender, EventArgs e)
{
apiURLTextBox.Text = Properties.Settings.Default.ApiURL;
ApiKeyTextBox.Text = Properties.Settings.Default.ApiKey;
ApiUserTextBox.Text = Properties.Settings.Default.ApiUser;
ApiPassTextBox.Text = Properties.Settings.Default.ApiPass;
if (apiURLTextBox.Text != "" && ApiKeyTextBox.Text != "" && ApiUserTextBox.Text != "" && ApiPassTextBox.Text != "")
{
loadReaders();
}
if (Properties.Settings.Default.ReaderId != 0)
{
if (portsComboBox.Items.Count > 0)
{
foreach (object obj in portsComboBox.Items)
{
if (obj is Reader && ((Reader)obj).readerId == Properties.Settings.Default.ReaderId)
{
portsComboBox.SelectedItem = obj;
break;
}
}
}
}
}
private void loadReaders()
{
string ret = "";
RestClient client = new RestClient();
try
{
ret = client.MakeRequest("reader/List");
var ser = new JavaScriptSerializer();
ReaderList readers = ser.Deserialize<ReaderList>(ret);
if (readers != null && readers.readers != null)
{
portsComboBox.Items.Clear();
portsComboBox.Items.Add(" ");
foreach (Reader reader in readers.readers)
{
portsComboBox.Items.Add(reader);
}
}
}
catch (Exception ex)
{
ret = ex.Message;
}
}
private void SaveButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.ApiURL = apiURLTextBox.Text;
Properties.Settings.Default.ApiKey = ApiKeyTextBox.Text;
Properties.Settings.Default.ApiUser = ApiUserTextBox.Text;
Properties.Settings.Default.ApiPass = ApiPassTextBox.Text;
if (portsComboBox.SelectedItem != null && portsComboBox.SelectedItem is Reader)
{
Properties.Settings.Default.ReaderId = ((Reader)portsComboBox.SelectedItem).readerId;
}
Properties.Settings.Default.Save();
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
}