1 | unit UFormItemList;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
9 | ComCtrls, ActnList, Menus, USystem;
|
---|
10 |
|
---|
11 | type
|
---|
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 |
|
---|
59 | var
|
---|
60 | ItemListForm: TItemListForm;
|
---|
61 |
|
---|
62 | implementation
|
---|
63 |
|
---|
64 | uses
|
---|
65 | UCore, UFormItemView, UFormItemEdit, UFormItemAdd, UFormMain;
|
---|
66 |
|
---|
67 | {$R *.lfm}
|
---|
68 |
|
---|
69 | { TItemListForm }
|
---|
70 |
|
---|
71 | procedure TItemListForm.Reload;
|
---|
72 | var
|
---|
73 | NewColumn: TListColumn;
|
---|
74 | I: Integer;
|
---|
75 | begin
|
---|
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);
|
---|
87 | end;
|
---|
88 |
|
---|
89 | procedure TItemListForm.UpdateInterface;
|
---|
90 | var
|
---|
91 | I: Integer;
|
---|
92 | begin
|
---|
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;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | procedure TItemListForm.AItemViewExecute(Sender: TObject);
|
---|
103 | var
|
---|
104 | NewItemViewForm: TItemViewForm;
|
---|
105 | begin
|
---|
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;
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TItemListForm.FormCreate(Sender: TObject);
|
---|
118 | begin
|
---|
119 | Report := TReport.Create;
|
---|
120 | Report.Base := Core.System;
|
---|
121 | SelectedObject := TChronisObject.Create;
|
---|
122 | SelectedObject.Base := Core.System;
|
---|
123 | end;
|
---|
124 |
|
---|
125 | procedure TItemListForm.FormDestroy(Sender: TObject);
|
---|
126 | begin
|
---|
127 | ListView1.Items.Clear;
|
---|
128 | SelectedObject.Free;
|
---|
129 | Report.Free;
|
---|
130 | end;
|
---|
131 |
|
---|
132 | procedure TItemListForm.FormShow(Sender: TObject);
|
---|
133 | begin
|
---|
134 | Reload;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TItemListForm.AItemEditExecute(Sender: TObject);
|
---|
138 | var
|
---|
139 | NewItemEditForm: TItemEditForm;
|
---|
140 | begin
|
---|
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;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | procedure TItemListForm.AItemAddExecute(Sender: TObject);
|
---|
154 | var
|
---|
155 | NewItemAddForm: TItemAddForm;
|
---|
156 | begin
|
---|
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;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | procedure TItemListForm.ACloseExecute(Sender: TObject);
|
---|
169 | begin
|
---|
170 | Close;
|
---|
171 | end;
|
---|
172 |
|
---|
173 | procedure TItemListForm.AItemDeleteExecute(Sender: TObject);
|
---|
174 | begin
|
---|
175 | if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
|
---|
176 | end;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | procedure TItemListForm.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
180 | var
|
---|
181 | I: Integer;
|
---|
182 | begin
|
---|
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;
|
---|
192 | end;
|
---|
193 |
|
---|
194 | procedure TItemListForm.ListView1DblClick(Sender: TObject);
|
---|
195 | begin
|
---|
196 | AItemView.Execute;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | procedure TItemListForm.ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
200 | begin
|
---|
201 | if Key = #13 then AItemViewExecute(Self);
|
---|
202 | end;
|
---|
203 |
|
---|
204 | procedure TItemListForm.ListView1Resize(Sender: TObject);
|
---|
205 | var
|
---|
206 | I: Integer;
|
---|
207 | begin
|
---|
208 | for I := 0 to ListView1.Columns.Count - 1 do
|
---|
209 | ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | procedure TItemListForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
213 | Selected: Boolean);
|
---|
214 | begin
|
---|
215 | UpdateInterface;
|
---|
216 | end;
|
---|
217 |
|
---|
218 | end.
|
---|
219 |
|
---|