Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Conexión con bases de datos

 
 
Herramientas Buscar en Tema Desplegado
  #15  
Antiguo 03-12-2008
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 27
Caral Va por buen camino
Hola
Bueno ten en cuenta que este codigo es de un novato, asi que no critiques mucho, solo te lo pongo de ejemplo.
Esta es una parte que uso en un sistema de facturacion con stringrid.
Código Delphi [-]
procedure TFFactura.RJustifyEdit(var ThisEdit : TEdit);
var
   Left, Width : Integer;
   GString : String;
   Rgn : TRect;
   TheCanvas : TControlCanvas;
begin
   TheCanvas := TControlCanvas.Create;
   try
      TheCanvas.Control := ThisEdit;
      GString := ThisEdit.Text;
      Rgn := ThisEdit.ClientRect;
      TheCanvas.FillRect(Rgn);
      Width := TheCanvas.TextWidth(GString);
      Left := Rgn.Right - Width - 1;
      TheCanvas.TextRect(Rgn, Left, 0, GString);
   finally
      TheCanvas.Free;
   end;
end;

Procedure GridRemoveRow(StrGrid: TStringGrid; DelRow: Integer);
Var Row: Integer;
begin
  If DelRow <= StrGrid.RowCount then
  Begin
    If (DelRow = StrGrid.RowCount-1) AND (DelRow = 1) then
    begin
       StrGrid.Rows[DelRow].Clear;
       StrGrid.Cells[3,1] := '0';
       StrGrid.Cells[4,1] := '0.00';
       StrGrid.Cells[5,1] := '0.00';
    end
    else if DelRow = StrGrid.RowCount - 1 then StrGrid.RowCount := StrGrid.RowCount-1
         else
         begin
            For Row := DelRow To StrGrid.RowCount-2 do
               StrGrid.Rows[Row].Assign(StrGrid.Rows[Row+1]);
            StrGrid.RowCount := StrGrid.RowCount-1;
         end;
  End;
end;

procedure TFFactura.CalculaTotales;
var i:integer;
begin
 //Calcula los totales de la factura
   SubTotal := 0;
   Impuesto := 0;
   Desc     := 0;
   Total    := 0;
   // Calcula el SubTotal
   For i:=1 to SGFact.RowCount-1 do
      SubTotal := SubTotal + StrToFloat(SGFact.Cells[5,i]);
   // Calcula el monto para cobrar el impuesto de ventas

   For i:=1 to SGFact.RowCount-1 do
      If SGFact.Cells[6,i] = 'Si' then Impuesto :=  Impuesto + StrToFloat(SGFact.Cells[5,i]);

   SubTotal := Round(SubTotal);
   Desc := (SubTotal * FLEPorcDesc.Value / 100);
   Desc := Round(Desc);
   Impuesto := (Impuesto * 0.13);
   Impuesto := Round(Impuesto);
   Total := (SubTotal - Desc + Impuesto);
   // escribe los valores en las celdas
   SGTotal.Cells[1,1] := Format('%8.2n',[desc]);
   SGTotal.Cells[1,2] := Format('%8.2n',[Impuesto]);
   SGTotal.Cells[1,0] := Format('%8.2n',[SubTotal]);
   SGTotal.Cells[1,3] := Format('%8.2n',[Total]);
 end;
Esta es otra:
Código Delphi [-]
procedure TFFactura.BitBtn2Click(Sender: TObject);
var i : integer;
begin
// ************ Boton de Agregar **************
   FSelProdFact:=TFSelProdFact.Create(self);
   FSelProdFact.Precio := Label15.Caption;
 // Filtra las series que ya estan en la factura
   If (SGFact.RowCount = 2) AND (SGFact.Cells[2,1] = '') then FSelProdFact.Filtro := ''
   else
   begin
      FSelProdFact.Filtro := 'NumSerie <> '+ SGFact.Cells[2,1];
      i:=2;
      While i < SGFact.RowCount do
      begin
         FSelProdFact.Filtro := FSelProdFact.Filtro + ' AND NumSerie <> '+SGFact.Cells[2,i];
         i:=i+1;
      end;
   end;
   try
      FSelProdFact.ShowModal;
   finally
      If FSelProdFact.Cancela = False then
      Begin
         If Cuenta > 1 then SGFact.RowCount := SGFact.RowCount + 1;
         QTemp.Close;
         QTemp.SQL.Text := 'SELECT Descripcion+" "+Categoria+" "+SubCategoria AS Descr, Precio1 FROM Articulos '+
                           'WHERE CodParte = '+QuotedStr(FSelProdFact.Edit1.Text);
         QTemp.Open;
         SGFact.Cells[0,cuenta] := FSelProdFact.Edit1.Text;
         SGFact.Cells[1,cuenta] := QTemp.Fields[0].AsString;
         SGFact.Cells[2,cuenta] := FSelProdFact.Edit2.Text;
         SGFact.Cells[3,cuenta] := FSelProdFact.Edit3.Text;
         SGFact.Cells[4,cuenta] := Format('%8.2f',[FSelProdFact.FloatEdit1.Value]);
         SGFact.Cells[5,cuenta] := Format('%8.2f',[FSelProdFact.FloatEdit1.Value * StrToFloat(SGFact.Cells[3,cuenta])]);
         If FSelProdFact.CBIV.Checked then SGFact.Cells[6,cuenta] := 'Si' else SGFact.Cells[6,cuenta] := 'No';
         Cuenta := Cuenta +1;
         QTemp.Close;
         SortGrid(SGFact,0,0);
         CalculaTotales;
      end;
      FSelProdFact.Free;
   end;
end;

procedure TFFactura.SGFactDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
Var
   X:Integer;
begin
   x:=0;
   With Sender As TStringGrid do begin
   Case Acol of
   0: Begin
      SetTextAlign(Canvas.Handle,TA_LEFT);
      X:= rect.left+5;
      end;
   1: Begin
      SetTextAlign(Canvas.Handle,TA_LEFT);
      X:= rect.left+5;
      end;
   2: Begin
      SetTextAlign(Canvas.Handle,TA_LEFT);
      X:= rect.left+5;
      end;
   3: Begin
      SetTextAlign(Canvas.Handle,TA_CENTER);
      X:=(rect.right+rect.left) div 2;
      end;
   4: Begin
      SetTextAlign(Canvas.Handle,TA_RIGHT);
      X:= rect.right-5;
      end;
   5: Begin
      SetTextAlign(Canvas.Handle,TA_RIGHT);
      X:= rect.right-5;
      end;
   6: Begin
      SetTextAlign(Canvas.Handle,TA_CENTER);
      X:=(rect.right+rect.left) div 2;
      end;
   END;{CASE}
   if Arow=0 then
   begin
      SetTextAlign(Canvas.Handle,TA_CENTER);
      X:=(rect.right+rect.left) div 2;
   end;
   Canvas.textrect(rect,X,rect.top+2,Cells[Acol,Arow]);
   end;{with}
end;
No te pongo todo por que es un poco extenso, pero mas o menos obtendrás una idea de esto.
Saludos
__________________
Siempre Novato
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 03:56:29.


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