uniGUI的0.95.0.1045版本提供了CallbackUrl, 我们也可以用这个提供的回调网址来实现优秀的国产报表插件在IE\Chorme\FireFox中在线设计并保存报表到服务端的功能。
界面效果如下:
代码如下:
unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIRegClasses, uniGUIForm, uniGUIBaseClasses, uniPanel, uniHTMLFrame, uniURLFrame, uniButton, uniLabel; type TMainForm = class(TUniForm) UniHTMLFrame1: TUniHTMLFrame; Panle1: TUniPanel; btn1: TUniButton; lbl1: TUniLabel; procedure btn1Click(Sender: TObject); procedure UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings); private procedure SetDeignReportHTML(); { Private declarations } public { Public declarations } end; function MainForm: TMainForm; implementation {$R *.dfm} uses uniGUIVars, MainModule, uniGUIApplication, ServerModule; function MainForm: TMainForm; begin Result := TMainForm(UniMainModule.GetFormInstance(TMainForm)); end; procedure TMainForm.btn1Click(Sender: TObject); begin self.SetDeignReportHTML; end; procedure TMainForm.SetDeignReportHTML; var stringList: TStringList; LoadReportURL,DataURL, saveReportURL,BrowSertype: string; c: TUniClientInfoRec; begin UniHTMLFrame1.HTML.Clear; LoadReportURL := 'POST::files/grf/1a.grf'; DataURL :='files/data/xmlCustomer.xml'; saveReportURL := UniSession.CallbackUrl('ReportSave', Self, []); stringList := TStringList.Create; try c := UniApplication.ClientInfoRec; BrowSertype := c.BrowserType; if (c.BrowserType = 'chrome') or (c.BrowserType = 'gecko') then begin stringList.Text := ' <object id="ReportDesigner" type="application/x-grplugin-designer" ' +'width="100%" height="100%">' +' <param name="LoadReportURL" value="' +LoadReportURL + '">' + '<param name="SaveReportURL" value="' + saveReportURL +'">' +' <param name="DataURL" value="'+DataURL+'">' +' <param name="SerialNo" value="4DFB949E066NYS7W11L8KAT53SA177391Q9LZQ094WUT9C9J3813SX8PTQC4ALPB9UAQN6">' + '<param name="UserName" value="锐浪报表插件本机开发测试注册">' +' <param name="ViewStyle" value="15"></object>'; end else if c.BrowserType = 'ie' then begin stringList.Text := '<object width="100%" height="100%" id="ReportDesigner" ' +'classid="clsid:3C19F439-B64D-4dfb-A96A-661FE70EA04D" ' +'codeBase="grinstall/grbsctl5.cab#Version=5,8,13,715">' +'<param name="LoadReportURL" value="' + LoadReportURL + '">' +'<param name="DataURL" value="'+DataURL+'">' +'<param name="SaveReportURL" value="' + saveReportURL +'">' +' <param name="SerialNo" value="4DFB949E066NYS7W11L8KAT53SA177391Q9LZQ094WUT9C9J3813SX8PTQC4ALPB9UAQN6">' + '<param name="UserName" value="锐浪报表插件本机开发测试注册">' +'<param name="ViewStyle" value="15"></object>'; end; UniHTMLFrame1.HTML.Text := stringList.Text; finally stringList.Free; end; end; procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings); var stringlist:TStringList; stringStream:TStringStream; FileName:string; begin if EventName='ReportSave' then begin stringlist := TStringList.Create; stringStream := TStringStream.Create; try TMemoryStream(UniSession.ARequest.PostStream).SaveToStream(stringStream); stringlist.Add(stringStream.DataString); FileName := UniServerModule.StartPath+'/files/grf/1a.grf'; //可以保存为文件,也可以根据需要保存到数据库中 stringlist.SaveToFile(fileName); finally stringlist.Free; stringStream.Free; end; end; end; initialization RegisterAppFormClass(TMainForm); end.
object MainForm: TMainForm Left = 0 Top = 0 ClientHeight = 369 ClientWidth = 598 Caption = 'uniGUI'#20013'Grid++Report'#35774#35745#24182#20445#23384#25253#34920#27169#26495 Color = clBtnFace WindowState = wsMaximized OldCreateOrder = False MonitoredKeys.Keys = <> ClientEvents.UniEvents.Strings = ( 'window.beforeInit=function window.beforeInit(sender)'#13#10'{'#13#10' Ext.u' + 'seShims =true;'#13#10'}') OnAjaxEvent = UniFormAjaxEvent PixelsPerInch = 96 TextHeight = 13 object UniHTMLFrame1: TUniHTMLFrame Left = 0 Top = 48 Width = 598 Height = 321 Hint = '' AutoScroll = False Align = alClient Anchors = [akLeft, akTop, akRight, akBottom] end object Panle1: TUniPanel Left = 0 Top = 0 Width = 598 Height = 48 Hint = '' Caption = '' Align = alTop Anchors = [akLeft, akTop, akRight] TabOrder = 1 object btn1: TUniButton Left = 3 Top = 3 Width = 102 Height = 39 Hint = '' Caption = #35774#35745#25253#34920 TabOrder = 1 OnClick = btn1Click end object lbl1: TUniLabel Left = 144 Top = 14 Width = 377 Height = 28 Hint = '' AutoSize = False Caption = #20445#23384#21518#65292#21487#20197#20877#27425#28857#35774#35745#25253#34920#65292#30475#26159#21542#25104#21151#20445#23384#20462#25913#30340#32467#26524 TabOrder = 2 end end end