source: branches/test1/Client/Forms/UFormItemList.pas

Last change on this file was 46, checked in by chronos, 13 years ago
File size: 5.7 KB
Line 
1unit UFormItemList;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ComCtrls, ActnList, Menus, USystem;
10
11type
12
13 { TItemListForm }
14
15 TItemListForm = class(TForm)
16 AClose: TAction;
17 AItemClone: TAction;
18 AItemView: TAction;
19 AItemEdit: TAction;
20 AItemAdd: TAction;
21 AItemDelete: TAction;
22 ActionList1: TActionList;
23 ListView1: TListView;
24 MenuItem1: TMenuItem;
25 MenuItem2: TMenuItem;
26 MenuItem3: TMenuItem;
27 MenuItem4: TMenuItem;
28 MenuItem5: TMenuItem;
29 PopupMenu1: TPopupMenu;
30 ToolBar1: TToolBar;
31 ToolButton1: TToolButton;
32 ToolButton2: TToolButton;
33 ToolButton3: TToolButton;
34 ToolButton4: TToolButton;
35 ToolButton5: TToolButton;
36 procedure ACloseExecute(Sender: TObject);
37 procedure AItemAddExecute(Sender: TObject);
38 procedure AItemDeleteExecute(Sender: TObject);
39 procedure AItemEditExecute(Sender: TObject);
40 procedure AItemViewExecute(Sender: TObject);
41 procedure FormCreate(Sender: TObject);
42 procedure FormDestroy(Sender: TObject);
43 procedure FormShow(Sender: TObject);
44 procedure ListView1Data(Sender: TObject; Item: TListItem);
45 procedure ListView1KeyPress(Sender: TObject; var Key: char);
46 procedure ListView1Resize(Sender: TObject);
47 procedure ListView1DblClick(Sender: TObject);
48 procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
49 Selected: Boolean);
50 private
51 Report: TReport;
52 public
53 SelectedObject: TChronisObject;
54 SelectedItem: Integer;
55 procedure Reload;
56 procedure UpdateInterface;
57 end;
58
59var
60 ItemListForm: TItemListForm;
61
62implementation
63
64uses
65 UCore, UFormItemView, UFormItemEdit, UFormItemAdd, UFormMain;
66
67{$R *.lfm}
68
69{ TItemListForm }
70
71procedure TItemListForm.Reload;
72var
73 NewColumn: TListColumn;
74 I: Integer;
75begin
76 with ListView1 do begin
77 Visible := True;
78 //SelectedObject.Load(SelectedObject.Id);
79 Report.Load(SelectedObject);
80
81 Report.FillListColumns(Columns);
82 Items.Count := Report.Count;
83 Refresh;
84 end;
85 ListView1Resize(Self);
86 ListView1SelectItem(Self, nil, False);
87end;
88
89procedure TItemListForm.UpdateInterface;
90var
91 I: Integer;
92begin
93 AItemDelete.Enabled := Assigned(ListView1.Selected);
94 AItemView.Enabled := Assigned(ListView1.Selected);
95 AItemEdit.Enabled := Assigned(ListView1.Selected);
96 AItemClone.Enabled := Assigned(ListView1.Selected);
97
98 for I := 0 to ToolBar1.ButtonCount - 1 do
99 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
100end;
101
102procedure TItemListForm.AItemViewExecute(Sender: TObject);
103var
104 NewItemViewForm: TItemViewForm;
105begin
106 if Assigned(ListView1.Selected) then begin
107 NewItemViewForm := TItemViewForm.Create(nil);
108 NewItemViewForm.SelectedObject.Assign(SelectedObject);
109 NewItemViewForm.SelectedItemId := Integer(ListView1.Selected.Data);
110 NewItemViewForm.Caption := NewItemViewForm.Caption + ' ' + SelectedObject.Name;
111 NewItemViewForm.ShowModal;
112 //MainForm.SetMainPanelForm(NewItemViewForm);
113 NewItemViewForm.Free;
114 end;
115end;
116
117procedure TItemListForm.FormCreate(Sender: TObject);
118begin
119 Report := TReport.Create;
120 Report.Base := Core.System;
121 SelectedObject := TChronisObject.Create;
122 SelectedObject.Base := Core.System;
123end;
124
125procedure TItemListForm.FormDestroy(Sender: TObject);
126begin
127 ListView1.Items.Clear;
128 SelectedObject.Free;
129 Report.Free;
130end;
131
132procedure TItemListForm.FormShow(Sender: TObject);
133begin
134 Reload;
135end;
136
137procedure TItemListForm.AItemEditExecute(Sender: TObject);
138var
139 NewItemEditForm: TItemEditForm;
140begin
141 if Assigned(ListView1.Selected) then
142 try
143 NewItemEditForm := TItemEditForm.Create(nil);
144 NewItemEditForm.SelectedObject.Assign(SelectedObject);
145 NewItemEditForm.SelectedItemId := Integer(ListView1.Selected.Data);
146 NewItemEditForm.Caption := NewItemEditForm.Caption + ' ' + SelectedObject.Name;
147 NewItemEditForm.ShowModal;
148 finally
149 NewItemEditForm.Free;
150 end;
151end;
152
153procedure TItemListForm.AItemAddExecute(Sender: TObject);
154var
155 NewItemAddForm: TItemAddForm;
156begin
157 try
158 NewItemAddForm := TItemAddForm.Create(nil);
159 NewItemAddForm.SelectedObject.Assign(SelectedObject);
160 //NewItemAddForm.SelectedItemId := Integer(ListView1.Selected.Data);
161 NewItemAddForm.Caption := NewItemAddForm.Caption + ' ' + SelectedObject.Name;
162 NewItemAddForm.ShowModal;
163 finally
164 NewItemAddForm.Free;
165 end;
166end;
167
168procedure TItemListForm.ACloseExecute(Sender: TObject);
169begin
170 Close;
171end;
172
173procedure TItemListForm.AItemDeleteExecute(Sender: TObject);
174begin
175 if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
176 end;
177end;
178
179procedure TItemListForm.ListView1Data(Sender: TObject; Item: TListItem);
180var
181 I: Integer;
182begin
183 if Item.Index < Report.Count then
184 with TReportLine(Report[Item.Index]) do begin
185 Item.Caption := Items[0];
186 Item.Data := Pointer(Id);
187 for I := 1 to Report.Columns.Count - 1 do
188 if not TReportColumn(Report.Columns[I]).VirtualItem then begin
189 Item.SubItems.Add(Items[I]);
190 end;
191 end;
192end;
193
194procedure TItemListForm.ListView1DblClick(Sender: TObject);
195begin
196 AItemView.Execute;
197end;
198
199procedure TItemListForm.ListView1KeyPress(Sender: TObject; var Key: char);
200begin
201 if Key = #13 then AItemViewExecute(Self);
202end;
203
204procedure TItemListForm.ListView1Resize(Sender: TObject);
205var
206 I: Integer;
207begin
208 for I := 0 to ListView1.Columns.Count - 1 do
209 ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
210end;
211
212procedure TItemListForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
213 Selected: Boolean);
214begin
215 UpdateInterface;
216end;
217
218end.
219
Note: See TracBrowser for help on using the repository browser.