-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeTable.cs
270 lines (250 loc) · 11.4 KB
/
ChangeTable.cs
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
265
266
267
268
269
270
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.Web.Script.Serialization;
using Business;
namespace Client
{
public partial class ChangeTable : Form
{
int people = 0;
HttpAskfor httpReq = new HttpAskfor();
public ChangeTable(int _people)
{
InitializeComponent();
people = _people;
}
public string Str_Tables;
public string Str_Status;
public string Str_consumptionsid;
public List<string> TableidList = new List<string>();
public List<string> ConsumptionList = new List<string>();
public List<int> PeopleList = new List<int>();
public List<string> SizeList = new List<string>();
public List<string> SubtotalList = new List<string>();
public List<string> StatusList = new List<string>();
private void ChangeTable_Load(object sender, EventArgs e)
{
this.lbTable.Text = PassValue.ChooseFloor +"F "+ PassValue.Tablename;
this.Txt_ID.Text = PassValue.consumptionid;
AddTable();
}
//取消
private void Btn_Canel_Click(object sender, EventArgs e)
{
this.Close();
}
public List<string> SelectIDList = new List<string>();//将被选中的桌子的消费ID存放进集合
//桌子点击事件
public void btntalbe_MouseDown(object sender, MouseEventArgs e)
{
PassValue.count_select_ordering = 0;
DeskControl.DeskControl dc = (DeskControl.DeskControl)sender;
if (e.Button == MouseButtons.Left)
{
if (!dc.picCheck.Visible)
{
dc.picCheck.Visible = true;
if (!SelectIDList.Contains(dc.lbTableID.Text))
{
SelectIDList.Add(dc.lbTableID.Text);//添加的时候,如果不包含才能添加
PassValue.count_select_ordering +=1;
}
}
else
{
dc.picCheck.Visible = false;
if (SelectIDList.Contains(dc.lbTableID.Text))
{
SelectIDList.Remove(dc.lbTableID.Text);//删除的时候,只有包含才能删除
PassValue.count_select_ordering -=1;
}
}
}
}
//桌子的构造
public void AddTable()
{
int n = this.Width;//总宽度
DeskControl.DeskControl dcdc2 = new DeskControl.DeskControl();
int w = dcdc2.Width;//控件宽度
int h = dcdc2.Height;//控件高度
int item = w / 5;//控件间距
int item2 = h / 5;
int t = (n - item) / (w + item);//控件个数
int y = n - (item + w) * t;//右边间距
this.panelTables.Controls.Clear();
SelectIDList.Clear();
TableidList.Clear();
SizeList.Clear();
StatusList.Clear();
List<Table> personsTable = httpReq.HttpGet<List<Table>>("tables");
List<Status> personsStatus = httpReq.HttpGet<List<Status>>("statuses");
//排序
if (personsStatus != null)
{
personsStatus = personsStatus.OrderBy(r => r.table.name).ToList();
}
for (int i = 0; i < personsStatus.Count(); i++)
{
if (personsStatus[i].consumption == null || personsStatus[i].consumption.id == this.Txt_ID.Text)
{
TableidList.Add(personsStatus[i].table.id);//桌子ID
SizeList.Add(personsStatus[i].table.size.ToString());//大小
StatusList.Add(personsStatus[i].state);//状态
if (personsStatus[i].consumption == null)
{
ConsumptionList.Add("");
PeopleList.Add(0);//人数
SubtotalList.Add("0.00");//总价
}
else
{
ConsumptionList.Add(personsStatus[i].consumption.id); //消费ID
PeopleList.Add(personsStatus[i].consumption.people);//人数
SubtotalList.Add(personsStatus[i].consumption.subtotal);//总价
}
}
}
for (int j = 0; j < TableidList.Count(); j++)
{
DeskControl.DeskControl dc = new DeskControl.DeskControl();
dc.Location = new System.Drawing.Point(item + (y - item) / 2 + (item + w) * (j % t), item2 * 2 + (item2 + h) * (j / t));//桌子控件坐标位置[动态坐标]
this.panelTables.Controls.Add(dc);//tab里面添加构造好的桌子
dc.MouseDown += new MouseEventHandler(btntalbe_MouseDown);//桌子的点击触发事件
dc.lbConsumption.Text = ConsumptionList[j];//消费ID
for (int c = 0; c < personsTable.Count(); c++)
{
if (personsTable[c].id == TableidList[j])
{
dc.lbName.Text = personsTable[c].name;//桌子名
dc.lbNumber.Text = personsTable[c].room.name;//包间名
dc.lbTableID.Text = personsTable[c].id;//桌子ID
dc.lbPeople.Text = PeopleList[j].ToString() + "/" + SizeList[j] + " ¥" + SubtotalList[j];
if (StatusList[j].Equals("ordering")) { dc.picDesk.Image = Properties.Resources.ordering; dc.lbStatus.Text = "ordering"; }
else if (StatusList[j].Equals("dining")) { dc.picDesk.Image = Properties.Resources.dining; dc.lbStatus.Text = "dining"; }
}
}
}
}
//提交
private void Btn_Enter_Click(object sender, EventArgs e)
{
if (SelectIDList.Count > 0)
{
Desk d;
d = (Desk)this.Owner;
d.CurrentChooseDesk.Clear();
//添加桌子
foreach (Control ctl in this.panelTables.Controls)
{
if (ctl is DeskControl.DeskControl)
{
DeskControl.DeskControl dc = (DeskControl.DeskControl)ctl;
if (dc.picCheck.Visible)
{
d.CurrentChooseDesk.Add(dc.lbTableID.Text, string.Format("{0}({1})", dc.lbName.Text, dc.lbNumber.Text));
}
}
}
Consumption cp = new Consumption();
cp.id = this.Txt_ID.Text;
cp.tables = new Table[SelectIDList.Count()];
cp.people = people;
int i = 0;
foreach (string id in SelectIDList)
{
Table table = new Table();
table.id = id;
cp.tables[i++] = table;
}
HttpResult httpResult = httpReq.HttpPatch(string.Format("consumptions/{0}", cp.id), cp);
if ((int)httpResult.StatusCode == 409)
{
MessageBox.Show("选择的桌子已被操作,请选择其他!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
AddTable();
return;
}
else if ((int)httpResult.StatusCode == 401)
{
LoginBusiness lg = new LoginBusiness();
lg.LoginAgain();
return;
}
else if ((int)httpResult.StatusCode == 0)
{
MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
MessageBox.Show("换台成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
d.Refresh_Method();
this.Close();
}
else
{
MessageBox.Show("请先选择桌子!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
private void Btn_Find_Click(object sender, EventArgs e)
{
int n = this.Width;//总宽度
DeskControl.DeskControl dcdc2 = new DeskControl.DeskControl();
int w = dcdc2.Width;//控件宽度
int h = dcdc2.Height;//控件高度
int item = w / 5;//控件间距
int item2 = h / 5;
int t = (n - item) / (w + item);//控件个数
int y = n - (item + w) * t;//右边间距
this.panelTables.Controls.Clear();
TableidList.Clear(); PeopleList.Clear(); SizeList.Clear(); SubtotalList.Clear(); SelectIDList.Clear();
if (string.IsNullOrEmpty(this.Txt_Find.Text))
{
AddTable();
}
else
{
List<Table> personsTable = httpReq.HttpGet<List<Table>>("tables");
List<Status> personsStatus = httpReq.HttpGet<List<Status>>("statuses");
for (int i = 0; i < personsStatus.Count(); i++)
{
if (personsStatus[i].table.name.Equals(this.Txt_Find.Text) && personsStatus[i].consumption == null && personsStatus[i].state == "idle")
{
TableidList.Add(personsStatus[i].table.id);//桌子ID
SizeList.Add(personsStatus[i].table.size.ToString());//大小
}
}
if (TableidList.Count() != 0)//判断是否有空的桌子,如果有的情况
{
for (int j = 0; j < TableidList.Count(); j++)
{
DeskControl.DeskControl dc = new DeskControl.DeskControl();
dc.Location = new System.Drawing.Point(item + (y - item) / 2 + (item + w) * (j % t), item2 * 2 + (item2 + h) * (j / t));//桌子控件坐标位置[动态坐标]
this.panelTables.Controls.Add(dc);//tab里面添加构造好的桌子
dc.MouseDown += new MouseEventHandler(btntalbe_MouseDown);//桌子的点击触发事件
for (int c = 0; c < personsTable.Count(); c++)
{
if (personsTable[c].id == TableidList[j])
{
dc.lbName.Text = personsTable[c].name;//桌子名
dc.lbNumber.Text = personsTable[c].room.name;//包间名
dc.lbTableID.Text = personsTable[c].id;//桌子ID
dc.lbPeople.Text = "人数:0/" + SizeList[j]+ " ¥" +"0.00";
dc.picDesk.Image = Properties.Resources.idle;
dc.lbStatus.Text = "idle";
}
}
}
}
else
{
MessageBox.Show("您输入的桌号不存在或未消费!");
}
}
}
}
}