We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Update predecessor after deleting

Thread ID:

Created:

Updated:

Platform:

Replies:

118088 Jan 30,2015 04:16 PM UTC Feb 2,2015 01:58 PM UTC ASP.NET Web Forms 1
loading
Tags: Gantt
Otto Moura Machado Filho
Asked On January 30, 2015 04:16 PM UTC

Hi,

How can I update my predecessor field on database when I delete a row that has a reference in another row. It updates on gantt but don't fire a edit event for exemple, only the "delete event".

Regards,
Otto Machado.

John Rajaram [Syncfusion]
Replied On February 2, 2015 01:58 PM UTC

Hi Otto,

We can update our predecessor field of the reference rows that connected with deleted task item to the database by retrieving the corresponding updated TaskId and Predecessor values of the rows from the Gantt data source and it can be updated to the database with the help of AJAX POST method in the controller.

Please refer the below code snippets for more details.

Code snippets:

In Index.cshtml:

@(Html.EJ().Gantt("Gantt").

         

//...

ClientSideEvents(eve =>

       {

           eve.ActionComplete("ActionComplete");          

       }).

       Datasource(ViewBag.dataSource)

    )

@(Html.EJ().ScriptManager())

<script type="text/javascript">

     function ActionComplete(args) {

            //...

      else if (args.requestType === 'delete') {

               // To delete a Task item

                var ganttRec = args.data.item;

                $.ajax({

                    type: "POST",

                    url: "/Gantt/Delete",  //Update is Server side method

                    data: ganttRec,

                    dataType: "json",                  

                });

               // To update the predecessors of the reference rows

                if (args.data.predecessor) {

                    var param = [], datalinks,links, j = 0;

                    for (var i = 0; i < args.data.predecessor.length; i++) {

                        if (args.data.predecessor[i].to != args.data.taskId) {

                            var updateId = args.data.predecessor[i].to;

                            for (var k = 0; k < args.model.dataSource.length; k++) {

                                if (updateId == args.model.dataSource[k].TaskId) {

                                    var links = args.model.dataSource[k].Predecessor;

                                    param[j] = {

                                        linkId: updateId,

                                        linkString: links

                                    };

                                    j++;

                                }

                            }

                        }

                    }

                }

                $.ajax({

                    contentType: 'application/json; charset=utf-8',

                    type: "POST",

                    url: "/Gantt/UpdatePredecessors",  //Update is Server side method

                    data: param,

                    dataType: "json",

                });

            }   

      

In GanttController.cs:

public class GanttController : Controller

    {

       //...

     [HttpPost()]

        public void UpdatePredecessors(List<TaskLinks> Items)

        {

            connectionString = string.Format(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + Server.MapPath("App_Data") + @"\GanttDatabase2008.mdf;Integrated Security=True;Connect Timeout=30");

          

            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString

            con.Open();

            for (int i = 0; i < Items.Count; i++)

            {

                int IDNumber = Items[i].LinkId;

                string cmdString = "UPDATE GanttData1 SET Predecessor=@Predecessor WHERE TaskId = '" + IDNumber + "'";

                using (SqlCommand sqlCommand = new SqlCommand(cmdString, con))

                {

                    if (Items[i].LinkString == null)

                    {

                        sqlCommand.Parameters.AddWithValue("@Predecessor", Items[i].LinkString).Value = "";

                    }

                    else

                    {

                        sqlCommand.Parameters.AddWithValue("@Predecessor", Items[i].LinkString);

                    }

                    sqlCommand.ExecuteNonQuery();

                }

            }

                con.Close();

         

        }

    }

 

Please let us know if you require further assistance on this.

Regards,
John. R



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;