C#实现在线点餐系统
程序员文章站
2023-11-09 18:57:46
这个是c#大作业,写作业很用心,写了很久,所以留存一下。不是现在的是之前的的期末作业,现在才想着整理一下
实现功能:
1、商家登录;客户的登录、注册。
2、商家界面实现了对菜单的...
这个是c#大作业,写作业很用心,写了很久,所以留存一下。不是现在的是之前的的期末作业,现在才想着整理一下
实现功能:
1、商家登录;客户的登录、注册。
2、商家界面实现了对菜单的增、删、改、查;还有订单的查看、查询、结账(删除订单)、查看已结账订单、关闭;退出系统。
3、用户界面实现了菜单的查看,查询,新建订单,选择餐桌,保存订单,增加菜品,退出。
c#语言实现在线点餐系统,具体功能如下图
登录界面
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.data.sqlclient; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace menusystemwss { public partial class form1 : form { int dlsf=0; /* sqlconnection sqlcon; sqlcommand sqlcom; sqldatareader sqlsdr;*/ baseinfo baseinfo = new baseinfo();// baseinfo.gkinfo gkinfo = new baseinfo.gkinfo();// public form1() { initializecomponent(); } public void dengluzt() { dataset ds = null; gkinfo.gk_num = textbox1.text.trim(); ds = baseinfo.denglu(gkinfo, "db_menu"); gkinfo.gk_zt = 1; gkinfo.gk_apw = gkinfo.gk_pw; gkinfo.gk_name = ds.tables[0].rows[0][1].tostring().trim(); baseinfo.updatgk(this.gkinfo); } private void button1_click(object sender, eventargs e) { if (radiobutton1.checked) dlsf = 1; if (radiobutton2.checked) dlsf = 2; if (textbox1.text.trim() == "") { label3.text = "账号不能为空"; textbox1.focus(); return; } else if (textbox2.text.trim() == "") { label3.text = "密码不能为空"; textbox1.focus(); return; } else if (dlsf == 2) { try { dataset ds = null; gkinfo.gk_num = textbox1.text.trim(); gkinfo.gk_pw = textbox2.text.trim(); ds = baseinfo.denglu(gkinfo, "db_menu"); if (ds== null||ds.tables.count == 0||(ds.tables.count == 1 && ds.tables[0].rows.count == 0)) { messagebox.show("用户名错误!"); return; } else if (ds.tables[0].rows[0][2].tostring().trim() != textbox2.text.trim()) { messagebox.show("密码错误"); } else { messagebox.show("登陆成功!"); dengluzt(); gkfm fm = new gkfm(); fm.add (convert.tostring(textbox1.text)); fm.show(); //this.hide(); } } catch (exception ee) { messagebox.show(ee.message); } } else if (dlsf == 1) { if (textbox1.text.trim() == "1" && textbox2.text.trim() == "1") { messagebox.show("登录成功"); sjfm fm = new sjfm(); fm.show(); // this.hide(); } else { messagebox.show("账号或密码错误!请重新输入!"); return; } } } private void label3_click(object sender, eventargs e) { zcfm fm = new zcfm(); fm.show(); this.hide(); } } }
注册界面
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.data.sqlclient; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace menusystemwss { public partial class zcfm : form { baseinfo baseinfo = new baseinfo();// baseinfo.gkinfo gkinfo = new baseinfo.gkinfo();// /* sqlconnection sqlcon; sqlcommand sqlcom;*/ public zcfm() { initializecomponent(); } private void label6_click(object sender, eventargs e) { form1 fm = new form1(); fm.show(); this.hide(); } private void button1_click(object sender, eventargs e) { if (textbox1.text.trim() == "" || textbox1.text.length != 11) { messagebox.show( "手机号错误,请规范填写"); } else if (textbox2.text.trim() == "") { messagebox.show("用户名错误,请规范填写4-8位"); } else if (textbox3.text.trim() == "" || textbox3.text.length < 6 || textbox3.text.length > 8) { messagebox.show("密码错误,请规范填写6-8位!"); } else if (textbox4.text.trim() == "") { messagebox.show("密码错误,请规范填写6-8位!"); } else if (textbox3.text.trim() != textbox4.text.trim()) { messagebox.show("两次输入密码必须一致!"); } else { try { gkinfo.gk_num = textbox1.text.trim(); gkinfo.gk_name = textbox2.text.trim(); gkinfo.gk_pw = textbox3.text.trim(); gkinfo.gk_apw = textbox4.text.trim(); gkinfo.gk_zt = 0; int id = baseinfo.addgk(gkinfo); messagebox.show("注册成功!", "成功提示!", messageboxbuttons.ok, messageboxicon.information); } catch (exception ee){ messagebox.show(ee.message); } } } private void zcfm_load(object sender, eventargs e) { } } }
商家界面:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace menusystemwss { public partial class sjfm : form { public sjfm() { initializecomponent(); } private void button1_click(object sender, eventargs e) { menushop fm = new menushop(); fm.show(); } private void button3_click(object sender, eventargs e) { application.exit(); } private void button2_click(object sender, eventargs e) { glfm fm = new glfm(); fm.show(); } } }
菜单管理
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace menusystemwss { public partial class menushop : form { baseinfo baseinfo = new baseinfo(); baseinfo.menuinfo stockinfo = new baseinfo.menuinfo(); int kj_bz = 0;//控件状态标志 public menushop() { initializecomponent(); } private void cleartext() { textboxnum.text = string.empty; textboxname.text = string.empty; textboxgg.text = string.empty; textboxlx.text = string.empty; textboxdj.text = string.empty; } private void cancelenabled() { groupbox1.enabled = false; tlbtnadd.enabled = true; btnedit.enabled = true; btndelete.enabled = true; btnsave.enabled = false; btncancel.enabled = false; } private void loadenabled() { groupbox1.enabled = false; tlbtnadd.enabled = true; btnedit.enabled = true; btndelete.enabled = true; btnsave.enabled = false; btncancel.enabled = false; } private void editenabled() { groupbox1.enabled = true; tlbtnadd.enabled = false; btnedit.enabled = false; btndelete.enabled =false; btnsave.enabled = true; btncancel.enabled = true; } private void addenabled() { textboxdj.text = ""; textboxgg.text = ""; textboxnum.text = ""; textboxname.text = ""; textboxlx.text = ""; groupbox1.enabled = true; tlbtnadd.enabled = false; btnedit.enabled = false; btndelete.enabled = false; btnsave.enabled = true; btncancel.enabled = true; } private void menushop_load(object sender, eventargs e) { this.loadenabled(); datagridview1.datasource = baseinfo.getallmenu("db_menu").tables[0].defaultview;//展示菜品信息 this.setdatagridview1headtext(); } private void setdatagridview1headtext() { datagridview1.columns[0].headertext = "菜品编号"; datagridview1.columns[1].headertext = "菜品名称"; datagridview1.columns[2].headertext = "菜品规格"; datagridview1.columns[3].headertext = "菜品类型"; datagridview1.columns[4].headertext = "菜品价格"; } private void datagridview1_cellclick(object sender, datagridviewcelleventargs e) { textboxnum.text = this.datagridview1[0, datagridview1.currentcell.rowindex].value.tostring();//显示菜品编号 textboxname.text = this.datagridview1[1, datagridview1.currentcell.rowindex].value.tostring();//显示菜品全称 textboxgg.text = this.datagridview1[2, datagridview1.currentcell.rowindex].value.tostring();//显示菜品规格 textboxlx.text = this.datagridview1[3, datagridview1.currentcell.rowindex].value.tostring();//显示菜品类型 textboxdj.text = this.datagridview1[4, datagridview1.currentcell.rowindex].value.tostring();//显示菜品单价 } public void labletime() { labelsj.text = system.datetime.now.tostring(); } private void timer1_tick(object sender, eventargs e) { labletime(); } private void tlbtnexit_click(object sender, eventargs e) { this.close(); //application.exit(); } private void btndelete_click(object sender, eventargs e) { if (textboxnum.text.trim() == string.empty) { messagebox.show("删除--菜品数据--失败!", "错误提示!", messageboxbuttons.ok, messageboxicon.error); return; } stockinfo.menu_num = textboxnum.text.trim(); int id = baseinfo.deletemenu(stockinfo); messagebox.show("删除--库存商品数据--成功!", "成功提示!", messageboxbuttons.ok, messageboxicon.information); datagridview1.datasource = baseinfo.getallmenu("db_menu").tables[0].defaultview; this.setdatagridview1headtext(); this.cleartext();//清空文本框 } private void btnsave_click(object sender, eventargs e) { if (kj_bz == 0) { try { //添加数据 stockinfo.menu_num =textboxnum.text; stockinfo.menu_name = textboxname.text; stockinfo.menu_gg = textboxgg.text; stockinfo.menu_lx= textboxlx.text; stockinfo.menu_dj = float.parse( textboxdj.text.trim()); //执行添加操作 int id = baseinfo.addmenu(stockinfo); messagebox.show("新增--库存商品数据--成功!", "成功提示!", messageboxbuttons.ok, messageboxicon.information); } catch (exception ex) { messagebox.show(ex.message, "错误提示", messageboxbuttons.ok, messageboxicon.error); } } else { //修改数据 stockinfo.menu_num = textboxnum.text; stockinfo.menu_name = textboxname.text; stockinfo.menu_gg = textboxgg.text; stockinfo.menu_lx = textboxlx.text; stockinfo.menu_dj = float.parse(textboxdj.text.trim()); //执行修改操作 int id = baseinfo.updatemenu(stockinfo); messagebox.show("修改--库存商品数据--成功!", "成功提示!", messageboxbuttons.ok, messageboxicon.information); } datagridview1.datasource = baseinfo.getallmenu("db_menu").tables[0].defaultview; this.setdatagridview1headtext(); this.cancelenabled();//设置各个按钮的可用状态 } private void btnfind_click(object sender, eventargs e) { if (tlcmbstocktype.text == string.empty) { messagebox.show("查询类别不能为空!", "错误提示!", messageboxbuttons.ok, messageboxicon.error); tlcmbstocktype.focus(); return; } else if (tlcmbstocktype.text.trim() == "全部") { datagridview1.datasource = baseinfo.getallmenu("db_menu").tables[0].defaultview; this.setdatagridview1headtext(); return; } else { dataset ds = null; stockinfo.menu_lx = tlcmbstocktype.text; ds = baseinfo.findmenubylx(stockinfo, "db_menu"); datagridview1.datasource = ds.tables[0].defaultview; this.setdatagridview1headtext(); } } private void btncancel_click(object sender, eventargs e) { this.cancelenabled(); } private void btnedit_click(object sender, eventargs e) { kj_bz = 1; this.editenabled(); } private void tlbtnadd_click(object sender, eventargs e) { this.addenabled(); kj_bz = 0; } } }
订单管理
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace menusystemwss { public partial class glfm : form { baseinfo baseinfo = new baseinfo(); baseinfo.ddinfo dd = new baseinfo.ddinfo(); public glfm() { initializecomponent(); } private void glfm_load(object sender, eventargs e) { textboxddxq.enabled = false; datagridview1.datasource = baseinfo.getalldd("db_dd").tables[0].defaultview;//展示订单信息 this.setdatagridview1headtext(); } private void setdatagridview1headtext() { datagridview1.columns[0].headertext = "桌号"; datagridview1.columns[1].headertext = "顾客手机号"; datagridview1.columns[2].headertext = "订单详情"; datagridview1.columns[3].headertext = "订单总价"; datagridview1.columns[4].headertext = "订单时间"; } private void toolstripbutton1_click(object sender, eventargs e) { if (comboboxzh.text == string.empty) { messagebox.show("查询类别不能为空!", "错误提示!", messageboxbuttons.ok, messageboxicon.error); comboboxzh.focus(); return; } else if (comboboxzh.text.trim() == "全部") { datagridview1.datasource = baseinfo.getalldd("db_dd").tables[0].defaultview; return; } if (comboboxzh.text.trim() == "已结账订单") { datagridview1.datasource = baseinfo.getallsydd("db_sydd").tables[0].defaultview; //labelxfzj.text = baseinfo.getallddsy("dd_sydd").tostring(); return; } else { dataset ds = null; dd.dd_num = int.parse(comboboxzh.text); ds = baseinfo.findddbyzh(dd, "db_dd"); datagridview1.datasource = ds.tables[0].defaultview; this.setdatagridview1headtext(); if (ds == null || ds.tables.count == 0 || (ds.tables.count == 1 && ds.tables[0].rows.count == 0)) { textboxddxq.text = ""; } else { textboxddxq.text = ds.tables[0].rows[0][2].tostring().trim(); } } } public void yjdd() { datagridview1.datasource = baseinfo.getalldd("db_sydd").tables[0].defaultview; setdatagridview1headtext(); } private void datagridview1_cellclick(object sender, datagridviewcelleventargs e) { comboboxzh.text = this.datagridview1[0, datagridview1.currentcell.rowindex].value.tostring(); textboxddxq.text = this.datagridview1[2, datagridview1.currentcell.rowindex].value.tostring(); labelxfzj.text = "本次消费总价为:" + this.datagridview1[3, datagridview1.currentcell.rowindex].value.tostring(); } private void exitbtn_click(object sender, eventargs e) { this.close(); } private void toolstripbutton2_click(object sender, eventargs e) { if (comboboxzh.text.trim() != "") { dd.dd_num = int.parse(comboboxzh.text.trim()); dd.zd_num = this.datagridview1[1, datagridview1.currentcell.rowindex].value.tostring(); dd.dd_name = this.datagridview1[2, datagridview1.currentcell.rowindex].value.tostring(); dd.dd_zj= float.parse(this.datagridview1[3, datagridview1.currentcell.rowindex].value.tostring()); dd.dd_time = this.datagridview1[4, datagridview1.currentcell.rowindex].value.tostring(); baseinfo.bcdd(dd); baseinfo.deletedd(dd); messagebox.show("结账完成!"); datagridview1.datasource = baseinfo.getalldd("db_dd").tables[0].defaultview; this.setdatagridview1headtext(); } else { messagebox.show("请选择正确的桌号!"); return ; } } } }
用户界面
using menusystemwss; using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace menusystemwss { public partial class gkfm : form { baseinfo baseinfo = new baseinfo(); baseinfo.gkinfo gkinfo = new baseinfo.gkinfo(); baseinfo.menuinfo menu = new baseinfo.menuinfo(); baseinfo.ddinfo ddinfo = new baseinfo.ddinfo(); public double xfzj = 0;//消费总价 public string yhsj = "";//用户手机号 public int qxzt = 0;//点击取消时的状态 public gkfm() { initializecomponent(); } private void gkfm_load(object sender, eventargs e) { datagridview1.datasource =baseinfo.getallmenu("db_menu").tables[0].defaultview;//展示菜品信息 datagridview1.readonly = true; this.setdatagridview1headtext(); load_enable(); } public void load_enable() { cancelall_enable(); dataset ds = null; ddinfo.zd_num = yhsj; ds = baseinfo.findddbyzcnum(ddinfo, "db_dd"); if (ds == null || ds.tables.count == 0 || (ds.tables.count == 1 && ds.tables[0].rows.count == 0)) { combobox1.enabled = true; tlbtnadd.enabled = true; } else { jcbtn.enabled = true; combobox1.text= ds.tables[0].rows[0][0].tostring().trim(); textboxxq.text = ds.tables[0].rows[0][2].tostring().trim(); textboxzj.text = ds.tables[0].rows[0][3].tostring().trim(); } if (textboxzj.text.trim() != "") { xfzj = convert.todouble(textboxzj.text.trim()); } else { xfzj = 0; } if (textboxxq.text != "") qxzt = 1; } public void cancelall_enable()//关闭所有的控件 { tlbtnadd.enabled = false; btnsave.enabled = false; btncancel.enabled = false; jcbtn.enabled = false; combobox1.enabled = false; textboxlx.enabled = false; textboxdj.enabled = false; textboxname.enabled = false; button1.enabled = false; textboxzj.enabled = false; textboxxq.enabled = false; } public void jc_enable() { btncancel.enabled = true; btnsave.enabled = true; button1.enabled = true; } public void add_enable() { tlbtnadd.enabled = false; btnsave.enabled = true; btncancel.enabled = true; button1.enabled = true; } public void cancel_enable() { if (qxzt == 0) { cancelall_enable(); tlbtnadd.enabled = true; combobox1.enabled = true; xfzj = 0; textboxxq.text = ""; } else { btnsave.enabled = false; btncancel.enabled = false; } } public void labletime() { labeltime.text = system.datetime.now.tostring(); } private void timer1_tick(object sender, eventargs e) { labletime(); } private void setdatagridview1headtext() { datagridview1.columns[0].headertext = "菜品编号"; datagridview1.columns[1].headertext = "菜品名称"; datagridview1.columns[2].headertext = "菜品规格"; datagridview1.columns[3].headertext = "菜品类型"; datagridview1.columns[4].headertext = "菜品价格"; } public void add(string strgk) { dataset ds = null; yhsj = strgk; gkinfo.gk_num = strgk; ds = baseinfo.denglu1(gkinfo, "db_menu"); label1.text = ds.tables[0].rows[0][1].tostring().trim() + "顾客您好 欢迎光临小帅饭店"; //**先生 } private void btnfind_click(object sender, eventargs e) { if (toolstripcombobox1.text == string.empty) { messagebox.show("查询类别不能为空!", "错误提示!", messageboxbuttons.ok, messageboxicon.error); toolstripcombobox1.focus(); return; } else if (toolstripcombobox1.text.trim() == "全部") { datagridview1.datasource = baseinfo.getallmenu("db_menu").tables[0].defaultview; this.setdatagridview1headtext(); return; } else { dataset ds = null; menu.menu_lx = toolstripcombobox1.text; ds = baseinfo.findmenubylx(menu, "db_menu"); datagridview1.datasource = ds.tables[0].defaultview; this.setdatagridview1headtext(); } } private void toolstrip1_itemclicked(object sender, toolstripitemclickedeventargs e) { } private void tlbtnadd_click(object sender, eventargs e) { messagebox.show("请选择桌号!"); add_enable(); } private void btncancel_click(object sender, eventargs e) { cancel_enable(); } private void datagridview1_cellclick(object sender, datagridviewcelleventargs e) { textboxname.text = this.datagridview1[1, datagridview1.currentcell.rowindex].value.tostring();//显示菜品全称 textboxlx.text = this.datagridview1[3, datagridview1.currentcell.rowindex].value.tostring();//显示菜品类型 textboxdj.text = this.datagridview1[4, datagridview1.currentcell.rowindex].value.tostring();//显示菜品价格 } private void tlbtnexit_click(object sender, eventargs e) { application.exit(); } private void button1_click(object sender, eventargs e) { textboxxq.text += textboxname.text.trim() + "*1; "; //listview1 .items.add(textboxname.text.trim()+"*1;"); xfzj += convert.todouble(textboxdj.text.trim()); textboxzj.text = xfzj.tostring(); } private void btnsave_click(object sender, eventargs e) { if (combobox1.text == "") { messagebox.show("桌号不能为空!请选择桌号!");return; } string strlist=textboxxq.text.trim() ; /* for (int i = 0; i < listview1.items.count; i++) { listviewitem item = listview1.items[i]; for (int j = 0; j < item.subitems.count; j++) { strlist += item.subitems[j].text; } }*/ if (qxzt == 0) { try { ddinfo.dd_num = convert.toint32(combobox1.selecteditem); ddinfo.zd_num = yhsj; ddinfo.dd_name = strlist; ddinfo.dd_zj = float.parse(textboxzj.text); ddinfo.dd_time = system.datetime.now.tostring().trim(); int id = baseinfo.adddd(ddinfo); messagebox.show("新增订单成功!", "成功提示!", messageboxbuttons.ok, messageboxicon.information); } catch (exception ex) { messagebox.show(ex.message, "错误提示", messageboxbuttons.ok, messageboxicon.error); } } else { ddinfo.dd_num = convert.toint32(combobox1.selecteditem); ddinfo.zd_num = yhsj; ddinfo.dd_name = strlist; ddinfo.dd_zj = float.parse(textboxzj.text); int id = baseinfo.updatedd(ddinfo); messagebox.show("菜品添加成功!"); } ////listview1.clear(); qxzt = 1; cancelall_enable(); jcbtn.enabled = true; } private void jcbtn_click(object sender, eventargs e) { jc_enable(); } private void combobox1_selectedindexchanged(object sender, eventargs e) { dataset ds = null; ddinfo.dd_num = int.parse(combobox1.text.trim()); ds = baseinfo.findddbyzh(ddinfo, "db_dd"); if (ds == null || ds.tables.count == 0 || (ds.tables.count == 1 && ds.tables[0].rows.count == 0)) { combobox1.enabled = false; } // else { messagebox.show("桌号选择错误!请重新选择");combobox1.text = ""; return; } } } }
还有两个类文件,可在项目中查看。
部分代码参考我们学的课本上的源代码,代码只是大作水平,仅供参考学习。
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。