forked from doctorstrange123456/KLTN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmLogin.cs
163 lines (148 loc) · 5.45 KB
/
frmLogin.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.LookAndFeel.Design;
namespace KhoaLuanTotNghiep
{
public partial class frmLogin : DevExpress.XtraEditors.XtraForm
{
public frmLogin()
{
InitializeComponent();
Init_Data();
}
KhoaLuanTotNghiepEntities1 ds = new KhoaLuanTotNghiepEntities1();
private void frmLogin_Load(object sender, EventArgs e)
{
}
private void Save_Data()
{
if (chkGhiNho.Checked)
{
Properties.Settings.Default.UserName = txtUser.Text;
Properties.Settings.Default.PassWord = txtPass.Text;
Properties.Settings.Default.Remme = "yes";
Properties.Settings.Default.Save();
}
else
{
Properties.Settings.Default.UserName = txtUser.Text;
Properties.Settings.Default.PassWord = "";
Properties.Settings.Default.Remme = "no";
Properties.Settings.Default.Save();
}
}
private void Init_Data()
{
if (Properties.Settings.Default.UserName != string.Empty)
{
if (Properties.Settings.Default.Remme == "yes")
{
txtUser.Text = Properties.Settings.Default.UserName;
txtPass.Text = Properties.Settings.Default.PassWord;
chkGhiNho.Checked = true;
}
else
{
txtUser.Text = Properties.Settings.Default.UserName;
}
}
}
private void chkGhiNho_CheckedChanged(object sender, EventArgs e)
{
//if (chkHienThi.Checked )
//{
// txtPass.UseSystemPasswordChar = true;
//}
//else
//{
// txtPass.UseSystemPasswordChar = false;
//}
}
private void btnDangNhap_Click(object sender, EventArgs e)
{
if (UserName.Trim().Length == 0 || PassWord.Trim().Length == 0)
{
XtraMessageBox.Show("Bạn chưa nhập UserName hoặc PassWord!\n\n Mời bạn nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (UserName.Trim().Length != 0 && PassWord.Trim().Length != 0)
{
try
{
var user = ds.tbl_Login.FirstOrDefault(x => x.UserName == UserName);
if (user == null)
{
XtraMessageBox.Show("UserName hoặc PassWord không chính xác!\n\n Mời bạn nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
else
{
if (user.PassWord == PassWord)
{
DialogResult traloi;
traloi = XtraMessageBox.Show("Bạn đã đăng nhập thành công!", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
Save_Data();
this.Hide();
if (traloi == DialogResult.OK)
{
Main main = new Main();
main.Show();
}
}
else
{
XtraMessageBox.Show("UserName hoặc PassWord không chính xác!\n\n Mời bạn nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
catch
{
XtraMessageBox.Show("Lỗi hệ thống !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private string UserName
{
get => (txtUser.Text != null) ? (string)(txtUser.Text) : "";
set => txtUser.Text = value;
}
private string PassWord
{
get => (txtPass.Text != null) ? (string)(txtPass.Text) : "";
set => txtPass.Text = value;
}
private void btnThoat_Click(object sender, EventArgs e)
{
DialogResult traloi;
traloi = XtraMessageBox.Show("Bạn có đồng ý thoát chương trình không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (traloi == DialogResult.OK)
{
this.Close();
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (chkHienThi.Checked)
{
txtPass.UseSystemPasswordChar = true;
}
else
{
txtPass.UseSystemPasswordChar = false;
}
}
private void pnDangNhap_Paint(object sender, PaintEventArgs e)
{
pnDangNhap.BackColor = Color.FromArgb(100, 0, 0, 0);
}
}
}