/// <summary>
        /// private common select by conditions
        /// </summary>
        /// <returns>IList<student_courseEntity></returns>
        private IList <student_courseEntity> Getstudent_coursesbyQueryString(string SQLstr)
        {
            IList <student_courseEntity> student_courses = new List <student_courseEntity>();

            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.ConnectionString, CommandType.Text, SQLstr))
            {
                while (reader.Read())
                {
                    student_courseEntity student_course = new student_courseEntity();
                    if (!reader.IsDBNull(0))
                    {
                        student_course.Id = reader.GetInt32(0);
                    }
                    if (!reader.IsDBNull(1))
                    {
                        student_course.StudentId = reader.GetString(1);
                    }
                    if (!reader.IsDBNull(2))
                    {
                        student_course.CourseId = reader.GetString(2);
                    }
                    if (!reader.IsDBNull(3))
                    {
                        student_course.CourseScore = reader.GetDecimal(3);
                    }
                    student_courses.Add(student_course);
                }
            }
            return(student_courses);
        }
        /// <summary>
        /// Select items by Columns
        /// </summary>
        /// <returns>IList<student_courseEntity></returns>
        public IList <student_courseEntity> Getstudent_coursesTopN(int n)
        {
            IList <student_courseEntity> student_courses = new List <student_courseEntity>();

            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.ConnectionString, CommandType.Text, SELECT_ALL_SQL, null))
            {
                int i = 0;
                while (reader.Read() && i < n)
                {
                    student_courseEntity student_course = new student_courseEntity();
                    if (!reader.IsDBNull(0))
                    {
                        student_course.Id = reader.GetInt32(0);
                    }
                    if (!reader.IsDBNull(1))
                    {
                        student_course.StudentId = reader.GetString(1);
                    }
                    if (!reader.IsDBNull(2))
                    {
                        student_course.CourseId = reader.GetString(2);
                    }
                    if (!reader.IsDBNull(3))
                    {
                        student_course.CourseScore = reader.GetDecimal(3);
                    }
                    student_courses.Add(student_course);
                    i++;
                }
            }
            return(student_courses);
        }
Example #3
0
        protected void btnDel_Click(object sender, EventArgs e)
        {
            DALstudent_course    dal    = new DALstudent_course();
            student_courseEntity course = new student_courseEntity();

            dal.Delstudent_course(int.Parse(lbx2.SelectedValue));
            Response.Write("<script>alert('放弃成功');location.href='CourseSelect.aspx'</script>");
        }
Example #4
0
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            DALstudent_course    dal    = new DALstudent_course();
            student_courseEntity course = new student_courseEntity();

            course.CourseId  = lbx1.SelectedValue;
            course.StudentId = Session["uName"].ToString();
            dal.Addstudent_course(course);
            Response.Write("<script>alert('添加成功');location.href='CourseSelect.aspx';</script>");
        }
        /// <summary>
        /// 保存成绩
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            DALstudent_course dal = new DALstudent_course();

            foreach (GridViewRow gvr in GridView1.Rows)
            {
                TextBox tb = (TextBox)gvr.FindControl("fs");
                int     id = int.Parse(GridView1.DataKeys[gvr.RowIndex].Value.ToString());
                student_courseEntity sc = dal.Getstudent_course(id);
                if (sc != null)
                {
                    sc.CourseScore = decimal.Parse(tb.Text);
                }
                dal.Modstudent_course(sc);
            }
        }
        /// <summary>
        /// Insert an item
        /// </summary>
        /// <param name="student_course"></param>
        /// <returns>count of rows affected</returns>
        public int Addstudent_course(student_courseEntity student_course)
        {
            int backvalue = 0;

            //get paras
            SqlParameter[] student_courseParms = Getstudent_courseParametersInsert();
            //set values to paras
            student_courseParms[0].Value = student_course.StudentId;
            student_courseParms[1].Value = student_course.CourseId;
            student_courseParms[2].Value = student_course.CourseScore;
            //insert
            using (SqlConnection conn = new SqlConnection(SQLHelper.ConnectionString))
            {
                backvalue = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionString, CommandType.Text, INSERT_SQL, student_courseParms);
            }
            return(backvalue);
        }
        protected void btnOK_Click(object sender, EventArgs e)
        {
            DALstudent_course    dal    = new DALstudent_course();
            student_courseEntity course = new student_courseEntity();

            foreach (GridViewRow gvr in grdCourse.Rows)
            {
                if (gvr.RowType == DataControlRowType.DataRow)
                {
                    int id = int.Parse(grdCourse.DataKeys[gvr.RowIndex].Value.ToString());
                    course = dal.Getstudent_course(id);
                    TextBox tb = (TextBox)gvr.FindControl("txtCourse");
                    course.CourseScore = decimal.Parse(tb.Text.Trim());
                    dal.Modstudent_course(course);
                }
            }
        }
        /// <summary>
        /// 确认保存选课信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button3_Click(object sender, EventArgs e)
        {
            DALstudent_course    dal = new DALstudent_course();
            student_courseEntity sc  = new student_courseEntity();

            if (lb2.Items.Count == 0)
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('无可操作项!');</script>");
            }
            else
            {
                foreach (ListItem li in lb2.Items)
                {
                    sc           = new student_courseEntity();
                    sc.CourseId  = li.Value;
                    sc.StudentId = Convert.ToInt32(Session["uName"]);
                    dal.Addstudent_course(sc);
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('选课成功!');</script>");
                }
            }
        }
Example #9
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            DALstudent_course    dal = new DALstudent_course();
            student_courseEntity sc  = new student_courseEntity();

            if (lb2.Items.Count == 0)
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(您还未选择课程!);</script>");
            }
            else
            {
                foreach (ListItem li in lb2.Items)
                {
                    sc           = new student_courseEntity();
                    sc.CourseId  = li.Value;
                    sc.StudentId = Session["id"].ToString();
                    dal.Addstudent_course(sc);
                }
                this.Page.RegisterStartupScript("", "<script>alert(选择课程完毕!);</script>");
                Response.Redirect("CourseSelectList.aspx");
            }
        }
        /// <summary>
        /// Select an item by Primarykey
        /// </summary>
        /// <param name="id"></param>
        /// <returns>an item</returns>
        public student_courseEntity Getstudent_course(int id)
        {
            student_courseEntity student_course = new student_courseEntity();

            //primarykeys
            //get paras
            SqlParameter[] student_courseParms = Getstudent_coursePrimaryKeyParameters();
            //set values to paras
            student_courseParms[0].Value = id;
            //select
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.ConnectionString, CommandType.Text, SELECT_ONE_SQL, student_courseParms))
            {
                if (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                    {
                        student_course.Id = reader.GetInt32(0);
                    }
                    if (!reader.IsDBNull(1))
                    {
                        student_course.StudentId = reader.GetString(1);
                    }
                    if (!reader.IsDBNull(2))
                    {
                        student_course.CourseId = reader.GetString(2);
                    }
                    if (!reader.IsDBNull(3))
                    {
                        student_course.CourseScore = reader.GetDecimal(3);
                    }
                }
                else
                {
                    student_course = null;
                }
            }
            return(student_course);
        }