quartz 复杂调用窗体(仿SqlServer)
程序员文章站
2022-05-24 19:05:20
...
[align=left][/align]
3Q for hzg
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:ns1="myCom.*" initialize="initTime()" creationComplete="init()" width="696" height="566">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.formatters.DateFormatter;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable]
private var freqStateList:ArrayCollection = new ArrayCollection([
{label:"每天"},
{label:"每周"},
{label:"每月"}
]);
[Bindable]
private var weekIndexList:ArrayCollection = new ArrayCollection([
{label:"第一个"},
{label:"第二个"},
{label:"第三个"},
{label:"第四个"},
{label:"最后一个"}
]);
[Bindable]
private var weekList:ArrayCollection = new ArrayCollection([
{label:"星期日"},
{label:"星期一"},
{label:"星期二"},
{label:"星期三"},
{label:"星期四"},
{label:"星期五"},
{label:"星期六"}
]);
[Bindable]
private var intervalUnit:ArrayCollection = new ArrayCollection([
{label:"小时"},
{label:"分钟"}
]);
private var second:String = "*";
private var minute:String = "*";
private var hour:String = "*";
private var day:String = "*";
private var month:String = "*";
private var week:String = "?";
private var year:String = "*";
private var edited:Boolean = false;
public function set quartzCronExp(value:String):void {
var arr:Array = value.split(" ");
initComponent1(arr[3].toString(), arr[4].toString(), arr[5].toString(), arr[6].toString());
initComponent2(arr[0].toString(), arr[1].toString(), arr[2].toString());
edited = true;
//displayIllustration();
}
/**
* 设置频率区域
* */
private function initComponent1(day:String, month:String, week:String, year:String):void {
this.day = day;
this.month = month;
this.week = week;
this.year = year;
// 每天
if(day == "*"){
cmb.selectedIndex = 0;
return;
}
// 每周
if(day == "?" && week.indexOf("#") == -1 && week.indexOf("L") == -1){
cmb.selectedIndex = 1;
if(week == "*"){
return;
}
weekBox.addEventListener(FlexEvent.CREATION_COMPLETE, function():void {
var arr:Array = week.split(",");
var cbWeekList:ArrayCollection = new ArrayCollection([
cbWeek1, cbWeek2, cbWeek3, cbWeek4, cbWeek5, cbWeek6, cbWeek7
]);
for each(var str:String in arr){
(cbWeekList.getItemAt(Number(str) - 1) as CheckBox).selected = true;
}
});
return;
}
// 每月 - 第
if(day != "*" && day != "?"){
cmb.selectedIndex = 2;
monthBox.addEventListener(FlexEvent.CREATION_COMPLETE, function():void {
rb1.selected = true;
rb2.selected = false;
nsDay1.value = Number(day);
});
return;
}
// 每月 - 在
cmb.selectedIndex = 2;
monthBox.addEventListener(FlexEvent.CREATION_COMPLETE, function():void {
rb1.selected = false;
rb2.selected = true;
if(week.indexOf("L") != -1){
cboWeekIndex.selectedIndex = 4;
cboWeek.selectedIndex = Number(week.substring(0, week.length - 1)) - 1;
}else{
cboWeekIndex.selectedIndex = Number(week.split("#")[1]) - 1;
cboWeek.selectedIndex = Number(week.split("#")[0]) - 1;
}
});
}
/**
* 设置每天频率区域
* */
private function initComponent2(second:String, minute:String, hour:String):void {
this.second = second;
this.minute = minute;
this.hour = hour;
// 每天频率 - 间隔(时)
if(hour.indexOf("/") != -1){
rb3.selected = false;
rb4.selected = true;
cbInterval.selectedIndex = 0;
nbInterval.maximum = 24;
nbInterval.value = Number(hour.split("/")[1]);
return;
}
// 每天频率 - 间隔(分钟)
if(minute.indexOf("/") != -1){
rb3.selected = false;
rb4.selected = true;
cbInterval.selectedIndex = 1;
nbInterval.maximum = 60;
nbInterval.value = Number(minute.split("/")[1]);
return;
}
// 每天频率 - 一次
rb3.selected = true;
rb4.selected = false;
nsHour.value = Number(hour);
nsMinute.value = Number(minute);
nsSecond.value = Number(second);
}
public function set startDateAndTime(value:String):void {
if(value && value.length>0)
{
var arr:Array = value.split(" ");
startDate.text = arr[0].toString();
startTime.times = arr[1].toString();
//displayIllustration();
}
}
public function set endDateAndTime(value:String):void {
if(value == null || value.length == 0){
rb6.selected = true;
return;
}
var arr:Array = value.split(" ");
endDate.text = arr[0].toString();
endTime.times = arr[1].toString();
//displayIllustration();
}
public function get quartzCronExp():String{
return second + " " + minute + " " + hour + " " + day + " " + month + " " + week + " " + year;
}
public function get startDateAndTime():String {
return startDate.text + " " + startTime.time;
}
public function get endDateAndTime():String {
return rb5.selected ? endDate.text + " " + endTime.time : null;
}
private function initTime():void {
var dateFormatter:DateFormatter = new DateFormatter();
dateFormatter.formatString = "HH:NN:SS";
startTime.times = dateFormatter.format(new Date());
endTime.times = dateFormatter.format(new Date());
}
private function init():void {
if(!edited){
setValue1();
setValue5();
}
displayIllustration();
}
/**
* 显示说明信息
* */
private function displayIllustration():void {
var arr:Array = quartzCronExp.split(" ");
var str1:String = createStr1(arr[3].toString(), arr[4].toString(), arr[5].toString(), arr[6].toString());
var str2:String = createStr2(arr[0].toString(), arr[1].toString(), arr[2].toString());
var str3:String = createStr3();
illustration.text = str1 + " " + str2 + "\n" + str3;
}
/**
* 创建频率区域的显示字符串
* */
private function createStr1(day:String, month:String, week:String, year:String):String {
// 每天
if(day == "*"){
return "每天";
}
// 每周
if(day == "?" && week.indexOf("#") == -1 && week.indexOf("L") == -1){
if(week == "*"){
return "每周";
}
var cbWeekList:ArrayCollection = new ArrayCollection([
cbWeek1, cbWeek2, cbWeek3, cbWeek4, cbWeek5, cbWeek6, cbWeek7
]);
var s:String = "每周 ";
for each(var cb:CheckBox in cbWeekList){
if(cb.selected){
s += cb.label + ","
}
}
s = s.substring(0, s.length - 1);
return s;
}
// 每月 - 第
if(day != "*" && day != "?"){
return "每月 " + "第 " + nsDay1.value + " 天";
}
// 每月 - 在
return "在每月的 " + cboWeekIndex.text + " " + cboWeek.text;
}
/**
* 创建每天频率区域的显示字符串
* */
private function createStr2(second:String, minute:String, hour:String):String {
// 每天频率 - 间隔(时)
if(hour.indexOf("/") != -1){
return "每 " + nbInterval.value + " 小时执行一次。"
}
// 每天频率 - 间隔(分钟)
if(minute.indexOf("/") != -1){
return "每 " + nbInterval.value + " 分钟执行一次。"
}
// 每天频率 - 一次
return "的 " + ((nsHour.value.toString().length == 1) ? ("0" + nsHour.value) : nsHour.value)
+ ":" + ((nsMinute.value.toString().length == 1) ? ("0" + nsMinute.value) : nsMinute.value)
+ ":" + ((nsSecond.value.toString().length == 1) ? ("0" + nsSecond.value) : nsSecond.value) + " 执行。"
}
/**
* 创建开始和结束日期的显示字符串
* */
private function createStr3():String {
if(rb5.selected){
return "任务从 " + startDateAndTime + " 开始,到 " + endDateAndTime + " 结束。";
}
return "任务从 " + startDateAndTime + " 开始。";
}
/**
* 设置每天
* */
private function setValue1():void {
day = "*";
month = "*";
week = "?";
year = "*";
displayIllustration();
}
/**
* 设置每周
* */
private function setValue2():void {
day = "?";
month = "*";
week = "";
var cbWeekList:ArrayCollection = new ArrayCollection([
cbWeek1, cbWeek2, cbWeek3, cbWeek4, cbWeek5, cbWeek6, cbWeek7
]);
for(var i:Number = 0; i < cbWeekList.length; i++) {
if(CheckBox(cbWeekList.getItemAt(i)).selected){
week += (i + 1) + ",";
}
}
if(week.charAt(week.length - 1) == ","){
week = week.substr(0, week.length - 1);
}
week = week == "" ? "*" : week;
year = "*";
displayIllustration();
}
/**
* 设置每月 - 第
* */
private function setValue3():void {
day = nsDay1.value.toString();
month = "*";
week = "?";
year = "*";
displayIllustration();
}
/**
* 设置每月 - 在
* */
private function setValue4():void {
day = "?";
month = "*";
week = (cboWeek.selectedIndex + 1).toString();
if(cboWeekIndex.selectedIndex != 4){
week += "#" + (cboWeekIndex.selectedIndex + 1);
}else{
week += "L";
}
year = "*";
displayIllustration();
}
/**
* 设置每天频率 - 一次
* */
private function setValue5():void {
second = nsSecond.value.toString();
minute = nsMinute.value.toString();
hour = nsHour.value.toString();
displayIllustration();
}
/**
* 设置每天频率 - 间隔(时)
* */
private function setValue6():void {
second = "0";
minute = "0";
hour = nbInterval.value > 24 ? "0/24" : "0/" + nbInterval.value.toString();
displayIllustration();
}
/**
* 设置每天频率 - 间隔(分)
* */
private function setValue7():void {
second = "0";
minute = "0/" + nbInterval.value.toString();
hour = "*";
displayIllustration();
}
private function cbIntervalChangeHandler(event:Event):void {
nbInterval.maximum = cbInterval.selectedIndex == 0 ? 24 : 60;
if(cbInterval.selectedIndex == 0){
setValue6();
}else{
setValue7();
}
}
private function cmbChangeHandler(event:Event):void {
switch (cmb.selectedIndex){
case 0:
setValue1();
break;
case 1:
setValue2();
break;
case 2:
if(rb1.selected){
setValue3();
}else{
setValue4();
}
break;
default:
break;
}
}
private function close():void {
PopUpManager.removePopUp(this);
}
private function ok():void {
var closeevent:WindowCloseEvent = new WindowCloseEvent(WindowCloseEvent.WINDOW_CLOSE);
closeevent.IsConfirm = true;
closeevent.ReturnValue = {quartzCronExp:quartzCronExp, startDateAndTime:startDateAndTime, endDateAndTime:endDateAndTime};
dispatchEvent(closeevent);
close();
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:Panel layout="vertical" title="频率" width="100%" verticalGap="0">
<mx:HBox width="100%" horizontalAlign="left" verticalAlign="middle" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2">
<mx:Label text="执行:"/>
<mx:Spacer width="100"/>
<mx:ComboBox id="cmb" dataProvider="{freqStateList}" labelField="label" editable="false" width="150" change="cmbChangeHandler(event)"/>
</mx:HBox>
<mx:ViewStack id="viewstack1" width="100%" selectedIndex="{cmb.selectedIndex}" resizeToContent="true">
<mx:Canvas label="每天" width="100%" height="100%">
</mx:Canvas>
<mx:Canvas id="weekBox" label="每周" width="100%" height="100%">
<mx:HBox width="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
<mx:VBox width="100%" verticalGap="0">
<mx:Grid width="100%" verticalGap="0">
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek2" click="setValue2()" label="星期一"/>
</mx:HBox>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek4" click="setValue2()" label="星期三"/>
</mx:HBox>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek6" click="setValue2()" label="星期五"/>
</mx:HBox>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek7" click="setValue2()" label="星期六"/>
</mx:HBox>
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek3" click="setValue2()" label="星期二"/>
</mx:HBox>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek5" click="setValue2()" label="星期四"/>
</mx:HBox>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:HBox width="100%">
<mx:CheckBox id="cbWeek1" click="setValue2()" label="星期日"/>
</mx:HBox>
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:VBox>
</mx:HBox>
</mx:Canvas>
<mx:Canvas id="monthBox" label="每月" width="100%" height="100%">
<mx:VBox width="100%" height="100%" verticalGap="0">
<mx:RadioButtonGroup id="radioButtonGroup1"/>
<mx:HBox width="100%" verticalAlign="middle" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2">
<mx:RadioButton id="rb1" label="第" groupName="radioButtonGroup1" selected="true" click="setValue3()"/>
<mx:Spacer width="100" height="0"/>
<mx:NumericStepper id="nsDay1" maximum="31" minimum="1" enabled="{rb1.selected}" change="setValue3()"/>
<mx:Label text="天"/>
</mx:HBox>
<mx:HBox width="100%" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2" verticalAlign="middle">
<mx:RadioButton id="rb2" label="在" groupName="radioButtonGroup1" click="setValue4()"/>
<mx:Spacer width="100" height="0"/>
<mx:ComboBox id="cboWeekIndex" width="100" dataProvider="{weekIndexList}" labelField="label" editable="false" enabled="{rb2.selected}" change="setValue4()"/>
<mx:ComboBox id="cboWeek" width="100" dataProvider="{weekList}" labelField="label" editable="false" enabled="{rb2.selected}" change="setValue4()"/>
</mx:HBox>
</mx:VBox>
</mx:Canvas>
</mx:ViewStack>
</mx:Panel>
<mx:Panel width="100%" height="115" layout="vertical" title="每天频率" verticalAlign="middle" verticalGap="0">
<mx:RadioButtonGroup id="radioButtonGroup2"/>
<mx:HBox width="100%" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2" verticalAlign="middle" horizontalGap="0">
<mx:RadioButton id="rb3" groupName="radioButtonGroup2" label="执行一次,时间为:" selected="true" click="setValue5()"/>
<mx:Spacer width="36"/>
<mx:NumericStepper id="nsHour" minimum="0" maximum="23" width="50" enabled="{rb3.selected}" change="setValue5()"/>
<mx:Label text="时"/>
<mx:NumericStepper id="nsMinute" width="50" minimum="0" maximum="59" enabled="{rb3.selected}" change="setValue5()"/>
<mx:Label text="分"/>
<mx:NumericStepper id="nsSecond" width="50" minimum="0" maximum="59" enabled="{rb3.selected}" change="setValue5()"/>
<mx:Label text="秒"/>
</mx:HBox>
<mx:HBox width="100%" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2" verticalAlign="middle">
<mx:RadioButton id="rb4" groupName="radioButtonGroup2" label="执行间隔:" click="cbInterval.selectedIndex == 0 ? setValue6() : setValue7()"/>
<mx:Spacer width="64"/>
<mx:NumericStepper id="nbInterval" minimum="1" maximum="24" enabled="{rb4.selected}" change="cbInterval.selectedIndex == 0 ? setValue6() : setValue7()"/>
<mx:ComboBox id="cbInterval" width="100" dataProvider="{intervalUnit}"
labelField="label" enabled="{rb4.selected}"
change="cbIntervalChangeHandler(event)"/>
</mx:HBox>
</mx:Panel>
<mx:Panel width="100%" height="115" layout="vertical" title="持续时间" verticalAlign="middle" verticalGap="0">
<mx:RadioButtonGroup id="radioButtonGroup3"/>
<mx:HBox width="100%" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2" verticalAlign="middle">
<mx:Spacer width="12"/>
<mx:Label text="开始时间:"/>
<mx:Spacer width="10"/>
<mx:DateField id="startDate" formatString="YYYY-MM-DD" selectedDate="{new Date()}" yearNavigationEnabled="true"/>
<ns1:TimeInput id="startTime" width="220" change="displayIllustration()"/>
</mx:HBox>
<mx:HBox width="100%" verticalAlign="middle" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2">
<mx:RadioButton id="rb5" label="结束日期:" groupName="radioButtonGroup3" selected="true" click="displayIllustration()"/>
<mx:Spacer width="10"/>
<mx:DateField id="endDate" enabled="{!rb6.selected}" formatString="YYYY-MM-DD" selectedDate="{new Date()}" yearNavigationEnabled="true"/>
<ns1:TimeInput id="endTime" enabled="{!rb6.selected}" width="220" change="displayIllustration()"/>
<mx:RadioButton id="rb6" label="无结束日期" groupName="radioButtonGroup3" click="displayIllustration()"/>
</mx:HBox>
</mx:Panel>
<mx:Panel width="100%" height="100%" layout="absolute" title="摘要">
<mx:VBox width="100%" height="100%" verticalGap="0">
<mx:HBox width="100%" height="100%" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2">
<mx:Label text="说明:"/>
<mx:Spacer width="100"/>
<mx:TextArea id="illustration" verticalScrollPolicy="on" horizontalScrollPolicy="off" width="100%" height="100%" editable="false"/>
</mx:HBox>
<mx:HBox width="100%" horizontalAlign="right" verticalAlign="middle" paddingBottom="2" paddingLeft="5" paddingRight="5" paddingTop="2">
<mx:Button label="确定" width="75" click="ok();"/>
<mx:Button label="关闭" width="75" click="close();"/>
</mx:HBox>
</mx:VBox>
</mx:Panel>
</mx:VBox>
</mx:TitleWindow>
3Q for hzg