-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminMembermgmt.aspx.cs
208 lines (191 loc) · 6.58 KB
/
AdminMembermgmt.aspx.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace e_Library_mgmt
{
public partial class WebForm8 : System.Web.UI.Page
{
string Conx = ConfigurationManager.ConnectionStrings["cLibrary"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
Session["role"] = "admin";
GridView1.DataBind();
}
//Search Button
protected void Button1_Click(object sender, EventArgs e)
{
GetMemberByID();
}
void GetMemberByID()
{
SqlConnection Connx = new SqlConnection(Conx);
try
{
if (Connx.State == ConnectionState.Closed)
{
Connx.Open();
}
SqlCommand cmd = new SqlCommand("Select * from Member_Master_tbl where " +
"Member_Id = '" + TextBox1.Text.Trim() + "'", Connx);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows) //if dr gets any rows with memeberid=entry
{
while (dr.Read())
{
TextBox2.Text = dr.GetValue(0).ToString();
//get the value from the dr object, retrieve the first placeholder value, and store it in the textbox
TextBox3.Text = dr.GetValue(10).ToString();
TextBox4.Text = dr.GetValue(1).ToString();
TextBox5.Text = dr.GetValue(2).ToString();
TextBox6.Text = dr.GetValue(3).ToString();
TextBox7.Text = dr.GetValue(4).ToString();
TextBox8.Text = dr.GetValue(5).ToString();
TextBox9.Text = dr.GetValue(6).ToString();
TextBox10.Text = dr.GetValue(7).ToString();
}
}
else
{
Response.Write("<script>alert('Invalid Credentials');</script>");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Connx.Close();
}
}
//Active
protected void Button2_Click(object sender, EventArgs e)
{
UpdateMemberStatusbyID("active");
}
//Pending
protected void Button3_Click(object sender, EventArgs e)
{
UpdateMemberStatusbyID("pending");
}
//Deactivate
protected void Button4_Click(object sender, EventArgs e)
{
UpdateMemberStatusbyID("deactive");
}
void UpdateMemberStatusbyID(string status)
{
SqlConnection Connx = new SqlConnection(Conx);
try
{
if (Connx.State == ConnectionState.Closed)
{
Connx.Open();
}
SqlCommand cmd = new SqlCommand("Update Member_Master_tbl Set Account_Status='"+status+"'" +
" where Member_Id = '" + TextBox1.Text.Trim() + "'", Connx);
//Update Acc stautus with the set parameter, where memberid=entry
cmd.ExecuteNonQuery(); //execute statement against connx
GridView1.DataBind();
Response.Write("<script>alert('Member Status Updated');</script>");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Connx.Close();
}
}
//DeleteUser
protected void Button5_Click(object sender, EventArgs e)
{
if (CheckIfMemberExists())
{
DeleteUser();
}
else
{
Response.Write("<script>alert('Member doesn't Exists!!');</script>");
}
}
void DeleteUser()
{
SqlConnection con = new SqlConnection(Conx);
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("Delete from Member_Master_tbl " +
"Where Member_Id= '" + TextBox1.Text.Trim() + "'", con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Member Deleted Successfully');</script>");
ClearForm();
GridView1.DataBind(); //Bind Datasource to the gridview
//Response.Redirect("homepage.aspx", false);
//string message = "Sign Up was Successful";
//MessageBox.Show(message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
bool CheckIfMemberExists()
{
try
{
SqlConnection con = new SqlConnection(Conx);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("Select * from Member_Master_tbl where " +
"Member_Id='" + TextBox1.Text.Trim() + "';", con); //Tsqlcmmd to execute against the sql database
SqlDataAdapter da = new SqlDataAdapter(cmd); //Disconnected connection model, open and closes the connection
DataTable dt = new DataTable(); //Create Datatable object to temporarily store the executed cmd
da.Fill(dt); //
if (dt.Rows.Count >= 1)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
void ClearForm()
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox10.Text = "";
}
}
}