TheBeerHouse:五也谈类的结构上

这次要~~说的不是很多~~呵呵主要是今天修理了n台电脑~~好累啊
---ClassDiagram2.gif
上面的图可以下载后在看是大的图片因为地方不够就~~隐藏了

从逻结构上看可以分为两大部分BLL和DAL:
先从DAl数据层说说

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Data.Common;
None.gif
using  System.Web.Caching;
None.gif
None.gif
namespace  MB.TheBeerHouse.DAL
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif   
public abstract class DataAccess
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif      
private string _connectionString = "";
InBlock.gif      
protected string ConnectionString
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif         
get dot.gifreturn _connectionString; }
ExpandedSubBlockStart.gifContractedSubBlock.gif         
set dot.gif{ _connectionString = value; }
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
private bool _enableCaching = true;
InBlock.gif      
protected bool EnableCaching
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif         
get dot.gifreturn _enableCaching; }
ExpandedSubBlockStart.gifContractedSubBlock.gif         
set dot.gif{ _enableCaching = value; }
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
private int _cacheDuration = 0;
InBlock.gif      
protected int CacheDuration
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif         
get dot.gifreturn _cacheDuration; }
ExpandedSubBlockStart.gifContractedSubBlock.gif         
set dot.gif{ _cacheDuration = value; }
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
protected Cache Cache
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif         
get dot.gifreturn HttpContext.Current.Cache; }
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
protected int ExecuteNonQuery(DbCommand cmd)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
if (HttpContext.Current.User.Identity.Name.ToLower() == "sampleeditor")
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif            
foreach (DbParameter param in cmd.Parameters)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif               
if (param.Direction == ParameterDirection.Output ||
InBlock.gif                  param.Direction 
== ParameterDirection.ReturnValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif               
dot.gif{
InBlock.gif                  
switch (param.DbType)
ExpandedSubBlockStart.gifContractedSubBlock.gif                  
dot.gif{
InBlock.gif                     
case DbType.AnsiString:
InBlock.gif                     
case DbType.AnsiStringFixedLength:
InBlock.gif                     
case DbType.String:
InBlock.gif                     
case DbType.StringFixedLength:
InBlock.gif                     
case DbType.Xml:
InBlock.gif                        param.Value 
= "";
InBlock.gif                        
break;
InBlock.gif                     
case DbType.Boolean:
InBlock.gif                        param.Value 
= false;
InBlock.gif                        
break;
InBlock.gif                     
case DbType.Byte:
InBlock.gif                        param.Value 
= byte.MinValue;
InBlock.gif                        
break;
InBlock.gif                     
case DbType.Date:
InBlock.gif                     
case DbType.DateTime:
InBlock.gif                        param.Value 
= DateTime.MinValue;
InBlock.gif                        
break;
InBlock.gif                     
case DbType.Currency:
InBlock.gif                     
case DbType.Decimal:
InBlock.gif                        param.Value 
= decimal.MinValue;
InBlock.gif                        
break;
InBlock.gif                     
case DbType.Guid:
InBlock.gif                        param.Value 
= Guid.Empty;
InBlock.gif                        
break;
InBlock.gif                     
case DbType.Double:
InBlock.gif                     
case DbType.Int16:
InBlock.gif                     
case DbType.Int32:
InBlock.gif                     
case DbType.Int64:
InBlock.gif                        param.Value 
= 0;
InBlock.gif                        
break;
InBlock.gif                     
default:
InBlock.gif                        param.Value 
= null;
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                  }

ExpandedSubBlockEnd.gif               }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return 1;
ExpandedSubBlockEnd.gif         }

InBlock.gif         
else
InBlock.gif            
return cmd.ExecuteNonQuery();
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
protected IDataReader ExecuteReader(DbCommand cmd)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
return ExecuteReader(cmd, CommandBehavior.Default);
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
protected IDataReader ExecuteReader(DbCommand cmd, CommandBehavior behavior)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
return cmd.ExecuteReader(behavior);
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
protected object ExecuteScalar(DbCommand cmd)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
return cmd.ExecuteScalar();
ExpandedSubBlockEnd.gif      }

ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif

//--上面的这个类是数据层的基类~~自然定义了数据层相关的方法请注意上面类的三个方法的参数都是DbCommand是为了应对不同数据库建立的,但是这里比较有意的是他在执行相关操作的时候是调用传入的
DbCommand对向的方法变相的说~~就是在传入之前您老的dbconnection.open();否则估计歇菜~~,而且也得
close()
//--ExecuteNonQuery方法让人摸不着头脑21.gif

sampleeditor--怎么看都向是测试修改~~但是他在过程中又分别给出了不同数据类型的数值~~到底要做什么呢~~大家一起考虑把- -

接下来就是子类的子类~~这些子类定义的时候和逻辑层是息息相关的比如如果有个模块叫sun,那么必然有个位他准备的数据模块- -有点装饰模式的味道哦- -

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Collections.Generic;
None.gif
None.gif
namespace  MB.TheBeerHouse.DAL
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif   
public abstract class PollsProvider : DataAccess
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif      
static private PollsProvider _instance = null;
ExpandedSubBlockStart.gifContractedSubBlock.gif      
/**//// <summary>
InBlock.gif      
/// Returns an instance of the provider type specified in the config file
ExpandedSubBlockEnd.gif      
/// </summary>

InBlock.gif      static public PollsProvider Instance
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
get
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif            
if (_instance == null)
InBlock.gif               _instance 
= (PollsProvider)Activator.CreateInstance(
InBlock.gif                  Type.GetType(Globals.Settings.Polls.ProviderType));
InBlock.gif            
return _instance;
ExpandedSubBlockEnd.gif         }

ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
public PollsProvider()
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
this.ConnectionString = Globals.Settings.Polls.ConnectionString;
InBlock.gif         
this.EnableCaching = Globals.Settings.Polls.EnableCaching;
InBlock.gif         
this.CacheDuration = Globals.Settings.Polls.CacheDuration;
ExpandedSubBlockEnd.gif      }

InBlock.gif
InBlock.gif      
// methods that work with polls
InBlock.gif
      public abstract List<PollDetails> GetPolls(bool includeActive, bool includeArchived);
InBlock.gif      
public abstract PollDetails GetPollByID(int pollID);
InBlock.gif      
public abstract int GetCurrentPollID();
InBlock.gif      
public abstract bool DeletePoll(int pollID);
InBlock.gif      
public abstract bool ArchivePoll(int pollID);
InBlock.gif      
public abstract bool UpdatePoll(PollDetails poll);
InBlock.gif      
public abstract int InsertPoll(PollDetails poll);
InBlock.gif      
public abstract bool InsertVote(int optionID);
InBlock.gif
InBlock.gif      
// methods that work with poll options
InBlock.gif
      public abstract List<PollOptionDetails> GetOptions(int pollID);
InBlock.gif      
public abstract PollOptionDetails GetOptionByID(int optionID);
InBlock.gif      
public abstract bool DeleteOption(int optionID);
InBlock.gif      
public abstract bool UpdateOption(PollOptionDetails option);
InBlock.gif      
public abstract int InsertOption(PollOptionDetails option);      
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif      
/**//// <summary>
InBlock.gif      
/// Returns a new PollDetails instance filled with the DataReader's current record data
ExpandedSubBlockEnd.gif      
/// </summary>

InBlock.gif      protected virtual PollDetails GetPollFromReader(IDataReader reader)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         
return new PollDetails(
InBlock.gif            (
int)reader["PollID"],
InBlock.gif            (DateTime)reader[
"AddedDate"],
InBlock.gif            reader[
"AddedBy"].ToString(),
InBlock.gif            reader[
"QuestionText"].ToString(),
InBlock.gif            (
bool)reader["IsCurrent"],
InBlock.gif            (
bool)reader["IsArchived"],
InBlock.gif            (reader[
"ArchivedDate"== DBNull.Value ? DateTime.MinValue : (DateTime)reader["ArchivedDate"]),
InBlock.gif            (reader[
"Votes"== DBNull.Value ? 0 : (int)reader["Votes"]));
ExpandedSubBlockEnd.gif      }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif      
/**//// <summary>
InBlock.gif      
/// Returns a collection of PollDetails objects with the data read from the input DataReader
ExpandedSubBlockEnd.gif      
/// </summary>

InBlock.gif      protected virtual List<PollDetails> GetPollCollectionFromReader(IDataReader reader)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         List
<PollDetails> polls = new List<PollDetails>();
InBlock.gif         
while (reader.Read())
InBlock.gif            polls.Add(GetPollFromReader(reader));
InBlock.gif         
return polls;
ExpandedSubBlockEnd.gif      }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif      
/**//// <summary>
InBlock.gif      
/// Returns a new PollOptionDetails instance filled with the DataReader's current record data
ExpandedSubBlockEnd.gif      
/// </summary>

InBlock.gif      protected virtual PollOptionDetails GetOptionFromReader(IDataReader reader)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         PollOptionDetails option 
= new PollOptionDetails(
InBlock.gif            (
int)reader["OptionID"],
InBlock.gif            (DateTime)reader[
"AddedDate"],
InBlock.gif            reader[
"AddedBy"].ToString(),
InBlock.gif            (
int)reader["PollID"],
InBlock.gif            reader[
"OptionText"].ToString(),
InBlock.gif            (
int)reader["Votes"],
InBlock.gif            Convert.ToDouble(reader[
"Percentage"]));
InBlock.gif
InBlock.gif         
return option;
ExpandedSubBlockEnd.gif      }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif      
/**//// <summary>
InBlock.gif      
/// Returns a collection of PollOptionDetails objects with the data read from the input DataReader
ExpandedSubBlockEnd.gif      
/// </summary>

InBlock.gif      protected virtual List<PollOptionDetails> GetOptionCollectionFromReader(IDataReader reader)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif         List
<PollOptionDetails> options = new List<PollOptionDetails>();
InBlock.gif         
while (reader.Read())
InBlock.gif            options.Add(GetOptionFromReader(reader));
InBlock.gif         
return options;
ExpandedSubBlockEnd.gif      }

ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif

//--这个还是抽象的~~哈哈~~这下就有意思了~~订立的时隔标准~~就是只要符合这个标准我就不管你数据放在那里~~(当然马桶除外14.gif) 


这个类在构造中得到连接字符串~~以及缓存相关的东西,其他就没什么可说的~~了都是取数据的方法~~有兴趣的研究研究哈

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Data.SqlClient;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Web.Caching;
None.gif
None.gif
namespace  MB.TheBeerHouse.DAL.SqlClient
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif   
public class SqlPollsProvider : PollsProvider
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
这是Polls的最中的sqlserver的数据层值得说说的是,这个类的多数方法根接受的参数也好或者是返回的参数也好都根PollDetails实体类有关系~~,实体类就是保护poll表中所有的字段~~,当然我们在做实体类的时候没必要自己写,省事的用别人的工具~~否则~,

写个字符串模板就像这样. @MM@就用列名填充就好了~~我在做这方面的东西~~当然是看了SubSonic2.0做的~~做好了在分享哈- -
"class  @MM@{}"

。。就说这么多~~腰酸背痛~~哈哈~~修电脑过度了,欢迎大家讨论还是,还是老话题~~共同进步

转载于:https://www.cnblogs.com/ajaxren/archive/2007/05/23/756382.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值