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.
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);
2. Delete
private void ultraGanttView1_TaskDeleting(object sender, TaskDeletingEventArgs e)
TaskDelete(e.Task);
private void TaskDelete(Task task)
command.CommandText = "sp_DeleteTask";
command.Parameters.Add("@TaskID", SqlDbType.UniqueIdentifier);
command.Parameters["@TaskID"].Direction = ParameterDirection.Input;
command.Parameters["@TaskID"].Value = task.Id;
IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", ex.Message, "Грешка 6 в UserInterface", MessageBoxIcon.Error, MessageBoxButtons.OK);
3. Update
private void ultraGanttView1_CellDeactivating(object sender, Infragistics.Win.UltraWinGanttView.CellDeactivatingEventArgs e)
TaskUpdate(e.TaskFieldInfo.Task);
private void TaskUpdate(Task task)
command.CommandText = "sp_UpdateTask";
command.Parameters["@TaskName"].Value = task.Name;
command.Parameters["@TaskStartTime"].Value = task.StartDateTime;
if (task.Parent == null) command.Parameters["@ParentTaskID"].Value = new Guid();
else command.Parameters["@ParentTaskID"].Value = ((Task)task.Parent).Id;
command.Parameters["@TaskPercentComplete"].Value = task.PercentComplete;
command.Parameters["@TaskDuration"].Value = task.Duration.ToString();
IMS_Common.IMSMessageBox.ShowIMSMessageBox("Грешка", ex.Message, "Грешка 5 в UserInterface", MessageBoxIcon.Error, MessageBoxButtons.OK);
Let me know if you have any questions.
Regards
Georgi