-
ASP.NET高级教程(2.1):转换编程思维
作者: bigeagle | ||
上次的内容说过asp.net和asp的最大区别在于编程思维的转换,那么我们现在就来看看如何转换编程思想。以前的web编程从cgi(perl)到asp,php,jsp的编程过程都是这样:美工人员给出页面原型,编程人员照页面填空,最后堆起来算完,下次如果原型变动,那么就再修改程序,这样业务逻辑和html页面混在一起,可以说是事倍功半。那么,现在有了asp.net,我们应该怎么做呢? 让我们找个实际的例子,就拿论坛来说吧,先从顶至下看看它的业务逻辑。我们可以把一个论坛视做一个对象,它有自己的属性和方法,常见的属性有名称、贴子数、用户数、版面数等等,这样的话,我们就可以这样来构造论坛对象: namespace MyOwnClass { using System; using System.Data.SQL ; using System.Data ; //////////////////////////////////////////////////////////////////// // // Class Name : BBS // // Description: 论坛类,构造一个论坛对象 // // date: 2000/02/03 // /// //////////////////////////////////////////////////////////////// public class BBS { //私有变量 private string m_strTitle ; //bbs名称 private int m_intForumCount ; //版面数 private int m_intTopicCount ; //贴子数 private int m_intUserCount ; //注册用户数 //属性 public string Title { get { return m_strTitle ; } } public int ForumCount { get { return m_intForumCount ; } } public int TopicCount { get { return m_intTopicCount ; } } public int UserCount { get { return m_intUserCount ; } } //构造函数 public BBS(string a_strTitle) { // // TODO: Add Constructor Logic here // m_strTitle = a_strTitle ; //读取数据库 MyConnection myConn = new MyConnection() ; SQLCommand myCommand = new SQLCommand() ; myCommand.ActiveConnection = myConn ; myCommand.CommandText = "up_GetBBSInfo" ; //调用存储过程 myCommand.CommandType = CommandType.StoredProcedure ; try { myConn.Open() ; SQLDataReader myReader ; myCommand.Execute(out myReader) ; if (myReader.Read()) { m_intForumCount = (int)myReader["ForumCount"] ; m_intTopicCount = (int)myReader["TopicCount"] ; m_intUserCount = (int)myReader["UserCount"] ; } else { throw(new Exception("表或存储过程不存在")) ; } //清场 myReader.Close(); myConn.Close() ; } catch(SQLException e) { throw(new Exception("数据库出错:" + e.Message)) ; } } } } |
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比