/
LoginForm.cs
80 lines (66 loc) · 2.49 KB
/
LoginForm.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
using MetroFramework;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginForm
{
public partial class LoginForm : MetroFramework.Forms.MetroForm
{
private MySqlConnection connection;
string ConnectionString = ConfigurationManager.AppSettings["connection"];
DataTable table = new DataTable();
public LoginForm()
{
InitializeComponent();
this.ActiveControl = txt_uname;
}
private void btn_login_Click(object sender, EventArgs e)
{
connection = new MySqlConnection(ConnectionString);
try
{
connection.Open();
MySqlCommand cmd = new MySqlCommand("SELECT uname, pword From users Where uname = '" + txt_uname.Text + "' AND pword = '" + txt_pword.Text + "' and status = 'Active'", connection);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
cmd.ExecuteNonQuery();
connection.Close();
int count = ds.Tables[0].Rows.Count;
if (count == 1)
{
MainForm main = new MainForm();
main.FormClosed += new FormClosedEventHandler(mainformclosed);
main.Show();
this.Hide();
}
else
{
btn_cancel.PerformClick();
MetroMessageBox.Show(this, "Invalid Username or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MetroMessageBox.Show(this, ex.Message);
}
}
private void mainformclosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
}
private void btn_cancel_Click(object sender, EventArgs e)
{
txt_uname.Text = "";
txt_pword.Text = "";
}
}
}