C#实现餐厅管理系统
程序员文章站
2023-12-12 09:34:58
本文实例为大家分享了c#实现餐厅管理系统的具体代码,供大家参考,具体内容如下
部分代码:
fm_change_password.cs
using system...
本文实例为大家分享了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#实现餐厅管理系统
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。