-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.cpp
163 lines (152 loc) · 4.81 KB
/
room.cpp
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "room.h"
#include "main.h"
#include "purchase.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
void __fastcall room::NewSeat (int tag, int l, int t)
{
if (l < 3)
l = 30 + l * 30;
else if ((l > 2) && (l < 7))
l = 60 + l * 30;
else l = 90 + l * 30;
seat* n = new seat();
if (n)
{
n->n = new TShape (Form1);
n->n->Tag = tag;
n->n->Left = l;
n->n->Top = t*30;
n->n->Width = 30;
n->n->Height = 30;
n->n->Brush->Color = clGreen;
n->n->Parent = Form3->Panel1;
n->n->OnMouseDown = (TMouseEvent)(&Occupy);
n->next = First;
First = n;
}
}
void __fastcall room::NewRow (int i) {
TLabel *row = new TLabel(Form3->Panel1);
row->Parent = Form3->Panel1;
row->Caption = " " + IntToStr(i+1);
row->Top = i*30;
row->Left = 1;
row->Width = 30;
row->Height = 30;
row->Font->Size = 16;
}
__fastcall room::room (int h): h(h), w(10)
{
int i, j;
First = 0;
for (i = 0; (i < h); ++i)
for (j = 0; j < w; ++j)
NewSeat(j+i*w, j, i);
Form3->Panel1->Height = 30*h;
Form3->Panel1->Visible = true;
for (i = 0; (i < h); ++i)
NewRow(i);
}
void __fastcall room::Occupy ( TShape * Sender, TMouseButton Button, \
TShiftState Shift, int X, int Y )
{
if (Sender->Brush->Color == clGreen)
Sender->Brush->Color = clMaroon;
}
void __fastcall room::Reserve(int srch)
{
seat * tmp;
for (tmp = First; tmp; tmp = tmp->next)
if (tmp->n->Tag == srch)
tmp->n->Brush->Color = clMaroon;
}
void __fastcall room::Buy(String n_fl, String n_pas, String t_type)
{
int n_s, n_t; // seat & ticket numbers
Form1->ADOQuery1->Close();
Form1->ADOQuery1->SQL->Clear();
Form1->ADOQuery1->SQL->Add("SELECT MAX (Íîìåð_áèëåòà) FROM Áèëåòû"); // ticket number
Form1->ADOQuery1->Open();
n_t = Form1->ADOQuery1->Fields->Fields[0]->AsInteger;
for(seat *tmp = First; tmp; tmp=tmp->next) {
if (tmp->n->Brush->Color==clMaroon) {
n_s = tmp->n->Tag+1;
n_t++;
Form1->ADOQuery1->Close();
Form1->ADOQuery1->SQL->Clear();
Form1->ADOQuery1->SQL->Add(\
"IF NOT EXISTS \
(\
SELECT * FROM Áèëåòû\
WHERE Íîìåð_ìåñòà = " + IntToStr(n_s) + "\
AND Íîìåð_ðåéñà = " + n_fl + "\
)\
INSERT INTO Áèëåòû\
(Íîìåð_áèëåòà, Òèï_áèëåòà, Íîìåð_ìåñòà, Íîìåð_ïàññàæèðà, Íîìåð_ðåéñà)\
VALUES (" + IntToStr(n_t) + ",'" + t_type + "'," + IntToStr(n_s)\
+ "," + n_pas + "," + n_fl + ")");
Form1->ADOQuery1->ExecSQL();
}
}
}
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormShow(TObject *Sender)
{
// get seat count (for plan's height)
Form1->ADOQuery1->Close();
Form1->ADOQuery1->SQL->Clear();
Form1->ADOQuery1->SQL->Add("\
SELECT Êîë_âî_ìåñò\
FROM Ñàìîëåòû INNER JOIN Ðåéñû\
ON Ñàìîëåòû.Íîìåð_ñàìîëåòà = Ðåéñû.Íîìåð_ñàìîëåòà\
WHERE Íîìåð_ðåéñà = '" + Form2->n_fl + "'");
Form1->ADOQuery1->Open();
// create the plan
r00m = new room((Form1->ADOQuery1->Fields->Fields[0]->AsInteger)/10);
// get tickets info to mark occupied seats
Form1->ADOQuery1->Active = false;
Form1->ADOQuery1->SQL->Text = "SELECT Íîìåð_ìåñòà FROM Áèëåòû\
WHERE Íîìåð_ðåéñà = '" + Form2->n_fl + "'";
Form1->ADOQuery1->Active = true;
for (; !Form1->ADOQuery1->Eof; Form1->ADOQuery1->Next())
r00m->Reserve(Form1->ADOQuery1->FieldByName("Íîìåð_ìåñòà")->AsInteger-1);
// get the surnames to choose from
Form1->ADOQuery1->Active = false;
Form1->ADOQuery1->SQL->Text = "SELECT Ôàìèëèÿ FROM Ïàññàæèðû";
Form1->ADOQuery1->Active = true;
for (; !Form1->ADOQuery1->Eof; Form1->ADOQuery1->Next())
ComboBox1->Items->Add\
(Form1->ADOQuery1->FieldByName("Ôàìèëèÿ")->AsString);
ComboBox1->Text = ComboBox1->Items->Strings[0];
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormClose(TObject *Sender, TCloseAction &Action)
{
Form2->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
// get passenger number to proceed with purchase
Form1->ADOQuery1->Close();
Form1->ADOQuery1->SQL->Clear();
Form1->ADOQuery1->SQL->Add("SELECT Íîìåð_ïàññàæèðà\
FROM Ïàññàæèðû WHERE Ôàìèëèÿ = '" + ComboBox1->Text + "'");
Form1->ADOQuery1->Open();
// do it
r00m->Buy(Form2->n_fl, Form1->ADOQuery1->Fields->Fields[0]->AsString,\
Form2->ticket_type);
ShowMessage("Óñïåõ");
}
//---------------------------------------------------------------------------