⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 st_rcatgeditmodule.ascx.cs

📁 酒店管理系统,适合做毕业设计的人
💻 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_RCatgEditModule 的摘要说明。
	/// </summary>
	public partial class ST_RCatgEditModule : ST_ModuleBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{   
				//显示房间类型信息
				RCategoryIdLabel.Text=Request.QueryString ["RCategoryId"].ToString ();
				//从文件Web.config中读取连接字符串
				string ST_sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
				//连接ST_GinShopManage数据库
				SqlConnection ST_Conn = new SqlConnection (ST_sqldb);
				ST_Conn.Open ();
				//定义sql语句
				String ST_selsql="select ST_Name,ST_Area,ST_BedNum,ST_Price,ST_AirCondition,ST_TV from ST_RoomCategory where ST_RCategoryId = @RCategoryId";
				//创建ST_mycommand对象,调用ST_selsql
				SqlCommand ST_mycommand=new SqlCommand(ST_selsql,ST_Conn);
				ST_mycommand.Parameters .Add ("@RCategoryId",SqlDbType.Int );
				ST_mycommand.Parameters ["@RCategoryId"].Value = int.Parse(RCategoryIdLabel.Text);
				SqlDataReader dr=ST_mycommand.ExecuteReader ();
				if(dr.Read ())
				{
					RCatgNameTextBox.Text =dr["ST_Name"].ToString ();
					AreaTextBox.Text =dr["ST_Area"].ToString ();
					BedNumTextBox.Text =dr["ST_BedNum"].ToString ();
					PriceTextBox.Text=dr["ST_Price"].ToString ();
				    AirConditionList.SelectedIndex =int.Parse(dr["ST_AirCondition"].ToString());
                    TvList.SelectedIndex =int.Parse(dr["ST_TV"].ToString());
				}
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </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数据库
				SqlConnection ST_Conn = new SqlConnection (ST_sqldb);
				ST_Conn.Open ();
				//定义sql语句
				String updatesql="update ST_RoomCategory set ST_Name=@Name,ST_Area=@Area,ST_BedNum=@BedNum,ST_Price=@Price,ST_AirCondition=@AirCondition,ST_TV=@TV  where ST_RCategoryId = @RCategoryId";
				//利用Command对象调用updatesql
				SqlCommand ST_mycommand=new SqlCommand (updatesql,ST_Conn);
				//往存储过程中添加参数
                ST_mycommand.Parameters .Add ("@RCategoryId",SqlDbType.Int);
				ST_mycommand.Parameters .Add ("@Name",SqlDbType.VarChar);
				ST_mycommand.Parameters .Add ("@Area",SqlDbType.Float);
				ST_mycommand.Parameters .Add ("@BedNum",SqlDbType.Int);
				ST_mycommand.Parameters .Add ("@Price",SqlDbType.Money);
				ST_mycommand.Parameters .Add ("@AirCondition",SqlDbType.Int);
				ST_mycommand.Parameters .Add ("@TV",SqlDbType.Int);
				//给存储过程的参数赋值
                ST_mycommand.Parameters ["@RCategoryId"].Value =int.Parse(RCategoryIdLabel.Text);
				ST_mycommand.Parameters ["@Name"].Value =RCatgNameTextBox.Text.Trim();
				ST_mycommand.Parameters ["@Area"].Value =Convert.ToDouble(AreaTextBox.Text.Trim());
				ST_mycommand.Parameters ["@BedNum"].Value =int.Parse(BedNumTextBox.Text.Trim());
				ST_mycommand.Parameters ["@Price"].Value =Convert.ToDouble(PriceTextBox.Text.Trim());  
				ST_mycommand.Parameters ["@AirCondition"].Value =AirConditionList.SelectedIndex;
				ST_mycommand.Parameters ["@TV"].Value =TvList.SelectedIndex;
				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 + -