-
Notifications
You must be signed in to change notification settings - Fork 0
/
Turmas.cs
139 lines (107 loc) · 5.2 KB
/
Turmas.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
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ElearningDesktop
{
class Turmas
{
private int turmaID;
private string turmaName;
private IconsApiResponse turmaIcon;
private string nomeSerie;
private string nomeProfessor;
private ColorsApiResponse turmaColors;
private string turmaRGTeacher;
private Panel turmaPanel;
private Thread getImageThread;
private PictureBox turmaPicture = new PictureBox();
public Turmas(int id, string nome, int idCores, int idicone, int idSerie, string rgProfessor, IconsApiResponse icone, ColorsApiResponse Cores, string nomeSerie, string nomeProfessor, int position)
{
#region Atributos
string[] words = nome.Trim().Split(' ');
if (words.Length > 1) nome = words[0] + " " + words[words.Length - 1];
turmaID = id;
turmaName = nome;
turmaIcon = icone;
turmaColors = Cores;
this.nomeSerie = nomeSerie;
this.nomeProfessor = nomeProfessor;
this.turmaRGTeacher = rgProfessor;
#endregion
#region Div Principal
turmaPanel = new Panel(); //cria uma div
turmaPanel.Size = Styles.seriesSize; //define o tamanho da div
turmaPanel.Location = new Point(20, 20 + (20 + Styles.seriesSize.Height) * (position)); // define a posição da div
turmaPanel.BackColor = Styles.backgroundColor; //define a cor preta para fundo da div
#endregion
#region Imagem
getImageThread = new Thread(new ThreadStart(getImage));
getImageThread.Start();
turmaPicture.BackColor = Color.White;
turmaPicture.Size = new Size(Convert.ToInt32(Styles.seriesSize.Width * 0.05), Convert.ToInt32(Styles.seriesSize.Height * 0.6));
turmaPicture.Padding = new Padding(Convert.ToInt32(Styles.seriesSize.Width * 0.005));
turmaPicture.SizeMode = PictureBoxSizeMode.StretchImage;
turmaPicture.Location = new Point(Convert.ToInt32(turmaPanel.Location.X + 2), Convert.ToInt32((turmaPanel.Size.Height / 2) - (turmaPicture.Size.Height / 2)));
Rectangle rectangle = new Rectangle(0, 0, turmaPicture.Width, turmaPicture.Height);
GraphicsPath roundedImage = Transform.BorderRadius(rectangle, 20, true, true, true, true);
turmaPicture.Region = new Region(roundedImage);
turmaPanel.Controls.Add(turmaPicture);//adiciona o pictureBox na div
#endregion
#region Nome
Label classNameLabel = new Label(); //cria a serie
classNameLabel.Text = turmaName + " " + this.nomeSerie; //define o nome da serie
classNameLabel.Font = Styles.defaultFont;//define a estilização do texto
classNameLabel.AutoSize = true;
classNameLabel.TextAlign = ContentAlignment.MiddleLeft; //alinha o texto ao centro(x) centro(y)
classNameLabel.Location = new Point(Convert.ToInt32(turmaPicture.Location.X + turmaPicture.Size.Width + 10), Convert.ToInt32((turmaPanel.Size.Height / 2) - (classNameLabel.Font.Height / 2)));
turmaPanel.Controls.Add(classNameLabel);//adiciona o label na div
#endregion
#region ID Série
Label nameTeacherLabel = new Label();
nameTeacherLabel.Text = nomeProfessor;
nameTeacherLabel.Font = Styles.customFont;//define a estilização do texto
nameTeacherLabel.Size = new Size(255, nameTeacherLabel.Font.Height);
nameTeacherLabel.TextAlign = ContentAlignment.TopRight;
nameTeacherLabel.Location = new Point(turmaPanel.Width - nameTeacherLabel.Width, Convert.ToInt32(turmaPanel.Size.Height / 2 - nameTeacherLabel.Font.SizeInPoints));
turmaPanel.Controls.Add(nameTeacherLabel);
#endregion
changePanelFormat(turmaPanel);//arredonda a div
}
private void getImage()
{
try
{
WebResponse imageResponse = null;
Stream responseStream;
HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(turmaIcon.Link);
imageResponse = imageRequest.GetResponse();
responseStream = imageResponse.GetResponseStream();
turmaPicture.Image = Image.FromStream(responseStream);
responseStream.Close();
imageResponse.Close();
}
catch
{
turmaPicture.Image = Properties.Resources.user;
}
}
public Panel getTurmaPanel()
{
return turmaPanel;
}
private void changePanelFormat(Panel panel)
{
Rectangle rectangle = new Rectangle(0, 0, panel.Width, panel.Height);
GraphicsPath roundedPanel = Transform.BorderRadius(rectangle, 13, true, true, true, true);
panel.Region = new Region(roundedPanel);
}
}
}