Ver Mensaje Individual
  #5  
Antiguo 24-08-2011
Avatar de joelphi
joelphi joelphi is offline
Miembro
 
Registrado: feb 2009
Ubicación: Guerrero
Posts: 24
Reputación: 0
joelphi Va por buen camino
probe

Tu consulta esta muy bien..se ve que ya tienes tu experiencia yo todavia soy estudiante..

Ya depure el programa y si se abre la consulta,ahora estoy probando los campos calculados quedo de esta forma solo que ahora no lo calcula
Código Delphi [-]
  Consulta.Close;
    Consulta.SQLs.SelectSQL.Clear;
    Consulta.SQLs.SelectSQL.Add(' Select P.nombre_producto,S.nombre as sustancia, Prov.nombre_proveedor, C.Id_categoria,C.nombre as categoria, P.aplicar_descuento,'+
                                  ' P.costo_referencia,P.iva, P.ganancia, P.precio_farmacia, P.precio_maximo'+
                                  '  From productos P'+
                                  '  Left Join categorias C on c.id_categoria = P.id_categoria'+
                                  '  Left Join sustancias_activas S on S.id_sustancia_activa = P.id_sustancia_activa'+
                                  '  Left Join proveedores Prov on Prov.id_proveedor = P.id_proveedor');
    try

        Consulta.Open;
    except on E: Exception do
    begin
        Raise;
        Exit;
    end;
    end;
   Consulta.Close;

    for I := 0 to Consulta.FieldDefs.Count - 1 do
     Consulta.FieldDefs[i].CreateField(Consulta, nil, Consulta.FieldDefs[i].Name);

  NuevoCampoCalculado := TStringField.Create(Consulta);
  NuevoCampoCalculado.FieldName := 'Precio_Con_Descuento';
//  NuevoCampoCalculado.AsCurrency;
  NuevoCampoCalculado.FieldKind := fkCalculated;
  NuevoCampoCalculado.DataSet := Consulta;
    Consulta.Open;
    Consulta.First;
    while not consulta.Eof do
    begin
        with Consulta do
        begin
        //Si aplica descuento a este producto..
            if(FieldByName('Aplicar_Descuento').AsString = 'SI') then
              begin
                for I := 0 to ListaDescuentos.Count -1  do //entonces buscar su categoria y si es igual aplicar el descuento
                 begin
                     if FieldByName('id_Categoria').AsInteger = TDescuentos_Clientes(ListaDescuentos[i]).Id_Categoria then
                     begin    //Si pasa por aqui pero no realiza la operacion-..
                        //ProductoDescuento.PrecioConDescuento := ProductoDescuento.PrecioMaximo - (ProductoDescuento.PrecioMaximo*descuento);
                        FieldByName('Precio_Con_Descuento').AsCurrency :=FieldByName('Precio_Maximo').AsCurrency - (FieldByname('Precio_Maximo').AsCurrency * TDescuentos_Clientes(ListaDescuentos[i]).Descuento);
                     end;
                 end;
              end;

        consulta.next;
        end;
    end;
    ListaDescuentos.Destroy;
    Result:= TDataSource.Create(Nil);
    Result.DataSet:=Consulta;

funciono bien pero no realiza la operacion..
Saludos..
Responder Con Cita