【已解决】如何AU3实现日历竖向排班问题
本帖最后由 menfan1 于 2010-12-13 10:05 编辑日历竖向排班如下:
N年N月 | 上班时间一 |上班时间二 |上班时间三 | 上班时间四|
日期星期几 |名一 |名二 |名三 |名四 |
例:
2009年01月| 上班时间一 |上班时间二 |上班时间三 | 上班时间四|
01星期四 |名一 |名二 |名三 |名四 |
02星期五 |名二 |名三 |名四 |名一 |
03星期六 |名三 |名四 |名一 |名二 |
04星期日 |名四 |名一 |名二 |名三 |
。
。
。
。
31星期六 |名三 |名四 |名一 |名二 |
如何AU3实现本年或者本月的日历竖向排班呢(另注:周末和节假日不需要排班)?呵呵 参考一下:
@echo off
color f2
set "xq=日一二三四五六"
for /f "tokens=1-3 delims=-/\:. " %%i in ("%date%") do set /a Y=%%i,M=1%%j%%100,D=1%%k%%100,M1=M
if %M% leq 2 set/a Y-=1,M+=12
set/a n1=(1+2*M+3*(M+1)/5+Y+Y/4-Y/100+Y/400+1)%%4
set/a PN="!(Y%%4) & !(!(Y%%100)) | !(Y%%400)+28",n=0,_a=0+n1,_b=1+n1,_c=2+n1,_d=3+n1
echo %Y%年%M%月 ^|08:30-17:30 ^|08:30-17:30 ^|17:30-21:00 ^| 休息 ^|
for %%i in(名字一 名字二 名字三 名字四 名字一 名字二 名字三)do call set "_%%n%%=%%i"&set/a n+=1
set/a W1=(1+2*M+3*(M+1)/5+Y+Y/4-Y/100+Y/400+1)%%7
for /F "tokens=%M1%" %%i in ("31 %PN% 31 30 31 30 31 31 30 31 30 31") do set/a W=w1+%%i-1
for /l %%j in (0 1 %w%) do (
if %%j geq %W1% (
set/a T=%%j%%7,DD+=1
call set D=0%%DD%%
call call echo %%D:~-2%% 星期%%%%xq:~%%t%%,1%%%% %%%%_%%_a%%%%%% %%%%_%%_b%%%%%% %%%%_%%_c%%%%%% %%%%_%%_d%%%%%%
set/a _a=^(_a+3^)%%4,_b=^(_b+3^)%%4,_c=^(_c+3^)%%4,_d=^(_d+3^)%%4
))
pause 自己顶一下哈。。 本帖最后由 yhxhappy 于 2010-12-11 22:52 编辑
写了一个,水平有限,感觉还不够乱序,就算是抛砖引玉吧#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <Date.au3>
$Form1 = GUICreate("Form1", 700, 603)
GUICtrlCreateLabel("月份:", 24, 24, 40, 17)
$Combo1 = GUICtrlCreateCombo("", 64, 24, 50, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12", "12")
$Button = GUICtrlCreateButton("生成", 150, 22, 100, 27)
$ListView1 = GUICtrlCreateListView("", 24, 56, 660, 534, $LVS_REPORT, $LVS_EX_GRIDLINES)
_GUICtrlListView_AddColumn($ListView1, "日期", 40, 2)
_GUICtrlListView_AddColumn($ListView1, "星期", 50, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间一", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间二", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间三", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间四", 100, 2)
$1 = "星期一"
$2 = "星期二"
$3 = "星期三"
$4 = "星期四"
$5 = "星期五"
$6 = "星期六"
$7 = "星期日"
$8 = "名一"
$9 = "名二"
$10 = "名三"
$11 = "名四"
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
$iMonth = GUICtrlRead($Combo1)
$DayNum = _DateDaysInMonth(@YEAR, $iMonth)
Local $Array[$DayNum+1]
For $i = 1 To $DayNum
$Week = _DateToDayOfWeek(@YEAR, $iMonth, $i)
$Array[$i] = $Week
If $Week <> 6 And $Week <> 7 Then
For $n = 1 To 4
For $Num = 8 To 11
If _ArraySearch($Array, $Num, $i, $i) = -1 And _ArraySearch($Array, $Num, Abs($i-3), $i, "", "", "", $n) = -1 Then
$Array[$i][$n] = $Num
ExitLoop
EndIf
Next
Next
EndIf
Next
_GUICtrlListView_DeleteAllItems($ListView1)
For $i = 1 To $DayNum
GUICtrlCreateListViewItem($i & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]), $ListView1)
Next
EndSwitch
WEnd
又改了改,比以前排列乱多了,代码还是在4楼 刚看到,不错哈,不过能加上排除自定义的日期更好:) 加了排除指定日期#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <Date.au3>
$Form1 = GUICreate("Form1", 700, 603)
GUICtrlCreateLabel("月份:", 24, 27, 40, 17)
$Combo1 = GUICtrlCreateCombo("", 64, 24, 50, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12", "12")
GUICtrlCreateLabel("需排除的日期,英文逗号隔开:", 130, 27, 180, 17)
$Input = GUICtrlCreateInput("", 300, 24, 250, 20)
$Button = GUICtrlCreateButton("生成", 580, 22, 100, 27)
$ListView1 = GUICtrlCreateListView("", 24, 56, 660, 534, $LVS_REPORT, $LVS_EX_GRIDLINES)
_GUICtrlListView_AddColumn($ListView1, "日期", 40, 2)
_GUICtrlListView_AddColumn($ListView1, "星期", 50, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间一", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间二", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间三", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间四", 100, 2)
$1 = "星期一"
$2 = "星期二"
$3 = "星期三"
$4 = "星期四"
$5 = "星期五"
$6 = "星期六"
$7 = "星期日"
$8 = "名一"
$9 = "名二"
$10 = "名三"
$11 = "名四"
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
_GUICtrlListView_DeleteAllItems($ListView1)
$Input_Txt = GUICtrlRead($Input)
If $Input_Txt = "" Then
Local $eee =
Else
Local $eee = StringSplit($Input_Txt, ",")
EndIf
$iMonth = GUICtrlRead($Combo1)
$DayNum = _DateDaysInMonth(@YEAR, $iMonth)
Local $Array[$DayNum+1]
For $i = 1 To $DayNum
$Week = _DateToDayOfWeek(@YEAR, $iMonth, $i)
$Array[$i] = $Week
If $Week <> 6 And $Week <> 7 And _ArraySearch($eee, $i, 1) = -1 Then
For $n = 1 To 4
For $Num = 8 To 11
If _ArraySearch($Array, $Num, $i, $i) = -1 And _ArraySearch($Array, $Num, Abs($i-3), $i, "", "", "", $n) = -1 Then
$Array[$i][$n] = $Num
ExitLoop
EndIf
Next
Next
EndIf
GUICtrlCreateListViewItem($i & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]) & "|" & Eval($Array[$i]), $ListView1)
Next
EndSwitch
WEnd 本帖最后由 menfan1 于 2010-12-13 11:09 编辑
回复 7# yhxhappy
动作好快啊呵呵,如果排班能再加上一点算法更好,比如名一到名四按顺序横向《从左到右》、纵向《从上到下》顺序隔开(不被断开的日期打乱顺序)等等。。 回复 8# menfan1
是这种效果吗?#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <Date.au3>
$Form1 = GUICreate("Form1", 700, 603)
GUICtrlCreateLabel("月份:", 24, 27, 40, 17)
$Combo1 = GUICtrlCreateCombo("", 64, 24, 50, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12", "12")
GUICtrlCreateLabel("需排除的日期,英文逗号隔开:", 130, 27, 180, 17)
$Input = GUICtrlCreateInput("", 300, 24, 250, 20)
$Button = GUICtrlCreateButton("生成", 580, 22, 100, 27)
$ListView1 = GUICtrlCreateListView("", 24, 56, 660, 534, $LVS_REPORT, $LVS_EX_GRIDLINES)
_GUICtrlListView_AddColumn($ListView1, "日期", 40, 2)
_GUICtrlListView_AddColumn($ListView1, "星期", 50, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间一", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间二", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间三", 100, 2)
_GUICtrlListView_AddColumn($ListView1, "上班时间四", 100, 2)
$1 = "星期一"
$2 = "星期二"
$3 = "星期三"
$4 = "星期四"
$5 = "星期五"
$6 = "星期六"
$7 = "星期日"
$32 = "名一"
$33 = "名二"
$34 = "名三"
$35 = "名四"
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
$Input_Txt = GUICtrlRead($Input)
If $Input_Txt = "" Then
Local $eee =
Else
Local $eee = StringSplit($Input_Txt, ",")
EndIf
$iMonth = GUICtrlRead($Combo1)
$DayNum = _DateDaysInMonth(@YEAR, $iMonth)
Local $Array
For $i = 1 To $DayNum
$Week = _DateToDayOfWeek(@YEAR, $iMonth, $i)
_GUICtrlListView_AddItem($ListView1, $i)
_GUICtrlListView_AddSubItem($ListView1, $i-1, Eval($Week), 1)
If $Week <> 6 And $Week <> 7 And _ArraySearch($eee, $i, 1) = -1 Then
ReDim $Array
$var = UBound($Array)-1
For $n = 1 To 4
For $Num = 32 To 35
If _ArraySearch($Array, $Num, $var, $var) = -1 And _ArraySearch($Array, $Num, Abs($var-3), $var, "", "", "", $n) = -1 Then
$Array[$var][$n] = $Num
_GUICtrlListView_AddSubItem($ListView1, $i-1, Eval($Array[$var][$n]), $n+1)
ExitLoop
EndIf
Next
Next
EndIf
Next
EndSwitch
WEnd 回复 9# yhxhappy
不错,速度啊,6个呢?N个人呢?呵呵 回复yhxhappy
不错,速度啊,6个呢?N个人呢?呵呵
menfan1 发表于 2010-12-13 12:28 http://www.autoitx.com/images/common/back.gif
该你自己动手了吧… 回复 11# afan
呵呵,我在扩展。。有人速度比我快哈。。 呵呵,大家都非常的积极 学习一下@!
页:
[1]