//save a task according add a new one or update the existing one. if task name, description, assign to, status, startdate,duedate ,completedate all same then update it else add a new one private void saveTask_Click(object sender, RoutedEventArgs e) { String strReturn = ""; strReturn = checkIfAddOrUpdate(); if (checkAllTexts()) { TaskManagement taskMgt = new TaskManagement(); String txtName = taskName.Text.Trim(); String txtDesc = taskDescription.Text.Trim(); String txtAssignTo = taskAssignTo.Text.Trim(); String cmbStatus = status.Text; DateTime?dtStartDate = startDate.SelectedDate; DateTime?dtDuedate = dueDate.SelectedDate; DateTime?dtCompleteDate = completeDate.SelectedDate; if (strReturn == "insert") { String txtCreateBy = Environment.UserName; DateTime dtCreateDate = DateTime.Now; taskMgt.AddTask(txtName, txtDesc, dtStartDate, dtDuedate, dtCompleteDate, txtAssignTo, cmbStatus, txtCreateBy, dtCreateDate); } if (strReturn == "update") { String txtTaskID = taskID.Text.Trim(); String txtUpdateBy = Environment.UserName; DateTime dtUpdateDate = DateTime.Now; Boolean updateDone = taskMgt.UpdateTask(Int32.Parse(txtTaskID), txtName, txtDesc, dtStartDate, dtDuedate, dtCompleteDate, txtAssignTo, cmbStatus, txtUpdateBy, dtUpdateDate); if (updateDone) { MessageBox.Show("Update is done!", "Message"); } } isLoading = true; PopulateTasks(false); isLoading = false; datagridTask.Items.Refresh(); } }