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

📄 st_customersmanmodule.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;
	using ST_GROUP;

	/// <summary>
	///		ST_CustomersManModule 的摘要说明。
	/// </summary>
	public partial class ST_CustomersManModule : ST_ModuleBase
	{

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack) Show_CustomersList();
		}

		protected void Show_CustomersList()
		{	
			//从文件Web.config中读取连接字符串
			string ST_sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
			//连接ST_GinShopManage数据库
			SqlConnection ST_Conn = new SqlConnection (ST_sqldb);
			//定义sql语句
			String ST_selsql="select c.ST_CName,c.ST_CIdentityId,r.ST_RoomId,r.ST_BeginTime,d.ST_EndTime,c.ST_CPhone "
				+" from ST_RoomOperation r inner join ST_CustomersInfo c on c.ST_CIdentityId=r.ST_CIdentityId "
				+" left outer join ST_History d on c.ST_CIdentityId=d.ST_CIdentityId";
			//创建SqlDataAdapter对象,调用ST_selsql
			SqlDataAdapter ST_myadapter = new SqlDataAdapter (ST_selsql,ST_Conn);
			//创建并填充DataSet
			DataSet ST_ds = new DataSet ();
			ST_myadapter.Fill (ST_ds);
        
			dg_CustomersList.DataSource =ST_ds;
			dg_CustomersList.DataBind ();

			ST_Conn.Close ();
		}

		protected void DataGrid_Page(Object sender,DataGridPageChangedEventArgs E)
		{
			dg_CustomersList.CurrentPageIndex =E.NewPageIndex ;
			Show_CustomersList();
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.search.Click += new System.EventHandler(this.search_Click);
			this.dg_CustomersList.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_CustomersList_ItemCommand);
			this.ShowAll.Click += new System.EventHandler(this.ShowAll_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ShowAll_Click(object sender, System.EventArgs e)
		{
			Show_CustomersList();
		}

		private void search_Click(object sender, System.EventArgs e)
		{
            dg_CustomersList.CurrentPageIndex=0;

			//从文件Web.config中读取连接字符串
			string ST_sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
			//连接ST_GinShopManage数据库
			SqlConnection ST_Conn = new SqlConnection (ST_sqldb);
			//定义sql语句
			String ST_selsql="select c.ST_CName,c.ST_CIdentityId,r.ST_RoomId,r.ST_BeginTime,c.ST_CPhone "+
				"from ST_RoomOperation r,ST_CustomersInfo c where c.ST_CIdentityId=r.ST_CIdentityId";
			//读取时间纪录
			string ST_datefrom=YearFromList.SelectedItem.Value.ToString()+"-"+MouthFromList.SelectedItem.Value.ToString()+"-"+DayFromList.SelectedItem.Value.ToString();
			string ST_dateto=YearToList.SelectedItem.Value.ToString()+"-"+MouthToList.SelectedItem.Value.ToString()+"-"+DayToList.SelectedItem.Value.ToString();
            ST_selsql=ST_selsql+" and r.ST_BeginTime between '"+ST_datefrom+"'and'"+ST_dateto+"'";
			//读取方式记录
			if(InputTextBox.Text!="")
			{
				//按姓名
			    if(StatusList.SelectedIndex==1)
					ST_selsql=ST_selsql+" and c.ST_CName='"+InputTextBox.Text.Trim()+"'";
				//按身份证号
				else if(StatusList.SelectedIndex==2)
                    ST_selsql=ST_selsql+" and c.ST_CIdentityId='"+InputTextBox.Text.Trim()+"'";
			}
			//创建SqlDataAdapter对象,调用ST_selsql
			SqlDataAdapter ST_myadapter = new SqlDataAdapter (ST_selsql,ST_Conn);
			//创建并填充DataSet
			DataSet ST_ds = new DataSet ();
			ST_myadapter.Fill (ST_ds);

			dg_CustomersList.DataSource =ST_ds;
			dg_CustomersList.DataBind ();

			ST_Conn.Close ();
		}

		private void dg_CustomersList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if(e.Item.Cells.Count>1)
			{
				DateTime begin=DateTime.Parse(e.Item.Cells [4].Text);
				System.TimeSpan timeSpan=DateTime.Now-begin  ;
				int ST_Day=timeSpan.Days+1;
		
				string ST_RoomID = e.Item.Cells[3].Text;
				string ST_CIdentityId = e.Item.Cells[1].Text;
				string ST_CName = e.Item.Cells[0].Text;
				string ST_CPhone = e.Item.Cells[2].Text;
			
				double ST_TotalPrice=0;
			
				//从文件Web.config中读取连接字符串
				string ST_sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
				//连接ST_GinShopManage数据库
				SqlConnection ST_Conn= new SqlConnection (ST_sqldb);
				ST_Conn.Open ();
				//定义sql语句
				string ST_mysql= "select ST_Price from ST_RoomCategory a,ST_RoomsInfo b where a.ST_RCategoryId=b.ST_RCategoryId "
					+" and b.ST_RoomId='"+ST_RoomID+"'";
				SqlCommand ST_command=new SqlCommand  (ST_mysql,ST_Conn);
				SqlDataReader ST_dr=ST_command.ExecuteReader ();
				if(ST_dr.Read ())
				{
					ST_TotalPrice=double.Parse(ST_dr["ST_Price"].ToString());

				}
				ST_Conn.Close ();
			
				//结算
				ST_TotalPrice = ST_TotalPrice*ST_Day;
				ST_mysql = "insert into ST_History values('" + e.Item.Cells[4].Text + "','"
					+ DateTime.Now + "','" + ST_RoomID + "'," + ST_TotalPrice + ",'" + ST_CIdentityId + "','" + ST_CName + "','"
					+ ST_CPhone + "')";
				//利用Command对象调用
				ST_Conn.Open ();
				SqlCommand ST_mycommand=new SqlCommand (ST_mysql,ST_Conn);
				ST_mycommand.CommandType=CommandType.Text;
				ST_mycommand.ExecuteNonQuery();
				ST_Conn.Close ();
			
				//删除正在使用的房间
				ST_Conn.Open ();
				ST_mysql = "delete from ST_RoomOperation where ST_RoomID='"+ST_RoomID+"'";
				ST_mycommand=new SqlCommand (ST_mysql,ST_Conn);
				ST_mycommand.CommandType=CommandType.Text;
				ST_mycommand.ExecuteNonQuery();
				ST_Conn.Close ();
			
				//设置房间状态
				ST_Conn.Open ();
				ST_mysql = "update ST_RoomStatus set ST_Status=1 where ST_RoomId='"+ST_RoomID+"'";
				ST_mycommand=new SqlCommand (ST_mysql,ST_Conn);
				ST_mycommand.CommandType=CommandType.Text;
				ST_mycommand.ExecuteNonQuery();
			
				ST_Conn.Close ();
			
				e.Item.Cells[5].Text = DateTime.Now.ToLongTimeString();
				e.Item.Cells[6].Text = ST_TotalPrice.ToString();
			}
		}
	}
}

⌨️ 快捷键说明

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