Recent

Author Topic: MemDataset validate not duplicate record  (Read 492 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 443
MemDataset validate not duplicate record
« on: May 28, 2023, 07:02:49 pm »
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
Code: Pascal  [Select][+][-]
  1. procedure TFormCtrlInv.EBProdExit(Sender: TObject);
  2. var Tsql:TsqlQuery;
  3.     RowId:Integer;
  4. begin
  5.   Tsql:= TsqlQuery.Create(nil);
  6.   Tsql.Database:= DM.MySQLCOpti;
  7.   Tsql.Transaction:= DM.SQLTopti;
  8.  ;
  9.   if( EBprod.Text<>'') Then begin
  10.        RowId:=MDInvFis.FieldByName('RowId').AsInteger   ;
  11. //     if( ValidaCapProd(EBprod.Text, RowId)='N' ) then begin
  12.        Tsql.sql.Text:='select * from productos where numprod=:pprod';
  13.        Tsql.ParamByName('pprod').AsString := EBprod.Text;
  14.        Tsql.Open;
  15.       if( (not Tsql.EOF)  ) then begin
  16.         MDInvFis.Edit;
  17.         MDInvFis.FieldByName('NumProd').AsString := EBProd.Text;
  18.         MDInvFis.FieldByName('NomProd').AsString := tsql.FieldByName('NomProd').AsString;
  19.         MDInvFis.FieldByName('Existencia').AsFloat := tsql.FieldByName('Existencia').AsFloat;
  20.         MDInvFis.FieldByName('fecha').AsDateTime  := Now;
  21.         EBProd.Text:='';
  22.         MDInvFis.Post;
  23.         EBProd.Visible:=false;
  24.         DbGInvFis.SelectedIndex:=3;
  25.       end else begin
  26.         MDInvFis.RecNo:=RowId;
  27.         ShowMessage('Producto no registrado , Teclee una clave de producto correcta');
  28.         EBProd.SetFocus;
  29.       end;
  30. //    end  else begin
  31. //      ShowMessage('Producto ya contado , Teclee una clave de producto correcta');
  32. //      EBProd.Visible:=false;
  33. //      EBProd.text:='';
  34. //      DbGInvFis.SelectedIndex:=1;
  35. //  end;
  36.  
  37.   end ;
  38.   DbGInvFis.SetFocus;
  39. end;
  40.  
  41.  
   

this my code for event onBeforePost
Code: Pascal  [Select][+][-]
  1. procedure TFormCtrlInv.MDinvFisBeforePost(DataSet: TDataSet);
  2. begin
  3.   if( (EBProd.Text<>'') and (DBGInvFis.SelectedIndex=0 ) ) then begin
  4.     if (MDInvFis.Locate('Numprod', EBProd.Text, [])) then begin
  5.         ShowMessage('Producto ya contado, Mofique su cantidad para afectar la aexistencia');
  6.         MDInvFis.Cancel;
  7. //        EBProd.Text:='';
  8. //        EBProd.Visible:=false;
  9. //        DbGInvFis.SelectedIndex:=3;
  10.     end;
  11.   end;
  12. end;
  13.  
  14.  

Any help or Idea could be Great help...

 

TinyPortal © 2005-2018