课程设计报告
(本科)
课程:数据库原理
学号:1310411061 1310411015
姓名:张自豪袁满
班级:2013级计算机科学与技术教师:孙雯
时间:2015.4-2015.7
计算机学院
附录(代码):
//软件载入
using System;
using System.Collections.Generic; using https://www.wendangku.net/doc/538318357.html,ponentModel; using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HotelManagement
{
public partial class Entering : Form
{
public Entering()
{
InitializeComponent();
}
int i=1;
private void timer1_Tick(object sender, EventArgs e) {
progressBar1.PerformStep();
if (progressBar1.Value == 100)
{
if (i == 20)
{
timer1.Stop();
this.Hide();
new index().Show(); }
i++;
}
}
}
}
//登陆界面代码
using System;
using System.Collections.Generic;
using https://www.wendangku.net/doc/538318357.html,ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace HotelManagement
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
public static int choice = 0; //用于标记是否登陆成功,并在index中将值传给index.choice,用于判断用户是否登陆
private void inlog(string infos) //写入日志infos信息
{
string paths = Directory.GetCurrentDirectory() + "\\log.txt"; //当前工作目录下创建文件
StreamWriter swtxt = new StreamWriter(paths, true, Encoding.Default);
swtxt.WriteLine(infos); //写文本流
swtxt.Close();
}
string username, password;
private void dl_Click(object sender, EventArgs e)
{
string sql;
DataSet ds; //数据在内存中的缓存
if (user.Text.Trim() != "" && userpwd.Text.Trim()!= "" && select.SelectedIndex != -1) //信息完整判断
{
username = user.Text.Trim(); //获取用户名
password = userpwd.Text.Trim();
sql = " select * from userInfo where username='" + username + "' and pwd='" + password + "'"; //默认为旅客登陆
if (select.SelectedItem.ToString() == "管理员")
{
sql = " select * from Manager where adminname='" + username + "' and pwd='" + password + "'";
}
connect data = new connect(); //connect实例
data.Database_con(); //打开数据库
ds = data.getDataset(sql); //获取执行结果
DataTable dt = ds.Tables[0]; //单表
DataRow dr; //单行
if (dt.Rows.Count == 1) //结果只有一行代表信
息正确
{
dr = dt.Rows[0]; //将查询结果的第一行赋值给 dr dr[i]表示该行的第i+1个单元格
if (select.SelectedItem.ToString() == "旅客") //
以旅客权限登陆
{
this.Hide();
choice = 1; //标记登录状态为登陆
Guest guest = new Guest();
https://www.wendangku.net/doc/538318357.html,er = username; //用于在admin或guest 的状态栏显示登陆者的账号
https://www.wendangku.net/doc/538318357.html,ertype = "旅客";
guest.Show();
string myss = System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString() + " " + username + " 登陆";
inlog(myss); //写入信息到文本
}
else if (select.SelectedItem.ToString() == "管理员") //以管理员权限登录
{
this.Hide();
choice = 1; //标记登录状态为登陆
admin manager = new admin();
https://www.wendangku.net/doc/538318357.html,er = username;
https://www.wendangku.net/doc/538318357.html,ertype= "管理员";
manager.Show();
string myss = System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString() + " " + username + " 登陆";
inlog(myss);
}
else
{
MessageBox.Show("用户权限选择错误!", "提示", MessageBoxButtons.OK);
}
}
else
{
MessageBox.Show("用户名或者密码错误!请重试!", "警告", MessageBoxButtons.OK);
https://www.wendangku.net/doc/538318357.html,er.Text = "";
https://www.wendangku.net/doc/538318357.html,erpwd.Text = "";
}
}
else
{
MessageBox.Show("请确认输入完整信息", "提示");
}
}
private void cancel_Click(object sender, EventArgs e)
{
this.Close();
index ind = new index();
ind.Show();
}
private void login_Load(object sender, EventArgs e) {
user.Focus();
userpwd.PasswordChar='*';
}
private void label1_Click(object sender, EventArgs e) {
this.Hide();
logon log = new logon();
log.Show();
}
}
}