-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmLofgin.cs
150 lines (132 loc) · 4.91 KB
/
FrmLofgin.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
using System;
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;
using MySql.Data.MySqlClient;
namespace Hostel_Managment_System
{
public partial class FrmLofgin : Form
{
DB_Function function = new DB_Function();
string query;
public FrmLofgin()
{
InitializeComponent();
}
private void FrmLofgin_Load(object sender, EventArgs e)
{
//query = "select UserID from UserDetails";
//DataSet ds1 = function.GetData(query);
//query = "select Password from UserDetails";
//DataSet ds2 = function.GetData(query);
}
private void BtnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void label3_MouseHover(object sender, EventArgs e)
{
LblCreateAccount.ForeColor = Color.FromArgb(60, 215, 35);
}
private void LblCreateAccount_MouseLeave(object sender, EventArgs e)
{
LblCreateAccount.ForeColor = Color.YellowGreen;
}
private void LblForPass_MouseMove(object sender, MouseEventArgs e)
{
LblForPass.ForeColor = Color.FromArgb(60, 215, 35);
}
private void LblForPass_MouseLeave(object sender, EventArgs e)
{
LblForPass.ForeColor = Color.YellowGreen;
}
private void LblForPass_MouseHover(object sender, EventArgs e)
{
LblForPass.ForeColor = Color.FromArgb(60, 215, 35);
}
private void BtnLogin_Click(object sender, EventArgs e)
{
if (TxtUID.Text != "")
{
Lbl_IDMsg.Visible = false;
MySqlConnection con = new MySqlConnection("data source = MySQL Community Server - GPL;integrated security = True;server=localhost;user=root;database=Hostel;port=3306;password=jinu0292");
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from UserDetails where UserID = '" + TxtUID.Text + "' and Password = '" + TxtPass.Text + "'", con);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
if (dataTable.Rows[i]["UserID"].ToString() == TxtUID.Text && dataTable.Rows[i]["Password"].ToString() == TxtPass.Text)
{
FrnMain frnmain = new FrnMain();
Hide();
frnmain.Show();
}
else if(dataTable.Rows[i]["UserID"].ToString() != TxtUID.Text)
{
Lbl_IDMsg.Visible = true;
}
else
{
LblMsg_InvPass.Visible = true;
}
}
}
else
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
if (dataTable.Rows[i]["UserID"].ToString() != TxtUID.Text)
{
Lbl_IDMsg.Visible = true;
}
else
{
LblMsg_InvPass.Visible = true;
}
}
MessageBox.Show("Invalid credentials...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
Lbl_IDMsg.Visible = true;
Lbl_IDMsg.Text = "Enter user ID.";
}
}
private void LblCreateAccount_Click(object sender, EventArgs e)
{
Frm_CreateAccount ca = new Frm_CreateAccount();
this.Hide();
ca.Show();
}
private void LblForPass_Click(object sender, EventArgs e)
{
Frm_ForgotPassword fp = new Frm_ForgotPassword();
this.Hide();
fp.Show();
}
private void TxtUID_Click(object sender, EventArgs e)
{
if (Lbl_IDMsg.Visible == true)
Lbl_IDMsg.Visible = false;
else
Lbl_IDMsg.Visible = false;
}
private void TxtPass_Click(object sender, EventArgs e)
{
if (LblMsg_InvPass.Visible == true)
LblMsg_InvPass.Visible = false;
else
LblMsg_InvPass.Visible = false;
}
}
}