-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrm_Principal.cs
173 lines (144 loc) · 5.96 KB
/
Frm_Principal.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using GerenciadorDeAcervos.Data.Functions.UsuarioData;
using GerenciadorDeAcervos.Data.Models;
using GerenciadorDeAcervos.Forms;
using GerenciadorDeAcervos.Funcoes;
using GerenciadorDeAcervos.Personalizacao;
using System.Runtime.InteropServices;
using static GerenciadorDeAcervos.Funcoes.GlobalConfiguration;
namespace GerenciadorDeAcervos
{
public partial class Frm_Principal : Form
{
public static Frm_Principal _principal;
public Frm_Principal()
{
_principal = this;
InitializeComponent();
// Caso não haja um usuario cadastrado, ele precisara adicionar o Master
SearchUsuarios searchUsuarios = new();
List<Usuario> userList = searchUsuarios.UsuarioToList();
if (userList.Count == 0)
{
ShowNewForm(typeof(Frm_CadastroUsuario), _principal.panel_Central);
MessageBox.Show("Adicione um usuario 'MASTER'", "Usuario Master", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = string.Empty;
this.ControlBox = false;
this.DoubleBuffered = true;
lbl_ErrorLoginMsg.Visible = false;
Personalisar.CenterLabelInPanel(panel_BarraTitulo, lbl_BarraTitulo);
Personalisar.CenterGroupBoxInPanel(panel_InformacoesInstituicao, gb_InformacoesIntituicao);
}
#region Botões Minimizar/Maximizar/Fechar
private void btn_FecharAplicacao_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void btn_MaximizarAplicacao_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal;
else this.WindowState = FormWindowState.Maximized;
}
private void btn_MinimizarAplicacao_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
#endregion
#region Manuseio do form
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(IntPtr hwnd, int wmsg, int wparam, int lparam);
private void panel_BarraTitulo_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
if (e.Button == MouseButtons.Left && e.Clicks == 2 && e.Y <= SystemInformation.CaptionHeight)
{
if (WindowState == FormWindowState.Maximized) WindowState = FormWindowState.Normal;
else WindowState = FormWindowState.Maximized;
}
}
private void lbl_BarraTitulo_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
if (e.Button == MouseButtons.Left && e.Clicks == 2 && e.Y <= SystemInformation.CaptionHeight)
{
if (WindowState == FormWindowState.Maximized) WindowState = FormWindowState.Normal;
else WindowState = FormWindowState.Maximized;
}
}
private void panel_BarraTitulo_Resize(object sender, EventArgs e)
{
Personalisar.CenterLabelInPanel(panel_BarraTitulo, lbl_BarraTitulo);
}
private void panel_BarraTitulo_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
}
else
{
WindowState = FormWindowState.Maximized;
}
}
private void lbl_BarraTitulo_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
}
else
{
WindowState = FormWindowState.Maximized;
}
}
private void panel_InformacoesInstituicao_Resize(object sender, EventArgs e)
{
Personalisar.CenterGroupBoxInPanel(panel_InformacoesInstituicao, gb_InformacoesIntituicao);
}
private void panel_Central_Resize(object sender, EventArgs e)
{
Personalisar.CenterGroupBoxInPanel(panel_Central, gb_PrincipalLogin);
}
#endregion
// Botão de Login
private void btn_Login_Click(object sender, EventArgs e)
{
btn_Login.Enabled = false;
string nomeUsuario = txtNomeUsuario.Text.ToLower();
string senha = txtSenha.Text;
GlobalConfiguration verificationCredentials = new GlobalConfiguration(nomeUsuario, senha);
Usuario user = verificationCredentials.ConnectionUser();
if (user != null)
{
_principal.gb_InformacoesIntituicao.Visible = true;
enumPermissao permissao = (enumPermissao)user.NivelPermissao;
_principal.lbl_ExibicaoUsuario.Text = user.UsuarioNome;
_principal.lbl_ExibicaoPermissao.Text = permissao.ToString();
_principal.pictureBox_Usuario.Image = verificationCredentials.ConverterParaImagem(user.Imagem);
if (user.NivelPermissao == 0)
{
ShowNewForm(typeof(Frm_Opcoes), _principal.panel_Central);
}
else if (user.NivelPermissao == 1)
{
}
else
{
}
}
else
{
_principal.lbl_ErrorLoginMsg.Text = " Usuario/Senha invalido.";
_principal.lbl_ErrorLoginMsg.Visible = true;
}
btn_Login.Enabled = true;
}
}
}