This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGradeWindow.cs
128 lines (112 loc) · 5.65 KB
/
GradeWindow.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
using Newtonsoft.Json;
using System;
using System.Drawing;
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace lxMeets {
public partial class GradeWindow : Form {
private readonly WebClient client = new WebClient();
string cedula = "";
string anioLectivo = "";
public GradeWindow() {
InitializeComponent();
if (Properties.Settings.Default.Cedula.Length > 2 && Properties.Settings.Default.UseDefaultCed) { cedula = Properties.Settings.Default.Cedula; } else {
cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula", true);
anioLectivo = cedula.Split('[', ']')[1];
cedula = cedula.Split('(', ')')[1];
while ((cedula.Length < 9 && cedula.Length > 0) || !Regex.IsMatch(cedula, @"^\d+$")) {
if (cedula == "Cancel") break;
MessageBox.Show("Cédula Inválida"); cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula");
}
}
if (cedula != "Cancel") FetchAPI(cedula, anioLectivo);
}
private async void FetchAPI(string cedula, string anioLect) {
try {
carreraLabel.Visible = false;
nombresLabel.Visible = false;
label1.Visible = false;
facultadLabel.Visible = false;
label2.Visible = false;
tablaParcial.Visible = false;
tablaPromedio.Visible = false;
string url = @"https://api.lxndr.dev/uae/notas/?ced=" + cedula + "&alectivo=" + anioLect;
if (cedula.Length == 0) this.Close();
var json = await client.DownloadStringTaskAsync(url);
dynamic stuff = JsonConvert.DeserializeObject(json);
if ((bool)stuff.error) { MessageBox.Show(stuff.message.ToString()); this.Close(); }
otraCButton.Visible = true;
nombresLabel.Text = stuff.apellidos + " " + stuff.nombres;
carreraLabel.Text = stuff.carrera;
facultadLabel.Text = stuff.facultad;
GenerateTable(stuff.parciales.Count, stuff.parciales[0].Count, tablaParcial, stuff, "parciales");
GenerateTable(stuff.promedios.Count, stuff.promedios[0].Count, tablaPromedio, stuff, "promedios");
label1.Visible = true;
label2.Visible = true;
tablaParcial.Visible = true;
carreraLabel.Visible = true;
nombresLabel.Visible = true;
facultadLabel.Visible = true;
tablaPromedio.Visible = true;
cargandoPicture.Visible = false;
} catch (Exception e) { }
}
private void GenerateTable(int rowCount, int columnCount, TableLayoutPanel tableController, dynamic stuff, string tipo) {
tableController.Controls.Clear();
tableController.ColumnStyles.Clear();
tableController.RowStyles.Clear();
tableController.AutoScroll = true;
tableController.ColumnCount = columnCount;
tableController.RowCount = rowCount;
for (int x = 0; x < columnCount; x++) {
tableController.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
for (int y = 0; y < rowCount; y++) {
if (x == 0) {
tableController.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
Label cmd = new Label {
AutoSize = true
};
if (y == 0) {
cmd.AutoSize = false;
cmd.TextAlign = ContentAlignment.MiddleCenter;
cmd.Font = new Font(cmd.Font, FontStyle.Bold);
cmd.Dock = DockStyle.None;
}
cmd.ForeColor = Color.White;
cmd.Text = stuff[tipo][y][x].ToString();
tableController.Controls.Add(cmd, x, y);
}
}
}
private void OtraCButton_Click(object sender, EventArgs e) {
cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula", true);
anioLectivo = cedula.Split('[', ']')[1];
cedula = cedula.Split('(', ')')[1];
while ((cedula.Length < 9 && cedula.Length > 0) || !Regex.IsMatch(cedula, @"^\d+$")) {
if (cedula == "Cancel") break;
MessageBox.Show("Cédula Inválida"); cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula");
}
if (cedula == "Cancel") return;
cargandoPicture.Visible = true;
otraCButton.Visible = false;
FetchAPI(cedula, anioLectivo);
}
private void GradeWindow_Shown(object sender, EventArgs e) {
if (cedula == "Cancel") this.Close();
}
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
private void BarraTitulo_MouseDown(object sender, MouseEventArgs e) {
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
}
private void CerrarButton_Click(object sender, EventArgs e) {
this.Close();
}
}
}