C# winform 汽车租赁系统
本系统采用C# winform以及第三方控件书写,数据库采用sqlserver,已将程序进行exe打包
登录注册页面
代码:
private void btnLogin_Click(object sender, EventArgs e)
{
/*string uneText = this.txtLoginName.Text.Trim();
string pwdText = this.txtLoginPwd.Text.Trim();*/
Computer computer = new Computer();
if (user.Checked)
{
//根据用户名查找员工信息
string sql = "select * from uUser where uUsername = @uUsername";
SqlParameter p = new SqlParameter("@uUsername", txtLoginName.Text);
DataTable dt = new DataTable();
dt = DBHelper.ExecuteQuery(sql, p);
if (dt.Rows.Count > 0)
{
userInfo userInfo = new userInfo();
userInfo.uId = Convert.ToInt32(dt.Rows[0][0]);
userInfo.uUsername = dt.Rows[0][1].ToString();
userInfo.uPassword = dt.Rows[0][2].ToString();
userInfo.uPhone = dt.Rows[0][3].ToString();
userInfo.uAddress = dt.Rows[0][4].ToString();
//用户名存在验证密码
if (txtLoginPwd.Text == dt.Rows[0][2].ToString())
{
//密码正确
this.ShowSuccessTip("登录成功!");
//添加登陆者的信息到数据库
string sqlLog = "insert into logTable (logName,logTime,logIp,logPermission) values (@logName,@logTime,@logIp,@logPermission)";
SqlParameter[] logPs =
{
new SqlParameter("@logName",txtLoginName.Text),
new SqlParameter("@logTime",DateTime.Now),
new SqlParameter("@logIp",computer.IpAddress),
new SqlParameter("@logPermission","普通用户")
};
//DBHelper.ExecuteNonQuery(sqlLog, logPs);
userMain userMain = new userMain();
userMain.Tag = userInfo;
userMain.Show();
this.Hide();
}
else
{
this.ShowErrorDialog("密码错误");
txtLoginName.Text = "";
txtLoginPwd.Text = "";
}
}
else
{
this.ShowErrorDialog("用户名不存在");
txtLoginName.Text = "";
txtLoginPwd.Text = "";
}
}
else if (admin.Checked)
{
//根据用户名查找管理员信息
string sql = "select * from Admin where superName = @superName";
SqlParameter p = new SqlParameter("@superName", txtLoginName.Text);
DataTable dt = new DataTable();
dt = DBHelper.ExecuteQuery(sql, p);
if (dt.Rows.Count > 0)
{
Admin admin = new Admin();
admin.superName = dt.Rows[0][0].ToString();
admin.superPassword = dt.Rows[0][1].ToString();
//用户名存在验证密码
if (txtLoginPwd.Text == admin.superPassword)
{
ControlHelper.ThreadRunExt(this, () =>
{
Thread.Sleep(500);
ControlHelper.ThreadInvokerControl(this, () =>
{
//添加登陆者的信息到数据库
string sqlLog = "insert into logTable (logName,logTime,logIp,logPermission) values (@logName,@logTime,@logIp,@logPermission)";
SqlParameter[] logPs =
{
new SqlParameter("@logName",txtLoginName.Text),
new SqlParameter("@logTime",DateTime.Now),
new SqlParameter("@logIp",computer.IpAddress),
new SqlParameter("@logPermission","超级管理员")
};
DBHelper.ExecuteNonQuery(sqlLog, logPs);
this.ShowSuccessTip("管理员账号登录成功!");
Form1 f1 = new Form1();
f1.Tag = admin;
f1.Show();
this.Hide();
});
}, null, this);
}
else
{
this.ShowErrorDialog("管理员密码错误");
txtLoginName.Text = "";
txtLoginPwd.Text = "";
}
}
else
{
this.ShowErrorDialog("此管理员不存在");
txtLoginName.Text = "";
txtLoginPwd.Text = "";
}
}
else
{
this.ShowErrorDialog("请选择登录类型");
}
}
用户界面:
管理员界面