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

📄 roomcheckoutmodule.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>
	///		RoomCheckOutModule 的摘要说明。
	/// </summary>
	public class RoomCheckOutModule : ModuleBase
	{
		protected System.Web.UI.WebControls.Label CreateLabel;
		protected System.Web.UI.WebControls.Label RoomIdLabel;
		protected System.Web.UI.WebControls.Label NowTimeLabel;
		protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
		protected System.Web.UI.WebControls.HyperLink Return;
		protected System.Web.UI.WebControls.Label NameLabel;
		protected System.Web.UI.WebControls.Label IdentityLabel;
		protected System.Web.UI.WebControls.Label PhoneLabel;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Label OrderTimeLabel;
		protected System.Web.UI.WebControls.TextBox RemarksTextBox;
		protected System.Web.UI.WebControls.Button CheckOut;
		protected System.Web.UI.WebControls.Label TotalPriceLabel;
		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();
				//从文件Web.config中读取连接字符串
				string sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				//创建mycommand对象,调用selsql
				SqlCommand mycommand=new SqlCommand("sp_getOrder",Conn);
				mycommand.CommandType=CommandType.StoredProcedure;
				mycommand.Parameters .Add ("@RoomId",SqlDbType.Int);
				mycommand.Parameters ["@RoomID"].Value = int.Parse(RoomIdLabel.Text);
				SqlDataReader dr=mycommand.ExecuteReader ();
				if(dr.Read ())
				{
					NameLabel.Text =dr["CName"].ToString ();
					IdentityLabel.Text =dr["CIdentityId"].ToString ();
					PhoneLabel.Text=dr["CPhone"].ToString ();
					OrderTimeLabel.Text =dr["BeginTime"].ToString ();
					RemarksTextBox.Text=dr["Remarks"].ToString ();

				}
			}
		}

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

		}
		#endregion

		private void CheckOut_Click(object sender, System.EventArgs e)
		{
			bool isValid=true;
			//检验该房间是否已退房
			//从文件Web.config中读取连接字符串
			string sqldb0 = ConfigurationSettings.AppSettings["ConnectionString"];
			//连接JdglSys数据库
			SqlConnection Conn0 = new SqlConnection (sqldb0);
			Conn0.Open ();
			string selsql="select * from History where RoomId='"+RoomIdLabel.Text+"' and BeginTime='"+OrderTimeLabel.Text+"'";
			//利用Command对象调用存储过程
			SqlCommand command=new SqlCommand (selsql,Conn0);
			//执行ExecuteReader ()方法
			SqlDataReader dr=command.ExecuteReader ();
			if(dr.Read ())
			{
				isValid =false;//该房间已退
				ShowMsg.Text="该房间已退,请返回进行其它操作";
				ShowMsg.Style["color"]="red";
			}
			//关闭连接
			Conn0.Close();
    
				
			//如果该房间为被退,则进行退房操作
			if(isValid)
			{
				//从文件Web.config中读取连接字符串
				string sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				//利用Command对象调用存储过程
				SqlCommand mycommand=new SqlCommand ("sp_AddCheckOut",Conn);
				mycommand.CommandType=CommandType.StoredProcedure;
				//添加参数
				mycommand.Parameters .Add ("@RoomId",SqlDbType.Int);
				mycommand.Parameters .Add ("@BeginTime",SqlDbType.DateTime);
				mycommand.Parameters .Add ("@EndTime",SqlDbType.DateTime);
				mycommand.Parameters .Add ("@CIdentityId",SqlDbType.VarChar);
				mycommand.Parameters .Add ("@CName",SqlDbType.VarChar);
				mycommand.Parameters .Add ("@CPhone",SqlDbType.VarChar);
				mycommand.Parameters .Add ("@Remarks",SqlDbType.VarChar);
				SqlParameter TotalPrice=new SqlParameter("@TotalPrice",SqlDbType.Int);
				TotalPrice.Direction=ParameterDirection.Output;
				//给存储过程的参数赋值
				mycommand.Parameters ["@RoomId"].Value =RoomIdLabel.Text;
				mycommand.Parameters ["@BeginTime"].Value =OrderTimeLabel.Text;
				mycommand.Parameters ["@EndTime"].Value =NowTimeLabel.Text;
				mycommand.Parameters ["@CIdentityId"].Value =IdentityLabel.Text;
				mycommand.Parameters ["@CName"].Value =NameLabel.Text;
				mycommand.Parameters ["@CPhone"].Value =PhoneLabel.Text;
				mycommand.Parameters ["@Remarks"].Value =RemarksTextBox.Text.Trim();
				mycommand.Parameters.Add(TotalPrice);
				try
				{
					mycommand.ExecuteNonQuery();
					TotalPriceLabel.Text=TotalPrice.Value.ToString();
					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 + -