初步学习petshop
2006-04-21 23:37 Clingingboy 阅读(859) 评论(0) 收藏 举报| 项目 | 用途 |
|
BLL |
业务逻辑组件存放之处 |
|
ConfigTool |
用来加密连接字符串和创建事件日志源的管理应用程序 |
|
DALFactory |
用来确定加载哪一个数据库访问程序集的类 |
|
IDAL |
每个 DAL 实现都要实现的一组接口 |
|
Model |
瘦数据类或业务实体 |
|
OracleDAL |
Oracle 特定的 Pet Shop DAL 实现,使用了 IDAL 接口 |
|
Post-Build |
运行编译后操作的项目,比如将程序集添加到 GAC 或 COM+ |
|
Pre-Build |
将程序集从 GAC 删除或从 COM+ 注销程序集的项目 |
|
SQLServerDAL |
Microsoft SQL Server 特定的 Pet Shop DAL 实现,使用了 IDAL 接口 |
|
Utility |
一组帮助器类,包括 DPAPI 的包装 |
|
Web |
Web 页和控件 |
|
Solution Items |
用来构建应用程序的杂项,比如用来签署应用程序程序集的 Pet Shop.snk 密钥文件 |
SQLServerDAL项目中存在一个SQLHelper的辅助类,其中重载了几个方法,用来向数据库发出不同类型的命令
public static int ExecuteNonQuery(string connString, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms) {
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connString)) {
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
.它提供的全是静态类.这个项目的其他类通过这个辅助类进行对数据库数据的操作,相关的几个类全实现了IDAL接口
public class Account : IAccount{Model项目为业务实体,如用户实体
1
using System;
2
3
namespace PetShop.Model {
4
5
/// <summary>
6
/// Business entity used to model accounts
7
/// </summary>
8
[Serializable]
9
public class AccountInfo {
10
11
// 声明成员变量
12
private string _userId;
13
private string _password;
14
private string _email;
15
private AddressInfo _address;
16
private string _language;
17
private string _category;
18
private bool _showFavorites;
19
private bool _showBanners;
20
21
/// <summary>
22
/// Default constructor
23
/// </summary>
24
public AccountInfo() {
25
}
26
27
/// <summary>
28
/// Constructor with specified initial values
29
/// </summary>
30
/// <param name="userId">userId</param>
31
/// <param name="password">密码</param>
32
/// <param name="email">Email</param>
33
/// <param name="address">地址</param>
34
/// <param name="language">语言</param>
35
/// <param name="category">关注类型</param>
36
/// <param name="showFavorites">是否显示我关注的其他信息</param>
37
/// <param name="showBanners">是否显示我所关注的信息</param>
38
public AccountInfo(string userId, string password, string email, AddressInfo address, string language, string category, bool showFavorites, bool showBanners) {
39
this._userId = userId;
40
this._password = password;
41
this._email = email;
42
this._address = address;
43
this._language = language;
44
this._category = category;
45
this._showFavorites = showFavorites;
46
this._showBanners = showBanners;
47
}
48
49
// Properties
50
public string UserId {
51
get { return _userId; }
52
}
53
public string Password {
54
get { return _password; }
55
}
56
public string Email {
57
get { return _email; }
58
}
59
public AddressInfo Address {
60
get { return _address; }
61
}
62
public string Language {
63
get { return _language; }
64
}
65
public string Category {
66
get { return _category; }
67
}
68
public bool IsShowFavorites {
69
get { return _showFavorites; }
70
}
71
public bool IsShowBanners {
72
get { return _showBanners; }
73
}
74
}
75
}
using System;2

3
namespace PetShop.Model {4

5
/// <summary>6
/// Business entity used to model accounts7
/// </summary>8
[Serializable]9
public class AccountInfo {10

11
// 声明成员变量12
private string _userId;13
private string _password;14
private string _email;15
private AddressInfo _address;16
private string _language;17
private string _category;18
private bool _showFavorites;19
private bool _showBanners;20

21
/// <summary>22
/// Default constructor23
/// </summary>24
public AccountInfo() {25
}26

27
/// <summary>28
/// Constructor with specified initial values29
/// </summary>30
/// <param name="userId">userId</param>31
/// <param name="password">密码</param>32
/// <param name="email">Email</param>33
/// <param name="address">地址</param>34
/// <param name="language">语言</param>35
/// <param name="category">关注类型</param>36
/// <param name="showFavorites">是否显示我关注的其他信息</param>37
/// <param name="showBanners">是否显示我所关注的信息</param>38
public AccountInfo(string userId, string password, string email, AddressInfo address, string language, string category, bool showFavorites, bool showBanners) {39
this._userId = userId;40
this._password = password;41
this._email = email;42
this._address = address;43
this._language = language;44
this._category = category;45
this._showFavorites = showFavorites;46
this._showBanners = showBanners;47
}48

49
// Properties50
public string UserId {51
get { return _userId; }52
}53
public string Password {54
get { return _password; }55
}56
public string Email {57
get { return _email; }58
}59
public AddressInfo Address {60
get { return _address; }61
}62
public string Language {63
get { return _language; }64
}65
public string Category {66
get { return _category; }67
}68
public bool IsShowFavorites {69
get { return _showFavorites; }70
}71
public bool IsShowBanners {72
get { return _showBanners; }73
}74
}75
}BLL这个项目就开始调用对数据库表操作的方法了.其中每个类都通过DALFactory项目载入需要的程序集,然后执行相关业务操作
这个是基本思想

浙公网安备 33010602011771号