Hello please i confuse how i can validate not duplicate records, My intentions is when capture inventory counting put that on MemDataSet and not send directly Main Data base of mysql, I using EBitButton to capture the product id and Dataset on post i trigger event onBeforepost to validate but event is trigger two time not only one as must be, how i can do validateand trigger event only once...
This my code onExitEditButton
procedure TFormCtrlInv.EBProdExit(Sender: TObject);
var Tsql:TsqlQuery;
RowId:Integer;
begin
Tsql:= TsqlQuery.Create(nil);
Tsql.Database:= DM.MySQLCOpti;
Tsql.Transaction:= DM.SQLTopti;
;
if( EBprod.Text<>'') Then begin
RowId:=MDInvFis.FieldByName('RowId').AsInteger ;
// if( ValidaCapProd(EBprod.Text, RowId)='N' ) then begin
Tsql.sql.Text:='select * from productos where numprod=:pprod';
Tsql.ParamByName('pprod').AsString := EBprod.Text;
Tsql.Open;
if( (not Tsql.EOF) ) then begin
MDInvFis.Edit;
MDInvFis.FieldByName('NumProd').AsString := EBProd.Text;
MDInvFis.FieldByName('NomProd').AsString := tsql.FieldByName('NomProd').AsString;
MDInvFis.FieldByName('Existencia').AsFloat := tsql.FieldByName('Existencia').AsFloat;
MDInvFis.FieldByName('fecha').AsDateTime := Now;
EBProd.Text:='';
MDInvFis.Post;
EBProd.Visible:=false;
DbGInvFis.SelectedIndex:=3;
end else begin
MDInvFis.RecNo:=RowId;
ShowMessage('Producto no registrado , Teclee una clave de producto correcta');
EBProd.SetFocus;
end;
// end else begin
// ShowMessage('Producto ya contado , Teclee una clave de producto correcta');
// EBProd.Visible:=false;
// EBProd.text:='';
// DbGInvFis.SelectedIndex:=1;
// end;
end ;
DbGInvFis.SetFocus;
end;
this my code for event onBeforePost
procedure TFormCtrlInv.MDinvFisBeforePost(DataSet: TDataSet);
begin
if( (EBProd.Text<>'') and (DBGInvFis.SelectedIndex=0 ) ) then begin
if (MDInvFis.Locate('Numprod', EBProd.Text, [])) then begin
ShowMessage('Producto ya contado, Mofique su cantidad para afectar la aexistencia');
MDInvFis.Cancel;
// EBProd.Text:='';
// EBProd.Visible:=false;
// DbGInvFis.SelectedIndex:=3;
end;
end;
end;
Any help or Idea could be Great help...