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:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22Config.xml
        33chronis
         4heaptrclog.trc
  • 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.