4.查询供求信息
SelectInfo()方法为可重载方法,用于根据不同的条件查询免费供求信息,通过调用数据层中的RunProcReturn()方法实现。实现代码如下:
例程12 代码位置:光盘\TM\01\SIS\ App_Code \ Operation.cs
#region 查询供求信息
/// <summary>
/// 按类型查询供求信息
/// </summary>
/// <param name="type">供求信息类型</param>
/// <returns>返回查询结果DataSet数据集</returns>
public DataSet SelectInfo(string type)
{
SqlParameter[] parms ={ data.MakeInParam("@type", SqlDbType.VarChar, 50, type) };
return data.RunProcReturn("SELECT ID, type, title, info, linkman, tel, checkState, date FROM tb_info where type=@type ORDER BY date DESC", parms, "tb_info");
}
/// <summary>
/// 按类型和ID查询供求信息
/// </summary>
/// <param name="type">供求信息类型</param>
/// <param name="id">供求信息ID</param>
/// <returns>返回查询结果DataSet数据集</returns>
public DataSet SelectInfo(string type, int id)
{
SqlParameter[] parms ={
data.MakeInParam("@type", SqlDbType.VarChar, 50, type) ,
};
return data.RunProcReturn("SELECT ID, type, title, info, linkman, tel, checkState, date FROM tb_info where (type=@type) AND (ID=" + id + ") ORDER BY date DESC", parms, "tb_info1");
}
/// <summary>
/// 按信息类型查询,审核和未审核信息
/// </summary>
/// <param name="type">信息类型</param>
/// <param name="checkState">True 显示审核信息 False显示未审核信息</param>
/// <returns>返回查询结果DataSet数据集</returns>
public DataSet SelectInfo(string type, bool checkState)
{
return data.RunProcReturn("select * from tb_info where type='" + type + "' and checkState='" + checkState + "'", "tb_info");
}
/// <summary>
/// 供求信息快速检索
/// </summary>
/// <param name="type">信息类型</param>
/// <param name="infoSearch">查询信息的关键字</param>
/// <returns>返回查询结果DataSet数据集</returns>
public DataSet SelectInfo(string type, string infoSearch)
{
SqlParameter[] pars ={
data.MakeInParam("@type", SqlDbType.VarChar, 50, type) ,
data.MakeInParam("@info",SqlDbType.VarChar,50,"%"+infoSearch+"%")
};
return data.RunProcReturn("select * from tb_info where (type=@type) and (info like @info)", pars, "tb_info");
}
#endregion
5.添加收费供求信息
InsertLeaguerInfo()方法主要用于将收费供求信息添加到数据库中。实现代码如下:
例程13 代码位置:光盘\TM\01\SIS\ App_Code \ Operation.cs
#region 添加收费供求信息
/// <summary>
/// 添加收费供求信息
/// </summary>
/// <param name="type">信息类型</param>
/// <param name="title">信息标题</param>
/// <param name="info">信息内容</param>
/// <param name="linkMan">联系人</param>
/// <param name="tel">联系电话</param>
/// <param name="sumDay">有效天数</param>
public void InsertLeaguerInfo(string type, string title, string info, string linkMan, string tel, DateTime sumDay,bool checkState)
{
SqlParameter[] parms ={
data.MakeInParam("@type",SqlDbType.VarChar,50,type),
data.MakeInParam("@title",SqlDbType.VarChar,50,title),
data.MakeInParam("@info",SqlDbType.VarChar,500,info),
data.MakeInParam("@linkMan",SqlDbType.VarChar,50,linkMan),
data.MakeInParam("@tel",SqlDbType.VarChar,50,tel),
data.MakeInParam("@showday",SqlDbType.DateTime,8,sumDay),
data.MakeInParam("@CheckState",SqlDbType.Bit,8,checkState)
};
int i = data.RunProc("INSERT INTO tb_LeaguerInfo (type, title, info, linkman, tel,showday,checkState) VALUES (@type, @title,@info,@linkMan, @tel,@showday,@CheckState)", parms);
}
#endregion