Changeset 4 for trunk/Forms/UMainForm.pas
- Timestamp:
- Jun 3, 2010, 5:25:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UMainForm.pas
r3 r4 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm, UItemView; 9 StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, 10 UPersistentForm, UTreeState; 10 11 11 12 const … … 13 14 14 15 type 16 TValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean, 17 vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword, 18 vtReference, vtDate, vtTime, vtColor); 15 19 16 20 { TMainForm } 17 21 18 22 TMainForm = class(TForm) 23 AObjectGroupEdit: TAction; 24 AObjectGroupAddObject: TAction; 25 AObjectGroupAddGroup: TAction; 26 AObjectGroupDelete: TAction; 27 AItemView: TAction; 28 AItemEdit: TAction; 29 AItemAdd: TAction; 30 AItemDelete: TAction; 31 ActionListItem: TActionList; 32 ButtonAdd: TButton; 33 ButtonRemove: TButton; 34 ImageListActions: TImageList; 19 35 Label1: TLabel; 20 36 Label2: TLabel; 21 37 ListView1: TListView; 38 MenuItem1: TMenuItem; 39 MenuItem2: TMenuItem; 40 MenuItem3: TMenuItem; 41 MenuItem4: TMenuItem; 42 MenuItem5: TMenuItem; 43 MenuItem6: TMenuItem; 44 MenuItem7: TMenuItem; 45 MenuItem8: TMenuItem; 46 Panel1: TPanel; 47 Panel2: TPanel; 48 PopupMenuObjectGroup: TPopupMenu; 49 PopupMenuObject: TPopupMenu; 50 PopupMenuItem: TPopupMenu; 51 Splitter1: TSplitter; 22 52 TreeView1: TTreeView; 53 procedure AItemAddExecute(Sender: TObject); 54 procedure AItemEditExecute(Sender: TObject); 55 procedure AItemViewExecute(Sender: TObject); 56 procedure AObjectGroupAddGroupExecute(Sender: TObject); 57 procedure ButtonAddClick(Sender: TObject); 23 58 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 24 59 procedure FormCreate(Sender: TObject); 60 procedure FormDestroy(Sender: TObject); 25 61 procedure FormShow(Sender: TObject); 26 62 procedure ListView1DblClick(Sender: TObject); … … 37 73 PersistentForm: TPersistentForm; 38 74 Database: TSQLDatabase; 75 TreeState: TTreeState; 39 76 procedure LoadTree; 40 77 procedure LoadItemList; … … 45 82 46 83 implementation 84 85 uses 86 UItemView, UItemEdit; 47 87 48 88 {$R *.lfm} … … 87 127 LoadConfiguration; 88 128 Database.Connect; 129 TreeState := TTreeState.Create; 89 130 PersistentForm := TPersistentForm.Create; 90 131 end; 91 132 133 procedure TMainForm.FormDestroy(Sender: TObject); 134 begin 135 TreeState.Destroy; 136 Database.Destroy; 137 PersistentForm.Destroy; 138 end; 139 92 140 procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); 93 141 begin 94 142 PersistentForm.Save(Self); 143 end; 144 145 procedure TMainForm.ButtonAddClick(Sender: TObject); 146 begin 147 148 end; 149 150 procedure TMainForm.AItemViewExecute(Sender: TObject); 151 begin 152 ItemViewForm.Show; 153 end; 154 155 procedure TMainForm.AObjectGroupAddGroupExecute(Sender: TObject); 156 begin 157 158 end; 159 160 procedure TMainForm.AItemEditExecute(Sender: TObject); 161 begin 162 ItemEditForm.Show; 163 end; 164 165 procedure TMainForm.AItemAddExecute(Sender: TObject); 166 begin 167 95 168 end; 96 169 … … 103 176 procedure TMainForm.ListView1DblClick(Sender: TObject); 104 177 begin 105 ItemViewForm.Show;178 AItemViewExecute(Self); 106 179 end; 107 180 108 181 procedure TMainForm.ListView1KeyPress(Sender: TObject; var Key: char); 109 182 begin 110 if Key = #13 then ListView1DblClick(Sender);183 if Key = #13 then AItemViewExecute(Self); 111 184 end; 112 185 … … 125 198 SelectedItem := Integer(ListView1.Selected.Data) 126 199 else SelectedItem := 0; 200 201 AItemDelete.Enabled := Assigned(ListView1.Selected); 202 AItemView.Enabled := Assigned(ListView1.Selected); 203 AItemEdit.Enabled := Assigned(ListView1.Selected); 127 204 end; 128 205 … … 130 207 begin 131 208 LoadItemList; 209 AObjectGroupDelete.Enabled := Assigned(TreeView1.Selected); 210 AObjectGroupEdit.Enabled := Assigned(TreeView1.Selected); 211 if Assigned(TreeView1.Selected) then begin 212 if TreeView1.Selected.ImageIndex = 0 then 213 TreeView1.PopupMenu := PopupMenuObjectGroup; 214 if TreeView1.Selected.ImageIndex = 1 then 215 TreeView1.PopupMenu := PopupMenuObject; 216 end; 132 217 end; 133 218 … … 142 227 begin 143 228 with TreeView1, Items do begin 229 TreeState.SaveTree(TreeView1); 144 230 Clear; 145 231 AddChild(nil, 'Skupiny'); 146 DbRows := Database.Query('SELECT * FROM `MenuGroup`'); 232 TopItem.ImageIndex := 0; 233 TopItem.SelectedIndex := 0; 234 DbRows := Database.Query('SELECT * FROM `ObjectGroup`'); 147 235 for I := 0 to DbRows.Count - 1 do begin 148 236 NewNode := AddChild(TopItem, DbRows[I].Values['Name']); 149 ObjectDbRows := Database.Query('SELECT * FROM `Object` WHERE `MenuGroup`=' + DbRows[I].Values['Id']); 237 NewNode.ImageIndex := 0; 238 NewNode.SelectedIndex := 0; 239 ObjectDbRows := Database.Query('SELECT * FROM `Object` WHERE `Group`=' + DbRows[I].Values['Id']); 150 240 for O := 0 to ObjectDbRows.Count - 1 do begin 151 241 NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']); 152 NewObjectNode.ImageIndex := StrToInt(ObjectDbRows[O].Values['Id']); 242 NewObjectNode.Data := Pointer(StrToInt(ObjectDbRows[O].Values['Id'])); 243 NewObjectNode.ImageIndex := 1; 244 NewObjectNode.SelectedIndex := 1; 153 245 end; 154 246 ObjectDbRows.Destroy; … … 156 248 TopItem.Expand(True); 157 249 DbRows.Destroy; 250 TreeState.LoadTree(TreeView1); 158 251 end; 159 252 end; … … 173 266 with ListView1, Items do begin 174 267 Clear; 175 DbRows := Database.Query('SELECT * FROM `Object` WHERE `Id`=' + IntToStr( TreeView1.Selected.ImageIndex));268 DbRows := Database.Query('SELECT * FROM `Object` WHERE `Id`=' + IntToStr(Integer(TreeView1.Selected.Data))); 176 269 if DbRows.Count = 1 then begin 177 270 SelectedObject := StrToInt(DbRows[0].Values['Id']);
Note:
See TracChangeset
for help on using the changeset viewer.