public static string ass(DataTable table)
string JSONString = string.Empty;
JSONString = JsonConvert.SerializeObject(table);
public static string stringout(int current, int total, string a, string b)
return ("\"" + a + "\":" + "\"" + b + "\",");
else if (current == total)
return ("\"" + a + "\":" + "\"" + b + "\"");
public static string stringbuild(DataTable table, DataTable resources)
var JSONString = new StringBuilder();
if (table.Rows.Count > 0)
for (int k = 0; k < resources.Rows.Count; k++)
JSONString.Append("{" + "\"" + resources.Columns[2].ColumnName.ToString() + "\":" + "\"" + resources.Rows[k][2].ToString() + "\",");
JSONString.Append("\"tasks\":");
int counter = a + Convert.ToInt32(resources.Rows[k][1].ToString());
for (int i = a; i < counter; i++)
JSONString.Append("\"" + table.Columns[3].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][3].ToString() + "\",");
JSONString.Append("\"" + table.Columns[1].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][1].ToString() + "\",");
JSONString.Append("\"" + table.Columns[2].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][2].ToString() + "\",");
JSONString.Append("\"" + table.Columns[4].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][4].ToString() + "\"");
if (k == resources.Rows.Count - 1)
return JSONString.ToString();
public static DataTable getDataR()
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof (Int32));
dt.Columns.Add("count", typeof (Int32));
dt.Columns.Add("resource", typeof (String));
dt.Rows.Add(1, 1, "jcb");
dt.Rows.Add(2, 2, "plotter");
public static DataTable getData()
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof (Int32));
dt.Columns.Add("start", typeof (string));
dt.Columns.Add("end", typeof (string));
dt.Columns.Add("color", typeof (string));
dt.Columns.Add("task", typeof (string));
dt.Rows.Add(1, "2016-01-01", "2016-01-10", "#7B742C", "slab fill");
dt.Rows.Add(2, "2016-01-10", "2016-01-23", "#7B742C", "slabfill");
dt.Rows.Add(2, "2016-01-11", "2016-01-24", "", "flooring");
public static void Main()
DataTable task = getData();
DataTable resources = getDataR();
string outout = stringbuild(task, resources);
Console.WriteLine(outout);