📄 st_rcatgmanmodule.ascx.cs
字号:
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;
using SQLExe;
public partial class ST_RCatgManModule : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Show_RCategoryList();
}
}
protected void Show_RCategoryList()
{
SQLExe.SQLExe myExe = new SQLExe.SQLExe();
DataSet ds = new DataSet();
string str = "select * from ST_RoomCategory";
ds = myExe.GetDataSet(str);
this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
}
protected void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "Detail")
{
Response.Redirect("ST_RCategoryEdit.aspx?RCategoryId=" + e.Item.Cells[0].Text.ToString());//传递房间编号
}
if (e.CommandName == "Delete")
{
string str = "delete from ST_RoomCategory where ST_RCategoryId=@RCategoryId";
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandText = str;
ST_mycommand.Parameters.Add("@RCategoryId", SqlDbType.Int);
ST_mycommand.Parameters["@RCategoryId"].Value = System.Convert.ToInt32(e.Item.Cells[0].Text);
try
{
ST_myCon.Open();
ST_mycommand.ExecuteNonQuery();
this.DataGrid1.EditItemIndex = -1;
Show_RCategoryList();
}
catch (Exception exx)
{
throw (exx);
}
finally
{
ST_myCon.Close();
}
}
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
Show_RCategoryList();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
SqlDataAdapter ST_myadapter = new SqlDataAdapter();
DataSet ds = new DataSet();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandText = "select * from ST_RoomCategory where ST_Name=@Name";
ST_mycommand.Parameters.Add("@Name", SqlDbType.VarChar, 50);
ST_mycommand.Parameters["@Name"].Value = this.txtSearch.Text.ToString();
try
{
ST_myCon.Open();
ST_mycommand.ExecuteNonQuery();
ST_myadapter.SelectCommand = ST_mycommand;
ST_myadapter.Fill(ds);
this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
}
catch (SqlException exx)
{
throw (exx);
}
finally
{
ST_myCon.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -