电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

课程4上课日志4+三层架构

5页
  • 卖家[上传人]: y****g
  • 文档编号:131872980
  • 上传时间:2020-05-10
  • 文档格式:DOC
  • 文档大小:73KB
  • / 5 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、课程4 三层架构让代码结构更清晰 上课日志4一、复习、回顾实例4-3主要知识要点验证用户是否登录(Page_Load事件),Session超时时间,注销退出的两种实现方法,C#中的null与数据库中的空值的理解、数据库字段值为空值在读取时处理方法(要用数据读取器读取的时候、要为文本框赋值的时候、要替换Sql语句中的占位符的时候)、数据读取器字段序号与数据读取器.GetInt32(字段序号)的区别、进一步领悟三层架构项目的开发方法。下面二、三为在实例4-3的基础上增加添加学生信息、删除学生信息功能简称为实例4-4二、为实例4-4实现添加学生信息功能1、表现层界面设计 复制UpdateStudent.aspx代码修改即可。lblId可以删除2、编写添加学生信息的数据访问层代码public int InsertStudent(Student stu) string sql = insert into Student values(stunum,stuname,stuclass,subject,stuage,stuphone,stugender) ; SqlParameter paras =

      2、new SqlParameter new SqlParameter(stunum,stu.StuNum), new SqlParameter(stuname,stu.StuName), new SqlParameter(stuclass,stu.StuClass), new SqlParameter(subject,stu.Subject),new SqlParameter(stuage,stu.StuAge=null?DBNull.Value:(object)stu.StuAge), new SqlParameter(stuphone,stu.StuPhone), new SqlParameter(stugender,stu.StuGender), ; int count = SqlHelper.ExecuteNonQuery(sql, paras); return count; public int SelectCount(string StuNum) string sql = select count(*) from Student where StuNum=StuNum; Sq

      3、lParameter para = new SqlParameter(StuNum, StuNum); int count = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, para); return count; 3、编写添加学生信息的业务逻辑层代码 public bool InsertStudent(Student stu) return dal.InsertStudent(stu) 0; public bool SelectCount(string StuNum) return dal.SelectCount(StuNum) 0; 4、编写添加学生信息的表现层代码private StudentBll bll = new StudentBll(); protected void Page_Load(object sender, EventArgs e) if (SessionUserName = null) SessionUserName = ; /Response.Redirect(Login.aspx); Response.Write

      4、(alert(你未登录或已超时,请重新登录!);location=Login.aspx); 与修改学生信息代码差不多 protected void btnSave_Click(object sender, ImageClickEventArgs e) string stuNum = txtStuNum.Text; string stuName = txtStuName.Text; string stuClass = txtStuClass.Text; string subject = txtSubject.Text; if (string.IsNullOrEmpty(stuNum) Response.Write(alert(学号不能为空); else if (string.IsNullOrEmpty(stuName) Response.Write(alert(姓名不能为空); else if (string.IsNullOrEmpty(stuClass) Response.Write(alert(班级不能为空); else if (string.IsNullOrEmpty(subjec

      5、t) Response.Write(alert(学科不能为空); else if (bll.SelectCount(stuNum) Response.Write(alert(学号重复); else int age; Student stu = new Student(); stu.StuAge = int.TryParse(txtStuAge.Text.Trim(), out age) ? (int?)age : null;/ stu.StuAge = int.TryParse(txtStuAge.Text.Trim(), out age) ? (int?)age : 0; stu.StuClass = stuClass; stu.StuGender = radbtnB.Checked ? 男 : (radbtnG.Checked ? 女 : ); stu.StuName = stuName; stu.StuNum = stuNum; stu.Subject = subject; stu.StuPhone = txtStuPhone.Text.Trim(); bool isok = b

      6、ll.InsertStudent(stu); if (isok) Response.Write(alert(添加成功);location=StudentList.aspx); else Response.Write(alert(添加失败); 三、为实例4-4实现删除学生信息功能1、数据访问层代码public int DeleteStudent(int id) string sql = delete from Student where ID=id; SqlParameter pa = new SqlParameter(id, id); int count=SqlHelper.ExecuteNonQuery(sql,pa); return count;2、业务层代码public bool DeleteStudent(int id) return dal.DeleteStudent(id) 0; 3、变现层代码删除操作只需要删除数据然后重新加载页面即可,不需要编辑页面。添加一般处理程序DeleteStudent.ashxprivate StudentBll bll = new StudentBll(); public void ProcessRequest(HttpContext context) context.Response.ContentType = text/html; /c

      《课程4上课日志4+三层架构》由会员 y****g分享,可在线阅读,更多相关《课程4上课日志4+三层架构》请在金锄头文库上搜索。

      点击阅读更多内容
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.