Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1310
Insert Task along with the dynamic projectkey
posted

I am using the tablaAdapter model of ganttview. I have a ultracomboeditor listing all the projects, The tasks are displayed, based on the project selected.

I would like to implement insert, update and delete functionality too. On insert, the projectkey should be taken from the value selected from the ultracomboeditor.

Please help on this.

  • 40
    Suggested Answer
    posted

    Hello Jeni,

    I suppose that you are using my previous suggestion and sample.  If so, the easiest way to solve this task is:

    1. You could handle RowSelected event of your UltraComboEditor and implement the code below:

    private void ucProjects_RowSelected(object sender, RowSelectedEventArgs e)

            {

                if (e.Row != null)

                {

                    ultraGanttView1.Enabled = true;

                    ProjectKey = e.Row.Cells["ProjectKey"].Text;

                    dbTasksTableAdapter1.FillByProjectKey(dbDataSetTasks1.dbTasks, ProjectKey);

                }

            }

    where ProjectKey is private static string variable where I keep the current project key from our UltraComboEditor.

    To implement Insert / Delete / Update functionality, I used in my sample three methods/events and stored procedures. For example:

    1. Insert:

    private void ultraGanttView1_TaskAdded(object sender, Infragistics.Win.UltraWinGanttView.TaskAddedEventArgs e)

            {

                SqlConnection connection;

                connection = IMS_Common.LoginForm.sqlConnection;

                if (connection == null)

                {

                    IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", "В момента няма връзка с базата данни. Моля, опитайте по-късно.", "Връзка с база данни", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    return;

                }

                try

                {

                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.CommandType = CommandType.StoredProcedure;

     

                    command.CommandTimeout = Convert.ToInt32(IMS_Common.LoginForm.sqlConnection.ConnectionTimeout);

                    command.CommandText = "sp_CreateNewTask";

     

                    command.Parameters.Add("@ProjectKey", SqlDbType.NVarChar);

                    command.Parameters["@ProjectKey"].Direction = ParameterDirection.Input;

                    command.Parameters["@ProjectKey"].Value = ProjectKey;// e.Task.ProjectKey;

     

                    command.Parameters.Add("@TaskName", SqlDbType.NVarChar);

                    command.Parameters["@TaskName"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskName"].Value = e.Task.Name;

     

                    command.Parameters.Add("@TaskStartTime", SqlDbType.DateTime);

                    command.Parameters["@TaskStartTime"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskStartTime"].Value = e.Task.StartDateTime;

     

                    command.Parameters.Add("@ParentTaskID", SqlDbType.UniqueIdentifier);

                    command.Parameters["@ParentTaskID"].Direction = ParameterDirection.Input;

                    if (e.Task.Parent == null) command.Parameters["@ParentTaskID"].Value = new Guid();// DBNull.Value;

                    else command.Parameters["@ParentTaskID"].Value = ((Task)e.Task.Parent).Id;

     

                    command.Parameters.Add("@TaskPercentComplete", SqlDbType.Int);

                    command.Parameters["@TaskPercentComplete"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskPercentComplete"].Value = e.Task.PercentComplete;

     

                    // TO DO

                    //command.Parameters.Add("@AllProperties", SqlDbType.VarBinary,1024);

                    //command.Parameters["@AllProperties"].Direction = ParameterDirection.Input;

                    //command.Parameters["@AllProperties"].Value = null;

     

                    command.Parameters.Add("@TaskDuration", SqlDbType.NVarChar, 50);

                    command.Parameters["@TaskDuration"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskDuration"].Value = e.Task.Duration.ToString();

     

     

                    command.Parameters.Add("@iErrorIsn", SqlDbType.Int);

                    command.Parameters["@iErrorIsn"].Direction = ParameterDirection.Output;

                    command.Parameters.Add("@sMessageHeader", SqlDbType.NVarChar, 50);

                    command.Parameters["@sMessageHeader"].Direction = ParameterDirection.Output;

                    command.Parameters.Add("@sMessage", SqlDbType.NVarChar, 512);

                    command.Parameters["@sMessage"].Direction = ParameterDirection.Output;

     

                    command.ExecuteNonQuery();

                    connection.Close();

     

                    if (Convert.ToInt32(command.Parameters["@iErrorIsn"].Value) > 0)

                    {

                        IMS_Common.IMSMessageBox.ShowIMSMessageBox(Convert.ToString(command.Parameters["@sMessageHeader"].Value), Convert.ToString(command.Parameters["@sMessage"].Value), "Грешка " + Convert.ToInt32(command.Parameters["@iErrorIsn"].Value).ToString() + " в Базата данни.", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    }

     

                }

                catch (Exception ex)

                {

                    IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", ex.Message, "Грешка 2 в UserInterface", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    connection.Close();

                }

            }

    2. Delete

    private void ultraGanttView1_TaskDeleting(object sender, TaskDeletingEventArgs e)

            {

                TaskDelete(e.Task);

            }

    private void TaskDelete(Task task)

            {

                SqlConnection connection;

                connection = IMS_Common.LoginForm.sqlConnection;

                if (connection == null)

                {

                    IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", "В момента няма връзка с базата данни. Моля, опитайте по-късно.", "Връзка с база данни", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    return;

                }

                try

                {

                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.CommandType = CommandType.StoredProcedure;

     

                    command.CommandTimeout = Convert.ToInt32(IMS_Common.LoginForm.sqlConnection.ConnectionTimeout);

                    command.CommandText = "sp_DeleteTask";

     

                    command.Parameters.Add("@TaskID", SqlDbType.UniqueIdentifier);

                    command.Parameters["@TaskID"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskID"].Value = task.Id;

     

                    command.Parameters.Add("@iErrorIsn", SqlDbType.Int);

                    command.Parameters["@iErrorIsn"].Direction = ParameterDirection.Output;

                    command.Parameters.Add("@sMessageHeader", SqlDbType.NVarChar, 50);

                    command.Parameters["@sMessageHeader"].Direction = ParameterDirection.Output;

                    command.Parameters.Add("@sMessage", SqlDbType.NVarChar, 512);

                    command.Parameters["@sMessage"].Direction = ParameterDirection.Output;

     

                    command.ExecuteNonQuery();

                    connection.Close();

     

                    if (Convert.ToInt32(command.Parameters["@iErrorIsn"].Value) > 0)

                    {

                        IMS_Common.IMSMessageBox.ShowIMSMessageBox(Convert.ToString(command.Parameters["@sMessageHeader"].Value), Convert.ToString(command.Parameters["@sMessage"].Value), "Грешка " + Convert.ToInt32(command.Parameters["@iErrorIsn"].Value).ToString() + " в Базата данни.", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    }

     

                }

                catch (Exception ex)

                {

                    IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", ex.Message, "Грешка 6 в UserInterface", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    connection.Close();

                }

     

            }

    3. Update

    private void ultraGanttView1_CellDeactivating(object sender, Infragistics.Win.UltraWinGanttView.CellDeactivatingEventArgs e)

            {

                TaskUpdate(e.TaskFieldInfo.Task);

            }

    private void TaskUpdate(Task task)

            {

                SqlConnection connection;

                connection = IMS_Common.LoginForm.sqlConnection;

                if (connection == null)

                {

                    IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", "В момента няма връзка с базата данни. Моля, опитайте по-късно.", "Връзка с база данни", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    return;

                }

                try

                {

                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.CommandType = CommandType.StoredProcedure;

     

                    command.CommandTimeout = Convert.ToInt32(IMS_Common.LoginForm.sqlConnection.ConnectionTimeout);

                    command.CommandText = "sp_UpdateTask";

     

                    command.Parameters.Add("@TaskID", SqlDbType.UniqueIdentifier);

                    command.Parameters["@TaskID"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskID"].Value = task.Id;

     

                    command.Parameters.Add("@TaskName", SqlDbType.NVarChar);

                    command.Parameters["@TaskName"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskName"].Value = task.Name;

     

                    command.Parameters.Add("@TaskStartTime", SqlDbType.DateTime);

                    command.Parameters["@TaskStartTime"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskStartTime"].Value = task.StartDateTime;

     

                    command.Parameters.Add("@ParentTaskID", SqlDbType.UniqueIdentifier);

                    command.Parameters["@ParentTaskID"].Direction = ParameterDirection.Input;

                    if (task.Parent == null) command.Parameters["@ParentTaskID"].Value = new Guid();

                    else command.Parameters["@ParentTaskID"].Value = ((Task)task.Parent).Id;

     

                    command.Parameters.Add("@TaskPercentComplete", SqlDbType.Int);

                    command.Parameters["@TaskPercentComplete"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskPercentComplete"].Value = task.PercentComplete;

     

                    // TO DO

                    //command.Parameters.Add("@AllProperties", SqlDbType.VarBinary,1024);

                    //command.Parameters["@AllProperties"].Direction = ParameterDirection.Input;

                    //command.Parameters["@AllProperties"].Value = null;

     

                    command.Parameters.Add("@TaskDuration", SqlDbType.NVarChar, 50);

                    command.Parameters["@TaskDuration"].Direction = ParameterDirection.Input;

                    command.Parameters["@TaskDuration"].Value = task.Duration.ToString();

     

     

                    command.Parameters.Add("@iErrorIsn", SqlDbType.Int);

                    command.Parameters["@iErrorIsn"].Direction = ParameterDirection.Output;

                    command.Parameters.Add("@sMessageHeader", SqlDbType.NVarChar, 50);

                    command.Parameters["@sMessageHeader"].Direction = ParameterDirection.Output;

                    command.Parameters.Add("@sMessage", SqlDbType.NVarChar, 512);

                    command.Parameters["@sMessage"].Direction = ParameterDirection.Output;

     

                    command.ExecuteNonQuery();

                    connection.Close();

     

                    if (Convert.ToInt32(command.Parameters["@iErrorIsn"].Value) > 0)

                    {

                        IMS_Common.IMSMessageBox.ShowIMSMessageBox(Convert.ToString(command.Parameters["@sMessageHeader"].Value), Convert.ToString(command.Parameters["@sMessage"].Value), "Грешка " + Convert.ToInt32(command.Parameters["@iErrorIsn"].Value).ToString() + " в Базата данни.", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    }

     

                }

                catch (Exception ex)

                {

                    IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", ex.Message, "Грешка 5 в UserInterface", MessageBoxIcon.Error, MessageBoxButtons.OK);

                    connection.Close();

                }

     

            }

    Let me know if you have any questions.

    Regards

    Georgi

  • 23930
    Offline posted

    Hello Jeni,

    I am just checking about the progress of this issue. Let me know if you need my further assistance on this issue.

    Thank you for using Infragistics Components.

  • 23930
    Offline posted

    Hello Jenni,

    Thank you for contacting Infragistics Developer Support.

    If you create a task in the GanttView it will automatically become associated with the current project. So what you could do in this case is to use the Update method of the TableAdapter. This way the task will be automatically saved to the current project.

    I have implemented a sample which uses a local database in order to demonstrate this approach. In the archive I have also added a video showing how the application works.

    Please let me know if you have any additional questions.

    WGV_MultipleProjects.zip