Changeset 9
- Timestamp:
- Nov 14, 2012, 4:08:53 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Dochazka.lpr
r8 r9 31 31 Application.CreateForm(TFormMain, FormMain); 32 32 Application.CreateForm(TFormSetting, FormSetting); 33 Application.CreateForm(TFormList, FormList);34 Application.CreateForm(TFormEdit, FormEdit);35 33 Application.Run; 36 34 end. -
trunk/Forms/UFormEdit.lfm
r8 r9 1 1 object FormEdit: TFormEdit 2 2 Left = 383 3 Height = 3 563 Height = 341 4 4 Top = 172 5 5 Width = 538 6 6 Caption = 'Edit item' 7 ClientHeight = 3 567 ClientHeight = 341 8 8 ClientWidth = 538 9 9 OnCreate = FormCreate … … 13 13 Left = 456 14 14 Height = 25 15 Top = 3 2015 Top = 305 16 16 Width = 75 17 17 Anchors = [akRight, akBottom] … … 23 23 Left = 368 24 24 Height = 25 25 Top = 3 2025 Top = 305 26 26 Width = 75 27 27 Anchors = [akRight, akBottom] … … 33 33 Left = 8 34 34 Height = 2 35 Top = 31235 Top = 297 36 36 Width = 523 37 37 Anchors = [akLeft, akRight, akBottom] 38 38 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 39 50 end -
trunk/Forms/UFormEdit.pas
r8 r9 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Buttons, ExtCtrls, SpecializedList, SpecializedDictionary; 9 Buttons, ExtCtrls, Spin, SpecializedList, SpecializedDictionary, UDataView, 10 USqlDatabase; 10 11 11 12 type 12 13 TControlType = (ctLabel, ctCheckBox, ctEdit, ctMemo, ctDate, ctTime, 13 ctComboBox );14 ctComboBox, ctSpinEdit, ctReference); 14 15 15 16 TFormItem = class … … 26 27 TFormItems = class(TListObject) 27 28 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; 29 41 end; 30 42 … … 35 47 ButtonOk: TButton; 36 48 ButtonCancel: TButton; 49 PanelControls: TPanel; 37 50 procedure FormCreate(Sender: TObject); 38 51 procedure FormDestroy(Sender: TObject); 39 52 private 53 FView: TDataViewForm; 54 procedure SetView(AValue: TDataViewForm); 40 55 { private declarations } 41 56 public 42 57 RuntimeControls: TListObject; 43 FormItems: TFormItems;44 58 Values: TDictionaryStringString; 45 procedure Update; 59 ItemId: Integer; 60 property View: TDataViewForm read FView write SetView; 61 procedure UpdateData; 46 62 end; 47 63 … … 51 67 implementation 52 68 69 uses 70 UCore; 71 72 { TDataViewForm } 73 74 constructor TDataViewForm.Create; 75 begin 76 Items := TFormItems.Create; 77 end; 78 79 destructor TDataViewForm.Destroy; 80 begin 81 Items.Free; 82 inherited Destroy; 83 end; 84 53 85 { TFormItems } 54 86 55 87 function TFormItems.AddItem(Caption, Name: string; ControlType: TControlType; 56 Visible: Boolean; Rect: TRect ): TFormItem;88 Visible: Boolean; Rect: TRect; TextPlacement: TAlign = alLeft): TFormItem; 57 89 begin 58 90 Result := TFormItem.Create; … … 62 94 Result.Rect := Rect; 63 95 Result.ControlType := ControlType; 96 Result.TitlePlacement := TextPlacement; 64 97 Add(Result); 65 98 end; … … 71 104 procedure TFormEdit.FormCreate(Sender: TObject); 72 105 begin 73 FormItems := TFormItems.Create;74 106 Values := TDictionaryStringString.Create; 75 107 RuntimeControls := TListObject.Create; … … 80 112 Values.Free; 81 113 RuntimeControls.Free; 82 FormItems.Free; 83 end; 84 85 procedure TFormEdit.Update; 114 end; 115 116 procedure TFormEdit.SetView(AValue: TDataViewForm); 117 begin 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; 125 end; 126 127 procedure TFormEdit.UpdateData; 86 128 var 87 129 NewControl: TControl; 88 130 I: Integer; 89 131 TitleRect: TRect; 90 const 91 W = 50; 92 H = 32; 93 begin 132 DbRows: TDbRows; 133 W: Integer; 134 H: Integer; 135 begin 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 94 151 RuntimeControls.Clear; 95 for I := 0 to FormItems.Count - 1 do96 with TFormItem( FormItems[I]) do begin152 for I := 0 to View.Items.Count - 1 do 153 with TFormItem(View.Items[I]) do begin 97 154 if TitlePlacement <> alNone then begin 98 155 NewControl := TLabel.Create(Self); 99 NewControl.Parent := Self;156 NewControl.Parent := PanelControls; 100 157 NewControl.Caption := Caption; 158 NewControl.AutoSize := False; 101 159 TitleRect := Rect; 102 160 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; 107 181 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); 110 185 NewControl.Show; 111 186 end; 112 187 if ControlType = ctLabel then begin 113 188 NewControl := TLabel.Create(Self); 114 NewControl.Parent := Self;189 NewControl.Parent := PanelControls; 115 190 NewControl.Caption := Values.Values[Name]; 116 191 NewControl.SetBounds(Rect.Left * W, Rect.Top * H, … … 122 197 NewControl := TEdit.Create(Self); 123 198 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 = ct Editthen begin199 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 130 205 NewControl := TMemo.Create(Self); 131 NewControl.Parent := Self;206 NewControl.Parent := PanelControls; 132 207 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, 134 209 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 135 210 NewControl.Show; … … 137 212 if ControlType = ctCheckBox then begin 138 213 NewControl := TCheckBox.Create(Self); 139 NewControl.Parent := Self;214 NewControl.Parent := PanelControls; 140 215 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, 142 217 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 143 218 NewControl.Show; … … 145 220 if ControlType = ctComboBox then begin 146 221 NewControl := TComboBox.Create(Self); 147 NewControl.Parent := Self;222 NewControl.Parent := PanelControls; 148 223 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, 150 233 (Rect.Right - Rect.Left) * W, (Rect.Bottom - Rect.Top) * H); 151 234 NewControl.Show; -
trunk/Forms/UFormList.pas
r8 r9 76 76 Selected: Boolean); 77 77 private 78 F DataViewList: TDataViewList;79 procedure Set DataViewList(AValue: TDataViewList);78 FView: TDataViewList; 79 procedure SetView(AValue: TDataViewList); 80 80 public 81 81 DbRows: TDbRows; 82 property DataViewList: TDataViewList read FDataViewList write SetDataViewList;82 property View: TDataViewList read FView write SetView; 83 83 procedure UpdateInterface; 84 84 procedure UpdateData; … … 93 93 94 94 uses 95 UCore, UFormEdit ;95 UCore, UFormEdit, UFormMain; 96 96 97 97 resourcestring … … 146 146 147 147 procedure TFormList.AModifyExecute(Sender: TObject); 148 begin 149 if FormEdit.ShowModal = mrOk then begin 150 end; 148 var 149 Index: Integer; 150 begin 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; 151 159 end; 152 160 … … 162 170 if MessageDlg(SItemDeletion, SDoYouWantToDeleteItem, mtConfirmation, 163 171 [mbYes, mbNo], 0) = mrYes then begin 164 Core.Database.Query(nil, 'DELETE FROM `' + DataViewList.Name +172 Core.Database.Query(nil, 'DELETE FROM `' + View.Name + 165 173 '` WHERE `Id` = ' + IntToStr(Integer(ListView1.Selected.Data))); 166 174 end; … … 190 198 begin 191 199 if (Item.Index >= 0) and (Item.Index < DbRows.Count) then begin 192 for I := 0 to DataViewList.Columns.Count - 1 do begin200 for I := 0 to View.Columns.Count - 1 do begin 193 201 Item.Data := Pointer(StrToInt(DbRows[Item.Index].Values['Id'])); 194 202 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]); 196 204 end; 197 205 end; … … 204 212 end; 205 213 206 procedure TFormList.Set DataViewList(AValue: TDataViewList);207 begin 208 if F DataViewList=AValue then Exit;214 procedure TFormList.SetView(AValue: TDataViewList); 215 begin 216 if FView = AValue then Exit; 209 217 if Assigned(AValue) then begin 210 218 end else begin … … 212 220 ListView1.Items.Clear; 213 221 end; 214 F DataViewList:= AValue;222 FView := AValue; 215 223 end; 216 224 … … 231 239 ListView1.Columns.Clear; 232 240 Filter := 'Id'; 233 for I := 0 to DataViewList.Columns.Count - 1 do234 with TDbColumn( DataViewList.Columns[I]) do begin241 for I := 0 to View.Columns.Count - 1 do 242 with TDbColumn(View.Columns[I]) do begin 235 243 NewColumn := ListView1.Columns.Add; 236 244 NewColumn.Caption := Caption; … … 239 247 Filter := Filter + ', `' + Name + '`'; 240 248 end; 241 Core.Database.Query(DbRows, 'SELECT ' + Filter + ' FROM ' + DataViewList.Name);249 Core.Database.Query(DbRows, 'SELECT ' + Filter + ' FROM ' + View.Name); 242 250 243 251 ListView1.Items.Count := DbRows.Count; -
trunk/Forms/UFormMain.pas
r8 r9 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 Menus, ActnList, UFormList, SpecializedList ;9 Menus, ActnList, UFormList, SpecializedList, UFormEdit; 10 10 11 11 type … … 34 34 procedure TabSheetShow(Sender: TObject); 35 35 private 36 DataViewLists: TListObject;37 36 procedure InitModules; 38 37 procedure ReloadPages; 39 38 public 40 { public declarations } 39 DataViewLists: TListObject; // TListObject<TDataViewList> 40 DataViewForms: TListObject; // TListObject<TDataViewForm> 41 41 end; 42 42 … … 90 90 begin 91 91 DataViewLists := TListObject.Create; 92 DataViewForms := TListObject.Create; 92 93 Core.Init; 93 94 Core.PersistentForm.Load(Self); … … 98 99 procedure TFormMain.FormDestroy(Sender: TObject); 99 100 begin 101 DataViewForms.Free; 100 102 DataViewLists.Free; 101 103 Core.PersistentForm.Save(Self); … … 126 128 Align := alClient; 127 129 Show; 128 DataViewList:= TDataViewList(DataViewLists[TTabSheet(Sender).Tag]);130 View := TDataViewList(DataViewLists[TTabSheet(Sender).Tag]); 129 131 UpdateData; 130 132 end; … … 134 136 var 135 137 NewDataView: TDataViewList; 138 NewDataView2: TDataViewForm; 136 139 begin 137 140 NewDataView := TDataViewList.Create; … … 153 156 end; 154 157 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); 155 175 156 176 NewDataView := TDataViewList.Create; … … 167 187 end; 168 188 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); 169 202 170 203 NewDataView := TDataViewList.Create;
Note:
See TracChangeset
for help on using the changeset viewer.