1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<%@ Page Language="vb" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="SortTask.aspx.vb" Inherits="Aspose.Tasks.Demos._9.SortTask" Title="Tasks Sorting" %> <asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> Please browse a valid mpp project file and press 'Upload and Sorted Task View' button to upload file to server so that Aspose.Tasks reads Tasks, Sort Tasks and then displays Sorted Tasks. <br /> <br /> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <br /> <asp:Button ID="btn_up_view" runat="server" OnClick="btn_up_view_Click" Text="Upload and Sorted Task View" /> <br /> <%=Session("outvar_S")%> <% Session("outvar_S") = "" %> </asp:Content>
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
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 Aspose.Tasks Imports System.IO Namespace Aspose.Tasks.Demos._9 Public Class ClsTask Implements IComparable Private tmpTSK As Task Public Sub New(ByVal ttK As Task) tmpTSK = ttK End Sub Public ReadOnly Property myID() As Integer Get Return tmpTSK.Id End Get End Property Public ReadOnly Property tName() As String Get Return tmpTSK.Name End Get End Property Public ReadOnly Property tStart() As DateTime Get Return tmpTSK.Start End Get End Property Public ReadOnly Property tFinish() As DateTime Get Return tmpTSK.Finish End Get End Property Public ReadOnly Property tEstimated() As Boolean Get Return tmpTSK.IsEstimated End Get End Property Private Function CompareTo(ByVal x As Object) As Integer Implements IComparable.CompareTo Dim tsk As ClsTask = CType(x, ClsTask) Return Me.tmpTSK.Name.CompareTo(tsk.tmpTSK.Name) End Function End Class Partial Public Class SortTask Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub Protected Sub btn_up_view_Click(ByVal sender As Object, ByVal e As EventArgs) '********* 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_S") = "<h3>Invalid file</h3>" Return End If Else '////Write html message and exit Session("outVar_S") = "<h3>No project file</h3>" Return End If '********* MPP File Upload block [Ends]*************** '''Read mpp file from the server Dim rdr As New ProjectReader() Dim prj As Project = rdr.Read(New FileStream(Server.MapPath("") & "\" & strFile, FileMode.Open)) 'Display Tasks Dim alTasks As ArrayList = prj.RootTask.Children Session("outVar_S") = Session("outVar_S") & "<h2>Tasks Assigned</h2><br/>" If alTasks.Count > 1 Then Session("outVar_S") = Session("outVar_S") & "<table border=1><tr bgcolor=blue><td><font color=white>Task ID</font></td><td><font color=white>Task Name</font></td><td><font color=white>Start Date(mm/dd)</font></td><td><font color=white>Task Duration</font></td><td><font color=white>End Date(mm/dd)</font></td><td><font color=white>Predecessor</font></td></tr>" Else Session("outVar_S") = Session("outVar_S") & "<h3>No Tasks Found...</h3><br/>" End If Dim arrSort As New ArrayList() For Each task As Task In alTasks Dim sortTsk As New ClsTask(task) arrSort.Add(sortTsk) Next task arrSort.Sort() For Each tsk As ClsTask In arrSort Session("outVar_S") = Session("outVar_S") & "<tr>" '''Get and Write Task ID Session("outVar_S") = Session("outVar_S") & "<td>" & tsk.myID & "</td>" '''Get and Wrtie Task Name Session("outVar_S") = Session("outVar_S") & "<td>" & tsk.tName & "</td>" '''Get and Wrtie Task Start Date Dim dtStart As DateTime = tsk.tStart Session("outVar_S") = Session("outVar_S") & "<td>" & dtStart.Month & "/" & dtStart.Day & "</td>" '''Get and Wrtie Task Duration Dim cal As Aspose.Tasks.Calendar = prj.Calendar 'TimeSpan ts = tsk.Duration; Dim dtFinish As DateTime = tsk.tFinish Dim dtTemp As DateTime = dtStart Dim durationInDays As Double = 0 Dim ts As TimeSpan Do While dtTemp < dtFinish If cal.IsDayWorking(dtTemp) Then ts = cal.GetWorkingHours(dtTemp) If ts.TotalHours > 0 Then durationInDays = durationInDays + ts.TotalDays * (24 / (ts.TotalHours)) End If End If dtTemp = dtTemp.AddDays(1) Loop Dim strDurValue As String = durationInDays.ToString() & "d" Dim blnTEMP As Boolean = tsk.tEstimated Dim strEST As String If (blnTEMP) Then strEST = "?" Else strEST = "" End If Dim strDuration As String = strDurValue & strEST Session("outVar_S") = Session("outVar_S") & "<td>" & strDuration & "</td>" '''Get and Write Task End Date Session("outVar_S") = Session("outVar_S") & "<td>" & dtFinish.Month.ToString() & "/" & dtFinish.Day.ToString() & "</td>" '''Get and Write Task Predecessor Dim alLNK As ArrayList = prj.TaskLinks For Each tsklnk As TaskLink In alLNK If tsklnk.SuccTask.Name = tsk.tName Then Session("outVar_S") = Session("outVar_S") & "<td>" & tsklnk.PredTask.Id & "</td>" End If Next tsklnk Session("outVar_S") = Session("outVar_S") & "</tr>" Next tsk Session("outVar_S") = Session("outVar_S") & "</table>" End Sub End Class End Namespace