home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Demo / conceptdraw / data1.cab / Libraries__Project_Management / Project_Management / Calendar.cdb next >
Text File  |  2004-02-13  |  8KB  |  272 lines

  1. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  2. ' ╨╜╨╕ ╨▓ ╨║╨╛╨╡╨╝ ╤Ç╨░╨╖╨╡ ╨╜╨╡ ╨┐╤Ç╨░╨▓╨╕╤é╤î ╤ì╤é╨╛╤é ╤ä╨░╨╣╨╗, ╤é.╨║. ╨┐╨╡╤Ç╨╡╤ü╤é╨░╨╜╨╡╤é ╤Ç╨░╨▒╨╛╤é╨░╤é╤î Wizard! '
  3. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4.  
  5. Dim dateCalEnd        As Date
  6. Dim dateCalStart    As Date
  7. Dim dblDayWidth        As Double
  8. Dim intTimeScale    As Integer
  9. Dim dblCalendarLeft As Double
  10.  
  11. Dim dblCurDayTop    As Date
  12. Dim dblCurDayBot    As Date
  13.  
  14. Dim shapeCalendar    As Shape
  15. Dim shapeBackground    As Shape
  16.  
  17. Const    dblOneCellWidth    As Double = 50
  18. Dim        dblTSCells(5)    As Double
  19. Dim        dblTSDays(5)    As Double
  20.  
  21. Dim arrayWeekSymb(7)    As String
  22. Dim arrayMonthDays(12)    As Integer
  23. Dim arrayQuartalDays(4)    As Integer
  24.  
  25. Function CalcTimeScale() As Integer
  26.     dblTSCells(1) = 1
  27.     dblTSCells(2) = 3
  28.     dblTSCells(3) = 3
  29.     dblTSCells(4) = 4
  30.     dblTSCells(5) = 4
  31.  
  32.     dblTSDays(1)  = 1
  33.     dblTSDays(2)  = 7
  34.     dblTSDays(3)  = 30
  35.     dblTSDays(4)  = 91
  36.     dblTSDays(5)  = 365
  37.  
  38.     CalcTimeScale = 5
  39.     For I=1 To 5
  40.         If dblDayWidth > dblTSCells(I)*dblOneCellWidth/dblTSDays(I) Then
  41.             CalcTimeScale = I
  42.             Exit For
  43.         End If
  44.     Next
  45.     dblDayWidth = Round(dblDayWidth * dblTSDays(CalcTimeScale) / dblOneCellWidth) * dblOneCellWidth / dblTSDays(CalcTimeScale)
  46. End Function
  47.  
  48. Function GetMinWidth(inKind As Integer) As Double
  49.     GetMinWidth = 0
  50.     Select Case inKind
  51.         Case 1
  52.             GetMinWidth = 45
  53.         Case 2
  54.             GetMinWidth = 100
  55.         Case 3
  56.             GetMinWidth = 100
  57.         Case 4
  58.             GetMinWidth = 45
  59.         Case 5
  60.             GetMinWidth = 100
  61.         Case 6
  62.             GetMinWidth = 190
  63.     End Select
  64. End Function
  65.  
  66. Function GetDateDay(inDate As Date) As Integer
  67.     GetDateDay = Format(inDate, "d")
  68. End Function
  69.  
  70. Function GetDateMonth(inDate As Date) As Integer
  71.     GetDateMonth = Format(inDate, "m")
  72. End Function
  73.  
  74. Function GetDateYear(inDate As Date) As Integer
  75.     GetDateYear = Format(inDate, "yyyy")
  76. End Function
  77.  
  78. Function GetDateWeekDay(inDate As Date) As Integer    '1-7 (╨┐╨╜. - ╨▓╤ü.)
  79.     GetDateWeekDay = Format(inDate, "w")
  80.     If GetDateWeekDay = 7 Then
  81.         GetDateWeekDay = 0
  82.     End If
  83.     GetDateWeekDay = GetDateWeekDay + 1
  84. End Function
  85.  
  86. Function GetDateYearDay(inDate As Date) As Integer
  87.     GetDateYearDay = Format(inDate, "y")
  88. End Function
  89.  
  90. Function IsLongYear(inDate As Date) As Boolean
  91.     Dim intYear As Integer
  92.     intYear = GetDateYear(inDate)
  93.     IsLongYear = ((intYear MOD 4) = 0) AND (((intYear MOD 100) > 0) OR ((intYear MOD 400) = 0))
  94. End Function
  95.  
  96. Function ChackEndDate(inDate As Date) As Date
  97.     ChackEndDate = inDate
  98.     If ChackEndDate > dateCalEnd+1 Then
  99.         ChackEndDate = dateCalEnd+1
  100.     End If
  101. End Function
  102.  
  103. Function GetNextCellDate(inKind As Integer, inCurDate As Date, ByRef outText As String) As Date
  104.     Dim val        As Integer
  105.     Dim val_d    As Double
  106.     Select Case inKind
  107.         Case 1    ' day
  108.             GetNextCellDate = ChackEndDate(inCurDate + 1)
  109.             outText = arrayWeekSymb(GetDateWeekDay(inCurDate))
  110.         Case 2    ' week
  111.             GetNextCellDate = ChackEndDate(inCurDate + 8 - GetDateWeekDay(inCurDate))
  112.             outText = Format(inCurDate, "dd.mm")
  113.         Case 3    ' month
  114.             val = GetDateMonth(inCurDate)
  115.             GetNextCellDate = ChackEndDate(inCurDate + arrayMonthDays(val) - GetDateDay(inCurDate) + 1)
  116.             If val = 2 AND IsLongYear(inCurDate) Then
  117.                 GetNextCellDate = GetNextCellDate + 1
  118.             End If
  119.             outText = Format(inCurDate, "mmm yyyy")
  120.         Case 4    ' quartal
  121.             val = GetDateMonth(inCurDate) - 1
  122.             val = val - (Int(val / 3) * 3) + 1
  123.             val_d = GetDateYearDay(inCurDate)
  124.             For I = 1 To val-1
  125.                 val_d = val_d - arrayQuartalDays(I)
  126.             Next
  127.             GetNextCellDate = ChackEndDate(inCurDate + arrayQuartalDays(val) - val_d)
  128.             If val < 4 Then
  129.                 outText = String("I", val)
  130.             Else
  131.                 outText = "IV"
  132.             End If
  133.         Case 5    ' year
  134.             If IsLongYear(inCurDate) Then
  135.                 GetNextCellDate = ChackEndDate(inCurDate + 366 - GetDateYearDay(inCurDate)+1)
  136.             Else
  137.                 GetNextCellDate = ChackEndDate(inCurDate + 365 - GetDateYearDay(inCurDate)+1)
  138.             End If
  139.             outText = Format(inCurDate, "yyyy")
  140.         Case 6    ' year5
  141.             val = GetDateYear(inCurDate)
  142.             val_d = CDate("01.01." & ((Int(val / 5) + 1) * 5))
  143.             GetNextCellDate = ChackEndDate(val_d)
  144.             outText = Format(inCurDate, "yyyy - ") & (((Int(val/5)+1)*5)-1)
  145.     End Select
  146. End Function
  147.  
  148. Sub BuildOneLineInCalendar(inKind As Integer, inTop As Double)
  149.     Dim dateCurDate        As Date
  150.     Dim dateNextDate    As Date
  151.     Dim X1                As Double
  152.     Dim X2                As Double
  153.     Dim shapeText        As String
  154.     Dim shapeCell        As Shape
  155.  
  156.     dateCurDate = dateCalStart
  157.     Do While dateCurDate < dateCalEnd+1
  158.         dateNextDate = GetNextCellDate(inKind, dateCurDate, shapeText)
  159.         X1 = (dateCurDate - dateCalStart) * dblDayWidth
  160.         X2 = (dateNextDate - dateCalStart) * dblDayWidth
  161.         Set shapeCell = shapeCalendar.DrawRect(X1, inTop, X2, inTop+50)
  162.         shapeCell.Text = shapeText
  163.         If shapeCell.Width < GetMinWidth(inKind) Then
  164.             shapeCell.Text = ""
  165.         End If
  166.         If inKind = 1 AND shapeText = "S" Then
  167.             shapeCell.ColorProperty(CDPT_FILLCOLOR).SetRGB(200, 200, 200)
  168.         End If
  169.         shapeCell.SetCharStyle(1, -1, 0)
  170.         shapeCell.SetParaHAlign(1, -1, 1)
  171.         dateCurDate = dateNextDate
  172.     Loop
  173. End Sub
  174.  
  175. Sub BuildBackground(inKind As Integer)
  176.     Dim dateCurDate        As Date
  177.     Dim dateNextDate    As Date
  178.     Dim X1                As Double
  179.     Dim X2                As Double
  180.     Dim shapeCell        As Shape
  181.     Dim shapeText        As String
  182.     Dim dblTop            As Double
  183.  
  184.     dblTop = shapeCalendar.GPinY + shapeCalendar.Height
  185.     Set shapeBackground = thisDoc.ActivePage.DrawGroup(dblCalendarLeft, dblTop, shapeCalendar.GPinX + shapeCalendar.Width, dblTop+50)
  186.     dateCurDate = dateCalStart
  187.     Do While dateCurDate < dateCalEnd+1
  188.         dateNextDate = GetNextCellDate(inKind, dateCurDate, shapeText)
  189.         X1 = (dateCurDate - dateCalStart) * dblDayWidth
  190.         X2 = (dateNextDate - dateCalStart) * dblDayWidth
  191.         Set shapeCell = shapeBackground.DrawRect(X1, 0, X2, 50)
  192.         If inKind = 1 AND GetDateWeekDay(dateCurDate) >= 6 Then
  193.             shapeCell.ColorProperty(CDPT_FILLCOLOR).SetRGB(200, 200, 200)
  194.         End If
  195.         shapeCell.RecalcProperty(CDPT_GPINY)
  196.         dateCurDate = dateNextDate
  197.     Loop
  198.     shapeBackground.LPinX = 0
  199.     shapeBackground.LPinY = 0
  200.     shapeBackground.SetPropertyFormula("=ObjID" & shapeCalendar.ID & ".GPinX", CDPT_GPINX)
  201.     shapeBackground.SetPropertyFormula("=ObjID" & shapeCalendar.ID & ".GPinY + ObjID" & shapeCalendar.ID & ".Height", CDPT_GPINY)
  202.     shapeBackground.SetPropertyFormula("=ObjID" & shapeCalendar.ID & ".Width", CDPT_WIDTH)
  203.  
  204.     shapeBackground.RecalcProperty(CDPT_GPINX)
  205.     shapeBackground.RecalcProperty(CDPT_GPINY)
  206.     shapeBackground.RecalcProperty(CDPT_WIDTH)
  207. End Sub
  208.  
  209. Sub AdjustCalendar()
  210.     Dim val As Integer
  211.     Select Case intTimeScale
  212.         Case 2
  213.             val = GetDateWeekDay(dateCalStart)
  214.             dateCalStart = dateCalStart - val + 1
  215.         Case 3
  216.             val = GetDateDay(dateCalStart)
  217.             dateCalStart = dateCalStart - val + 1
  218.         Case 4
  219.             val = Int((GetDateMonth(dateCalStart)-1) / 3) * 3 + 1
  220.             dateCalStart = CDate("01." & val & "." & GetDateYear(dateCalStart))
  221.         Case 5
  222.             dateCalStart = CDate("01.01." & GetDateYear(dateCalStart))
  223.     End Select
  224. End Sub
  225.  
  226. Sub BuildCalendar()
  227.     dblDayWidth = (thisDoc.PageSizeX - dblCalendarLeft) / (dateCalEnd - dateCalStart + 1)
  228.     
  229.     intTimeScale = CalcTimeScale()
  230.     AdjustCalendar()
  231.  
  232.     thisDoc.PageSizeY = (dateCalEnd - dateCalStart + 1) * dblDayWidth + dblCalendarLeft + 100
  233.  
  234.     arrayWeekSymb(1) = "M"
  235.     arrayWeekSymb(2) = "T"
  236.     arrayWeekSymb(3) = "W"
  237.     arrayWeekSymb(4) = "T"
  238.     arrayWeekSymb(5) = "F"
  239.     arrayWeekSymb(6) = "S"
  240.     arrayWeekSymb(7) = "S"
  241.  
  242.     arrayMonthDays(01) = 31
  243.     arrayMonthDays(02) = 28
  244.     arrayMonthDays(03) = 31
  245.     arrayMonthDays(04) = 30
  246.     arrayMonthDays(05) = 31
  247.     arrayMonthDays(06) = 30
  248.     arrayMonthDays(07) = 31
  249.     arrayMonthDays(08) = 31
  250.     arrayMonthDays(09) = 30
  251.     arrayMonthDays(10) = 31
  252.     arrayMonthDays(11) = 30
  253.     arrayMonthDays(12) = 31
  254.  
  255.     arrayQuartalDays(1) = 31 + 28 + 31
  256.     arrayQuartalDays(2) = 30 + 31 + 30
  257.     arrayQuartalDays(3) = 31 + 31 + 30
  258.     arrayQuartalDays(4) = 31 + 30 + 31
  259.  
  260.     Set shapeCalendar = thisDoc.ActivePage.DrawGroup(dblCalendarLeft, 0, (dateCalEnd-dateCalStart+1)*dblDayWidth + dblCalendarLeft, 100)
  261.     shapeCalendar.LPinX = 0
  262.     shapeCalendar.LPinY = 0
  263.  
  264.     BuildOneLineInCalendar(intTimeScale+1, 0)
  265.     BuildOneLineInCalendar(intTimeScale, 50)
  266.     If intTimeScale = 1 Then
  267.         BuildBackground(intTimeScale)
  268.     Else
  269.         BuildBackground(intTimeScale+1)
  270.     End If
  271. End Sub
  272.