protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridViewScoreInfo.DataKeys[e.RowIndex].Value.ToString(); bool success = dao.DeleteBody(id, 5); if (success) { Response.Write("<script>alert('删除成功!')</script>"); //刷新该页面 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select score.id,score.Score,Score.SubmitTime,Score.Score,Course.Name,student.Name as'studentname' from score left join student on Score.Student=student.ID join Course on Score.Course=Course.ID where course.id in (select id from course where teacher='{0}')", sqlConnection); DataSet dataSet = new DataSet(); GridViewScoreInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewScoreInfo.DataSource = dataSet; GridViewScoreInfo.DataBind(); sqlConnection.Close(); } else { Response.Write("<script>alert('删除失败!')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { //获取所有老师 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from teacher", sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有老师绑定到系别下拉框 DropDownListTeacher.DataSource = dataSet1; DropDownListTeacher.DataTextField = "name"; DropDownListTeacher.DataBind(); //获取所有教室 SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select * from classroom", sqlConnection); DataSet dataSet2 = new DataSet(); sqlDataAdapter2.Fill(dataSet2); //所有教室绑定到系别下拉框 DropDownListPlace.DataSource = dataSet2; DropDownListPlace.DataTextField = "id"; DropDownListPlace.DataBind(); }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridViewExamInfo.DataKeys[e.RowIndex].Value.ToString(); bool success = dao.DeleteBody(id, 7); if (success) { Response.Write("<script>alert('删除成功!')</script>"); //刷新该页面 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select exam.*,Course.name,ClassInfo.Name as'classname' from exam left join Course on Exam.Course=Course.ID join ClassInfo on exam.ClassInfo=ClassInfo.id", sqlConnection); DataSet dataSet = new DataSet(); GridViewExamInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewExamInfo.DataSource = dataSet; GridViewExamInfo.DataBind(); sqlConnection.Close(); sqlConnection.Close(); } else { Response.Write("<script>alert('删除失败!')</script>"); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridViewCourse.DataKeys[e.RowIndex].Value.ToString(); bool success = dao.DeleteBody(id, 4); if (success) { Response.Write("<script>alert('删除成功!')</script>"); //刷新该页面 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select Course.id ,Course.Name as'coursename',Teacher.Name as'teachername',Course.Date,course.time,place,week,Score from Course left join Teacher on Course.Teacher=Teacher.id", sqlConnection); DataSet dataSet = new DataSet(); GridViewCourse.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewCourse.DataSource = dataSet; GridViewCourse.DataBind(); sqlConnection.Close(); } else { Response.Write("<script>alert('删除失败!')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from course", sqlConnection); DataSet dataSet = new DataSet(); GridViewSelectCourse.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)//将上课节次编号替换为上课节次 { string s = dataSet.Tables[0].Rows[i]["Time"].ToString(); string[] dayAndNode = s.Split(','); string CourseInfo = ""; for (int j = 0; j < dayAndNode.Length; j++) { CourseInfo += AlterString.outString(dayAndNode[j]) + "\n"; } s = CourseInfo; dataSet.Tables[0].Rows[i][4] = s; //循环修改列传值 string s2 = dataSet.Tables[0].Rows[i]["Place"].ToString(); ClassRoom classRoom = (ClassRoom)dao.getBody(s2, 6);; dataSet.Tables[0].Rows[i]["Place"] = classRoom.Number; //循环修改列传值 string s3 = dataSet.Tables[0].Rows[i]["Teacher"].ToString(); Teacher tea = (Teacher)dao.getBody(s3, 2);; dataSet.Tables[0].Rows[i]["Teacher"] = tea.Name1; //循环修改列传值 } dataSet.AcceptChanges(); //这句最关键,完成修改,做用是允许对DATASET的修改 GridViewSelectCourse.DataSource = dataSet; GridViewSelectCourse.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { //获取所有班级 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from classinfo", sqlConnection); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); //所有班级绑定到班级下拉框 DropDownListClass.DataSource = dataSet; DropDownListClass.DataTextField = "name"; DropDownListClass.DataBind(); //获取所有系别 SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from dept", sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有系别绑定到系别下拉框 DropDownListDept.DataSource = dataSet1; DropDownListDept.DataTextField = "name"; DropDownListDept.DataBind(); sqlConnection.Close(); }
//每改变一次课程号,课程名和选课学生就得跟着变 protected void DropDownListCourseId_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); //课程名根据课程号变化 //1.获取课程号下拉框对应的课程名 string sqlselectcoursename = string.Format("select name from course where id ='{0}'", DropDownListCourseId.SelectedValue); string coursename = ""; IDataReader idr = SqlTools.Read(sqlselectcoursename); if (idr.Read()) { coursename = idr.GetString(0); } //绑定课程名 TextBoxCourseName.Text = coursename; //学生集根据课程号变化 //1.获取课程号获取选择了该课程的所有学生 SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter(string.Format("select name from student left join SelectCourse on selectcourse.student=student.id where course='{0}'", DropDownListCourseId.Text), sqlConnection); DataSet dataSet2 = new DataSet(); sqlDataAdapter2.Fill(dataSet2); //所有系别绑定到学生下拉框 DropDownListStudent.DataSource = dataSet2; DropDownListStudent.DataTextField = "name"; DropDownListStudent.DataBind(); }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridViewTeacher.DataKeys[e.RowIndex].Value.ToString(); bool success = dao.DeleteBody(id, 2); if (success) { Response.Write("<script>alert('删除成功!')</script>"); //刷新该页面 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select teacher.*,Dept.Name as'deptname' from teacher left join dept on Dept.ID=Teacher.Department", sqlConnection); DataSet dataSet = new DataSet(); GridViewTeacher.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewTeacher.DataSource = dataSet; GridViewTeacher.DataBind(); sqlConnection.Close(); } else { Response.Write("<script>alert('删除失败!')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //获取要编辑学生 string id = Request.QueryString["id"]; Student s = (Student)dao.getBody(id, 1); TextBoxID.Text = s.ID1; TextBoxName.Text = s.Name1; TextBoxPassword.Text = s.Password1; TextBoxBirth.Text = s.Birth1; TextBoxEmail.Text = s.Email1; TextBoxPhone.Text = s.Telephone1; TextBoxAddress.Text = s.Address1; TextBoxState.Text = s.State1; if (s.Sex1.Equals("女")) { RadioButtonSexFemale.Checked = true; } else { RadioButtonSexMale.Checked = true; } //获取所有班级 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from classinfo", sqlConnection); DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); //所有班级绑定到班级下拉框 DropDownListClass.DataSource = dataSet; DropDownListClass.DataTextField = "name"; DropDownListClass.DataBind(); //下拉框选中该学生班级 DropDownListClass.SelectedValue = s.Class1; //获取所有系别 SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from dept", sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有系别绑定到系别下拉框 DropDownListDept.DataSource = dataSet1; DropDownListDept.DataTextField = "name"; DropDownListDept.DataBind(); //下拉框选中该学生系别 DropDownListDept.SelectedValue = s.Dept1; sqlConnection.Close(); } //不能改学号 TextBoxID.Enabled = false; }
protected void Page_Load(object sender, EventArgs e) { Student Stu = (Student)Session["student"]; SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@"select course from SelectCourse where Student={0}", Stu.ID1); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);; DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); int count = 0; Course[] course = new Course[dataSet.Tables[0].Rows.Count]; //存储所有课程信息 foreach (DataRow col in dataSet.Tables[0].Rows) //获取全部选课的课程号 { course[count] = (Course)dao.getBody(col["course"].ToString(), 4);; count++; } for (int i = 0; i < count; i++)//将字符串节次转换文字 { string[] dayAndNode = course[i].Time.Split(','); string CourseInfo = ""; for (int j = 0; j < dayAndNode.Length; j++) { CourseInfo += AlterString.outString(dayAndNode[j]) + "<Br>"; } course[i].Time = CourseInfo; string Teacher = ""; Teacher tea = (Teacher)dao.getBody(course[i].Teacher, 2);; Teacher = tea.Name1; course[i].Teacher = Teacher; string s = course[i].Place; ClassRoom classRoom = (ClassRoom)dao.getBody(s, 6);; course[i].Place = classRoom.Number; //循环修改列传值 } DataTable dt = new DataTable(); //实例化一个空数据源 for (int k = 0; k < count; k++) //要添加的行数 { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); } GridViewShowSelectCourse.DataSource = dt; GridViewShowSelectCourse.DataBind(); for (int i = 0; i < count; i++) { GridViewShowSelectCourse.Rows[i].Cells[0].Text = course[i].ID; GridViewShowSelectCourse.Rows[i].Cells[1].Text = course[i].Name; GridViewShowSelectCourse.Rows[i].Cells[2].Text = course[i].Teacher; GridViewShowSelectCourse.Rows[i].Cells[3].Text = course[i].Date; GridViewShowSelectCourse.Rows[i].Cells[4].Text = course[i].Time; GridViewShowSelectCourse.Rows[i].Cells[5].Text = course[i].Week; GridViewShowSelectCourse.Rows[i].Cells[6].Text = course[i].Place; GridViewShowSelectCourse.Rows[i].Cells[7].Text = course[i].Score; } }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select ClassRoom.*,dept.Name from classroom left join Dept on ClassRoom.Dept=Dept.ID", sqlConnection); DataSet dataSet = new DataSet(); GridViewClassRoom.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewClassRoom.DataSource = dataSet; GridViewClassRoom.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select exam.*,Course.name,ClassInfo.Name as'classname' from exam left join Course on Exam.Course=Course.ID join ClassInfo on exam.ClassInfo=ClassInfo.id", sqlConnection); DataSet dataSet = new DataSet(); GridViewExamInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewExamInfo.DataSource = dataSet; GridViewExamInfo.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from student", sqlConnection); DataSet dataSet = new DataSet(); GridViewStudent.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewStudent.DataSource = dataSet; GridViewStudent.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select score.id,Score.SubmitTime,Score.Score,Course.Name,student.Name as'studentname' from score left join student on Score.Student=student.ID join Course on Score.Course=Course.ID", sqlConnection); DataSet dataSet = new DataSet(); GridViewScore.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewScore.DataSource = dataSet; GridViewScore.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select Course.id ,Course.Name as'coursename',Teacher.Name as'teachername',Course.Date,course.time,place,week,Score from Course left join Teacher on Course.Teacher=Teacher.id", sqlConnection); DataSet dataSet = new DataSet(); GridViewCourse.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewCourse.DataSource = dataSet; GridViewCourse.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select teacher.*,Dept.Name as'deptname' from teacher left join dept on Dept.ID=Teacher.Department", sqlConnection); DataSet dataSet = new DataSet(); GridViewTeacher.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewTeacher.DataSource = dataSet; GridViewTeacher.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { Teacher t = (Teacher)Session["teacher"]; SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(string.Format("select score.id,score.Score,Score.SubmitTime,Score.Score,Course.Name,student.Name as'studentname' from score left join student on Score.Student=student.ID join Course on Score.Course=Course.ID where course.id in (select id from course where teacher='{0}')", t.ID1), sqlConnection); DataSet dataSet = new DataSet(); GridViewScoreInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewScoreInfo.DataSource = dataSet; GridViewScoreInfo.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { Teacher t = (Teacher)Session["teacher"]; SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(string.Format("select exam.*,Course.name,ClassInfo.Name as'classname' from exam left join Course on Exam.Course=Course.ID join ClassInfo on exam.ClassInfo=ClassInfo.id where course.ID in (select id from course where teacher='{0}')", t.ID1), sqlConnection); DataSet dataSet = new DataSet(); GridViewExamInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewExamInfo.DataSource = dataSet; GridViewExamInfo.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { string id = Session["informationid"].ToString(); SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@"select * from PublicInformation where id={0}", id); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);; DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); //dataSet.Tables[0].Rows[0]["ClassInfo"].ToString(); this.TextBoxTitle.Text = dataSet.Tables[0].Rows[0]["Title"].ToString(); TextBoxText.Text = dataSet.Tables[0].Rows[0]["News"].ToString(); TextBoxSender.Text = dataSet.Tables[0].Rows[0]["SubmitPerson"].ToString(); TextBoxTime.Text = dataSet.Tables[0].Rows[0]["Time"].ToString(); }
protected void Page_Load(object sender, EventArgs e) { Teacher t = (Teacher)Session["teacher"]; SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(string.Format("select selectcourse.ID as'id',Course.ID as'courseid',course.Name as'coursename',student.ID as'studentid',student.Name as'studentname',Course.Score as'coursescore' from SelectCourse join course on Course.ID=SelectCourse.Course join student on student.ID=SelectCourse.Student where Course.id in(select id from course where teacher='{0}')", t.ID1), sqlConnection); DataSet dataSet = new DataSet(); GridViewQuerySelectCourse.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewQuerySelectCourse.DataSource = dataSet; GridViewQuerySelectCourse.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //获取要编辑老师 string id = Request.QueryString["id"]; Teacher t = (Teacher)dao.getBody(id, 2); TextBoxID.Text = t.ID1; TextBoxName.Text = t.Name1; TextBoxPassword.Text = t.Password1; TextBoxBirth.Text = t.Birthday1; TextBoxEmail.Text = t.Email1; TextBoxPhone.Text = t.Telephone1; TextBoxAddress.Text = t.Address1; TextBoxState.Text = t.State1; TextBoxArriveDate.Text = t.ArriveDate1; if (t.Sex1.Equals("女")) { RadioButtonSexFemale.Checked = true; } else { RadioButtonSexMale.Checked = true; } //获取所有系别 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from dept", sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有系别绑定到系别下拉框 DropDownListDept.DataSource = dataSet1; DropDownListDept.DataTextField = "name"; DropDownListDept.DataBind(); //下拉框选中该老师系别 DropDownListDept.SelectedValue = t.Department1; sqlConnection.Close(); } //不能改工号 TextBoxID.Enabled = false; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Teacher t = (Teacher)Session["teacher"]; SqlConnection sqlConnection = SqlTools.Connection(); //获取自己所上的课程号 SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(string.Format("select id from course where teacher='{0}'", t.ID1), sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有课程号绑定到课程号下拉框 DropDownListCourseId.DataSource = dataSet1; DropDownListCourseId.DataTextField = "id"; DropDownListCourseId.DataBind(); //课程名根据课程号变化 //1.获取课程号下拉框对应的课程名 string sqlselectcoursename = string.Format("select name from course where id ='{0}'", DropDownListCourseId.SelectedValue); string coursename = ""; IDataReader idr = SqlTools.Read(sqlselectcoursename); if (idr.Read()) { coursename = idr.GetString(0); } //绑定课程名 TextBoxCourseName.Text = coursename; //学生集根据课程号变化 //1.获取课程号获取选择了该课程的所有学生 SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter(string.Format("select name from student left join SelectCourse on selectcourse.student=student.id where course='{0}'", DropDownListCourseId.Text), sqlConnection); DataSet dataSet2 = new DataSet(); sqlDataAdapter2.Fill(dataSet2); //所有系别绑定到学生下拉框 DropDownListStudent.DataSource = dataSet2; DropDownListStudent.DataTextField = "name"; DropDownListStudent.DataBind(); sqlConnection.Close(); } TextBoxCourseName.Enabled = false; }
protected void Page_Load(object sender, EventArgs e) { Student Stu = (Student)Session["student"]; SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@" select * from Exam where ClassInfo='{0}'", Stu.Class1.ToLower().Trim()); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection); DataSet dataSet = new DataSet(); GridViewShowExam.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); GridViewShowExam.DataSource = dataSet; GridViewShowExam.DataBind(); for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)//将教师编号替换为教师姓名 { string s = dataSet.Tables[0].Rows[i]["Course"].ToString(); Course course = (Course)dao.getBody(s, 4); ClassRoom cl = (ClassRoom)dao.getBody(dataSet.Tables[0].Rows[i]["Place"].ToString(), 6); ClassInfo classInfo = (ClassInfo)dao.getBody(dataSet.Tables[0].Rows[i]["ClassInfo"].ToString(), 9); string s2 = dataSet.Tables[0].Rows[i]["Time"].ToString(); string[] dayAndNode = s2.Split(','); string CourseInfo = ""; for (int j = 0; j < dayAndNode.Length; j++) { CourseInfo += AlterString.outString(dayAndNode[j]) + "\n"; } dataSet.Tables[0].Rows[i]["Time"] = CourseInfo; dataSet.Tables[0].Rows[i]["Place"] = cl.Number; dataSet.Tables[0].Rows[i]["Classinfo"] = classInfo.Name; //循环修改列传值 } dataSet.AcceptChanges(); GridViewShowExam.DataSource = dataSet; GridViewShowExam.DataBind(); for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)//将教师编号替换为教师姓名 { string s = dataSet.Tables[0].Rows[i]["Course"].ToString(); Course course = (Course)dao.getBody(s, 4); GridViewShowExam.Rows[i].Cells[2].Text = course.Name; } }
protected void Page_Load(object sender, EventArgs e) { Student Stu = (Student)Session["student"]; SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@"select * from PublicInformation where Receiver='全部' or Receiver='全体学生' or Receiver='{0}'", Stu.ID1); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);; DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); GridViewInformation.DataKeyNames = new string[] { "id" }; GridViewInformation.DataSource = dataSet; GridViewInformation.DataBind(); for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)//添加序号 { GridViewInformation.Rows[i].Cells[0].Text = (i + 1).ToString(); } }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); //获取所有课程名 SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from course", sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有课程名绑定到课程号下拉框 DropDownListCourse.DataSource = dataSet1; DropDownListCourse.DataTextField = "name"; DropDownListCourse.DataBind(); //获取所有教室 SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select * from classroom", sqlConnection); DataSet dataSet2 = new DataSet(); sqlDataAdapter2.Fill(dataSet2); //所有教室绑定到地点下拉框 DropDownListPlace.DataSource = dataSet2; DropDownListPlace.DataTextField = "id"; DropDownListPlace.DataBind(); //获取所有班级 SqlDataAdapter sqlDataAdapter3 = new SqlDataAdapter("select * from classinfo", sqlConnection); DataSet dataSet3 = new DataSet(); sqlDataAdapter3.Fill(dataSet3); //所有班级绑定到班级下拉框 DropDownListClass.DataSource = dataSet3; DropDownListClass.DataTextField = "name"; DropDownListClass.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //获取要编辑成绩 string id = Request.QueryString["id"]; Score sc = (Score)dao.getBody(id, 5); TextBoxScore.Text = sc.Scores1; TextBoxTime.Text = sc.Submittime; //绑定课程号 TextBoxCourseID.Text = sc.Course1; string sqlselectcoursename = string.Format("select name from course where id='{0}'", sc.Course1); string coursename = ""; IDataReader idr = SqlTools.Read(sqlselectcoursename); if (idr.Read()) { coursename = idr.GetString(0); } //绑定课程名 TextBoxName.Text = coursename; //获取所有选择了该课的学生 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(string.Format("select student.Name from score left join student score.student=student.id where student.ID=Score.Student and course='{0}'", sc.Course1), sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有系别绑定到学生下拉框 DropDownListStudent.DataSource = dataSet1; DropDownListStudent.DataTextField = "name"; DropDownListStudent.DataBind(); //下拉框选中该成绩学生 DropDownListStudent.SelectedValue = sc.Student1; } //不能改 TextBoxCourseID.Enabled = false; DropDownListStudent.Enabled = false; TextBoxName.Enabled = false; }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { Student Stu = (Student)Session["student"]; string ID = GridViewSelectCourse.SelectedValue.ToString(); SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@"select course from SelectCourse where Student={0}", Stu.ID1); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);; DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); String[] CourseId = new string[dataSet.Tables[0].Rows.Count]; int count = 0; foreach (DataRow col in dataSet.Tables[0].Rows)//获取全部选课的课程号 { CourseId[count] = col["course"].ToString(); count++; } if (CourseId.Contains(ID)) { Response.Write("<script>alert('选课失败!已经选择该课~')</script>"); } else { string sql2 = string.Format(@"insert into SelectCourse values('{0}','{1}')", Stu.ID1, ID); int i = SqlTools.Excute(sql2); if (i == 1) { Response.Write("<script>alert('选课成功~')</script>"); } else { Response.Write("<script>alert('选课失败~')</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { Student Stu = (Student)Session["student"]; SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@" select * from Score where student='{0}'", Stu.ID1); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection); DataSet dataSet = new DataSet(); GridViewShowScore.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); GridViewShowScore.DataSource = dataSet; GridViewShowScore.DataBind(); for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)//将教师编号替换为教师姓名 { string s = dataSet.Tables[0].Rows[i]["Course"].ToString(); Course course = (Course)dao.getBody(s, 4); GridViewShowScore.Rows[i].Cells[2].Text = course.Name; //循环修改列传值 GridViewShowScore.Rows[i].Cells[3].Text = course.Score; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["student"] != null) { DataTable dt = new DataTable(); //实例化一个空数据源 for (int k = 0; k < 5; k++) //要添加的行数,这里是5行 { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); } this.GridViewCourse.DataSource = dt; this.GridViewCourse.DataBind();//初始化表内数据 GridViewCourse.Rows[0].Cells[0].Text = "第一节"; GridViewCourse.Rows[1].Cells[0].Text = "第二节"; GridViewCourse.Rows[2].Cells[0].Text = "第三节"; GridViewCourse.Rows[3].Cells[0].Text = "第四节"; GridViewCourse.Rows[4].Cells[0].Text = "第五节"; Student Stu = (Student)Session["student"]; LabelShowName.Text = Stu.Name1; LabelShowDept.Text = Stu.Dept1; LabelShowClass.Text = Stu.Class1; LabelShowWelcome.Text = "学生端→欢迎你:" + Stu.Name1 + "(" + Stu.ID1 + ")"; ImageHead.ImageUrl = Stu.Photo1; SqlConnection sqlConnection = SqlTools.Connection(); string sql = string.Format(@"select course from SelectCourse where Student={0}", Stu.ID1); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);; DataSet dataSet = new DataSet(); sqlDataAdapter.Fill(dataSet); sqlConnection.Close(); String[] CourseId = new string[dataSet.Tables[0].Rows.Count]; int count = 0; Course[] course = new Course[dataSet.Tables[0].Rows.Count]; //存储所有课程信息 foreach (DataRow col in dataSet.Tables[0].Rows) //获取全部选课的课程号 { course[count] = (Course)dao.getBody(col["course"].ToString(), 4); count++; } ClassRoom[] classRoom = new ClassRoom[count]; for (int i = 0; i < count; i++) { classRoom[i] = (ClassRoom)dao.getBody(course[i].Place, 6); } string[,] ShowCourseInfo = new string[count, 5]; string[,] ShowCoursetime = new string[count, 5]; for (int j = 0; j < count; j++) { string[] dayAndNode = course[j].Time.Split(','); for (int i = 0; i < dayAndNode.Length; i++) { if (dayAndNode[i].Substring(0, 1).Equals("1")) { ShowCourseInfo[j, i] = "星期一"; ShowCoursetime[j, i] = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("2")) { ShowCourseInfo[j, i] = "星期二"; ShowCoursetime[j, i] = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("3")) { ShowCourseInfo[j, i] = "星期三"; ShowCoursetime[j, i] = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("4")) { ShowCourseInfo[j, i] = "星期四"; ShowCoursetime[j, i] = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("5")) { ShowCourseInfo[j, i] = "星期五"; ShowCoursetime[j, i] = dayAndNode[i].Substring(2, 1); } } } for (int i = 0; i < count; i++) { for (int j = 0; j < 5; j++) { switch (ShowCourseInfo[i, j]) { case "星期一": { GridViewCourse.Rows[int.Parse(ShowCoursetime[i, j]) - 1].Cells[1].Text += course[i].Name + "<br>" + classRoom[i].Number + "<br>"; } break; case "星期二": { GridViewCourse.Rows[int.Parse(ShowCoursetime[i, j]) - 1].Cells[2].Text += course[i].Name + "<br>" + classRoom[i].Number + "<br>"; } break; case "星期三": { GridViewCourse.Rows[int.Parse(ShowCoursetime[i, j]) - 1].Cells[3].Text += course[i].Name + "<br>" + classRoom[i].Number + "<br>"; } break; case "星期四": { GridViewCourse.Rows[int.Parse(ShowCoursetime[i, j]) - 1].Cells[4].Text += course[i].Name + "<br>" + classRoom[i].Number + "<br>"; } break; case "星期五": { GridViewCourse.Rows[int.Parse(ShowCoursetime[i, j]) - 1].Cells[5].Text += course[i].Name + "<br>" + classRoom[i].Number + "<br>"; } break; default: break; } } } } else { Response.Write(" <script language=javascript>alert('登录过期,请重新登陆');window.window.location.href='./../LoginTest.aspx';</script> "); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //获取要编辑课程 string id = Request.QueryString["id"]; Exam ex = (Exam)dao.getBody(id, 7); TextBoxID.Text = ex.ID; TextBoxDate.Text = ex.Date; SqlConnection sqlConnection = SqlTools.Connection(); //获取所有课程名 SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from course", sqlConnection); DataSet dataSet1 = new DataSet(); sqlDataAdapter1.Fill(dataSet1); //所有课程名绑定到课程号下拉框 DropDownListCourse.DataSource = dataSet1; DropDownListCourse.DataTextField = "name"; DropDownListCourse.DataBind(); //选中 DropDownListCourse.SelectedValue = ex.Course; //获取所有教室 SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select * from classroom", sqlConnection); DataSet dataSet2 = new DataSet(); sqlDataAdapter2.Fill(dataSet2); //所有教室绑定到地点下拉框 DropDownListPlace.DataSource = dataSet2; DropDownListPlace.DataTextField = "id"; DropDownListPlace.DataBind(); //选中 DropDownListPlace.SelectedValue = ex.Place; //获取所有班级 SqlDataAdapter sqlDataAdapter3 = new SqlDataAdapter("select * from classinfo", sqlConnection); DataSet dataSet3 = new DataSet(); sqlDataAdapter3.Fill(dataSet3); //所有班级绑定到班级下拉框 DropDownListClass.DataSource = dataSet3; DropDownListClass.DataTextField = "name"; DropDownListClass.DataBind(); //选中 DropDownListClass.SelectedValue = ex.ClassInfo; //绑定考试时间 string[] dayAndNode = ex.Time.Split(','); for (int i = 0; i < dayAndNode.Length; i++) { //第一个字符为1说明是星期一 if (dayAndNode[i].Substring(0, 1).Equals("1")) { RadioButtonMonday.Checked = true; DropDownListMonday.SelectedValue = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("2")) { RadioButtonTuesday.Checked = true; DropDownListTuesday.SelectedValue = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("3")) { RadioButtonWed.Checked = true; DropDownListWednesday.SelectedValue = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("4")) { RadioButtonThur.Checked = true; DropDownListThursday.SelectedValue = dayAndNode[i].Substring(2, 1); } else if (dayAndNode[i].Substring(0, 1).Equals("5")) { RadioButtonFri.Checked = true; DropDownListFriday.SelectedValue = dayAndNode[i].Substring(2, 1); } } sqlConnection.Close(); } //不能改课程号 TextBoxID.Enabled = false; }