Ver Mensaje Individual
  #6  
Antiguo 05-01-2007
chileno chileno is offline
Miembro
 
Registrado: jun 2005
Posts: 121
Reputación: 19
chileno Va por buen camino
ContraVeneno te envio las rutinas asociadas para que veas ....okis..

crea un ficha que muestra los productos asociados a un proveedor.
Código Delphi [-]
procedure TFichaOrden.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var nro_campo : integer;
    dato      : string;
begin
  case key of
    #13 : begin
            if (DM.tbDet_orden.State = dsInsert) then
            begin
               nro_campo := DBGrid1.SelectedIndex;
               if not (DBGrid1.Fields[nro_campo].IsNull) then
               begin
                  dato      := DBGrid1.Fields[nro_campo].Value + '%';
                  if  (DBGrid1.SelectedField.FieldName = 'id_unidad_venta') then
                  begin
                      with TFichaBuscarUnidad.Create(Self) do
                      try
                        ZQuery1.Close;
                        ZQuery1.SQL.Clear;
                        ZQuery1.SQL.Add('select unidad_venta.id_unidad_venta, unidad_proveedor.codigo_externo,    ');
                        ZQuery1.SQL.Add('       unidad_venta.codigo_barra,                                    ');
                        ZQuery1.SQL.Add('concat(unidad_venta.descripcion," ",unidad_venta.formato) as Descripcion,');
                        ZQuery1.SQL.Add('       unidad_venta.costo,                                               ');
                        ZQuery1.SQL.Add('       existencia.existencia,                                            ');
                        ZQuery1.SQL.Add('       existencia.peso                                                   ');
                        ZQuery1.SQL.Add('from unidad_venta, unidad_proveedor, existencia where                    ');
                        ZQuery1.SQL.Add('unidad_venta.id_unidad_venta = unidad_proveedor.id_unidad_venta and      ');
                        ZQuery1.SQL.Add('unidad_venta.id_unidad_venta = existencia.id_unidad_venta       and      ');
                        ZQuery1.SQL.Add('unidad_proveedor.id_unidad_venta like Id                      and      ');
                        ZQuery1.SQL.Add('existencia.id_almacen            like Id_Almacen              and      ');
                        ZQuery1.SQL.Add('unidad_venta.Bloqueado <> "Si"                                            ');
                        ZQuery1.ParamByName('pId').Value := dato;
                        ZQuery1.ParamByName('pId_Almacen').Value := DM.tbOrdenid_almacen.Value;
                        ZQuery1.Open;
                        ShowModal;
                      finally
                        Free;
                      end;
                  end;
                  if  DBGrid1.SelectedField.FieldName = 'codigo_externo' then
                  begin
                      with TFichaBuscarUnidad.Create(Self) do
                      try
                        ZQuery1.Close;
                        ZQuery1.SQL.Clear;
                        ZQuery1.SQL.Add('select unidad_venta.id_unidad_venta, unidad_proveedor.codigo_externo,    ');
                        ZQuery1.SQL.Add('       unidad_venta.codigo_barra,                                        ');
                        ZQuery1.SQL.Add('concat(unidad_venta.descripcion," ",unidad_venta.formato) as Descripcion,');
                        ZQuery1.SQL.Add('       unidad_venta.costo,                                               ');
                        ZQuery1.SQL.Add('       existencia.existencia,                                            ');
                        ZQuery1.SQL.Add('       existencia.peso                                                   ');
                        ZQuery1.SQL.Add('from unidad_venta, unidad_proveedor, existencia where                    ');
                        ZQuery1.SQL.Add('unidad_venta.id_unidad_venta = unidad_proveedor.id_unidad_venta and      ');
                        ZQuery1.SQL.Add('unidad_venta.id_unidad_venta = existencia.id_unidad_venta       and      ');
                        ZQuery1.SQL.Add('unidad_proveedor.codigo_externo  like Id                      and      ');
                        ZQuery1.SQL.Add('existencia.id_almacen            like Id_Almacen              and      ');
                        ZQuery1.SQL.Add('unidad_venta.Bloqueado <> "Si"                                            ');
                        ZQuery1.ParamByName('pId').Value := dato;
                        ZQuery1.ParamByName('pId_Almacen').Value := DM.tbOrdenid_almacen.Value;
                        ZQuery1.Open;
                        ShowModal;
                      finally
                        Free;
                      end;
                  end;
               end;
            end;
          end;
  end;

Ficha creada......selecciono el elemento y doy enter:

Código Delphi [-]
procedure TFichaBuscarUnidad.DBGrid1KeyPress(Sender: TObject;var Key: Char);
var miQuery : TZQuery;
begin
  if (key = #13) and (ZQuery1.RecordCount <> 0) then
  begin
    miQuery := TZQuery.Create(nil);
    miQuery.Connection := DM.miConexion;
    miQuery.Close;
    miQuery.SQL.Clear;
    miQuery.SQL.Add('select unidad_venta.id_unidad_venta, unidad_venta.descripcion,                   ');
    miQuery.SQL.Add('unidad_venta.formato, unidad_venta.formato_real,unidad_proveedor.codigo_externo  ');
    miQuery.SQL.Add('from unidad_venta, unidad_proveedor where unidad_venta.id_unidad_venta =ID and ');
    miQuery.SQL.Add('unidad_venta.id_unidad_venta = unidad_proveedor.id_unidad_venta              and ');
    miQuery.SQL.Add('unidad_proveedor.rutproveedor =Rut                                             ');
    miQuery.ParamByName('pID').Value  := ZQuery1.FieldValues['id_unidad_venta'];
    miQuery.ParamByName('pRut').Value := DM.tbOrdenrutProveedor.Value;
    miQuery.Open;
    //DM.tbDet_orden.Edit;
    DM.tbDet_ordenid_unidad_venta.Value := miQuery.FieldValues['id_unidad_venta'];
    DM.tbDet_ordencodigo_externo.Value  := miQuery.FieldValues['codigo_externo'];
    DM.tbDet_ordendescripcion.Value     := miQuery.FieldValues['descripcion'];
    DM.tbDet_ordenformato.Value         := miQuery.FieldValues['formato'];
    DM.tbDet_ordenformato_real.Value    := miQuery.FieldValues['formato_real'];
   // DM.tbDet_Orden.Post;
    close;
  end;
end;
Responder Con Cita