-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoster.aspx.cs
105 lines (87 loc) · 4.42 KB
/
Roster.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
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; //lets us access our webconfig file in C#
namespace CapstoneFinal
{
public partial class Roster : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTC_Click(object sender, EventArgs e)
{
String sqlQuery = "SELECT StudentID, student.FirstName, student.LastName, Age, ParentComing, Permission, TCheck FROM Student inner join teacher on student.teacherID=teacher.teacherID where TCheck = '0' AND teacher.EmailAddress = " + Session["Username"].ToString();
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlQuery, sqlConnect);
DataTable dtForGridView = new DataTable();
sqlAdapter.Fill(dtForGridView);
gvStudent.DataSource = dtForGridView;
gvStudent.DataBind();
}
protected void btnTU_Click(object sender, EventArgs e)
{
String sqlQuery = "SELECT StudentID, student.FirstName, student.LastName, Age, ParentComing, Permission, TCheck FROM Student, teacher WHERE student.teacherID=teacher.teacherID and TCheck = '1' AND teacher.EmailAddress=" + Session["Username"].ToString();
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlQuery, sqlConnect);
DataTable dtForGridView = new DataTable();
sqlAdapter.Fill(dtForGridView);
gvStudent.DataSource = dtForGridView;
gvStudent.DataBind();
}
protected void btnAll_Click(object sender, EventArgs e)
{
String sqlQuery = "SELECT StudentID, student.FirstName, student.LastName, Age, ParentComing, Permission, TCheck FROM Student, teacher WHERE student.teacherID=teacher.teacherID AND teacher.EmailAddress=" + Session["Username"].ToString() ;
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlQuery, sqlConnect);
DataTable dtForGridView = new DataTable();
sqlAdapter.Fill(dtForGridView);
gvStudent.DataSource = dtForGridView;
gvStudent.DataBind();
}
protected void gvStudent_RowEditing(object sender, GridViewEditEventArgs e)
{
gvStudent.EditIndex = e.NewEditIndex;
gvStudent.DataBind();
}
protected void gvStudent_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
CheckBox cbTC = (CheckBox)gvStudent.Rows[e.RowIndex].Cells[7].Controls[0];
int TC;
if (cbTC.Checked == true)
{
TC = 1;
}
else
{
TC = 0;
}
int studentid = Convert.ToInt32(gvStudent.Rows[e.RowIndex].Cells[1].Text);
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnect;
sqlCommand.CommandType = CommandType.Text;
String sqlQuery = "UPDATE [dbo].[Student] SET [TCheck] = '" + TC + "' WHERE StudentID = '" + studentid + "'";
sqlCommand.CommandText = sqlQuery;
sqlConnect.Open();
//SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["lab4"].ToString());
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlQuery, sqlConnect);
DataTable dtForGridView = new DataTable();
sqlAdapter.Fill(dtForGridView);
gvStudent.DataSource = dtForGridView;
gvStudent.DataBind();
gvStudent.DataBind();
sqlConnect.Close();
}
protected void gvStudent_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvStudent.EditIndex = -1;
gvStudent.DataBind();
}
}
}