Пример #1
0
    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();
    }
Пример #2
0
    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;
        }
    }
Пример #3
0
    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;
        }
    }