界面展示:
系统功能的基本要求: 客房各种信息,包括客房的类别、当前的状态、负责人等;客房信息的查询和修改,包括按房间号查询住宿情况、按客户信息查询房间状态等。以及退房、订房、换房等信息的修改。对查询、统计结果打印输出。
数据库信息代码:
create table 房间信息表 (房间号 int primary key, 房间类别 varchar(10) , 房间状态 smallint, 房间负责人 varchar(10), 房间价格 int, ); create table 员工信息表 (员工类别 varchar(10), 用户名 varchar(10) primary key, 密码 varchar(10), ); create table 顾客信息表 (身份证号 char(18) primary key, 姓名 varchar(8)NOT NULL, 性别 char(2)NOT NULL CONSTRAINT P1 CHECK(性别 IN ('男','女')), 年龄 int NOT NULL CONSTRAINT P2 CHECK(年龄>0), 手机号 char(11), 会员等级 varchar(10) , ); create table 订房记录表 (订单编号 int primary key, 房间号 int, 住客身份证号 char(18), 开始时间 char(18), 到期时间 char(18), foreign key (住客身份证号) references 顾客信息表(身份证号), foreign key (房间号) references 房间信息表(房间号) , ); drop table 顾客服务表 create table 顾客服务表 ( 房间号 int, 服务类型 varchar(10), 负责人 varchar(10), foreign key (房间号) references 房间信息表(房间号), ); Create unique index 身份证信息 on 顾客信息表(身份证号); Create unique index 订单信息 on 订房记录表(订单编号); Create unique index 房间信息 on 房间信息表(房间号); create view 空房查询 (房间号, 房间类别, 房间价格 ) as select 房间号,房间类别,房间价格 from 房间信息表 where 房间状态=0 create view 顾客订房信息查询 (顾客姓名, 身份, 预定房间类别, 订单房间状态, 房间价格, 房间号, 订单编号 ) as select 姓名,会员等级,房间类别,房间状态,房间价格,订房记录表.房间号,订单编号 from 订房记录表,房间信息表,顾客信息表 where 订房记录表.房间号=房间信息表.房间号 and 顾客信息表.身份证号=订房记录表.住客身份证号 create view 房间列表 ( 房间号, 房间类别, 房间状态, 房间价格 ) as select 房间号,房间类别,房间状态,房间价格 from 房间信息表 create view 负责人任务列表 ( 负责人, 房间号, 任务 ) as select 负责人,房间号,服务类型 from 顾客服务表 /*(订单编号 int primary key, 房间号 int, 住客身份证号 char(18), 开始时间 char(18), 到期时间 char(18), */ /*drop trigger 订房操作触发器*/ create trigger 服务触发器 on 顾客服务表 for insert as begin declare @room int,@房间负责人 varchar(10) select @room=房间号 from inserted select @房间负责人=房间负责人 from 房间信息表 where 房间号=@room update 顾客服务表 set 负责人=@房间负责人 where 房间号=@room select ('申请成功') end create trigger 订房操作触发器 on 订房记录表 for insert as begin declare @idnum varchar,@room int,@starttime char(18),@endtime char(18) select @idnum=住客身份证号,@room=房间号,@starttime=开始时间,@endtime=到期时间 from inserted update 房间信息表 set 房间状态=1 where 房间号=@room select ('订房成功') end create trigger 退房操作触发器 on 订房记录表 for delete as begin declare @idnum varchar,@room int,@starttime char(18),@endtime char(18) select @idnum=住客身份证号,@room=房间号,@starttime=开始时间,@endtime=到期时间 from deleted update 房间信息表 set 房间状态=0 where 房间号=@room select('退房成功') end insert into 顾客服务表 values(103,'打扫房间',NULL); select * from 顾客服务表 select * from 房间信息表
C#界面程序主窗口源码: (完整程序源码私信)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void Button_Click(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string username; string password; string lei = ""; if (b1.IsChecked == true) { lei += "管理员"; } else if (b2.IsChecked == true) { lei += "员工"; } else { MessageBox.Show("请选择类型"); return; } username = t1.Text; password = t2.Text; string sql = "select * from 员工信息表 where 员工类别=" + "'" + lei + "' and " + "用户名=" + "'" + username + "' and " + "密码=" + "'" + password + "'"; //MessageBox.Show(sql); try { SqlCommand cmd = new SqlCommand(sql,conn); SqlDataReader res = cmd.ExecuteReader();//执行SQL语句,并返回一个结果集 if(res.Read()) { MessageBox.Show("登录成功"); } else { MessageBox.Show("用户名或密码错误"); return; } } catch (Exception) { MessageBox.Show("用户名或密码错误"); return; } //MssageBox.Show(sql); /*NavigationWindow window = new NavigationWindow(); window.Source = new Uri("Page1.xaml", UriKind.Relative); window.Show();*/ Window2 isw = new Window2(); isw.Show(); this.Close(); } private void Button_Click_2(object sender, RoutedEventArgs e) { Window1 isw = new Window1(); isw.Show(); } private void 用户名_TextChanged(object sender, TextChangedEventArgs e) { } private void 用户名_Copy_TextChanged(object sender, TextChangedEventArgs e) { } /*string sql = "select * from 顾客信息表"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView;*/ } }
C#界面程序窗口一源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window1.xaml 的交互逻辑 /// </summary> /// public partial class Window1 : Window { public Window1() { InitializeComponent(); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { } private void Button_Click(object sender, RoutedEventArgs e) { string username; string password; string lei = ""; if (b1.IsChecked == true) { lei += "管理员"; } else if (b2.IsChecked == true) { lei += "员工"; } else { MessageBox.Show("请选择类型"); return; } username = t1.Text; password = t2.Text; if (t2.Text != t3.Text) { MessageBox.Show("两次密码不一致"); return; } // string sqls = "insert into 员工信息表 values('管理员','lihao','123456')"; string sql = "insert into 员工信息表 values('" + lei + "','" + username + "','"+password+"')"; // MessageBox.Show(sqls); SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); SqlCommand sqlman = new SqlCommand(sql, conn); sqlman.ExecuteNonQuery(); MessageBox.Show("注册成功"); this.Close(); } /*string sql = "select * from 顾客信息表"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView;*/ } }
C#界面程序窗口二源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window2.xaml 的交互逻辑 /// </summary> public partial class Window2 : Window { public Window2() { InitializeComponent(); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void Button_Click(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string sql = "select * from 空房查询"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView; } private void b2_Click(object sender, RoutedEventArgs e) { Window4 isw = new Window4(); isw.Show(); } private void Button_Click_1(object sender, RoutedEventArgs e) { Window3 isw = new Window3(); isw.Show(); } private void b4_Click(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string sql = "select * from 顾客订房信息查询"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView; } private void da1_SelectionChanged(object sender, SelectionChangedEventArgs e) { } private void b3_Click(object sender, RoutedEventArgs e) { Window5 isw = new Window5(); isw.Show(); } private void Button_Click_2(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string sql = "select * from 房间列表"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView; } private void Button_Click_3(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string sql = "select * from 顾客信息表"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView; } private void nb2_Click(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string sql = "select * from 负责人任务列表"; SqlDataAdapter myda = new SqlDataAdapter(sql, conn); DataTable dt = new DataTable(); myda.Fill(dt); da1.ItemsSource = dt.DefaultView; } private void nb1_Click(object sender, RoutedEventArgs e) { Window6 isw = new Window6(); isw.Show(); } private void Button_Click_4(object sender, RoutedEventArgs e) { Window7 isw = new Window7(); isw.Show(); } } }
C#界面程序窗口三源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window3.xaml 的交互逻辑 /// </summary> public partial class Window3 : Window { public Window3() { InitializeComponent(); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void Button_Click(object sender, RoutedEventArgs e) { string id; string name; string sex; string age; string phone; id = t1.Text; name = t2.Text; sex = t3.Text; age = t4.Text; phone = t5.Text; // string sqls = "insert into 员工信息表 values('管理员','lihao','123456')"; string sql = "insert into 顾客信息表 values('" + id + "','" + name + "','" + sex + "'," + age + ",'"+phone+"',"+"100"+")"; //MessageBox.Show(sql); SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); SqlCommand sqlman = new SqlCommand(sql, conn); sqlman.ExecuteNonQuery(); MessageBox.Show("注册成功"); this.Close(); } } }
C#界面程序窗口四源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window3.xaml 的交互逻辑 /// </summary> public partial class Window4 : Window { public Window4() { InitializeComponent(); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void Button_Click(object sender, RoutedEventArgs e) { SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); string id; string starttime; string endtime; int biaohao; int room; id = t1.Text; starttime= t2.Text; endtime= t3.Text; string sql = "select * from 顾客信息表 where 身份证号=" + "'" + id + "'"; // MessageBox.Show(sql); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader res = cmd.ExecuteReader();//执行SQL语句,并返回一个结果集 if (res.Read()) { Random rd = new Random(); biaohao = rd.Next(); string sqlss1 = "select * from 房间信息表 where 房间状态=0 and 房间类别='总统套房'"; string sqlss2 = "select * from 房间信息表 where 房间状态=0 and 房间类别='垃圾房'"; // MessageBox.Show(sqlss1); // MessageBox.Show(sqlss2); if (b1.IsChecked == true) { SqlCommand cmdd = new SqlCommand(sqlss1, conn); //MessageBox.Show("0"); res.Close(); res = cmdd.ExecuteReader();//执行SQL语句,并返回一个结果集 // MessageBox.Show("2"); if (res.Read()) { // MessageBox.Show("1"); room = (int)(res["房间号"]); string sqls = "insert into 订房记录表 values('" + biaohao + "'," + room + ",'" + id + "','" + starttime + "','" + endtime + "'" + ")"; SqlCommand sqlman = new SqlCommand(sqls, conn); res.Close(); sqlman.ExecuteNonQuery(); //MessageBox.Show(sqls); MessageBox.Show("预定成功"); return; } else { MessageBox.Show("无闲置的此类房间"); } } else if(b2.IsChecked == true) { SqlCommand cmdd = new SqlCommand(sqlss2, conn); //MessageBox.Show("0"); res.Close(); res = cmdd.ExecuteReader();//执行SQL语句,并返回一个结果集 // MessageBox.Show("2"); if (res.Read()) { // MessageBox.Show("1"); room = (int)(res["房间号"]); string sqls = "insert into 订房记录表 values('" + biaohao + "'," + room + ",'" + id + "','" + starttime + "','" + endtime + "'" + ")"; //MessageBox.Show(sqls); SqlCommand sqlman = new SqlCommand(sqls, conn); res.Close(); sqlman.ExecuteNonQuery(); MessageBox.Show("预定成功"); return; } else { MessageBox.Show("无闲置的此类房间"); } } else { MessageBox.Show("请选择房间类型"); } } else { MessageBox.Show("未查询到顾客信息,请先登记信息"); return; } this.Close(); } private void b2_Checked(object sender, RoutedEventArgs e) {
} private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { } private void t2_TextChanged(object sender, TextChangedEventArgs e) { } private void t3_TextChanged(object sender, TextChangedEventArgs e) { } private void b1_Checked(object sender, RoutedEventArgs e) { } } }
C#界面程序窗口五源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window5.xaml 的交互逻辑 /// </summary> public partial class Window5 : Window { public Window5() { InitializeComponent(); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void b1_Click(object sender, RoutedEventArgs e) { string s; SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); s =t1.Text; string sqlss1 = "select * from 房间信息表 where 房间状态=1 and 房间号="+s; SqlCommand cmd = new SqlCommand(sqlss1, conn); SqlDataReader res = cmd.ExecuteReader(); if (res.Read()) { res.Close(); string sql = "delete from 订房记录表 where 房间号=" + s; cmd = new SqlCommand(sql, conn); cmd.ExecuteReader(); MessageBox.Show("退房成功"); } else { MessageBox.Show("无此房间号或当前房间不需要退订"); } this.Close(); } } }
C#界面程序窗口六源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window6.xaml 的交互逻辑 /// </summary> public partial class Window6 : Window { public Window6() { InitializeComponent(); string sqlss1 = "select * from 房间信息表 "; SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); SqlCommand cmd = new SqlCommand(sqlss1, conn); SqlDataReader res = cmd.ExecuteReader(); while (res.Read()) { string s; if (res["房间号"]==null) break; s = res["房间号"].ToString(); t2.Items.Add(s); } comboBox1.Items.Add("打扫房间"); comboBox1.Items.Add("送洗漱用品"); comboBox1.Items.Add("送餐"); comboBox1.Items.Add("紧急呼救"); comboBox1.Items.Add("上门按摩"); } string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; private void Button_Click(object sender, RoutedEventArgs e) { string s; SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); s = comboBox1.Text; string num = t2.Text; string sql = "insert into 顾客服务表 values("+num + ",'" + s + "','"+"NULL"+"')"; //MessageBox.Show(sql); SqlCommand sqlman = new SqlCommand(sql, conn); sqlman.ExecuteNonQuery(); MessageBox.Show("添加成功"); this.Close(); } private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { } } }
C#界面程序窗口七源码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using System.Data.SqlClient; namespace WpfApp2 { /// <summary> /// Window7.xaml 的交互逻辑 /// </summary> public partial class Window7 : Window { string SqlConnectionStatement = "server=localhost;database=QT+SQL酒店master;Trusted_Connection=SSPI"; public Window7() { InitializeComponent(); string sqlss1 = "select * from 顾客服务表 "; SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); SqlCommand cmd = new SqlCommand(sqlss1, conn); SqlDataReader res = cmd.ExecuteReader(); while (res.Read()){ string s; s = (res["房间号"]).ToString() + ","+(string)(res["服务类型"]) + ","+(string)(res["负责人"]); comboBox1.Items.Add(s); } } private void Button_Click_1(object sender, RoutedEventArgs e) { string s; SqlConnection conn = new SqlConnection(SqlConnectionStatement); conn.Open(); s = comboBox1.Text; string s1=""; string s2=""; int fl = 1; for(int i = 0; i < s.Length; i++) { if (fl == 1) { if (s[i] == ',') { fl++; } else { s1 += s[i]; } } else { if (s[i] == ',') { break; } else { s2 += s[i]; } } } string sql = "delete from 顾客服务表 where 房间号=" + s1 + "and 服务类型='"+s2+"'"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteReader(); MessageBox.Show("操作完成"); this.Close(); } private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { } } }