-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmPasswordChange.cs
81 lines (73 loc) · 2.69 KB
/
frmPasswordChange.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
namespace QuanLyKinhDoanhDienThoai
{
public partial class frmPasswordChange : Form
{
CurrentUser cu;
String pass = "";
SqlConnection conn;
public frmPasswordChange(CurrentUser cu)
{
InitializeComponent();
this.cu = cu;
}
private void btnChangePass_Click(object sender, EventArgs e)
{
AccessData acc = new AccessData();
string StrSQL = Share.select_tblUser;
SqlDataReader reader = acc.ExecuteReader(StrSQL);
while (reader.Read())
{
if (reader[0].ToString() == cu.Username)
{
pass = reader[1].ToString();
break;
}
}
if (txtOld_Pass.Text.CompareTo(pass) != 0)
{
MessageBox.Show("Mật khẩu cũ không đúng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtOld_Pass.Text = "";
txtOld_Pass.Focus();
}
else
{
if (txtNew_Pass.Text.CompareTo(txtNew_Pass_EnterAgain.Text) != 0)
{
MessageBox.Show("Nhập lại mật khẩu mới không đúng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtNew_Pass_EnterAgain.Focus();
}
else
{
cu.Pass = txtNew_Pass.Text;
StrSQL = @"Update [tblUser] set [Pass]=@pass where [Name]=@name";
SqlCommand cmd = new SqlCommand(StrSQL, conn);
cmd.Parameters.Add(new SqlParameter("name", txtUserName.Text));
cmd.Parameters.Add(new SqlParameter("pass", txtNew_Pass.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Mật khẩu thay đổi thành công !");
this.Close();
frmUserInfomation frm_ui = new frmUserInfomation(cu);
frm_ui.Show();
}
}
}
private void frmPasswordChange_Load(object sender, EventArgs e)
{
txtOld_Pass.Focus();
txtUserName.Text = cu.Username;
String strConn = ConfigurationManager.ConnectionStrings["MyConnection"].ToString();
conn = new SqlConnection(strConn);
conn.Open();
}
}
}