git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@46 b6239004-a887-0f4b-9937-50029ccdca16
289 lines
8.8 KiB
ObjectPascal
289 lines
8.8 KiB
ObjectPascal
unit uDAReconcileDialogDetails;
|
|
|
|
{----------------------------------------------------------------------------}
|
|
{ Data Abstract Library - Core Library }
|
|
{ }
|
|
{ compiler: Delphi 6 and up, Kylix 3 and up }
|
|
{ platform: Win32, Linux }
|
|
{ }
|
|
{ (c)opyright RemObjects Software. all rights reserved. }
|
|
{ }
|
|
{ Using this code requires a valid license of the Data Abstract }
|
|
{ which can be obtained at http://www.remobjects.com. }
|
|
{----------------------------------------------------------------------------}
|
|
|
|
{$I DataAbstract.inc}
|
|
|
|
interface
|
|
uses
|
|
SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, StdCtrls, ExtCtrls, uDADelta, uDADataTable, DB,
|
|
{$IFDEF FPC} buttons,LResources,{$ENDIF}
|
|
uDARemoteDataAdapter;
|
|
|
|
type
|
|
TReconcileDialogDetailsForm = class(TForm)
|
|
ScrollBox: TScrollBox;
|
|
BottomPanel: TPanel;
|
|
OkButton: TButton;
|
|
CloseButton: TButton;
|
|
TopPanel: TPanel;
|
|
CancelButton: TButton;
|
|
memMessageError: TMemo;
|
|
procedure FormCreate(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
dbeditHeight, labelheight: integer;
|
|
FChange: TDADeltaChange;
|
|
Datasource: TDADataSource;
|
|
procedure Setup;
|
|
procedure GenerateControls;
|
|
procedure OnFieldValueChanged(Sender: TObject);
|
|
public
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
var
|
|
ReconcileDialogDetailsForm: TReconcileDialogDetailsForm;
|
|
|
|
procedure ReconcileDialogShowDetails(AChange: TDADeltaChange; aTable: TDADataTable; aCaption: string; var AAction: TDAReconcileDialogAction);
|
|
implementation
|
|
uses
|
|
uDAInterfaces, uROClasses, dbCtrls, uROBinaryHelpers;
|
|
|
|
{$IFNDEF FPC}
|
|
{$R *.dfm}
|
|
{$ENDIF}
|
|
|
|
const
|
|
labelWidth = 100;
|
|
editWidth = 200;
|
|
c_Color: TColor = clMoneyGreen;
|
|
|
|
procedure ReconcileDialogShowDetails(AChange: TDADeltaChange; aTable: TDADataTable; aCaption: string; var AAction: TDAReconcileDialogAction);
|
|
var
|
|
FFiltered: Boolean;
|
|
FMasterDS: TDADataSource;
|
|
FRemoteFetchEnabled: Boolean;
|
|
FMasterFields: string;
|
|
r: integer;
|
|
begin
|
|
with TReconcileDialogDetailsForm.Create(Application) do try
|
|
Caption := Format(Caption, [aCaption]);
|
|
FChange := AChange;
|
|
FFiltered := ATable.Filtered;
|
|
FMasterDS := aTable.MasterSource;
|
|
FMasterFields := aTable.MasterFields;
|
|
FRemoteFetchEnabled := aTable.RemoteFetchEnabled;
|
|
try
|
|
ATable.Filtered := False;
|
|
aTable.MasterSource := nil;
|
|
aTable.MasterFields := '';
|
|
aTable.RemoteFetchEnabled := False;
|
|
DataSource.DataTable := aTable;
|
|
Setup;
|
|
r := ShowModal;
|
|
if (ruoOnPost in aTable.RemoteUpdatesOptions) then begin
|
|
case r of
|
|
mrOk: AAction := rdlgRepost;
|
|
mrCancel: AAction := rdlgRevert;
|
|
end;
|
|
DataSource.DataTable.Delta.EndChange;
|
|
end
|
|
else begin
|
|
case r of
|
|
mrOk: AAction := rdlgSkip;
|
|
mrCancel: AAction := rdlgCancel;
|
|
else AAction := rdlgNone;
|
|
end;
|
|
if DataSource.DataTable.State in [dsEdit, dsInsert] then DataSource.DataTable.Post;
|
|
end;
|
|
finally
|
|
aTable.RemoteFetchEnabled := FRemoteFetchEnabled;
|
|
aTable.Filtered := FFiltered;
|
|
aTable.MasterSource := FMasterDS;
|
|
aTable.MasterFields := FMasterFields
|
|
end;
|
|
finally
|
|
Release;
|
|
end;
|
|
end;
|
|
|
|
{ TShowDetailsForm }
|
|
|
|
procedure TReconcileDialogDetailsForm.Setup;
|
|
begin
|
|
if FChange.ChangeType <> ctDelete then
|
|
with DataSource.DataTable do
|
|
if not (ruoOnPost in RemoteUpdatesOptions) and not Locate(RecIDFieldName, FChange.RecID, []) then RaiseError('Couldn''t find record #' + FormatRecIDString(FChange.RecID));
|
|
GenerateControls;
|
|
memMessageError.Lines.Text := FChange.Message;
|
|
|
|
if (ruoOnPost in DataSource.DataTable.RemoteUpdatesOptions) then begin
|
|
OkButton.Left := CancelButton.Left;
|
|
OkButton.Enabled := False;
|
|
OkButton.Visible := FChange.ChangeType <> ctDelete ;
|
|
OkButton.Caption := 'Update';
|
|
CancelButton.Left := CloseButton.Left;
|
|
CancelButton.Caption := 'Revert';
|
|
CloseButton.Visible := False;
|
|
CloseButton.Enabled := False;
|
|
ActiveControl := CancelButton;
|
|
DataSource.DataTable.Delta.StartChange(ctUpdate);
|
|
end;
|
|
end;
|
|
|
|
procedure TReconcileDialogDetailsForm.OnFieldValueChanged(Sender: TObject);
|
|
begin
|
|
OkButton.Enabled := True;
|
|
OkButton.Caption := 'Update';
|
|
end;
|
|
|
|
procedure TReconcileDialogDetailsForm.GenerateControls;
|
|
|
|
function _VarToStr(AValue: variant; ADataType: TDADataType): string;
|
|
begin
|
|
if ADataType = datDecimal then
|
|
Result := DecimalVariantToString(AValue)
|
|
else
|
|
Result := VarToStr(AValue)
|
|
end;
|
|
|
|
var
|
|
i: integer;
|
|
aField: string;
|
|
aField2: string;
|
|
aTop, aleft: integer;
|
|
FLabel: TLabel;
|
|
FdbEdit: TDBEdit;
|
|
FEdit: TEdit;
|
|
begin
|
|
aleft := 7;
|
|
aTop := 7;
|
|
for i := 0 to FChange.Delta.LoggedFieldCount - 1 do begin
|
|
aField := FChange.Delta.LoggedFieldNames[i];
|
|
aField2 := StringReplace(aField,'@','___replaced___',[rfReplaceAll]); // it should be unique
|
|
aTop := 7 + (3 + dbeditHeight) * i;
|
|
aleft := 7;
|
|
|
|
FLabel := TLabel.Create(Self);
|
|
with FLabel do begin
|
|
Parent := ScrollBox;
|
|
Name := 'l_' + aField2;
|
|
Caption := aField;
|
|
Left := aleft;
|
|
Top := (dbeditHeight - Height) div 2 + aTop + 1;
|
|
Width := labelWidth;
|
|
aleft := aleft + 7 + labelWidth;
|
|
Font.Name := 'Tahoma';
|
|
end;
|
|
|
|
if FChange.ChangeType in [ctInsert, ctUpdate] then begin
|
|
if Self.DataSource.DataTable.FieldByName(aField).DataType = datBlob then begin
|
|
FEdit := TEdit.Create(Self);
|
|
with FEdit do begin
|
|
Name := 'dbe_' + aField2;
|
|
Parent := ScrollBox;
|
|
Left := aleft;
|
|
aleft := aleft + 7 + editWidth;
|
|
Top := aTop;
|
|
Width := editWidth;
|
|
ReadOnly := True;
|
|
Text := '[blob]';
|
|
Font.Name := 'Tahoma';
|
|
end;
|
|
end
|
|
else begin
|
|
FdbEdit := TDBEdit.Create(Self);
|
|
with FdbEdit do begin
|
|
Name := 'dbe_' + aField2;
|
|
DataSource := Self.DataSource;
|
|
Parent := ScrollBox;
|
|
DataField := aField;
|
|
Left := aleft;
|
|
Top := aTop;
|
|
Width := editWidth;
|
|
aleft := aleft + 7 + editWidth;
|
|
OnChange := OnFieldValueChanged;
|
|
if (FChange.ChangeType = ctUpdate) and
|
|
not ROVariantsEqual(FChange.OldValues[i], FChange.NewValues[i]) then
|
|
Color := c_Color;
|
|
Font.Name := 'Tahoma';
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if FChange.ChangeType in [ctUpdate, ctDelete] then begin
|
|
FEdit := TEdit.Create(Self);
|
|
with FEdit do begin
|
|
Name := 'e_' + aField2;
|
|
Parent := ScrollBox;
|
|
Left := aleft;
|
|
aleft := aleft + 7 + editWidth;
|
|
Top := aTop;
|
|
Width := editWidth;
|
|
ReadOnly := True;
|
|
Color := clBtnFace;
|
|
Font.Name := 'Tahoma';
|
|
if Self.DataSource.DataTable.FieldByName(aField).DataType = datBlob then begin
|
|
Text := '[blob]'
|
|
end
|
|
else begin
|
|
case FChange.ChangeType of
|
|
ctDelete: text := _VarToStr(FChange.OldValues[i],FChange.Delta.LoggedFieldTypes[i]);
|
|
ctUpdate: begin
|
|
if not Self.DataSource.DataTable.HasReducedDelta then
|
|
text := _VarToStr(FChange.OldValues[i],FChange.Delta.LoggedFieldTypes[i])
|
|
else
|
|
if not VarIsEmpty(FChange.OldValues[i]) then
|
|
text := _VarToStr(FChange.OldValues[i],FChange.Delta.LoggedFieldTypes[i])
|
|
else text := Self.DataSource.DataTable.FieldByName(aField).AsString;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
inc(aTop, 20);
|
|
inc(aLeft, 7);
|
|
//ScrollBox.HorzScrollBar.Range := aleft;
|
|
Self.ClientWidth := aleft + ScrollBox.VertScrollBar.Size + 2;
|
|
Self.Constraints.MinWidth := Self.Width;
|
|
Self.Constraints.MaxWidth := Self.Width;
|
|
|
|
|
|
CloseButton.left := Self.ClientWidth - 7 - CloseButton.Width;
|
|
CancelButton.Left := CloseButton.left - 5 - CancelButton.Width;
|
|
OkButton.Left := CancelButton.left - 5 - OkButton.Width;
|
|
|
|
ScrollBox.VertScrollBar.Range := aTop;
|
|
if Screen.Height > Self.Height + (aTop - ScrollBox.Height) then
|
|
Self.Height := Self.Height + (aTop - ScrollBox.Height)
|
|
else
|
|
Self.Height := Screen.Height;
|
|
end;
|
|
|
|
procedure TReconcileDialogDetailsForm.FormCreate(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
with TDBEdit.Create(Self) do try
|
|
dbeditHeight := Height;
|
|
finally
|
|
free;
|
|
end;
|
|
with TLabel.Create(Self) do try
|
|
labelheight := Height;
|
|
finally
|
|
free;
|
|
end;
|
|
Datasource := TDADataSource.Create(Self);
|
|
end;
|
|
|
|
{$IFDEF FPC}
|
|
initialization
|
|
{$I uDAReconcileDialogDetails.lrs}
|
|
{$ENDIF}
|
|
end.
|
|
|