Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Drag & Drop de una selección múltiple. (https://www.clubdelphi.com/foros/showthread.php?t=83905)

TiammatMX 13-08-2013 21:45:11

Drag & Drop de una selección múltiple.
 
Buen día/tarde/noche, jóvenes del foro.

Tengo dos TwwDbgrid (InfoPower4000 de WollToWoll Software) y necesito "pasar" de una a otra una serie de registros de una de las rejillas, los cuales se "marcarán" y usando el ratón, arrastrados y depositados en la otra para ser INSERTADAS en la tabla que es representada en ésta rejilla; ésto es debido a que se requiere agilizar la definición de una serie de parámetros.

El código que "recibe" el proceso de "soltar en la segunda rejilla" (que en éste momento sólo acepta UN registro a la vez) lo tengo actualmente así:

Código Delphi [-]
procedure TfrmRubrosSIS.grdReporteDragDrop(Sender, Source: TObject; X, Y: Integer);

   function GetGenreLabel(sEtiqueta: string) : string;
   begin
      with TADOQuery.Create(Self) do
      try
         Connection := cnxConexion;
         with SQL do
         begin
            Add('SELECT C_SIS_CLAVE_GENERO');
            Add('FROM   C_SIS_CLAVE');
            Add('WHERE  C_SIS_CLAVE_SIS_ID = '+QuotedStr(sEtiqueta));
         end;
         Open;
         GetGenreLabel := IntToStr(FieldByName('C_SIS_CLAVE_GENERO').AsInteger);
      finally
         Close;
         Free;
      end;
   end;

begin
   with TADOQuery.Create(Self) do
   try
      Connection := cnxConexion;
      with SQL do
      begin
         Add('INSERT INTO C_SIS_SS_AUXILIAR');
         Add(           '(C_SIS_CODIGO_MATRIZ');
         Add(           ',C_SIS_CLAVE_SIS');
         Add(           ',C_SIS_GENERO');
         Add(           ',E4_SERVICIO_ID');
         Add(           ',E4_SRV_DETALLE_ID)');
         Add(    'VALUES (');
         Add(             QuotedStr(cmbxReporte.Value));
         Add(         ','+QuotedStr(cmbxEtiquetaSIS.Value));
         Add(         ','+GetGenreLabel(cmbxEtiquetaSIS.Value));
         Add(         ','+QuotedStr(QryServiciosE4_SERVICIO_ID.AsString));
         Add(         ','+IntToStr(QryServiciosE4_SRV_DETALLE_ID.AsInteger));
         Add(           ')');
      end;
      ExecSQL;
   finally
      Free;
   end;
   QryData001.Requery;
   QryServicios.Requery;
end;

Y que deberá prepararse para "recibir" más de un registro a la vez.

¿Alguna idea, código, orientación que me sirva para cumplimentar ésto?

ecfisa 13-08-2013 23:35:13

Hola tiammat.

No conozco el componente que mencionas pero, por si te pudiera servir de algo, te pongo un ejemplo de como podes copiar los registros seleccionados de un TDBGrid a otro usando Drag & Drop.

Para el ejemplo, los DataSets (orígen y destino) asociados a ambos DBGrids son iguales:
Código Delphi [-]
...
procedure TForm1.DBGridDestinoDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Source is TDBGrid;
end;

procedure TForm1.DBGridDestinoDragDrop(Sender, Source: TObject; X, Y: Integer);
var
  i,j: Integer;
begin
  for i:= 0 to DBGridOrigen.SelectedRows.Count-1 do
  begin
    DBGridOrigen.DataSource.DataSet.GotoBookmark(Pointer(DBGridOrigen.SelectedRows.Items[i]));
    DBGridDestino.DataSource.DataSet.Append;
    for j:= 0 to DBGridDestino.FieldCount-1 do
      DBGridDestino.Fields[j].Value := DBGridOrigen.Fields[j].Value;
    DBGridDestino.DataSource.DataSet.Post;
  end;
end;

procedure TForm1.btnDragDropClick(Sender: TObject);
begin
  if DBGridOrigen.SelectedRows.Count > 0 then
    DBGridOrigen.BeginDrag(True);
end;

Saludos. :)

TiammatMX 17-08-2013 03:03:01

Cita:

Empezado por ecfisa (Mensaje 465534)
Hola tiammat.

No conozco el componente que mencionas pero, por si te pudiera servir de algo, te pongo un ejemplo de como podes copiar los registros seleccionados de un TDBGrid a otro usando Drag & Drop...

Tu solución, adaptada a éste componente:
Código Delphi [-]
procedure TfrmRubrosSIS.grdReporteDragDrop(Sender, Source: TObject; X, Y: Integer);
var
   iIndicador: Integer;
begin
   with TADOQuery.Create(Self) do
   try
      Connection := cnxConexion;
      with grdServicios, grdServicios.DataSource.DataSet do
      begin
         DisableControls;
         for iIndicador := 0 to SelectedList.Count -1 do
         begin
           GotoBookmark(SelectedList.Items[iIndicador]);
            with SQL do
            begin
               Clear;
               Add('INSERT INTO C_SIS_SS_AUXILIAR');
               Add(           '(C_SIS_CODIGO_MATRIZ');
               Add(           ',C_SIS_CLAVE_SIS');
               Add(           ',C_SIS_GENERO');
               Add(           ',E4_SERVICIO_ID');
               Add(           ',E4_SRV_DETALLE_ID)');
               Add(    'VALUES (');
               Add(             QuotedStr(cmbxReporte.Value));
               Add(         ','+QuotedStr(cmbxEtiquetaSIS.Value));
               Add(         ','+GetGenreLabel(cmbxEtiquetaSIS.Value));
               Add(         ','+QuotedStr(QryServiciosE4_SERVICIO_ID.AsString));
               Add(         ','+IntToStr(QryServiciosE4_SRV_DETALLE_ID.AsInteger));
               Add(           ')');
            end;
            ExecSQL;
         end;
         UnselectAll;
         EnableControls;
      end;
   finally
      Free;
   end;
   QryData001.Requery;
   QryServicios.Requery;
end;


La franja horaria es GMT +2. Ahora son las 19:57:58.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi