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
|
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 System.Text;
using System.Drawing;
using System.IO;
using Aspose.Tasks;
using Aspose.Tasks.Util;
using Aspose.Tasks.Visualization;
namespace Aspose.Tasks.Demos._9
{
public partial class Gantt_Chart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
this.imgGantt.Visible = true;
this.imgGantt.ImageUrl = Session["imagePath"].ToString();
}
}
protected void btn_up_view_Click(object sender, EventArgs e)
{
this.imgGantt.Visible = false;
/********** 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"] = "<h3>Invalid file</h3>";
return;
}
}
else
{
//////Write html message and exit
Session["outVar"] = "<h3>No project file</h3>";
return;
}
/********** MPP File Upload block [Ends]****************/
ProjectReader rdr = new ProjectReader();
Project project = rdr.Read(new FileStream(Server.MapPath("") + "\\" + this.FileUpload1.FileName, FileMode.Open));
ArrayList columns = new ArrayList();
columns.Add(new GanttChartColumn("Name", 100, new TaskToColumnTextConverter(TaskName)));
columns.Add(new GanttChartColumn("Notes", 100, new TaskToColumnTextConverter(TaskNotes)));
columns.Add(new GanttChartColumn("Resources", 200, new TaskToColumnTextConverter(TaskResources)));
//Create the view
ProjectView view = new ProjectView(columns);
//Render to image
string strTemp = DateTime.Now.ToString("ddmmyyhhmmss");
IRenderResult res = project.Export(RenderFormat.Image, PresentationFormat.GanttChart, Server.MapPath("") + "\\images\\" + strTemp + ".jpg", new BaseImageRenderParam(null,
new Point(), new Size(800, 600), 100, 0, false), true, null, view);
Session["imagePath"] = "~/images/" + strTemp + ".jpg";
}
private string TaskName(Task task)
{
StringBuilder res = new StringBuilder();
for (int i = 1; i < task.OutlineLevel; i++)
res.Append(" ");
res.AppendFormat("{0}. {1}", task.Id, task.Name);
return res.ToString();
}
private static string TaskNotes(Task task)
{
if (task.NotesText != null)
return task.NotesText;
else
return string.Empty;
}
private static string TaskResources(Task task)
{
StringBuilder res = new StringBuilder();
Project project = task.ParentProject;
bool bFirst = true;
foreach (ResourceAssignment assignment in project.GetResourceAssignmentsByTask(task))
if (assignment.Resource != null)
{
if (!bFirst)
res.Append(", ");
res.Append(assignment.Resource.Name);
bFirst = false;
}
return res.ToString();
}
}
}
|