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

  1. Declare Function PPCalendarPropDlg Lib "CDWizards" (ByRef str As String) As Long
  2.  
  3. Dim arrayWeekSymb(7)    As String
  4. Dim arrayMonthDays(12)    As Integer
  5. Dim arrayQuartalDays(4)    As Integer
  6. Dim shapeCalendar        As Shape
  7.  
  8. Function GetCalStart() As Double
  9.     GetCalStart = TasksTitle.CustomProp(2).Value
  10. End Function
  11.  
  12. Sub SetCalStart(inDate As Double)
  13.     TasksTitle.CustomProp(2).Value = inDate
  14. End Sub
  15.  
  16. Function GetCalEnd() As Double
  17.     GetCalEnd = TasksTitle.CustomProp(3).Value
  18. End Function
  19.  
  20. Sub SetCalEnd(inDate As Double)
  21.     TasksTitle.CustomProp(3).Value = inDate
  22. End Sub
  23.  
  24. Function GetDayWidth() As Double
  25.     GetDayWidth = TasksTitle.CustomProp(1).Value
  26. End Function
  27.  
  28. Sub SetDayWidth(inWidth As Double)
  29.     TasksTitle.CustomProp(1).Value = inWidth
  30. End Sub
  31.  
  32. Function GetTimeScale() As Integer
  33.     GetTimeScale = TasksTitle.CustomProp(4).Value
  34. End Function
  35.  
  36. Sub SetTimeScale(inTimeScale As Integer)
  37.     TasksTitle.CustomProp(4).Value = inTimeScale
  38. End Sub
  39.  
  40. Function GetDateDay(inDate As Date) As Integer
  41.     GetDateDay = Format(inDate, "d")
  42. End Function
  43.  
  44. Function GetDateMonth(inDate As Date) As Integer
  45.     GetDateMonth = Format(inDate, "m")
  46. End Function
  47.  
  48. Function GetDateYear(inDate As Date) As Integer
  49.     GetDateYear = Format(inDate, "yyyy")
  50. End Function
  51.  
  52. Function GetDateWeekDay(inDate As Date) As Integer
  53.     GetDateWeekDay = Format(inDate, "w")
  54.     If GetDateWeekDay = 1 Then
  55.         GetDateWeekDay = 8
  56.     End If
  57.     GetDateWeekDay = GetDateWeekDay - 1
  58. End Function
  59.  
  60. Function GetDateYearDay(inDate As Date) As Integer
  61.     GetDateYearDay = Format(inDate, "y")
  62. End Function
  63.  
  64. Function IsLongYear(inDate As Date) As Boolean
  65.     Dim intYear As Integer
  66.     intYear = GetDateYear(inDate)
  67.     IsLongYear = ((intYear MOD 4) = 0) AND (((intYear MOD 100) > 0) OR ((intYear MOD 400) = 0))
  68. End Function
  69.  
  70. Function ChackEndDate(inDate As Date) As Date
  71.     ChackEndDate = inDate
  72.     If ChackEndDate > GetCalEnd() + 1 Then
  73.         ChackEndDate = GetCalEnd() + 1
  74.     End If
  75. End Function
  76.  
  77. Function GetNextCellDate(inKind As Integer, inCurDate As Date, ByRef outText As String, IsTop As Integer) As Date
  78.     Dim val        As Integer
  79.     Dim val_d    As Double
  80.     Select Case inKind
  81.         Case 1    ' day
  82.             GetNextCellDate = inCurDate + 1
  83.             outText = arrayWeekSymb(GetDateWeekDay(inCurDate))
  84.         Case 2    ' week
  85.             GetNextCellDate = inCurDate + 8 - GetDateWeekDay(inCurDate)
  86.             If IsTop = 1 Then
  87.                 outText = Format(inCurDate, "dd mmm yyyy")
  88.             Else
  89.                 outText = Format(inCurDate, "dd.mm")
  90.             End If
  91.         Case 3    ' month
  92.             val = GetDateMonth(inCurDate)
  93.             GetNextCellDate = inCurDate + arrayMonthDays(val) - GetDateDay(inCurDate) + 1
  94.             If val = 2 AND IsLongYear(inCurDate) Then
  95.                 GetNextCellDate = GetNextCellDate + 1
  96.             End If
  97.             If IsTop = 1 Then
  98.                 outText = Format(inCurDate, "mmm yyyy")
  99.             Else
  100.                 outText = Format(inCurDate, "mmm")
  101.             End If
  102.         Case 4    ' quartal
  103.             val = Int((GetDateMonth(inCurDate) - 1) / 3) + 1
  104.             val_d = GetDateYearDay(inCurDate)
  105.             For I = 1 To val-1
  106.                 val_d = val_d - arrayQuartalDays(I)
  107.             Next
  108.             GetNextCellDate = inCurDate + arrayQuartalDays(val) - val_d + 1
  109.             If IsLongYear(inCurDate) Then
  110.                 GetNextCellDate = GetNextCellDate + 1
  111.             End If
  112.             If val < 4 Then
  113.                 outText = String(val, "I")
  114.             Else
  115.                 outText = "IV"
  116.             End If
  117.         Case 5    ' year
  118.             If IsLongYear(inCurDate) Then
  119.                 GetNextCellDate = inCurDate + 366 - GetDateYearDay(inCurDate)+1
  120.             Else
  121.                 GetNextCellDate = inCurDate + 365 - GetDateYearDay(inCurDate)+1
  122.             End If
  123.             outText = Format(inCurDate, "yyyy")
  124.         Case 6    ' year5
  125.             val = GetDateYear(inCurDate)
  126.             GetNextCellDate = CDate("01.01." & ((Int(val / 5) + 1) * 5))
  127.             outText = Format(inCurDate, "yyyy - ") & (((Int(val/5)+1)*5)-1)
  128.     End Select
  129.     GetNextCellDate = ChackEndDate(GetNextCellDate)
  130. End Function
  131.  
  132. Sub BuildOneLineInCalendar(inKind As Integer, inTop As Double, isLineNum As Integer)
  133. On Error Goto ErrorHandle
  134.     Dim dateCurDate        As Date
  135.     Dim dateNextDate    As Date
  136.     Dim X1                As Double
  137.     Dim X2                As Double
  138.     Dim shapeText        As String
  139.     Dim shapeCell        As Shape
  140.     Dim varVariable        As Variable
  141.  
  142.     dateCurDate = GetCalStart()
  143.     Do While dateCurDate < GetCalEnd() + 1
  144.         dateNextDate = GetNextCellDate(inKind, dateCurDate, shapeText, (isLineNum=0))
  145.         X1 = (dateCurDate - GetCalStart()) * GetDayWidth()
  146.         X2 = (dateNextDate - GetCalStart()) * GetDayWidth()
  147.         Set shapeCell = shapeCalendar.DrawRect(X1, inTop, X2, inTop+50)
  148.  
  149.         
  150.         shapeCell.Text = shapeText
  151.         shapeCell.SetPropertyFormula("_AND(_TEXTWIDTH(TheText)<Width;_TEXTHEIGHT(TheText;Width)<Height)", CDPT_SHOWTEXT)
  152.         shapeCell.RecalcProperty(CDPT_SHOWTEXT)
  153.         If inKind = 1 AND shapeText = "S" Then
  154.             shapeCell.FillColor.SetRGB(200, 200, 200)
  155.         Else
  156.             shapeCell.FillColor.SetRGB(255, 255, 255)
  157.         End If
  158.         shapeCell.PenPattern = 1
  159.         shapeCell.SetCharStyle(1, -1, 0)
  160.         shapeCell.SetParaHAlign(1, -1, 1)
  161.         shapeCell.FillPattern = 1
  162.         shapeCell.FillPatColor.SetRGB(255, 255, 255)
  163.         dateCurDate = dateNextDate
  164.     Loop
  165. ErrorHandle:
  166. End Sub
  167.  
  168. Sub BuildBackground(inKind As Integer, inCalWidth As Double)
  169. On Error Goto ErrorHandle
  170.     Dim shapeBackground    As Shape
  171.     Dim shapeCell        As Shape
  172.     Dim dateCurDate        As Date
  173.     Dim dateNextDate    As Date
  174.     Dim X1                As Double
  175.     Dim X2                As Double
  176.     Dim shapeText        As String
  177.     Dim dblTop            As Double
  178.  
  179.     Set shapeBackground = TasksTitle.DrawGroup(TasksTitle.ControlDot(7).X, 100, inCalWidth + TasksTitle.ControlDot(7).X, 101)
  180.     shapeBackground.LPinX = 0
  181.     shapeBackground.LPinY = 0
  182.     shapeBackground.GPinX = TasksTitle.ControlDot(7).X
  183.     shapeBackground.GPinY = 100
  184.     shapeBackground.Name = "Background"
  185.     dateCurDate = GetCalStart()
  186.     Do While dateCurDate < GetCalEnd()+1
  187.         dateNextDate = GetNextCellDate(inKind, dateCurDate, shapeText)
  188.         X1 = (dateCurDate - GetCalStart()) * GetDayWidth()
  189.         X2 = (dateNextDate - GetCalStart()) * GetDayWidth()
  190.         Set shapeCell = shapeBackground.DrawRect(X1, 0, X2, 1)
  191.         shapeCell.LPinY = 0
  192.         shapeCell.GPinY = 0
  193.         shapeCell.LPinX = 0
  194.         shapeCell.GPinX = X1
  195.         If inKind = 1 AND GetDateWeekDay(dateCurDate) >= 6 Then
  196.             shapeCell.FillColor.SetRGB(200, 200, 200)
  197.         Else
  198.             shapeCell.FillColor.SetRGB(255, 255, 255)
  199.         End If
  200.         shapeCell.PenPattern = 1
  201.         shapeCell.FillPattern = 1
  202.         shapeCell.FillPatColor.SetRGB(255, 255, 255)
  203.         shapeCell.SetPropertyFormula("=0", CDPT_LPINY)
  204.         shapeCell.SetPropertyFormula("=0", CDPT_GPINY)
  205.         shapeCell.SetPropertyFormula("=0", CDPT_LPINX)
  206.         shapeCell.SetPropertyFormula("=" & X1, CDPT_GPINX)
  207.         shapeCell.RecalcProperty(CDPT_LPINY)
  208.         shapeCell.RecalcProperty(CDPT_GPINY)
  209.         shapeCell.RecalcProperty(CDPT_LPINX)
  210.         shapeCell.RecalcProperty(CDPT_GPINX)
  211.         dateCurDate = dateNextDate
  212.     Loop
  213.     shapeBackground.SetPropertyFormula("=100", CDPT_GPINY)
  214.     shapeBackground.SetPropertyFormula("=Parent.Controls.X7", CDPT_GPINX)
  215.     shapeBackground.SetPropertyFormula("=Parent.Variables.Y2+1", CDPT_HEIGHT)
  216.  
  217.     shapeBackground.PropertyChanged(CDPT_LPINX)
  218.     shapeBackground.PropertyChanged(CDPT_LPINY)
  219.     shapeBackground.RecalcProperty(CDPT_GPINX)
  220.     shapeBackground.RecalcProperty(CDPT_GPINY)
  221.     shapeBackground.RecalcProperty(CDPT_HEIGHT)
  222.     shapeBackground.PropertyChanged(CDPT_VARIABLE_Y, 2)
  223. ErrorHandle:
  224. End Sub
  225.  
  226. Sub AdjustCalendar()
  227.     Dim val As Integer
  228.     Select Case GetTimeScale()
  229.         Case 2
  230.             val = GetDateWeekDay(GetCalStart())
  231.             SetCalStart(GetCalStart() - val + 1)
  232.         Case 3
  233.             val = GetDateDay(GetCalStart())
  234.             SetCalStart(GetCalStart() - val + 1)
  235.         Case 4
  236.             val = Int((GetDateMonth(GetCalStart())-1) / 3) * 3 + 1
  237.             SetCalStart(CDate("01." & val & "." & GetDateYear(GetCalStart())))
  238.         Case 5
  239.             SetCalStart(CDate("01.01." & GetDateYear(GetCalStart())))
  240.     End Select
  241. End Sub
  242.  
  243. '+---------------------------------------------------
  244. '!    line 0
  245. '+---------------------------------------------------
  246. '!    line 1
  247. '+---------------------------------------------------
  248. Function GetTimeScaleForLine(inLineNum As integer, inTimeScale As Integer) As Integer
  249.     GetTimeScaleForLine = inTimeScale
  250.     If inLineNum = 0 Then
  251.         If inTimeScale = 3 Then
  252.             GetTimeScaleForLine = 5
  253.         Else
  254.             GetTimeScaleForLine = inTimeScale + 1
  255.         End If
  256.     End If
  257. End Function
  258.  
  259. Function RecalcTimeLines(shpTasksTitle As Shape) As Integer
  260. On Error Goto ErrorHandle
  261.     Dim dblStart        As Double
  262.     Dim dblEnd            As Double
  263.     Dim dblComplete        As Double
  264.     Dim shapeTask        As Shape
  265.  
  266.     Dim strFormula        As String
  267.     Dim dblPosS            As Double
  268.     Dim dblPosE            As Double
  269.     Dim dblPosC            As Double
  270.     Dim dblDayWidth        As Double
  271.     Dim dblCalStart        As Double
  272.  
  273.     dblDayWidth = GetDayWidth()
  274.     dblCalStart = GetCalStart()
  275.  
  276.     For I=1 To thisDoc.ActivePage.ShapesNum()
  277.         If thisDoc.ActivePage.Shape(I).Name = "TaskBar" Then
  278.             Set shapeTask = thisDoc.ActivePage.Shape(I)
  279.             If IsDate(shapeTask.CustomProp(6).Value) Then
  280.                 dblStart = CDbl(CDate(shapeTask.CustomProp(6).Value))
  281.             Else
  282.                 dblStart = dblCalStart
  283.             End If
  284.             If IsDate(shapeTask.CustomProp(7).Value) Then
  285.                 dblEnd = CDbl(CDate(shapeTask.CustomProp(7).Value))
  286.             Else
  287.                 dblEnd = dblCalStart + 2
  288.             End If
  289.             dblComplete = shapeTask.CustomProp(9).Value
  290.  
  291.             strFormula = shapeTask.GetPropertyFormula(CDPT_VARIABLE_X, 7)
  292.             shapeTask.Variable(7).X = shpTasksTitle.Width
  293.             shapeTask.SetPropertyFormula(strFormula, CDPT_VARIABLE_X, 7)
  294.             shapeTask.RecalcProperty(CDPT_VARIABLE_X, 7)
  295.  
  296.             dblPosS = (dblStart - dblCalStart) * dblDayWidth + shapeTask.Variable(6).X
  297.             shapeTask.ControlDot(1).X = dblPosS
  298.             dblPosE = (dblEnd - dblCalStart + 1) * dblDayWidth + shapeTask.Variable(6).X
  299.             shapeTask.ControlDot(2).X = dblPosE
  300.             dblPosC = (dblPosE - dblPosS) * dblComplete + dblPosS
  301.             shapeTask.ControlDot(3).X = dblPosC
  302.  
  303.             shapeTask.PropertyChanged(CDPT_CONTROL_X, 1)
  304.             shapeTask.PropertyChanged(CDPT_CONTROL_X, 2)
  305.             shapeTask.PropertyChanged(CDPT_CONTROL_X, 3)
  306.             shapeTask.PropertyChanged(CDPT_CUSTOM_VALUE, 1)
  307.         End if
  308.     Next
  309. ErrorHandle:
  310. End Function
  311.  
  312. Function BuildCalendar(this As Shape, inFlag As Integer) As Integer
  313. On Error Goto ErrorHandle
  314.     Dim shapeForDel        As Shape
  315.     Dim ret                As Long
  316.  
  317.     Dim calStart        As Double
  318.     Dim calEnd            As Double
  319.     Dim intScale        As Long
  320.  
  321.     BuildCalendar = 0
  322.     Set TasksTitle = this
  323.  
  324.     If inFlag = 1 Then
  325.         Dim str As String
  326.         Dim val As Double
  327.  
  328.         str = GetCalStart() & " " & GetCalEnd() & " " & (GetTimeScale()-1) & Space(32)
  329.         ret = PPCalendarPropDlg(str)
  330.         If ret = -1 Then
  331.             Exit Function
  332.         End If
  333.         SetCalStart(CDbl(str))
  334.         str = Trim(Right(str, Len(str) - InStr(str, " ")))
  335.         SetCalEnd(CDbl(str))
  336.         str = Trim(Right(str, Len(str) - InStr(str, " ")))
  337.         SetTimeScale(CInt(str)+1)
  338.     End If
  339.  
  340.     Set shapeForDel = FindShapeByNameInGroup(TasksTitle, "Calendar")
  341.     If shapeForDel <> Null Then
  342.         TasksTitle.RemoveShapeByID(shapeForDel.ID)
  343.     End If
  344.     Set shapeForDel = FindShapeByNameInGroup(TasksTitle, "Background")
  345.     If shapeForDel <> Null Then
  346.         TasksTitle.RemoveShapeByID(shapeForDel.ID)
  347.     End If
  348.     Select Case GetTimeScale()
  349.         Case 1
  350.             SetDayWidth(50)
  351.         Case 2
  352.             SetDayWidth(150 / 7)
  353.         Case 3
  354.             SetDayWidth(150 / 30.4375)
  355.         Case 4
  356.             SetDayWidth(200 / 92)
  357.         Case 5
  358.             SetDayWidth(200 / 365.25)
  359.     End Select
  360.     AdjustCalendar()
  361.  
  362.     arrayWeekSymb(1) = "M"
  363.     arrayWeekSymb(2) = "T"
  364.     arrayWeekSymb(3) = "W"
  365.     arrayWeekSymb(4) = "T"
  366.     arrayWeekSymb(5) = "F"
  367.     arrayWeekSymb(6) = "S"
  368.     arrayWeekSymb(7) = "S"
  369.  
  370.     arrayMonthDays(01) = 31
  371.     arrayMonthDays(02) = 28
  372.     arrayMonthDays(03) = 31
  373.     arrayMonthDays(04) = 30
  374.     arrayMonthDays(05) = 31
  375.     arrayMonthDays(06) = 30
  376.     arrayMonthDays(07) = 31
  377.     arrayMonthDays(08) = 31
  378.     arrayMonthDays(09) = 30
  379.     arrayMonthDays(10) = 31
  380.     arrayMonthDays(11) = 30
  381.     arrayMonthDays(12) = 31
  382.  
  383.     arrayQuartalDays(1) = 31 + 28 + 31
  384.     arrayQuartalDays(2) = 30 + 31 + 30
  385.     arrayQuartalDays(3) = 31 + 31 + 30
  386.     arrayQuartalDays(4) = 31 + 30 + 31
  387.  
  388.     thisDoc.ActivePage.ReorderShape(TasksTitle.SubID, 1)
  389.     thisDoc.StartRebuild()
  390.  
  391.     Dim dblCalWidth As Double
  392.     dblCalWidth = (GetCalEnd() - GetCalStart() + 1) * GetDayWidth()
  393.  
  394.     TasksTitle.SetNullFormula(CDPT_WIDTH)
  395.     TasksTitle.Width = TasksTitle.ControlDot(7).X + dblCalWidth
  396.     TasksTitle.PropertyChanged(CDPT_WIDTH)
  397.     Set shapeCalendar = TasksTitle.DrawGroup(TasksTitle.ControlDot(7).X, 0, TasksTitle.ControlDot(7).X + dblCalWidth, TasksTitle.Height)
  398.  
  399.     BuildOneLineInCalendar(GetTimeScaleForLine(0, GetTimeScale()), 0, 0)
  400.     BuildOneLineInCalendar(GetTimeScaleForLine(1, GetTimeScale()), TasksTitle.Height*0.5, 1)
  401.  
  402.     thisDoc.EndRebuild()
  403.     thisDoc.StartRebuild()
  404.  
  405.     If GetTimeScale() > 1 Then
  406.         BuildBackground(GetTimeScaleForLine(0, GetTimeScale()), dblCalWidth)
  407.     Else
  408.         BuildBackground(GetTimeScaleForLine(1, GetTimeScale()), dblCalWidth)
  409.     End If
  410.  
  411.     shapeCalendar.LPinX = 0
  412.     shapeCalendar.LPinY = 0
  413.     shapeCalendar.Name = "Calendar"
  414.     shapeCalendar.SetPropertyFormula("=Parent.Controls.X7", CDPT_GPINX)
  415.     shapeCalendar.RecalcProperty(CDPT_GPINX)
  416.  
  417.     thisDoc.PageSizeX = TasksTitle.GPinX + TasksTitle.Width + 100
  418.  
  419.     RecalcTimeLines(TasksTitle)
  420.  
  421.     thisDoc.EndRebuild()
  422.     thisDoc.UpdateAllViews()
  423.  
  424.     BuildCalendar = 1
  425. ErrorHandle:
  426. End Function
  427.