-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddProfile.cs
134 lines (107 loc) · 4.77 KB
/
AddProfile.cs
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
using System;
using System.Net;
using System.Net.Http;
using System.Windows.Forms;
namespace Horus {
public partial class AddProfile : Form {
String ServerAPIURL = "" + Program.Server;
String GlobalUUID = "";
public AddProfile(String UUID) {
InitializeComponent();
GlobalUUID = UUID;
}
private async void AddNewProfile() {
try {
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
HttpResponseMessage response;
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Program.LogInToken.Trim());
form.Add(new StringContent(this.Tipo.SelectedIndex.ToString()), "profiletype");
form.Add(new StringContent(this.Perfil.Text.Trim()), "profilename");
form.Add(new StringContent(this.CatalogoCNN.Text.Trim()), "catalog");
response = await httpClient.PostAsync(ServerAPIURL + "/api/v2/admin/accounts/users=" + GlobalUUID + "/profiles", form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
String[] RecivedMatrix = response.Content.ReadAsStringAsync().Result.Split('|');
if (RecivedMatrix[0] != "201")
MessageBox.Show(RecivedMatrix[1], "Atención", MessageBoxButtons.OK);
else
this.Close();
}
catch (Exception Ex) {
MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK);
}
}
private void AddProfilesType() {
try {
WebClient webClient = new WebClient();
String response = webClient.DownloadString(ServerAPIURL + "/api/v2/dictionary/profilestype");
String[] RecivedMatrix = response.Split('|');
this.Tipo.Items.Clear();
if (RecivedMatrix[0] == "200") {
String[] UserList = response.Split('\n');
foreach (String User in UserList) {
if (User != "") {
RecivedMatrix = User.Split('|');
String code = RecivedMatrix[0];
String id = RecivedMatrix[1];
String name = RecivedMatrix[2];
if (code == "200") {
this.Tipo.Items.Add(name);
this.Tipo.SelectedIndex = 0;
}
}
}
}
}
catch (Exception Ex) {
MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK);
}
}
private void AddCNNCatalogs() {
try {
WebClient webClient = new WebClient();
String response = webClient.DownloadString(ServerAPIURL + "/api/v2/dictionary/cnncatalogs");
String[] RecivedMatrix = response.Split('|');
this.CatalogoCNN.Items.Clear();
if (RecivedMatrix[0] == "200") {
String[] UserList = response.Split('\n');
foreach (String User in UserList) {
if (User != "") {
RecivedMatrix = User.Split('|');
String code = RecivedMatrix[0];
String id = RecivedMatrix[1];
String name = RecivedMatrix[2];
if (code == "200") {
this.CatalogoCNN.Items.Add(name);
this.CatalogoCNN.SelectedIndex = 0;
}
}
}
}
}
catch (Exception Ex) {
MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK);
}
}
private void Cancelar_Click(object sender, EventArgs e) {
this.Close();
}
private void Aceptar_Click(object sender, EventArgs e) {
AddNewProfile();
}
private void AddProfile_Load(object sender, EventArgs e) {
AddProfilesType();
AddCNNCatalogs();
}
private void Tipo_SelectedIndexChanged(object sender, EventArgs e) {
if (Tipo.SelectedIndex == 1)
CatalogoCNN.Enabled = true;
else
CatalogoCNN.Enabled = false;
}
private void Button1_Click(object sender, EventArgs e) {
this.Close();
}
}
}