Hi,
I’m having trouble implementing bar styles. Although, I’m setting bar styles for every task in the project, only some of the tasks are showing the assigned style. When I read my edited mpp file using Aspose, I can see a bar style is assigned to each task. But when I open this file in Project 2010 or 2016 only some tasks show the defined style.
I find some of the documentation confusing. For example, the GanttbarStyle Property ShowFor is defined as “Task categories separated by semicolumns, which are to be represented by the gantt bar.” What is a “semicolumns?” Is this a typo, should it be “semicolon?” Also, I can’t find a definition of “Task categories”. In examples, this seems to be the Uid. Is this correct? When I use a string containing semicolons between Uid’s for the ShowFor property, the bar style is not applied.
Also, what is the GanttbarStyle Property Row? Why can it be only 1 to 4?
The fact that some of the tasks show my assigned bar style suggests to me that the functionally works but I’m implementing this feature or something else in the project incorrectly.
The following is my method for setting the bar style. The bar style for each Task is recorded as XML in a SQL table called MMPFormat and is identified by field called UID.
Any thoughts or suggestions would be appreciated.
Thanks!
private void AddBarstyleToProject()
{
ChildTasksCollector collector = new ChildTasksCollector();
TaskUtils.Apply(_project.RootTask, collector, 0);
foreach (Aspose.Tasks.Task tsk in collector.Tasks)
{
string sqlBarStyle = string.Format("SELECT top 1 [BarStyle] FROM [QmV3].[QmSchema].[ MMPFormat] where UID = {0}", tsk.Get(Tsk.Uid));
var barStyle = _UOW.ExecuteScalar(sqlBarStyle);
if (barStyle != null)
{
GanttBarStyle style = new GanttBarStyle();
GanttBarStyleExport taskBarStyle = Serializer.XmlDeserializeFromString<GanttBarStyleExport>(barStyle.ToString());
style.Row = taskBarStyle.Row;
style.From = taskBarStyle.From;
style.To = taskBarStyle.To;
style.LeftField = taskBarStyle.LeftField;
style.RightField = taskBarStyle.RightField;
style.TopField = taskBarStyle.TopField;
style.BottomField = taskBarStyle.BottomField;
style.InsideField = taskBarStyle.InsideField;
style.StartShape = taskBarStyle.StartShape;
style.StartShapeColor = ColorTranslator.FromHtml(taskBarStyle.StartShapeColorHex);
style.StartShapeType = taskBarStyle.StartShapeType;
style.EndShape = taskBarStyle.EndShape;
style.EndShapeColor = ColorTranslator.FromHtml(taskBarStyle.EndShapeColorHex);
style.EndShapeType = taskBarStyle.EndShapeType;
style.MiddleShape = taskBarStyle.MiddleShape;
style.MiddleShapeColor = ColorTranslator.FromHtml(taskBarStyle.MiddleShapeColorHex);
style.MiddleFillPattern = taskBarStyle.MiddleFillPattern;
style.ShowFor = tsk.Get(Tsk.Uid).ToString();
GanttChartView view = _project.DefaultView as GanttChartView;
view.CustomBarStyles.Add(style);
}
}
}