Flex AdvancedDataGridColumn 运用
<?xml version="1.0" encoding="utf-8"?>
<!--添加会商纪录-->
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:an="com.cist.utils.page.action.*"
xmlns:com="com.cist.components.company.*"
xmlns:cdf="com.cist.utils.date.*"
creationComplete="init()"
width="840"
height="397"
title="应急能力评估--{titleStr}"
layout="absolute"
showCloseButton="true"
close="closewindow()">
<mx:Script>
<![CDATA[
import mx.controls.List;
import com.cist.utils.ImageHelper;
import com.cist.BaseWidget;
import com.cist.widgets.UrgencyAssess.CapacityAssessmentWidget;
import com.cist.utils.OpenManager;
import mx.collections.*;
import mx.controls.Alert;
import com.cist.utils.RemoteConnection;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
import com.cist.utils.page.action.PageUtil;
import com.cist.utils.init.Store;
import mx.controls.DateField;
import mx.printing.*;
import mx.printing.PrintAdvancedDataGrid;
[Bindable]
private var titleStr:String; //窗口标题
[Bindable]
private var isShow:Boolean = false; //是否显示
[Bindable]
private var isShow2:Boolean = false;
[Bindable]
private var update:Object = {};//修改查看基础信息对象
private var selCondition:Object = {};
private var bw:BaseWidget;
private var rc:RemoteObject;
private var obj:Object;
private var condition:Object = {};
private var oldState:String;
private var list:ArrayCollection= new ArrayCollection();
[Bindable]
private var assess:Object = {};
[Bindable]
private var as1:Object = {};
[Bindable]
private var as2:Object = {};
private var byteArray:ByteArray;
private var fileReference:FileReference = new FileReference();
private function init():void{
//upload
fileReference.addEventListener(Event.SELECT,file_selected);
fileReference.addEventListener(ProgressEvent.PROGRESS,progress);
fileReference.addEventListener(Event.COMPLETE,complete);
}
private var fileName:String = "";
private var size:uint = 0;
private function complete(event:Event):void{
size = fileReference.size;
fileName = fileReference.name;
byteArray = fileReference.data;
}
private function progress(event:ProgressEvent):void{
}
private function file_selected(event:Event):void{
try {
fileReference.load();
} catch (err:Error) {
// message.text = "ERROR: zero-byte file";
}
}
//下载导出文档
private function exportdownload():void{
var headname:String = update.name+update.id+".doc";
if(headname!=null&&headname!=""){
var url:String = Store.geturl();
url = url.replace("index.swf","downfile/"+headname);
var urlR:URLRequest = new URLRequest(encodeURI(url));
try{
fileReference.download(urlR,headname);
this.closewindow();
}catch(err:Error){
Alert.show("下载失败");
}
}
}
//删除导出文档
private function exportdelete():void{
var headname:String = update.name+update.id+".doc";
RemoteConnection.getRemote("assessmentService").exportDelete(headname);
this.closewindow();
}
//关闭窗口
private function closewindow():void{
OpenManager.closeTitleWindow(this,true);
}
//窗口标题、MeetingRecord、是否显示、是否可编辑
public function setparamValue(title:String,bw:BaseWidget,isShow:Boolean=false,isShow2:Boolean=false):void{
this.isShow = isShow;
this.bw = bw;
this.titleStr = title;
this.isShow2 = isShow2;
}
public function set up(o:Object):void{
this.update = o;
dpHierarchy = new ArrayCollection([
{Region:update.name, children: [
{Region:"Arizona", children: [
]},
]}
]);
showAS();
}
public function set select(s:String):void{
this.titleStr = s;
}
[Bindable]
private var dpHierarchy:ArrayCollection ;
[Bindable]
private var acc:ArrayCollection ;
public function showAS():void{
var condition :Object= {
name:update.name,
createtime:update.createTime}
RemoteConnection.getRemote("assessmentService",resultHandle).getAssess(condition);
}
public function resultHandle(event:ResultEvent):void{
list = event.result as ArrayCollection;
var aa:ArrayCollection = new ArrayCollection();
var ab:ArrayCollection = new ArrayCollection();
var cc:ArrayCollection = new ArrayCollection();
for(var i:int=0;i<list.length;i++){
var ob:Object = list[i];
if(ob.rank == "1"){
as1 = {v3id:ob.v3id,v4id:ob.v4id, Actual:ob.grade, Estimate:ob.name,con:ob.organization,expert:ob.expert,personal:ob.personnel};
aa.addItem(as1);
}
}
var oo:Object = dpHierarchy.getItemAt(0);
oo.children = aa;
for(var a:int=0;a<aa.length;a++){
for(var j:int=0;j<list.length;j++){
var ob:Object = list[j];
if(ob.rank == "2"){
as2 = {v4id:ob.v4id, Actual:ob.grade, Estimate:ob.name,con:ob.organization,expert:ob.expert,personal:ob.personnel};
ab.addItem(as2);
}
}
var ob:Object = aa.getItemAt(a);
ob.children = ab;
}
for(var b:int=0;b<ab.length;b++){
var bb:ArrayCollection = new ArrayCollection();
for(var j:int=0;j<list.length;j++){
var ob:Object = list[j];
if(ab[b].v4id == ob.v4id&&ob.rank == "3"){
assess = {v4id:ob.v4id,Actual:ob.grade, Estimate:ob.name,con:ob.organization,expert:ob.expert,personal:ob.personnel};
bb.addItem(assess);
}
}
var oa:Object = ab.getItemAt(b);
oa.children = bb;
}
this.acc = aa;
export();
}
//生成word
private function export():void{
var headname:String = update.name + ""+update.id;
var time:String = DateField.dateToString(update.createTime,"YYYY-MM-DD");
var aa:ArrayCollection = new ArrayCollection();
var condition :Object= {headname:headname,time:time,list:this.acc}
rc=RemoteConnection.getRemote("assessmentService");
rc.exportWord(condition);
}
private function doPrint():void {
var printJob:FlexPrintJob = new FlexPrintJob();
var printADG:PrintAdvancedDataGrid =
new PrintAdvancedDataGrid();
printADG.includeInLayout = false;
printADG.source = adg;
addChild(printADG);
if (printJob.start() == false) {
removeChild(printADG);
return;
}
printJob.addObject(printADG, FlexPrintJobScaleType.NONE);
printJob.send();
removeChild(printADG);
}
public function myColStyleFunc(data:Object,col:AdvancedDataGridColumn):Object {
var str:String = data["Actual"];
if(str!=null&&str!=""){
var num:Number =Number(str.charAt(0));
if((1.5<num) && (num<=2.5)){
return {color:0xEEEE55};
}
if((2.5<num) && (num<=3.5)){
return {color:0x00FF00};
}
if((3.5<num) && (num<=4)){
return {color:0x0000FF};
}
if((1.0<num) && (num<=1.5)){
return {color:0xFF0000};
}
return null;
}
return null;
}
]]>
</mx:Script>
<mx:Form width="100%" height="100%">
<mx:AdvancedDataGrid id="adg"
width="100%" height="100%">
<mx:dataProvider>
<mx:HierarchicalData source="{dpHierarchy}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Region" headerText="事件名称"/>
<mx:AdvancedDataGridColumn dataField="v3id" headerText="大类"/>
<mx:AdvancedDataGridColumn dataField="v4id" headerText="属性"/>
<mx:AdvancedDataGridColumn dataField="Estimate" headerText="评分对象"/>
<mx:AdvancedDataGridColumn dataField="Actual" headerText="评分结果" styleFunction="myColStyleFunc"/>
<mx:AdvancedDataGridColumn dataField="con" headerText="所属地区"/>
<mx:AdvancedDataGridColumn dataField="expert" headerText="评估专家"/>
<mx:AdvancedDataGridColumn dataField="personal" headerText="评估人员"/>
</mx:columns>
</mx:AdvancedDataGrid>
<mx:HBox horizontalAlign="right" width="100%">
<mx:Button id="myButton" label="打印文档" click="doPrint()" visible="{isShow2}"/>
<mx:Button id="mybt" label="返回目录" click="exportdelete()" visible="{isShow2}"/>
<mx:Button label="导出文档" click="exportdownload()" visible="{isShow}"/>
<mx:Button label="关闭返回" click="exportdelete()" visible="{isShow}"/>
</mx:HBox>
</mx:Form>
</mx:TitleWindow>