-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientsInfoForm.cpp
More file actions
182 lines (155 loc) · 5.54 KB
/
Copy pathClientsInfoForm.cpp
File metadata and controls
182 lines (155 loc) · 5.54 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
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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClientsInfoForm.h"
#include "Data\AllData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm10 *Form10;
//---------------------------------------------------------------------------
__fastcall TForm10::TForm10(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;
}
//Loads info on screen & sends file to the server
LoadListView();
translation["AddClient"] = {
{
{"EN", "Add new client"},
{"HR", "Dodaj novog klijenta na popis"}
}
};
translation["DeleteClient"] = {
{
{"EN", "Delete selected client"},
{"HR", "Izbrišite odabranog klijenta"}
}
};
translation["EditClient"] = {
{
{"EN", "Edit selected client"},
{"HR", "Ažurirajte odabranog klijenta"}
}
};
translation["GroupBox1"] = {
{
{"EN", "Enter information about client"},
{"HR", "Unesite podatke o klijentu"}
}
};
translation["CompanyLabel"] = {
{
{"EN", "Company"},
{"HR", "Tvrtka"}
}
};
translation["ContactPersonLabel"] = {
{
{"EN", "Contact Person"},
{"HR", "Osoba za kontakt"}
}
};
translation["IDLabel"] = {
{
{"EN", "ID Number"},
{"HR", "OIB"}
}
};
translation["AddressLabel"] = {
{
{"EN", "Address"},
{"HR", "Sjedište"}
}
};
translation["Title"] = {
{
{"EN", "Information about clients"},
{"HR", "Podaci o svim klijentima"}
}
};
}
//---------------------------------------------------------------------------
void __fastcall TForm10::AddClientClick(TObject *Sender)
{
// place info into cache before adding to file
DataModule1->jsonHelper.currentClient.CompanyName = CompanyNameBox->Text;
DataModule1->jsonHelper.currentClient.Address = AddressBox->Text;
DataModule1->jsonHelper.currentClient.IdentificationNumber = IDBox->Text;
DataModule1->jsonHelper.currentClient.Email = EmailBox->Text;
DataModule1->jsonHelper.currentClient.ContactPerson = ContactPersonBox->Text;
// write to file is added into AddClient()
DataModule1->jsonHelper.AddClient();
LoadListView(); //refresh view
DataModule1->SendJSON(); //update file on server
}
//---------------------------------------------------------------------------
void TForm10::LoadListView(){
//fill the list view
ListView1->Items->Clear();
for(int i = 0; i < DataModule1->jsonHelper.allClients.size(); i++){
ListView1->Items->Add();
ListView1->Items->Item[i]->Caption = DataModule1->jsonHelper.allClients[i].CompanyName;
ListView1->Items->Item[i]->SubItems->Add(DataModule1->jsonHelper.allClients[i].Address);
ListView1->Items->Item[i]->SubItems->Add(DataModule1->jsonHelper.allClients[i].IdentificationNumber);
ListView1->Items->Item[i]->SubItems->Add(DataModule1->jsonHelper.allClients[i].Email);
ListView1->Items->Item[i]->SubItems->Add(DataModule1->jsonHelper.allClients[i].ContactPerson);
}
//can't place this here because constructor happens before the keys are generated
//DataModule1->SendJSON();
}
void __fastcall TForm10::DeleteClientClick(TObject *Sender)
{
if(ListView1->ItemIndex == -1){
return;
}
DataModule1->jsonHelper.DeleteClient(ListView1->ItemIndex);
DataModule1->jsonHelper.RewriteFile();
LoadListView();
ListView1->ItemIndex = -1;
DataModule1->SendJSON(); //update file on server
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm10::ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected)
{
//remove info in input fields if noone is selected
if(ListView1->ItemIndex == -1){
DataModule1->jsonHelper.currentClient.CompanyName = "";
DataModule1->jsonHelper.currentClient.Address = "";
DataModule1->jsonHelper.currentClient.IdentificationNumber = "";
DataModule1->jsonHelper.currentClient.Email = "";
DataModule1->jsonHelper.currentClient.ContactPerson = "";
return;
}
//update cache with selected information - TODO: extract this
DataModule1->jsonHelper.currentClient.CompanyName = ListView1->Selected->Caption;
DataModule1->jsonHelper.currentClient.Address = ListView1->Selected->SubItems->Strings[0];
DataModule1->jsonHelper.currentClient.IdentificationNumber = ListView1->Selected->SubItems->Strings[1];
DataModule1->jsonHelper.currentClient.Email = ListView1->Selected->SubItems->Strings[2];
DataModule1->jsonHelper.currentClient.ContactPerson = ListView1->Selected->SubItems->Strings[3];
}
//---------------------------------------------------------------------------
void __fastcall TForm10::EditClientClick(TObject *Sender)
{
//don't do anything if noone is selected
if(ListView1->ItemIndex == -1){
return;
}
//update cache with selected info
DataModule1->jsonHelper.currentClient.CompanyName = CompanyNameBox->Text;
DataModule1->jsonHelper.currentClient.Address = AddressBox->Text;
DataModule1->jsonHelper.currentClient.IdentificationNumber = IDBox->Text;
DataModule1->jsonHelper.currentClient.Email = EmailBox->Text;
DataModule1->jsonHelper.currentClient.ContactPerson = ContactPersonBox->Text;
DataModule1->jsonHelper.EditClient(ListView1->ItemIndex);
LoadListView();
DataModule1->SendJSON();
}
//---------------------------------------------------------------------------