Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Relacion Maestro-Detalle (https://www.clubdelphi.com/foros/showthread.php?t=74490)

sleep25000 22-06-2011 23:43:05

Relacion Maestro-Detalle
 
Buenas noches,
He creado una relacion maestro-detalles con las propiedades MasterSource y MasterFields, tengo tres DBGrid, productos, productosProveedor, Stock, de inicio todo funciona bien, pero al moverme por productos, en los demas DBGrid se van creando automaticamente registros, he probado todo, pero no hay forma de solucionarlo, me pueden ayudar? gracias.

Casimiro Noteví 22-06-2011 23:54:19

¿Y el código fuente de lo que estás haciendo?, explica con detalle lo que haces y lo que necesitas, componentes, base de datos, etc.

oscarac 22-06-2011 23:58:19

se van creando registros?
que quieres decir con eso?
cual es la finalidad de este Maestro-Detalle?
solo consultar?
adiccionar datos?
cual es el flujo?

debes ser un poquito mas explicito para tener una mejor idea y ayudarte
saludos

sleep25000 23-06-2011 10:05:15

Relacion Maestro-Detalle
 
Les Comento:
Tengo estas cuatro tablas:
Código SQL [-]
CREATE TABLE Items (
  ItemID varchar(25) NOT NULL,
  ItemType int NOT NULL,
  TaxID int NOT NULL,
  MetricUnitID int NOT NULL,
  FamilyID int NOT NULL,
  ProviderID integer NOT NULL,
  BarrCode varchar(25) NULL,
  Capacity float NOT NULL,
  ItemName varchar(255) NOT NULL,
  ItemDescription Text NULL,
  CostPrice float NULL,
  Percentage1 float NULL,
  Percentage2 float NULL,
  Percentage3 float NULL,
  PV1 float NOT NULL,
   PV2 float NOT NULL,
  PV3 float NOT NULL,
  PVP1 float NOT NULL,
   PVP2 float NOT NULL,
  PVP3 float NOT NULL,
  ImageDir varchar(255) NULL,
  BoImageStrech bit NULL,
  Weigth float NULL,
  Width float NULL,
  Length float NULL,
  Heigth float NULL,
  Warranty integer NULL,
  MinStock integer NULL,
  BoStock bit NULL,
  BoItemSerial bit NULL,
  BoDescription bit NULL,
  User int NULL,
  Date datetime NULL,
  Terminal int NULL,

 PRIMARY KEY (ItemID)
);


CREATE TABLE Stock (
  IntCodID int NOT NULL AUTO_INCREMENT,
  ItemID varchar(25) NOT NULL,
  WarehouseID int NOT NULL,
  ColorID int NULL,
  SizeID int  NULL,
  AviableQty float  NULL,
  PhisicalQty integer NULL,
  SuppliersOrderQty integer NULL,
  CustomersOrderQty integer NULL,
  LastPurchase DateTime NULL,
  LastSale DateTime NULL,
  DocumentPurchase varchar(15) NULL,
  DocumentSale varchar(15) NULL,
  User int NULL,
  Date datetime NULL,
  Terminal int NULL,

 PRIMARY KEY (IntCodID,ItemID,WareHouseID)
);
CREATE TABLE ItemBarCodes (
  ItemID  varchar(25) NOT NULL,
  BarCode varchar(25) NOT NULL,
  ItemName varchar(255) NOT NULL,
  Qty float NOT NULL,
  PriceID varchar(5) NULL,
  Price float NULL,
  User int NULL,
  Date datetime NULL,
  Terminal int NULL,
  
 PRIMARY KEY (ItemID),
); 

CREATE TABLE ItemProvider (
  ItemID varchar(25) NOT NULL,
  ItemProvider varchar(25) NOT NULL,
  ProviderID integer NOT NULL,
  CostPrice float NULL,
  BuyDate datetime NULL,
  User int NULL,
  Date datetime NULL,
  Terminal int NULL,

 PRIMARY KEY (ItemID, ItemProvider,ProviderID)  
);
De momento no tengo código, solo componentes:
TADOQuery, TDataSetProvider, TClientDataSet para cada componente, también un TDataSource enlazado al TClientDataSet Items que es la tabla maestra, y en el resto que son los detalles, através de la propiedad MasterSource apunta al TDataSource Items, y MasterField con ItemID > ItemID, en el formulario tengo cuatro DBGrid,todos enlazados con un DataSource.
Inicio el formulario y todo esta correcto, DBGrid Items está situado en el primer registro y todos los demás DBGrid muestran los registros correspondientes, selecciono otro registro en DBGrid Items y los DBGrid Detalle
esta todo correcto, pero ahora selecciono el registro anterior y los DBGrid que apuntan a ItemProvider y Stock, automaticamente se duplican los registros, selecciono otro registro, y vuelvo al registro otra vez y se vuelve a duplicar, no hay codigo, estoy trabajando con delphi 2010 y MySql, es posible que sea
por el primary Key, ya que el DBGrid ItemBarCodes no se duplica y da la casualidad que sus claves primarias son ItemID, en cambio en ItemProvider es
PRIMARY KEY (ItemID, ItemProvider,ProviderID) y en Stock PRIMARY KEY (IntCodID,ItemID,WareHouseID), espero que asi puedan entender mi problema, gracias.


La franja horaria es GMT +2. Ahora son las 23:44:53.

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