1 | unit UFormItemEdit;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
---|
9 | StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, ComCtrls, USystem,
|
---|
10 | SpecializedList, SpecializedDictionary, UPDClient;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TItemEditForm }
|
---|
15 |
|
---|
16 | TItemEditForm = class(TForm)
|
---|
17 | ButtonAdd: TButton;
|
---|
18 | ButtonDelete: TButton;
|
---|
19 | ButtonEdit: TButton;
|
---|
20 | ButtonSave: TButton;
|
---|
21 | ButtonCancel: TButton;
|
---|
22 | ButtonView: TButton;
|
---|
23 | ListView1: TListView;
|
---|
24 | Panel1: TPanel;
|
---|
25 | Panel2: TPanel;
|
---|
26 | Panel3: TPanel;
|
---|
27 | PanelControls: TPanel;
|
---|
28 | Splitter1: TSplitter;
|
---|
29 | TabControl1: TTabControl;
|
---|
30 | procedure ButtonAddClick(Sender: TObject);
|
---|
31 | procedure ButtonCancelClick(Sender: TObject);
|
---|
32 | procedure ButtonDeleteClick(Sender: TObject);
|
---|
33 | procedure ButtonEditClick(Sender: TObject);
|
---|
34 | procedure ButtonSaveClick(Sender: TObject);
|
---|
35 | procedure ButtonViewClick(Sender: TObject);
|
---|
36 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
37 | procedure FormCreate(Sender: TObject);
|
---|
38 | procedure FormDestroy(Sender: TObject);
|
---|
39 | procedure FormShow(Sender: TObject);
|
---|
40 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
41 | procedure ListView1DblClick(Sender: TObject);
|
---|
42 | procedure ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
43 | procedure ListView1Resize(Sender: TObject);
|
---|
44 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
45 | Selected: Boolean);
|
---|
46 | procedure TabControl1Change(Sender: TObject);
|
---|
47 | private
|
---|
48 | SubListObject: TChronisObject;
|
---|
49 | TabObjectList: TListInteger;
|
---|
50 | TabDataTypeList: TListObject;
|
---|
51 | procedure LoadSubList;
|
---|
52 | public
|
---|
53 | SelectedObject: TChronisObject;
|
---|
54 | SelectedItemId: Integer;
|
---|
55 | Report: TReport;
|
---|
56 | procedure BuildControls;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | var
|
---|
60 | ItemEditForm: TItemEditForm;
|
---|
61 |
|
---|
62 | implementation
|
---|
63 |
|
---|
64 | uses
|
---|
65 | UFormMain, UDataTypes, UCore, UFormItemAdd, UFormItemView, UFormMenu;
|
---|
66 |
|
---|
67 | {$R *.lfm}
|
---|
68 |
|
---|
69 | { TItemEditForm }
|
---|
70 |
|
---|
71 | procedure TItemEditForm.ButtonCancelClick(Sender: TObject);
|
---|
72 | begin
|
---|
73 | Close;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | procedure TItemEditForm.ButtonDeleteClick(Sender: TObject);
|
---|
77 | begin
|
---|
78 | if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
|
---|
79 |
|
---|
80 | end;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TItemEditForm.ButtonEditClick(Sender: TObject);
|
---|
84 | begin
|
---|
85 | if Assigned(ListView1.Selected) then
|
---|
86 | ItemEditForm.Show;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | procedure TItemEditForm.ButtonAddClick(Sender: TObject);
|
---|
90 | begin
|
---|
91 | ItemAddForm.Show;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | procedure TItemEditForm.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
95 | var
|
---|
96 | I: Integer;
|
---|
97 | begin
|
---|
98 | if Item.Index < Report.Count then
|
---|
99 | with TReportLine(Report[Item.Index]) do begin
|
---|
100 | Item.Caption := Items[0];
|
---|
101 | Item.Data := Pointer(Id);
|
---|
102 | for I := 1 to Items.Count - 1 do
|
---|
103 | if not TReportColumn(Report.Columns[I]).VirtualItem then
|
---|
104 | Item.SubItems.Add(Items[I]);
|
---|
105 | end;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TItemEditForm.ListView1DblClick(Sender: TObject);
|
---|
109 | begin
|
---|
110 | if Assigned(ListView1.Selected) then ButtonView.Click;
|
---|
111 | end;
|
---|
112 |
|
---|
113 | procedure TItemEditForm.ListView1KeyPress(Sender: TObject; var Key: char);
|
---|
114 | begin
|
---|
115 | if Key = #13 then ButtonView.Click;
|
---|
116 | end;
|
---|
117 |
|
---|
118 |
|
---|
119 | procedure TItemEditForm.ButtonSaveClick(Sender: TObject);
|
---|
120 | var
|
---|
121 | Proxy: TObjectProxy;
|
---|
122 | I: Integer;
|
---|
123 | DataType: TDataType;
|
---|
124 | begin
|
---|
125 | with Core.System do
|
---|
126 | try
|
---|
127 | Proxy := TObjectProxy.Create;
|
---|
128 | Proxy.Client := Client;
|
---|
129 | Proxy.ObjectName := SelectedObject.Table;
|
---|
130 | Proxy.Path := SelectedObject.Schema;
|
---|
131 | Proxy.Id := SelectedItemId;
|
---|
132 | for I := 0 to Report.Columns.Count - 1 do
|
---|
133 | if not (TReportColumn(Report.Columns[I]).CustomType is TDataTypeRelationMany) then
|
---|
134 | if TReportColumn(Report.Columns[I]).ColumnName <> SelectedObject.PrimaryKey then begin
|
---|
135 | DataType := TReportColumn(Report.Columns[I]).CustomType;
|
---|
136 | Proxy.Properties.Add(TReportColumn(Report.Columns[I]).ColumnName,
|
---|
137 | DataType.GetControlValue(TWinControl(TReportColumn(Report.Columns[I]).Control)));
|
---|
138 | end;
|
---|
139 | Proxy.Save;
|
---|
140 | finally
|
---|
141 | Proxy.Free;
|
---|
142 | end;
|
---|
143 | if (SelectedObject.Table = SystemMenuTable) or
|
---|
144 | (SelectedObject.Table = SystemObjectTable) then
|
---|
145 | FormMenu.LoadTree;
|
---|
146 | //MainForm.LoadItemList;
|
---|
147 | Close;
|
---|
148 | end;
|
---|
149 |
|
---|
150 | procedure TItemEditForm.ButtonViewClick(Sender: TObject);
|
---|
151 | begin
|
---|
152 | if Assigned(ListView1.Selected) then
|
---|
153 | ItemViewForm.Show;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | procedure TItemEditForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
---|
157 | );
|
---|
158 | begin
|
---|
159 | MainForm.PersistentForm.Save(Self);
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TItemEditForm.FormCreate(Sender: TObject);
|
---|
163 | begin
|
---|
164 | SubListObject := TChronisObject.Create;
|
---|
165 | SubListObject.Base := Core.System;
|
---|
166 | Report := TReport.Create;
|
---|
167 | Report.Base := Core.System;
|
---|
168 | TabObjectList := TListInteger.Create;
|
---|
169 | TabDataTypeList := TListObject.Create;
|
---|
170 | TabDataTypeList.OwnsObjects := False;
|
---|
171 | TabControl1.Tabs.Clear;
|
---|
172 | SelectedObject := TChronisObject.Create;
|
---|
173 | SelectedObject.Base := Core.System;
|
---|
174 | end;
|
---|
175 |
|
---|
176 | procedure TItemEditForm.FormDestroy(Sender: TObject);
|
---|
177 | begin
|
---|
178 | SubListObject.Free;
|
---|
179 | Report.Free;
|
---|
180 | TabObjectList.Free;
|
---|
181 | TabDataTypeList.Free;
|
---|
182 | SelectedObject.Free;
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TItemEditForm.FormShow(Sender: TObject);
|
---|
186 | begin
|
---|
187 | MainForm.PersistentForm.Load(Self);
|
---|
188 | BuildControls;
|
---|
189 | LoadSubList;
|
---|
190 | end;
|
---|
191 |
|
---|
192 | procedure TItemEditForm.BuildControls;
|
---|
193 | var
|
---|
194 | Values: TDbRows;
|
---|
195 | LastTop: Integer;
|
---|
196 | I: Integer;
|
---|
197 | Column: Integer;
|
---|
198 | DataType: TDataType;
|
---|
199 | NewControl: TControl;
|
---|
200 | NewWinControl: TWinControl;
|
---|
201 | const
|
---|
202 | ColumnCount = 2;
|
---|
203 | begin
|
---|
204 | LastTop := 8;
|
---|
205 | Column := 0;
|
---|
206 | Report.Load(SelectedObject, SelectedObject.PrimaryKey + ' = ' +
|
---|
207 | IntToStr(SelectedItemId));
|
---|
208 |
|
---|
209 | // Clear previous controls on panel
|
---|
210 | for I := PanelControls.ControlCount - 1 downto 0 do
|
---|
211 | PanelControls.Controls[I].Free;
|
---|
212 |
|
---|
213 | TabControl1.Tabs.Clear;
|
---|
214 | TabObjectList.Clear;
|
---|
215 | TabDataTypeList.Clear;
|
---|
216 | if Report.Count = 1 then
|
---|
217 | for I := 0 to Report.Columns.Count - 1 do
|
---|
218 | if (TReportColumn(Report.Columns[I]).ColumnName <> 'Id') then begin
|
---|
219 | DataType := TReportColumn(Report.Columns[I]).CustomType;
|
---|
220 | DataType.LoadDef(TReportColumn(Report.Columns[I]).CustomType.CustomType);
|
---|
221 | if DataType is TDataTypeRelationMany then begin
|
---|
222 | TabControl1.Tabs.Add(TReportColumn(Report.Columns[I]).Caption);
|
---|
223 | TabDataTypeList.Add(DataType);
|
---|
224 | TabObjectList.Add(SelectedItemId);
|
---|
225 | end else begin
|
---|
226 | NewControl := TLabel.Create(Panel1);
|
---|
227 | NewControl.Parent := PanelControls;
|
---|
228 | NewControl.Top := LastTop;
|
---|
229 | NewControl.Left := Column * Width div ColumnCount + 10;
|
---|
230 | TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
|
---|
231 |
|
---|
232 | NewWinControl := DataType.CreateControl(Panel1);
|
---|
233 | DataType.Load(TReportLine(Report[0]).Items[I]);
|
---|
234 | DataType.SetupControl(NewWinControl);
|
---|
235 | NewWinControl.Parent := Panel1;
|
---|
236 | NewWinControl.Top := LastTop;
|
---|
237 | NewWinControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
|
---|
238 | NewWinControl.Width := (Width div ColumnCount) div 2 - 20;
|
---|
239 | TReportColumn(Report.Columns[I]).Control := NewWinControl;
|
---|
240 |
|
---|
241 | Column := (Column + 1) mod 2;
|
---|
242 | if Column = 0 then LastTop := LastTop + NewWinControl.Height + 4;
|
---|
243 | end;
|
---|
244 | end;
|
---|
245 | // Panel1;
|
---|
246 | // ListView1;
|
---|
247 | // TabControl1;
|
---|
248 | Panel2.Visible := TabControl1.Tabs.Count > 0;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | procedure TItemEditForm.LoadSubList;
|
---|
252 | begin
|
---|
253 | //SelectedObjectId := 0;
|
---|
254 | if (TabControl1.TabIndex >= 0) and (TabControl1.TabIndex < TabControl1.Tabs.Count) then
|
---|
255 | with ListView1 do
|
---|
256 | with TDataTypeRelationMany(TabDataTypeList[TabControl1.TabIndex]) do begin
|
---|
257 | Visible := True;
|
---|
258 | SubListObject.Load(ObjectId);
|
---|
259 | Report.Load(SubListObject, '`' + PropertyName + '`=' + IntToStr(TabObjectList[TabControl1.TabIndex]));
|
---|
260 |
|
---|
261 | Report.FillListColumns(Columns);
|
---|
262 | Items.Count := Report.Count;
|
---|
263 | Refresh;
|
---|
264 | end;
|
---|
265 | ListView1Resize(Self);
|
---|
266 | end;
|
---|
267 |
|
---|
268 | procedure TItemEditForm.ListView1Resize(Sender: TObject);
|
---|
269 | var
|
---|
270 | I: Integer;
|
---|
271 | begin
|
---|
272 | for I := 0 to ListView1.Columns.Count - 1 do
|
---|
273 | ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
|
---|
274 | end;
|
---|
275 |
|
---|
276 | procedure TItemEditForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
277 | Selected: Boolean);
|
---|
278 | begin
|
---|
279 | ButtonDelete.Enabled := Assigned(ListView1.Selected);
|
---|
280 | ButtonView.Enabled := Assigned(ListView1.Selected);
|
---|
281 | ButtonEdit.Enabled := Assigned(ListView1.Selected);
|
---|
282 | end;
|
---|
283 |
|
---|
284 | procedure TItemEditForm.TabControl1Change(Sender: TObject);
|
---|
285 | begin
|
---|
286 | LoadSubList;
|
---|
287 | end;
|
---|
288 |
|
---|
289 |
|
---|
290 | end.
|
---|
291 |
|
---|