-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login.cs
107 lines (91 loc) · 2.83 KB
/
Login.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace HRM
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
if (txtID.Text.Trim() == "")
{
MessageBox.Show("Please Enter User Name");
txtID.Focus();
return;
}
if (txtPass.Text.Trim() == "")
{
MessageBox.Show("Please Enter Password");
txtPass.Focus();
return;
}
if (DbAccess.recordExist("select * from Employee_Info where UserName='" + txtID.Text.Trim() + "' and Password='" + txtPass.Text + "'"))
{
VariableDecleration_Class.sLoginStatus = 1;
string connectionStr = DbAccess.connectionString;
SqlCommand cm = new SqlCommand();
SqlConnection cn = new SqlConnection(connectionStr);
try
{
cn.Open();
cm.Connection = cn;
cm.CommandText = "SELECT * FROM Employee_Info where UserName='" + txtID.Text.Trim() + "' and Password='" + txtPass.Text.Trim() + "'";
SqlDataReader reader;
reader = cm.ExecuteReader();
while (reader.Read())
{
VariableDecleration_Class.sUserType = reader["UserType"].ToString();
VariableDecleration_Class.sUserName = reader["UserName"].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
this.Close();
}
else
{
MessageBox.Show("Invalid User ID or Password");
txtID.Focus();
return;
}
}
private void Login_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
btnConnect_Click(this, e);
}
}
private void txtID_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
txtPass.Focus();
}
}
}
}