C# 使用JSGrid控件的甘特图
我正在尝试使用共享点控件创建甘特图生成器:C# 使用JSGrid控件的甘特图,c#,asp.net,sharepoint,gantt-chart,C#,Asp.net,Sharepoint,Gantt Chart,我正在尝试使用共享点控件创建甘特图生成器: <Sharepoint:JsGrid> (此代码来自教程中的答案) 在钥匙里,我要放什么?如果有人做了或者知道怎么做,那就太好了。不确定你是否仍然面临这个问题。但这是我们为前辈专栏所做的,据我所知: 1] 稍微更改依赖项类以添加一个构造函数,如图所示(否则会出错) 2] 然后,基本上需要将一个依赖项数组传递给前置项列,这意味着JSGrid控件需要知道依赖项的起点/行和终点/行(因此需要一个数组)。由于继承和ToJson方法,JSON序列化
<Sharepoint:JsGrid>
(此代码来自教程中的答案)
在钥匙里,我要放什么?如果有人做了或者知道怎么做,那就太好了。不确定你是否仍然面临这个问题。但这是我们为
前辈
专栏所做的,据我所知:
1] 稍微更改依赖项类以添加一个构造函数,如图所示(否则会出错)
2] 然后,基本上需要将一个依赖项
数组传递给前置项
列,这意味着JSGrid控件需要知道依赖项的起点/行和终点/行(因此需要一个数组)。由于继承和ToJson
方法,JSON序列化已经得到了处理,因此无需担心
代码:
1] 依赖类:
public class Dependency : IJsonSerializable
{
public object Key { get; set; } // recordKey
public LinkType Type { get; set; } // SP.JsGrid.LinkType
public Dependency() {
Key = DBNull.Value;
Type = LinkType.FinishStart;
}
public string ToJson(Serializer s)
{
return JsonUtility.SerializeToJsonFromProperties(s, this);
}
}
2] 如果不是针对SharePoint任务列表(其中数据是DataTable的对象),则添加列:
3] 将右对象数组设置为preventors
列:
if (<<A predecessor exists>>){
Dependency[] dep = new Dependency[2];
dep[0] = new Dependency();
try{
/*
// Unique Identifier for your row based on what you are
// passing to the GridSerializer while initializing it
// (as a third parameter which is called keyColumnName)
// In my case I had to get it by doing some coding as
// shown. The first object in the array represents the
// previous row and so the unique identifier should
// point to the previous row
*/
dep[0].Key = (
data.Select(
"ID=" +
data.Rows[s]["PredecessorsID"].ToString()
)
[0]["Key"]
);
}catch (Exception ex){
dep[0].Key = DBNull.Value;
}
dep[0].Type = LinkType.FinishStart;
/*
// Unique Identifier for your row based on what you are
// passing to the GridSerializer while initializing it
// (as a third parameter which is called keyColumnName)
// In my case I had to get it by doing some coding as
// shown. The second object in the array represents the
// current row and so the unique identifier should
// point to the current row
*/
dep[1] = new Dependency();
try{
dep[1].Key = data.Rows[s]["Key"];
}catch (Exception ex){
dep[0].Key = DBNull.Value;
}
dep[1].Type = LinkType.StartFinish;
data.Rows[s]["Predecessors"] = dep;
}
确保StartFinish和FinishStart链接类型与正确的行相匹配,并且任务正确列出,任务开始日期、任务结束日期和前置键正确
data.Columns.Add(new DataColumn("Predecessors",typeof(Dependency[])));
if (<<A predecessor exists>>){
Dependency[] dep = new Dependency[2];
dep[0] = new Dependency();
try{
/*
// Unique Identifier for your row based on what you are
// passing to the GridSerializer while initializing it
// (as a third parameter which is called keyColumnName)
// In my case I had to get it by doing some coding as
// shown. The first object in the array represents the
// previous row and so the unique identifier should
// point to the previous row
*/
dep[0].Key = (
data.Select(
"ID=" +
data.Rows[s]["PredecessorsID"].ToString()
)
[0]["Key"]
);
}catch (Exception ex){
dep[0].Key = DBNull.Value;
}
dep[0].Type = LinkType.FinishStart;
/*
// Unique Identifier for your row based on what you are
// passing to the GridSerializer while initializing it
// (as a third parameter which is called keyColumnName)
// In my case I had to get it by doing some coding as
// shown. The second object in the array represents the
// current row and so the unique identifier should
// point to the current row
*/
dep[1] = new Dependency();
try{
dep[1].Key = data.Rows[s]["Key"];
}catch (Exception ex){
dep[0].Key = DBNull.Value;
}
dep[1].Type = LinkType.StartFinish;
data.Rows[s]["Predecessors"] = dep;
}
gds.EnableGantt(
Convert.ToDateTime(
dr["start Date"]
),
Convert.ToDateTime(
dr["Due Date"]
),
GanttUtilities.GetStyleInfo(),
"Predecessors"
);