flex cron 表达式生成器

界面凑活着看吧!


Cron.mxml  :

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			    width="50%" height="80%" creationComplete="start()">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.utils.StringUtil;
			
			import spark.components.CheckBox;
			
			private var check:ExtendsCheckBox; 
			
			protected function start():void
			{
			}
			
			[Bindable]
			public var minArr:Array=new Array(); 
			private function initMin():void
			{
				for(var i:int=0;i<60;i++) 
				{ 
					check=new ExtendsCheckBox(); 
					check.id="min"+i; 
					check.label=""+i; 
					check.selected =false; 
					check.value=""+i;
					minArr.push(check);
					minTimes.addElement(check); 
				} 
			}
			
			[Bindable]
			public var hourArr:Array=new Array(); 
			private function initHour():void
			{
				for(var i:int=0;i<24;i++) 
				{ 
					check=new ExtendsCheckBox(); 
					check.id="hour"+i; 
					check.label=""+i; 
					check.selected =false; 
					check.value=""+i;
					hourArr.push(check);
					hourTimes.addElement(check); 
				} 
				
			}
			
			[Bindable]
			public var dayArr:Array=new Array(); 
			private function initDay():void
			{
				for(var i:int=1;i<=31;i++) 
				{ 
					
					check=new ExtendsCheckBox(); 
					
					check.id="day"+i; 
					check.label=""+i; 
					check.selected =false; 
					check.value=""+i;
					dayArr.push(check);
					dayTimes.addElement(check); 
				} 
				
			}
			
			[Bindable]
			public var monthArr:Array=new Array(); 
			private function initMonth():void
			{
				for(var i:int=1;i<=12;i++) 
				{ 
					
					check=new ExtendsCheckBox(); 
					
					check.id="day"+i; 
					check.label=""+i; 
					check.selected =false; 
					check.value=""+i;
					monthArr.push(check);
					monthTimes.addElement(check); 
				} 
				
			}
			
			[Bindable]
			public var weekArr:Array=new Array(); 
			private function initWeek():void
			{
				
				for(var i:int=1;i<=7;i++) 
				{ 
					check=new ExtendsCheckBox(); 
					check.id="day"+i; 
					check.label="星期"+getWeek(i); 
					check.selected =false; 
					check.value=""+i;
					weekArr.push(check);
					weekTimes.addElement(check); 
				} 
				
			}
			
			private function getWeek(w:int):String
			{
				switch(w)
				{
					case(1): return "一";
					case(2): return "二";
					case(3): return "三";
					case(4): return "四";
					case(5): return "五";
					case(6): return "六";
					case(7): return "日";
				}
				return null;
			}
			
			protected function getnerateCron(event:MouseEvent):void
			{
				var rs:String="0 "; //0秒
				//分钟
				if(mincycle.selected)
				{
					rs+=startTime.text+"/"+cycleTime.text+" ";
				}else
				{
					rs+=getTime(minArr)+" ";
				}
				
				//小时
				if(hourcycle==null || hourcycle.selected)
				{
					rs+="* ";
				}else
				{
					rs+=getTime(hourArr)+" ";
				}
				
				//天  注意只要是week 起作用那么day 就不起作用了 ?
				if(isUseWeek==null || isUseWeek.selected)
				{
					rs+="? ";
				}else
				if(daycycle==null || daycycle.selected)
				{
					rs+="* ";
				}else
				{
					rs+=getTime(dayArr)+" ";
				}
				
				//月
				if(monthcycle==null || monthcycle.selected)
				{
					rs+="* ";
				}else
				{
					rs+=getTime(monthArr)+" ";
				}
				
				//周  注意只要是week 起作用那么day 就不起作用了 ?
				if(isUseWeek==null ||isUseWeek.selected)
				{
					if(weekcycle==null || weekcycle.selected)
					{
						rs+="* ";
					}else
					{
						rs+=getTime(weekArr)+" ";
					}
				}else
				{
					rs+="? ";
				}
				resultStr.text=StringUtil.trim(rs);
				
			}
			
			//得到checkbox 的时间设置
			private function getTime(rr:Array):String
			{
				var rs:String=""
				for(var i:int=0;i<rr.length;i++) 
				{ 
					var check:ExtendsCheckBox=ExtendsCheckBox(rr[i]);   
					if(check.selected)
					{
						rs+=check.value+",";
					}
				} 
				if(rs.length !=0)
				{
					rs=rs.substring(0,rs.length-1);	
				}else
				{
					//Alert.show("请选择时间!","提示");
					rs+="*"
				}
				return rs;
			}
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<mx:TabNavigator left="10" top="10" width="100%" height="80%">
		<mx:VBox id="min" label="分钟" paddingLeft="5" paddingTop="5">
			<mx:HBox>
			<s:RadioButton id="mincycle" label="循环" groupName="ming" selected="true"/>
			<s:RadioButton label="定时" groupName="ming" />
			</mx:HBox>
			 
			<mx:HBox id="cyclebox" width="100%"  visible="{mincycle.selected}">
				
				<s:Label text="从"/>
				<s:TextInput id="startTime" maxChars ="2" visible="true" width="100" text="{startTimeSpinner.value}"/>
				<s:Spinner id="startTimeSpinner" allowValueWrap="true" maximum="60" minimum="0"
						   stepSize="1"/>
				<s:Label text="开始,每"/>
				<s:TextInput id="cycleTime" maxChars ="50" visible="true" text="{cycleTimeSpinner.value}"/>
				<s:Spinner id="cycleTimeSpinner" allowValueWrap="true" maximum="60" minimum="1"
						   stepSize="1"/>
				<s:Label text="执行一次"/>
				
			</mx:HBox>
			
			<s:TileGroup id="minTimes"  visible="{!mincycle.selected}" creationComplete="initMin()" >
			</s:TileGroup>
			
		</mx:VBox>
		
		<mx:VBox label="小时">
			<mx:HBox>
				<s:RadioButton id="hourcycle" label="每个小时" groupName="hourg" selected="true" />
				<s:RadioButton label="定时" groupName="hourg"  />
			</mx:HBox>
			
			
			<s:TileGroup id="hourTimes"  visible="{!hourcycle.selected}" creationComplete="initHour()" >
			</s:TileGroup>
			
		</mx:VBox>
		
		<mx:VBox label="天">
			<mx:HBox>
				<s:RadioButton id="daycycle" label="每天" groupName="dayg" selected="true" />
				<s:RadioButton label="定时" groupName="dayg"  />
			</mx:HBox>
			
			
			<s:TileGroup id="dayTimes"  visible="{!daycycle.selected}" creationComplete="initDay()" >
			</s:TileGroup>
			
		</mx:VBox>
		
		<mx:VBox label="月">
			<mx:HBox>
				<s:RadioButton id="monthcycle" label="每月" groupName="monthg" selected="true" />
				<s:RadioButton label="定时" groupName="monthg"  />
			</mx:HBox>
			
			<s:TileGroup id="monthTimes"  visible="{!monthcycle.selected}" creationComplete="initMonth()" />
		</mx:VBox>
		
		<mx:VBox label="周">
			<s:CheckBox id="isUseWeek" label="是否使用week" selected="false"/>
			<mx:VBox visible="{isUseWeek.selected}">
			<mx:HBox >
				<s:RadioButton id="weekcycle" label="每周" groupName="weekg" selected="true" />
				<s:RadioButton label="定时" groupName="weekg"  />
			</mx:HBox>
			<s:TileGroup id="weekTimes"  visible="{!weekcycle.selected}" creationComplete="initWeek()" />
			</mx:VBox>
			
		</mx:VBox>
		
	</mx:TabNavigator>
	
	<mx:VBox width="100%" height="50">
		<mx:HBox width="100%" height="100%">
			<s:Label text="CronValue:"/>
			<s:TextInput id="resultStr" width="100%"/>
		</mx:HBox>
		<mx:HBox>
			<s:Button label="Generate" click="getnerateCron(event)"/>
			<s:Button label="保存"/>
		</mx:HBox>
	</mx:VBox>
	
</s:Application>





ExtendsCheckBox.as  :

package com.gzhdi.backup.cron
{
	import spark.components.CheckBox;
	
	public class ExtendsCheckBox extends CheckBox
	{
		private var _value:String;
		
		
		public function ExtendsCheckBox()
		{
			super();
		}

		public function get value():String
		{
			return _value;
		}

		public function set value(value:String):void
		{
			_value = value;
		}

	}
}


  • 1
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

321哈哈哈

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值