-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainUnit.cpp
More file actions
112 lines (100 loc) · 3.44 KB
/
MainUnit.cpp
File metadata and controls
112 lines (100 loc) · 3.44 KB
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "VirtualTrees"
#pragma link "VirtualTrees.AncestorVCL"
#pragma link "VirtualTrees.BaseAncestorVCL"
#pragma link "VirtualTrees.BaseTree"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
LibraryStringTree->NodeDataSize = sizeof(NodeStruct);
it = Container.GetIterator();
RepairBooks->Enabled = false;
InspectBooks->Enabled = false;
}
//---------------------------------------------------------------------------
Iterator<PtrBook>* TMainForm::GetIterator()
{
return Container.GetIterator();
}
//---------------------------------------------------------------------------
void FillStringTree(TVirtualStringTree *stringTree, Iterator<PtrBook> *it)
{
//Îñòàíàâëèâàåì îáíîâëåíèå èíòåðôåéñà
stringTree->BeginUpdate();
//Î÷èñòèòü äåðåâî
stringTree->Clear();
for(it->First(); !it->IsDone(); it->Next())
{
//Äîáàâëÿåì î÷åðåäíóþ çàïèñü
PVirtualNode entryNode = stringTree->AddChild(stringTree->RootNode);
//Çàïîëíÿåì äàííûå óçëà
NodeStruct *nodeData = (NodeStruct*)stringTree->GetNodeData(entryNode);
PtrBook book = it->GetCurrent();
nodeData->Year = book->GetYear();
nodeData->Pages = book->GetNumberOfPage();
nodeData->Condition = book->GetCondition();
nodeData->Type = UnicodeString( PrintType(book->GetType()).c_str() );
switch((int)book->GetType())
{
case 0:
nodeData->Specific = PrintGenre(((Fiction *)book)->GetGenre());
break;
case 1:
nodeData->Specific = PrintDiscipline(((Textbook *)book)->GetDisc());
break;
case 2:
nodeData->Specific = PrintTheme(((Journal *)book)->GetTheme());
break;
}
}
//Âêëþ÷àåì îáíîâëåíèå èíòåðôåéñà
stringTree->EndUpdate();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::LibraryStringTreeGetText(TBaseVirtualTree *Sender, PVirtualNode Node,
TColumnIndex Column, TVSTTextType TextType, UnicodeString &CellText)
{
if(!Node) return;
NodeStruct *nodeData = (NodeStruct*)Sender->GetNodeData(Node);
switch(Column)
{
case 0: CellText = nodeData->Year; break;
case 1: CellText = nodeData->Pages; break;
case 2: CellText = nodeData->Condition; break;
case 3: CellText = nodeData->Specific; break;
case 4: CellText = nodeData->Type; break;
}
}
//---------------------------------------------------------------------------
void TMainForm::AddBookToContainer()
{
//srand(time(0));
Container.AddBook(Book::createBook(RandomBookType()));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::GetBooksClick(TObject *Sender)
{
th = new Thread2(true, true, false, false, it);
th->Resume();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::InspectBooksClick(TObject *Sender)
{
th = new Thread2(true, false, true, false, it);
th->Resume();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::RepairBooksClick(TObject *Sender)
{
th = new Thread2(true, false, false, true, it);
th->Resume();
}
//---------------------------------------------------------------------------