Skip to content

Commit

Permalink
Última aula 15122020(DB Mestre Detalhe) inserida
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusschwede committed Dec 17, 2020
1 parent 7bb7276 commit 03539ac
Show file tree
Hide file tree
Showing 24 changed files with 8,042 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,003 changes: 1,003 additions & 0 deletions rad/15122020 (DB Mestre Detalhe)/Loja/Fontes/uClientes.dfm

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions rad/15122020 (DB Mestre Detalhe)/Loja/Fontes/uClientes.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
unit uClientes;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uDM, Data.DB, Vcl.ExtCtrls, Vcl.DBCtrls,
Vcl.Grids, Vcl.DBGrids, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxContainer, cxEdit, Vcl.StdCtrls, Vcl.Buttons,
cxTextEdit, cxDBEdit;

type
TfrmClientes = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
cxDBTextEdit1: TcxDBTextEdit;
Label3: TLabel;
cxDBTextEdit2: TcxDBTextEdit;
Label4: TLabel;
cxDBTextEdit3: TcxDBTextEdit;
Label5: TLabel;
cxDBTextEdit4: TcxDBTextEdit;
Label6: TLabel;
cxDBTextEdit5: TcxDBTextEdit;
Label7: TLabel;
cxDBTextEdit6: TcxDBTextEdit;
Panel2: TPanel;
btInserir: TBitBtn;
DBNavigator1: TDBNavigator;
btExcluir: TBitBtn;
btEditar: TBitBtn;
btCancelar: TBitBtn;
btConfirmar: TBitBtn;
btSair: TBitBtn;
DBText1: TDBText;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btInserirClick(Sender: TObject);
procedure btEditarClick(Sender: TObject);
procedure btCancelarClick(Sender: TObject);
procedure btConfirmarClick(Sender: TObject);
procedure btExcluirClick(Sender: TObject);
procedure btSairClick(Sender: TObject);
private
{ Private declarations }
Procedure TrataBotoes;
public
{ Public declarations }
end;

var
frmClientes: TfrmClientes;

implementation

{$R *.dfm}

procedure TfrmClientes.btCancelarClick(Sender: TObject);
begin
dm.tbClientes.Cancel;
TrataBotoes;
end;

procedure TfrmClientes.btConfirmarClick(Sender: TObject);
begin
// Regras de validação
if dm.tbClientes.FieldByName('DCCLIENTE').AsString = '' then
begin
MessageDlg('Falta digitar o nome do cliente',
mtWarning, [mbOk], 0);
cxDBTextEdit1.SetFocus;
Exit;
end;

dm.tbClientes.Post;
TrataBotoes;
end;

procedure TfrmClientes.btEditarClick(Sender: TObject);
begin
TrataBotoes;
dm.tbClientes.Edit;
end;

procedure TfrmClientes.btExcluirClick(Sender: TObject);
begin
if MessageDlg('Deseja realmente excluir?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes
then
Dm.tbClientes.Delete;

end;

procedure TfrmClientes.btInserirClick(Sender: TObject);
var
prox:integer;
begin
TrataBotoes;

Dm.tbClientes.Last; //Posiciona no último registro
prox := Dm.tbClientes.FieldByName('cdcliente').asInteger + 1;

Dm.tbClientes.Append; //Insere no final da tabela
Dm.tbClientes.fieldbyname('cdcliente').asinteger := prox;

cxDBTextEdit1.SetFocus;
end;
procedure TfrmClientes.btSairClick(Sender: TObject);
begin
if dm.tbClientes.State IN [dsInsert, dsEdit] then
begin
MessageDlg('Cancele ou confirme a operação', mtWarning,
[mbOk], 0);
Exit;
end;

Close;
end;

procedure TfrmClientes.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//dm.tbClientes.Active := False;

dm.tbClientes.Close;
end;

procedure TfrmClientes.FormShow(Sender: TObject);
begin
//dm.tbClientes.Active := True;

dm.tbClientes.Open;
end;

procedure TfrmClientes.TrataBotoes;
begin

btInserir.enabled := not BtInserir.enabled;
btEditar.enabled := not BtEditar.enabled;
btExcluir.enabled := not BtExcluir.enabled;
btConfirmar.enabled := not btConfirmar.enabled;
BtCancelar.enabled := not BtCancelar.enabled;

DBNavigator1.Enabled := not DBNavigator1.Enabled;
end;

end.
Expand Down
127 changes: 127 additions & 0 deletions rad/15122020 (DB Mestre Detalhe)/Loja/Fontes/uConsulta.dfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
object frmPesquisar: TfrmPesquisar
Left = 0
Top = 0
Caption = 'Pesquisar'
ClientHeight = 289
ClientWidth = 718
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 96
TextHeight = 13
object Tabela: TLabel
Left = 160
Top = 21
Width = 32
Height = 13
Caption = 'Tabela'
end
object rgSel: TRadioGroup
Left = 8
Top = 8
Width = 137
Height = 105
Caption = ' Selecionar por '
ItemIndex = 0
Items.Strings = (
'C'#243'digo'
'Descri'#231#227'o')
TabOrder = 0
end
object rgOrdem: TRadioGroup
Left = 8
Top = 119
Width = 137
Height = 105
Caption = 'Ordem da apresenta'#231#227'o'
ItemIndex = 0
Items.Strings = (
'Normal'
'Ascendente'
'Descendente')
TabOrder = 1
end
object edBusca: TEdit
Left = 8
Top = 230
Width = 137
Height = 21
TabOrder = 2
end
object btSel: TBitBtn
Left = 8
Top = 257
Width = 137
Height = 25
Caption = 'Pesquisar'
Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000020000
000A000000160000001B000000170000000B0000000200000000000000010000
00060000000B0000000F0000000C0000000600000001000000000000000F2616
1072583424D8693D2AFF4D2C1FD91D110B750000001200000003000000082416
1162513023CF613927FF45281BD01A0F0A630000000900000001291A136DA380
70FFD4C5BDFFEDE5E1FFCFBEB7FF907163FF1F120C770000000F2C1C1663A181
72FFD4C6BEFFEEE8E4FFCDC0B8FF866A5DFF190E096000000005734937DEE3D7
D1FFCEAE9EFFAF7957FFD0B39EFFD7C9C3FF553324E00000001B77503FD8E2D7
D2FFD0AD9BFFB37753FFD2B29AFFD6CBC5FF4A2B1ED90000000A8E5A47FBF8F6
F4FFAE725BFFE7AF66FFB27F5EFFF0EBE8FF744835FF000000489A6B55FFF8F6
F3FFB27056FFE8AF64FFB67E59FFEAE3DFFF613B29FA0000000B90604DF8F1E8
E4FFD2B0A5FFAA6C53FFD4B6A7FFCDC0BAFF71422FFF4C2920FF80513DFFF1E8
E3FFD3ADA1FFAE684FFFD4B2A1FFC5B6AFFF6A4231F700000009583C31A2CAAF
A3FFF7F2EEFFFDFCFBFFEAE0DAFF9E847AFF774835FF663E36FF855944FFE8D9
CFFFF7F0EDFFFCFAF9FFDFD4CEFF8A6657FF452D229A000000050805041D9F72
5DF8E8DBD4FFE6D7CEFFCDB7AAFF8B6B5EFF7D4C3AFF865F56FF8B5F4BFFE9D8
CEFFEADCD4FFCFB9ACFF997B6DFF966A54F70705041600000001000000076047
3BA4D0B7ADFFEEE3DFFFD5C1B7FF93766CFF82533FFF734635FF926550FFECE0
D9FFEBDED8FFC4B0A5FF9B7868FF5F45389D0000000400000000000000022219
1541B89383FFF3EBE8FFD9C9C2FFA99389FFA67966FF00000026B48B76FFF0E7
E3FFEADED9FFBDA79FFFA67D6CFF211915390000000100000000000000000000
0007846554C6DDCCC4FFE6DCD8FFC2A99EFFA67E69F90000000CB38E79F8E0D1
C9FFE9DFDAFFBCA497FF846555C2000000030000000000000000000000000000
0002130F0D237D6152B7AF8673FA7B6050B9130E0C270000000414100E1E8365
58B3B68F79F9806455B3130F0D1E000000010000000000000000000000000000
0000000000010000000400000006000000050000000200000000000000000000
0001000000010000000100000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000}
Layout = blGlyphRight
TabOrder = 3
OnClick = btSelClick
end
object DBGrid1: TDBGrid
Left = 160
Top = 40
Width = 550
Height = 242
DataSource = dm.dsConsulta
TabOrder = 4
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object cmbTabela: TComboBox
Left = 198
Top = 13
Width = 145
Height = 21
Style = csDropDownList
Sorted = True
TabOrder = 5
Items.Strings = (
'Clientes'
'Fornecedores'
'Produtos')
end
end
104 changes: 104 additions & 0 deletions rad/15122020 (DB Mestre Detalhe)/Loja/Fontes/uConsulta.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
unit uConsulta;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls,
Data.DB, Vcl.Grids, Vcl.DBGrids, uDM;

type
TfrmPesquisar = class(TForm)
rgSel: TRadioGroup;
rgOrdem: TRadioGroup;
edBusca: TEdit;
btSel: TBitBtn;
DBGrid1: TDBGrid;
cmbTabela: TComboBox;
Tabela: TLabel;
procedure btSelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmPesquisar: TfrmPesquisar;

implementation

{$R *.dfm}

procedure TfrmPesquisar.btSelClick(Sender: TObject);
var nmTab, vSQL : string;

function RetCampoCodigo(aTab:string) : string;
begin
if aTab = 'CLIENTES' then
Result := 'CDCLIENTE'
else
if aTab = 'FORNECEDORES' then
Result := 'CDFORNECEDOR'
else
if aTab = 'PRODUTOS' then
Result := 'CDPRODUTO'
end;

function RetCampoDesc(aTab:string) : string;
begin
if aTab = 'CLIENTES' then
Result := 'DCCLIENTE'
else
if aTab = 'FORNECEDORES' then
Result := 'DCFORNECEDOR'
else
if aTab = 'PRODUTOS' then
Result := 'DCPRODUTO'
end;

begin
nmTab := '';

if cmbTabela.ItemIndex = -1 then
begin
MessageDlg('Selecione uma tabela', mtError, [mbOk],0);
Exit;
end;

if edBusca.Text = '' then
begin
MessageDlg('Digite algum valor', mtWarning, [mbOk],0);
Exit;
end;

case cmbTabela.ItemIndex of
0 : nmTab := 'CLIENTES';
1 : nmTab := 'FORNECEDORES';
2 : nmTab := 'PRODUTOS';
end;

vSQL := 'SELECT * FROM ' + nmTab;

case rgSel.ItemIndex of // #13 ======= ENTER - Trocar de linha
0 : vSQL := vSQL + #13 + ' WHERE ' + RetCampoCodigo(nmTab) + ' = :PCD';
1 : vSQL := vSQL + #13 + ' WHERE ' + RetCampoDesc(nmTab) + ' CONTAINING :PCD';
end;

case rgOrdem.ItemIndex of
1 : vSQL := vSQL + #13 + ' ORDER BY ' + RetCampoCodigo(nmTab) + ' ASC '; //ASC opcional
2 : vSQL := vSQL + #13 + ' ORDER BY ' + RetCampoCodigo(nmTab) + ' DESC ';
end;

dm.qrConsulta.Close;
dm.qrConsulta.SQL.Text := vSQL;
dm.qrConsulta.ParamByName('PCD').AsString := edBusca.Text;
dm.qrConsulta.Open;

if dm.qrConsulta.IsEmpty then
begin
MessageDlg('Nenhum resultado encontrado', mtInformation, [mbOk], 0);
end;
end;

end.
Loading

0 comments on commit 03539ac

Please sign in to comment.