Ver Mensaje Individual
  #4  
Antiguo 23-06-2011
sleep25000 sleep25000 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 29
Reputación: 0
sleep25000 Va por buen camino
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.

Última edición por Casimiro Noteví fecha: 23-06-2011 a las 10:20:44. Razón: Poner etiquetas [sql] [/sql]
Responder Con Cita