MyReport实践:为ERP系统添加打印功能



准备阶段

首先准备2html页面分别集成myreport的预览和设计功能,作为预览页面和打印编辑页面。

集成方式参考:Js与flash交互:在html页面中用js与MyReport插件交互

 

打印相关API

加载数据和格式

页面初始化时,获取浏览器地址栏参数,然后加载配置文件,加载单据的数据和打印格式,调用OrderAPI.LoadPrintData方法。

                     private var _Params:UrlParams;

                    

                     private function Init():void

                     {

                           //

                          

                           _Params = new UrlParams(url);

                           if(!_Params.HasParam("uid"))

                           {

                                  hlib.MsgUtil.ShowInfo("URL缺少uid参数!");

                                  return;

                           }

                           if(!_Params.HasParam("mid"))

                           {

                                  hlib.MsgUtil.ShowInfo("URL缺少mid参数!");

                                  return;

                           }

                           if(!_Params.HasParam("action"))

                           {

                                  hlib.MsgUtil.ShowInfo("URL缺少action参数!");

                                  return;

                           }

                           if(!_Params.HasParam("code"))

                           {

                                  hlib.MsgUtil.ShowInfo("URL缺少code参数!");

                                  return;

                           }

                          

                           var configLoader:UrlLoader = new UrlLoader();

                           configLoader.DisposeAfterLoad = true;

                           configLoader.addEventListener(Event.COMPLETE, OnConfigLoadComplete);

                           configLoader.Load("Config.xml");

                     }

                     private function OnConfigLoadComplete(e:Event):void

                     {

                           var configLoader:UrlLoader = e.currentTargetas UrlLoader;

                           var settings:XML = XML(configLoader.Data);

                           common.net.APIUtil.Server = settings.ERPServicePath;

                           if(!APIUtil.Server)

                           {

                                  MsgUtil.ShowInfo("Config.xml缺少配置ERPServicePath");

                           }

                          

                           OrderAPI.LoadPrintData(_Params.GetParam("mid"),_Params.GetParam("action"),

                                  _Params.GetParam("uid"),_Params.GetParam("code"),

                                  function(item:Object):void

                                  {

                                         var style:XML = null;

                                         if(item.PRINT_STYLE)

                                                style = new XML(item.PRINT_STYLE);

                                         delete item.PRINT_STYLE;

                                        

                                         var detail:Object = item.detail;

                                         delete item.detail;

                                        

                                         _Preview.Load(style,detail, item);//MyReport控件加载数据

                                  });

                     }

打印完成通知

监控MyReport控件的打印完成事件MyReportEvent.PRINT,向后台发送打印完成通知,调用OrderAPI.ReportPrintCompleted方法

                     private function OnMyReportEvent(e:MyReportEvent):void

                     {

                           if(e.type == MyReportEvent.PRINT)

                           {

                                  OrderAPI.ReportPrintCompleted(_Params.GetParam("mid"),_Params.GetParam("action"),

                                         _Params.GetParam("uid"),_Params.GetParam("code"), new Date(), "", function(value:int):void

                                         {

                                                if(_Preview.ParameterData)

                                                       _Preview.ParameterData.PRINT_COUNT = value;

                                         });

                           }

                     }

保存打印格式

监听MyReport设计控件的保存事件DesignEvent.SAVE,向后台保存打印格式,调用OrderAPI.SavePrintStyle方法。

                     private function OnDesignEvent(e:DesignEvent):void

                     {

                           if(e.type == DesignEvent.SAVE)

                           {

                                  var content:String = _Design.GetSettingXML();

                                  OrderAPI.SavePrintStyle(_Params.GetParam("mid"),_Params.GetParam("action"),

                                         _Params.GetParam("uid"),content,

                                         function(success:Boolean):void

                                         {

                                                hui.tooltip.ToolTipUtil.ShowToolTip("保存");

                                         });

                           }

        

                     }

页面与后台服务器的接口交互

MyReport实践:为ERP系统添加打印功能_第1张图片 

MyReport实践:为ERP系统添加打印功能_第2张图片

集成效果

在单据模块的工具栏增加打印相关按钮:打印、格式编辑、打印详情。

点击【打印】按钮,在新页面显示打印预览。

MyReport实践:为ERP系统添加打印功能_第3张图片

点击【格式编辑】,在新页面显示打印编辑。

MyReport实践:为ERP系统添加打印功能_第4张图片

点击【打印详情】,弹出窗体显示打印详情列表。

MyReport实践:为ERP系统添加打印功能_第5张图片

相关链接

MyReport演示、产品网站

 

相关文章

MyReport专栏

 

你可能感兴趣的:(打印,Flex,设计,ERP,MyReport)