日期:2014-05-17 浏览次数:20420 次
Web层 addStudent.aspx.cs protected void btnAdd_Click(object sender, EventArgs e) { StudentInfo info = new StudentInfo(); info.Name = txtName.Text; ...... if (StudentBLL.AddStudent(info)) { JScript.AlertAndRedirect("添加成功!", "ManageStudent.aspx"); } } addTeacher.aspx.cs protected void btnAdd_Click(object sender, EventArgs e) { TeacherInfo info = new TeacherInfo(); info.Name = txtName.Text; ...... if (TeacherBLL.AddTeacher(info)) { JScript.AlertAndRedirect("添加成功!", "ManageTeacher.aspx"); } } BLL层 (StudentBLL.cs) public static bool AddStudent(StudentInfo info) { if (instance.AddStudent(info)) return true; else return false; } (TeacherBLL.cs) public static bool AddTeacher(TeacherInfo info) { if (instance.AddTeacher(info)) return true; else return false; } DAL层 (StudentDAL.cs) public bool AddStudent(StudentInfo info) { StringBuilder buffer = new StringBuilder(); buffer.Append("insert into People(Flag,Name,Sex) Values (@Flag,@Name,@Sex)"); SqlParameter[] parameters = { new SqlParameter("@Flag",SqlDbType.Int,4)...}; parameters[0].Value = 1; ... SqlDbHelper db = new SqlDbHelper(); return db.ExecuteNonQuery(buffer.ToString(), CommandType.Text, parameters) > 0; } (TeacherDAL.cs) public bool AddTeacher(TeacherInfo info) { StringBuilder buffer = new StringBuilder(); buffer.Append("insert into People(Flag,Name,Sex) Values (@Flag,@Name,@Sex)"); SqlParameter[] parameters = { new SqlParameter("@Flag",SqlDbType.Int,4)...}; parameters[0].Value = 2; ... SqlDbHelper db = new SqlDbHelper(); return db.ExecuteNonQuery(buffer.ToString(), CommandType.Text, parameters) > 0; } DBUtility层 StudentInfo.cs ... TeacherInfo.cs ...