asp.net|server|架构|数据
#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对象是另外一个独立的类,如下: