📄 task.cs
字号:
using System;
using MSProject = Microsoft.Office.Interop.MSProject;
namespace PrjXlsRpt
{
/// <summary>
/// Task
///
/// Revision History
/// ----------------
/// 20060103 mcarey file created
///
/// Copyright (c) 2006 Michael Carey. All Rights Reserved/
/// </summary>
public class Task
{
private string wbs;
private string name;
private System.DateTime startDate;
private System.DateTime finishDate;
private double percentComplete;
public Task()
{
Wbs = "";
Name = "";
StartDate = System.DateTime.Now;
FinishDate = System.DateTime.Now;
percentComplete = 0.0;
}
public Task(MSProject.Task o) {
SetProperties(o);
}
#region Properties
/// <summary>
/// Get/Set the work breakdown structure id.
/// </summary>
public string Wbs {
get {return wbs;}
set {wbs = value;}
}
/// <summary>
/// Get/Set the name.
/// </summary>
public string Name {
get {return name;}
set {name = value;}
}
/// <summary>
/// Get/Set the start date.
/// </summary>
public System.DateTime StartDate {
get {return startDate;}
set {startDate = value;}
}
/// <summary>
/// Get the start date in a format that is used by Excel.
/// </summary>
public string StartDateExcelFormat {
get {
// the excel format is: 1970-01-01T00:00:00.000
string s = StartDate.Year.ToString() + "-";
if(StartDate.Month > 9) {
s += StartDate.Month.ToString() + "-";
} else {
s += "0" + StartDate.Month.ToString() + "-";
}
if(StartDate.Day > 9) {
s += StartDate.Day.ToString();
} else {
s += "0" + StartDate.Day.ToString();
}
s += "T00:00:00.000";
return s;
}
}
/// <summary>
/// Get/Set the finish date.
/// </summary>
public System.DateTime FinishDate {
get {return finishDate;}
set {finishDate = value;}
}
/// <summary>
/// Get the finish date in a format that is used by Excel.
/// </summary>
public string FinishDateExcelFormat {
get {
// the excel format is: 1970-01-01T00:00:00.000
string s = FinishDate.Year.ToString() + "-";
if(FinishDate.Month > 9) {
s += FinishDate.Month.ToString() + "-";
} else {
s += "0" + FinishDate.Month.ToString() + "-";
}
if(FinishDate.Day > 9) {
s += FinishDate.Day.ToString();
} else {
s += "0" + FinishDate.Day.ToString();
}
s += "T00:00:00.000";
return s;
}
}
/// <summary>
/// Get/Set the percent complete.
/// </summary>
public double PercentComplete {
get {return percentComplete;}
set {percentComplete = value;}
}
#endregion Properties
/// <summary>
/// Assigns all the properties based upon the data in the
/// Microsoft Project task.
/// </summary>
/// <param name="o">The task to get the values from.</param>
public void SetProperties(MSProject.Task o) {
Wbs = o.WBS.ToString();
Name = o.Name.ToString();
StartDate = (System.DateTime) o.Start;
FinishDate = (System.DateTime) o.Finish;
PercentComplete = (System.Int16) o.PercentComplete;
}
/// <summary>
/// Returns the task data as XML formatted for Excel.
/// </summary>
/// <returns>The task data as XML formatted for Excel.</returns>
public string ToXml() {
string s = "";
s += "<Row>" + System.Environment.NewLine;
s += "<Cell><Data ss:Type=\"String\">" + Wbs + "</Data></Cell>" + System.Environment.NewLine;
s += "<Cell><Data ss:Type=\"String\">" + ToXml(Name) + "</Data></Cell>" + System.Environment.NewLine;
s += "<Cell ss:StyleID=\"s21\"><Data ss:Type=\"DateTime\">" + StartDateExcelFormat + "</Data></Cell>" + System.Environment.NewLine;
s += "<Cell ss:StyleID=\"s21\"><Data ss:Type=\"DateTime\">" + FinishDateExcelFormat + "</Data></Cell>" + System.Environment.NewLine;
s += "<Cell><Data ss:Type=\"Number\">" + (PercentComplete /100.0) + "</Data></Cell>" + System.Environment.NewLine;
s += "</Row>" + System.Environment.NewLine;
return s;
}
/// <summary>
/// Converts the passed string into a string that can be used in XML. The conversions are:
/// the ampersand, less than, greater than quote, and appostrophe.
/// </summary>
/// <param name="str">The string to convert.</param>
/// <returns>The converted string.</returns>
public static string ToXml(string str) {
string s = (str == null) ? "" : str;
s = s.Trim().Replace("&","&");
s = s.Replace("<","<");
s = s.Replace(">",">");
s = s.Replace("\"", """);
s = s.Replace("'","'");
return s;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -