-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCriarProjeto.pas
277 lines (258 loc) · 7.13 KB
/
CriarProjeto.pas
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
unit CriarProjeto;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Menus, Buttons, DB, ZAbstractRODataset,
ZAbstractDataset, ZDataset, ZAbstractConnection, ZConnection, Mask,
ComCtrls;
type
TFormCriarProjeto = class(TForm)
Menu: TMainMenu;
Ajuda1: TMenuItem;
Logoff: TMenuItem;
Panel: TPanel;
lblTitulo: TLabel;
edtnome: TLabeledEdit;
cboxModelo: TComboBox;
lblDesenvolvimento: TLabel;
memoDescricao: TMemo;
lblDescricao: TLabel;
btnCadastrar: TBitBtn;
btnLimpar: TBitBtn;
btnVoltar: TBitBtn;
Query: TZQuery;
edtcriacao: TLabeledEdit;
lblEntrega: TLabel;
edtEntrega: TMaskEdit;
Calendario: TMonthCalendar;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure LogoffClick(Sender: TObject);
procedure btnLimparClick(Sender: TObject);
procedure btnVoltarClick(Sender: TObject);
procedure btnCadastrarClick(Sender: TObject);
procedure cboxModeloChange(Sender: TObject);
procedure Ajuda1Click(Sender: TObject);
procedure edtEntregaClick(Sender: TObject);
procedure CalendarioDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormCriarProjeto: TFormCriarProjeto;
modelo:string;
implementation
uses Home, CriarProjetoAjuda;
{$R *.dfm}
procedure TFormCriarProjeto.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//Fechar o form
FormCriarProjeto.close;
FormCriarProjeto:=Nil;
end;
procedure TFormCriarProjeto.FormCreate(Sender: TObject);
begin
//Centraliza form
Left := (GetSystemMetrics(SM_CXSCREEN) - Width) div 2;
Top := (GetSystemMetrics(SM_CYSCREEN) - Height) div 2;
//Edtcriacao pega data atual
edtcriacao.text:=DatetoStr(Date);
end;
procedure TFormCriarProjeto.LogoffClick(Sender: TObject);
begin
//Fechar o programa
Application.Terminate;
end;
procedure TFormCriarProjeto.btnLimparClick(Sender: TObject);
begin
//Limpar os capos
edtnome.clear;
cboxmodelo.itemindex:=-1;
memodescricao.clear;
edtEntrega.Clear;
edtNome.SetFocus;
end;
procedure TFormCriarProjeto.btnVoltarClick(Sender: TObject);
begin
//Fechar o form
FormCriarProjeto.Close;
end;
procedure TFormCriarProjeto.btnCadastrarClick(Sender: TObject);
var
//Variável que irá armazenar o código do login do usuário para usar de FK
codigo:integer;
//Variáveis para restrição de espaços excessivos
palavra,letra,hora:string;
i,cont,tamanho:integer;
begin
//Verificar se os campos estão vazios, se estiverem, aborta o laço
if (edtnome.text='') then
begin
messagedlg('O campo nome do projeto é obrigatório!',mterror,mbokcancel,0);
edtnome.setfocus;
abort;
end;
if (cboxmodelo.itemindex=0) then
begin
messagedlg('Selecione algum modelo de desenvolvimento, é obrigatório!',mterror,mbokcancel,0);
cboxmodelo.setfocus;
abort;
end;
if (memodescricao.Lines.text='') then
begin
messagedlg('O projeto necessita de uma descrição, é obrigatório!',mterror, mbokcancel, 0);
memodescricao.setfocus;
abort;
end;
if (edtentrega.text='') then
begin
messagedlg('Selecione uma data de entrega no calendário, é obrigatório!',mterror,mbokcancel,0);
edtEntrega.setfocus;
abort;
end;
//Verrifica se existe muitos espaços nos campos
cont:=0;
palavra:=edtnome.text;
tamanho:=length(palavra);
for i:=1 to tamanho do
begin
letra:=copy(palavra,i,1);
if (letra=' ') then
begin
cont:=cont-2;
end
else
begin
cont:=cont+1;
end;
end;
if (cont<0) then
begin
messagedlg('Existe muitos espaços no campo nome do projeto!',mterror,mbokcancel,0);
edtnome.setfocus;
abort;
end;
cont:=0;
palavra:=memodescricao.lines.text;
tamanho:=length(palavra);
for i:=1 to tamanho do
begin
letra:=copy(palavra,i,1);
if (letra=' ') then
begin
cont:=cont-2;
end
else
begin
cont:=cont+1;
end;
end;
if (cont<0) then
begin
messagedlg('Existe muitos espaços no campo descrição!',mterror,mbokcancel,0);
memodescricao.setfocus;
abort;
end;
//Verifica o codigo do login do usuário para armazenar FK
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('select * from tbacesso where codigo= (select max(codigo) from tbacesso)');
query.open;
codigo:=Query.FieldByName('codigo_login').Asinteger;
end;
//Inicia a variável hora
hora:=TimetoStr(Time);
//Inserir na tabela
with query do
begin
query.close;
query.sql.clear;
query.SQL.text:=('select nome from tbprojeto where nome="'+edtnome.text+'"');
query.Open;
if query.IsEmpty then
begin
query.close;
query.sql.clear;
query.sql.text:=('insert into tbprojeto (nome, modelo, descricao, datacriacao, horacriacao, dataentrega, codigo_login) values ("'+edtnome.text+'","'+modelo+'","'+memodescricao.lines.text+'","'+edtcriacao.text+'","'+hora+'","'+edtentrega.Text+'","'+InttoStr(codigo)+'")');
Query.ExecSql;
showmessage('Seu projeto foi criado com sucesso!');
//Fecha o FormCriarProjeto após criar o projeto com sucesso
FormCriarProjeto.Close;
end
else
begin
messagedlg('Já existe um projeto criado com este nome, escolha outro!',mterror,mbokcancel,0);
edtnome.setfocus;
abort;
end;
end;
end;
procedure TFormCriarProjeto.cboxModeloChange(Sender: TObject);
begin
//Pega o modelo do combobox e insera em uma variável string
if (cboxmodelo.itemindex=0) then
begin
modelo:='';
end;
if (cboxmodelo.itemindex=1) then
begin
modelo:='CASCATA';
end;
if (cboxmodelo.itemindex=2) then
begin
modelo:='ESPIRAL';
end;
if (cboxmodelo.itemindex=3) then
begin
modelo:='PROTOTIPAÇÃO';
end;
if (cboxmodelo.itemindex=4) then
begin
modelo:='XP';
end;
if (cboxmodelo.itemindex=5) then
begin
modelo:='SCRUM';
end;
if (cboxmodelo.itemindex=6) then
begin
modelo:='PERSONALIZADO';
end;
end;
procedure TFormCriarProjeto.Ajuda1Click(Sender: TObject);
begin
//Criar o FormCriarProjetoAjuda e exibir
Application.CreateForm(TFormCriarProjetoAjuda, FormCriarProjetoAjuda);
FormCriarProjetoAjuda.Showmodal;
end;
procedure TFormCriarProjeto.edtEntregaClick(Sender: TObject);
begin
//Exibe o calendario
Calendario.Visible:=True;
Calendario.Date:=Date;
end;
procedure TFormCriarProjeto.CalendarioDblClick(Sender: TObject);
var
//Variáveis para calcular data
datacriacao,dataentrega:TDateTime;
begin
//edtEntrega pega data do calendário
edtentrega.text:=DateToStr(Calendario.Date);
//Esconde o calendario
Calendario.Visible:=False;
//Verificar data
datacriacao:=StrToDate(edtcriacao.text);
dataentrega:=StrToDate(edtentrega.Text);
//Exibe erro se a data de entrega estiver para um dia que já passou
if (datacriacao>dataentrega) then
begin
messagedlg('Impossível inserir uma data que já passou!',mterror,mbokcancel,0);
edtEntrega.Clear;
end
end;
end.