PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Base #498895

23/10/2014

0

Pessoal, Sou iniciante no delphi e estou desenvolvendo uma aplicação Windows Form para cadastro de artigo, bem básico, gravando os dados no Sql Server 2008. A parte de inserção e exclusão está Ok, mas não estou conseguindo fazer com que o botão "Alterar" funcione, segue o fonte: #Código

Esse é o fonte..

Eu faco uma pesquisa de um artigo e quando clico no botão alterar para alterar o artigo, aparece o forma de cadastro de artigo mas sem o artigo que quero alterar.

unit UPrincipal;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, JvExComCtrls,
JvPageListTreeView, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Mask,
Vcl.Grids, Vcl.DBGrids, Vcl.Buttons, Vcl.ImgList,DB, Vcl.CheckLst,Data.Win.ADODB,
Web.HTTPApp, Wwdbigrd, Wwdbgrid, JvExControls, JvLabel;

type
TfrmPrincipal = class(TForm)
PnlCategorias: TPanel;
pnlTop: TPanel;
Timer1: TTimer;
dsPesquisar: TDataSource;
pnlPesquisa: TPanel;
Panel1: TPanel;
btnVisualizar: TBitBtn;
pnlPesquisar: TPanel;
edtPesquisar: TEdit;
wwDBGrid1: TwwDBGrid;
Panel3: TPanel;
JvLabel1: TJvLabel;
JvLabel2: TJvLabel;
jvlblUsuario: TJvLabel;
jvlblData: TJvLabel;
jvlblHora: TJvLabel;
jvlblCopyright: TJvLabel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
btnAreas: TSpeedButton;
btnNovoArtigo: TSpeedButton;
btnNovaCategoria: TSpeedButton;
btnUsuario: TSpeedButton;
chklstCategoria: TCheckListBox;
chklstArea: TCheckListBox;
pnlÁreas: TPanel;
Bevel1: TBevel;
JvLabel3: TJvLabel;
pnlCateg: TPanel;
JvLabel4: TJvLabel;
pnlAdm: TPanel;
JvLabel5: TJvLabel;
Splitter1: TSplitter;
Bevel3: TBevel;
Bevel2: TBevel;
btnFechar: TBitBtn;
btnAlterar: TBitBtn;
btnExcluir: TBitBtn;
procedure Timer1Timer(Sender: TObject);
procedure btnAreasClick(Sender: TObject);
procedure btnNovaCategoriaClick(Sender: TObject);
procedure btnUsuarioClick(Sender: TObject);
procedure btnNovoArtigoClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CheckListBox1Click(Sender: TObject);
procedure CheckListBox2Click(Sender: TObject);
procedure edtPesquisarKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure btnVisualizarClick(Sender: TObject);
procedure edtPesquisarEnter(Sender: TObject);
procedure edtPesquisarExit(Sender: TObject);
procedure btnFecharClick(Sender: TObject);
procedure btnExcluirClick(Sender: TObject);
procedure btnAlterarClick(Sender: TObject);



private
{ Private declarations }
procedure ExecutaPesquisa;
public
{ Public declarations }
end;

var
frmPrincipal: TfrmPrincipal;

implementation

{$R *.dfm}

uses Udm,UMatriz,UCadArea,UCadCategoria,UCadUsuario,UCadArtigo,Area,Categoria,
ULogin, UVisualizarArtigo,Util;

procedure TfrmPrincipal.ExecutaPesquisa;
var
i: Integer;
obj: TArea;
obje: TCategoria;

FPesquisaTxt, FAreas, FCategorias: string;
begin
// Executa as pesquisas --
if (Trim(edtPesquisar.Text) = 'Pesquisar') then
FPesquisaTxt := ''
else
FPesquisaTxt := Trim(edtPesquisar.Text);

// Areas --
FAreas := '';
for i := 0 to chklstArea.Items.Count -1 do
if chklstArea.Checked[i] then
begin
obj := TArea(chklstArea.Items.Objects[i]);
FAreas := FAreas + IntToStr(obj.AreaID) + ',';
end;
FAreas := Copy(FAreas, 1, Length(FAreas) -1);

// Categorias --
FCategorias := '';
for i := 0 to chklstCategoria.Items.Count -1 do
if chklstCategoria.Checked[i] then
begin
obje := TCategoria(chklstCategoria.Items.Objects[i]);
FCategorias := FCategorias + IntToStr(obje.CategoriaID) + ',';
end;
FCategorias := Copy(FCategorias, 1, Length(FCategorias) -1);

//--

DM.PesquisaArtigo(FPesquisaTxt, FAreas, FCategorias);
end;

procedure TfrmPrincipal.btnAlterarClick(Sender: TObject);
begin
if DM.qryPesquisar.IsEmpty then
BEGIN
DM.qryArtigo.Edit;
DM.qryArtigoArtigoID.AsInteger :=
DM.qryArtigo.FieldByName('ArtigoID').AsInteger;

end;

DM.VisualizarArtigo;

Application.CreateForm(TfrmCadArtigo,frmCadArtigo);
frmCadArtigo.ShowModal;
FreeAndNil(frmCadArtigo);
end;

procedure TfrmPrincipal.btnAreasClick(Sender: TObject);
begin
if (Trim(DM.UsuarioNome) = '') then
if not TfrmLogin.Execute then
Exit;

Application.CreateForm(TfrmCadArea,frmCadArea);
frmCadArea.ShowModal;
FreeAndNil(frmCadArea);
end;

procedure TfrmPrincipal.btnNovoArtigoClick(Sender: TObject);
begin
if (Trim(DM.UsuarioNome) = '') then
if not TfrmLogin.Execute then
Exit;

Application.CreateForm(TfrmCadArtigo,frmCadArtigo);
frmCadArtigo.ShowModal;
FreeAndNil(frmCadArtigo);
end;

procedure TfrmPrincipal.btnExcluirClick(Sender: TObject);
begin
if MessageDlg('Deseja Excluir o Registro', mtconfirmation, [mbYes, mbNo], 0) = mrYes then
Dm.qryPesquisar.Delete;

Application.CreateForm(TfrmCadArtigo,frmCadArtigo);
frmCadArtigo.ShowModal;
FreeAndNil(frmCadArtigo);
end;

procedure TfrmPrincipal.btnFecharClick(Sender: TObject);
begin
if MessageDlg('Deseja fechar a aplicação?', mtConfirmation,[mbYes, mbNo], 0) = mrYes then
Application.Terminate;
end;

procedure TfrmPrincipal.btnNovaCategoriaClick(Sender: TObject);
begin
if (Trim(DM.UsuarioNome) = '') then
if not TfrmLogin.Execute then
Exit;

Application.CreateForm(TfrmCadCategoria,frmCadCategoria);
frmCadCategoria.ShowModal;
FreeAndNil(frmCadCategoria);
end;

procedure TfrmPrincipal.btnUsuarioClick(Sender: TObject);
begin
if (Trim(DM.UsuarioNome) = '') then
if not TfrmLogin.Execute then
Exit;

if (Trim(DM.UsuarioAdmin) <> 'S') then
raise Exception.Create('Acesso não autorizado.' + #13 +
'Consulte o Administrador do sistema.');

Application.CreateForm(TfrmCadUsuario,frmCadUsuario);
frmCadUsuario.ShowModal;
FreeAndNil(frmCadUsuario);
end;

procedure TfrmPrincipal.btnVisualizarClick(Sender: TObject);
begin
if DM.qryPesquisar.IsEmpty then
begin
DM.Msg('Nenhum artigo foi selecionado', mtWarning);
Exit;
end;

DM.VisualizarArtigo;

Application.CreateForm(TFrmVisualizarArtigo, FrmVisualizarArtigo);
FrmVisualizarArtigo.ShowModal;
FreeAndNil(FrmVisualizarArtigo);

TADOQuery(dsPesquisar.DataSet).Requery();
end;

procedure TfrmPrincipal.CheckListBox1Click(Sender: TObject);
begin
ExecutaPesquisa;
end;

procedure TfrmPrincipal.CheckListBox2Click(Sender: TObject);
begin
ExecutaPesquisa;
end;

procedure TfrmPrincipal.edtPesquisarEnter(Sender: TObject);
begin
edtPesquisar.Text := '';
end;

procedure TfrmPrincipal.edtPesquisarExit(Sender: TObject);
begin
if (Trim(edtPesquisar.Text) = '') then
edtPesquisar.Text := 'Pesquisar';
end;

procedure TfrmPrincipal.edtPesquisarKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_RETURN) then
begin
Key := 0;
ExecutaPesquisa;
end;
end;

procedure TfrmPrincipal.FormCreate(Sender: TObject);
begin
DM.MontaArea(chklstArea);
Dm.MontaCategoria(chklstCategoria);

jvlblUsuario.Caption := 'Usuário Logado: ...';
jvlblData.Caption := '';
jvlblHora.Caption := '';
end;

procedure TfrmPrincipal.Timer1Timer(Sender: TObject);
begin
jvlblData.Caption := ' Hoje é ' + FormatDateTime ('dddd", "dd" de "mmmm" de "yyyy' ,Now);
jvlblHora.Caption := ' Hora: ' + FormatDateTime('hh:nn:ss',now);
end;



end.



Estou no aguardo de alguem para me ajudar...
Silmar Araujo

Silmar Araujo

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar