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

Last change on this file was 53, checked in by chronos, 13 years ago
  • Opraveno: Aktualizace seznamu modulů do databáze a použití příznaku modulů "Instalován" pro zjištění, zda vytvářet znova strukturu.
File size: 4.4 KB
Line 
1unit UFormItemAdd;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
9 StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase, USystem,
10 SpecializedDictionary, SpecializedList, UPDClient;
11
12type
13
14 { TItemAddForm }
15
16 TItemAddForm = class(TForm)
17 ButtonCancel: TButton;
18 ButtonSave: TButton;
19 Panel1: TPanel;
20 procedure ButtonCancelClick(Sender: TObject);
21 procedure ButtonSaveClick(Sender: TObject);
22 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
23 procedure FormCreate(Sender: TObject);
24 procedure FormDestroy(Sender: TObject);
25 procedure FormKeyPress(Sender: TObject; var Key: char);
26 procedure FormShow(Sender: TObject);
27 private
28 procedure BuildControls;
29 { private declarations }
30 public
31 SelectedObject: TChronisObject;
32 SelectedItemId: Integer;
33 Report: TReport;
34 end;
35
36var
37 ItemAddForm: TItemAddForm;
38
39implementation
40
41uses
42 UFormMain, UDataTypes, UCore;
43
44{$R *.lfm}
45
46{ TItemAddForm }
47
48procedure TItemAddForm.ButtonCancelClick(Sender: TObject);
49begin
50 Close;
51end;
52
53procedure TItemAddForm.ButtonSaveClick(Sender: TObject);
54var
55 Data: TDictionaryStringString;
56 NewProxy: TObjectProxy;
57 I: Integer;
58 DataType: TDataType;
59begin
60 with Core.System do
61 try
62 Data := TDictionaryStringString.Create;
63 NewProxy := TObjectProxy.Create;
64 NewProxy.Client := Client;
65 NewProxy.ObjectName := SelectedObject.Table;
66 NewProxy.Path := SelectedObject.Schema;
67 for I := 0 to Report.Columns.Count - 1 do
68 if not (TReportColumn(Report.Columns[I]).CustomType is TDataTypeRelationMany) then
69 if TReportColumn(Report.Columns[I]).ColumnName <> SelectedObject.PrimaryKey then begin
70 DataType := TReportColumn(Report.Columns[I]).CustomType;
71 NewProxy.Properties.Add(TReportColumn(Report.Columns[I]).ColumnName,
72 DataType.GetControlValue(TWinControl(TReportColumn(Report.Columns[I]).Control)));
73 end;
74 NewProxy.Save;
75 finally
76 Data.Free;
77 NewProxy.Free;
78 end;
79 //MainForm.LoadItemList;
80 Close;
81end;
82
83procedure TItemAddForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
84 );
85begin
86 MainForm.PersistentForm.Save(Self);
87end;
88
89procedure TItemAddForm.FormCreate(Sender: TObject);
90begin
91 Report := TReport.Create;
92 Report.Base := Core.System;
93 SelectedObject := TChronisObject.Create;
94 SelectedObject.Base := Core.System;
95end;
96
97procedure TItemAddForm.FormDestroy(Sender: TObject);
98begin
99 Report.Free;
100 SelectedObject.Free;
101end;
102
103procedure TItemAddForm.FormKeyPress(Sender: TObject; var Key: char);
104begin
105 if Key = #27 then Close;
106end;
107
108procedure TItemAddForm.FormShow(Sender: TObject);
109begin
110 MainForm.PersistentForm.Load(Self);
111 BuildControls;
112end;
113
114procedure TItemAddForm.BuildControls;
115var
116 NewControl: TWinControl;
117 LastTop: Integer;
118 I: Integer;
119 Column: Integer;
120 ValueType: Integer;
121 NewLabel: TLabel;
122 DataType: TDataType;
123const
124 ColumnCount = 2;
125begin
126 LastTop := 8;
127 Column := 0;
128
129 for I := Panel1.ControlCount - 1 downto 0 do
130 Panel1.Controls[I].Free;
131
132 Report.Load(SelectedObject, SelectedObject.PrimaryKey + ' = ' +
133 IntToStr(SelectedItemId));
134
135 // Load column names
136 for I := 0 to Report.Columns.Count - 1 do
137 if TReportColumn(Report.Columns[I]).ColumnName <> 'Id' then begin
138 NewLabel := TLabel.Create(Panel1);
139 NewLabel.Parent := Panel1;
140 NewLabel.Top := LastTop;
141 NewLabel.Left := Column * Width div ColumnCount + 10;
142 NewLabel.Caption := TReportColumn(Report.Columns[I]).Caption + ':';
143
144 DataType := TReportColumn(Report.Columns[I]).CustomType;
145 DataType.LoadDef(TReportColumn(Report.Columns[I]).CustomType.CustomType);
146 if not (DataType is TDataTypeRelationMany) then begin
147 NewControl := DataType.CreateControl(Panel1);
148 DataType.SetDefault;
149 DataType.SetupControl(NewControl);
150 NewControl.Parent := Panel1;
151 NewControl.Top := LastTop;
152 NewControl.Left := Column * Width div ColumnCount + (Width div ColumnCount) div 2;
153 NewControl.Width := (Width div ColumnCount) div 2 - 20;
154 TReportColumn(Report.Columns[I]).Control := NewControl;
155
156 Column := (Column + 1) mod 2;
157 if Column = 0 then LastTop := LastTop + NewControl.Height + 4;
158 end;
159 end;
160end;
161
162
163end.
164
Note: See TracBrowser for help on using the repository browser.