Changeset 14 for trunk/Forms


Ignore:
Timestamp:
Jun 10, 2011, 2:16:52 PM (13 years ago)
Author:
george
Message:
  • Added: Classes for base data types.
Location:
trunk/Forms
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UItemAdd.pas

    r12 r14  
    3636
    3737uses
    38   UMainForm;
     38  UMainForm, UDataTypes, UCore;
    3939
    4040{$R *.lfm}
     
    6161begin
    6262  Report := TReport.Create;
    63   Report.Base := MainForm.System;
     63  Report.Base := Core.System;
    6464end;
    6565
     
    7777procedure TItemAddForm.BuildControls;
    7878var
    79   NewControl: TControl;
     79  NewControl: TWinControl;
    8080  LastTop: Integer;
    8181  I: Integer;
    8282  Column: Integer;
    8383  ValueType: Integer;
     84  NewLabel: TLabel;
     85  DataType: TDataType;
    8486const
    8587  ColumnCount = 2;
     
    9799    for I := 0 to Report.Columns.Count - 1 do
    98100    if TReportColumn(Report.Columns[I]).ColumnName <> 'Id' then begin
    99       NewControl := TLabel.Create(Panel1);
     101      NewLabel := TLabel.Create(Panel1);
     102      NewLabel.Parent := Panel1;
     103      NewLabel.Top := LastTop;
     104      NewLabel.Left := Column * Width div ColumnCount + 10;
     105      NewLabel.Caption := TReportColumn(Report.Columns[I]).Caption + ':';
     106
     107      DataType := TReportColumn(Report.Columns[I]).CustomType;
     108      NewControl := DataType.CreateControl(Panel1);
     109      DataType.SetDefault;
     110      DataType.SetupControl(NewControl);
    100111      NewControl.Parent := Panel1;
    101112      NewControl.Top := LastTop;
    102       NewControl.Left := Column * Width div ColumnCount + 10;
    103       TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    104 
    105       ValueType := TReportColumn(Report.Columns[I]).TypeDef.TypeIndex;
    106       if ValueType = Integer(vtInteger) then begin
    107         NewControl := TSpinEdit.Create(Panel1);
    108         NewControl.Parent := Panel1;
    109         NewControl.Top := LastTop;
    110         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    111         TSpinEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    112       end else
    113       if ValueType = Integer(vtDate) then begin
    114         NewControl := TDateEdit.Create(Panel1);
    115         NewControl.Parent := Panel1;
    116         NewControl.Top := LastTop;
    117         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    118         TDateEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    119       end else
    120       if ValueType = Integer(vtFloat) then begin
    121         NewControl := TFloatSpinEdit.Create(Panel1);
    122         NewControl.Parent := Panel1;
    123         NewControl.Top := LastTop;
    124         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    125         TFloatSpinEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    126       end else
    127       if ValueType = Integer(vtString) then begin
    128         NewControl := TEdit.Create(Panel1);
    129         NewControl.Parent := Panel1;
    130         NewControl.Top := LastTop;
    131         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    132         TEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    133       end else
    134       if ValueType = Integer(vtPassword) then begin
    135         NewControl := TMaskEdit.Create(Panel1);
    136         NewControl.Parent := Panel1;
    137         NewControl.Top := LastTop;
    138         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    139         TMaskEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    140       end else
    141       if ValueType = Integer(vtBoolean) then begin
    142         NewControl := TCheckBox.Create(Panel1);
    143         NewControl.Parent := Panel1;
    144         NewControl.Top := LastTop;
    145         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    146       end else begin
    147         NewControl := TEdit.Create(Panel1);
    148         NewControl.Parent := Panel1;
    149         NewControl.Top := LastTop;
    150         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    151         TEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    152       end;
     113      NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
     114      NewControl.Width := (Width div ColumnCount) div 2 - 20;
    153115
    154116      Column := (Column + 1) mod 2;
  • trunk/Forms/UItemEdit.pas

    r12 r14  
    3636
    3737uses
    38   UMainForm;
     38  UMainForm, UDataTypes, UCore;
    3939
    4040{$R *.lfm}
     
    6363begin
    6464  Report := TReport.Create;
    65   Report.Base := MainForm.System;
     65  Report.Base := Core.System;
    6666end;
    6767
     
    8080var
    8181  Values: TDbRows;
    82   NewControl: TControl;
    8382  LastTop: Integer;
    8483  I: Integer;
    8584  Column: Integer;
    86   ValueType: Integer;
     85  DataType: TDataType;
     86  NewControl: TWinControl;
     87  NewLabel: TLabel;
    8788const
    8889  ColumnCount = 2;
     
    100101    if TReportColumn(Report.Columns[I]).ColumnName <> 'Id' then begin
    101102
    102       NewControl := TLabel.Create(Panel1);
     103      NewLabel := TLabel.Create(Panel1);
     104      NewLabel.Parent := Panel1;
     105      NewLabel.Top := LastTop;
     106      NewLabel.Left := Column * Width div ColumnCount + 10;
     107      NewLabel.Caption := TReportColumn(Report.Columns[I]).Caption + ':';
     108
     109      DataType := TReportColumn(Report.Columns[I]).CustomType;
     110      NewControl := DataType.CreateControl(Panel1);
     111      DataType.Load(TReportLine(Report[0]).Items[I]);
     112      DataType.SetupControl(NewControl);
    103113      NewControl.Parent := Panel1;
    104114      NewControl.Top := LastTop;
    105       NewControl.Left := Column * Width div ColumnCount + 10;
    106       TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    107 
    108       ValueType := TReportColumn(Report.Columns[I]).TypeDef.TypeIndex;
    109       if ValueType = Integer(vtInteger) then begin
    110         NewControl := TSpinEdit.Create(Panel1);
    111         NewControl.Parent := Panel1;
    112         NewControl.Top := LastTop;
    113         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    114         TSpinEdit(NewControl).Value := StrToInt(TReportLine(Report[0]).Items[I]);
    115         TSpinEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    116       end else
    117       if ValueType = Integer(vtDate) then begin
    118         NewControl := TDateEdit.Create(Panel1);
    119         NewControl.Parent := Panel1;
    120         NewControl.Top := LastTop;
    121         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    122         TDateEdit(NewControl).Date := StrToDate(TReportLine(Report[0]).Items[I]);
    123         TDateEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    124       end else
    125       if ValueType = Integer(vtFloat) then begin
    126         NewControl := TFloatSpinEdit.Create(Panel1);
    127         NewControl.Parent := Panel1;
    128         NewControl.Top := LastTop;
    129         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    130         TFloatSpinEdit(NewControl).Value := StrToFloat(TReportLine(Report[0]).Items[I]);
    131         TFloatSpinEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    132       end else
    133       if ValueType = Integer(vtString) then begin
    134         NewControl := TEdit.Create(Panel1);
    135         NewControl.Parent := Panel1;
    136         NewControl.Top := LastTop;
    137         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    138         TEdit(NewControl).Text := TReportLine(Report[0]).Items[I];
    139         TEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    140       end else
    141       if ValueType = Integer(vtPassword) then begin
    142         NewControl := TMaskEdit.Create(Panel1);
    143         NewControl.Parent := Panel1;
    144         NewControl.Top := LastTop;
    145         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    146         TMaskEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    147       end else
    148       if ValueType = Integer(vtBoolean) then begin
    149         NewControl := TCheckBox.Create(Panel1);
    150         NewControl.Parent := Panel1;
    151         NewControl.Top := LastTop;
    152         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    153         TCheckBox(NewControl).Checked := Boolean(StrToInt(TReportLine(Report[0]).Items[I]));
    154       end else begin
    155         NewControl := TEdit.Create(Panel1);
    156         NewControl.Parent := Panel1;
    157         NewControl.Top := LastTop;
    158         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    159         TEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    160         TEdit(NewControl).Text := TReportLine(Report[0]).Items[I];
    161       end;
     115      NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
     116      NewControl.Width := (Width div ColumnCount) div 2 - 20;
    162117
    163118      Column := (Column + 1) mod 2;
  • trunk/Forms/UItemView.pas

    r12 r14  
    4242
    4343uses
    44   UMainForm, UItemEdit;
     44  UMainForm, UItemEdit, UDataTypes, UCore;
    4545
    4646{$R *.lfm}
     
    5757begin
    5858  Report := TReport.Create;
    59   Report.Base := MainForm.System;
     59  Report.Base := Core.System;
    6060end;
    6161
     
    9393  I: Integer;
    9494  Column: Integer;
     95  DataType: TDataType;
    9596const
    9697  ColumnCount = 2;
     
    107108
    108109  if Report.Count = 1 then
    109   for I := 0 to Report.Columns.Count - 1 do
    110   if TReportColumn(Report.Columns[I]).TypeDef.TypeIndex = Integer(vtPointer) then begin
     110  for I := 0 to Report.Columns.Count - 1 do begin
     111    DataType := TReportColumn(Report.Columns[I]).CustomType;
     112  if DataType is TDataTypeRelationOne then begin
    111113    TabControl1.Tabs.Add(TReportColumn(Report.Columns[I]).Caption);
    112114  end else begin
     
    126128    if Column = 0 then LastTop := LastTop + 24;
    127129  end;
     130  end;
    128131  Panel2.Visible := TabControl1.Tabs.Count > 0;
    129132end;
  • trunk/Forms/UMainForm.pas

    r13 r14  
    104104    PersistentForm: TPersistentForm;
    105105    TreeState: TTreeState;
    106     System: TChronisBase;
    107106    Report: TReport;
    108107    procedure LoadTree;
     
    138137    OpenKey(RegistryKey, True);
    139138    Panel1.Width := ReadIntegerWithDefault('GroupTreeWidth', 200);
    140     System.Database.Database := ReadStringWithDefault('DatabaseSchema', 'chronis');
    141     System.Database.Hostname := ReadStringWithDefault('DatabaseHostName', 'localhost');
    142     System.Database.UserName := ReadStringWithDefault('DatabaseUserName', 'chronis');
    143     System.Database.Password := ReadStringWithDefault('DatabasePassword', '');
     139    Core.System.Database.Database := ReadStringWithDefault('DatabaseSchema', 'chronis');
     140    Core.System.Database.Hostname := ReadStringWithDefault('DatabaseHostName', 'localhost');
     141    Core.System.Database.UserName := ReadStringWithDefault('DatabaseUserName', 'chronis');
     142    Core.System.Database.Password := ReadStringWithDefault('DatabasePassword', '');
    144143    with Core.CoolTranslator1 do
    145144      Language := Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''));
     
    156155    OpenKey(RegistryKey, True);
    157156    WriteInteger('GroupTreeWidth', Panel1.Width);
    158     WriteString('DatabaseSchema', System.Database.Database);
    159     WriteString('DatabaseHostName', System.Database.Hostname);
    160     WriteString('DatabaseUserName', System.Database.UserName);
    161     WriteString('DatabasePassword', System.Database.Password);
     157    WriteString('DatabaseSchema', Core.System.Database.Database);
     158    WriteString('DatabaseHostName', Core.System.Database.Hostname);
     159    WriteString('DatabaseUserName', Core.System.Database.UserName);
     160    WriteString('DatabasePassword', Core.System.Database.Password);
    162161    with Core.CoolTranslator1 do
    163162      WriteString('LanguageCode', Language.Code);
     
    177176  I: Integer;
    178177begin
    179   with System do
     178  with Core.System do
    180179  try
    181180    DbRows := TDbRows.Create;
     
    245244      '`Name` varchar(255) NOT NULL,' +
    246245      '`DbType` varchar(255) NOT NULL,' +
    247       '`TypeIndex` int(11) NOT NULL,' +
    248246      'PRIMARY KEY (`Id`)' +
    249247      ') ENGINE=InnoDB  DEFAULT CHARSET=utf8');
     
    326324    end;
    327325
    328     if Tables.IndexOf(CustomType) = -1 then begin
    329       Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + CustomType + '` ( ' +
     326    if Tables.IndexOf(CustomTypeTableName) = -1 then begin
     327      Database.Query(DbRows, 'CREATE TABLE IF NOT EXISTS `' + CustomTypeTableName + '` ( ' +
    330328        '`Id` int(11) NOT NULL AUTO_INCREMENT,' +
    331329        '`Type` int NOT NULL,' +
     
    373371  EnumId: Integer;
    374372begin
    375   with System do begin
     373  with Core.System do begin
    376374  TypeNumber := AddType('Number', 'INT', vtInteger);
    377375  TypeString := AddType('String', 'VARCHAR(255)', vtString);
     
    407405  GroupId := AddObjectGroup('System');
    408406
    409   ObjectId := AddObject('Object groups', 'ObjectGroup', System.Database.Database, GroupId);
     407  ObjectId := AddObject('Object groups', 'ObjectGroup', Core.System.Database.Database, GroupId);
    410408    AddPropertyString(ObjectId, 'Name', 'Name');
    411   ObjectId := AddObject('Objects', 'Object', System.Database.Database, GroupId);
     409  ObjectId := AddObject('Objects', 'Object', Core.System.Database.Database, GroupId);
    412410    AddPropertyString(ObjectId, 'Name', 'Name');
    413411    AddPropertyNumber(ObjectId, 'Group', 'Group');
     
    416414    AddPropertyString(ObjectId, 'Primary key', 'PrimaryKey');
    417415    AddPropertyNumber(ObjectId, 'Sequence', 'Sequence');
    418   ObjectId := AddObject('Property types', 'Type', System.Database.Database, GroupId);
     416  ObjectId := AddObject('Property types', 'Type', Core.System.Database.Database, GroupId);
    419417    AddPropertyString(ObjectId, 'Name', 'Name');
    420418    AddPropertyString(ObjectId, 'Type', 'DbType');
    421     AddPropertyNumber(ObjectId, 'Type index', 'TypeIndex');
    422419    AddPropertyNumber(ObjectId, 'Parent', 'Parent');
    423   ObjectId := AddObject('Property groups', 'PropertyGroup', System.Database.Database, GroupId);
    424   ObjectId := AddObject('Properties', 'Property', System.Database.Database, GroupId);
     420  ObjectId := AddObject('Property groups', 'PropertyGroup', Core.System.Database.Database, GroupId);
     421  ObjectId := AddObject('Properties', 'Property', Core.System.Database.Database, GroupId);
    425422    AddPropertyString(ObjectId, 'Name', 'Name');
    426423    AddPropertyNumber(ObjectId, 'Object', 'Object');
    427     AddPropertyNumber(ObjectId, 'PropertyGroup', 'PropertyGroup');
    428     AddPropertyNumber(ObjectId, 'Type', 'Type');
     424    AddPropertyNumber(ObjectId, 'Property group', 'PropertyGroup');
     425    AddPropertyNumber(ObjectId, 'Custom type', 'CustomType');
    429426    AddProperty(ObjectId, 'Editable', 'Editable', TypeBoolean);
    430     AddPropertyString(ObjectId, 'ColumnName', 'ColumnName');
     427    AddPropertyString(ObjectId, 'Column name', 'ColumnName');
    431428  end;
    432429end;
     
    434431procedure TMainForm.FormCreate(Sender: TObject);
    435432begin
    436   System := TChronisBase.Create;
    437   System.Database := TSqlDatabase.Create;
    438433  TreeState := TTreeState.Create;
    439434  Report := TReport.Create;
    440   Report.Base := System;
     435  Report.Base := Core.System;
    441436  SelectedObject := TChronisObject.Create;
    442   SelectedObject.Base := System;
     437  SelectedObject.Base := Core.System;
    443438  RegistryRootKey := HKEY_CURRENT_USER;
    444439  RegistryKey := '\Software\' + ApplicationInfo.CompanyName + '\' +
     
    453448  TreeState.Free;
    454449  PersistentForm.Free;
    455   System.Free;
    456450end;
    457451
     
    564558  PersistentForm.Load(Self);
    565559  LoadFromRegistry;
    566   System.Database.Connect;
     560  Core.System.Database.Connect;
    567561  InitStructure;
    568   System.LoadTypes;
     562  Core.System.LoadTypes;
    569563  LoadTree;
    570564end;
     
    645639    try
    646640      DbRows := TDbRows.Create;
    647       System.Database.Query(DbRows, 'SELECT * FROM `' + ObjectGroupTable + '`');
     641      Core.System.Database.Query(DbRows, 'SELECT * FROM `' + ObjectGroupTable + '`');
    648642      for I := 0 to DbRows.Count - 1 do begin
    649643        NewNode := AddChild(TopItem, DbRows[I].Values['Name']);
     
    653647        try
    654648          ObjectDbRows := TDbRows.Create;
    655           System.Database.Query(ObjectDbRows, 'SELECT * FROM `' + ObjectTable + '` WHERE `Group`=' + DbRows[I].Values['Id']);
     649          Core.System.Database.Query(ObjectDbRows, 'SELECT * FROM `' + ObjectTable + '` WHERE `Group`=' + DbRows[I].Values['Id']);
    656650          for O := 0 to ObjectDbRows.Count - 1 do begin
    657651            NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']);
Note: See TracChangeset for help on using the changeset viewer.