-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompanyCarsForm.cpp
More file actions
134 lines (114 loc) · 3.73 KB
/
Copy pathCompanyCarsForm.cpp
File metadata and controls
134 lines (114 loc) · 3.73 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CompanyCarsForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm12 *Form12;
//---------------------------------------------------------------------------
__fastcall TForm12::TForm12(TComponent* Owner)
: TForm(Owner)
{
//make ListView columns have equally distributed width & fill entire space
if(ListView1->Columns->Count > 0)
{
int ColWidth = ListView1->ClientWidth / ListView1->Columns->Count;
for(int i = 0; i < ListView1->Columns->Count; i++)
ListView1->Columns->Items[i]->Width = ColWidth;
}
DataModule1->RequestXMLFile();
FillListView();
}
//---------------------------------------------------------------------------
//update company cars and fill the list view with most recent info
void __fastcall TForm12::FillListView(){
DataModule1->companycars = Getcompanycars(DataModule1->XmlDoc);
ListView1->Items->Clear();
for(int i = 0; i < DataModule1->companycars->Count; i++){
TListItem *Item = ListView1->Items->Add();
Item->Caption = DataModule1->companycars->car[i]->licenseplate;
Item->SubItems->Add(DataModule1->companycars->car[i]->internalmark);
Item->SubItems->Add(DataModule1->companycars->car[i]->assigned);
Item->SubItems->Add(DataModule1->companycars->car[i]->currentuser);
Item->SubItems->Add(DataModule1->companycars->car[i]->location);
}
translation["LoadAll"] = {
{
{"EN", "Load all cars"},
{"HR", "Učitajte sve podatke "}
}
};
translation["AddNewCar"] = {
{
{"EN", "Add new car"},
{"HR", "Unesite novo vozilo "}
}
};
translation["EditCar"] = {
{
{"EN", "Edit selected car"},
{"HR", "Ažurirajte odabrano vozilo "}
}
};
translation["RemoveCar"] = {
{
{"EN", "Remove selected car"},
{"HR", "Izbrišite odabrano vozilo "}
}
};
translation["Title"] = {
{
{"EN", "Information about company cars"},
{"HR", "Podaci o službenim vozilima "}
}
};
}
void __fastcall TForm12::AddNewCarClick(TObject *Sender)
{
//open separate window for entering car info
Form3->AddCarMode();
Form3->ShowModal();
//get changes
FillListView();
}
//---------------------------------------------------------------------------
void __fastcall TForm12::EditCarClick(TObject *Sender)
{
//open separate window for entering car info with selected info
Form3->EditCarMode(ListView1->ItemIndex);
Form3->ShowModal();
FillListView();
}
//---------------------------------------------------------------------------
void __fastcall TForm12::RemoveCarClick(TObject *Sender)
{
DataModule1->XmlDoc->Active = false;
DataModule1->DeleteFromXml(ListView1->ItemIndex);
DataModule1->XmlDoc->Active = true;
DataModule1->XmlDoc->Active = false;
DataModule1->RequestXMLFile();
DataModule1->XmlDoc->Active = true;
//delete car based on index
//DataModule1->companycars->Delete(ListView1->ItemIndex);
//DataModule1->XmlDoc->SaveToFile(DataModule1->XmlDoc->FileName);
//avoid double click deleting next node in line
ListView1->ItemIndex = -1;
FillListView();
}
//---------------------------------------------------------------------------
void __fastcall TForm12::ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected)
{
//get the selected node from xml on selecting the listview item
if(ListView1->ItemIndex == -1){
return;
}
DataModule1->currentCar = DataModule1->companycars->car[ListView1->ItemIndex];
}
//---------------------------------------------------------------------------
void __fastcall TForm12::LoadAllClick(TObject *Sender)
{
DataModule1->RequestXMLFile();
FillListView();
}
//---------------------------------------------------------------------------