protected void btnSave_Click(object sender, EventArgs e)
        {
            CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
            culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
            culture.DateTimeFormat.LongTimePattern = "";
            Thread.CurrentThread.CurrentCulture = culture;

            taskdetails auxNewTaskDetail = new taskdetails();
            taskdetailsBus oTaskDetail = new taskdetailsBus();

            tasks auxTasks = new tasks();
            tasksBus oTasks = new tasksBus();

            users auxUser = new users();
            usersBus oUser = new usersBus();

            eventsdetectionBus oEventsDetection = new eventsdetectionBus();

            bool needRequiredFields = false;
            int saveType = 0;

            if (btnNew.Enabled) saveType = 2;
            if (!btnNew.Enabled) saveType = 1;

            if (String.IsNullOrEmpty(txtDateTime.Text)) needRequiredFields = true;
            if (String.IsNullOrEmpty(txtEffortHours.Text)) needRequiredFields = true;
            if (String.IsNullOrEmpty(txtDetail.Text)) needRequiredFields = true;
            if (String.IsNullOrEmpty(txtTaskId.Text)) needRequiredFields = true;

            if (!needRequiredFields)
            {
                auxUser = oUser.usersGetByUserName(HttpContext.Current.User.Identity.Name);

                DateTime dateTime = DateTime.ParseExact(txtDateTime.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                auxNewTaskDetail.DateTime = dateTime;
                auxNewTaskDetail.EffortHours = Convert.ToDecimal(txtEffortHours.Text);
                auxNewTaskDetail.Details = txtDetail.Text;
                auxNewTaskDetail.TaskId = Convert.ToInt32(txtTaskId.Text);
                auxNewTaskDetail.UserId = Convert.ToInt32(ddlUsers.SelectedValue);
                int auxTaskStatus   = Convert.ToInt32(ddlTaskStatus.SelectedValue);
                int auxUserAssigned = Convert.ToInt32(ddlUsers.SelectedValue);
                switch (saveType)
                {
                    case 1: //save
                        if (oTaskDetail.taskdetailsAdd(auxNewTaskDetail) > 0)
                        {
                            if (!oTasks.tasksUpdateStatus(Convert.ToInt32(txtTaskId.Text), auxTaskStatus ))
                            {
                                lblMessage.Text = "Imposible actualizar nuevo Estado de Tarea...\n";
                            }

                            auxTasks = oTasks.tasksGetById(Convert.ToInt32(txtTaskId.Text));

                            if (!oEventsDetection.eventsdetectionUpdateStatus(auxTasks.EventsDetectionId, auxTaskStatus))
                            {
                                lblMessage.Text = "Imposible actualizar nuevo Estado del Evento de Intrusión...\n";
                            }

                            if (!oTasks.tasksUpdateUser(Convert.ToInt32(txtTaskId.Text), auxUserAssigned))
                            {
                                lblMessage.Text = "Imposible actualizar nuevo Usuario asignado a la Tarea...\n";
                            }

                            clearFields();
                            activateFields(false, true);
                            btnNew.Enabled = true;
                            getTaskDetailsData(TaskId);
                            lblMessage.Text = "Datos guardados correctamente!";
                        }
                        else
                            lblMessage.Text = "Error al guardar los datos!";
                        break;
                    case 2: //update

                        if (Convert.ToInt32(hfTaskStatusOrigin.Value) != auxTaskStatus)
                        {
                            if (!oTasks.tasksUpdateStatus(Convert.ToInt32(txtTaskId.Text), auxTaskStatus ))
                            {
                                lblMessage.Text = "Imposible actualizar nuevo Estado de Tarea...\n";
                            }

                            if (!oEventsDetection.eventsdetectionUpdateStatus(auxTasks.EventsDetectionId, auxTaskStatus))
                            {
                                lblMessage.Text = "Imposible actualizar nuevo Estado del Evento de Intrusión...\n";
                            }
                        }

                        if (Convert.ToInt32(hfUserOrigin.Value) != auxUserAssigned)
                        {
                            if (!oTasks.tasksUpdateUser(Convert.ToInt32(txtTaskId.Text), auxUserAssigned))
                            {
                                lblMessage.Text = "Imposible actualizar nuevo Usuario asignado a la Tarea...\n";
                            }
                        }

                        auxNewTaskDetail.TaskDetailsId = Convert.ToInt32(txtTaskDetailId.Text);

                        if (oTaskDetail.taskdetailsUpdate(auxNewTaskDetail))
                        {
                            lblMessage.Text = "Datos actualizados correctamente!";
                            clearFields();
                            activateFields(false, true);
                            btnSave.Enabled = false;
                            getTaskDetailsData(TaskId);
                            lblMessage.Text = "Datos actualizados correctamente!";
                        }
                        else
                            lblMessage.Text = "Error al guardar los datos!";
                        break;
                }
            }
            else
            {
                lblMessage.Text = "Datos requeridos no cargados...";
            }
        }
        protected void getTaskDetailsData(int taskId)
        {
            DataTable dttTaskDetails = new DataTable();
            dttTaskDetails.Columns.Add(new DataColumn("taskDetailsId", System.Type.GetType("System.Int32")));
            dttTaskDetails.Columns.Add(new DataColumn("taskId", System.Type.GetType("System.Int32")));
            dttTaskDetails.Columns.Add(new DataColumn("taskDetails", System.Type.GetType("System.String")));
            dttTaskDetails.Columns.Add(new DataColumn("datetime", System.Type.GetType("System.DateTime")));
            dttTaskDetails.Columns.Add(new DataColumn("effortHours", System.Type.GetType("System.Decimal")));
            dttTaskDetails.Columns.Add(new DataColumn("userId", System.Type.GetType("System.Int32")));
            dttTaskDetails.Columns.Add(new DataColumn("userName", System.Type.GetType("System.String")));

            List<taskdetails> lstTaskDetails = new List<taskdetails>();
            taskdetailsBus oTaskDetails = new taskdetailsBus();
            usersBus oUsers = new usersBus();

            lstTaskDetails = oTaskDetails.taskdetailsGetByTaskId(taskId);

            if (lstTaskDetails.Count > 0)
            {
                foreach (taskdetails row in lstTaskDetails)
                {
                    users auxUser = new users();
                    auxUser = oUsers.usersGetById(row.UserId);

                    dttTaskDetails.Rows.Add(row.TaskDetailsId,
                                            row.TaskId,
                                            row.Details,
                                            row.DateTime,
                                            row.EffortHours,
                                            row.UserId,
                                            auxUser.UserName);
                }

                gvTaskDetails.DataSource = dttTaskDetails;
                gvTaskDetails.DataBind();
            }
        }