Changeset 9 for trunk


Ignore:
Timestamp:
Nov 14, 2012, 4:08:53 PM (12 years ago)
Author:
chronos
Message:
  • Upraveno: Zprovozněno zobrazování formulářového pohledu pro uživatele.
Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Dochazka.lpr

    r8 r9  
    3131  Application.CreateForm(TFormMain, FormMain);
    3232  Application.CreateForm(TFormSetting, FormSetting);
    33   Application.CreateForm(TFormList, FormList);
    34   Application.CreateForm(TFormEdit, FormEdit);
    3533  Application.Run;
    3634end.
  • trunk/Forms/UFormEdit.lfm

    r8 r9  
    11object FormEdit: TFormEdit
    22  Left = 383
    3   Height = 356
     3  Height = 341
    44  Top = 172
    55  Width = 538
    66  Caption = 'Edit item'
    7   ClientHeight = 356
     7  ClientHeight = 341
    88  ClientWidth = 538
    99  OnCreate = FormCreate
     
    1313    Left = 456
    1414    Height = 25
    15     Top = 320
     15    Top = 305
    1616    Width = 75
    1717    Anchors = [akRight, akBottom]
     
    2323    Left = 368
    2424    Height = 25
    25     Top = 320
     25    Top = 305
    2626    Width = 75
    2727    Anchors = [akRight, akBottom]
     
    3333    Left = 8
    3434    Height = 2
    35     Top = 312
     35    Top = 297
    3636    Width = 523
    3737    Anchors = [akLeft, akRight, akBottom]
    3838  end
     39  object PanelControls: TPanel
     40    Left = 4
     41    Height = 285
     42    Top = 4
     43    Width = 530
     44    Align = alTop
     45    Anchors = [akTop, akLeft, akRight, akBottom]
     46    BorderSpacing.Around = 4
     47    BevelOuter = bvNone
     48    TabOrder = 2
     49  end
    3950end
  • trunk/Forms/UFormEdit.pas

    r8 r9  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   Buttons, ExtCtrls, SpecializedList, SpecializedDictionary;
     9  Buttons, ExtCtrls, Spin, SpecializedList, SpecializedDictionary, UDataView,
     10  USqlDatabase;
    1011
    1112type
    1213  TControlType = (ctLabel, ctCheckBox, ctEdit, ctMemo, ctDate, ctTime,
    13     ctComboBox);
     14    ctComboBox, ctSpinEdit, ctReference);
    1415
    1516  TFormItem = class
     
    2627  TFormItems = class(TListObject)
    2728    function AddItem(Caption, Name: string; ControlType: TControlType;
    28       Visible: Boolean; Rect: TRect): TFormItem;
     29      Visible: Boolean; Rect: TRect; TextPlacement: TAlign = alLeft): TFormItem;
     30  end;
     31
     32  { TDataViewForm }
     33
     34  TDataViewForm = class(TDataView)
     35    Name: string;
     36    Caption: string;
     37    ImageIndex: Integer;
     38    Items: TFormItems;
     39    constructor Create;
     40    destructor Destroy; override;
    2941  end;
    3042
     
    3547    ButtonOk: TButton;
    3648    ButtonCancel: TButton;
     49    PanelControls: TPanel;
    3750    procedure FormCreate(Sender: TObject);
    3851    procedure FormDestroy(Sender: TObject);
    3952  private
     53    FView: TDataViewForm;
     54    procedure SetView(AValue: TDataViewForm);
    4055    { private declarations }
    4156  public
    4257    RuntimeControls: TListObject;
    43     FormItems: TFormItems;
    4458    Values: TDictionaryStringString;
    45     procedure Update;
     59    ItemId: Integer;
     60    property View: TDataViewForm read FView write SetView;
     61    procedure UpdateData;
    4662  end;
    4763
     
    5167implementation
    5268
     69uses
     70  UCore;
     71
     72{ TDataViewForm }
     73
     74constructor TDataViewForm.Create;
     75begin
     76  Items := TFormItems.Create;
     77end;
     78
     79destructor TDataViewForm.Destroy;
     80begin
     81  Items.Free;
     82  inherited Destroy;
     83end;
     84
    5385{ TFormItems }
    5486
    5587function TFormItems.AddItem(Caption, Name: string; ControlType: TControlType;
    56   Visible: Boolean; Rect: TRect): TFormItem;
     88  Visible: Boolean; Rect: TRect; TextPlacement: TAlign = alLeft): TFormItem;
    5789begin
    5890  Result := TFormItem.Create;
     
    6294  Result.Rect := Rect;
    6395  Result.ControlType := ControlType;
     96  Result.TitlePlacement := TextPlacement;
    6497  Add(Result);
    6598end;
     
    71104procedure TFormEdit.FormCreate(Sender: TObject);
    72105begin
    73   FormItems := TFormItems.Create;
    74106  Values := TDictionaryStringString.Create;
    75107  RuntimeControls := TListObject.Create;
     
    80112  Values.Free;
    81113  RuntimeControls.Free;
    82   FormItems.Free;
    83 end;
    84 
    85 procedure TFormEdit.Update;
     114end;
     115
     116procedure TFormEdit.SetView(AValue: TDataViewForm);
     117begin
     118  if FView=AValue then Exit;
     119  FView := AValue;
     120  if Assigned(AValue) then UpdateData
     121    else begin
     122      Values.Clear;
     123      RuntimeControls.Clear;
     124    end;
     125end;
     126
     127procedure TFormEdit.UpdateData;
    86128var
    87129  NewControl: TControl;
    88130  I: Integer;
    89131  TitleRect: TRect;
    90 const
    91   W = 50;
    92   H = 32;
    93 begin
     132  DbRows: TDbRows;
     133  W: Integer;
     134  H: Integer;
     135begin
     136  W := 130;
     137  H := 24;
     138  try
     139    DbRows := TDbRows.Create;
     140    Core.Database.Query(DbRows, 'SELECT * FROM ' + View.Name + ' WHERE Id=' +
     141      IntToStr(ItemId));
     142    if DbRows.Count > 0 then Values.Assign(DbRows[0])
     143      else begin
     144        Values.Free;
     145        Exit;
     146      end;
     147  finally
     148    DbRows.Free;
     149  end;
     150
    94151  RuntimeControls.Clear;
    95   for I := 0 to FormItems.Count - 1 do
    96   with TFormItem(FormItems[I]) do begin
     152  for I := 0 to View.Items.Count - 1 do
     153  with TFormItem(View.Items[I]) do begin
    97154    if TitlePlacement <> alNone then begin
    98155      NewControl := TLabel.Create(Self);
    99       NewControl.Parent := Self;
     156      NewControl.Parent := PanelControls;
    100157      NewControl.Caption := Caption;
     158      NewControl.AutoSize := False;
    101159      TitleRect := Rect;
    102160      case TitlePlacement of
    103         alLeft: TitleRect.Left := TitleRect.Left - 1;
    104         alRight: TitleRect.Left := TitleRect.Left + 1;
    105         alTop: TitleRect.Top := TitleRect.Top - 1;
    106         alBottom: TitleRect.Top := TitleRect.Top + 1;
     161        alLeft: begin
     162          TitleRect.Left := TitleRect.Left - 1;
     163          TitleRect.Right := TitleRect.Right - 1;
     164          TLabel(NewControl).Alignment := taRightJustify;
     165        end;
     166        alRight: begin
     167          TitleRect.Left := TitleRect.Left + 1;
     168          TitleRect.Right := TitleRect.Right + 1;
     169          TLabel(NewControl).Alignment := taLeftJustify;
     170        end;
     171        alTop: begin
     172          TitleRect.Top := TitleRect.Top - 1;
     173          TitleRect.Bottom := TitleRect.Bottom - 1;
     174          TLabel(NewControl).Alignment := taLeftJustify;
     175        end;
     176        alBottom: begin
     177          TitleRect.Top := TitleRect.Top + 1;
     178          TitleRect.Bottom := TitleRect.Bottom + 1;
     179          TLabel(NewControl).Alignment := taLeftJustify;
     180        end;
    107181      end;
    108       NewControl.SetBounds(TitleRect.Left * W, TitleRect.Top * H,
    109         (TitleRect.Right - TitleRect.Left) * W, (TitleRect.Bottom - TitleRect.Top) * H);
     182      NewControl.SetBounds(TitleRect.Left * W + 4, TitleRect.Top * H + 2,
     183        (TitleRect.Right - TitleRect.Left) * W - 8,
     184        (TitleRect.Bottom - TitleRect.Top) * H - 4);
    110185      NewControl.Show;
    111186    end;
    112187    if ControlType = ctLabel then begin
    113188      NewControl := TLabel.Create(Self);
    114       NewControl.Parent := Self;
     189      NewControl.Parent := PanelControls;
    115190      NewControl.Caption := Values.Values[Name];
    116191      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
     
    122197      NewControl := TEdit.Create(Self);
    123198      TEdit(NewControl).Text := Values.Values[Name];
    124       NewControl.Parent := Self;
    125       NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
    126        (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    127       NewControl.Show;
    128     end else
    129     if ControlType = ctEdit then begin
     199      NewControl.Parent := PanelControls;
     200      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
     201       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     202      NewControl.Show;
     203    end else
     204    if ControlType = ctMemo then begin
    130205      NewControl := TMemo.Create(Self);
    131       NewControl.Parent := Self;
     206      NewControl.Parent := PanelControls;
    132207      TMemo(NewControl).Lines.Text := Values.Values[Name];
    133       NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     208      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
    134209       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    135210      NewControl.Show;
     
    137212    if ControlType = ctCheckBox then begin
    138213      NewControl := TCheckBox.Create(Self);
    139       NewControl.Parent := Self;
     214      NewControl.Parent := PanelControls;
    140215      TCheckBox(NewControl).Enabled :=  Values.Values[Name] = '1';
    141       NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     216      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
    142217       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    143218      NewControl.Show;
     
    145220    if ControlType = ctComboBox then begin
    146221      NewControl := TComboBox.Create(Self);
    147       NewControl.Parent := Self;
     222      NewControl.Parent := PanelControls;
    148223      TComboBox(NewControl).Text := Values.Values[Name];
    149       NewControl.SetBounds((Rect.Left + 1) * W, Rect.Top * H,
     224      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
     225       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     226      NewControl.Show;
     227    end else
     228    if ControlType = ctSpinEdit then begin
     229      NewControl := TSpinEdit.Create(Self);
     230      NewControl.Parent := PanelControls;
     231      TSpinEdit(NewControl).Value := StrToInt(Values.Values[Name]);
     232      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
    150233       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    151234      NewControl.Show;
  • trunk/Forms/UFormList.pas

    r8 r9  
    7676      Selected: Boolean);
    7777  private
    78     FDataViewList: TDataViewList;
    79     procedure SetDataViewList(AValue: TDataViewList);
     78    FView: TDataViewList;
     79    procedure SetView(AValue: TDataViewList);
    8080  public
    8181    DbRows: TDbRows;
    82     property DataViewList: TDataViewList read FDataViewList write SetDataViewList;
     82    property View: TDataViewList read FView write SetView;
    8383    procedure UpdateInterface;
    8484    procedure UpdateData;
     
    9393
    9494uses
    95   UCore, UFormEdit;
     95  UCore, UFormEdit, UFormMain;
    9696
    9797resourcestring
     
    146146
    147147procedure TFormList.AModifyExecute(Sender: TObject);
    148 begin
    149   if FormEdit.ShowModal = mrOk then begin
    150   end;
     148var
     149  Index: Integer;
     150begin
     151  Index := FormMain.DataViewLists.IndexOf(View);
     152  FormEdit := TFormEdit.Create(FormMain);
     153  FormEdit.ItemId := Integer(ListView1.Selected.Data);
     154  FormEdit.View := TDataViewForm(FormMain.DataViewForms[Index]);
     155  Core.CoolTranslator1.TranslateComponentRecursive(FormEdit);
     156  if FormEdit.ShowModal = mrOk then begin
     157  end;
     158  FormEdit.Free;
    151159end;
    152160
     
    162170    if MessageDlg(SItemDeletion, SDoYouWantToDeleteItem, mtConfirmation,
    163171      [mbYes, mbNo], 0) = mrYes then begin
    164       Core.Database.Query(nil, 'DELETE FROM `' + DataViewList.Name +
     172      Core.Database.Query(nil, 'DELETE FROM `' + View.Name +
    165173        '` WHERE `Id` = ' + IntToStr(Integer(ListView1.Selected.Data)));
    166174    end;
     
    190198begin
    191199  if (Item.Index >= 0) and (Item.Index < DbRows.Count) then begin
    192     for I := 0 to DataViewList.Columns.Count - 1 do begin
     200    for I := 0 to View.Columns.Count - 1 do begin
    193201      Item.Data := Pointer(StrToInt(DbRows[Item.Index].Values['Id']));
    194202      if I = 0 then Item.Caption := DbRows[Item.Index].Items[0].Value
    195         else Item.SubItems.Add(DbRows[Item.Index].Values[TDbColumn(DataViewList.Columns[I]).Name]);
     203        else Item.SubItems.Add(DbRows[Item.Index].Values[TDbColumn(View.Columns[I]).Name]);
    196204    end;
    197205  end;
     
    204212end;
    205213
    206 procedure TFormList.SetDataViewList(AValue: TDataViewList);
    207 begin
    208   if FDataViewList=AValue then Exit;
     214procedure TFormList.SetView(AValue: TDataViewList);
     215begin
     216  if FView = AValue then Exit;
    209217  if Assigned(AValue) then begin
    210218  end else begin
     
    212220    ListView1.Items.Clear;
    213221  end;
    214   FDataViewList := AValue;
     222  FView := AValue;
    215223end;
    216224
     
    231239  ListView1.Columns.Clear;
    232240  Filter := 'Id';
    233   for I := 0 to DataViewList.Columns.Count - 1 do
    234   with TDbColumn(DataViewList.Columns[I]) do begin
     241  for I := 0 to View.Columns.Count - 1 do
     242  with TDbColumn(View.Columns[I]) do begin
    235243    NewColumn := ListView1.Columns.Add;
    236244    NewColumn.Caption := Caption;
     
    239247    Filter := Filter + ', `' + Name + '`';
    240248  end;
    241   Core.Database.Query(DbRows, 'SELECT ' + Filter + ' FROM ' + DataViewList.Name);
     249  Core.Database.Query(DbRows, 'SELECT ' + Filter + ' FROM ' + View.Name);
    242250
    243251  ListView1.Items.Count := DbRows.Count;
  • trunk/Forms/UFormMain.pas

    r8 r9  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   Menus, ActnList, UFormList, SpecializedList;
     9  Menus, ActnList, UFormList, SpecializedList, UFormEdit;
    1010
    1111type
     
    3434    procedure TabSheetShow(Sender: TObject);
    3535  private
    36     DataViewLists: TListObject;
    3736    procedure InitModules;
    3837    procedure ReloadPages;
    3938  public
    40     { public declarations }
     39    DataViewLists: TListObject; // TListObject<TDataViewList>
     40    DataViewForms: TListObject; // TListObject<TDataViewForm>
    4141  end;
    4242
     
    9090begin
    9191  DataViewLists := TListObject.Create;
     92  DataViewForms := TListObject.Create;
    9293  Core.Init;
    9394  Core.PersistentForm.Load(Self);
     
    9899procedure TFormMain.FormDestroy(Sender: TObject);
    99100begin
     101  DataViewForms.Free;
    100102  DataViewLists.Free;
    101103  Core.PersistentForm.Save(Self);
     
    126128    Align := alClient;
    127129    Show;
    128     DataViewList := TDataViewList(DataViewLists[TTabSheet(Sender).Tag]);
     130    View := TDataViewList(DataViewLists[TTabSheet(Sender).Tag]);
    129131    UpdateData;
    130132  end;
     
    134136var
    135137  NewDataView: TDataViewList;
     138  NewDataView2: TDataViewForm;
    136139begin
    137140  NewDataView := TDataViewList.Create;
     
    153156  end;
    154157  DataViewLists.Add(NewDataView);
     158  NewDataView2 := TDataViewForm.Create;
     159  with NewDataView2 do begin
     160    Name := 'User';
     161    Caption := SUser;
     162    with Items do begin
     163      AddItem(SEnabled, 'Enabled', ctCheckBox, True, Bounds(1, 0, 1, 1));
     164      AddItem(SPersonalId, 'PersonalId', ctSpinEdit, True, Bounds(3, 0, 1, 1));
     165      AddItem(SLogin, 'Login', ctEdit, True, Bounds(1, 1, 1, 1));
     166      AddItem(SPassword, 'Password', ctEdit, True, Bounds(3, 1, 1, 1));
     167      AddItem(SFirstName, 'FirstName', ctEdit, True, Bounds(1, 2, 1, 1));
     168      AddItem(SSecondName, 'SecondName', ctEdit, True, Bounds(3, 2, 1, 1));
     169      AddItem(SCardCode, 'CardCode', ctEdit, True, Bounds(1, 3, 1, 1));
     170      AddItem(SFingerPrint, 'FingerPrint', ctEdit, True, Bounds(3, 3, 1, 1));
     171      AddItem(SNote, 'Note', ctMemo, True, Bounds(0, 5, 4, 4), alTop);
     172    end;
     173  end;
     174  DataViewForms.Add(NewDataView2);
    155175
    156176  NewDataView := TDataViewList.Create;
     
    167187  end;
    168188  DataViewLists.Add(NewDataView);
     189  NewDataView2 := TDataViewForm.Create;
     190  with NewDataView2 do begin
     191    with Items do begin
     192      AddItem(STime, 'Time', ctDate, True, Bounds(0, 0, 1, 1));
     193      AddItem(SUser, 'User', ctReference, True, Bounds(3, 0, 1, 1));
     194      AddItem(SOperation, 'Operation', ctReference, True, Bounds(0, 1, 1, 1));
     195      AddItem(STerminal, 'Terminal', ctReference, True, Bounds(3, 1, 1, 1));
     196    end;
     197    Name := 'Passage';
     198    Caption := SPassage;
     199    ImageIndex := 12;
     200  end;
     201  DataViewForms.Add(NewDataView2);
    169202
    170203  NewDataView := TDataViewList.Create;
Note: See TracChangeset for help on using the changeset viewer.