[CS]
public ActionResult UrlDatasource(DataManagerRequest dm)
{
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password=yourpassword");//connectionString
con.Open();
using (con)
{
using (var command = con.CreateCommand())
{
command.CommandText = "SELECT * FROM GanttData";
using (var reader = command.ExecuteReader())
{
var indexOfCol1 = reader.GetOrdinal("TaskId");
var indexOfCol2 = reader.GetOrdinal("TaskName");
//...
while (reader.Read())
{
GanttData obj = new GanttData();
obj.TaskId = reader.GetValue(indexOfCol1).ToString();
//...
}
reader.Close();
}
}
con.Close();
}
var count = list.Count();
return Json(new { result = list, count = count });
}
public ActionResult BatchSave([FromBody]ICRUDModel<GanttData> data)
{
//...
return Json(new { addedRecords = uAdded, changedRecords = uChanged, deletedRecords = uDeleted });
}
public GanttData Create(GanttData value)
{
string cmdString = "INSERT INTO GanttData (`TaskId`, `TaskName`, `StartDate`, `EndDate`, `Duration`, `Progress`, `ParentId`,`Predecessor`)" +
"VALUES(@TaskId,@TaskName,@StartDate,@EndDate,@Duration,@Progress,@ParentId, @Predecessor)";
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password=yourpassword");//connectionString
con.Open();
//...
con.Close();
}
public GanttData Edit(GanttData Task)
{
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password= yourpassword");//connectionString
con.Open();
string IDNumber = Task.TaskId;
string cmdString = "UPDATE ganttdata SET `TaskId`=@TaskId,`TaskName`=@TaskName,`StartDate`=@StartDate,`EndDate`=@EndDate,`Duration`=@Duration,`Progress`=@Progress,`ParentId`=@ParentId,`Predecessor`=@Predecessor WHERE(TaskId = " + IDNumber + ")";
//...
}
public GanttData Delete(string TaskId)
{
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=ganttdata;password=yourpassword");//connectionString
con.Open();
MySqlCommand cmd = new MySqlCommand("delete from GanttData where TaskId = '" + TaskId + "'", con);
//...
con.Close();
return data; |