| 1 | unit UFormItemAdd;
|
|---|
| 2 |
|
|---|
| 3 | {$mode Delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
|---|
| 9 | StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase, USystem,
|
|---|
| 10 | SpecializedDictionary, SpecializedList, UPDClient;
|
|---|
| 11 |
|
|---|
| 12 | type
|
|---|
| 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 |
|
|---|
| 36 | var
|
|---|
| 37 | ItemAddForm: TItemAddForm;
|
|---|
| 38 |
|
|---|
| 39 | implementation
|
|---|
| 40 |
|
|---|
| 41 | uses
|
|---|
| 42 | UFormMain, UDataTypes, UCore;
|
|---|
| 43 |
|
|---|
| 44 | {$R *.lfm}
|
|---|
| 45 |
|
|---|
| 46 | { TItemAddForm }
|
|---|
| 47 |
|
|---|
| 48 | procedure TItemAddForm.ButtonCancelClick(Sender: TObject);
|
|---|
| 49 | begin
|
|---|
| 50 | Close;
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | procedure TItemAddForm.ButtonSaveClick(Sender: TObject);
|
|---|
| 54 | var
|
|---|
| 55 | Data: TDictionaryStringString;
|
|---|
| 56 | NewProxy: TObjectProxy;
|
|---|
| 57 | I: Integer;
|
|---|
| 58 | DataType: TDataType;
|
|---|
| 59 | begin
|
|---|
| 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;
|
|---|
| 81 | end;
|
|---|
| 82 |
|
|---|
| 83 | procedure TItemAddForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
|---|
| 84 | );
|
|---|
| 85 | begin
|
|---|
| 86 | MainForm.PersistentForm.Save(Self);
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | procedure TItemAddForm.FormCreate(Sender: TObject);
|
|---|
| 90 | begin
|
|---|
| 91 | Report := TReport.Create;
|
|---|
| 92 | Report.Base := Core.System;
|
|---|
| 93 | SelectedObject := TChronisObject.Create;
|
|---|
| 94 | SelectedObject.Base := Core.System;
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TItemAddForm.FormDestroy(Sender: TObject);
|
|---|
| 98 | begin
|
|---|
| 99 | Report.Free;
|
|---|
| 100 | SelectedObject.Free;
|
|---|
| 101 | end;
|
|---|
| 102 |
|
|---|
| 103 | procedure TItemAddForm.FormKeyPress(Sender: TObject; var Key: char);
|
|---|
| 104 | begin
|
|---|
| 105 | if Key = #27 then Close;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | procedure TItemAddForm.FormShow(Sender: TObject);
|
|---|
| 109 | begin
|
|---|
| 110 | MainForm.PersistentForm.Load(Self);
|
|---|
| 111 | BuildControls;
|
|---|
| 112 | end;
|
|---|
| 113 |
|
|---|
| 114 | procedure TItemAddForm.BuildControls;
|
|---|
| 115 | var
|
|---|
| 116 | NewControl: TWinControl;
|
|---|
| 117 | LastTop: Integer;
|
|---|
| 118 | I: Integer;
|
|---|
| 119 | Column: Integer;
|
|---|
| 120 | ValueType: Integer;
|
|---|
| 121 | NewLabel: TLabel;
|
|---|
| 122 | DataType: TDataType;
|
|---|
| 123 | const
|
|---|
| 124 | ColumnCount = 2;
|
|---|
| 125 | begin
|
|---|
| 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;
|
|---|
| 160 | end;
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 | end.
|
|---|
| 164 |
|
|---|