-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfInputInfor.cs
168 lines (134 loc) · 5.13 KB
/
fInputInfor.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
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;
using TicketSelling.DAO;
namespace TicketSelling
{
public partial class fInputInfor : Form
{
private string idTrip;
private string idUser;
private int numTicket;
private int numSeat;
private List<int> seat = new List<int>();
private bool control = false;
private int count = 0;
private List<Button> listButton = new List<Button>();
private int same = 0;
public fInputInfor(string idTrip, string idUser, int numTicket)
{
InitializeComponent();
this.idTrip = idTrip;
this.idUser = idUser;
this.numTicket = numTicket;
LoadSeat(this.idTrip);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnBook_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void btn_Click(object sender, EventArgs e)
{
this.control = true;
this.numSeat = (int) (sender as Button).Tag;
listButton.Add(sender as Button);
listButton[listButton.Count - 1].BackColor = Color.Red;
if (listButton.Count > 1)
{
if (listButton[listButton.Count - 2].Equals(listButton[listButton.Count - 1]))
{
same++;
if (same % 2 != 0) listButton[listButton.Count - 2].BackColor = Color.Gainsboro;
}
else
{
listButton[listButton.Count - 2].BackColor = Color.Gainsboro;
same = 0;
}
}
}
private void btnClear_Click(object sender, EventArgs e)
{
//Get list of booked seats
List<int> list = SeatDAO.Instance.LoadBookedSeat(idTrip);
//Choose ticket and check condition
if (control && (this.count < numTicket))
{
if (!list.Contains(numSeat) && !seat.Contains(numSeat))
{
this.count++;
MessageBox.Show("Choose Successfully!\nTicket " + count.ToString() + " Number is: " + numSeat.ToString());
seat.Add(this.numSeat);
control = false;
listButton = new List<Button>();
same = 0;
} else
{
MessageBox.Show("Ticket number: " + numSeat.ToString() + " is canceled ");
seat.Remove(this.numSeat);
this.count--;
control = false;
listButton = new List<Button>();
same = 0;
}
}
//Mark ticket is booked
foreach (Control c in flowLayoutSeat.Controls.OfType<Button>())
{
string temp = c.ToString().Substring(35, 2);
int a = Int32.Parse(temp);
if (seat.Contains(a)) c.BackColor = Color.Red; else if (!list.Contains(a)) c.BackColor =Color.Gainsboro;
}
//Move next form
if (this.count == numTicket)
{
fConfirm fConfirm = new fConfirm(this.idTrip, this.idUser, this.seat);
this.Hide();
fConfirm.ShowDialog();
//this.Show();
control = false;
}
}
//Get Seat
int getSeat (string idTrip)
{
DataTable result = SeatDAO.Instance.getSeat(idTrip);
return (int)(result.Rows[0].ItemArray[0]);
}
//Load Seat
void LoadSeat(string idTrip)
{
List<int> list = SeatDAO.Instance.LoadBookedSeat(idTrip);
for (int i = 1; i <= getSeat(idTrip); i++)
{
int newSize = 11; string status = "Available";
Button btn = new Button { Width = 80, Height = 80 };
if (list.Contains(i))
{
btn.BackColor = Color.Aqua;
status = "Booked";
btn.Font = new Font(btn.Font.OriginalFontName, newSize);
btn.Text = i.ToString() + Environment.NewLine + status;
} else
{
btn.Font = new Font(btn.Font.OriginalFontName, newSize);
btn.Text = i.ToString() + Environment.NewLine + status;
btn.Click += btn_Click; //Create event Click of button
btn.Tag = i; //Assign value to button
}
flowLayoutSeat.Controls.Add(btn);
}
}
}
}