正文

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

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


6.刪除收費(fèi)供求信息

DeleteLeaguerInfo()方法主要用于刪除收費(fèi)供求信息。實(shí)現(xiàn)代碼如下:

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

#region 刪除收費(fèi)供求信息

/// <summary>

/// 刪除收費(fèi)供求信息

/// </summary>

/// <param name="id">要?jiǎng)h除信息的ID</param>

public void DeleteLeaguerInfo(string id)

{

int d = data.RunProc("Delete from tb_LeaguerInfo where id='" + id + "'");

}

#endregion

7.查詢收費(fèi)供求信息

SelectLeaguerInfo()方法為可重載方法,用于根據(jù)不同的條件查詢收費(fèi)供求信息。實(shí)現(xiàn)代碼如下:

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

#region 查詢收費(fèi)供求信息

/// <summary>

/// 顯示所有的收費(fèi)信息

/// </summary>

/// <returns>返回DataSet結(jié)果集</returns>

public DataSet SelectLeaguerInfo()

{

return data.RunProcReturn("Select * from tb_LeaguerInfo order by date desc", "tb_LeaguerInfo");

}

/// <summary>

/// 查詢收費(fèi)到期和未到期供求信息

/// </summary>

/// <param name="All">True顯示未到期信息,False顯示到期信息</param>

/// <returns>返回DataSet結(jié)果集</returns>

public DataSet SelectLeaguerInfo(bool All)

{

if (All) //顯示有效收費(fèi)信息

return data.RunProcReturn("Select * from tb_LeaguerInfo where showday >= getdate() order by date desc", "tb_LeaguerInfo");

else //顯示過期收費(fèi)信息

return data.RunProcReturn("select * from tb_LeaguerInfo where showday<getdate() order by date desc", "tb_LeaguerInfo");

}

/// <summary>

/// 查詢同類型收費(fèi)到期和未到期供求信息

/// </summary>

/// <param name="all">True顯示未到期信息,False顯示到期信息</param>

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

/// <returns>返回DataSet結(jié)果集</returns>

public DataSet SelectLeaguerInfo(bool All, string infoType)

{

if (All) //顯示有效收費(fèi)信息

return data.RunProcReturn("Select * from tb_LeaguerInfo where type='" + infoType + "' and showday >= getdate() order by date desc", "tb_LeaguerInfo");

else //顯示過期收費(fèi)信息

return data.RunProcReturn("select * from tb_LeaguerInfo where type='" + infoType + "' and showday<getdate() order by date desc", "tb_LeaguerInfo");

}

/// <summary>

/// 查詢顯示“按類型未過期推薦信息”或“所有的未過期推薦信息”

/// </summary>

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

/// <param name="checkState">True按類型顯示未過期推薦信息 False顯示所有未過期推薦信息</param>

/// <returns></returns>

public DataSet SelectLeaguerInfo(string infoType,bool checkState)

{

if (checkState) //按類型未過期推薦信息

return data.RunProcReturn("SELECT top 20 * FROM tb_LeaguerInfo WHERE (type = '" + infoType + "') AND (showday >= GETDATE()) AND (CheckState = '" + checkState + "') ORDER BY date DESC", "tb_LeaguerInfo");

else //顯示未過期推薦信息

return data.RunProcReturn("SELECT top 10 * FROM tb_LeaguerInfo WHERE (showday >=GETDATE()) AND (CheckState = '" + !checkState + "') ORDER BY date DESC", "tb_LeaguerInfo");

}

/// <summary>

/// 查詢同類型收費(fèi)到期和未到期供求信息(前N條信息)

/// </summary>

/// <param name="all">True顯示未到期信息,F(xiàn)alse顯示到期信息</param>

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

/// <param name="top">獲取前N條信息</param>

/// <returns></returns>

public DataSet SelectLeaguerInfo(bool All, string infoType, int top)

{

if (All) //顯示有效收費(fèi)信息

return data.RunProcReturn("Select top(" + top + ") * from tb_LeaguerInfo where type='" + infoType + "' and showday >= getdate() order by date desc", "tb_LeaguerInfo");

else //顯示過期收費(fèi)信息

return data.RunProcReturn("select top(" + top + ") * from tb_LeaguerInfo where type='" + infoType + "' and showday<getdate() order by date desc", "tb_LeaguerInfo");

}

/// <summary>

/// 根據(jù)ID查詢收費(fèi)供求信息

/// </summary>

/// <param name="id">供求信息ID</param>

/// <returns></returns>

public DataSet SelectLeaguerInfo(string id)

{

return data.RunProcReturn("Select * from tb_LeaguerInfo where id='" + id + "' order by date desc", "tb_LeaguerInfo");

}

#endregion

8.DataList分頁(yè)設(shè)置綁定

PageDataListBind()方法主要用于實(shí)現(xiàn)DataList綁定分頁(yè)功能。實(shí)現(xiàn)代碼如下:

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

#region 分頁(yè)設(shè)置綁定

/// <summary>

/// 綁定DataList控件,并且設(shè)置分頁(yè)

/// </summary>

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

/// <param name="infoKey">查詢的關(guān)鍵字(如果為空,則查詢所有)</param>

/// <param name="currentPage">當(dāng)前頁(yè)</param>

/// <param name="PageSize">每頁(yè)顯示數(shù)量</param>

/// <returns>返回PagedDataSource對(duì)象</returns>

public PagedDataSource PageDataListBind(string infoType, string infoKey, int currentPage,int PageSize)

{

PagedDataSource pds = new PagedDataSource();

pds.DataSource = SelectInfo(infoType, infoKey).Tables[0].DefaultView; //將查詢結(jié)果綁定到分頁(yè)數(shù)據(jù)源上

pds.AllowPaging = true; //允許分頁(yè)

pds.PageSize = PageSize; //設(shè)置每頁(yè)顯示的頁(yè)數(shù)

pds.CurrentPageIndex = currentPage - 1; //設(shè)置當(dāng)前頁(yè)

return pds;

}

#endregion

9.后臺(tái)登錄

Logon()方法主要用于實(shí)現(xiàn)網(wǎng)站后臺(tái)驗(yàn)證用戶登錄功能。實(shí)現(xiàn)代碼如下:

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

#region 后臺(tái)登錄

public DataSet Logon(string user, string pwd)

{

SqlParameter[] parms ={

data.MakeInParam("@sysName",SqlDbType.VarChar,20,user),

data.MakeInParam("@sysPwd",SqlDbType.VarChar,20,pwd)

};

return data.RunProcReturn("Select * from tb_Power where sysName=@sysName and

sysPwd=@sysPwd",parms, "tb_Power");

}

#endregion


上一章目錄下一章

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