-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.aspx.cs
151 lines (112 loc) · 5.31 KB
/
Student.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace CapstoneFinal
{
public partial class Student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String sqlQuery = "SELECT * FROM Teacher";
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnect;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = sqlQuery;
sqlConnect.Open();
SqlDataReader queryResults = sqlCommand.ExecuteReader();
int countTeach = 0;
while (queryResults.Read())
{
countTeach++;
teachers.Items.Add(queryResults["LastName"].ToString() + ": " + queryResults["TeacherID"].ToString());
teachers.DataValueField = (queryResults["TeacherID"].ToString());
}
queryResults.Close();
sqlQuery = "SELECT * FROM Event";
sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnect;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = sqlQuery;
queryResults = sqlCommand.ExecuteReader();
queryResults.Close();
sqlQuery = "SELECT * FROM TShirtConfigurations";
sqlCommand.Connection = sqlConnect;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = sqlQuery;
queryResults = sqlCommand.ExecuteReader();
while (queryResults.Read())
{
//shirtsList.Items.Add(queryResults["ShirtSize"].ToString() + " " + queryResults["ShirtColor"].ToString() + ": " + queryResults["ShirtInfoID"].ToString());
}
queryResults.Close();
sqlConnect.Close();
}
protected void ButPop_Click(object sender, EventArgs e)
{
Response.Redirect("Student2.aspx");
}
protected void ButClear_Click(object sender, EventArgs e)
{
txtFirstName.Text = String.Empty;
Response.Redirect("student.aspx");
}
protected void ButInsert_Click(object sender, EventArgs e)
{
String sqlQuery = "SELECT * FROM Student";
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnect;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = sqlQuery;
sqlConnect.Open();
SqlDataReader queryResults = sqlCommand.ExecuteReader();
int counter = 0;
while (queryResults.Read())
{
counter++;
}
queryResults.Close();
int check = 0;
if (CheckBox1.Checked)
{
check = 1;
}
int check2 = 0;
if (CheckBox2.Checked)
{
check2 = 1;
}
String tID = teachers.SelectedValue.Substring(teachers.SelectedValue.IndexOf(':') + 2);
//String sID = (shirtsList.SelectedValue.Substring(shirtsList.SelectedValue.IndexOf(':') + 2));
sqlCommand = new SqlCommand();
sqlQuery = "INSERT INTO STUDENT VALUES (" + counter + ", @FirstName , @LastName, @Age, @Notes, " + tID + ", @Gender, @Dietary, " + check + ", " + check2 + " , 0 , @ParentName, @ParentEmail); ";
sqlCommand.Parameters.AddWithValue("@FirstName", HttpUtility.HtmlEncode(txtFirstName.Text));
sqlCommand.Parameters.AddWithValue("@LastName", HttpUtility.HtmlEncode(txtLastName.Text));
sqlCommand.Parameters.AddWithValue("@Age", HttpUtility.HtmlEncode(txtAge.Text));
sqlCommand.Parameters.AddWithValue("@Notes", HttpUtility.HtmlEncode(txtNotes.Text));
sqlCommand.Parameters.AddWithValue("@Gender", HttpUtility.HtmlEncode(txtGender.Text));
sqlCommand.Parameters.AddWithValue("@Dietary", HttpUtility.HtmlEncode(txtDiet.Text));
sqlCommand.Parameters.AddWithValue("@ParentName", HttpUtility.HtmlEncode(txtParent.Text));
sqlCommand.Parameters.AddWithValue("@ParentEmail", HttpUtility.HtmlEncode(txtEmail.Text));
sqlCommand.Connection = sqlConnect;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = sqlQuery;
queryResults = sqlCommand.ExecuteReader();
queryResults.Close();
sqlConnect.Close();
Response.Write("Success! Student Added");
Response.Redirect("successPS.aspx");
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = CheckBox2.Checked;
}
}
}