-
Notifications
You must be signed in to change notification settings - Fork 8
/
PersonalDetails.aspx.cs
159 lines (141 loc) · 5.31 KB
/
PersonalDetails.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
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class personal_details : System.Web.UI.Page
{
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
private bool _editClicked = false;
protected void Page_Load(object sender, EventArgs e)
{
lblErr.Text = "";
if (!IsPostBack)
{
string rollNumber = string.Empty;
int i = 0;
if (Session["roleNo"] != null)
{
rollNumber = Session["roleNo"].ToString();
i = 1;
}
if (Session["roleNo"] == null)
{
if (Session["UserID"] != null)
{
rollNumber = Session["UserID"].ToString();
i = 2;
}
}
conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conn"].ToString();
if (i == 1)
{
da = new SqlDataAdapter("Select * from studentdetails where rollno = '" +Session["roleNo"].ToString()+"'", conn);
ds = new DataSet();
da.Fill(ds);
}
else if (i == 2)
{
da = new SqlDataAdapter("Select * from studentdetails where userid = " + Convert.ToInt32(Session["UserID"].ToString()), conn);
ds = new DataSet();
da.Fill(ds);
}
//Fill the Controls
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
TextBox1.Text = ds.Tables[0].Rows[0][1].ToString();
TextBox2.Text = ds.Tables[0].Rows[0][2].ToString();
TextBox3.Text = ds.Tables[0].Rows[0][3].ToString();
TextBox4.Text = ds.Tables[0].Rows[0][4].ToString();
TextBox5.Text = ds.Tables[0].Rows[0][6].ToString();
TextBox6.Text = ds.Tables[0].Rows[0][7].ToString();
TextBox7.Text = ds.Tables[0].Rows[0][5].ToString();
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Enabled = true;
TextBox2.Enabled = true;
TextBox3.Enabled = true;
TextBox4.Enabled = true;
TextBox5.Enabled = true;
TextBox6.Enabled = true;
TextBox7.Enabled = true;
ViewState["_editClicked"] = "true";
}
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["_editClicked"] != null)
{
if (ViewState["_editClicked"].ToString() == "true")
{
string rollNumber = string.Empty;
int i = 0;
if (Session["roleNo"] != null)
{
rollNumber = Session["roleNo"].ToString();
i = 1;
}
if (Session["roleNo"] == null)
{
if (Session["UserID"] != null)
{
rollNumber = Session["UserID"].ToString();
i = 2;
}
}
conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conn"].ToString();
conn.Open();
cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
if (i == 1)
{
cmd.CommandText = "UPDATE studentdetails set firstName = '" + TextBox1.Text + "',lastname = '"
+ TextBox2.Text + "',fathername = '" + TextBox3.Text + "',phoneno = '" +
TextBox4.Text + "',emailid = ' " + TextBox7.Text + "',rollno = ' " +
TextBox5.Text + "',address = ' " + TextBox6.Text + "' where rollno=" + rollNumber;
cmd.ExecuteNonQuery();
}
else if (i == 2)
{
cmd.CommandText = "UPDATE studentdetails set firstName = '" + TextBox1.Text + "',lastname = '"
+ TextBox2.Text + "',fathername = '" + TextBox3.Text + "',phoneno = '" +
TextBox4.Text + "',emailid = ' " + TextBox7.Text + "',rollno = ' " +
TextBox5.Text + "',address = ' " + TextBox6.Text + "' where userid=" + rollNumber;
cmd.ExecuteNonQuery();
}
}
else
{
lblErr.Text = "Please get the controls in Edit mode!!!";
}
}
else
{
lblErr.Text = "Please get the controls in Edit mode!!!";
}
}
protected void Button3_Click(object sender, EventArgs e)
{
if (Request.QueryString["From"] == null)
Response.Redirect("studentHomePage.aspx");
else
Response.Redirect("admissionHomePage.aspx");
}
}