首页 > 编程 > C# > 正文

C#实现餐厅管理系统

2020-01-24 00:10:37
字体:
来源:转载
供稿:网友

本文实例为大家分享了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#实现餐厅管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表