-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUBD.pas
More file actions
115 lines (100 loc) · 3.07 KB
/
Copy pathUBD.pas
File metadata and controls
115 lines (100 loc) · 3.07 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
unit UBD;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, PngBitBtn, ExtCtrls, IniFiles, pngimage;
type
TfrmBD = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
lstBanco: TListBox;
Assistente: TPngBitBtn;
btConectar: TPngBitBtn;
btSair: TPngBitBtn;
Image1: TImage;
procedure btSairClick(Sender: TObject);
procedure CarregaBanco;
procedure FormShow(Sender: TObject);
procedure ConectarBanco;
procedure btConectarClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure AssistenteClick(Sender: TObject);
procedure lstBancoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmBD: TfrmBD;
Arq : TIniFile;
implementation
uses UDados, UFuncoes, UAssistente;
{$R *.dfm}
procedure TfrmBD.AssistenteClick(Sender: TObject);
begin
AbreForm(TfrmAssistente, frmAssistente);
CarregaBanco;
end;
procedure TfrmBD.btConectarClick(Sender: TObject);
begin
ConectarBanco;
end;
procedure TfrmBD.btSairClick(Sender: TObject);
begin
if application.MessageBox('Deseja Realmente Sair do Sistema?', 'Confirmação', MB_YesNo + MB_IconQuestion) = idYes then begin
if dados.DB.Connected then begin
Dados.DB.CloseDataSets;
dados.DB.Close;
end;
application.Terminate;
end;
end;
procedure TfrmBD.CarregaBanco;
begin
//procedimento para ler todos os bancos de dados cadastrados no arquivo de inicilização
lstBanco.Items.Clear;
Arq := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Sistema.ini');
Arq.ReadSection('Banco', lstBanco.Items);
Arq.Free;
end;
procedure TfrmBD.ConectarBanco;
begin
//Procedimento para conectar a banco de dados do sistema
try
Arq := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Sistema.ini');
dados.DB.Close;
Dados.DB.Params.Values['DATABASE'] := Arq.ReadString('Banco', lstBanco.Items.Strings[lstBanco.ItemIndex], 'C:\InforCENTER\Banco\SISCOFI.gdb');
Dados.DB.Params.Values['USERNAME'] := 'SYSDBA';
Dados.DB.Params.Values['PASSWORD'] := 'masterkey';
dados.DB.Open;
close;
except on E : Exception do begin
application.MessageBox(PChar('Erro ao Conectar o Banco de dados' + e.Message),'Atenção', MB_IconError);
end;
end;
end;
procedure TfrmBD.FormClose(Sender: TObject; var Action: TCloseAction);
begin
release;
end;
procedure TfrmBD.FormShow(Sender: TObject);
begin
CarregaBanco;
end;
procedure TfrmBD.lstBancoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_DELETE then begin
if application.MessageBox('Deseja Realmente Excluir Configurações do Banco de Dados?', 'Confirmação', MB_YesNo + MB_IconQuestion) = idYes then begin
Arq := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Sistema.ini');
Arq.DeleteKey('Banco', lstBanco.Items[lstBanco.ItemIndex]);
Arq.Free;
CarregaBanco;
end;
end;
end;
end.