#region 公共方法
/// <summary>
/// 根据不同条件取得积分设置
/// </summary>
/// <param name="functionid">功能id</param>
/// <param name="operationid">操作id</param>
/// <param name="roletypeid">角色id</param>
/// <param name="bbstypeid">版块类型di</param>
/// <param name="score">积分</param>
/// <param name="bb">币币</param>
/// <param name="buytype">购买类型</param>
/// <param name="functionstate">功能状态</param>
/// <returns></returns>
public bool getspecialinfo(int functionid,int operationid,int roletypeid,int bbstypeid,int score,int bb,int buytype,int functionstate)
{
sqldataadapter dataadapter = null;
database data = new database("town");
#region 创建参数
arraylist sqlparameterlist=new arraylist();
if(functionid!=-1)
sqlparameterlist.add(data.makeinparam("@functionid", sqldbtype.int, 4, functionid));
if(operationid!=-1)
sqlparameterlist.add(data.makeinparam("@operationid", sqldbtype.int, 4, operationid));
if(roletypeid!=-1)
sqlparameterlist.add(data.makeinparam("@roletypeid", sqldbtype.int, 4, roletypeid));
if(bbstypeid!=-1)
sqlparameterlist.add(data.makeinparam("@bbstypeid", sqldbtype.int, 4, bbstypeid));
if(score!=-1)
sqlparameterlist.add(data.makeinparam("@score", sqldbtype.int, 4, score));
if(bb!=-1)
sqlparameterlist.add(data.makeinparam("@bb", sqldbtype.int, 4, bb));
if(buytype!=-1)
sqlparameterlist.add(data.makeinparam("@buytype", sqldbtype.int, 4, buytype));
if(functionstate!=-1)
sqlparameterlist.add(data.makeinparam("@functionstate", sqldbtype.int, 4, functionstate));
sqlparameter[] prams= new sqlparameter[sqlparameterlist.count];
for( int i=0;i<sqlparameterlist.count;i++)
{
prams[i]=(sqlparameter)sqlparameterlist[i];
}
#endregion
try
{
data.runproc("getscoresetting", prams, out dataadapter);
dataset dataset = new dataset();
dataadapter.fill(dataset,"table");
dataadapter.dispose();
if(dataset.tables["table"].rows.count == 0)
{
dataset.clear();
dataset.dispose();
return false;
}
else
{
foreach(datarow dr in dataset.tables["table"].rows)
{
scoresetting ss = new scoresetting();
ss.id= int32.parse(dr["scoresettingid"].tostring().trim());
ss.functionid= int32.parse(dr["functionid"].tostring().trim());
ss.operationid= int32.parse(dr["operationid"].tostring().trim());
ss.roletypeid= int32.parse(dr["roletypeid"].tostring().trim());
ss.bbstypeid= int32.parse(dr["bbstypeid"].tostring().trim());
ss.score= int32.parse(dr["score"].tostring().trim());
ss.bb= int32.parse(dr["bb"].tostring().trim());
ss.buytype= int32.parse(dr["buytype"].tostring().trim());
ss.functionstate= int32.parse(dr["functionstate"].tostring().trim());
add(ss);
}
dataset.clear();
dataset.dispose();
return true;
}
}
catch (exception ex)
{
error.log("town", ex.tostring());
dataadapter.dispose();
return false;
}
finally
{
data.close();
data.dispose();//释放database
}
}
#endregion
}
}
一点说明:
数据层类分类的代码分了六块:私有成员、构造函数、公共属性、索引、私有方法、公有方法。这里为类建立了索引,这是集合类的必须元素。然后有一个私有方法,作用是把对象加到集合中,公有方法就是一个查询方法,上面的例子中是通过参数传的,其实也可以用属性传。这里作了个约定,如果传进的值为-1便认为此变量不起作用,基本跟存储过程中的思想是一样的。这个例子中的scoresetting对象是另外一个独立的类,如下: