-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmEditProfile.cs
159 lines (148 loc) · 6.08 KB
/
FrmEditProfile.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
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.Threading.Tasks;
using System.Windows.Forms;
namespace PharmacyAutomation
{
public partial class FrmEditProfile : Form
{
public FrmEditProfile()
{
InitializeComponent();
}
public string personID;
SqlConnection connection = new SqlConnection("Data Source=DESKTOP-2H5V0KB\\SQLEXPRESS;Initial Catalog=DbPharmacy;Integrated Security=True");
public string AdminID()
{
string adminID=null;
connection.Open();
SqlCommand command1 = new SqlCommand("Select AuthorityID From TblAuthority Where AuthorityName = 'admin'", connection);
SqlDataReader dataReader1 = command1.ExecuteReader();
if (dataReader1.Read())
{
adminID = dataReader1[0].ToString();
}
connection.Close();
return adminID;
}
public string IsAdmin(string personID)
{
string adminID = null;
connection.Open();
SqlCommand command = new SqlCommand("Select AuthorityID From TblPersonAuthority Where PersonID=@p1", connection);
command.Parameters.AddWithValue("@p1", personID);
SqlDataReader dataReader = command.ExecuteReader();
if (dataReader.Read())
{
adminID = dataReader[0].ToString();
}
connection.Close();
return adminID;
}
public void GoAdminOrSellerDashboard()
{
if (IsAdmin(personID) == AdminID())
{
FrmAdminDashboard frmAdminDashboard = new FrmAdminDashboard();
frmAdminDashboard.username = txtUserName.Text;
frmAdminDashboard.personID = personID;
frmAdminDashboard.Show();
}
else
{
FrmSellerDashboard frmSellerDashboard = new FrmSellerDashboard();
frmSellerDashboard.username = txtUserName.Text;
frmSellerDashboard.personID = personID;
frmSellerDashboard.Show();
}
}
private void btnBack_Click(object sender, EventArgs e)
{
GoAdminOrSellerDashboard();
Close();
}
private void FrmEditProfile_Load(object sender, EventArgs e)
{
connection.Open();
SqlCommand command1 = new SqlCommand("Select PersonID,PersonName,PersonSurname,UserName,Password From TblPerson Where PersonID=@p1", connection);
command1.Parameters.AddWithValue("@p1", personID);
SqlDataReader dataReader1 = command1.ExecuteReader();
if (dataReader1.Read())
{
txtName.Text = dataReader1["PersonName"].ToString();
txtSurname.Text = dataReader1["PersonSurname"].ToString();
txtUserName.Text = dataReader1["UserName"].ToString();
txtOldPassword.Text = dataReader1["Password"].ToString();
txtOldPassword.UseSystemPasswordChar = false;
txtOldPassword.Enabled = false;
}
connection.Close();
}
private void eyePassword_Click(object sender, EventArgs e)
{
eyePassword.Visible = false;
txtPassword.UseSystemPasswordChar = false;
eyeClosedPassword.Visible = true;
}
private void eyeClosedPassword_Click(object sender, EventArgs e)
{
eyePassword.Visible = true;
txtPassword.UseSystemPasswordChar = true;
eyeClosedPassword.Visible = false;
}
private void eyePasswordRepeat_Click(object sender, EventArgs e)
{
eyePasswordRepeat.Visible = false;
txtPasswordRepeat.UseSystemPasswordChar = false;
eyeClosedPasswordRepeat.Visible = true;
}
private void eyeClosedPasswordRepeat_Click(object sender, EventArgs e)
{
eyePasswordRepeat.Visible = true;
txtPasswordRepeat.UseSystemPasswordChar = true;
eyeClosedPasswordRepeat.Visible = false;
}
private void btnSave_Click(object sender, EventArgs e)
{
if (txtPassword.Text != txtOldPassword.Text)
{
if (txtPassword.Text == txtPasswordRepeat.Text)
{
connection.Open();
SqlCommand command = new SqlCommand("Update TblPerson Set PersonName=@p1,PersonSurname=@p2,UserName=@p3,Password=@p4 Where PersonID=@p5", connection);
command.Parameters.AddWithValue("@p1", txtName.Text);
command.Parameters.AddWithValue("@p2", txtSurname.Text);
command.Parameters.AddWithValue("@p3", txtUserName.Text);
command.Parameters.AddWithValue("@p4", txtPassword.Text);
command.Parameters.AddWithValue("@p5", personID);
command.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Hesabınız başarıyla güncellendi", "Bilgi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
GoAdminOrSellerDashboard();
//FrmAdminDashboard frmAdminDashboard = new FrmAdminDashboard();
//frmAdminDashboard.username = txtUserName.Text;
//frmAdminDashboard.personID = personID;
//frmAdminDashboard.Show();
Close();
}
else
{
MessageBox.Show("Şifreler birbiriyle eşleşmiyor", "Uyarı", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("Lütfen eski şifrenizden farklı bir şifre giriniz", "Uyarı", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
}
}