VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#实现在线点餐系统(2)

订单管理

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 ;
 }
 }
 }
}

用户界面

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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; }
 }
 }
}

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


相关教程
关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号