This repository has been archived by the owner on Aug 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
funcoesdetransferencia.pas
137 lines (117 loc) · 3.88 KB
/
funcoesdetransferencia.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
unit FuncoesDeTransferencia;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ComCtrls, variants;
var nomeContaDestino, dataNascContaDestino, cpfContaDestino, numeroContaDestino, saldoContaDestino :String;
function validaTranferencia(valor,agencia,conta :String):integer;
//function validaValor(valor : String):Integer;
function validaConta(conta : String): Integer;
function dadosContaDestino(conta:String):String;
function descontaValorTransferencia(valor, contaUsuario:String):Integer;
function somaValorTransferencia(valor, nContaDestino: String): Integer;
function salvaTransferencia(contaUsuario, contaDestino, valor: String):Integer;
function contaTransferencia: Integer;
implementation
uses conexaoDB, telaLogin, dadosUsuario, telaInicial, telaInseriNotas, FuncoesDeSaque, funcoes;
function validaTranferencia(valor, agencia, conta: String): integer;
begin
if (valor ='') OR (agencia ='') OR (conta='') then
Result:=0
else
begin
if(validaSaque(valor) = 5) AND (validaConta(conta) = 1) then
Result:=1
else
Result :=2;
end;
end;
function validaConta(conta: String): Integer;
var checarConta: String;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT idconta FROM conta WHERE idconta ='''+conta+'''';
DB.SQLQuery1.Open;
checarConta :=VarToStr(DB.SQLQuery1['idconta']);
DB.SQLQuery1.Close;
if checarConta = conta then
validaConta:=1;
except
On E:Exception do
falhaBanco();
end;
end;
function dadosContaDestino(conta :String): String;
begin
try
DB.SQLQuery1.SQL.Text:='select nome, datanasc, cpf, idconta, saldo FROM cartao JOIN cliente ON cartao.idcliente =cliente.idcliente JOIN conta ON conta.idconta = cartao.idcartao where idconta ='+conta+'';
DB.SQLQuery1.Open;
numeroContaDestino :=DB.SQLQuery1['idconta'];
nomeContaDestino:= DB.SQLQuery1['nome'];
dataNascContaDestino:= DB.SQLQuery1['datanasc'];
cpfContaDestino:= DB.SQLQuery1['cpf'];
saldoContaDestino:= DB.SQLQuery1['saldo'];
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function descontaValorTransferencia(valor, contaUsuario: String): Integer;
var saldoUp :Integer;
begin
saldoUp:= StrToInt(saldoUsuario) - StrToInt(valor);
try
DB.SQLQuery1.SQL.Text:='UPDATE conta SET saldo = '''+IntToStr(saldoUp)+''' WHERE idconta ='''+contaUsuario+'''';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function somaValorTransferencia(valor, nContaDestino: String): Integer;
var saldoUp :Integer;
begin
saldoUp:= StrToInt(saldoContaDestino) + StrToInt(valor);
try
DB.SQLQuery1.SQL.Text:='UPDATE conta SET saldo = '''+IntToStr(saldoUp)+''' WHERE idconta ='''+nContaDestino+'''';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
function salvaTransferencia(contaUsuario, contaDestino, valor: String):Integer;
begin
try
DB.SQLQuery1.SQL.Text:='INSERT INTO transferencia(idcontausuario, idcontadestino, valor, dataTrans, idCaixa) VALUES ('''+contaUsuario+''', '''+contaDestino+''', '''+valor+''', current_date, 1)';
DB.SQLTransaction1.Active:=false;
DB.SQLTransaction1.StartTransaction;
DB.SQLQuery1.ExecSQL;
DB.SQLTransaction1.Commit;
except
On E:Exception do
falhaBanco();
end;
end;
function contaTransferencia: Integer;
begin
try
DB.SQLQuery1.SQL.Text:='SELECT COUNT(*) AS trans FROM transferencia WHERE idcaixa = 1';
DB.SQLQuery1.Open;
contaTransferencia :=StrToInt(DB.SQLQuery1['trans']);
DB.SQLQuery1.Close;
except
On E:Exception do
falhaBanco();
end;
end;
end.