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/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
Note: See TracChangeset for help on using the changeset viewer.