您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關使用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#怎么編寫一個在線點餐系統有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。