Changeset 16


Ignore:
Timestamp:
Nov 15, 2012, 2:01:43 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Vkládání, úprava a mazání položek jsou nyní funkční.
Location:
trunk
Files:
5 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Dochazka.lpi

    r15 r16  
    7272      </local>
    7373    </RunParams>
    74     <RequiredPackages Count="7">
     74    <RequiredPackages Count="8">
    7575      <Item1>
     76        <PackageName Value="TEditExtensions"/>
     77        <DefaultFilename Value="Packages/TEditExtensions/TEditExtensions.lpk" Prefer="True"/>
     78      </Item1>
     79      <Item2>
    7680        <PackageName Value="synapse"/>
    7781        <DefaultFilename Value="Packages/synapse/synapse.lpk" Prefer="True"/>
    78       </Item1>
    79       <Item2>
     82      </Item2>
     83      <Item3>
    8084        <PackageName Value="ModularSystem"/>
    8185        <DefaultFilename Value="Packages/ModularSystem/ModularSystem.lpk" Prefer="True"/>
    82       </Item2>
    83       <Item3>
     86      </Item3>
     87      <Item4>
    8488        <PackageName Value="TemplateGenerics"/>
    8589        <DefaultFilename Value="Packages/TemplateGenerics/TemplateGenerics.lpk" Prefer="True"/>
    86       </Item3>
    87       <Item4>
     90      </Item4>
     91      <Item5>
    8892        <PackageName Value="CoolTranslator"/>
    8993        <DefaultFilename Value="Packages/CoolTranslator/CoolTranslator.lpk" Prefer="True"/>
    90       </Item4>
    91       <Item5>
     94      </Item5>
     95      <Item6>
    9296        <PackageName Value="Common"/>
    9397        <DefaultFilename Value="Packages/Common/Common.lpk" Prefer="True"/>
    94       </Item5>
    95       <Item6>
     98      </Item6>
     99      <Item7>
    96100        <PackageName Value="CoolWeb"/>
    97101        <DefaultFilename Value="Packages/CoolWeb/CoolWeb.lpk" Prefer="True"/>
    98       </Item6>
    99       <Item7>
     102      </Item7>
     103      <Item8>
    100104        <PackageName Value="LCL"/>
    101       </Item7>
     105      </Item8>
    102106    </RequiredPackages>
    103107    <Units Count="14">
  • trunk/Dochazka.lpr

    r15 r16  
    1010  Forms, UFormMain, UCore, UAttendance, UPersistentForm, CoolWeb, Common,
    1111  CoolTranslator, UFormSetting, SysUtils, UFormList, UFormEdit, UDataView,
    12   URegistredModules, TemplateGenerics, synapse, UFormConnection,
    13 UModuleAttendance, UDataModel
     12  URegistredModules, TemplateGenerics, synapse, TEditExtensions,
     13  UFormConnection, UModuleAttendance, UDataModel
    1414  { you can add units after this };
    1515
  • trunk/Forms/UFormEdit.lfm

    r15 r16  
    3838  end
    3939  object PanelControls: TPanel
    40     Left = 0
    41     Height = 290
    42     Top = 0
    43     Width = 553
     40    Left = 8
     41    Height = 282
     42    Top = 8
     43    Width = 537
    4444    Align = alTop
    4545    Anchors = [akTop, akLeft, akRight, akBottom]
     46    BorderSpacing.Around = 8
    4647    BevelOuter = bvNone
    4748    TabOrder = 2
  • trunk/Forms/UFormEdit.pas

    r15 r16  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  Buttons, ExtCtrls, Spin, ComCtrls, EditBtn, SpecializedList,
    10   SpecializedDictionary, UDataView, USqlDatabase;
     10  SpecializedDictionary, UDataView, USqlDatabase, UTimeEdit;
    1111
    1212type
     
    1919    Visible: Boolean;
    2020    Rect: TRect;
     21    Control: TControl; // Used by TFormEdit
    2122    ControlType: TControlType;
    2223    TitlePlacement: TAlign;
     
    4849    ButtonOk: TButton;
    4950    ButtonCancel: TButton;
    50     CalcEdit1: TCalcEdit;
    5151    PanelControls: TPanel;
    5252    procedure FormCreate(Sender: TObject);
    5353    procedure FormDestroy(Sender: TObject);
    54     procedure SpeedButton1Click(Sender: TObject);
    5554  private
    5655    FView: TDataViewForm;
    5756    procedure SetView(AValue: TDataViewForm);
    58     { private declarations }
     57    procedure RebuildControls;
    5958  public
    60     RuntimeControls: TListObject;
    6159    Values: TDictionaryStringString;
    6260    ItemId: Integer;
    6361    property View: TDataViewForm read FView write SetView;
    64     procedure UpdateData;
     62    procedure ClearData;
     63    procedure LoadFromDatabase;
     64    procedure SaveToDatabase;
     65    procedure LoadFromControls;
    6566  end;
    6667
     
    7273uses
    7374  UCore, UFormMain;
     75
     76resourcestring
     77  SItemNotFound = 'Item not found';
    7478
    7579{ TDataViewForm }
     
    108112begin
    109113  Values := TDictionaryStringString.Create;
    110   RuntimeControls := TListObject.Create;
    111114end;
    112115
    113116procedure TFormEdit.FormDestroy(Sender: TObject);
    114117begin
    115   Values.Free;
    116   RuntimeControls.Free;
    117 end;
    118 
    119 procedure TFormEdit.SpeedButton1Click(Sender: TObject);
    120 begin
    121 
     118  FreeAndNil(Values);
    122119end;
    123120
     
    126123  if FView=AValue then Exit;
    127124  FView := AValue;
    128   if Assigned(AValue) then UpdateData
     125  if Assigned(AValue) then ClearData
    129126    else begin
    130127      Values.Clear;
    131       RuntimeControls.Clear;
    132     end;
    133 end;
    134 
    135 procedure TFormEdit.UpdateData;
     128    end;
     129end;
     130
     131procedure TFormEdit.RebuildControls;
    136132var
    137133  NewControl: TControl;
    138134  I: Integer;
    139135  TitleRect: TRect;
    140   DbRows: TDbRows;
    141136  W: Integer;
    142137  H: Integer;
     
    144139  W := 130;
    145140  H := 24;
    146   try
    147     DbRows := TDbRows.Create;
    148     Core.Database.Query(DbRows, 'SELECT * FROM ' + View.Name + ' WHERE Id=' +
    149       IntToStr(ItemId));
    150     if DbRows.Count > 0 then Values.Assign(DbRows[0])
    151       else begin
    152         Values.Free;
    153         Exit;
    154       end;
    155   finally
    156     DbRows.Free;
    157   end;
    158 
    159   RuntimeControls.Clear;
    160141  for I := 0 to View.Items.Count - 1 do
    161142  with TFormItem(View.Items[I]) do begin
     
    200181        (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    201182      NewControl.Show;
     183      Control := NewControl;
    202184    end else
    203185    if ControlType = ctEdit then begin
     
    209191       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    210192      NewControl.Show;
     193      Control := NewControl;
    211194    end else
    212195    if ControlType = ctMemo then begin
     
    217200       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    218201      NewControl.Show;
     202      Control := NewControl;
    219203    end else
    220204    if ControlType = ctCheckBox then begin
    221205      NewControl := TCheckBox.Create(Self);
    222206      NewControl.Parent := PanelControls;
    223       TCheckBox(NewControl).Enabled :=  Values.Values[Name] = '1';
    224       NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
    225        (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    226       NewControl.Show;
     207      TCheckBox(NewControl).Checked := Values.Values[Name] = '1';
     208      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
     209       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     210      NewControl.Show;
     211      Control := NewControl;
    227212    end else
    228213    if ControlType = ctComboBox then begin
     
    233218       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    234219      NewControl.Show;
     220      Control := NewControl;
    235221    end else
    236222    if ControlType = ctSpinEdit then begin
     
    241227       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    242228      NewControl.Show;
     229      Control := NewControl;
    243230    end else
    244231    if ControlType = ctDate then begin
     
    249236       (Rect.Right - Rect.Left) * W - TEditButton(NewControl).Button.Width, (Rect.Bottom - Rect.Top) * H);
    250237      NewControl.Show;
     238      Control := NewControl;
    251239    end else
    252240    if ControlType = ctTime then begin
    253       NewControl := TEdit.Create(Self);
    254       NewControl.Parent := PanelControls;
    255       TEdit(NewControl).Text := TimeToStr(SQLToTime(Values.Values[Name]));
    256       NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
    257        (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
    258       NewControl.Show;
     241      NewControl := TTimeEdit.Create(Self);
     242      NewControl.Parent := PanelControls;
     243      TTimeEdit(NewControl).Time := SQLToTime(Values.Values[Name]);
     244      NewControl.SetBounds(Rect.Left * W, Rect.Top * H,
     245       (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H);
     246      NewControl.Show;
     247      Control := NewControl;
    259248    end else
    260249    if ControlType = ctReference then begin
     
    267256       (Rect.Bottom - Rect.Top) * H);
    268257      NewControl.Show;
     258      Control := NewControl;
     259    end;
     260  end;
     261end;
     262
     263procedure TFormEdit.ClearData;
     264var
     265  I: Integer;
     266begin
     267  Values.Clear;
     268  for I := 0 to View.Items.Count - 1 do
     269  with TFormItem(View.Items[I]) do begin
     270    case ControlType of
     271      ctSpinEdit, ctDate, ctTime, ctDateTime, ctReference: Values.Add(Name, '0');
     272      else Values.Add(Name, '');
     273    end;
     274  end;
     275  RebuildControls;
     276end;
     277
     278procedure TFormEdit.LoadFromDatabase;
     279var
     280  DbRows: TDbRows;
     281  Columns: string;
     282  I: Integer;
     283begin
     284  Columns := '';
     285  for I := 0 to View.Items.Count - 1 do
     286  with TFormItem(View.Items[I]) do
     287  if Visible then
     288    Columns := Columns + ', ' + Name;
     289  Delete(Columns, 1, 2);
     290  try
     291    DbRows := TDbRows.Create;
     292    Core.Database.Query(DbRows, 'SELECT ' + Columns + ' FROM `' + View.Name + '` WHERE `Id`=' +
     293      IntToStr(ItemId));
     294    if DbRows.Count > 0 then Values.Assign(DbRows[0])
     295      else raise Exception.Create(SItemNotFound);
     296  finally
     297    DbRows.Free;
     298  end;
     299  RebuildControls;
     300end;
     301
     302procedure TFormEdit.SaveToDatabase;
     303var
     304  DbRows: TDbRows;
     305begin
     306  LoadFromControls;
     307  try
     308    DbRows := TDbRows.Create;
     309    if ItemId < 1 then Core.Database.Insert(View.Name, Values)
     310      else Core.Database.Update(View.Name, Values, '`Id`=' + IntToStr(ItemId));
     311  finally
     312    DbRows.Free;
     313  end;
     314end;
     315
     316procedure TFormEdit.LoadFromControls;
     317var
     318  I: Integer;
     319begin
     320  for I := 0 to View.Items.Count - 1 do
     321  with TFormItem(View.Items[I]) do begin
     322    if ControlType = ctLabel then begin
     323      Values.Values[Name] := TLabel(Control).Caption;
     324    end else
     325    if ControlType = ctEdit then begin
     326      Values.Values[Name] := TEdit(Control).Text;
     327    end else
     328    if ControlType = ctMemo then begin
     329      Values.Values[Name] := TMemo(Control).Lines.Text;
     330    end else
     331    if ControlType = ctCheckBox then begin
     332      Values.Values[Name] := BoolToStr(TCheckBox(Control).Checked);
     333    end else
     334    if ControlType = ctComboBox then begin
     335      Values.Values[Name] := TComboBox(Control).Text;
     336    end else
     337    if ControlType = ctSpinEdit then begin
     338      Values.Values[Name] := IntToStr(TSpinEdit(Control).Value);
     339    end else
     340    if ControlType = ctDate then begin
     341      Values.Values[Name] := DateToSQL(TDateEdit(Control).Date);
     342    end else
     343    if ControlType = ctTime then begin
     344      Values.Values[Name] := TimeToSQL(TTimeEdit(Control).Time);
     345    end else
     346    if ControlType = ctReference then begin
     347      Values.Values[Name] := TEditButton(Control).Text;
    269348    end;
    270349  end;
  • trunk/Forms/UFormList.lfm

    r14 r16  
    3030    end
    3131    object ToolButton2: TToolButton
    32       Left = 49
     32      Left = 45
    3333      Top = 2
    3434      Action = ADelete
    3535    end
    3636    object ToolButton3: TToolButton
    37       Left = 97
     37      Left = 89
    3838      Top = 2
    3939      Action = ADuplicate
    4040    end
    4141    object ToolButton4: TToolButton
    42       Left = 149
     42      Left = 141
    4343      Top = 2
    4444      Action = AModify
    4545    end
    4646    object ToolButton5: TToolButton
    47       Left = 197
     47      Left = 185
    4848      Top = 2
    4949      Action = AReload
    5050    end
    5151    object ToolButton6: TToolButton
    52       Left = 245
     52      Left = 229
    5353      Top = 2
    5454      Action = APrint
    5555    end
    5656    object ToolButton7: TToolButton
    57       Left = 293
     57      Left = 273
    5858      Top = 2
    5959      Action = AExport
     
    128128      Hint = 'Reload data'
    129129      ImageIndex = 5
     130      OnExecute = AReloadExecute
    130131    end
    131132    object APrint: TAction
  • trunk/Forms/UFormList.pas

    r9 r16  
    6969    procedure ADuplicateExecute(Sender: TObject);
    7070    procedure AModifyExecute(Sender: TObject);
     71    procedure AReloadExecute(Sender: TObject);
    7172    procedure FormCreate(Sender: TObject);
    7273    procedure FormDestroy(Sender: TObject);
     
    99100  SDoYouWantToDeleteItem = 'Do you want to really delete item?';
    100101  SItemCount = 'Item count: %s';
     102  SModifyItem = 'Modify item';
     103  SAddItem = 'Add item';
    101104
    102105{ TDataViewList }
     
    149152  Index: Integer;
    150153begin
    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;
     154  try
     155    FormEdit := TFormEdit.Create(FormMain);
     156    Index := FormMain.DataViewLists.IndexOf(View);
     157    FormEdit.ItemId := Integer(ListView1.Selected.Data);
     158    FormEdit.View := TDataViewForm(FormMain.DataViewForms[Index]);
     159    FormEdit.LoadFromDatabase;
     160    FormEdit.Caption := SModifyItem;
     161    Core.CoolTranslator1.TranslateComponentRecursive(FormEdit);
     162    if FormEdit.ShowModal = mrOk then begin
     163      FormEdit.SaveToDatabase;
     164      UpdateData;
     165    end;
     166  finally
     167    FormEdit.Free;
     168  end;
     169end;
     170
     171procedure TFormList.AReloadExecute(Sender: TObject);
     172begin
     173  UpdateData;
    159174end;
    160175
    161176procedure TFormList.AAddExecute(Sender: TObject);
    162 begin
    163   if FormEdit.ShowModal = mrOk then begin
     177var
     178  Index: Integer;
     179begin
     180  try
     181    FormEdit := TFormEdit.Create(FormMain);
     182    Index := FormMain.DataViewLists.IndexOf(View);
     183    FormEdit.ItemId := 0;
     184    FormEdit.View := TDataViewForm(FormMain.DataViewForms[Index]);
     185    FormEdit.ClearData;
     186    FormEdit.Caption := SAddItem;
     187    Core.CoolTranslator1.TranslateComponentRecursive(FormEdit);
     188    if FormEdit.ShowModal = mrOk then begin
     189      FormEdit.SaveToDatabase;
     190      UpdateData;
     191    end;
     192  finally
     193    FormEdit.Free;
    164194  end;
    165195end;
     
    167197procedure TFormList.ADeleteExecute(Sender: TObject);
    168198begin
    169   if FormEdit.ShowModal = mrOk then begin
    170     if MessageDlg(SItemDeletion, SDoYouWantToDeleteItem, mtConfirmation,
    171       [mbYes, mbNo], 0) = mrYes then begin
    172       Core.Database.Query(nil, 'DELETE FROM `' + View.Name +
    173         '` WHERE `Id` = ' + IntToStr(Integer(ListView1.Selected.Data)));
    174     end;
     199  if MessageDlg(SItemDeletion, SDoYouWantToDeleteItem, mtConfirmation,
     200    [mbYes, mbNo], 0) = mrYes then begin
     201    Core.Database.Delete(View.Name, '`Id` = ' + IntToStr(Integer(ListView1.Selected.Data)));
     202    UpdateData;
    175203  end;
    176204end;
     
    200228    for I := 0 to View.Columns.Count - 1 do begin
    201229      Item.Data := Pointer(StrToInt(DbRows[Item.Index].Values['Id']));
    202       if I = 0 then Item.Caption := DbRows[Item.Index].Items[0].Value
     230      if I = 0 then Item.Caption := DbRows[Item.Index].Values[TDbColumn(View.Columns[I]).Name]
    203231        else Item.SubItems.Add(DbRows[Item.Index].Values[TDbColumn(View.Columns[I]).Name]);
    204232    end;
  • trunk/Languages/Dochazka.cs.po

    r15 r16  
    146146
    147147#: tformlist.amodify.hint
     148msgctxt "tformlist.amodify.hint"
    148149msgid "Modify item"
    149150msgstr "Upravit poloÅŸku"
     
    254255msgstr "Nastavení"
    255256
     257#: uformedit.sitemnotfound
     258msgid "Item not found"
     259msgstr ""
     260
     261#: uformlist.sadditem
     262msgid "Add item"
     263msgstr ""
     264
    256265#: uformlist.sdoyouwanttodeleteitem
    257266#| msgid "Do you want to delte item"
     
    268277msgstr "Mazání poloşky"
    269278
     279#: uformlist.smodifyitem
     280msgctxt "uformlist.smodifyitem"
     281msgid "Modify item"
     282msgstr "Upravit poloÅŸku"
     283
    270284#: uformmain.saddress
    271285msgctxt "uformmain.saddress"
  • trunk/Languages/Dochazka.po

    r15 r16  
    136136
    137137#: tformlist.amodify.hint
     138msgctxt "tformlist.amodify.hint"
    138139msgid "Modify item"
    139140msgstr ""
     
    242243msgstr ""
    243244
     245#: uformedit.sitemnotfound
     246msgid "Item not found"
     247msgstr ""
     248
     249#: uformlist.sadditem
     250msgid "Add item"
     251msgstr ""
     252
    244253#: uformlist.sdoyouwanttodeleteitem
    245254msgid "Do you want to really delete item?"
     
    255264msgstr ""
    256265
     266#: uformlist.smodifyitem
     267msgctxt "uformlist.smodifyitem"
     268msgid "Modify item"
     269msgstr ""
     270
    257271#: uformmain.saddress
    258272msgctxt "uformmain.saddress"
  • trunk/Modules/Attendance/UModuleAttendance.pas

    r15 r16  
    183183  with ViewFormPassage do begin
    184184    with Items do begin
    185       AddItem(STime, 'Time', ctDate, True, Bounds(0, 0, 1, 1));
     185      AddItem(STime, 'Time', ctDate, True, Bounds(1, 0, 1, 1));
    186186      with AddItem(SUser, 'User', ctReference, True, Bounds(3, 0, 1, 1)) do
    187187        ReferencedTable := 'User';
    188       with AddItem(SOperation, 'Operation', ctReference, True, Bounds(0, 1, 1, 1)) do
     188      with AddItem(SOperation, 'Operation', ctReference, True, Bounds(1, 1, 1, 1)) do
    189189        ReferencedTable := 'User';
    190190      with AddItem(STerminal, 'Terminal', ctReference, True, Bounds(3, 1, 1, 1)) do
  • trunk/Packages/CoolWeb/Persistence/USqlDatabase.pas

    r15 r16  
    9292  function SQLToTime(Value: string): TDateTime;
    9393  function DateTimeToSQL(Value: TDateTime): string;
     94  function TimeToSQL(Value: TDateTime): string;
     95  function DateToSQL(Value: TDateTime): string;
    9496
    9597procedure Register;
     
    176178end;
    177179
     180function TimeToSQL(Value: TDateTime): string;
     181begin
     182  Result := FormatDateTime('hh.nn.ss', Value);
     183end;
     184
     185function DateToSQL(Value: TDateTime): string;
     186begin
     187  Result := FormatDateTime('yyyy-mm-dd', Value);
     188end;
     189
    178190function SQLToTime(Value: string): TDateTime;
    179191var
Note: See TracChangeset for help on using the changeset viewer.