- Recompilación en Delphi10 de todos los paquetes de RO para generar las DCU's en Lib\D10 - Recompilación en Delphi10 de todos los paquetes de DA para generar las DCU's en Lib\D10 git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@9 b6239004-a887-0f4b-9937-50029ccdca16
188 lines
6.7 KiB
ObjectPascal
188 lines
6.7 KiB
ObjectPascal
unit XSLTMain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, StdCtrls, uDADataTable, uDAXMLAdapter, uDAClasses,
|
|
uDADriverManager, uDAEngine, uDAADODriver, Spin, Buttons, OleCtrls,
|
|
SHDocVw, ExtCtrls, ComCtrls, DB, uDAScriptingProvider, uDACDSDataTable,
|
|
Grids, DBGrids, uDABINAdapter, DBCtrls, uDADataStreamer,
|
|
uDARemoteDataAdapter, uDAInterfaces;
|
|
|
|
type
|
|
TXSLTMainForm = class(TForm)
|
|
DriverManager: TDADriverManager;
|
|
ADODriver: TDAADODriver;
|
|
PageControl: TPageControl;
|
|
tsXML: TTabSheet;
|
|
tsGrid: TTabSheet;
|
|
WebBrowser: TWebBrowser;
|
|
gCustomers: TDBGrid;
|
|
ConnectionManager: TDAConnectionManager;
|
|
XMLAdapter: TDAXmlDataStreamer;
|
|
gOrders: TDBGrid;
|
|
Splitter2: TSplitter;
|
|
dtCustomers: TDACDSDataTable;
|
|
GetDataButton: TButton;
|
|
dsCustomers: TDADataSource;
|
|
dtOrders: TDACDSDataTable;
|
|
dsOrders: TDADataSource;
|
|
GenerateDeltaButton: TButton;
|
|
XSLTTransformationButton: TButton;
|
|
GenerateHTMLButton: TButton;
|
|
Schema: TDASchema;
|
|
DAXmlDataStreamer: TDAXmlDataStreamer;
|
|
procedure GetDataButtonClick(Sender: TObject);
|
|
procedure GenerateDeltaButtonClick(Sender: TObject);
|
|
procedure XSLTTransformationButtonClick(Sender: TObject);
|
|
private
|
|
fTempFileName,
|
|
fHTMLFileName,
|
|
fAppDir: string;
|
|
function CreateTestUpdates1: Boolean;
|
|
procedure RefreshXMLView(AfileName: string; aDelta: Boolean = False);
|
|
public
|
|
constructor Create(aOwner: TComponent); override;
|
|
property AppDir: string read fAppDir;
|
|
property TempFileName: string read fTempFileName;
|
|
property HTMLFileName: string read fHTMLFileName;
|
|
end;
|
|
|
|
var
|
|
XSLTMainForm: TXSLTMainForm;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses
|
|
uROMSXMLImpl, uROMSXML2_TLB, uROXMLIntf, ShellAPI, uDADelta, StrUtils;
|
|
|
|
constructor TXSLTMainForm.Create(aOwner: TComponent);
|
|
begin
|
|
inherited;
|
|
fAppDir := ExtractFilePath(Application.ExeName);
|
|
fTempFileName := fAppDir + 'Temp.xml';
|
|
fHTMLFileName := fAppDir + 'CustomersHTML.html';
|
|
PageControl.ActivePageIndex := 0;
|
|
end;
|
|
|
|
procedure TXSLTMainForm.GetDataButtonClick(Sender: TObject);
|
|
begin
|
|
dtCustomers.Open;
|
|
dtOrders.Open;
|
|
if dtCustomers.DeltaInitialized then dtCustomers.CancelUpdates;
|
|
if dtOrders.DeltaInitialized then dtOrders.CancelUpdates;
|
|
XMLAdapter.WriteXSLT := nil; // In case there's one set
|
|
RefreshXMLView(TempFileName);
|
|
end;
|
|
|
|
procedure TXSLTMainForm.RefreshXMLView(AfileName: string; aDelta: Boolean = False);
|
|
var
|
|
xmlstream: TMemoryStream;
|
|
begin
|
|
xmlstream := TMemoryStream.Create;
|
|
try
|
|
// Writes the data or Delta into the stream by using the XML Adapter
|
|
XMLAdapter.Initialize(xmlstream, aiWrite);
|
|
if aDelta then begin
|
|
XMLAdapter.WriteDelta(dtCustomers);
|
|
XMLAdapter.WriteDelta(dtOrders);
|
|
end
|
|
else begin
|
|
XMLAdapter.WriteDataset(dtCustomers, [woSchema, woRows]);
|
|
XMLAdapter.WriteDataset(dtOrders, [woSchema, woRows]);
|
|
end;
|
|
XMLAdapter.Finalize;
|
|
|
|
// Saves the XML stream and displays it in the WebBrowser control
|
|
xmlstream.SaveToFile(aFileName);
|
|
WebBrowser.Navigate(aFileName);
|
|
finally
|
|
XMLStream.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TXSLTMainForm.GenerateDeltaButtonClick(Sender: TObject);
|
|
begin
|
|
// Generates some test updates (ask confirmation first)
|
|
dtCustomers.Open;
|
|
dtOrders.Open;
|
|
if not CreateTestUpdates1 then Exit;
|
|
|
|
// Erases the XSLT in case there's one set
|
|
XMLAdapter.WriteXSLT := nil; // In case there's one set
|
|
RefreshXMLView(TempFileName, True);
|
|
end;
|
|
|
|
function TXSLTMainForm.CreateTestUpdates1: Boolean;
|
|
begin
|
|
Result := False;
|
|
if (MessageDlg('Do you want to create some updates?', mtConfirmation, [mbYes, mbNo], 0) <> mrYes) then Exit;
|
|
|
|
dtCustomers.open;
|
|
dtOrders.open;
|
|
if dtCustomers.DeltaInitialized then dtCustomers.CancelUpdates;
|
|
if dtOrders.DeltaInitialized then dtOrders.CancelUpdates;
|
|
dtCustomers.Last;
|
|
|
|
try
|
|
// Inserts a bunch of new ones
|
|
dtCustomers.AddRecord(
|
|
['CustomerID', 'CompanyName', 'ContactName', 'ContactTitle', 'Address', 'City', 'Region', 'PostalCode', 'Country', 'Phone', 'Fax'],
|
|
['JONSM', 'JohnSmith&Co', 'John Smith', 'Owner', '202 North Lake Drive', 'Barrington', 'IL', '60010', 'USA', '847 389 2112', '847 389 2115']);
|
|
|
|
dtOrders.AddRecord(
|
|
['OrderID', 'EmployeeID', 'OrderDate', 'RequiredDate', 'ShippedDate', 'ShipVia', 'Freight', 'ShipName', 'ShipAddress', 'ShipCity', 'ShipRegion', 'ShipPostalCode', 'ShipCountry'],
|
|
[60000, 5, Date, Date + 30, Date + 15, 1, 73.23, 'QUICK-Stop', 'Taucherstrabe 10', 'Rio de Janeiro', 'RJ', '50739', 'Brazil']);
|
|
|
|
dtOrders.AddRecord(
|
|
['OrderID', 'EmployeeID', 'OrderDate', 'RequiredDate', 'ShippedDate', 'ShipVia', 'Freight', 'ShipName', 'ShipAddress', 'ShipCity', 'ShipRegion', 'ShipPostalCode', 'ShipCountry'],
|
|
[60001, 2, Date + 15, Date + 30, Date + 25, 1, 22.45, 'LINO-Delicateses', '2743 Bering St.', 'Rio de Janeiro', 'RJ', '50700', 'Brazil']);
|
|
|
|
dtCustomers.AddRecord(
|
|
['CustomerID', 'CompanyName', 'ContactName', 'ContactTitle', 'Address', 'City', 'Region', 'PostalCode', 'Country', 'Phone', 'Fax'],
|
|
['JACDO', 'JackDohrn Ltd', 'Jack Dohrn', 'Owner', '32 Manhattan Lane', 'Hoffman Estates', 'IL', '60074', 'USA', '847 221 3221', '842 221 3221']);
|
|
|
|
dtOrders.AddRecord(
|
|
['OrderID', 'EmployeeID', 'OrderDate', 'RequiredDate', 'ShippedDate', 'ShipVia', 'Freight', 'ShipName', 'ShipAddress', 'ShipCity', 'ShipRegion', 'ShipPostalCode', 'ShipCountry'],
|
|
[60002, 5, Date, Date + 20, Date + 10, 1, 45673.29, 'Save-a-lot Markets', 'Torikatu 38', 'Rio de Janeiro', 'RJ', '50759', 'Brazil']);
|
|
|
|
dtOrders.AddRecord(
|
|
['OrderID', 'EmployeeID', 'OrderDate', 'RequiredDate', 'ShippedDate', 'ShipVia', 'Freight', 'ShipName', 'ShipAddress', 'ShipCity', 'ShipRegion', 'ShipPostalCode', 'ShipCountry'],
|
|
[60003, 2, Date, Date + 10, Date + 2, 1, 722.23, 'Bottom-Dollar Markets', 'Fauntleroy Circus', 'Rio de Janeiro', 'RJ', '50730', 'Brazil']);
|
|
|
|
Result := True;
|
|
except
|
|
Result := False;
|
|
if dtCustomers.Editing then dtCustomers.Cancel;
|
|
if dtOrders.Editing then dtOrders.Cancel;
|
|
end;
|
|
end;
|
|
|
|
procedure TXSLTMainForm.XSLTTransformationButtonClick(Sender: TObject);
|
|
var
|
|
resfilename, xsltname: string;
|
|
begin
|
|
dtCustomers.open;
|
|
dtOrders.open;
|
|
|
|
dtCustomers.First;
|
|
|
|
// Loads the XSLT document
|
|
if (Sender = GenerateHTMLButton) then begin
|
|
xsltname := 'CustomersToHTML.xsl';
|
|
resfilename := HTMLFileName;
|
|
end
|
|
else begin
|
|
xsltname := 'CustomersToSimpleXML.xsl';
|
|
resfilename := TempFileName;
|
|
end;
|
|
XMLAdapter.WriteXSLT.LoadFromFile(xsltname);
|
|
RefreshXMLView(resfilename);
|
|
end;
|
|
|
|
end.
|
|
|