-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.aspx.cs
182 lines (176 loc) · 6.93 KB
/
update.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace ASPWebApplication
{
public partial class update : System.Web.UI.Page
{
static string connectName = "MS:SQL2019 Bağlantısı"; //web.config dosyasında yer alan bağlantıya atanmış isim/name
static SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings[connectName].ConnectionString);
static string query;
void updateOpen()
{
//ID.Enabled = true;
UserID.Enabled = true;
Password.Enabled = true;
EMail.Enabled = true;
Name.Enabled = true;
Surname.Enabled = true;
regSex.Enabled = true;
Phone.Enabled = true;
}
void updateClose()
{
//ID.Enabled = false;
UserID.Enabled = false;
Password.Enabled = false;
EMail.Enabled = false;
Name.Enabled = false;
Surname.Enabled = false;
regSex.Enabled = false;
Phone.Enabled = false;
}
void clear()
{
//ID.Text = "";
UserID.Text = "";
Password.Text = "";
EMail.Text = "";
Name.Text = "";
Surname.Text = "";
regSex.SelectedValue = null;
Phone.Text = "";
}
void reload()
{
ID.Text = "";
clear();
ID.Enabled = true;
SelectButton.Enabled = true;
ProcessButton.Text = "İşlem";
ProcessButton.Enabled = false;
ProcessSelect.Items[0].Enabled = true;
ProcessSelect.SelectedIndex = 0;
ProcessSelect.Enabled = false;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["SessionID"] != null)
{
}
else
{
Response.Redirect("login.aspx");
login login = new login();
login.target = "update.aspx";
}
}
protected void Process_SelectedIndexChanged(object sender, EventArgs e)
{
if (ProcessSelect.SelectedValue == "Update")
{
ProcessButton.Text = "Güncelle";
ProcessButton.Enabled = true;
ID.Enabled = false;
SelectButton.Enabled = false;
ProcessSelect.Items[0].Enabled = false;
updateOpen();
}
else if (ProcessSelect.SelectedValue == "Delete")
{
ProcessButton.Text = "Kaldır";
ProcessButton.Enabled = true;
ID.Enabled = false;
SelectButton.Enabled = false;
ProcessSelect.Items[0].Enabled = false;
updateClose();
}
else
{
ProcessButton.Text = "İşlem";
}
}
protected void ProcessButton_Click(object sender, EventArgs e)
{
if (ProcessSelect.SelectedValue == "Update")
{
query = "UPDATE DBO_TestTable SET UserID=@UserID, Password=@Password, EMail=@EMail, Name=@Name, Surname=@Surname, Sex=@Sex, Phone=@Phone WHERE ID=@ID";
SqlCommand command = new SqlCommand(query, connect);
if (UserID.Text != "" & Password.Text != "" & EMail.Text != "" & ID.Text != "" & Name.Text != "" & Surname.Text != "" & regSex.SelectedValue != "" & Phone.Text != "")
{
connect.Open();
command.Parameters.AddWithValue("@ID", ID.Text);
command.Parameters.AddWithValue("@UserID", UserID.Text);
command.Parameters.AddWithValue("@Password", Password.Text);
command.Parameters.AddWithValue("@EMail", EMail.Text);
command.Parameters.AddWithValue("@Name", Name.Text);
command.Parameters.AddWithValue("@Surname", Surname.Text);
command.Parameters.AddWithValue("@Sex", regSex.Text);
command.Parameters.AddWithValue("@Phone", Phone.Text);
SqlDataReader reader = command.ExecuteReader();
connect.Close();
updateClose();
Response.Write("<script>alert('ID: " + ID.Text + " numaralı veride, Güncelleme işlemi başarılı.');</script>");
reload();
Sonuc.Text = "";
}
else
{
Sonuc.Text = "Boş alan bırakmayınız.";
}
}
else if (ProcessSelect.SelectedValue == "Delete")
{
query = "DELETE FROM DBO_TestTable WHERE ID=@ID";
SqlCommand command = new SqlCommand(query, connect);
connect.Open();
command.Parameters.AddWithValue("@ID", ID.Text);
SqlDataReader reader = command.ExecuteReader();
connect.Close();
Response.Write("<script>alert('ID: " + ID.Text + " numaralı veride Silme işlemi başarılı.');</script>");
reload();
}
}
protected void SelectButton_Click(object sender, EventArgs e)
{
clear();
if (ID.Text != "")
{
query = "SELECT * FROM DBO_TestTable WHERE ID=@ID";
SqlCommand command = new SqlCommand(query, connect);
connect.Open();
command.Parameters.AddWithValue("@ID", ID.Text);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
ID.Text = reader["ID"].ToString();
UserID.Text = reader["UserID"].ToString();
Password.Text = reader["Password"].ToString();
EMail.Text = reader["EMail"].ToString();
Name.Text = reader["Name"].ToString();
Surname.Text = reader["Surname"].ToString();
regSex.SelectedValue = reader["Sex"].ToString();
Phone.Text = reader["Phone"].ToString();
}
connect.Close();
if (Name.Text != "")
{
ProcessSelect.Enabled = true;
}
else
{
ProcessSelect.Enabled = false;
}
}
else
{
Response.Write("<script>alert('Alanı boş bırakmayınız.');</script>");
}
}
}
}