/// <summary> /// 加载已选课程 /// </summary> public void BindSelectCourese() { DALstudent_course dal = new DALstudent_course(); IList <student_courseEntity> scs = dal.Getstudent_coursesbyCondition("StudentId='" + Session["name"].ToString() + "'"); if (scs.Count > 0) { Button1.Enabled = false; Button2.Enabled = false; Button3.Enabled = false; Button3.ToolTip = "您已经选过课程了,只能查看!"; lb2.Items.Clear();//先清空,再绑定已选择的课程 DALcourse dalc = new DALcourse(); courseEntity c = new courseEntity(); foreach (student_courseEntity sc in scs) { c = dalc.Getcourse(int.Parse(sc.CourseId));//通过选课存储的课程号,到课程表中取出该课程的课程名称等信息 ListItem li = new ListItem(c.CourseName, c.Id.ToString()); lb2.Items.Add(li); } } else { Button1.Enabled = true; Button2.Enabled = true; Button3.Enabled = true; } }
/// <summary> /// 单击课程名时显示课程详细信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lb1_SelectedIndexChanged(object sender, EventArgs e) { DALcourse dal = new DALcourse(); courseEntity course = dal.Getcourse(int.Parse(lb1.SelectedValue)); Literal1.Text = "课程名称:" + course.CourseName + ";<br/>授课教师:" + course.CourseTeacher + ";<br/>课程简介:" + course.CourseInfo + ";<br/>限选人数:" + course.CourseStudentNum; }
/// <summary> /// 当行数据绑定的时候,进行必要的翻译处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //翻译课程 DALcourse dalc = new DALcourse(); courseEntity c = dalc.Getcourse(int.Parse(e.Row.Cells[1].Text)); if (c != null) //判断是否有值 { e.Row.Cells[1].Text = c.CourseName; //有值才能使用 } //else //{ // Response.Write("<script>alert('kongde');</script>"); //} //翻译学生 DALstudent_info dals = new DALstudent_info(); IList <student_infoEntity> ss = dals.Getstudent_infosbyCondition("studentId='" + e.Row.Cells[0].Text + "'"); if (ss.Count > 0) { e.Row.Cells[0].Text = ss[0].StudentId; } } }
//加载所有课程 public void BindAllCourse() { DALcourse dal = new DALcourse(); IList <courseEntity> courses = dal.Getcourses(); lb1.DataSource = courses; lb1.DataTextField = "CourseName"; lb1.DataValueField = "Id"; lb1.DataBind(); }
/// <summary> /// 加载数据信息 /// </summary> public void LoadData() { string conditon = string.Empty; conditon += " Id in (select CourseId from student_course where StudentId='" + Session["id"].ToString() + "')"; DALcourse dal = new DALcourse(); IList <courseEntity> course = dal.GetcoursesbyCondition(conditon);//按照条件来查询数据 GridView1.DataSource = course; GridView1.DataBind(); }
/// <summary> /// 加载已有的课程 /// /// </summary> public void BindCourse() { DropDownList1.Items.Clear();//避免重复加载 DALcourse dal = new DALcourse(); IList <courseEntity> courses = dal.Getcourses(); DropDownList1.DataSource = courses; DropDownList1.DataTextField = "CourseName"; DropDownList1.DataValueField = "Id"; DropDownList1.DataBind(); DropDownList1.Items.Insert(0, new ListItem("请选择课程", "0")); }
public void LoadData() { string conditon = string.Empty; conditon = "(CourseId is not null and CourseId<>' ')"; DALcourse dal = new DALcourse(); IList <courseEntity> course = dal.GetcoursesbyCondition(conditon);//按照条件来查询数据 grdCourse.DataSource = course; grdCourse.DataBind(); }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //翻译课程号->名称 DALcourse dalc = new DALcourse(); courseEntity c = dalc.Getcourse(int.Parse(e.Row.Cells[0].Text)); if (c != null) { e.Row.Cells[0].Text = c.CourseName; } } }
protected void btnsave_Click(object sender, EventArgs e) { DALcourse dal = new DALcourse(); courseEntity course = new courseEntity(); course.CourseId = CourseId.Value; //课程编号 course.CourseName = CourseName.Value; //课程名 course.CourseInfo = Info.Value; //课程详情 course.CourseTeacher = Teacher.Value; //任课教师 course.CourseStudentNum = Convert.ToInt16(Num.Value); //限报人数 dal.Addcourse(course); //调用添加课程方法添加课程 //建议后续在添加之前先行查看表中是否含有该条数据,那就拜托张老板啦 加油 奥里给!!! ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('添加成功');</script>"); }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { DALcourse dal = new DALcourse(); //定义针对admin_user表的操作对象 string Id = GridView1.DataKeys[e.RowIndex].Value.ToString(); //获取操作行数据的主键Id courseEntity course = dal.Getcourse(int.Parse(Id)); course.CourseName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim(); course.CourseTeacher = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim(); course.CourseInfo = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(); course.CourseStudentNum = int.Parse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim()); dal.Modcourse(course); GridView1.EditIndex = -1; LoadData();//重新加载数据,验证是否重置 }
/// <summary> /// 加载数据信息 /// </summary> public void LoadData() { string conditon = string.Empty; conditon = "(CourseId is not null and CourseId<>' ')"; if (!string.IsNullOrEmpty(course_id.Value)) { conditon += " and cast(CourseId as char) like'%" + course_id.Value + "%'"; } DALcourse dal = new DALcourse(); IList <courseEntity> course = dal.GetcoursesbyCondition(conditon);//按照条件来查询数据 GridView1.DataSource = course; GridView1.DataBind(); }
/// <summary> /// 当行数据绑定的时候,进行必要的翻译处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //翻译课程编号->名称 DALcourse dalc = new DALcourse(); courseEntity c = dalc.Getcourse(int.Parse(e.Row.Cells[1].Text)); if (c != null) { e.Row.Cells[1].Text = c.CourseName; } //翻译学生编号->姓名 DALstudent_info dals = new DALstudent_info(); IList <student_infoEntity> ss = dals.Getstudent_infosbyCondition("Id='" + e.Row.Cells[0].Text + "'"); if (ss.Count > 0) { e.Row.Cells[0].Text = ss[0].StudentName; } } }