Cache使用方法1
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ypxt.IDAL;
using System.Data;
using System.Data.SqlClient;
using ypxt.MODEL;
using ypxt.DBUtility;
namespace ypxt.SQLDAL
{
public class DALKey: IKey
{
private const string PARM_KeyId = "@KeyId";
private const string PARM_KeyText = "@KeyText";
private const string PARM_AdverId = "@AdverId";
private const string PARM_Money = "@Money";
private const string ADD_Keyinfo = "Insert into Key(KeyText,AdverId,Money) values(" + PARM_KeyText + "," + PARM_AdverId + "," + PARM_Money + ")";
private const string UPDATE_Keyinfo = "UPDATE Key SET KeyText=" + PARM_KeyText + ",AdverId=" + PARM_AdverId + ",Money=" + PARM_Money + " WHERE CorpId=" + PARM_KeyId;
private const string DELETE_KeyinfoByID = "DELETE FROM Key WHERE KeyId=" + PARM_KeyId;
private const string SELECT_KeyinfoByID = "SELECT * FROM Key WHERE KeyId=" + PARM_KeyId;
private const string SELECT_Keyinfo = "SELECT * FROM Key";
/// 增加数据 ---郑
#region
public bool addKeyinfo(Keyinfo Keyinfo)
{
SqlParameter[] param = GetKeyinfoParameters();
setKeyinfoParameters(param, Keyinfo);
int result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, ADD_Keyinfo, param);
if (result == 0)
{
return false;
}
return true;
}
public static SqlParameter[] GetKeyinfoParameters()
{
//从缓存里面取参数,如果缓存里面没有参数,就将 参数加入缓存里面,,)
SqlParameter[] param = SqlHelper.GetCachedParameters(ADD_Keyinfo);//.GetCachedParameters(ADD_MEMBERINFO);//从缓存里面取数据
//将参数加入缓存里面
if (param == null)
{
/// 创建各个参数
param = new SqlParameter[]{
new SqlParameter(PARM_KeyText,SqlDbType.NVarChar,50),
new SqlParameter(PARM_AdverId,SqlDbType.Int,30),
new SqlParameter(PARM_Money,SqlDbType.Decimal,30)
};
//放入缓存
SqlHelper.CacheParameters(ADD_Keyinfo, param);
}
return param;
}
public static void setKeyinfoParameters(SqlParameter[] parms, Keyinfo Keyinfo)
{
parms[0].Value = Keyinfo.KeyText;
parms[1].Value = Keyinfo.AdverId;
parms[2].Value = Keyinfo.Money;
}
#endregion
#region
public bool updateKeyinfo(Keyinfo Keyinfo)
{
return true;
}
#endregion
public bool deleteKeyinfo(int KeyinfoID)
{
return true;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ypxt.IDAL;
using System.Data;
using System.Data.SqlClient;
using ypxt.MODEL;
using ypxt.DBUtility;
namespace ypxt.SQLDAL
{
public class DALKey: IKey
{
private const string PARM_KeyId = "@KeyId";
private const string PARM_KeyText = "@KeyText";
private const string PARM_AdverId = "@AdverId";
private const string PARM_Money = "@Money";
private const string ADD_Keyinfo = "Insert into Key(KeyText,AdverId,Money) values(" + PARM_KeyText + "," + PARM_AdverId + "," + PARM_Money + ")";
private const string UPDATE_Keyinfo = "UPDATE Key SET KeyText=" + PARM_KeyText + ",AdverId=" + PARM_AdverId + ",Money=" + PARM_Money + " WHERE CorpId=" + PARM_KeyId;
private const string DELETE_KeyinfoByID = "DELETE FROM Key WHERE KeyId=" + PARM_KeyId;
private const string SELECT_KeyinfoByID = "SELECT * FROM Key WHERE KeyId=" + PARM_KeyId;
private const string SELECT_Keyinfo = "SELECT * FROM Key";
/// 增加数据 ---郑
#region
public bool addKeyinfo(Keyinfo Keyinfo)
{
SqlParameter[] param = GetKeyinfoParameters();
setKeyinfoParameters(param, Keyinfo);
int result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, ADD_Keyinfo, param);
if (result == 0)
{
return false;
}
return true;
}
public static SqlParameter[] GetKeyinfoParameters()
{
//从缓存里面取参数,如果缓存里面没有参数,就将 参数加入缓存里面,,)
SqlParameter[] param = SqlHelper.GetCachedParameters(ADD_Keyinfo);//.GetCachedParameters(ADD_MEMBERINFO);//从缓存里面取数据
//将参数加入缓存里面
if (param == null)
{
/// 创建各个参数
param = new SqlParameter[]{
new SqlParameter(PARM_KeyText,SqlDbType.NVarChar,50),
new SqlParameter(PARM_AdverId,SqlDbType.Int,30),
new SqlParameter(PARM_Money,SqlDbType.Decimal,30)
};
//放入缓存
SqlHelper.CacheParameters(ADD_Keyinfo, param);
}
return param;
}
public static void setKeyinfoParameters(SqlParameter[] parms, Keyinfo Keyinfo)
{
parms[0].Value = Keyinfo.KeyText;
parms[1].Value = Keyinfo.AdverId;
parms[2].Value = Keyinfo.Money;
}
#endregion
#region
public bool updateKeyinfo(Keyinfo Keyinfo)
{
return true;
}
#endregion
public bool deleteKeyinfo(int KeyinfoID)
{
return true;
}
}
}