正文

供求信息網(wǎng)(11)

ASP.NET項(xiàng)目開發(fā)案例全程實(shí)錄(第2版) 作者:明日科技


4.查詢供求信息

SelectInfo()方法為可重載方法,用于根據(jù)不同的條件查詢免費(fèi)供求信息,通過調(diào)用數(shù)據(jù)層中的RunProcReturn()方法實(shí)現(xiàn)。實(shí)現(xiàn)代碼如下:

例程12 代碼位置:光盤\TM\01\SIS\ App_Code \ Operation.cs

#region 查詢供求信息

/// <summary>

/// 按類型查詢供求信息

/// </summary>

/// <param name="type">供求信息類型</param>

/// <returns>返回查詢結(jié)果DataSet數(shù)據(jù)集</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>返回查詢結(jié)果DataSet數(shù)據(jù)集</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>返回查詢結(jié)果DataSet數(shù)據(jù)集</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">查詢信息的關(guān)鍵字</param>

/// <returns>返回查詢結(jié)果DataSet數(shù)據(jù)集</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.添加收費(fèi)供求信息

InsertLeaguerInfo()方法主要用于將收費(fèi)供求信息添加到數(shù)據(jù)庫中。實(shí)現(xiàn)代碼如下:

例程13 代碼位置:光盤\TM\01\SIS\ App_Code \ Operation.cs

#region 添加收費(fèi)供求信息

/// <summary>

/// 添加收費(fèi)供求信息

/// </summary>

/// <param name="type">信息類型</param>

/// <param name="title">信息標(biāo)題</param>

/// <param name="info">信息內(nèi)容</param>

/// <param name="linkMan">聯(lián)系人</param>

/// <param name="tel">聯(lián)系電話</param>

/// <param name="sumDay">有效天數(shù)</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


上一章目錄下一章

Copyright ? 讀書網(wǎng) ranfinancial.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號 鄂公網(wǎng)安備 42010302001612號