Gnatt Chart:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace Gnatt_Chart2
{
public partial class WebForm1 : System.Web.UI.Page
{
string sqlc = System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnection"].ToString();
// public string dateHeader, subHeader;
DateTime dtMin, dtMax, days;
int dateSpan;
string x, y;
//string[] c = new string[345];
//string[] colors = new string[] { "Red", "Green", "blue", "Yellow" };
protected void Page_Load(object sender, EventArgs e)
{
dtMin = Convert.ToDateTime("01/01/2015");
x = string.Format("{0:MM/dd/YYYY}", "01/01/2015");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
days = Convert.ToDateTime("01/01/2015");
dtMax = Convert.ToDateTime("02/01/2015");
y = string.Format("{0:MM/dd/YYYY}", "02/01/2015");
dateSpan = (dtMax - dtMin).Days;
if (dateSpan > 0)
{
sb.Append("<table border='1'>");
sb.Append("<th>");
sb.Append("<tr id='tr1'>");
sb.Append("<td>");
sb.Append(x);
sb.Append("</td>");
for (int i = 1; i <= dateSpan; i++)
{
sb.Append("<td width='40px' height='40px' id='tr'" + i.ToString() + "> ");
//sb.Append(i + "|");
sb.Append(i);
sb.Append("</td>");
}
sb.Append("<td>");
sb.Append(y);
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("</th>");
sb.Append(CreateRows());
sb.Append("</table>");
}
PlaceHolder1.Controls.Add(new Literal { Text = sb.ToString() });
}
/* sb.Append("<tr>");
sb.Append("<td>");
StartDate = dt.Rows[k]["Start"].ToString();
sb.Append(StartDate);
sb.Append("</td>");
sb.Append("<td width='14px'>");
//sb.Append("<div class=\"gantt\" style=\"background:" + colors[count % colors.Count()] + ">");
Task = dt.Rows[k]["Title"].ToString();
sb.Append(Task);
sb.Append("</div>");
sb.Append("</td>");
sb.Append("<td>");
EndDate = dt.Rows[k]["End"].ToString();
sb.Append(EndDate);
sb.Append("</td>");
sb.Append("</tr>");*/
public string CreateRows()
{
string StartDate = "", EndDate="";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
DataTable dt = this.display();
for (int k = 0; k < dt.Rows.Count; k++)
{
sb.Append("<tr>");
sb.Append("<td>");
StartDate = dt.Rows[k]["Start"].ToString();
sb.Append(StartDate);
sb.Append("</td>");
for (int i = 1; i <= dateSpan; i++)
{
if (i >= Convert.ToInt32(dt.Rows[k]["SDay"]) && i <= Convert.ToInt32(dt.Rows[k]["EDay"]))
{
sb.Append("<td bgcolor='#FF0000'>"+ dt.Rows[k]["Title"].ToString());
sb.Append("</td>");
}
else
{
sb.Append("<td >");
sb.Append("</td>");
}
}
sb.Append("<td>");
EndDate = dt.Rows[k]["End"].ToString();
sb.Append(EndDate);
sb.Append("</td>");
sb.Append("</tr>");
}
return sb.ToString();
}
public DataTable display()
{
try
{
SqlConnection con = new SqlConnection(sqlc);
SqlCommand cmd = new SqlCommand("select Title,CONVERT( NVARCHAR(125),Start,101)[Start],CONVERT( NVARCHAR(125),[End],101)[End], DATEPART(day,Start) SDay, DATEPART(day,[End]) EDay from Gnatt", con);
SqlDataAdapter sd = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sd.Fill(dt);
return dt;
}
catch (Exception)
{
throw;
}
}
}
}
OutPut:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace Gnatt_Chart2
{
public partial class WebForm1 : System.Web.UI.Page
{
string sqlc = System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnection"].ToString();
// public string dateHeader, subHeader;
DateTime dtMin, dtMax, days;
int dateSpan;
string x, y;
//string[] c = new string[345];
//string[] colors = new string[] { "Red", "Green", "blue", "Yellow" };
protected void Page_Load(object sender, EventArgs e)
{
dtMin = Convert.ToDateTime("01/01/2015");
x = string.Format("{0:MM/dd/YYYY}", "01/01/2015");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
days = Convert.ToDateTime("01/01/2015");
dtMax = Convert.ToDateTime("02/01/2015");
y = string.Format("{0:MM/dd/YYYY}", "02/01/2015");
dateSpan = (dtMax - dtMin).Days;
if (dateSpan > 0)
{
sb.Append("<table border='1'>");
sb.Append("<th>");
sb.Append("<tr id='tr1'>");
sb.Append("<td>");
sb.Append(x);
sb.Append("</td>");
for (int i = 1; i <= dateSpan; i++)
{
sb.Append("<td width='40px' height='40px' id='tr'" + i.ToString() + "> ");
//sb.Append(i + "|");
sb.Append(i);
sb.Append("</td>");
}
sb.Append("<td>");
sb.Append(y);
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("</th>");
sb.Append(CreateRows());
sb.Append("</table>");
}
PlaceHolder1.Controls.Add(new Literal { Text = sb.ToString() });
}
/* sb.Append("<tr>");
sb.Append("<td>");
StartDate = dt.Rows[k]["Start"].ToString();
sb.Append(StartDate);
sb.Append("</td>");
sb.Append("<td width='14px'>");
//sb.Append("<div class=\"gantt\" style=\"background:" + colors[count % colors.Count()] + ">");
Task = dt.Rows[k]["Title"].ToString();
sb.Append(Task);
sb.Append("</div>");
sb.Append("</td>");
sb.Append("<td>");
EndDate = dt.Rows[k]["End"].ToString();
sb.Append(EndDate);
sb.Append("</td>");
sb.Append("</tr>");*/
public string CreateRows()
{
string StartDate = "", EndDate="";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
DataTable dt = this.display();
for (int k = 0; k < dt.Rows.Count; k++)
{
sb.Append("<tr>");
sb.Append("<td>");
StartDate = dt.Rows[k]["Start"].ToString();
sb.Append(StartDate);
sb.Append("</td>");
for (int i = 1; i <= dateSpan; i++)
{
if (i >= Convert.ToInt32(dt.Rows[k]["SDay"]) && i <= Convert.ToInt32(dt.Rows[k]["EDay"]))
{
sb.Append("<td bgcolor='#FF0000'>"+ dt.Rows[k]["Title"].ToString());
sb.Append("</td>");
}
else
{
sb.Append("<td >");
sb.Append("</td>");
}
}
sb.Append("<td>");
EndDate = dt.Rows[k]["End"].ToString();
sb.Append(EndDate);
sb.Append("</td>");
sb.Append("</tr>");
}
return sb.ToString();
}
public DataTable display()
{
try
{
SqlConnection con = new SqlConnection(sqlc);
SqlCommand cmd = new SqlCommand("select Title,CONVERT( NVARCHAR(125),Start,101)[Start],CONVERT( NVARCHAR(125),[End],101)[End], DATEPART(day,Start) SDay, DATEPART(day,[End]) EDay from Gnatt", con);
SqlDataAdapter sd = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sd.Fill(dt);
return dt;
}
catch (Exception)
{
throw;
}
}
}
}
OutPut:
No comments:
Post a Comment