Changeset 8 for trunk/Forms


Ignore:
Timestamp:
Dec 25, 2010, 10:28:06 PM (14 years ago)
Author:
george
Message:
 
Location:
trunk/Forms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.lfm

    r7 r8  
    11object MainForm: TMainForm
    2   Left = 332
     2  Left = 255
    33  Height = 445
    4   Top = 106
     4  Top = 75
    55  Width = 649
    66  ActiveControl = Panel1
     
    7171      Anchors = [akTop, akLeft, akRight, akBottom]
    7272      Columns = <>
     73      OwnerData = True
    7374      PopupMenu = PopupMenuItem
    7475      ReadOnly = True
     
    7677      TabOrder = 0
    7778      ViewStyle = vsReport
     79      OnData = ListView1Data
    7880      OnDblClick = ListView1DblClick
    7981      OnKeyPress = ListView1KeyPress
  • trunk/Forms/UMainForm.pas

    r7 r8  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    99  StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite,
    10   UPersistentForm, UTreeState;
     10  UPersistentForm, UTreeState, SpecializedList;
    1111
    1212const
     
    1414
    1515type
    16   TValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,
     16  TDbValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,
    1717  vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword,
    1818  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;
    1928
    2029  { TMainForm }
     
    7685    procedure FormDestroy(Sender: TObject);
    7786    procedure FormShow(Sender: TObject);
     87    procedure ListView1Data(Sender: TObject; Item: TListItem);
    7888    procedure ListView1DblClick(Sender: TObject);
    7989    procedure ListView1KeyPress(Sender: TObject; var Key: char);
     
    93103    Database: TSQLDatabase;
    94104    TreeState: TTreeState;
     105    Report: TListObject;
    95106    procedure LoadTree;
    96107    procedure LoadItemList;
     
    103114  SItemNotFound = 'Item not found';
    104115  SObjectNotFound = 'Object not found';
     116  SGroup = 'Groups';
    105117
    106118
     
    109121uses
    110122  UItemView, UItemEdit, UItemAdd;
     123
     124{ TReportLine }
     125
     126constructor TReportLine.Create;
     127begin
     128  Items := TListString.Create;
     129end;
     130
     131destructor TReportLine.Destroy;
     132begin
     133  Items.Free;
     134  inherited Destroy;
     135end;
    111136
    112137{$R *.lfm}
     
    154179  TreeState := TTreeState.Create;
    155180  PersistentForm := TPersistentForm.Create;
     181  Report := TListObject.Create;
    156182end;
    157183
    158184procedure TMainForm.FormDestroy(Sender: TObject);
    159185begin
     186  Report.Free;
    160187  TreeState.Free;
    161188  Database.Free;
     
    249276end;
    250277
     278procedure TMainForm.ListView1Data(Sender: TObject; Item: TListItem);
     279var
     280  I: Integer;
     281begin
     282  if Item.Index < Report.Count then
     283  with TReportLine(Report[Item.Index]) do begin
     284    Item.Caption := Items[0];
     285    for I := 1 to Items.Count - 1 do
     286      Item.SubItems.Add(Items[I]);
     287  end;
     288end;
     289
    251290procedure TMainForm.ListView1DblClick(Sender: TObject);
    252291begin
     
    271310begin
    272311  if Assigned(ListView1.Selected) then
    273     SelectedItem := Integer(ListView1.Selected.Data)
     312    SelectedItem := TReportLine(Report[ListView1.Selected.Index]).Id
    274313    else SelectedItem := 0;
    275314
     
    307346    TreeState.SaveTree(TreeView1);
    308347    Clear;
    309     AddChild(nil, 'Skupiny');
     348    AddChild(nil, SGroup);
    310349    TopItem.ImageIndex := 0;
    311350    TopItem.SelectedIndex := 0;
     
    346385  I: Integer;
    347386  C: Integer;
    348   NewItem: TListItem;
     387  NewItem: TReportLine;
    349388  NewColumn: TListColumn;
    350389begin
    351390  SelectedObject := 0;
    352   if Assigned(TreeView1.Selected)then
    353   with ListView1, Items do begin
     391  if Assigned(TreeView1.Selected) then
     392  with ListView1 do begin
    354393    Visible := True;
    355     Clear;
     394    Report.Clear;
    356395    try
    357396    DbRows := TDbRows.Create;
     
    372411          NewColumn.Caption := Properties[I].Values['Name'];
    373412        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;
    374431      finally
    375432        Properties.Free;
    376       end;
    377 
    378       ListView1Resize(Self);
    379 
    380       // Load items
    381       try
    382       Values := TDbRows.Create;
    383       Database.Query(Values, 'SELECT * FROM `' + DbRows[0].Values['Schema'] + '`.`' +
    384         DbRows[0].Values['Table'] + '`');
    385       for I := 0 to Values.Count - 1 do begin
    386         NewItem := Items.Add;
    387         NewItem.Caption := Values[I].Values[DbRows[0].Values['PrimaryKey']];
    388         NewItem.Data := Pointer(StrToInt(Values[I].Values[DbRows[0].Values['PrimaryKey']]));
    389         for C := 0 to Properties.Count - 1 do begin
    390           NewItem.SubItems.Add(Values[I].Values[Properties[C].Values['ColumnName']]);
    391         end;
    392       end;
    393       finally
    394433        Values.Free;
    395434      end;
Note: See TracChangeset for help on using the changeset viewer.