السلام عليكم ورحمة الله وبركاته ..عندي مشكلة في كود التحويل من object إلى datetime
هذا الكود
string[] colors = new string[] { "navy", "maroon", "orange" };
//DataTable dt = new DataTable();
public string dateHeader;
DateTime dtMin, dtMax;
int dateSpan;
int count = 0;
// string[] colors = new string[] { "navy", "maroon", "orange" };
protected void Page_Load(object sender, EventArgs e)
{
string pr=Request.QueryString["pr_Id"];
SqlConnection SqlConnection1 = new SqlConnection();
SqlConnection1.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
SqlDataAdapter sub = new SqlDataAdapter();
DataTable custDS = new DataTable();
SqlCommand selectCMD = new SqlCommand("SELECT Subproject_Name,date_Start,date_end FROM Subprojects where Project_Id=" + pr, SqlConnection1);
sub.SelectCommand = selectCMD;
SqlConnection1.Open();
sub.Fill(custDS);
SqlConnection1.Close();
rpt.DataSource = custDS;
rpt.DataBind();
// buildData(); // make your dt
//get min and max dates (or whatever you choose to use)
dtMin = (DateTime)(from p in custDS.AsEnumerable() select p["date_start"]).Min();
dtMax = (DateTime)(from p in custDS.AsEnumerable() select p["date_end"]).Max();
dateSpan = (dtMax - dtMin).Days;
dateHeader = "<span style=\"float:left;\">" + dtMin.ToShortDateString() + "</span><span style=\"float:right;\">" + dtMax.ToShortDateString() + "</span>";
//displays the test data in table format
//GridView gv = new GridView();
//gv.DataSource = dt;
//gv.DataBind();
//form1.Controls.Add(gv);
}
public string doGantt(object sub, object start_sub, object end_sub)
{
string title_sub = (string)sub;
DateTime start = (DateTime) start_sub;
DateTime end = (DateTime)end_sub;
int numberOfDays = (end - start).Days;
int startDivAt = (start - dtMin).Days > 0 ? (start - dtMin).Days * 100 / dateSpan : 0;
int howWide = end != dtMax ? ((end - start).Days + 1) * 100 / dateSpan : (end - start).Days * 100 / dateSpan;
count++;
return "<div class=\"gantt\" style=\"background:" + colors[count % colors.Count()] + ";width:" + howWide + "%;margin-left:" + startDivAt + "%;\"> " + title_sub + "</div>";
}

