Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 24-12-2007
Avatar de NickName
NickName NickName is offline
Miembro
 
Registrado: may 2003
Ubicación: Guerrero, México
Posts: 96
Poder: 22
NickName Va por buen camino
Clases Maestro Detalle

Hola...

Primero que nada q tengan una feliz navidad...

Sucede que decidí incursionar un poco en la programación orientada a objetos… Estoy desarrollando un proyecto donde tengo mis formas y uso métodos de clases creadas… Tengo una clase Conexión y mis clases de Clientes, Proveedores etc. heredan de esa clase les pongo el código de mi clase proveedor… Todas las demas clases son identicas...
Código Delphi [-]
unit C_Proveedores;

interface

Uses C_Conexion, Db, SysUtils;

Type
    TProveedores = class(TConexion)
  private
    FNombre_Proveedor: string;
    FCod_Proveedor: integer;
    FPagina_Web: string;
    FColonia: string;
    FFax: string;
    FCalle: string;
    FCiudad: string;
    FEstado: string;
    FCodigo_Postal: string;
    procedure SetCodigo_Postal(const Value: string);
    procedure SetCalle(const Value: string);
    procedure SetCiudad(const Value: string);
    procedure SetCod_Proveedor(const Value: integer);
    procedure SetColonia(const Value: string);
    procedure SetEstado(const Value: string);
    procedure SetFax(const Value: string);
    procedure SetNombre_Proveedor(const Value: string);
    procedure SetPagina_Web(const Value: string);

    Published
       Property Cod_Proveedor:integer read FCod_Proveedor write SetCod_Proveedor;
       Property Nombre_Proveedor:string read FNombre_Proveedor write SetNombre_Proveedor;
       Property Estado:string read FEstado write SetEstado;
       Property Ciudad:string read FCiudad write SetCiudad;
       Property Colonia:string read FColonia write SetColonia;
       Property Calle:string read FCalle write SetCalle;
       Property Codigo_Postal:string read FCodigo_Postal write SetCodigo_Postal;
       Property Fax:string read FFax write SetFax;
       Property Pagina_Web:string read FPagina_Web write SetPagina_Web;
{$REGION '   Metodos...'}
       Function Insertar_Proveedor:Boolean;
       Function Modificar_Proveedor:Boolean;
       Function Eliminar_Proveedor:Boolean;
       Function Traer_Proveedores:TDataSource;
{$ENDREGION}
    end;
implementation

{ TProveedores }

function TProveedores.Eliminar_Proveedor: Boolean;
begin
    With Operacion Do
    Begin
         SQL.Clear;
         SQL.Add('Delete From Proveedores' +
                 ' Where Cod_Proveedor = :Old_Cod_Proveedor');
         ParamByName('Old_Cod_Proveedor').AsInteger:=Cod_Proveedor;
         //---- Iniciar transa
         Transaccion.StartTransaction;
         Prepare;
         Try
              ExecQuery;
         Except on E:Exception do
         Begin
              Transaccion.Rollback;
              Raise;
              Exit;
         End; // execept
         End; // Try
    End;  // With

    Transaccion.Commit;
    Result:=True;
end;

function TProveedores.Insertar_Proveedor: Boolean;
begin
    With Operacion Do
    Begin
         SQL.Clear;
         SQL.Add('Insert Into Proveedores(Nombre_Proveedor, Estado, Ciudad, Colonia, Calle, Codigo_Postal, Fax, Pagina_Web)' +
                 'Values(:Nombre_Proveedor, :Estado, :Ciudad, :Colonia, :Calle, :Codigo_Postal, :Fax, :Pagina_Web)');
         ParamByName('Nombre_Proveedor').AsString:=Nombre_Proveedor;
         ParamByName('Estado').AsString:=Estado;
         ParamByName('Ciudad').AsString:=Ciudad;
         ParamByName('Colonia').AsString:=Colonia;
         ParamByName('Calle').AsString:=Calle;
         ParamByName('Codigo_postal').AsString:=Codigo_Postal;
         ParamByName('Fax').AsString:=Fax;
         ParamByName('Pagina_Web').AsString:=Pagina_Web;
         //---- Iniciar transa
         Transaccion.StartTransaction;
         Prepare;
         Try
              ExecQuery;
         Except on E:Exception do
         Begin
              Transaccion.Rollback;
              Raise;
              Exit;
         End; // execept
         End; // Try
    End;  // With
    Transaccion.Commit;
    Result:=True;
end;

function TProveedores.Modificar_Proveedor: Boolean;
begin
    With Operacion Do
    Begin
         SQL.Clear;
         SQL.Add('Update Proveedores Set Nombre_Proveedor = :Nombre_Proveedor, Estado = :Estado, Ciudad = :Ciudad, Colonia = :Colonia, Calle = :Calle, Codigo_Postal = :Codigo_Postal, Fax = :Fax, Pagina_Web = :Pagina_Web' +
                 ' Where Cod_Proveedor = :Old_Cod_Proveedor');
         ParamByName('Old_Cod_Proveedor').AsInteger:=Cod_Proveedor;
         ParamByName('Nombre_Proveedor').AsString:=Nombre_Proveedor;
         ParamByName('Estado').AsString:=Estado;
         ParamByName('Ciudad').AsString:=Ciudad;
         ParamByName('Colonia').AsString:=Colonia;
         ParamByName('Calle').AsString:=Calle;
         ParamByName('Codigo_postal').AsString:=Codigo_Postal;
         ParamByName('Fax').AsString:=Fax;
         ParamByName('Pagina_Web').AsString:=Pagina_Web;
         //---- Iniciar transa
         Transaccion.StartTransaction;
         Prepare;
         Try
              ExecQuery;
         Except on E:Exception do
         Begin
              Transaccion.Rollback;
              Raise;
              Exit;
         End; // execept
         End; // Try
    End;  // With

    Transaccion.Commit;
    Result:=True;
end;

procedure TProveedores.SetCalle(const Value: string);
begin
  FCalle := Value;
end;

procedure TProveedores.SetCiudad(const Value: string);
begin
  FCiudad := Value;
end;

procedure TProveedores.SetCodigo_Postal(const Value: string);
begin
  FCodigo_Postal := Value;
end;

procedure TProveedores.SetCod_Proveedor(const Value: integer);
begin
  FCod_Proveedor := Value;
end;

procedure TProveedores.SetColonia(const Value: string);
begin
  FColonia := Value;
end;

procedure TProveedores.SetEstado(const Value: string);
begin
  FEstado := Value;
end;

procedure TProveedores.SetFax(const Value: string);
begin
  FFax := Value;
end;

procedure TProveedores.SetNombre_Proveedor(const Value: string);
begin
  FNombre_Proveedor := Value;
end;

procedure TProveedores.SetPagina_Web(const Value: string);
begin
  FPagina_Web := Value;
end;

function TProveedores.Traer_Proveedores: TDataSource;
begin
    Consulta.Close;
    Consulta.SQLs.SelectSQL.Clear;
    Consulta.SQLs.SelectSQL.Add('Select * From Proveedores ');
    try
        Consulta.Open;
    except on E: Exception do
    begin
        Raise;
        Exit;
    end;
    end;
    Result:= TDataSource.Create(Nil);
    Result.DataSet:=Consulta;
end;

end.
Me gustaría que checaran el código y me dijeran si la forma de hacerlo es la correcta… ya que no tengo experiencia en esto...

Pero lo que me esta deteniendo con el desarrollo es como se harían las clases de Maestro detalle por ejemplo tengo Mis Clases Movimientos que contiene los movimientos que se hacen en el almacén pero cada movimiento puede tener varios Productos en la clase Detalle_Movimiento estas 2 clases se comunican con las tablas de la Db. que son Movimientos y Detalle_Movimiento les pongo lo que tengo para ver si alguien me puede iluminar un poco y decirme como puedo hacer para ir guardando los productos en la clase Detalle_Movimiento o si solo tengo que hacer una sola clase es la primera vez que estoy haciendo esto y la verdad no se como se hace… declaro Propiedades de tipo Arrays …? En la clase Movimiento o fuera de ella uso listas…?
Clase Movimeinto
Código Delphi [-]
unit C_Movimientos;

interface
Uses C_Conexion, Db, SysUtils, C_Detalle_Movimiento;
Type
 TMovimientos = class(TConexion)
  private
    FNumero_Partidas: Integer;
    FTotal: Integer;
    FCod_Movimiento: Integer;
    FObs_Movimiento: String;
    FNumero_Piezas: Integer;
    FCod_Tipo_Movimiento: String;
    FProductos: TDetalle_Movimiento;
    procedure SetProductos(const Value: TDetalle_Movimiento);
    procedure SetCod_Movimiento(const Value: Integer);
    procedure SetCod_Tipo_Movimiento(const Value: String);
    procedure SetNumero_Partidas(const Value: Integer);
    procedure SetNumero_Piezas(const Value: Integer);
    procedure SetObs_Movimiento(const Value: String);
    procedure SetTotal(const Value: Integer);
  Public
    constructor Create;
  Published
    Property Cod_Movimiento:Integer read FCod_Movimiento write SetCod_Movimiento;
    Property Cod_Tipo_Movimiento:String read FCod_Tipo_Movimiento write SetCod_Tipo_Movimiento;
    Property Numero_Partidas:Integer read FNumero_Partidas write SetNumero_Partidas;
    Property Numero_Piezas:Integer read FNumero_Piezas write SetNumero_Piezas;
    Property Total: Integer read FTotal write SetTotal;
    Property Productos:TDetalle_Movimiento read FProductos write SetProductos;
    Property Obs_Movimiento:String read FObs_Movimiento write SetObs_Movimiento;
      {$REGION 'Mis Metodos '}

      Function Insertar_Movimiento:Boolean;
      Function Eliminar_Movimiento:Boolean;
      Function Modificar_Movimiento:Boolean;
      Function Traer_Movimientos:TDataSource;
      {$ENDREGION}
 end;

implementation

{ TMovimientos }

constructor TMovimientos.Create;
begin
    Productos:=TDetalle_Movimiento.Create;
end;

function TMovimientos.Eliminar_Movimiento: Boolean;
begin
    With Operacion Do
    Begin
         SQL.Clear;
         SQL.Add('Delete From Movimientos' +
                 ' Where Cod_Movimiento = :Old_Cod_Movimiento');
         ParamByName('Old_Cod_Movimiento').AsInteger:=Cod_Movimiento;
         //---- Iniciar transa
         Transaccion.StartTransaction;
         Prepare;
         Try
              ExecQuery;
         Except on E:Exception do
         Begin
              Transaccion.Rollback;
              Raise;
              Exit;
         End; // execept
         End; // Try
    End;  // With

    Transaccion.Commit;
    Result:=True;
end;

function TMovimientos.Insertar_Movimiento: Boolean;
begin

end;

function TMovimientos.Modificar_Movimiento: Boolean;
begin

end;

procedure TMovimientos.SetCod_Movimiento(const Value: Integer);
begin
  FCod_Movimiento := Value;
end;

procedure TMovimientos.SetCod_Tipo_Movimiento(const Value: String);
begin
  FCod_Tipo_Movimiento := Value;
end;

procedure TMovimientos.SetNumero_Partidas(const Value: Integer);
begin
  FNumero_Partidas := Value;
end;

procedure TMovimientos.SetNumero_Piezas(const Value: Integer);
begin
  FNumero_Piezas := Value;
end;

procedure TMovimientos.SetObs_Movimiento(const Value: String);
begin
  FObs_Movimiento := Value;
end;

procedure TMovimientos.SetProductos(const Value: TDetalle_Movimiento);
begin
  FProductos := Value;
end;

procedure TMovimientos.SetTotal(const Value: Integer);
begin
  FTotal := Value;
end;

function TMovimientos.Traer_Movimientos: TDataSource;
begin
    Consulta.Close;
    Consulta.SQLs.SelectSQL.Clear;
    Consulta.SQLs.SelectSQL.Add('Select * From Movimientos');
    try
        Consulta.Open;
    except on E: Exception do
    begin
        Raise;
        Exit;
    end;
    end;
    Result:= TDataSource.Create(Nil);
    Result.DataSet:=Consulta;
end;

end.
Clase Detalle_Movimeinto
Código Delphi [-]
unit C_Detalle_Movimiento;

interface
Uses C_Conexion, Db, SysUtils;
Type
  TDetalle_Movimiento = class(TConexion)
  private
    FCodigo_Barras: string;
    FImporte: Currency;
    FCod_Movimiento: Integer;
    FP_Unitario: Currency;
    FCantidad: Integer;
    FCod_Detalle_Movimiento: Integer;
    procedure SetCantidad(const Value: Integer);
    procedure SetCod_Detalle_Movimiento(const Value: Integer);
    procedure SetCod_Movimiento(const Value: Integer);
    procedure SetCodigo_Barras(const Value: string);
    procedure SetImporte(const Value: Currency);
    procedure SetP_Unitario(const Value: Currency);
    Published
     Property Cod_Detalle_Movimiento:Integer read FCod_Detalle_Movimiento write SetCod_Detalle_Movimiento;
     Property Cod_Movimiento:Integer read FCod_Movimiento write SetCod_Movimiento;
     Property Codigo_Barras:string read FCodigo_Barras write SetCodigo_Barras;
     Property Cantidad:Integer read FCantidad write SetCantidad;
     Property P_Unitario:Currency read FP_Unitario write SetP_Unitario;
     Property Importe:Currency read FImporte write SetImporte;
      {$REGION 'Mis Metodos '}
      Function Insertar_Detalle_Movimiento:Boolean;
      Function Eliminar_Detalle_Movimiento:Boolean;
      Function Modificar_Detalle_Movimiento:Boolean;
      Function Traer_Detalle_Movimientos:TDataSource;
      {$ENDREGION}
  end;
implementation

{ TDetalle_Movimiento }

function TDetalle_Movimiento.Eliminar_Detalle_Movimiento: Boolean;
begin

end;

function TDetalle_Movimiento.Insertar_Detalle_Movimiento: Boolean;
begin

end;

function TDetalle_Movimiento.Modificar_Detalle_Movimiento: Boolean;
begin

end;

procedure TDetalle_Movimiento.SetCantidad(const Value: Integer);
begin
  FCantidad := Value;
end;

procedure TDetalle_Movimiento.SetCodigo_Barras(const Value: string);
begin
  FCodigo_Barras := Value;
end;

procedure TDetalle_Movimiento.SetCod_Detalle_Movimiento(const Value: Integer);
begin
  FCod_Detalle_Movimiento := Value;
end;

procedure TDetalle_Movimiento.SetCod_Movimiento(const Value: Integer);
begin
  FCod_Movimiento := Value;
end;

procedure TDetalle_Movimiento.SetImporte(const Value: Currency);
begin
  FImporte := Value;
end;

procedure TDetalle_Movimiento.SetP_Unitario(const Value: Currency);
begin
  FP_Unitario := Value;
end;

function TDetalle_Movimiento.Traer_Detalle_Movimientos: TDataSource;
begin

end;

end.
Ojala y alguien me pueda ayudar me siento perdido...
__________________
Saludos...
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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Problema tabla Maestro-detalle en la q la pk de t.detalle formad por 2cods de la maes akinom38 Varios 1 09-11-2007 19:27:44
Respecto a la relacion maestro detalle detalle ilichhernandez Conexión con bases de datos 0 15-05-2007 18:13:54
Numerar el detalle Maestro / detalle en secuencia josejose SQL 5 10-02-2007 00:27:38
Reporte Maestro/Detalle/Detalle de 4 Tablas jovehe Impresión 2 23-03-2005 01:25:02
Maestro-Detalle ;Actualizar detalle a partir de un DBgrid norberto_larios Conexión con bases de datos 1 11-09-2004 18:17:34


La franja horaria es GMT +2. Ahora son las 23:46:04.


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
Copyright 1996-2007 Club Delphi