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 Buscar Temas de Hoy Marcar Foros Como Leídos

Conexión con bases de datos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 03-12-2008
deprimera deprimera is offline
Miembro
 
Registrado: jul 2008
Posts: 26
Poder: 0
deprimera Va por buen camino
Me podrias pasar algun codigo aproximado para orientarme un poco mas?? Perdon que sea tan jodon.

Gracias!
Responder Con Cita
  #2  
Antiguo 03-12-2008
Avatar de felipe88
[felipe88] felipe88 is offline
Miembro Premium
 
Registrado: may 2007
Ubicación: Mi Valle del Cauca... Colombia!!!
Posts: 1.120
Poder: 21
felipe88 Va por buen camino
En el momento no tengo un código como quieres... solo recuerdo como lo hice, aunque no se si fuese la mejor manera .

Como te digo, podrias hacer un query al cambiar de fecha que te consulte todas las citas en la misma y retornar los campos F y C, luego en una rutina ubicar esta celda y cambiarle el color por ejemplo, si el usuario da click en ella; pues será otra consulta, esta vez buscando las coincidencias en la fecha y los campos F C, evita resultados ambiguos... (me imagino que buscaras la forma de mostrar siempre el resultado adecuado), depues de esto en el otro formulario deberias tener desde la consulta el detalle completo de la cita... recuerda que es la idea la que te aporto.
Responder Con Cita
  #3  
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
  #4  
Antiguo 03-12-2008
deprimera deprimera is offline
Miembro
 
Registrado: jul 2008
Posts: 26
Poder: 0
deprimera Va por buen camino
Gracias Felipe por la idea, voy a ver como me la rebusco con el codigo. Algo voy a hacer, voy a hacer lo posible...

Gracias Caral por el codigo que me pasaste, mañana tranquilo lo voy a ver con mas atencion.

Cualquier duda, la consultare y espero sus respuestas.

Gracias por todo.
Responder Con Cita
  #5  
Antiguo 03-12-2008
Avatar de felipe88
[felipe88] felipe88 is offline
Miembro Premium
 
Registrado: may 2007
Ubicación: Mi Valle del Cauca... Colombia!!!
Posts: 1.120
Poder: 21
felipe88 Va por buen camino
Cita:
Empezado por deprimera Ver Mensaje
Gracias Felipe por la idea, voy a ver como me la rebusco con el codigo. Algo voy a hacer, voy a hacer lo posible...

Gracias Caral por el codigo que me pasaste, mañana tranquilo lo voy a ver con mas atencion.

Cualquier duda, la consultare y espero sus respuestas.

Gracias por todo.
Considero que el codigo de Caral va muy bien con la idea y con parte de lo que necesitas...
Responder Con Cita
  #6  
Antiguo 03-12-2008
Avatar de felipe88
[felipe88] felipe88 is offline
Miembro Premium
 
Registrado: may 2007
Ubicación: Mi Valle del Cauca... Colombia!!!
Posts: 1.120
Poder: 21
felipe88 Va por buen camino
...........

Última edición por felipe88 fecha: 03-12-2008 a las 03:46:32.
Responder Con Cita
  #7  
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
En realidad creo que la parte en donde actuliza es la que te podria servir mas o donde podrias sacar mas provecho.
Este es el pequeño codigo:
Código Delphi [-]
procedure TFFactura.BitBtn4Click(Sender: TObject);
var numfact, i, OrdTrans : integer;
    Fecha, FechaVence, iv: String;
    FPagoOK : Boolean;
    MntContado, MntCheque, MntTarjeta, MntOtros, Saldo, Pagado :String;
    BalanceAnterior, BalanceTotal : Double;
    Tipo :char;
begin
   If cbTipo.ItemIndex = 0 then
   begin
      FFormaPago:=TFFormaPago.Create(self);
      FFormaPago.Valores(SubTotal, Impuesto, Total);
      try
         FFormaPago.ShowModal;
      finally
         FPagoOK := FFormaPago.OK;
         MntContado := FFormaPago.FEContado.Text;
         MntCheque  := FFormaPago.FECheque.Text;
         MntTarjeta := FFormaPago.FETarjeta.Text;
         MntOtros   := FFormaPago.FEOtro.Text;
         Saldo      := FloatToStr(FFormaPago.Saldo);
         Pagado     := FloatToStr(FFormaPago.Pagado);
         FFormaPago.Free;
      end;
      Tipo:= 'F';
   end else
   begin
      FPagoOK := True;
      MntContado := '0';
      MntCheque  := '0';
      MntTarjeta := '0';
      MntOtros   := '0';
      Saldo      := '0';
      Pagado     := '0';
      Tipo := 'C';
   end;
   If FPagoOk then
   begin
     ShortDateFormat := 'yyyy-mm-dd';
     Fecha := DateToStr(now);
     FechaVence := DateToStr(IncDay(now,(StrToInt(Label21.Caption))));
     ShortDateFormat := 'dd/mm/yyyy';
  // Obtener el numero de factura
     QTemp.SQL.Text := 'Select Max(CodFactura) From Factura where Tipo = '+QuotedStr(Tipo);
     QTemp.Open;
     If QTemp.RecordCount = 0 then NumFact:=1
     else NumFact := QTemp.Fields[0].AsInteger+1;
     QTemp.Close;
  //Iniciar la Transaccion
     DataModule1.AC1.BeginTrans;
     try
     If Edit2.Text <> '' then
  // Insertar en la tabla de Factura Si tiene ORDEN
        QTemp.SQL.Text := 'Insert Into Factura Values '+
           '( '+IntToStr(NumFact)+', 0, '+QuotedStr(Tipo)+', '+QuotedStr(Fecha)+', '+Edit1.Text+', '+QuotedStr(Label19.Caption)+', '+QuotedStr(Edit4.Text)+', '+QuotedStr(Edit5.Text)+', '+QuotedStr(Edit3.Text)+
           ', False, ''0.13'', False, ''0.00'', '+QuotedStr(SGTotal.Cells[1,0])+', '+QuotedStr(SGTotal.Cells[1,1])+', '+
           QuotedStr(SGTotal.Cells[1,2])+', '+QuotedStr(SGTotal.Cells[1,3])+', '+Edit2.Text+', '+QuotedStr(MntContado)+', '+QuotedStr(MntCheque)+', '+
           QuotedStr(MntTarjeta)+', '+QuotedStr(MntOtros)+', '+QuotedStr(Saldo)+', '+QuotedStr(Pagado)+', '+QuotedStr(FloatToStr(TipoCambio))+')'
        else
  // Insertar en la tabla de Factura si NO tiene ORDEN
        QTemp.SQL.Text := 'Insert Into Factura ( CodFactura, Secuencia, Tipo, Fecha, CodCliente, Terminos, OrdenCompra, CodVendedor, Excento, TasaImpuesto, Anulada, MntEnvio, MntSubTotal, MntDescuento, MntImpuesto, MntTotal, '+
        'MntContado, MntCheque, MntTarjeta, MntOtros, Saldo, Pagado, TC) Values '+
           '( '+IntToStr(NumFact)+', 0, '+QuotedStr(Tipo)+', '+QuotedStr(Fecha)+', '+Edit1.Text+', '+QuotedStr(Label19.Caption)+', '+QuotedStr(Edit4.Text)+', '+QuotedStr(Edit5.Text)+', '+QuotedStr(Edit3.Text)+
           ', False, ''0.13'', False, ''0.00'', '+QuotedStr(SGTotal.Cells[1,0])+', '+QuotedStr(SGTotal.Cells[1,1])+', '+
           QuotedStr(SGTotal.Cells[1,2])+', '+QuotedStr(SGTotal.Cells[1,3])+', '+QuotedStr(MntContado)+', '+QuotedStr(MntCheque)+', '+
           QuotedStr(MntTarjeta)+', '+QuotedStr(MntOtros)+', '+QuotedStr(Saldo)+', '+QuotedStr(Pagado)+', '+QuotedStr(FloatToStr(TipoCambio))+')';
        QTemp.ExecSQL;

   //Insertar en la tabla de FacturaItem
        For i := 1 to SgFact.RowCount-1 do
         begin
           if SGFact.Cells[6,i] = 'Si' then iv:='True)' else iv:='False)';
           QTemp.SQL.Text := 'Insert Into FacturaItem Values '+
           '( '+IntToStr(numfact)+', 0, '+QuotedStr(Tipo)+', '+IntToStr(i)+', '+QuotedStr(SGFact.Cells[0,i])+', '+QuotedStr(SGFact.Cells[2,i])+','+QuotedStr(SGFact.Cells[3,i])+', '+
           QuotedStr(SGFact.Cells[4,i])+', '+iv;
           QTemp.ExecSQL;
         end;
   //Calcula el siguiente numero de OrdTrans
         QTemp.SQL.Text := 'SELECT Max([OrdTrans]) AS Expr1 '+
                           'FROM CxCobrar;';
         QTemp.Active := True;
         If QTemp.RecordCount = 0 then OrdTrans:=1
         else OrdTrans := QTemp.Fields[0].AsInteger+1;
         QTemp.Close;

        If Tipo = 'F' then
        begin
   //  Insertar en la tabla de CxCobrar
           QTemp.SQL.Text := 'Select BalanceTotal From CxCobrar where CodCliente = '+Edit1.Text+
                             ' Order By OrdTrans;';
           QTemp.Open;
           IF QTemp.RecordCount = 0 then BalanceAnterior := 0
           else
           begin
              QTemp.Last;
              BalanceAnterior := QTemp.Fields[0].AsFloat;
           end;
           QTemp.Close;
           BalanceTotal := StrToFloat(Saldo) + BalanceAnterior;

           QTemp.SQL.Text := 'Insert Into CxCobrar ( CodTransac, Secuencia, TipoTransac, OrdTrans, FechaTransac, FechaVencimiento, CodCliente, SubTotal, Descuento, Impuesto, Total, Efectivo, Cheque, Tarjeta, Otro, Balance, BalanceTotal, BalanceAnterior, PagosRec, EstadoCuenta )'+
                             ' Values ('+IntToStr(NumFact)+', 0, ''FA'', '+IntToStr(OrdTrans)+', '+QuotedStr(Fecha)+', '+QuotedStr(FechaVence)+', '+Edit1.Text+', '+QuotedStr(SGTotal.Cells[1,0])+', '+QuotedStr(SGTotal.Cells[1,1])+', '+
                             QuotedStr(SGTotal.Cells[1,2])+', '+QuotedStr(SGTotal.Cells[1,3])+', '+QuotedStr(MntContado)+', '+QuotedStr(MntCheque)+', '+
                             QuotedStr(MntTarjeta)+', '+QuotedStr(MntOtros)+', '+QuotedStr(Saldo)+', '+QuotedStr(FloatToStr(BalanceTotal))+', '+QuotedStr(FloatToStr(BalanceAnterior))+', 0, 0)';
           QTemp.ExecSQL;
        end;

  // Actualizar la tabla de series
        For i := 1 to SgFact.RowCount-1 do
         begin
           if Tipo = 'F' then
              QTemp.SQL.Text := 'Update Series Set NumFactura = '+IntToStr(numfact)+', Estado = ''Facturado'' Where '+
                                'NumSerie = '+SGFact.Cells[2,i]
           else
              QTemp.SQL.Text := 'Update Series Set NumFactura = '+IntToStr(numfact)+', Estado = ''Consignac'' Where '+
                                'NumSerie = '+SGFact.Cells[2,i];
           QTemp.ExecSQL;
         end;

  // Actualizar la tabla de OrdenProdItem
        For i := 1 to SgFact.RowCount-1 do
         begin
           if Tipo = 'F' then
              QTemp.SQL.Text := 'Update OrdenProdItem Set Estacion = ''Est05'' Where '+
                                'NumSerie = '+SGFact.Cells[2,i]
           else
              QTemp.SQL.Text := 'Update OrdenProdItem Set Estacion = ''Est06'' Where '+
                                'NumSerie = '+SGFact.Cells[2,i];
           QTemp.ExecSQL;
         end;

  // Actualizar la tabla de Articulos
        For i := 1 to SgFact.RowCount-1 do
         begin
           QTemp.SQL.Text := 'Update Articulos Set Disponible = Disponible - '+SGFact.Cells[3,i]+' Where '+
                             'CodParte = '+QuotedStr(SGFact.Cells[0,i]);
           QTemp.ExecSQL;
         end;

   // Completa la Transaccion
        DataModule1.AC1.CommitTrans;

   // Imprime la factura si el usuario quiere
      FImprimirFactura:=TFImprimirFactura.Create(self);
      FImprimirFactura.numfact := numfact;
      FImprimirFactura.Tipo := Tipo;      
      try
         FImprimirFactura.ShowModal;
      finally
         FImprimirFactura.Free;
      end;

   except
        on E:Exception do
        begin
           DataModule1.AC1.RollbackTrans;
           MessageDlg('No fue posible completar la transacción, por favor contacte al administrador',mtError,[mbOK],0);
        end;
     end;//try
   end;
   Close;
end;
Espero te sirva de ejemplo.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #8  
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
01010001 01110101 01100101 00100000 01110110 01100001 00100000 01100001 01101101 01101001 01100111 01101111 00101100 00100000 01111001 01100001 00100000 01100001 01110000 01110010 01100101 01101110 01100100 01100101 01110010 01100001 00101100 00100000 01100101 01110011 00100000 01100011 01110101 01100101 01110011 01110100 01101001 01101111 01101110 00100000 01100100 01100101 00100000 01110100 01101001 01100101 01101101 01110000 01101111
Saludos
__________________
Siempre Novato
Responder Con Cita
  #9  
Antiguo 03-12-2008
Avatar de felipe88
[felipe88] felipe88 is offline
Miembro Premium
 
Registrado: may 2007
Ubicación: Mi Valle del Cauca... Colombia!!!
Posts: 1.120
Poder: 21
felipe88 Va por buen camino
En realidad todos empezamos con dudas
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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 01:56:46.


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