Componentes.Terceros.RemObj.../official/5.0.23.613/Data Abstract for Delphi/Source/IDE/uDADataTableEditorForm.pas

436 lines
15 KiB
ObjectPascal

unit uDADataTableEditorForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uDADataTable, StdCtrls, Buttons, ExtCtrls, uRODL, uROClasses,
uRORemoteService, uROClientIntf;
type
TDADataTableEditorForm = class(TForm)
btn_Ok: TBitBtn;
BitBtn2: TBitBtn;
cb_DataSets: TComboBox;
Label1: TLabel;
Label2: TLabel;
cb_GetSchemaMethods: TComboBox;
Label3: TLabel;
cb_GetDataMethods: TComboBox;
cb_ApplyUpdatesMethods: TComboBox;
Label6: TLabel;
Label9: TLabel;
pnl_GetSchemaOptions: TPanel;
Label4: TLabel;
Label5: TLabel;
ed_GetSchemaValue: TEdit;
cb_GetSchemaParams: TComboBox;
pnl_GetDataOptions: TPanel;
Label7: TLabel;
Label8: TLabel;
ed_GetDataValue: TEdit;
cb_GetDataParams: TComboBox;
pnl_ApplyUpdatesOptions: TPanel;
Label10: TLabel;
Label11: TLabel;
ed_ApplyUpdatesValue: TEdit;
cb_ApplyUpdatesParams: TComboBox;
Label12: TLabel;
cb_GetScriptsMethods: TComboBox;
pnl_GetScriptOptions: TPanel;
Label13: TLabel;
Label14: TLabel;
ed_GetScriptsValue: TEdit;
cb_GetScriptsParams: TComboBox;
procedure OnMethodChanged(Sender: TObject);
procedure cb_DataSetsChange(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure cb_GetSchemaMethodsChange(Sender: TObject);
procedure cb_GetDataMethodsChange(Sender: TObject);
procedure cb_ApplyUpdatesMethodsChange(Sender: TObject);
procedure btn_OkClick(Sender: TObject);
procedure cb_GetScriptsMethodsChange(Sender: TObject);
private
fDataTable: TDADataTable;
fManuallySelectedMethods:boolean;
fMethods:TStringList;
fLibrary:TRODLLibrary;
fGetSchemaParams,fGetDataParams,fApplyUpdateParams,fGetScriptsParams:TDARemoteRequestParams;
procedure FillDataSetsCombo;
procedure EnablePanel(iPanel:TPanel; iEnable:boolean=true);
procedure FillParameters(iMethodCombo, iParamCombo: TComboBox; iParamEdit:TEdit);
procedure CreateParameters(iMethodCombo, iParamCombo: TComboBox; iParamEdit: TEdit; ioParams: TDARemoteRequestParams);
function GetSchemaAsXML(aRemoteService : TRORemoteService): String;
public
class function Execute(aOwner:TComponent; aDataTable:TDADataTable; var aDataSet:string):boolean;
end;
implementation
uses
uROTypes, uDAClientDataModule, uDAClasses, uDAIDERes, uDAPleaseWaitForm;
{$R *.dfm}
{ TForm1 }
procedure TDADataTableEditorForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fMethods);
FreeAndNil(fLibrary);
FreeAndNil(fGetSchemaParams);
FreeAndNil(fGetDataParams);
FreeAndNil(fApplyUpdateParams);
FreeAndNil(fGetScriptsParams);
end;
class function TDADataTableEditorForm.Execute(aOwner: TComponent; aDataTable: TDADataTable; var aDataSet:string): boolean;
begin
with self.Create(aOwner) do try
Caption := Format(Caption,[aDataTable.Name]);
fDataTable := aDataTable;
FillDataSetsCombo();
cb_DataSets.ItemIndex := cb_DataSets.Items.IndexOf(aDataSet);
cb_DataSetsChange(nil);
result := ShowModal = idOk;
if result then begin
{aDataTable.SchemaCall.MethodName := cb_GetSchemaMethods.Text;
aDataTable.SchemaCall.Params.Assign(fGetSchemaParams);
aDataTable.DataRequestCall.MethodName := cb_GetDataMethods.Text;
aDataTable.DataRequestCall.Params.Assign(fGetDataParams);
aDataTable.DataUpdateCall.MethodName := cb_ApplyUpdatesMethods.Text;
aDataTable.DataUpdateCall.Params.Assign(fApplyUpdateParams);
aDataTable.ScriptCall.MethodName := cb_GetScriptsMethods.Text;
aDataTable.ScriptCall.Params.Assign(fGetScriptsParams);}
aDataSet := cb_DataSets.Text;
end;
finally
Free();
end;
end;
function TDADataTableEditorForm.GetSchemaAsXML(aRemoteService : TRORemoteService): String;
var __request, __response : TMemoryStream;
__TransportChannel : IROTransportChannel;
__Message : IROMessage;
begin
__TransportChannel := aRemoteService.Channel;
__Message := aRemoteService.Message;
__request := TMemoryStream.Create;
__response := TMemoryStream.Create;
try
__Message.Initialize(__TransportChannel, 'DataAbstract', aRemoteService.ServiceName, 'GetSchemaAsXML');
__Message.Finalize;
__Message.WriteToStream(__request);
__TransportChannel.Dispatch(__request, __response);
__Message.ReadFromStream(__response);
__Message.Read('Result', TypeInfo(String), result, []);
finally
__request.Free;
__response.Free;
end
end;
procedure TDADataTableEditorForm.FillDataSetsCombo;
var
p: Integer;
lDataSets: TStringList;
i: Integer;
lService: TRODLService;
lSchema:TDASchema;
begin
(*fMethods := TStringList.Create();
fLibrary := fDataTable.RemoteService.GetRODLLibrary();
fGetSchemaParams := TDARemoteRequestParams.Create(nil);
fGetDataParams := TDARemoteRequestParams.Create(nil);
fApplyUpdateParams := TDARemoteRequestParams.Create(nil);
fGetScriptsParams := TDARemoteRequestParams.Create(nil);
lDataSets := TStringList.Create();
try
lService := fLibrary.FindService(fDataTable.RemoteService.ServiceName);
while Assigned(lService) do begin
for i := 0 to lService.Default.Count-1 do begin
fMethods.AddObject(lService.Default.Items[i].Info.Name,lService.Default.Items[i]);
end;
if (lService.Ancestor <> '')
then lService := fLibrary.FindService(lService.Ancestor)
else lService := nil;
end;
fMethods.Sort();
cb_GetSchemaMethods.Items.Assign(fMethods);
cb_GetDataMethods.Items.Assign(fMethods);
cb_ApplyUpdatesMethods.Items.Assign(fMethods);
cb_GetScriptsMethods.Items.Assign(fMethods);
lDataSets.Duplicates := dupIgnore;
lDataSets.Sorted := true;
if Assigned(fDataTable.RemoteService) then begin
if not Assigned(fDataTable.RemoteService.Channel) then RaiseError(err_AssignRemoteServiceChannel);
if not Assigned(fDataTable.RemoteService.Message) then RaiseError(err_AssignRemoteServiceMessage);
lSchema := nil;
with CreatePleaseWaitForm(self,'Retrieving Schema...') do try
try
lSchema := TDASchema.Create(nil);
lSchema.LoadFromXml(GetSchemaAsXML(fDataTable.RemoteService));
except
lSchema.Free;
raise;
end;
finally
Hide;
end;
try
for i := 0 to lSchema.Datasets.Count-1 do begin
lDataSets.Add(lSchema.Datasets[i].Name);
end; { for }
finally
lSchema.Free();
end;
end
else begin
for i := 0 to fMethods.Count-1 do begin
p := Pos('_',fMethods[i]);
if p > 0 then lDataSets.Add(Copy(fMethods[i],p+1,Length(fMethods[i])-p));
end; { for }
end;
cb_DataSets.Items.Assign(lDataSets);
finally
FreeAndNil(lDataSets);
end;
*)
end;
procedure TDADataTableEditorForm.OnMethodChanged(Sender: TObject);
begin
fManuallySelectedMethods := true;
end;
procedure TDADataTableEditorForm.EnablePanel(iPanel:TPanel; iEnable:boolean=true);
var
i:integer;
begin
for i := 0 to ComponentCount-1 do if (Components[i] as TControl).Parent = iPanel then begin
if Components[i] is TLabel then TLabel(Components[i]).Enabled := iEnable
else if Components[i] is TComboBox then TComboBox(Components[i]).Enabled := iEnable
else if Components[i] is TEdit then TEdit(Components[i]).Enabled := iEnable
end;
end;
procedure TDADataTableEditorForm.cb_DataSetsChange(Sender: TObject);
var
lIndex:integer;
lDataSetName:string;
begin
if not fManuallySelectedMethods then begin
lDataSetName := StringReplace(cb_DataSets.Text,' ','_',[rfReplaceAll]);
lIndex := cb_GetSchemaMethods.Items.IndexOf('GetDatasetSchema_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetSchemaMethods.Items.IndexOf('GetSchema_'+lDataSetName);
if lIndex > -1 then begin
cb_GetSchemaMethods.ItemIndex := lIndex;
cb_GetSchemaMethodsChange(nil);
EnablePanel(pnl_GetSchemaOptions,false);
end
else begin
lIndex := cb_GetSchemaMethods.Items.IndexOf('GetDatasetSchema');
if lIndex = -1 then cb_GetSchemaMethods.Text := '';
cb_GetSchemaMethods.ItemIndex := lIndex;
cb_GetSchemaMethodsChange(nil);
end;
lIndex := cb_GetScriptsMethods.Items.IndexOf('GetDatasetScript_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetScriptsMethods.Items.IndexOf('GetDatasetScripts_'+lDataSetName);
if lIndex > -1 then begin
cb_GetScriptsMethods.ItemIndex := lIndex;
cb_GetScriptsMethodsChange(nil);
EnablePanel(pnl_GetScriptOptions,false);
end
else begin
lIndex := cb_GetScriptsMethods.Items.IndexOf('GetDatasetScripts');
if lIndex = -1 then cb_GetScriptsMethods.Text := '';
cb_GetScriptsMethods.ItemIndex := lIndex;
cb_GetScriptsMethodsChange(nil);
end;
lIndex := cb_GetDataMethods.Items.IndexOf('GetDatasetData_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Get_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Get'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Load_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Load'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Read_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Read'+lDataSetName);
if lIndex > -1 then begin
cb_GetDataMethods.ItemIndex := lIndex;
cb_GetDataMethodsChange(nil);
EnablePanel(pnl_GetDataOptions,false);
end
else begin
EnablePanel(pnl_GetDataOptions);
lIndex := cb_GetDataMethods.Items.IndexOf('GetDatasetDataEx');
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('GetDatasetData');
if lIndex = -1 then cb_GetDataMethods.Text := '';
cb_GetDataMethods.ItemIndex := lIndex;
cb_GetDataMethodsChange(nil);
end;
lIndex := cb_ApplyUpdatesMethods.Items.IndexOf('UpdateData_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Update_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Update'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Set_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Set'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Save_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Save'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Write_'+lDataSetName);
if lIndex = -1 then lIndex := cb_GetDataMethods.Items.IndexOf('Write'+lDataSetName);
if lIndex > -1 then begin
cb_ApplyUpdatesMethods.ItemIndex := lIndex;
cb_ApplyUpdatesMethodsChange(nil);
EnablePanel(pnl_ApplyUpdatesOptions,false);
end
else begin
EnablePanel(pnl_ApplyUpdatesOptions);
lIndex := cb_ApplyUpdatesMethods.Items.IndexOf('UpdateData');
if lIndex = -1 then cb_ApplyUpdatesMethods.Text := '';
cb_ApplyUpdatesMethods.ItemIndex := lIndex;
cb_ApplyUpdatesMethodsChange(nil);
end;
fManuallySelectedMethods := false;
end;
end;
procedure TDADataTableEditorForm.FillParameters(iMethodCombo, iParamCombo:TComboBox; iParamEdit:TEdit);
var
lIndex:integer;
lMethod:TRODLOperation;
i:integer;
begin
iParamCombo.Items.Clear();
lIndex := iMethodCombo.ItemIndex;
if lIndex > -1 then begin
lMethod := (fMethods.Objects[lIndex] as TRODLOperation);
iParamCombo.ItemIndex := -1;
iParamCombo.Text := '';
iParamEdit.Text := '';
for i := 0 to lMethod.Count-1 do begin
if (lMethod.Items[i].Flag in [fIn, fInOut]) and (lMethod.Items[i].DataType = DataTypeNames[rtString]) then begin
iParamCombo.Items.Add(lMethod.Items[i].Name);
end;
end;
//if iParamCombo.Enabled then begin
if (iParamCombo.Items.Count > 0) then begin
iParamCombo.ItemIndex := 0;
iParamEdit.Text := cb_DataSets.Text;
EnablePanel(iParamEdit.Parent as TPanel);
end
else begin
iParamEdit.Text := '';
EnablePanel(iParamEdit.Parent as TPanel,false);
end;
//end
end;
end;
procedure TDADataTableEditorForm.cb_GetSchemaMethodsChange(Sender: TObject);
begin
FillParameters(cb_GetSchemaMethods, cb_GetSchemaParams, ed_GetSchemaValue);
end;
procedure TDADataTableEditorForm.cb_GetDataMethodsChange(Sender: TObject);
begin
FillParameters(cb_GetDataMethods, cb_GetDataParams, ed_GetDataValue);
end;
procedure TDADataTableEditorForm.cb_ApplyUpdatesMethodsChange(Sender: TObject);
begin
FillParameters(cb_ApplyUpdatesMethods, cb_ApplyUpdatesParams, ed_ApplyUpdatesValue);
end;
procedure TDADataTableEditorForm.cb_GetScriptsMethodsChange(Sender: TObject);
begin
FillParameters(cb_GetScriptsMethods, cb_GetScriptsParams, ed_GetScriptsValue);
end;
procedure TDADataTableEditorForm.CreateParameters(iMethodCombo, iParamCombo:TComboBox; iParamEdit:TEdit; ioParams:TDARemoteRequestParams);
var
lIndex:integer;
lMethod:TRODLOperation;
i:integer;
newparam : TDARemoteRequestParam;
begin
ioParams.Clear();
lIndex := iMethodCombo.ItemIndex;
if lIndex > -1 then begin
lMethod := (fMethods.Objects[lIndex] as TRODLOperation);
// AleF: fixed this one too and moved up to be consistent with the RODL changes of ages ago
if Assigned(lMethod.Result) then begin
ioParams.Add.CopyRODLParam(lMethod.Result);
end;
for i := 0 to lMethod.Count-1 do begin
// AleF: fixed this up so that it uses a common copy function instead of duplicating it like it was before
newparam := ioParams.Add;
newparam.CopyRODLParam(lMethod.Items[i]);
// Sets defaults
with newparam do begin
if (Flag in [fIn, fInOut]) and (Name = iParamCombo.Text) then begin
AsString := ed_GetSchemaValue.Text;
end
else if SameText(Name, 'MaxRecords') then begin
AsInteger := -1;
end
else if SameText(Name, 'IncludeSchema') then begin
AsBoolean := false;
end
else if (newparam.DataType=rtString) and VarIsEmpty(newparam.AsVariant) then begin
newparam.AsVariant := '';
end;
end;
end;
end;
end;
procedure TDADataTableEditorForm.btn_OkClick(Sender: TObject);
begin
CreateParameters(cb_GetSchemaMethods, cb_GetSchemaParams, ed_GetSchemaValue, fGetSchemaParams);
CreateParameters(cb_GetDataMethods, cb_GetDataParams, ed_GetDataValue, fGetDataParams);
CreateParameters(cb_ApplyUpdatesMethods, cb_ApplyUpdatesParams, ed_ApplyUpdatesValue, fApplyUpdateParams);
CreateParameters(cb_GetScriptsMethods, cb_GetScriptsParams, ed_GetScriptsValue, fGetScriptsParams);
end;
end.