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

Last change on this file was 54, checked in by chronos, 12 years ago
  • Added: ChronisAppServer base project.
  • Modified: Changes in client virtual database layer handling.
File size: 8.0 KB
Line 
1unit UFormItemEdit;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
9 StdCtrls, Spin, EditBtn, USqlDatabase, MaskEdit, ComCtrls, USystem,
10 SpecializedList, SpecializedDictionary, UPDClient;
11
12type
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
59var
60 ItemEditForm: TItemEditForm;
61
62implementation
63
64uses
65 UFormMain, UDataTypes, UCore, UFormItemAdd, UFormItemView, UFormMenu;
66
67{$R *.lfm}
68
69{ TItemEditForm }
70
71procedure TItemEditForm.ButtonCancelClick(Sender: TObject);
72begin
73 Close;
74end;
75
76procedure TItemEditForm.ButtonDeleteClick(Sender: TObject);
77begin
78 if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
79
80 end;
81end;
82
83procedure TItemEditForm.ButtonEditClick(Sender: TObject);
84begin
85 if Assigned(ListView1.Selected) then
86 ItemEditForm.Show;
87end;
88
89procedure TItemEditForm.ButtonAddClick(Sender: TObject);
90begin
91 ItemAddForm.Show;
92end;
93
94procedure TItemEditForm.ListView1Data(Sender: TObject; Item: TListItem);
95var
96 I: Integer;
97begin
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;
106end;
107
108procedure TItemEditForm.ListView1DblClick(Sender: TObject);
109begin
110 if Assigned(ListView1.Selected) then ButtonView.Click;
111end;
112
113procedure TItemEditForm.ListView1KeyPress(Sender: TObject; var Key: char);
114begin
115 if Key = #13 then ButtonView.Click;
116end;
117
118
119procedure TItemEditForm.ButtonSaveClick(Sender: TObject);
120var
121 Proxy: TObjectProxy;
122 I: Integer;
123 DataType: TDataType;
124begin
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;
148end;
149
150procedure TItemEditForm.ButtonViewClick(Sender: TObject);
151begin
152 if Assigned(ListView1.Selected) then
153 ItemViewForm.Show;
154end;
155
156procedure TItemEditForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
157 );
158begin
159 MainForm.PersistentForm.Save(Self);
160end;
161
162procedure TItemEditForm.FormCreate(Sender: TObject);
163begin
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;
174end;
175
176procedure TItemEditForm.FormDestroy(Sender: TObject);
177begin
178 SubListObject.Free;
179 Report.Free;
180 TabObjectList.Free;
181 TabDataTypeList.Free;
182 SelectedObject.Free;
183end;
184
185procedure TItemEditForm.FormShow(Sender: TObject);
186begin
187 MainForm.PersistentForm.Load(Self);
188 BuildControls;
189 LoadSubList;
190end;
191
192procedure TItemEditForm.BuildControls;
193var
194 Values: TDbRows;
195 LastTop: Integer;
196 I: Integer;
197 Column: Integer;
198 DataType: TDataType;
199 NewControl: TControl;
200 NewWinControl: TWinControl;
201const
202 ColumnCount = 2;
203begin
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;
249end;
250
251procedure TItemEditForm.LoadSubList;
252begin
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);
266end;
267
268procedure TItemEditForm.ListView1Resize(Sender: TObject);
269var
270 I: Integer;
271begin
272 for I := 0 to ListView1.Columns.Count - 1 do
273 ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
274end;
275
276procedure TItemEditForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
277 Selected: Boolean);
278begin
279 ButtonDelete.Enabled := Assigned(ListView1.Selected);
280 ButtonView.Enabled := Assigned(ListView1.Selected);
281 ButtonEdit.Enabled := Assigned(ListView1.Selected);
282end;
283
284procedure TItemEditForm.TabControl1Change(Sender: TObject);
285begin
286 LoadSubList;
287end;
288
289
290end.
291
Note: See TracBrowser for help on using the repository browser.