?? st_roomeditmodule.ascx.cs
字號:
namespace ST_GROUP.Modules
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
/// <summary>
/// ST_RoomEditModule 的摘要說明。
/// </summary>
public partial class ST_RoomEditModule : ST_ModuleBase
{
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//綁定房間類型信息下拉列表框
//從文件Web.config中讀取連接字符串
string ST_sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//連接ST_GinShopManage數(shù)據(jù)庫
SqlConnection ST_Conn= new SqlConnection (ST_sqldb);
ST_Conn.Open ();
//定義sql語句
string ST_mysql="select ST_RCategoryId,ST_Name from ST_RoomCategory ";
SqlCommand ST_command=new SqlCommand (ST_mysql,ST_Conn);
SqlDataReader dr=ST_command.ExecuteReader ();
while(dr.Read ())
{
ListItem li=new ListItem(dr["ST_Name"].ToString(),dr["ST_RCategoryId"].ToString());
RCategoryNameList.Items.Add (li);
}
ST_Conn.Close ();
//顯示房間信息
RoomIdLabel.Text=Request.QueryString ["RoomId"].ToString ();
//連接ST_GinShopManage數(shù)據(jù)庫
SqlConnection ST_Conn1 = new SqlConnection (ST_sqldb);
ST_Conn1.Open ();
//利用Command對象調(diào)用存儲過程
SqlCommand ST_mycommand=new SqlCommand ("ST_ShowRoomById",ST_Conn1);
//將命令類型轉為存儲類型
ST_mycommand.CommandType =CommandType.StoredProcedure ;
ST_mycommand.Parameters .Add ("@RoomId",SqlDbType.Int);
ST_mycommand.Parameters ["@RoomID"].Value = int.Parse(RoomIdLabel.Text);
SqlDataReader dr1=ST_mycommand.ExecuteReader ();
if(dr1.Read ())
{
RCategoryNameList.Items.FindByText(dr1["ST_Name"].ToString()).Selected=true;
RPositionTextBox.Text =dr1["ST_RPosition"].ToString();
DescriptionTextBox.Text =dr1["ST_Description"].ToString ();
}
//關閉ST_Conn1
ST_Conn1.Close();
}
}
//房間類型是否已選定
public void NotNullValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if(RCategoryNameList.SelectedIndex==0)
{
args.IsValid =false;//房間類型未選
}
else
{
args.IsValid =true;//房間類型已選
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.Submit.Click += new System.EventHandler(this.Submit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Submit_Click(object sender, System.EventArgs e)
{
if(Page.IsValid )
{
//從文件Web.config中讀取連接字符串
string ST_sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
//連接ST_GinShopManage數(shù)據(jù)庫
SqlConnection ST_Conn = new SqlConnection (ST_sqldb);
ST_Conn.Open ();
//定義sql語句
String updatesql="update ST_RoomsInfo set ST_RCategoryId= @RCategoryId, ST_RPosition=@RPosition,ST_Description=@Description where ST_RoomId = @RoomId";
//利用Command對象調(diào)用updatesql
SqlCommand ST_mycommand=new SqlCommand (updatesql,ST_Conn);
//添加參數(shù)
ST_mycommand.Parameters .Add ("@RoomId",SqlDbType.Int);
ST_mycommand.Parameters .Add ("@RCategoryId",SqlDbType.Int);
ST_mycommand.Parameters .Add ("@RPosition",SqlDbType.NVarChar);
ST_mycommand.Parameters .Add ("@Description",SqlDbType.NVarChar);
//給存儲過程的參數(shù)賦值
ST_mycommand.Parameters ["@RoomId"].Value =RoomIdLabel.Text;
ST_mycommand.Parameters ["@RCategoryId"].Value =RCategoryNameList.SelectedIndex;
ST_mycommand.Parameters ["@RPosition"].Value =RPositionTextBox.Text.Trim();
ST_mycommand.Parameters ["@Description"].Value =DescriptionTextBox.Text.Trim();
try
{
ST_mycommand.ExecuteNonQuery();
ShowMsg.Text="房間信息修改成功";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="修改未成功,請稍后再試。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//關閉連接
ST_Conn.Close();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -