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

📄 roomordermodule.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>
	///		RoomOrderModule 的摘要说明。
	/// </summary>
	public class RoomOrderModule : ModuleBase
	{
		protected System.Web.UI.WebControls.Label CreateLabel;
		protected System.Web.UI.WebControls.TextBox NameTextBox;
		protected System.Web.UI.WebControls.TextBox PhoneTextBox;
		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 RoomIdLabel;
		protected System.Web.UI.WebControls.TextBox IdentityTextBox;
		protected System.Web.UI.WebControls.Label NowTimeLabel;
		protected System.Web.UI.WebControls.Button Order;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.TextBox DescriptionTextBox;
		protected System.Web.UI.WebControls.TextBox RemarksTextBox;
		protected System.Web.UI.WebControls.Label ShowMsg;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack){
			   RoomIdLabel.Text=Request.QueryString["RoomId"].ToString();
               NowTimeLabel.Text=DateTime.Now.ToString();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Order.Click += new System.EventHandler(this.Order_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Order_Click(object sender, System.EventArgs e)
		{ 
			if(Page.IsValid)
			{   
				//从文件Web.config中读取连接字符串
				string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn= new SqlConnection (sqldb);
				Conn.Open ();
				//利用Command对象调用存储过程
				SqlCommand mycommand=new SqlCommand  ("sp_AddOrder",Conn);
				//将命令类型转为存储类型
				mycommand.CommandType =CommandType.StoredProcedure ;
				//往存储过程中添加参数
				mycommand.Parameters .Add ("@RoomId",SqlDbType.Int);
				mycommand.Parameters .Add ("@CName",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@CIdentityId",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@CPhone",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@BeginTime",SqlDbType.DateTime);
				mycommand.Parameters .Add ("@Remarks",SqlDbType.NVarChar);
				//给存储过程的参数付值
				mycommand.Parameters ["@RoomId"].Value =int.Parse(RoomIdLabel.Text.Trim());
				mycommand.Parameters ["@CName"].Value = NameTextBox.Text.Trim();
				mycommand.Parameters ["@CIdentityId"].Value =IdentityTextBox.Text.Trim();
				mycommand.Parameters ["@CPhone"].Value =PhoneTextBox.Text.Trim();
                mycommand.Parameters ["@BeginTime"].Value =NowTimeLabel.Text;
				mycommand.Parameters ["@Remarks"].Value =RemarksTextBox.Text.Trim();
				try
				{
					mycommand.ExecuteNonQuery();
					ShowMsg.Text="房间"+ RoomIdLabel.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 + -