本帖最后由 86971375 于 2022-9-20 15:23 编辑
我的数据只有不到200条,但是加载速度太慢了,下面是我的代码,麻烦看看
/// <summary>
/// 加载根级节点数据集
/// </summary>
/// <param name="Id"></param>
private void BulidTaskInfo()
{
GanttView1.Tasks.Clear();
GanttView1.StartDate = ucStartDate.Value.Date;
GanttView1.FinishDate = ucEndDate.Value.Date;
Guid Pid = Guid.Empty;
var rootList = myBll.GetProjectPlanDetailList(MyModel.Id,Guid.Empty);//xmmxList.OrderBy(p => p.StartDate).ThenBy(p => p.SerialNumber);
foreach (var item in rootList)
{
C1.Win.C1GanttView.Task task = new C1.Win.C1GanttView.Task();
task.ID = item.Id.GetHashCode();
task.Name = item.WorkContent;
task.Notes = item.WorkingRrules;
task.Start = item.StartDate.Date;
task.Finish = item.EndDate.Date;
task.Mode = TaskMode.Manual;
#region old
//TimeSpan daysSpan = new TimeSpan(item.EndDate.Date.Ticks - item.StartDate.Date.Ticks);
//task.Duration = daysSpan.Days;
//task.DurationUnits= DurationUnits.Days;
//任务完成百分比
//task.PercentComplete = 0;
//task.ConstraintType = ConstraintType.Default;
//task.ConstraintDate = item.EndDate;
#endregion
//自定义列
task.SetFieldValue("KeyId", item.Id);
task.SetFieldValue("HandlerMan", item.HandlerMan);
task.SetFieldValue("PID", item.PID);
task.SetFieldValue("HandlerName", item.HandlerName);
task.OutlineParentID = 399205711;
GanttView1.Tasks.Add(task);
//xmmxList.Where(p => p.PID == item.Id).OrderBy(p => p.StartDate).ThenBy(p => p.SerialNumber).ToList();
var childList = myBll.GetProjectPlanDetailList(MyModel.Id,item.Id);
if (childList.Any())
{
BulidChildTaskInfo(task, childList, item.Id);
}
}
CollapseGroupTasks(true);
//C1.Win.C1GanttView.Task t = GanttView1.Tasks.Search("First Task");
//GanttView1.ScrollToTask(t);
//GanttView1.SelectedTask = t;
}
/// <summary>
/// 获取某个任务的子任务信息
/// </summary>
/// <param name="taskList"></param>
/// <param name="Id">父节点</param>
/// <param name="durationUnits">图形显示单位:0Minutes,1Hours,2Days,3Weeks,4Months</param>
/// <returns></returns>
private void BulidChildTaskInfo(C1.Win.C1GanttView.Task masterTask, List<JHGLGTT_ProjectPlanDetail> childList, Guid Id)
{
foreach (var item in childList)
{
C1.Win.C1GanttView.Task task1 = GanttView1.Tasks.AddNew();
task1.ID = item.Id.GetHashCode();
task1.Name = item.WorkContent;
task1.Notes = item.WorkingRrules;
task1.Start = item.StartDate.Date;
task1.Finish = item.EndDate.Date;
task1.Mode = TaskMode.Manual;
#region old
//TimeSpan daysSpan = new TimeSpan(item.EndDate.Date.Ticks - item.StartDate.Date.Ticks);
//task1.Duration = daysSpan.Days;
//task1.DurationUnits = durationUnits;
//完成百分比
//task1.PercentComplete = 0;
//task1.ConstraintType = ConstraintType.Default;
//task1.ConstraintDate = item.StartDate;
#endregion
//自定义列
task1.SetFieldValue("KeyId", item.Id);
task1.SetFieldValue("HandlerMan", item.HandlerMan);
task1.SetFieldValue("PID", item.PID);
task1.SetFieldValue("HandlerName", item.HandlerName);
task1.OutlineParentID = masterTask.ID;
//xmmxList.Where(p => p.PID == item.Id).OrderBy(p => p.StartDate).ThenBy(p => p.SerialNumber).ToList();
var taskList0 = myBll.GetProjectPlanDetailList(MyModel.Id,item.Id);
if (taskList0.Any())
{
BulidChildTaskInfo(task1, taskList0, item.Id);
}
if (task1 != null)
{
masterTask.AddChild(task1);
//GanttView1.Tasks.Add(task1);
}
}
}
|