unit U_DMCommon;

interface

uses
  U_BaseCommon, U_BaseConstants, SysUtils, Classes, DB, FIBDataSet, pFIBDataSet, FIBDatabase, pFIBDatabase, pFIBProps,
  kbmMemTable, cxEditRepositoryItems, cxExtEditRepositoryItems,
  cxDBEditRepository, cxEdit, ImgList, Controls, cxClasses;

type
  TDMCommon = class(TDataModule)
    mtConnectionRelType: TkbmMemTable;
    dsrcConnectionRelType: TDataSource;
    erPropValue: TcxEditRepository;
    EditRepositoryCheckBoxItem: TcxEditRepositoryCheckBoxItem;
    EditRepositorySpinItem: TcxEditRepositorySpinItem;
    EditRepositoryDateItem: TcxEditRepositoryDateItem;
    EditRepositoryLookupCompSateType: TcxEditRepositoryLookupComboBoxItem;
    EditRepositoryButtonItem: TcxEditRepositoryButtonItem;
    EditRepositoryComboBoxItem: TcxEditRepositoryComboBoxItem;
    EditRepositoryMRUItem: TcxEditRepositoryMRUItem;
    EditRepositoryColorComboBox: TcxEditRepositoryColorComboBox;
    EditRepositoryLookupCableCanalElementType: TcxEditRepositoryLookupComboBoxItem;
    EditRepositoryCurrencyItemForFloat: TcxEditRepositoryCurrencyItem;
    EditRepositoryMaskItemSectionSide: TcxEditRepositoryMaskItem;
    EditRepositorySpinItemInt: TcxEditRepositorySpinItem;
    EditRepositoryImageComboBoxTubeConnectKind: TcxEditRepositoryImageComboBoxItem;
    mtCompStateType: TkbmMemTable;
    dsrcCompStateType: TDataSource;
    dsrcCableCanalElementType: TDataSource;
    mtCableCanalElementType: TkbmMemTable;
    mtPlaneMaterialType: TkbmMemTable;
    dsrcPlaneMaterialType: TDataSource;
    erLookupPlaneMaterialType: TcxEditRepositoryLookupComboBoxItem;
    mtRoofHipType: TkbmMemTable;
    dsrcRoofHipType: TDataSource;
    mtRoofHipApexType: TkbmMemTable;
    dsrcRoofHipApexType: TDataSource;
    erLookupRoofHipType: TcxEditRepositoryLookupComboBoxItem;
    mtRoofHipValleyType: TkbmMemTable;
    dsrcRoofHipValleyType: TDataSource;
    erLookupRoofHipApexType: TcxEditRepositoryLookupComboBoxItem;
    erLookupRoofHipValleyType: TcxEditRepositoryLookupComboBoxItem;
    ImageList_Tree: TImageList;
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure DefineMTLookupFields(AMT: TkbmMemTable);
    procedure RelateLookupRepository(ALookup: TcxEditRepositoryLookupComboBoxItem; ADataSource: TDataSource);
  end;

var
  DMCommon: TDMCommon;

implementation

{$R *.dfm}

procedure TDMCommon.DataModuleCreate(Sender: TObject);
begin
  // Связка компонентов
  DefineMTLookupFields(mtConnectionRelType);
  AppendIDNameToMemTable(crtDirect, crtnDirect, mtConnectionRelType);
  AppendIDNameToMemTable(crtReverse, crtnReverse, mtConnectionRelType);

  // Типы условных обоначений
  DefineMTLookupFields(mtCompStateType);
  AppendIDNameToMemTable(oitProjectible, cDM_Msg1, mtCompStateType);
  AppendIDNameToMemTable(oitActive, cDM_Msg2, mtCompStateType);
  RelateLookupRepository(EditRepositoryLookupCompSateType, dsrcCompStateType);

  // Типы элементов кабельных каналов
  DefineMTLookupFields(mtCableCanalElementType);
  AppendIDNameToMemTable(contCork, ctnCork, mtCableCanalElementType);
  AppendIDNameToMemTable(contAnglePlane, ctnAnglePlane, mtCableCanalElementType);
  AppendIDNameToMemTable(contTjoin, ctnTjoin, mtCableCanalElementType);
  AppendIDNameToMemTable(contAngleIn, ctnAngleIn, mtCableCanalElementType);
  AppendIDNameToMemTable(contAngleOut, ctnAngleOut, mtCableCanalElementType);
  AppendIDNameToMemTable(contADapter, ctnADapter, mtCableCanalElementType);
  AppendIDNameToMemTable(contConnector, ctnConnector, mtCableCanalElementType);
  AppendIDNameToMemTable(contWallCork, ctnWallCork, mtCableCanalElementType);
  AppendIDNameToMemTable(contCross, ctnCross, mtCableCanalElementType);
  RelateLookupRepository(EditRepositoryLookupCableCanalElementType, dsrcCableCanalElementType);

  // Типы материалов
  DefineMTLookupFields(mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtNone, '', mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtSheetSlate, pmtnSheetSlate, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtSheetSteel, pmtnSheetSteel, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtRoller, pmtnRoller, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtTileMetal, pmtnTileMetal, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtTileCeramic, pmtnTileCeramic, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtTileBitumen, pmtnTileBitumen, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtTileInterlocking, pmtnTileInterlocking, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtOndura, pmtnOndura, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtOnduline, pmtnOnduline, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtFronton, pmtnFronton, mtPlaneMaterialType);
  AppendIDNameToMemTable(pmtRoofBase, pmtnRoofBase, mtPlaneMaterialType);
  RelateLookupRepository(erLookupPlaneMaterialType, dsrcPlaneMaterialType);

  // Тип ребра крыши
  DefineMTLookupFields(mtRoofHipType);
  AppendIDNameToMemTable(rhtNone, '', mtRoofHipType);
  AppendIDNameToMemTable(rhtApex, rhtnApex, mtRoofHipType);
  AppendIDNameToMemTable(rhtValley, rhtnValley, mtRoofHipType);
  AppendIDNameToMemTable(rhtEaves, rhtnEaves, mtRoofHipType);
  AppendIDNameToMemTable(rhtEnd, rhtnEnd, mtRoofHipType);
  AppendIDNameToMemTable(rhtJunction, rhtnJunction, mtRoofHipType);
  AppendIDNameToMemTable(rhtRoofHip, rhtnRoofHip, mtRoofHipType);
  RelateLookupRepository(erLookupRoofHipType, dsrcRoofHipType);

  // Тип конька крыши
  DefineMTLookupFields(mtRoofHipApexType);
  AppendIDNameToMemTable(rhatNone, '', mtRoofHipApexType);
  AppendIDNameToMemTable(rhatLargeRound, rhatnLargeRound, mtRoofHipApexType);
  AppendIDNameToMemTable(rhatSmallRound, rhatnSmallRound, mtRoofHipApexType);
  AppendIDNameToMemTable(rhatTrapezoidal, rhatnTrapezoidal, mtRoofHipApexType);
  AppendIDNameToMemTable(rhatTriangularStraight, rhatnTriangularStraight, mtRoofHipApexType);
  AppendIDNameToMemTable(rhatStraight, rhatnStraight, mtRoofHipApexType);
  RelateLookupRepository(erLookupRoofHipApexType, dsrcRoofHipApexType);

  // Тип ендовы крыши
  DefineMTLookupFields(mtRoofHipValleyType);
  AppendIDNameToMemTable(rhvtNone, '', mtRoofHipValleyType);
  AppendIDNameToMemTable(rhvtDeep, rhvtnDeep, mtRoofHipValleyType);
  AppendIDNameToMemTable(rhvtDecorative, rhvtnDecorative, mtRoofHipValleyType);
  AppendIDNameToMemTable(rhvtLarge, rhvtnLarge, mtRoofHipValleyType);
  RelateLookupRepository(erLookupRoofHipValleyType, dsrcRoofHipValleyType);
end;

procedure TDMCommon.DefineMTLookupFields(AMT: TkbmMemTable);
begin
  AMT.FieldDefs.Add(fnID, ftInteger);
  AMT.FieldDefs.Add(fnName, ftString, 255);
  AMT.Active := true;
end;

procedure TDMCommon.RelateLookupRepository(ALookup: TcxEditRepositoryLookupComboBoxItem; ADataSource: TDataSource);
begin
  ALookup.Properties.KeyFieldNames := fnID;
  ALookup.Properties.ListFieldNames := fnName;
  ALookup.Properties.ListSource := ADataSource;
end;

end.
