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演示、產品網站

 

相關文章

MyReport專欄

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com