-
Notifications
You must be signed in to change notification settings - Fork 2
/
frmInicioSesion.cs
168 lines (142 loc) · 4.97 KB
/
frmInicioSesion.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
using System;
using MySql.Data.MySqlClient;
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.Windows.Forms;
namespace Bubble_Information_System
{
public partial class FrmInicioSesion : Form
{
private MySqlConnection conexionDB;
private MySqlCommand sqlComando;
private MySqlDataAdapter adaptador;
public FrmInicioSesion()
{
InitializeComponent();
MySqlConnectionStringBuilder strConstructor = new MySqlConnectionStringBuilder();
strConstructor.Server = "localhost";
strConstructor.UserID = "root";
strConstructor.Password = "";
strConstructor.Database = "dbLavanderia";
try
{
this.conexionDB = new MySqlConnection(strConstructor.ToString());
}
catch (MySqlException e)
{
MessageBox.Show(e.ToString());
}
}
private void btnIniciarSesion_Click(object sender, EventArgs e)
{
String usuario = this.txtUsuario.Text;
String password = this.txtContrasena.Text;
if ( ( usuario != "" ) && ( password != "" ))
{
logear(usuario, password);
}
else
{
MessageBox.Show("Porfavor rellene ambos campos", "Bubble Information System");
}
}
public void logear(string nombreUsuario, string contraseña)
{
try
{
conexionDB.Open();
sqlComando = new MySqlCommand("select nombreUsuario, tipoUsuario, numEmpleado from usuario where nombreUsuario =?nombreUsuario and contraseña =?contraseña and status = 0 ", conexionDB);
sqlComando.Parameters.AddWithValue("nombreUsuario", nombreUsuario);
sqlComando.Parameters.AddWithValue("contraseña", contraseña);
adaptador = new MySqlDataAdapter(sqlComando);
DataTable dt = new DataTable();
adaptador.Fill(dt);
if (dt.Rows.Count == 1)
{
this.Hide();
if (dt.Rows[0][1].ToString() == "Administrador")
{
MenuAd meA = new MenuAd(Convert.ToInt32(dt.Rows[0][2]));
meA.ShowDialog();
this.Close();
}
else if (dt.Rows[0][1].ToString() == "Usuario")
{
MenuUs meU = new MenuUs(Convert.ToInt32(dt.Rows[0][2]));
meU.ShowDialog();
this.Close();
}
}
else
{
MessageBox.Show("El usuario y/o contraseña es incorrecto", "Bubble Information System");
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
conexionDB.Close();
}
}
private void controlUsuario()
{
if (txtUsuario.Text.Trim() != string.Empty && txtContrasena.Text.Trim() != string.Empty)
{
btnIniciarSesion.Enabled = true;
}
if (txtUsuario.Text.Trim() != string.Empty)
{
errorProvider1.SetError(txtUsuario, "");
}
else
{
errorProvider1.SetError(txtUsuario, "Debe introducir el usuario");
btnIniciarSesion.Enabled = false;
txtUsuario.Focus();
}
}
private void controlContrasena()
{
if (txtUsuario.Text.Trim() != string.Empty && txtContrasena.Text.Trim() != string.Empty)
{
btnIniciarSesion.Enabled = true;
}
if (txtContrasena.Text.Trim() != string.Empty)
{
errorProvider1.SetError(txtContrasena, "");
}
else
{
errorProvider1.SetError(txtContrasena, "Debe introducir el usuario");
btnIniciarSesion.Enabled = false;
txtUsuario.Focus();
}
}
private void txtUsuario_TextChanged(object sender, EventArgs e)
{
controlUsuario();
}
private void txtContrasena_TextChanged(object sender, EventArgs e)
{
controlContrasena();
}
private void txtContrasena_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == (int)Keys.Enter)
{
btnIniciarSesion_Click(null, null);
}
}
private void FrmInicioSesion_Load(object sender, EventArgs e)
{
}
}
}