-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edit.cpp
72 lines (58 loc) · 2.15 KB
/
Edit.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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Edit.h"
#include "Main.h"
#include "UserControls.h"
#include "UserData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
using namespace std;
namespace fs = std::filesystem;
extern int rowId;
extern vector<userBook> userBooks;
//UserControls.cpp
void setAddNewComboBox(TComboBox *comboBox, string selected);
//Main.cpp
string returnStr(AnsiString output);
TEditForm *EditForm;
//---------------------------------------------------------------------------
__fastcall TEditForm::TEditForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TEditForm::FormActivate(TObject *Sender)
{
BookNameEdit1->Text = userBooks[rowId - 1].bookName.c_str();
BookAuthorEdit1->Text = userBooks[rowId - 1].bookAuthor.c_str();
setAddNewComboBox(BookGenreComboBox, userBooks[rowId - 1].genre.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TEditForm::DeleteButton1Click(TObject *Sender)
{
bool isDeleting = MessageDlg("Are you sure that you want to delete this book from reading history?", mtConfirmation, TMsgDlgButtons() << mbYes << mbNo,0) == mrYes;
if (isDeleting) {
MainForm->aDeleteItem->Execute();
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TEditForm::EditButton1Click(TObject *Sender)
{
userBook newBook = userBooks[rowId - 1];
newBook.bookName = returnStr(BookNameEdit1->Text);
newBook.bookAuthor = returnStr(BookAuthorEdit1->Text);
if (CustomBookGenre->Text != "") {
newBook.genre = returnStr(CustomBookGenre->Text);
}
else {
newBook.genre = returnStr(BookGenreComboBox->Text);
}
//newBook.isFinished = IsFinishedCheckbox->Checked;
userBooks[rowId - 1] = newBook;
MainForm->aEditItem->Execute();
Close();
}
//---------------------------------------------------------------------------