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

📄 rcatgeditmodule.ascx.cs

📁 这是酒店客房管理系统
💻 CS
字号:
namespace JdglWeb.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>
	///		RCatgEditModule 的摘要说明。
	/// </summary>
	public class RCatgEditModule : ModuleBase
	{
		protected System.Web.UI.WebControls.Label CreateLabel;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
		protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
		protected System.Web.UI.WebControls.Button Submit;
		protected System.Web.UI.WebControls.HyperLink Return;
		protected System.Web.UI.WebControls.Label RCategoryIdLabel;
		protected System.Web.UI.WebControls.TextBox RCatgNameTextBox;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.TextBox AreaTextBox;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox BedNumTextBox;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.TextBox PriceTextBox;
		protected System.Web.UI.WebControls.RadioButtonList AirConditionList;
		protected System.Web.UI.WebControls.RadioButtonList TvList;
		protected System.Web.UI.WebControls.Label ShowMsg;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{   
				//显示房间类型信息
				RCategoryIdLabel.Text=Request.QueryString ["RCategoryId"].ToString ();
				//从文件Web.config中读取连接字符串
				string sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				//定义sql语句
				String selsql="select Name,Area,BedNum,Price,AirCondition,TV from RoomCategory where RCategoryId = @RCategoryId";
				//创建mycommand对象,调用selsql
				SqlCommand mycommand=new SqlCommand(selsql,Conn);
				mycommand.Parameters .Add ("@RCategoryId",SqlDbType.Int );
				mycommand.Parameters ["@RCategoryId"].Value = int.Parse(RCategoryIdLabel.Text);
				SqlDataReader dr=mycommand.ExecuteReader ();
				if(dr.Read ())
				{
					RCatgNameTextBox.Text =dr["Name"].ToString ();
					AreaTextBox.Text =dr["Area"].ToString ();
					BedNumTextBox.Text =dr["BedNum"].ToString ();
					PriceTextBox.Text=dr["Price"].ToString ();
				    AirConditionList.SelectedIndex =int.Parse(dr["AirCondition"].ToString());
                    TvList.SelectedIndex =int.Parse(dr["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 sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				//定义sql语句
				String updatesql="update RoomCategory set Name=@Name,Area=@Area,BedNum=@BedNum,Price=@Price,AirCondition=@AirCondition,TV=@TV  where RCategoryId = @RCategoryId";
				//利用Command对象调用updatesql
				SqlCommand mycommand=new SqlCommand (updatesql,Conn);
				//往存储过程中添加参数
                mycommand.Parameters .Add ("@RCategoryId",SqlDbType.Int);
				mycommand.Parameters .Add ("@Name",SqlDbType.VarChar);
				mycommand.Parameters .Add ("@Area",SqlDbType.Float);
				mycommand.Parameters .Add ("@BedNum",SqlDbType.Int);
				mycommand.Parameters .Add ("@Price",SqlDbType.Money);
				mycommand.Parameters .Add ("@AirCondition",SqlDbType.Int);
				mycommand.Parameters .Add ("@TV",SqlDbType.Int);
				//给存储过程的参数赋值
                mycommand.Parameters ["@RCategoryId"].Value =int.Parse(RCategoryIdLabel.Text);
				mycommand.Parameters ["@Name"].Value =RCatgNameTextBox.Text.Trim();
				mycommand.Parameters ["@Area"].Value =Convert.ToDouble(AreaTextBox.Text.Trim());
				mycommand.Parameters ["@BedNum"].Value =int.Parse(BedNumTextBox.Text.Trim());
				mycommand.Parameters ["@Price"].Value =Convert.ToDouble(PriceTextBox.Text.Trim());  
				mycommand.Parameters ["@AirCondition"].Value =AirConditionList.SelectedIndex;
				mycommand.Parameters ["@TV"].Value =TvList.SelectedIndex;
				try
				{
					mycommand.ExecuteNonQuery();
					ShowMsg.Text="房间类型信息修改成功";
					ShowMsg.Style["color"]="green";}
				catch(SqlException error)
				{
					ShowMsg.Text="修改未成功,请稍后再试。原因:"+error.Message;
					ShowMsg.Style["color"]="red";
				}
				//关闭连接
				Conn.Close();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -