Changeset 9 for trunk/Forms


Ignore:
Timestamp:
Dec 26, 2010, 8:12:59 PM (14 years ago)
Author:
george
Message:
  • Modified: Non-visual functions moved to USystem unit.
  • Modified: Loading of object, properties and values rebuilded to general structures.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22Config.xml
        33chronis
         4heaptrclog.trc
  • trunk/Forms/UItemAdd.lfm

    r7 r9  
    44  Top = 130
    55  Width = 567
     6  ActiveControl = Panel1
    67  Caption = 'Add item'
    78  ClientHeight = 421
    89  ClientWidth = 567
    910  OnClose = FormClose
     11  OnCreate = FormCreate
     12  OnDestroy = FormDestroy
    1013  OnShow = FormShow
    1114  LCLVersion = '0.9.29'
  • trunk/Forms/UItemAdd.pas

    r7 r9  
    11unit UItemAdd;
    22
    3 {$mode objfpc}{$H+}
     3{$mode Delphi}{$H+}
    44
    55interface
     
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9    StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase;
     9   StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase, USystem;
    1010
    1111type
     
    2020    procedure ButtonSaveClick(Sender: TObject);
    2121    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     22    procedure FormCreate(Sender: TObject);
     23    procedure FormDestroy(Sender: TObject);
    2224    procedure FormShow(Sender: TObject);
    2325  private
     
    2527    { private declarations }
    2628  public
    27     { public declarations }
     29    Report: TReport;
    2830  end;
    2931
     
    5658end;
    5759
     60procedure TItemAddForm.FormCreate(Sender: TObject);
     61begin
     62  Report := TReport.Create;
     63  Report.Base := MainForm.System;
     64end;
     65
     66procedure TItemAddForm.FormDestroy(Sender: TObject);
     67begin
     68  Report.Free;
     69end;
     70
    5871procedure TItemAddForm.FormShow(Sender: TObject);
    5972begin
     
    6477procedure TItemAddForm.BuildControls;
    6578var
    66   Properties: TDbRows;
    67   Values: TDbRows;
    6879  NewControl: TControl;
    6980  LastTop: Integer;
    7081  I: Integer;
    7182  Column: Integer;
    72   ObjectInfo: TDbRows;
    7383  ValueType: Integer;
    7484const
     
    7787  LastTop := 8;
    7888  Column := 0;
    79   try
    80   ObjectInfo := TDbRows.Create;
    81   MainForm.Database.Query(ObjectInfo, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(MainForm.SelectedObject));
    82   if ObjectInfo.Count = 1 then begin
    8389
    84     for I := Panel1.ControlCount - 1 downto 0 do
    85       Panel1.Controls[I].Free;
     90  for I := Panel1.ControlCount - 1 downto 0 do
     91    Panel1.Controls[I].Free;
    8692
    87     // Load column names
    88     try
    89     Properties := TDbRows.Create;
    90     MainForm.Database.Query(Properties, 'SELECT * FROM `Property` WHERE `Object`=' +
    91       IntToStr(MainForm.SelectedObject));
    92     for I := 0 to Properties.Count - 1 do begin
     93  Report.Load(MainForm.SelectedObject, MainForm.SelectedObject.PrimaryKey + ' = ' +
     94    IntToStr(MainForm.SelectedItem));
     95
     96  // Load column names
     97    for I := 0 to Report.Columns.Count - 1 do
     98    if TReportColumn(Report.Columns[I]).ColumnName <> 'Id' then begin
    9399      NewControl := TLabel.Create(Panel1);
    94100      NewControl.Parent := Panel1;
    95101      NewControl.Top := LastTop;
    96102      NewControl.Left := Column * Width div ColumnCount + 10;
    97       TLabel(NewControl).Caption := Properties[I].Values['Name'] + ':';
     103      TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    98104
    99       ValueType := StrToInt(Properties[I].Values['Type']);
     105      ValueType := TReportColumn(Report.Columns[I]).TypeId;
    100106      if ValueType = Integer(vtInteger) then begin
    101107        NewControl := TSpinEdit.Create(Panel1);
     
    149155      if Column = 0 then LastTop := LastTop + NewControl.Height + 4;
    150156    end;
    151 
    152     finally
    153       Properties.Free;
    154     end;
    155   end else ShowMessage(SObjectNotFound);
    156   finally
    157     ObjectInfo.Free;
    158   end;
    159157end;
    160158
  • trunk/Forms/UItemEdit.lfm

    r7 r9  
    99  ClientWidth = 558
    1010  OnClose = FormClose
     11  OnCreate = FormCreate
     12  OnDestroy = FormDestroy
    1113  OnShow = FormShow
    1214  LCLVersion = '0.9.29'
  • trunk/Forms/UItemEdit.pas

    r7 r9  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit;
     9  StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, USystem;
    1010
    1111type
     
    2020    procedure ButtonSaveClick(Sender: TObject);
    2121    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     22    procedure FormCreate(Sender: TObject);
     23    procedure FormDestroy(Sender: TObject);
    2224    procedure FormShow(Sender: TObject);
    2325  private
    2426    { private declarations }
    2527  public
     28    Report: TReport;
    2629    procedure BuildControls;
    2730  end;
     
    5760end;
    5861
     62procedure TItemEditForm.FormCreate(Sender: TObject);
     63begin
     64  Report := TReport.Create;
     65  Report.Base := MainForm.System;
     66end;
     67
     68procedure TItemEditForm.FormDestroy(Sender: TObject);
     69begin
     70  Report.Free;
     71end;
     72
    5973procedure TItemEditForm.FormShow(Sender: TObject);
    6074begin
     
    6579procedure TItemEditForm.BuildControls;
    6680var
    67   Properties: TDbRows;
    6881  Values: TDbRows;
    6982  NewControl: TControl;
     
    7184  I: Integer;
    7285  Column: Integer;
    73   ObjectInfo: TDbRows;
    7486  ValueType: Integer;
    7587const
     
    7890  LastTop := 8;
    7991  Column := 0;
    80   try
    81   ObjectInfo := TDbRows.Create;
    82   MainForm.Database.Query(ObjectInfo, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(MainForm.SelectedObject));
    83   if ObjectInfo.Count = 1 then begin
     92  Report.Load(MainForm.SelectedObject, MainForm.SelectedObject.PrimaryKey + ' = ' +
     93    IntToStr(MainForm.SelectedItem));
    8494
    85     for I := Panel1.ControlCount - 1 downto 0 do
    86       Panel1.Controls[I].Free;
     95  for I := Panel1.ControlCount - 1 downto 0 do
     96    Panel1.Controls[I].Free;
    8797
    88     // Load column names
    89     try
    90     Properties := TDbRows.Create;
    91     MainForm.Database.Query(Properties, 'SELECT * FROM `Property` WHERE `Object`=' +
    92       IntToStr(MainForm.SelectedObject));
    93     Values := TDbRows.Create;
    94     MainForm.Database.Query(Values, 'SELECT * FROM `' + ObjectInfo[0].Values['Schema'] + '`.`' +
    95       ObjectInfo[0].Values['Table'] + '` WHERE ' + ObjectInfo[0].Values['PrimaryKey'] + ' = ' +
    96       IntToStr(MainForm.SelectedItem));
    97     if Values.Count = 1 then
    98     for I := 0 to Properties.Count - 1 do begin
     98  if Report.Count = 1 then
     99    for I := 0 to Report.Columns.Count - 1 do
     100    if TReportColumn(Report.Columns[I]).ColumnName <> 'Id' then begin
     101
    99102      NewControl := TLabel.Create(Panel1);
    100103      NewControl.Parent := Panel1;
    101104      NewControl.Top := LastTop;
    102105      NewControl.Left := Column * Width div ColumnCount + 10;
    103       TLabel(NewControl).Caption := Properties[I].Values['Name'] + ':';
     106      TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    104107
    105       ValueType := StrToInt(Properties[I].Values['Type']);
     108      ValueType := TReportColumn(Report.Columns[I]).TypeId;
    106109      if ValueType = Integer(vtInteger) then begin
    107110        NewControl := TSpinEdit.Create(Panel1);
     
    109112        NewControl.Top := LastTop;
    110113        NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    111         TSpinEdit(NewControl).Value := StrToInt(Values[0].Values[Properties[I].Values['ColumnName']]);
     114        TSpinEdit(NewControl).Value := StrToInt(TReportLine(Report[0]).Items[I]);
    112115        TSpinEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    113116      end else
     
    117120        NewControl.Top := LastTop;
    118121        NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    119         TDateEdit(NewControl).Date := StrToDate(Values[0].Values[Properties[I].Values['ColumnName']]);
     122        TDateEdit(NewControl).Date := StrToDate(TReportLine(Report[0]).Items[I]);
    120123        TDateEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    121124      end else
     
    125128        NewControl.Top := LastTop;
    126129        NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    127         TFloatSpinEdit(NewControl).Value := StrToFloat(Values[0].Values[Properties[I].Values['ColumnName']]);
     130        TFloatSpinEdit(NewControl).Value := StrToFloat(TReportLine(Report[0]).Items[I]);
    128131        TFloatSpinEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    129132      end else
     
    133136        NewControl.Top := LastTop;
    134137        NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    135         TEdit(NewControl).Text := Values[0].Values[Properties[I].Values['ColumnName']];
     138        TEdit(NewControl).Text := TReportLine(Report[0]).Items[I];
    136139        TEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    137140      end else
     
    148151        NewControl.Top := LastTop;
    149152        NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    150         TCheckBox(NewControl).Checked := Boolean(StrToInt(Values[0].Values[Properties[I].Values['ColumnName']]));
     153        TCheckBox(NewControl).Checked := Boolean(StrToInt(TReportLine(Report[0]).Items[I]));
    151154      end else begin
    152155        NewControl := TEdit.Create(Panel1);
     
    155158        NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    156159        TEdit(NewControl).Width := (Width div ColumnCount) div 2 - 20;
    157         TEdit(NewControl).Text := Values[0].Values[Properties[I].Values['ColumnName']];
     160        TEdit(NewControl).Text := TReportLine(Report[0]).Items[I];
    158161      end;
    159162
    160163      Column := (Column + 1) mod 2;
    161164      if Column = 0 then LastTop := LastTop + NewControl.Height + 4;
    162     end else ShowMessage(SItemNotFound);
    163     finally
    164       Values.Free;
    165       Properties.Free;
    166     end;
    167   end else ShowMessage(SObjectNotFound);
    168   finally
    169     ObjectInfo.Free;
    170   end;
     165   end;
    171166end;
    172167
  • trunk/Forms/UItemView.lfm

    r7 r9  
    11object ItemViewForm: TItemViewForm
    2   Left = 337
    3   Height = 416
    4   Top = 135
    5   Width = 552
     2  Left = 311
     3  Height = 469
     4  Top = 110
     5  Width = 626
    66  Caption = 'View item'
    7   ClientHeight = 416
    8   ClientWidth = 552
     7  ClientHeight = 469
     8  ClientWidth = 626
    99  OnClose = FormClose
     10  OnCreate = FormCreate
     11  OnDestroy = FormDestroy
    1012  OnShow = FormShow
    1113  LCLVersion = '0.9.29'
    1214  object ButtonClose: TButton
    13     Left = 472
     15    Left = 546
    1416    Height = 25
    15     Top = 386
     17    Top = 439
    1618    Width = 75
    1719    Anchors = [akRight, akBottom]
     
    2022    TabOrder = 0
    2123  end
    22   object Panel1: TPanel
    23     Left = 0
    24     Height = 378
    25     Top = 0
    26     Width = 552
    27     Align = alTop
    28     Anchors = [akLeft, akRight, akBottom]
    29     BevelOuter = bvNone
    30     TabOrder = 1
    31   end
    3224  object ButtonEdit: TButton
    33     Left = 384
     25    Left = 458
    3426    Height = 25
    35     Top = 386
     27    Top = 439
    3628    Width = 75
    3729    Anchors = [akRight, akBottom]
    3830    Caption = 'Edit'
    3931    OnClick = ButtonEditClick
     32    TabOrder = 1
     33  end
     34  object Panel1: TPanel
     35    Left = 0
     36    Height = 433
     37    Top = 0
     38    Width = 626
     39    Align = alTop
     40    Anchors = [akTop, akLeft, akRight, akBottom]
     41    BevelOuter = bvNone
     42    ClientHeight = 433
     43    ClientWidth = 626
    4044    TabOrder = 2
     45    object Panel2: TPanel
     46      Left = 0
     47      Height = 200
     48      Top = 233
     49      Width = 626
     50      Align = alBottom
     51      BevelOuter = bvNone
     52      ClientHeight = 200
     53      ClientWidth = 626
     54      TabOrder = 0
     55      object TabControl1: TTabControl
     56        Left = 0
     57        Height = 32
     58        Top = 0
     59        Width = 626
     60        Align = alTop
     61        TabIndex = 0
     62        TabOrder = 0
     63        Tabs.Strings = (
     64          'Tab1'
     65          'Tab2'
     66          'Tab3'
     67        )
     68        TabStop = False
     69      end
     70      object ListView1: TListView
     71        Left = 0
     72        Height = 168
     73        Top = 32
     74        Width = 626
     75        Align = alClient
     76        Columns = <>
     77        TabOrder = 1
     78      end
     79    end
     80    object Splitter1: TSplitter
     81      Cursor = crVSplit
     82      Left = 0
     83      Height = 3
     84      Top = 230
     85      Width = 626
     86      Align = alBottom
     87      ResizeAnchor = akBottom
     88    end
     89    object PanelControls: TPanel
     90      Left = 0
     91      Height = 230
     92      Top = 0
     93      Width = 626
     94      Align = alClient
     95      Anchors = [akLeft, akRight, akBottom]
     96      BevelOuter = bvNone
     97      TabOrder = 2
     98    end
    4199  end
    42100end
  • trunk/Forms/UItemView.pas

    r7 r9  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls, USqlDatabase;
     9  ExtCtrls, ComCtrls, USqlDatabase, USystem;
    1010
    1111type
     
    1616    ButtonClose: TButton;
    1717    ButtonEdit: TButton;
     18    ListView1: TListView;
    1819    Panel1: TPanel;
     20    Panel2: TPanel;
     21    PanelControls: TPanel;
     22    Splitter1: TSplitter;
     23    TabControl1: TTabControl;
    1924    procedure ButtonCancelClick(Sender: TObject);
    2025    procedure ButtonCloseClick(Sender: TObject);
    2126    procedure ButtonEditClick(Sender: TObject);
    2227    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     28    procedure FormCreate(Sender: TObject);
     29    procedure FormDestroy(Sender: TObject);
    2330    procedure FormShow(Sender: TObject);
    2431  private
    2532    { private declarations }
    2633  public
     34    Report: TReport;
    2735    procedure BuildControls;
    2836  end;
     
    4452begin
    4553  MainForm.PersistentForm.Save(Self);
     54end;
     55
     56procedure TItemViewForm.FormCreate(Sender: TObject);
     57begin
     58  Report := TReport.Create;
     59  Report.Base := MainForm.System;
     60end;
     61
     62procedure TItemViewForm.FormDestroy(Sender: TObject);
     63begin
     64  Report.Free;
    4665end;
    4766
     
    7089procedure TItemViewForm.BuildControls;
    7190var
    72   Properties: TDbRows;
    73   Values: TDbRows;
    7491  NewControl: TControl;
    7592  LastTop: Integer;
    7693  I: Integer;
    7794  Column: Integer;
    78   ObjectInfo: TDbRows;
    7995const
    8096  ColumnCount = 2;
     
    8298  LastTop := 8;
    8399  Column := 0;
    84   try
    85   ObjectInfo := TDbRows.Create;
    86   MainForm.Database.Query(ObjectInfo, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(MainForm.SelectedObject));
    87   if ObjectInfo.Count = 1 then begin
     100  Report.Load(MainForm.SelectedObject, MainForm.SelectedObject.PrimaryKey + ' = ' +
     101    IntToStr(MainForm.SelectedItem));
     102  for I := PanelControls.ControlCount - 1 downto 0 do
     103    PanelControls.Controls[I].Free;
    88104
    89     for I := Panel1.ControlCount - 1 downto 0 do
    90       Panel1.Controls[I].Free;
     105  TabControl1.Tabs.Clear;
     106  // Load column names
    91107
    92     // Load column names
    93     try
    94     Properties := TDbRows.Create;
    95     MainForm.Database.Query(Properties, 'SELECT * FROM `Property` WHERE `Object`=' +
    96       IntToStr(MainForm.SelectedObject));
    97     Values := TDbRows.Create;
    98     MainForm.Database.Query(Values, 'SELECT * FROM `' + ObjectInfo[0].Values['Schema'] + '`.`' +
    99       ObjectInfo[0].Values['Table'] + '` WHERE ' + ObjectInfo[0].Values['PrimaryKey'] + ' = ' +
    100       IntToStr(MainForm.SelectedItem));
    101     if Values.Count = 1 then
    102     for I := 0 to Properties.Count - 1 do begin
    103       NewControl := TLabel.Create(Panel1);
    104       NewControl.Parent := Panel1;
    105       NewControl.Top := LastTop;
    106       NewControl.Left := Column * Width div ColumnCount + 10;
    107       TLabel(NewControl).Caption := Properties[I].Values['Name'] + ':';
     108  if Report.Count = 1 then
     109  for I := 0 to Report.Columns.Count - 1 do
     110  if TReportColumn(Report.Columns[I]).TypeId = 20 then begin
     111    TabControl1.Tabs.Add(TReportColumn(Report.Columns[I]).Caption);
     112  end else begin
     113    NewControl := TLabel.Create(PanelControls);
     114    NewControl.Parent := PanelControls;
     115    NewControl.Top := LastTop;
     116    NewControl.Left := Column * Width div ColumnCount + 10;
     117    TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    108118
    109       NewControl := TLabel.Create(Panel1);
    110       NewControl.Parent := Panel1;
    111       NewControl.Top := LastTop;
    112       NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    113       TLabel(NewControl).Caption := Values[0].Values[Properties[I].Values['ColumnName']];
     119    NewControl := TLabel.Create(PanelControls);
     120    NewControl.Parent := PanelControls;
     121    NewControl.Top := LastTop;
     122    NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
     123    TLabel(NewControl).Caption := TReportLine(Report[0]).Items[I];
    114124
    115       Column := (Column + 1) mod 2;
    116       if Column = 0 then LastTop := LastTop + NewControl.Height + 4;
    117     end else ShowMessage(SItemNotFound);
    118     finally
    119       Values.Free;
    120       Properties.Free;
    121     end;
    122   end else ShowMessage(SObjectNotFound);
    123   finally
    124     ObjectInfo.Free;
     125    Column := (Column + 1) mod 2;
     126    if Column = 0 then LastTop := LastTop + 24;
    125127  end;
     128  Panel2.Visible := TabControl1.Tabs.Count > 0;
    126129end;
    127130
  • trunk/Forms/UMainForm.lfm

    r8 r9  
    66  ActiveControl = Panel1
    77  Caption = 'ChronIS'
    8   ClientHeight = 422
     8  ClientHeight = 418
    99  ClientWidth = 649
    1010  Menu = MainMenu1
     
    1616  object Panel1: TPanel
    1717    Left = 0
    18     Height = 422
     18    Height = 418
    1919    Top = 0
    2020    Width = 184
    2121    Align = alLeft
    2222    BevelOuter = bvNone
    23     ClientHeight = 422
     23    ClientHeight = 418
    2424    ClientWidth = 184
    2525    TabOrder = 0
    2626    object Label1: TLabel
    2727      Left = 7
    28       Height = 14
     28      Height = 18
    2929      Top = 4
    30       Width = 44
     30      Width = 51
    3131      Caption = 'Groups:'
    3232      ParentColor = False
    3333    end
    3434    object TreeView1: TTreeView
    35       Left = 8
    36       Height = 398
     35      Left = 4
     36      Height = 394
    3737      Top = 19
    38       Width = 176
     38      Width = 180
    3939      Anchors = [akTop, akLeft, akRight, akBottom]
    40       DefaultItemHeight = 16
     40      DefaultItemHeight = 19
    4141      Images = ImageListActions
    4242      ReadOnly = True
     
    4848  object Panel2: TPanel
    4949    Left = 189
    50     Height = 422
     50    Height = 418
    5151    Top = 0
    5252    Width = 460
    5353    Align = alClient
    5454    BevelOuter = bvNone
    55     ClientHeight = 422
     55    ClientHeight = 418
    5656    ClientWidth = 460
    5757    TabOrder = 1
    5858    object Label2: TLabel
    59       Left = 11
    60       Height = 14
     59      Left = 2
     60      Height = 18
    6161      Top = 4
    62       Width = 46
     62      Width = 54
    6363      Caption = 'Reports:'
    6464      ParentColor = False
    6565    end
    6666    object ListView1: TListView
    67       Left = 3
    68       Height = 366
     67      Left = 2
     68      Height = 362
    6969      Top = 19
    70       Width = 450
     70      Width = 456
    7171      Anchors = [akTop, akLeft, akRight, akBottom]
    7272      Columns = <>
     
    8686      Left = 3
    8787      Height = 25
    88       Top = 393
     88      Top = 389
    8989      Width = 75
    9090      Action = AItemAdd
     
    9595      Left = 83
    9696      Height = 25
    97       Top = 393
     97      Top = 389
    9898      Width = 75
    9999      Action = AItemDelete
     
    104104  object Splitter1: TSplitter
    105105    Left = 184
    106     Height = 422
     106    Height = 418
    107107    Top = 0
    108108    Width = 5
  • trunk/Forms/UMainForm.pas

    r8 r9  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
     8  Registry, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    99  StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite,
    10   UPersistentForm, UTreeState, SpecializedList;
     10  UPersistentForm, UTreeState, SpecializedList, URegistry, USystem;
    1111
    1212const
     
    1414
    1515type
    16   TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,
    17   vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword,
    18   vtReference, vtDate, vtTime, vtColor);
    19 
    20   { TReportLine }
    21 
    22   TReportLine = class
    23     Id: Integer;
    24     Items: TListString;
    25     constructor Create;
    26     destructor Destroy; override;
    27   end;
    28 
    2916  { TMainForm }
    3017
     
    9683    OriginalWindowState: TWindowState;
    9784    ScreenBounds: TRect;
     85    RegistryKey: string;
     86    RegistryRootKey: HKEY;
    9887    procedure LoadConfiguration;
     88    procedure LoadFromRegistry;
     89    procedure SaveToRegistry;
    9990  public
    100     SelectedObject: Integer;
     91    SelectedObjectId: Integer;
     92    SelectedObject: TChronisObject;
    10193    SelectedItem: Integer;
    10294    PersistentForm: TPersistentForm;
    103     Database: TSQLDatabase;
    10495    TreeState: TTreeState;
    105     Report: TListObject;
     96    System: TChronisBase;
     97    Report: TReport;
    10698    procedure LoadTree;
    10799    procedure LoadItemList;
     
    121113uses
    122114  UItemView, UItemEdit, UItemAdd;
    123 
    124 { TReportLine }
    125 
    126 constructor TReportLine.Create;
    127 begin
    128   Items := TListString.Create;
    129 end;
    130 
    131 destructor TReportLine.Destroy;
    132 begin
    133   Items.Free;
    134   inherited Destroy;
    135 end;
    136115
    137116{$R *.lfm}
     
    157136        with ChildNodes[I3] do begin
    158137          if NodeName = 'hostname' then
    159             Database.HostName := TextContent;
     138            System.Database.HostName := TextContent;
    160139          if NodeName = 'schema' then
    161             Database.Database := TextContent;
     140            System.Database.Database := TextContent;
    162141          if NodeName = 'username' then
    163             Database.UserName := TextContent;
     142            System.Database.UserName := TextContent;
    164143          if NodeName = 'password' then
    165             Database.Password := TextContent;
     144            System.Database.Password := TextContent;
    166145        end;
    167146      end;
     
    172151end;
    173152
     153procedure TMainForm.LoadFromRegistry;
     154begin
     155  with TRegistryEx.Create do
     156  try
     157    RootKey := RegistryRootKey;
     158    OpenKey(RegistryKey, True);
     159    Panel1.Width := ReadIntegerWithDefault('GroupTreeWidth', 200);
     160  finally
     161    Free;
     162  end;
     163end;
     164
     165procedure TMainForm.SaveToRegistry;
     166begin
     167  with TRegistryEx.Create do
     168  try
     169    RootKey := RegistryRootKey;
     170    OpenKey(RegistryKey, True);
     171    WriteInteger('GroupTreeWidth', Panel1.Width);
     172  finally
     173    Free;
     174  end;
     175end;
     176
    174177procedure TMainForm.FormCreate(Sender: TObject);
    175178begin
    176   Database := TSqlDatabase.Create;
     179  System := TChronisBase.Create;
     180  System.Database := TSqlDatabase.Create;
    177181  LoadConfiguration;
    178   Database.Connect;
     182  System.Database.Connect;
    179183  TreeState := TTreeState.Create;
     184  Report := TReport.Create;
     185  Report.Base := System;
     186  SelectedObject := TChronisObject.Create;
     187  SelectedObject.Base := System;
     188  RegistryRootKey := HKEY_CURRENT_USER;
     189  RegistryKey := '\Software\Chronosoft\Chronis';
    180190  PersistentForm := TPersistentForm.Create;
    181   Report := TListObject.Create;
     191  PersistentForm.RegistryKey := RegistryKey;
    182192end;
    183193
     
    186196  Report.Free;
    187197  TreeState.Free;
    188   Database.Free;
    189198  PersistentForm.Free;
     199  System.Free;
    190200end;
    191201
     
    193203begin
    194204  PersistentForm.Save(Self);
     205  SaveToRegistry;
    195206end;
    196207
     
    208219begin
    209220  if Assigned(TreeView1.Selected) then begin
    210     SelectedObject := 9;
     221    SelectedObjectId := 9;
    211222    SelectedItem := Integer(TreeView1.Selected.Data);
    212223    ItemEditForm.Show;
     
    222233begin
    223234  if Assigned(TreeView1.Selected) then begin
    224     SelectedObject := 8;
     235    SelectedObjectId := 8;
    225236    SelectedItem := Integer(TreeView1.Selected.Data);
    226237    ItemEditForm.Show;
     
    274285  PersistentForm.Load(Self);
    275286  LoadTree;
     287  LoadFromRegistry;
    276288end;
    277289
     
    351363    try
    352364      DbRows := TDbRows.Create;
    353       Database.Query(DbRows, 'SELECT * FROM `ObjectGroup`');
     365      System.Database.Query(DbRows, 'SELECT * FROM `ObjectGroup`');
    354366      for I := 0 to DbRows.Count - 1 do begin
    355367        NewNode := AddChild(TopItem, DbRows[I].Values['Name']);
     
    359371        try
    360372          ObjectDbRows := TDbRows.Create;
    361           Database.Query(ObjectDbRows, 'SELECT * FROM `Object` WHERE `Group`=' + DbRows[I].Values['Id']);
     373          System.Database.Query(ObjectDbRows, 'SELECT * FROM `Object` WHERE `Group`=' + DbRows[I].Values['Id']);
    362374          for O := 0 to ObjectDbRows.Count - 1 do begin
    363375            NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']);
     
    380392procedure TMainForm.LoadItemList;
    381393var
    382   DbRows: TDbRows;
    383   Properties: TDbRows;
    384   Values: TDbRows;
     394  NewColumn: TListColumn;
    385395  I: Integer;
    386   C: Integer;
    387   NewItem: TReportLine;
    388   NewColumn: TListColumn;
    389 begin
    390   SelectedObject := 0;
     396begin
     397  SelectedObjectId := 0;
    391398  if Assigned(TreeView1.Selected) then
    392399  with ListView1 do begin
    393400    Visible := True;
    394     Report.Clear;
    395     try
    396     DbRows := TDbRows.Create;
    397     Database.Query(DbRows, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(Integer(TreeView1.Selected.Data)));
    398     if DbRows.Count = 1 then begin
    399       SelectedObject := StrToInt(DbRows[0].Values['Id']);
    400 
    401       // Load column names
    402       try
    403         Properties := TDbRows.Create;
    404         Database.Query(Properties, 'SELECT * FROM `Property` WHERE `Object`=' +
    405           DbRows[0].Values['Id']);
    406         Columns.Clear;
    407         NewColumn := Columns.Add;
    408         NewColumn.Caption := 'Id';
    409         for I := 0 to Properties.Count - 1 do begin
    410           NewColumn := Columns.Add;
    411           NewColumn.Caption := Properties[I].Values['Name'];
    412         end;
    413 
    414         ListView1Resize(Self);
    415 
    416         // Load items
    417         Values := TDbRows.Create;
    418         Database.Query(Values, 'SELECT * FROM `' + DbRows[0].Values['Schema'] + '`.`' +
    419           DbRows[0].Values['Table'] + '`');
    420         for I := 0 to Values.Count - 1 do begin
    421           NewItem := TReportLine.Create;
    422           NewItem.Items.Add(Values[I].Values[DbRows[0].Values['PrimaryKey']]);
    423           NewItem.Id := StrToInt(Values[I].Values[DbRows[0].Values['PrimaryKey']]);
    424           for C := 0 to Properties.Count - 1 do begin
    425             NewItem.Items.Add(Values[I].Values[Properties[C].Values['ColumnName']]);
    426           end;
    427           Report.Add(NewItem);
    428         end;
    429         Items.Count := Values.Count;
    430         Refresh;
    431       finally
    432         Properties.Free;
    433         Values.Free;
    434       end;
     401    SelectedObject.Load(Integer(TreeView1.Selected.Data));
     402    Report.Load(SelectedObject);
     403
     404    Columns.Clear;
     405    for I := 0 to Report.Columns.Count - 1 do begin
     406      NewColumn := Columns.Add;
     407      NewColumn.Caption := TReportColumn(Report.Columns[I]).Caption;
    435408    end;
    436     finally
    437       DbRows.Free;
    438     end;
    439   end;
     409    Items.Count := Report.Count;
     410    Refresh;
     411  end;
     412  ListView1Resize(Self);
    440413end;
    441414
Note: See TracChangeset for help on using the changeset viewer.