1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Text
Imports System.Drawing
Imports System.IO
Imports Aspose.Tasks
Imports Aspose.Tasks.Util
Imports Aspose.Tasks.Visualization
Namespace Aspose.Tasks.Demos._9
Partial Public Class Gantt_Chart
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Page.IsPostBack Then
Me.imgGantt.Visible = True
Me.imgGantt.ImageUrl = Session("imagePath").ToString()
End If
End Sub
Protected Sub btn_up_view_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.imgGantt.Visible = False
'********* MPP File Upload block [Starts]***************
'''The MPP file name to be read
Dim strFile As String = ""
'''Upload file to server
If Me.FileUpload1.HasFile Then
If Me.FileUpload1.FileName.EndsWith(".mpp") Then
strFile = Me.FileUpload1.FileName
Me.FileUpload1.PostedFile.SaveAs(MapPath(Me.FileUpload1.FileName))
Else
'''Write html message and exit
Session("outVar") = "<h3>Invalid file</h3>"
Return
End If
Else
'////Write html message and exit
Session("outVar") = "<h3>No project file</h3>"
Return
End If
'********* MPP File Upload block [Ends]***************
Dim rdr As New ProjectReader()
Dim project As Project = rdr.Read(New FileStream(Server.MapPath("") & "\" & Me.FileUpload1.FileName, FileMode.Open))
Dim columns As New ArrayList()
columns.Add(New GanttChartColumn("Name", 100, New TaskToColumnTextConverter(AddressOf TaskName)))
columns.Add(New GanttChartColumn("Notes", 100, New TaskToColumnTextConverter(AddressOf TaskNotes)))
columns.Add(New GanttChartColumn("Resources", 200, New TaskToColumnTextConverter(AddressOf TaskResources)))
'Create the view
Dim view As New ProjectView(columns)
'Render to image
Dim strTemp As String = DateTime.Now.ToString("ddmmyyhhmmss")
Dim res As IRenderResult = project.Export(RenderFormat.Image, PresentationFormat.GanttChart, Server.MapPath("") & "\images\" & strTemp & ".jpg", New BaseImageRenderParam(Nothing, New Point(), New Size(800, 600), 100, 0, False), True, Nothing, view)
Session("imagePath") = "~/images/" & strTemp & ".jpg"
End Sub
Private Function TaskName(ByVal task As Task) As String
Dim res As New StringBuilder()
For i As Integer = 1 To task.OutlineLevel - 1
res.Append(" ")
Next i
res.AppendFormat("{0}. {1}", task.Id, task.Name)
Return res.ToString()
End Function
Private Shared Function TaskNotes(ByVal task As Task) As String
If task.NotesText IsNot Nothing Then
Return task.NotesText
Else
Return String.Empty
End If
End Function
Private Shared Function TaskResources(ByVal task As Task) As String
Dim res As New StringBuilder()
Dim project As Project = task.ParentProject
Dim bFirst As Boolean = True
For Each assignment As ResourceAssignment In project.GetResourceAssignmentsByTask(task)
If assignment.Resource IsNot Nothing Then
If (Not bFirst) Then
res.Append(", ")
End If
res.Append(assignment.Resource.Name)
bFirst = False
End If
Next assignment
Return res.ToString()
End Function
End Class
End Namespace
|