Hi,
I am building a new project, and create some tasks and …
but when i check the mpp, its seem like some filters display worry things,
just like Duration and PercentComplete …
now i gonna show you my code:
AsposeProject asposeProject = new AsposeProject(@"C:\Users\A4\Desktop\AsposeTest\XXXX.mpp");
///项目计算模式
///None 0 无。在此模式下不会重新计算项目日期和成本。
///Automatic 1 自动模式。使用此模式时重新计算项目日期和成本。
///Manual 2 手动模式。在此模式下仅重新计算必要的字段,例如对象的 UID 和 ID。
asposeProject.CalculationMode = CalculationMode.None;
asposeProject.WorkFormat = TimeUnitType.Day;
asposeProject.NewTasksAreManual = false;//新任务模式
var calendar = project.Calendars.GetByUid(1);
calendar.Exceptions.Clear();
AsposeCalendar.MakeStandardCalendar(calendar);
//Calendar calendar = file.addDefaultBaseCalendar();
calendar.Name = "默认日历";
AsposeTask currentTask = parentTask.Children.Add(taskName);
currentTask.Id = taskEidDics[taskEID];////////////////////////////////////////////////////////////////
currentTask.IgnoreResourceCalendar = true;
currentTask.OutlineLevel = 1 + int.Parse(task["TASKLEVEL"].ToString());
currentTask.Duration = project.GetDuration(double.Parse(task["PLANPERIOD"].ToString()) / project.MinutesPerDay, TimeUnitType.Day);
DateTime start = DatetimeUtil.GetDateTimeByInternalTicks(para, long.Parse(task["PLANSTARTDATE"].ToString()));
DateTime end = DatetimeUtil.GetDateTimeByInternalTicks(para, long.Parse(task["PLANENDDATE"].ToString()));
currentTask.Start = start;
currentTask.Finish = end;
currentTask.PercentComplete = System.Int32.Parse(task["FINISHPERCENT"].ToString());
currentTask.PercentWorkComplete = System.Int32.Parse(task["FINISHPERCENT"].ToString());
currentTask.IsMilestone = bool.Parse(isMilestone);
currentTask.ConstraintType = AsposeConstraintType.AsSoonAsPossible;
currentTask.ConstraintDate = limitTime;
currentTask.IsEstimated = true;
currentTask.IsEstimated = true;
List<AsposeTask> alltasklist = file.RootTask.SelectAllChildTasks().ToList();
int assUid = 1;
int count = 0;
List<DataRow> tempDr = new List<DataRow>();
AsposeCalendar calendar = file.Calendar;
foreach (var row in taskRowDics)
{
DataRow task = row.Value;
count++;
resourceLinkDics.TryGetValue(task["EID"].ToString(), out tempDr);
if (tempDr != null && tempDr.Count > 0)
{
//排序,主资源在前,其他在后
tempDr.OrderBy(t => t["ISMAIN"]);
foreach (DataRow link in tempDr.OrderByDescending(t => t["ISMAIN"]))
{
AsposeResource res = file.Resources.GetById(resUniqueIdDic[link["ENAME"].ToString()]);
AsposeTask aspTask = alltasklist.FirstOrDefault(p => p.Id == taskEidDics[row.Key]);
Aspose.Tasks.ResourceAssignment resAssigment = file.ResourceAssignments.Add(aspTask, res); //10.6.2 调整
double unit = 100;
double.TryParse(link["RATE"].ToString(), out unit);
resAssigment.Units = unit / 100D; //资源单位(百分比)
resAssigment.Resource.Uid = resUniqueIdDic[link["ENAME"].ToString()];
resAssigment.Uid = assUid;
assUid++;
long longStartTime = long.Parse(task["PLANSTARTDATE"].ToString());
DateTime start = DatetimeUtil.GetDateTimeByInternalTicks(para, longStartTime);
long longEndTime = long.Parse(task["PLANENDDATE"].ToString());
DateTime end = DatetimeUtil.GetDateTimeByInternalTicks(para, longStartTime);
resAssigment.Start = start;
resAssigment.Finish = end;
int finishPercent = 0;
int.TryParse(task["FINISHPERCENT"].ToString(), out finishPercent);
resAssigment.PercentWorkComplete = finishPercent;
double taskWork = 0;
double.TryParse(task["PLANPERIOD"].ToString(), out taskWork);
file.Set(Prj.WorkFormat, TimeUnitType.Day); ///此行是否可以提前???
resAssigment.ActualWork = file.GetWork(taskWork * finishPercent / (minInday * 100));
resAssigment.RemainingWork = file.GetWork(taskWork * (100 - finishPercent) / (minInday * 100));
resAssigment.Work = file.GetWork(taskWork / minInday);
resAssigment.UpdateNeeded = true;
}
}
}