Jump to content

Problem with refresh uniDBGrid


apicito

Recommended Posts

In a uniDBGrid I list a table records with calculate fields.

With this code I create new form for edit one Record:

procedure TAveriasFrame.GridExptesDblClick(Sender: TObject);
var AveriasExpteEdit : TAveriasExpteEdit;
begin
  AveriasExpteEdit := TAveriasExpteEdit.Create(UniApplication);
  AveriasExpteEdit.Codigo := Codigo;
  AveriasExpteEdit.Modo := Modo;
  AveriasExpteEdit.ShowModal(
    procedure(Result : integer) begin
      if Result = 1 then begin
        cdsExpte.Refresh;
      end;
    end
  );
end;

When I save changes and applyupdates in AveriasExpteEdit form and return to form with grid not refresh the Grid. But if I reload page or put 2 times "cdsExpte.Refresh;" it's work fine.

      if Result = 1 then begin
        cdsExpte.Refresh;
        cdsExpte.Refresh;
      end;

Can anyboby hel me with this problem.

Thanks.

Link to comment
Share on other sites

This is the unit:

unit uAveriasExpteEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIForm, Data.FMTBcd, Data.DB, Datasnap.DBClient,
  Datasnap.Provider, Data.SqlExpr, uniEdit, uniDBEdit, uniGUIBaseClasses,
  uniMultiItem, uniComboBox, uniDBComboBox, uniDBLookupComboBox, uniButton,
  uniMemo, uniDBMemo, uniLabel, uniPanel;

type
  TAveriasExpteEdit = class(TUniForm)
    QueryTipo: TSQLQuery;
    dspTipo: TDataSetProvider;
    cdsTipo: TClientDataSet;
    LargeintField4: TLargeintField;
    StringField4: TStringField;
    surceTipo: TDataSource;
    queryZona: TSQLQuery;
    dspZona: TDataSetProvider;
    cdsZona: TClientDataSet;
    LargeintField11: TLargeintField;
    StringField11: TStringField;
    surceZona: TDataSource;
    surceEstado: TDataSource;
    cdsEstado: TClientDataSet;
    LargeintField18: TLargeintField;
    StringField18: TStringField;
    dspEstado: TDataSetProvider;
    queryEstado: TSQLQuery;
    queryExpte: TSQLQuery;
    dspExpte: TDataSetProvider;
    cdsExpte: TClientDataSet;
    cdsExpteAVEDIA_CODIGO: TLargeintField;
    cdsExpteAVEDIA_TIPO: TLargeintField;
    cdsExpteAVEDIA_ZONA: TLargeintField;
    cdsExpteAVEDIA_ESTADO: TLargeintField;
    cdsExpteAVEDIA_ASIGNADO: TStringField;
    cdsExpteAVEDIA_LOCALIZACION: TStringField;
    cdsExpteAVEDIA_DESCRIP: TStringField;
    cdsExpteAVEDIA_TER_DNI: TStringField;
    cdsExpteAVEDIA_TER_DNI_DUP: TFMTBCDField;
    cdsExpteAVEDIA_TER_NOME: TStringField;
    cdsExpteAVEDIA_TER_ENDEREZO: TStringField;
    cdsExpteAVEDIA_TER_POBO: TStringField;
    cdsExpteAVEDIA_TER_TLNO: TStringField;
    cdsExpteAVEDIA_TER_EMAIL: TStringField;
    cdsExpteAVEDIA_TER_NOTIFICACION: TFMTBCDField;
    cdsExpteAVEDIA_A_USUARIO: TStringField;
    cdsExpteAVEDIA_A_FECHA: TSQLTimeStampField;
    cdsExpteAVEDIA_M_USUARIO: TStringField;
    cdsExpteAVEDIA_M_FECHA: TSQLTimeStampField;
    surceExpte: TDataSource;
    cEstado: TUniDBLookupComboBox;
    cZona: TUniDBLookupComboBox;
    cTipo: TUniDBLookupComboBox;
    UniDBEdit1: TUniDBEdit;
    eNome: TUniDBEdit;
    eTlno: TUniDBEdit;
    eMail: TUniDBEdit;
    eEnderezo: TUniDBEdit;
    ePobo: TUniDBEdit;
    UniLabel1: TUniLabel;
    UniLabel2: TUniLabel;
    UniLabel3: TUniLabel;
    UniLabel4: TUniLabel;
    UniLabel5: TUniLabel;
    UniLabel6: TUniLabel;
    UniLabel7: TUniLabel;
    UniLabel8: TUniLabel;
    UniLabel9: TUniLabel;
    UniLabel11: TUniLabel;
    UniDBMemo1: TUniDBMemo;
    UniDBEdit7: TUniDBEdit;
    UniLabel10: TUniLabel;
    BOk: TUniButton;
    BCancel: TUniButton;
    eAsignado: TUniDBEdit;
    PEdit: TUniPanel;
    procedure UniFormShow(Sender: TObject);
    procedure CargaTipos;
    procedure CargaZonas;
    procedure CargaEstados;
    procedure BCancelClick(Sender: TObject);
    procedure BOkClick(Sender: TObject);
    procedure UniFormClose(Sender: TObject; var Action: TCloseAction);
  private

  public
    Codigo            : Integer;
    Modo              : char;
  end;

implementation

uses
  uniGUIApplication, Datosunit;

{$R *.dfm}

procedure TAveriasExpteEdit.UniFormShow(Sender: TObject);
begin
   CargaTipos;
   CargaZonas;
   CargaEstados;

   cdsExpte.Close;
   with queryExpte do begin
    SQL.Clear;
    SQL.Add('select * from AVEAVEDIA where AVEDIA_CODIGO=:codigo');
   end;

   cdsExpte.Params.ParamByName('codigo').AsInteger := Codigo;
   cdsExpte.Open;
   case Modo of
    'A' : begin
        Caption := 'Alta';
        cdsExpte.Insert;
        cdsExpte.FieldByName('AVEDIA_CODIGO').AsInteger := Datos.getAutoincremental;
      end;
    'M' : begin
        Caption := 'Editar';
        cdsExpte.Edit;
      end;
    'E' : begin
        Caption := 'Eliminar';
        BOk.Caption := '<i class="fa fa-check fa-2x color-verde">'+
                         '</i><span class=" fa-15x color-roxo" style="margin-left:1em">ELIMINAR</span>';
      end;
   end;
end;

procedure TAveriasExpteEdit.BOkClick(Sender: TObject);
var Td           : TTransactionDesc;
begin
  td.TransactionID:=1;
  td.IsolationLevel:=xilREADCOMMITTED;
  Datos.Conexion.StartTransaction(td);
  if Modo = 'E' then
    cdsExpte.Delete
  else
    if cdsExpte.Modified then cdsExpte.Post;
  if cdsExpte.ChangeCount > 0 then
    if cdsExpte.ApplyUpdates(0)=0 then
      Datos.Conexion.Commit(td)
    else begin
      Datos.Conexion.Rollback(td);
      showmessage('Error al grabar');
      Exit;
  end;
  cdsExpte.Close;
  ModalResult := mrOk;
end;

procedure TAveriasExpteEdit.BCancelClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TAveriasExpteEdit.UniFormClose(Sender: TObject; var Action: TCloseAction);
begin
  cdsExpte.Close;
  cdsTipo.Close;
  cdsZona.Close;
  cdsEstado.Close;
end;

procedure TAveriasExpteEdit.CargaTipos;
begin
  cdsTipo.Close;
  with QueryTipo do begin
    SQL.Clear;
    SQL.Add('select AVETIP_CODIGO,AVETIP_DESCRIP,AVETIP_ACTIVO');
    SQL.Add('from AVEAVETIP');
    SQL.Add('where AVETIP_ACTIVO=1');
    SQL.Add('order by AVETIP_DESCRIP');
  end;
  cdsTipo.Open;
end;

procedure TAveriasExpteEdit.CargaZonas;
begin
  cdsZona.Close;
  with QueryZona do begin
    SQL.Clear;
    SQL.Add('select AVEZON_CODIGO,AVEZON_DESCRIP,AVEZON_ACTIVO');
    SQL.Add('from AVEAVEZON');
    SQL.Add('where AVEZON_ACTIVO=1');
    SQL.Add('order by AVEZON_DESCRIP');
  end;
  cdsZona.Open;
end;

procedure TAveriasExpteEdit.CargaEstados;
begin
  cdsEstado.Close;
  with QueryEstado do begin
    SQL.Clear;
    SQL.Add('select AVEEST_CODIGO,AVEEST_DESCRIP,AVEEST_ACTIVO');
    SQL.Add('from AVEAVEEST');
    SQL.Add('where AVEEST_ACTIVO=1');
    SQL.Add('order by AVEEST_DESCRIP');
  end;
  cdsEstado.Open;
end;

end.
Link to comment
Share on other sites

  • 3 months later...

Anybody can help me with this problem?

Hi, I found a similar problem trying how to make a filter with TCLIENTDATASET, when I filter a dataset that selects a single record and then filter the same TCLIENTDATASET and cannot find any record in the DBGRID leaves the previous record, which should not appear because that is not in the selection. The solution was to the DataSource1.DataSet: = ClientDataSetDUMMY assign a TCLIENTDATASET not having logs, redo the filter and assign the datasource the proper clientdataset

 

procedure TFDSPTAB.BTN_FILTRARClick(Sender: TObject);

var
 W_Filtro     :string;
 w_filtroField:string ;
 w_filtroValue:string ;
 
begin
  DataSource1.DataSet:= ClientDataSetDUMMY;
  ClientDataSet1.Filtered  := false ;
  ClientDataSet1.First;
 
  w_filtroField:= Trim(EDT_FILTROFIELD.Text);
  W_FILTROVALUE:= EDT_FILTRO.Text ;
  w_filtro := CHR(27) + trim(w_filtroField) + '=' + CHR(27);    // CHR(27)=ESCAPE
  w_filtro :=  w_filtroField + ' LIKE ' +  QuotedStr( '%' + Trim(W_FILTROVALUE) + '%' ) ;
 
 
 
  W_FILTROVALUE:= w_filtro + QuotedStr( W_FILTROVALUE);
 
  ClientDataSet1.Filter := w_filtro;
  ClientDataSet1.Filtered  := True ;
  ClientDataSet1.First;
  DataSource1.DataSet:= ClientDataSet1;
end;
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...