Condicao num DbEdit
20/09/2004
0
Se o campo curso(dbedit) for ´anual´ DbEdit10(Campo Preco) = 50,00;
se for ´Semestral´ DbEdit10(Campo Preco) = 60,00
Se for ´Supletivo´ DbEdit10(Campo Preco) = 70,00
gostaria que ficasse gravado na tabela, para quando for colocar um qrdbtext com o campo ´preco´ no quickReport apareça o valor correspondente ao campo, e quando eu mudar o campo curso no banco de dados, o preço mude automaticamente.
Obs.: Estou usando AdoQuery no dataModule!!!!!
Grato,
Antecipadamente,
Adriano.
Xadriano
Posts
20/09/2004
Bruno Belchior
procedure Orderar
begin
&&& case DBEditCurso.Text of
&& &&&& ´Anual´:
DataModule1.ADOQuery1Preco := 50;
&& &&&& ´Semestral´:
DataModule1.ADOQuery1Preco := 60;
&& &&&& ´Supletivo´:
DataModule1.ADOQuery1Preco := 50;
&&& else
&& &&&& ShowMessage(´Valor
Informado Inválido!!!´);
&&& end;
end;
20/09/2004
Bruno Belchior
procedure Orderar
begin
case DBEditCurso.Text of
´Anual´: DataModule1.ADOQuery1Preco := 50;
´Semestral´: DataModule1.ADOQuery1Preco := 60;
´Supletivo´: DataModule1.ADOQuery1Preco := 50;
else
ShowMessage(´Valor Informado Inválido!!!´);
end;
end;
21/09/2004
Xadriano
procedure TForm1.DBEdit3Exit(Sender: TObject);
begin
procedure ordenar
Begin
Case DbEdit3.Text of
´Anual´:ADOTable1Preco:= 50;
´Semestral´:ADOTable1Preco:= 60;
´Supletivo´:ADOTable1Preco:= 70;
Else
ShowMessage(´Valor Invalido´);
end;
end;
está dando varios erros ao compilar:
[Error] Unit1.pas(42): Statement expected but ´PROCEDURE´ found
[Error] Unit1.pas(43): ´;´ expected but ´BEGIN´ found
[Error] Unit1.pas(44): Undeclared identifier: ´DbEdit3´
[Error] Unit1.pas(44): ´(´ expected but ´OF´ found
[Error] Unit1.pas(45): Missing operator or semicolon
[Error] Unit1.pas(46): Duplicate case label
[Error] Unit1.pas(47): Duplicate case label
[Fatal Error] Project1.dpr(5): Could not compile used unit ´Unit1.pas´
o que estou errando?
21/09/2004
Martins
Existem (N) maneiras de se fazer isso, vejamos algumas:
1 - Utilizando rapidinho Edit para fazer testes
[b:4324fd5e2e]Componentes[/b:4324fd5e2e] Dois Edit´s e Button.
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin key:=0; If Edit1.Text=´ANUAL´ then Edit2.Text:=´50,00´ else If Edit1.Text=´SEMESTRAL´ then Edit2.Text:=´60,00´ else if Edit1.Text=´SUPLETIVO´ then Edit2.Text:=´70,00´ else ShowMessage(´convênio não consta na tabela´); exit; end; end;
Ops! tenho q sair agora, mas vc poderia fazer isso usando DBLoockcomboBox eu acho, utilizando uma tabela, mas se o padrão for esses três itens, faça assim é mais fácil.
T+
21/09/2004
Bruno Belchior
//------------------------
Case DbEdit3.Text of
´Anual´: DataModule1.ADOTable1Preco:= 50;
´Semestral´: DataModule1.ADOTable1Preco:= 60;
´Supletivo´: DataModule1.ADOTable1Preco:= 70;
Else
ShowMessage(´Valor Invalido´);
//------------------------
mas lembre-se, esse código leva em conta que se DataModule chame-se DataModule1, sua Tabela ou Query chame-se ADOTable1, e seu campo de preço chame-se Preco
21/09/2004
Xadriano
procedure TForm1.DBEdit3Exit(Sender: TObject);
begin
Case DbEdit3.Text of
´Anual´: ADOTable1Preco:= 50;
´Semestral´: ADOTable1Preco:= 60;
´Supletivo´: ADOTable1Preco:= 70;
Else
ShowMessage(´Valor Invalido´);
end;
end;
e está dando os seguintes Erros:
[Error] Unit1.pas(43): Ordinal type required
[Error] Unit1.pas(44): Incompatible types: ´Integer´ and ´String´
[Error] Unit1.pas(44): Incompatible types: ´TBCDField´ and ´Integer´
[Error] Unit1.pas(45): Incompatible types: ´Integer´ and ´String´
[Error] Unit1.pas(45): Incompatible types: ´TBCDField´ and ´Integer´
[Error] Unit1.pas(46): Incompatible types: ´Integer´ and ´String´
[Error] Unit1.pas(46): Incompatible types: ´TBCDField´ and ´Integer´
[Fatal Error] Project1.dpr(5): Could not compile used unit ´Unit1.pas´
21/09/2004
Bruno Belchior
22/09/2004
Martins
vc poderia testar da forma como descrita abaixo e ver se funciona, qualquer diculdade estaremos aqui para enxugar seu código.
T+
22/09/2004
Martins
vc teria q mudar um pouco seu projeto, pois as vezes q trabalhei com CASE OF... utilizei valores como [color=red:29179c2e3f]word; byte; integer[/color:29179c2e3f]
nunca consegui utilizá-la com String ou algo do tipo... claro q este é só um comentário particular...
tente assim:
procedure ordenar Begin Case StrToInt(DbEdit3.Text) of 1:ADOTable1Preco:= 50; // Anual 2:ADOTable1Preco:= 60; // Semestral 3:ADOTable1Preco:= 70; // Supletivo Else ShowMessage(´Valor Invalido´); end;
vc só teria q montar uma pequena legenda, deu para entender?
Espero q possa lhe ser útil.
Até a próxima...
22/09/2004
Xadriano
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls, Mask, DBCtrls, ADODB, ExtCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable1Codigo: TWideStringField;
ADOTable1Nome: TWideStringField;
ADOTable1Curso: TWideStringField;
ADOTable1Preco: TBCDField;
Label1: TLabel;
DBEdit1: TDBEdit;
DataSource1: TDataSource;
Label2: TLabel;
DBEdit2: TDBEdit;
Label3: TLabel;
DBEdit3: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
DBNavigator1: TDBNavigator;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
22/09/2004
Bruno Belchior
if (DbEdit3.Text = ´Anual´) then ADOTable1Preco.AsString := ´50´ else if (DbEdit3.Text = ´Anual´) then ADOTable1Preco.AsString:= ´60´ else if (DbEdit3.Text = ´Anual´) then ADOTable1Preco.AsString:= ´70´;
Clique aqui para fazer login e interagir na Comunidade :)