Ignore:
Timestamp:
Nov 24, 2011, 8:35:25 AM (13 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UItemEdit.pas

    r22 r30  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, USystem,
     9  StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, ComCtrls, USystem,
    1010  SpecializedList, SpecializedDictionary;
    1111
     
    1515
    1616  TItemEditForm = class(TForm)
     17    ButtonAdd: TButton;
     18    ButtonDelete: TButton;
     19    ButtonEdit: TButton;
    1720    ButtonSave: TButton;
    1821    ButtonCancel: TButton;
     22    ButtonView: TButton;
     23    ListView1: TListView;
    1924    Panel1: TPanel;
     25    Panel2: TPanel;
     26    Panel3: TPanel;
     27    PanelControls: TPanel;
     28    Splitter1: TSplitter;
     29    TabControl1: TTabControl;
     30    procedure ButtonAddClick(Sender: TObject);
    2031    procedure ButtonCancelClick(Sender: TObject);
     32    procedure ButtonDeleteClick(Sender: TObject);
     33    procedure ButtonEditClick(Sender: TObject);
    2134    procedure ButtonSaveClick(Sender: TObject);
     35    procedure ButtonViewClick(Sender: TObject);
    2236    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2337    procedure FormCreate(Sender: TObject);
    2438    procedure FormDestroy(Sender: TObject);
    2539    procedure FormShow(Sender: TObject);
     40    procedure ListView1Data(Sender: TObject; Item: TListItem);
     41    procedure ListView1DblClick(Sender: TObject);
     42    procedure ListView1KeyPress(Sender: TObject; var Key: char);
     43    procedure ListView1Resize(Sender: TObject);
     44    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
     45      Selected: Boolean);
     46    procedure TabControl1Change(Sender: TObject);
    2647  private
    27     { private declarations }
     48    SelectedItem: Integer;
     49    SubListObject: TChronisObject;
     50    TabObjectList: TListInteger;
     51    TabDataTypeList: TListObject;
     52    procedure LoadSubList;
    2853  public
    2954    Report: TReport;
     
    3762
    3863uses
    39   UMainForm, UDataTypes, UCore;
     64  UMainForm, UDataTypes, UCore, UItemAdd, UItemView;
    4065
    4166{$R *.lfm}
     
    4772  Close;
    4873end;
     74
     75procedure TItemEditForm.ButtonDeleteClick(Sender: TObject);
     76begin
     77  if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
     78
     79  end;
     80end;
     81
     82procedure TItemEditForm.ButtonEditClick(Sender: TObject);
     83begin
     84  if Assigned(ListView1.Selected) then
     85    ItemEditForm.Show;
     86end;
     87
     88procedure TItemEditForm.ButtonAddClick(Sender: TObject);
     89begin
     90  if Assigned(ListView1.Selected) then
     91    ItemAddForm.Show;
     92end;
     93
     94procedure TItemEditForm.ListView1Data(Sender: TObject; Item: TListItem);
     95var
     96  I: Integer;
     97begin
     98  if Item.Index < Report.Count then
     99  with TReportLine(Report[Item.Index]) do begin
     100    Item.Caption := Items[0];
     101    for I := 1 to Items.Count - 1 do
     102    if not TReportColumn(Report.Columns[I]).VirtualItem then
     103      Item.SubItems.Add(Items[I]);
     104  end;
     105end;
     106
     107procedure TItemEditForm.ListView1DblClick(Sender: TObject);
     108begin
     109  if Assigned(ListView1.Selected) then ButtonView.Click;
     110end;
     111
     112procedure TItemEditForm.ListView1KeyPress(Sender: TObject; var Key: char);
     113begin
     114  if Key = #13 then ButtonView.Click;
     115end;
     116
    49117
    50118procedure TItemEditForm.ButtonSaveClick(Sender: TObject);
     
    76144end;
    77145
     146procedure TItemEditForm.ButtonViewClick(Sender: TObject);
     147begin
     148  if Assigned(ListView1.Selected) then
     149    ItemViewForm.Show;
     150end;
     151
    78152procedure TItemEditForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
    79153  );
     
    84158procedure TItemEditForm.FormCreate(Sender: TObject);
    85159begin
     160  SubListObject := TChronisObject.Create;
     161  SubListObject.Base := Core.System;
    86162  Report := TReport.Create;
    87163  Report.Base := Core.System;
     164  TabObjectList := TListInteger.Create;
     165  TabDataTypeList := TListObject.Create;
     166  TabDataTypeList.OwnsObjects := False;
     167  TabControl1.Tabs.Clear;
    88168end;
    89169
    90170procedure TItemEditForm.FormDestroy(Sender: TObject);
    91171begin
     172  SubListObject.Free;
    92173  Report.Free;
     174  TabObjectList.Free;
     175  TabDataTypeList.Free;
    93176end;
    94177
     
    97180  MainForm.PersistentForm.Load(Self);
    98181  BuildControls;
     182  LoadSubList;
    99183end;
    100184
     
    106190  Column: Integer;
    107191  DataType: TDataType;
    108   NewControl: TWinControl;
    109   NewLabel: TLabel;
     192  NewControl: TControl;
     193  NewWinControl: TWinControl;
    110194const
    111195  ColumnCount = 2;
     
    116200    IntToStr(MainForm.SelectedItem));
    117201
    118   for I := Panel1.ControlCount - 1 downto 0 do
    119     Panel1.Controls[I].Free;
    120 
     202  // Clear previous controls on panel
     203  for I := PanelControls.ControlCount - 1 downto 0 do
     204    PanelControls.Controls[I].Free;
     205
     206  TabControl1.Tabs.Clear;
     207  TabObjectList.Clear;
     208  TabDataTypeList.Clear;
    121209  if Report.Count = 1 then
    122210    for I := 0 to Report.Columns.Count - 1 do
    123211    if (TReportColumn(Report.Columns[I]).ColumnName <> 'Id') then begin
    124 
    125       NewLabel := TLabel.Create(Panel1);
    126       NewLabel.Parent := Panel1;
    127       NewLabel.Top := LastTop;
    128       NewLabel.Left := Column * Width div ColumnCount + 10;
    129       NewLabel.Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    130 
    131212      DataType := TReportColumn(Report.Columns[I]).CustomType;
    132213      DataType.LoadDef(TReportColumn(Report.Columns[I]).CustomType.CustomType);
    133       if not (DataType is TDataTypeRelationMany) then begin
    134         NewControl := DataType.CreateControl(Panel1);
     214      if DataType is TDataTypeRelationMany then begin
     215        TabControl1.Tabs.Add(TReportColumn(Report.Columns[I]).Caption);
     216        TabDataTypeList.Add(DataType);
     217        TabObjectList.Add(MainForm.SelectedItem);
     218      end else begin
     219        NewControl := TLabel.Create(Panel1);
     220        NewControl.Parent := PanelControls;
     221        NewControl.Top := LastTop;
     222        NewControl.Left := Column * Width div ColumnCount + 10;
     223        TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
     224
     225        NewWinControl := DataType.CreateControl(Panel1);
    135226        DataType.Load(TReportLine(Report[0]).Items[I]);
    136         DataType.SetupControl(NewControl);
    137         NewControl.Parent := Panel1;
    138         NewControl.Top := LastTop;
    139         NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
    140         NewControl.Width := (Width div ColumnCount) div 2 - 20;
    141         TReportColumn(Report.Columns[I]).Control := NewControl;
     227        DataType.SetupControl(NewWinControl);
     228        NewWinControl.Parent := Panel1;
     229        NewWinControl.Top := LastTop;
     230        NewWinControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
     231        NewWinControl.Width := (Width div ColumnCount) div 2 - 20;
     232        TReportColumn(Report.Columns[I]).Control := NewWinControl;
    142233
    143234        Column := (Column + 1) mod 2;
    144         if Column = 0 then LastTop := LastTop + NewControl.Height + 4;
     235        if Column = 0 then LastTop := LastTop + NewWinControl.Height + 4;
    145236      end;
    146    end;
    147 end;
     237  end;
     238  // Panel1;
     239  // ListView1;
     240  // TabControl1;
     241  Panel2.Visible := TabControl1.Tabs.Count > 0;
     242end;
     243
     244procedure TItemEditForm.LoadSubList;
     245begin
     246  //SelectedObjectId := 0;
     247  if (TabControl1.TabIndex >= 0) and (TabControl1.TabIndex < TabControl1.Tabs.Count) then
     248  with ListView1 do
     249  with TDataTypeRelationMany(TabDataTypeList[TabControl1.TabIndex]) do begin
     250    Visible := True;
     251    SubListObject.Load(ObjectId);
     252    Report.Load(SubListObject, '`' + PropertyName + '`=' + IntToStr(TabObjectList[TabControl1.TabIndex]));
     253
     254    Report.FillListColumns(Columns);
     255    Items.Count := Report.Count;
     256    Refresh;
     257  end;
     258  ListView1Resize(Self);
     259end;
     260
     261procedure TItemEditForm.ListView1Resize(Sender: TObject);
     262var
     263  I: Integer;
     264begin
     265  for I := 0 to ListView1.Columns.Count - 1 do
     266    ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
     267end;
     268
     269procedure TItemEditForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
     270  Selected: Boolean);
     271begin
     272  if Assigned(ListView1.Selected) then
     273    SelectedItem := TReportLine(Report[ListView1.Selected.Index]).Id
     274    else SelectedItem := 0;
     275
     276  ButtonDelete.Enabled := Assigned(ListView1.Selected);
     277  ButtonView.Enabled := Assigned(ListView1.Selected);
     278  ButtonEdit.Enabled := Assigned(ListView1.Selected);
     279end;
     280
     281procedure TItemEditForm.TabControl1Change(Sender: TObject);
     282begin
     283  LoadSubList;
     284end;
     285
    148286
    149287end.
Note: See TracChangeset for help on using the changeset viewer.