C#实现在线点餐系统

这篇文章主要为大家详细介绍了C#实现在线点餐系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

这个是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; }
 }
 }
}

还有两个类文件,可在项目中查看。
部分代码参考我们学的课本上的源代码,代码只是大作水平,仅供参考学习。

更多学习资料请关注专题《管理系统开发》。

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

本文标题为:C#实现在线点餐系统

基础教程推荐