-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteForm.cpp
More file actions
156 lines (139 loc) · 3.75 KB
/
NoteForm.cpp
File metadata and controls
156 lines (139 loc) · 3.75 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
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "NoteForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include <Vcl.Imaging.pngimage.hpp>
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner, const Note& note_)
: TForm(Owner)
{
success = false;
isDelete = false;
note = note_;
if(note.firstName.Length() == 0)
{
Photo->Canvas->Brush->Color = clWhite;
Photo->Canvas->FillRect(TRect(0, 0, 128, 160));
AddButton->Caption = L"Äîáàâèòü";
AddButton->Width = 254;
DeleteButton->Visible = false;
TResourceStream* stream
= new TResourceStream((int)HInstance, "PngImage_1", RT_RCDATA);
TPngImage* img = new TPngImage();
img->LoadFromStream(stream);
auto* bitmap = new Graphics::TBitmap();
bitmap->Width = 128;
bitmap->Height = 160;
TRect rect = TRect(0, 0, bitmap->Width, bitmap->Height);
bitmap->Canvas->StretchDraw(rect, img);
img->Assign(bitmap);
Photo->Picture->Assign(img);
}
else
{
LastNameEdit->Text = note.lastName;
FirstNameEdit->Text = note.firstName;
MiddleNameEdit->Text = note.middleName;
AdressEdit->Text = note.adress;
NumberEdit->Text = note.number;
photoPath = note.photoPath;
TPngImage* img = new TPngImage();
auto* bitmap = new Graphics::TBitmap();
bitmap->Width = 128;
bitmap->Height = 160;
img->LoadFromFile(photoPath);
TRect rect = TRect(0, 0, bitmap->Width, bitmap->Height);
bitmap->Canvas->StretchDraw(rect, img);
img->Assign(bitmap);
Photo->Picture->Assign(img);
delete img;
delete bitmap;
AddButton->Caption = L"Èçìåíèòü";
AddButton->Width = 121;
DeleteButton->Visible = true;
}
}
//---------------------------------------------------------------------------
Note TForm2::getNote()
{
return note;
}
void __fastcall TForm2::AddButtonClick(TObject *Sender)
{
note.lastName = LastNameEdit->Text;
if(note.lastName.Length() == 0)
{
Application->MessageBox(L"Ââåäèòå ôàìèëèþ!", L"Îøèáêà", MB_OK);
return;
}
note.firstName = FirstNameEdit->Text;
if(note.firstName.Length() == 0)
{
Application->MessageBox(L"Ââåäèòå èìÿ!", L"Îøèáêà", MB_OK);
return;
}
note.middleName = MiddleNameEdit->Text;
if(note.middleName.Length() == 0)
{
Application->MessageBox(L"Ââåäèòå îò÷åñòâî!", L"Îøèáêà", MB_OK);
return;
}
note.number = NumberEdit->Text;
if(note.number.Length() == 0)
{
Application->MessageBox(L"Ââåäèòå íîìåð!", L"Îøèáêà", MB_OK);
return;
}
note.adress = AdressEdit->Text;
if(note.adress.Length() == 0)
{
Application->MessageBox(L"Ââåäèòå àäðåñ!", L"Îøèáêà", MB_OK);
return;
}
note.photoPath = photoPath;
if(note.photoPath.Length() == 0)
{
note.photoPath = L"user-male.png";
}
success = true;
isDelete = false;
Close();
}
bool TForm2::isSuccess()
{
return success;
}
void __fastcall TForm2::GetPhotoButtonClick(TObject *Sender)
{
if(OpenPhotoDialog->Execute())
{
photoPath = OpenPhotoDialog->FileName;
TPngImage* img = new TPngImage();
auto* bitmap = new Graphics::TBitmap();
bitmap->Width = 128;
bitmap->Height = 160;
img->LoadFromFile(photoPath);
TRect rect = TRect(0, 0, bitmap->Width, bitmap->Height);
bitmap->Canvas->StretchDraw(rect, img);
img->Assign(bitmap);
Photo->Picture->Assign(img);
delete img;
delete bitmap;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::DeleteButtonClick(TObject *Sender)
{
isDelete = true;
success = true;
Close();
}
//---------------------------------------------------------------------------
bool TForm2::toDelete()
{
return isDelete;
}