C#实现餐厅管理系统
作者:malloc_w 时间:2023-11-27 16:05:05
本文实例为大家分享了C#实现餐厅管理系统的具体代码,供大家参考,具体内容如下
部分代码:
fm_change_password.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace FoodManage
{
public partial class fm_change_password : Form
{
public fm_change_password()
{
InitializeComponent();
}
public string useridname = "";
private void bt_ok_Click(object sender, EventArgs e)
{
SqlConnection conn=new SqlConnection(fm_public.strcon);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("SELECT Password FROM TUser WHERE UserIDName='" + useridname + "'", conn);
DataTable DT=new DataTable();
sda.Fill(DT);
if(DT.Rows[0]["Password"].ToString()!=tb_oldpass.Text)
{
MessageBox.Show("旧密码错误请重新输入");
return;
}
if (tb_newpassw.Text != tb_newpass.Text)
{
MessageBox.Show("两次密码不相同请重新输入");
return;
}
SqlCommand cmd = new SqlCommand("UPDATE TUser SET Password=@Password WHERE UserIDName='" + useridname + "'", conn);
cmd.Parameters.Add("@Password",SqlDbType.VarChar,128).Value=tb_newpassw.Text;
cmd.ExecuteNonQuery();
MessageBox.Show("修改密码成功!(* ̄︶ ̄)y ");
conn.Close();
this.Close();
}
private void bt_esc_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
fm_login.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FoodManage
{
public partial class fm_login : Form
{
public fm_login()
{
InitializeComponent();
}
private void bt_login_Click(object sender, EventArgs e)
{
//判断用户名或密码文本框是否为空
if(tb_username.Text==""||tb_password.Text=="")
{
if(tb_username.Text=="")
{
MessageBox.Show("用户名为空,请重新输入!(* ̄︶ ̄)y ");
return;
}
if (tb_password.Text == "")
{
MessageBox.Show("密码为空,请重新输入!(* ̄︶ ̄)y ");
return;
}
}
//连接数据库
SqlConnection conn = new SqlConnection(fm_public.strcon);
conn.Open();
string selectsql = "SELECT * FROM TUser WHERE UserIDName='" + tb_username.Text + "'";
SqlDataAdapter sda = new SqlDataAdapter(selectsql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
//判断用户是否存在
if (dt.Rows.Count == 0)
{
MessageBox.Show("无该用户");
return;
}
//判断用户名是否被锁定
if (Convert.ToBoolean(dt.Rows[0]["LockIf"]) == true)
{
MessageBox.Show("该用户已经被锁定,请联系管理员!/(ㄒoㄒ)/~~ ");
return;
}
//更新数据库前的准备
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
//判断输入密码是否正确,输入错误则“错误次数”+1,成功登录则“错误次数”清零
if(tb_password.Text!=dt.Rows[0]["Password"].ToString())
{
//错误次数+1
cmd.CommandText = @"UPDATE TUser SET ErrorTime=ErrorTime+1 WHERE UserIDName=@UserName";
cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 8);
cmd.Parameters["@UserName"].Value = tb_username.Text.Trim();
cmd.ExecuteNonQuery();
MessageBox.Show("密码错误请重新输入!/(ㄒoㄒ)/~~ ");
return;
}
//经过以上验证用户名密码无错执行以下代码(设置错误次数为0)
cmd.CommandText = "update TUser set ErrorTime=0 where UserIDName=@UserName";
cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 8);
cmd.Parameters["@UserName"].Value = tb_username.Text.Trim();
cmd.ExecuteNonQuery();
conn.Close();
fm_public.LoginSuccess = true;
//设置用户权限以及初始化主界面的相关参数
if (dt.Rows[0]["Post"].ToString() == "管理员")
{
fm_public.userpower = "管理员";
}
else
{
fm_public.userpower = "服务员";
}
fm_public.useridname = dt.Rows[0]["UserIDName"].ToString();
fm_public.logintime = DateTime.Now.ToShortDateString();
this.Close();
}
private void bt_esc_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定退出系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
{
Application.Exit();
}
}
private void fm_login_Activated(object sender, EventArgs e)
{
tb_username.Focus();
}
private void fm_login_Load(object sender, EventArgs e)
{
fm_start fm_starts = new fm_start();
fm_starts.ShowDialog();
}
}
}
源码下载:C#实现餐厅管理系统
标签:C#,管理系统
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java创建ZIP压缩文件的方法
2022-10-05 05:05:23
springboot集成redis并使用redis生成全局唯一索引ID
2023-11-28 05:42:39
![](https://img.aspxhome.com/file/2023/0/59020_0s.jpg)
Unity3D使用Shader实现腐蚀消失
2022-01-07 20:57:59
![](https://img.aspxhome.com/file/2023/1/89751_0s.gif)
Android程序开发中单选按钮(RadioGroup)的使用详解
2023-09-18 03:43:39
![](https://img.aspxhome.com/file/2023/5/137955_0s.png)
c# 预处理识别硬币的数据集
2022-05-21 17:26:09
kotlin使用Dagger2的过程全纪录
2021-08-18 05:45:54
jpa多数据源时Hibernate配置自动生成表不生效的解决
2023-04-24 06:19:55
![](https://img.aspxhome.com/file/2023/8/79168_0s.jpg)
SpringBoot使用WebSocket的方法实例详解
2022-12-26 03:19:25
常用类之TCP连接类-socket编程
2021-08-03 16:46:25
slf4j与jul、log4j1、log4j2、logback的集成原理
2023-01-31 18:01:47
![](https://img.aspxhome.com/file/2023/2/68552_0s.png)
Java中使用StackWalker和Stream API进行堆栈遍历
2023-04-12 11:29:07
Android自定义View实现选座功能
2022-12-23 00:05:45
![](https://img.aspxhome.com/file/2023/4/139574_0s.png)
Android中的Intent Filter匹配规则简介
2021-07-29 16:02:30
Android拍照或从图库选择图片并裁剪
2023-07-01 08:21:45
Android自定义RadioGroupX实现多行多列布局
2023-03-27 17:19:47
![](https://img.aspxhome.com/file/2023/9/128989_0s.jpg)
springmvc后台基于@ModelAttribute获取表单提交的数据
2023-08-05 12:29:35
![](https://img.aspxhome.com/file/2023/7/71657_0s.jpg)
thymeleaf中前后端数据交互方法汇总
2023-07-18 21:15:59
解决RedisTemplate调用increment报错问题
2023-11-20 06:35:05
Android 监听屏幕是否锁屏的实例代码
2022-01-19 14:31:24
Java cookie和session会话技术介绍
2021-12-30 06:51:22