-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmChangePassword.cs
93 lines (80 loc) · 3.06 KB
/
frmChangePassword.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
using System;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace POS_System
{
public partial class frmChangePassword : Form
{
SqlConnection cn;
SqlCommand cm;
DBConnection dataBase = new DBConnection();
frmPOS frmPOSRef;
public frmChangePassword(frmPOS frm)
{
InitializeComponent();
cn = new SqlConnection(dataBase.MyConnection());
this.frmPOSRef = frm;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
// fetch old password
string oldPassword = dataBase.GetPassword(frmPOSRef.lblUser.Text);
string newPassword = txtNewPass.Text.Trim();
// verify old password
if (!oldPassword.Equals(txtOldPass.Text))
{
MessageBox.Show("Old password did not matched!".ToUpper(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else if (!txtNewPass.Text.Equals(txtConfirmNewPass.Text))
{
MessageBox.Show("Confirm new password did not matched!".ToUpper(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else
{
if (MessageBox.Show("Change Password?".ToUpper(), "CONFIRM", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
// Update password in DataBase
cn.Open();
cm = new SqlCommand($"UPDATE tblUser SET password = '{newPassword}' WHERE username = '{frmPOSRef.lblUser.Text}'", cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Password has been successfully saved!".ToUpper(), "SAVE CHANGES" , MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Dispose();
}
}
} catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
} finally
{
cn.Close();
}
}
private void txtConfirmNewPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
btnSave.PerformClick();
}
}
private void txtOldPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
txtNewPass.Focus();
}
}
private void txtNewPass_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
txtConfirmNewPass.Focus();
}
}
}
}