C#实验报告Word格式.docx
《C#实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《C#实验报告Word格式.docx(19页珍藏版)》请在冰豆网上搜索。
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
namespaceripi
{
staticclassProgram
{
///<
summary>
///应用程序的主入口点。
/summary>
[STAThread]
staticvoidMain()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(newHotel());
}}}
Hotel.cs
publicpartialclassHotel:
Form
{
Parkpark=newPark();
The_hotel_deskdesk=newThe_hotel_desk();
publicHotel()
InitializeComponent();
}
privatevoidbutton2_Click(objectsender,EventArgse)
if(park.Visible==false)
park.Show();
this.Hide();
}}
privatevoidbutton1_Click(objectsender,EventArgse)
{
//弹出酒店前台窗口
if(desk.Visible==false)
desk.Show();
}}}
(2)停车场
(3)酒店前台
Thehoteldesk.cs
publicpartialclassThe_hotel_desk:
Guestguest=newGuest();
Passwordpassword=newPassword();
publicThe_hotel_desk()
if(password.Visible==false)
password.Show();
privatevoidtimer1_Tick(objectsender,EventArgse)
//标签显示时间(年月日)
label1.Text=DateTime.Now.ToString("
yyyy-MM-dd:
HH:
mm:
ss"
);
if(guest.Visible==false)
guest.Show();
privatevoidbutton3_Click(objectsender,EventArgse)
Hotelhotel=newHotel();
hotel.Show();
privatevoidbutton4_Click(objectsender,EventArgse)
//退出整个程序环境
System.Environment.Exit(0);
(4)客户登录
Guest.cs
publicpartialclassGuest:
publicGuest()
//各项输入不能为空
try
if(textBox1.Text=="
"
||textBox2.Text=="
)
MessageBox.Show("
用户名或密码不能为空!
return;
elseif(textBox3.Text=="
请输入确认密码!
else
//连接数据库
SqlConnectionmyConnection=newSqlConnection(Properties.Settings.Default.Hoteldatabase1ConnectionString);
myConnection.Open();
stringsql="
Select*From客户注册where客户ID='
+textBox1.Text+"
'
and密码='
+textBox2.Text+"
"
;
SqlCommandcmd=newSqlCommand(sql,myConnection);
SqlDataReadersdr=cmd.ExecuteReader();
sdr.Read();
if(sdr.HasRows)
//调用HasRows判断是否正确
myConnection.Close();
this.Hide();
Hotel_informationregister=newHotel_information();
register.Show();
textBox1.Text="
textBox2.Text="
textBox3.Text="
用户名或密码错误!
catch(Exceptionex)
MessageBox.Show(ex.Message);
Registerregister=newRegister();
register.Show();
Close();
}
(5)客户注册
Register.cs
publicRegister()
privatevoidbutton2_Click_1(objectsender,EventArgse)
privateboola;
privatevoidtextBox1_TextChanged(objectsender,EventArgse)
myConnection.Open();
stringcmd="
select*from客户注册"
SqlCommandcom=newSqlCommand(cmd,myConnection);
com.CommandText=cmd;
com.Connection=myConnection;
com.ExecuteNonQuery();
SqlDataReaderread=com.ExecuteReader();
while(read.Read())
//判断是否存在
if(textBox1.Text==read["
客户ID"
].ToString().Trim())
用户名已存在请重新输入!
);
a=true;
//判断客户ID是否重复
elseif(textBox1.Text!
=read["
恭喜你,用户名可以使用!
a=false;
//将用户写入数据库
if(a==false)
insertinto客户注册(客户ID,姓名,密码)values('
'
'
+textBox3.Text+"
)"
myConnection.Close();
注册成功,点击确定返回登陆界面!
//返回到登陆界面
}}}
(6)房间列表
Roomlist.cs
publicpartialclassHotel_information:
publicHotel_information()
}
Form1single=newForm1();
single.ShowDialog();
Form2two=newForm2();
two.ShowDialog();
Form3triple=newForm3();
triple.ShowDialog();
Form4quadruple=newForm4();
quadruple.ShowDialog();
privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)
privatevoidtoolStripMenuItem2_Click(objectsender,EventArgse)
privatevoid单人间ToolStripMenuItem2_Click(objectsender,EventArgse)
Select房间号From客房信息where房间状态=@okand客房类型=@yes"
SqlCommandcmd=newSqlCommand(sql,myConnection);
cmd.Parameters.Add("
@ok"
SqlDbType.NVarChar).Value="
可用"
@yes"
单人间"
BindingSourcebind=newBindingSource();
SqlDataReaderread=cmd.ExecuteReader();
bind.DataSource=read;
dataGridView1.DataSource=bind;
privatevoid双人间ToolStripMenuItem1_Click(objectsender,EventArgse)
stringsql="
双人间"
privatevoid豪华套间ToolStripMenuItem1_Click(objectsender,EventArgse)
cmd.Parameters.Add("
豪华套间"
privatevoid总统套间ToolStripMenuItem1_Click(objectsender,EventArgse)
stringsql="
Select房间号From客房信息where房间状态=@okand客房类型=@yes"
cmd.Parameters.Add("
总统套间"
privatevoid主题房间ToolStripMenuItem1_Click(objectsender,EventArgse)
Select房间号From客房信息where房间状态=@okand客房类型=@yes"
SqlCommandcmd=newSqlCommand(sql,myConnection);
主题房间"
privatevoid订购电话ToolStripMenuItem_MouseDown(objectsender,MouseEventArgse)
{MessageBox.Show("
***---*****"
(7)酒店管理员验证
Password.cs
publicpartialclassPassword:
publicPassword()
User_managementa=newUser_management();
privatevoidtextBox1_MouseEnter(objectsender,EventArgse)
label2.Text="
密码提示:
我的学号!
!
//管理员密码判断
stringb=textBox1.Text;
if(b=="
2123323"
欢迎登陆!
"
登陆成功"
a.Show();
else
登陆失败"
(8)用户管理
Usermanagement.cs
publicpartialclassUser_management:
publicUser_management()
&
&
textBox2.Text=="
textBox3.Text