1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="SortTask.aspx.cs" 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 167 168 169
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Aspose.Tasks; using System.IO; namespace Aspose.Tasks.Demos._9 { public class ClsTask : IComparable { private Task tmpTSK; public ClsTask(Task ttK) { tmpTSK = ttK; } public int myID { get { return tmpTSK.Id; } } public string tName { get { return tmpTSK.Name; } } public DateTime tStart { get { return tmpTSK.Start; } } public DateTime tFinish { get { return tmpTSK.Finish; } } public bool tEstimated { get { return tmpTSK.IsEstimated; } } int IComparable.CompareTo(object x) { ClsTask tsk = (ClsTask)x; return this.tmpTSK.Name.CompareTo(tsk.tmpTSK.Name); } } public partial class SortTask : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btn_up_view_Click(object sender, EventArgs e) { /********** MPP File Upload block [Starts]****************/ ///The MPP file name to be read string strFile = ""; ///Upload file to server if (this.FileUpload1.HasFile) { if (this.FileUpload1.FileName.EndsWith(".mpp")) { strFile = this.FileUpload1.FileName; this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName)); } else { ///Write html message and exit Session["outVar_S"] = "<h3>Invalid file</h3>"; return; } } else { //////Write html message and exit Session["outVar_S"] = "<h3>No project file</h3>"; return; } /********** MPP File Upload block [Ends]****************/ ///Read mpp file from the server ProjectReader rdr = new ProjectReader(); Project prj = rdr.Read(new FileStream(Server.MapPath("") + "\\" + strFile, FileMode.Open)); //Display Tasks ArrayList alTasks = prj.RootTask.Children; Session["outVar_S"] = Session["outVar_S"] + "<h2>Tasks Assigned</h2><br/>"; if (alTasks.Count > 1) 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/>"; ArrayList arrSort = new ArrayList(); foreach (Task task in alTasks) { ClsTask sortTsk = new ClsTask(task); arrSort.Add(sortTsk); } arrSort.Sort(); foreach (ClsTask tsk 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 DateTime dtStart = tsk.tStart; Session["outVar_S"] = Session["outVar_S"] + "<td>" + dtStart.Month + "/" + dtStart.Day + "</td>"; ///Get and Wrtie Task Duration Aspose.Tasks.Calendar cal = prj.Calendar; //TimeSpan ts = tsk.Duration; DateTime dtFinish = tsk.tFinish; DateTime dtTemp = dtStart; double durationInDays = 0; TimeSpan ts; while (dtTemp < dtFinish) { if (cal.IsDayWorking(dtTemp)) { ts = cal.GetWorkingHours(dtTemp); if (ts.TotalHours > 0) durationInDays = durationInDays + ts.TotalDays * (24 / (ts.TotalHours)); } dtTemp = dtTemp.AddDays(1); } string strDurValue = durationInDays.ToString() + "d"; bool blnTEMP = tsk.tEstimated; string strEST; strEST = (blnTEMP) ? "?" : ""; string strDuration = 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 ArrayList alLNK = prj.TaskLinks; foreach (TaskLink tsklnk in alLNK) { if (tsklnk.SuccTask.Name == tsk.tName) Session["outVar_S"] = Session["outVar_S"] + "<td>" + tsklnk.PredTask.Id + "</td>"; } Session["outVar_S"] = Session["outVar_S"] + "</tr>"; } Session["outVar_S"] = Session["outVar_S"] + "</table>"; } } }