?? st_rbussimanmodule.ascx.cs
字號(hào):
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Context_ST_RBussiManModule :ST_ModuleBase
{
protected string Status;
private int PageSize = 1;///每頁的記錄數(shù)
private int CurrentPage;////當(dāng)前頁
private int RecordCount;///記錄數(shù)
private int PageCount;//總頁數(shù)
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);/////填沖 房間類型 下拉列表
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandText = "select ST_RCategoryId,ST_Name from ST_RoomCategory";
ST_myCon.Open();
SqlDataReader dl = ST_mycommand.ExecuteReader();
while (dl.Read())
{
ListItem li = new ListItem(dl["ST_Name"].ToString(), dl["ST_RCategoryId"].ToString());
this.ddlCategory.Items.Add(li);
}
dl.Close();
ST_myCon.Close();
ViewState["str"]="select * from RoomStatusView";////ViewState["str"]用于保存SQL語句 (次出用于全部顯示時(shí))
Shoe_RoomList(ViewState["str"].ToString());
this.CurrentPage = 0;//////當(dāng)前頁
ViewState["PageIndex"] = 0;
this.RecordCount = RetrunCount(ViewState["str"].ToString());//得到總記錄數(shù)
if (this.RecordCount % this.PageSize == 0)
{
this.PageCount = this.RecordCount / this.PageSize;
}
else
{
this.PageCount = this.RecordCount / this.PageSize;
this.PageCount++;
}
ViewState["PageCount"] = this.PageCount;
}
}
public int RetrunCount(string str)/////得到總記錄數(shù)
{
SQLExe.SQLExe myExe = new SQLExe.SQLExe();
DataSet tempds = new DataSet();
tempds = myExe.GetDataSet(str);
int count = tempds.Tables[0].Rows.Count;
return count;
}
public void Shoe_RoomList(string str)
{
this.lblPre.Enabled = true;
this.lblNext.Enabled = true;
int StartIndex;
StartIndex = this.CurrentPage * this.PageSize;
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
DataSet ds = new DataSet();
SqlCommand myCommand = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
myCommand.Connection = ST_myCon;
myCommand.CommandText=str;
sda.SelectCommand = myCommand;
sda.Fill(ds, StartIndex, this.PageSize, "guest");
this.DataList1.DataSource = ds;
this.DataList1.DataKeyField = "ST_RoomId";
this.DataList1.DataBind();
if (this.CurrentPage == (this.PageCount - 1))////判斷上下頁按鈕是否有效
{
this.lblNext.Enabled = false;
}
if (this.CurrentPage == 0)
{
this.lblPre.Enabled = false;
}
for (int i = 0; i < this.DataList1.Items.Count; i++)
{
DataRow dr = ds.Tables[0].Rows[i];
if (dr["ST_Status"].ToString() == "2")
{
((Label)this.DataList1.Items[i].FindControl("lblIsNull")).Text = "否";
Status = "否";
}
else if(dr["ST_Status"].ToString()=="1")
{
((Label)this.DataList1.Items[i].FindControl("lblIsNull")).Text = "有";
Status = "有";
}
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Detail")
{
int RoomId =int.Parse(this.DataList1.DataKeys[e.Item.ItemIndex].ToString());
Response.Redirect("RoomDetail.aspx?RoomId=" + RoomId);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SQLExe.SQLExe myExe = new SQLExe.SQLExe();
DataSet ds = new DataSet();
string str="";
if (this.ddlCategory.SelectedItem.ToString() != "--請(qǐng)選擇--" && this.ddlState.SelectedItem.ToString() != "--請(qǐng)選擇--")
{
if (this.ddlState.SelectedItem.ToString()== "未訂")
{
str = "select * from RoomStatusView where ST_RCategoryId=" + System.Convert.ToInt32(this.ddlCategory.SelectedValue) + " and ST_Status='2'";
}
else if (this.ddlState.SelectedItem.ToString() == "已訂")
{
str = "select * from RoomStatusView where ST_RCategoryId=" + System.Convert.ToInt32(this.ddlCategory.SelectedValue) + " and ST_Status='1'";
}
}
else if (this.ddlCategory.SelectedItem.ToString() != "--請(qǐng)選擇--")
{
str = "select * from RoomStatusView where ST_RCategoryId=" + System.Convert.ToInt32(this.ddlCategory.SelectedValue) + "";
}
else if (this.ddlState.SelectedItem.ToString() != "--請(qǐng)選擇--")
{
if (this.ddlState.SelectedItem.ToString() == "未訂")
{
str = "select * from RoomStatusView where ST_Status='2'";
}
else if (this.ddlState.SelectedItem.ToString() == "已訂")
{
str = "select * from RoomStatusView where ST_Status='1'";
}
}
else if (this.ddlCategory.SelectedItem.ToString() == "--請(qǐng)選擇--" && this.ddlState.SelectedItem.ToString() == "--請(qǐng)選擇--")
{
str="select * from RoomStatusView";
}
this.CurrentPage = 0;//////當(dāng)前頁
ViewState["PageIndex"] = 0;
ViewState["str"] = str;
this.RecordCount = RetrunCount(ViewState["str"].ToString());//得到總記錄數(shù)
if (this.RecordCount % this.PageSize == 0)
{
this.PageCount = this.RecordCount / this.PageSize;
}
else
{
this.PageCount = this.RecordCount / this.PageSize;
this.PageCount++;
}
ViewState["PageCount"] = this.PageCount;
Shoe_RoomList(str);
}
protected void lblNext_Click(object sender, EventArgs e) /////下頁
{
this.CurrentPage = (int)ViewState["PageIndex"];
this.PageCount = (int)ViewState["PageCount"];
if (this.CurrentPage < (this.PageCount - 1))
{
this.CurrentPage++;
}
ViewState["PageIndex"] = this.CurrentPage;
Shoe_RoomList(ViewState["str"].ToString());
}
protected void lblPre_Click(object sender, EventArgs e)////上頁
{
this.CurrentPage = (int)ViewState["PageIndex"];
this.PageCount = (int)ViewState["PageCount"];
if (this.CurrentPage > 0)
{
this.CurrentPage--;
}
ViewState["PageIndex"] = this.CurrentPage;
Shoe_RoomList(ViewState["str"].ToString());
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -