public List<taskdetails> taskdetailsGetAll()
 {
     List<taskdetails> lsttaskdetails = new List<taskdetails>();
     try
     {
         DataTable dt = SqlHelper.ExecuteDataset(SqlImplHelper.getConnectionString(), "taskdetailsGetAll").Tables[0];
         if (dt.Rows.Count > 0)
         {
             int colTaskDetailsId =  dt.Columns["TaskDetailsId"].Ordinal;
             int colTaskId =  dt.Columns["TaskId"].Ordinal;
             int colDetails =  dt.Columns["Details"].Ordinal;
             int colDateTime =  dt.Columns["DateTime"].Ordinal;
             int colEffortHours =  dt.Columns["EffortHours"].Ordinal;
             int colUserId = dt.Columns["UserId"].Ordinal;
             for (int i = 0; dt.Rows.Count > i; i++)
             {
                 taskdetails NewEnt = new taskdetails();
                 NewEnt.TaskDetailsId = Int32.Parse(dt.Rows[i].ItemArray[colTaskDetailsId].ToString());
                 NewEnt.TaskId = Int32.Parse(dt.Rows[i].ItemArray[colTaskId].ToString());
                 NewEnt.Details = dt.Rows[i].ItemArray[colDetails].ToString();
                 NewEnt.DateTime = DateTime.Parse(dt.Rows[i].ItemArray[colDateTime].ToString());
                 NewEnt.EffortHours = Decimal.Parse(dt.Rows[i].ItemArray[colEffortHours].ToString());
                 NewEnt.UserId = Int32.Parse(dt.Rows[i].ItemArray[colUserId].ToString());
                 lsttaskdetails.Add(NewEnt);
             }
         }
         return lsttaskdetails;
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
 public int taskdetailsAdd( taskdetails taskdetails)
 {
     try
     {
         return (int)SqlHelper.ExecuteScalar(SqlImplHelper.getConnectionString(), "taskdetailsAdd",
                                                                                 taskdetails.TaskId,
                                                                                 taskdetails.Details,
                                                                                 taskdetails.DateTime,
                                                                                 taskdetails.EffortHours,
                                                                                 taskdetails.UserId);
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
 public bool taskdetailsUpdate(taskdetails taskdetails)
 {
     taskdetailsImpl otaskdetailsImpl = new taskdetailsImpl();
     return otaskdetailsImpl.taskdetailsUpdate( taskdetails);
 }
 public int taskdetailsAdd(taskdetails taskdetails)
 {
     taskdetailsImpl otaskdetailsImpl = new taskdetailsImpl();
     return otaskdetailsImpl.taskdetailsAdd( taskdetails);
 }
        public taskdetails taskdetailsGetById(int TaskDetailsId)
        {
            try
            {
                DataTable dt = SqlHelper.ExecuteDataset(SqlImplHelper.getConnectionString(), "taskdetailsGetById",
                                                                                                TaskDetailsId).Tables[0];
                taskdetails NewEnt = new taskdetails();

                if(dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    NewEnt.TaskDetailsId = Int32.Parse(dr["TaskDetailsId"].ToString());
                    NewEnt.TaskId = Int32.Parse(dr["TaskId"].ToString());
                    NewEnt.Details = dr["Details"].ToString();
                    NewEnt.DateTime = DateTime.Parse(dr["DateTime"].ToString());
                    NewEnt.EffortHours = Decimal.Parse(dr["EffortHours"].ToString());
                    NewEnt.UserId = Int32.Parse(dr["UserId"].ToString());
                }
                return NewEnt;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
 public bool taskdetailsUpdate( taskdetails taskdetails)
 {
     try
     {
         int update = (int)SqlHelper.ExecuteScalar(SqlImplHelper.getConnectionString(), "taskdetailsUpdate",
                                                                                     taskdetails.TaskDetailsId,
                                                                                     taskdetails.TaskId,
                                                                                     taskdetails.Details,
                                                                                     taskdetails.DateTime,
                                                                                     taskdetails.EffortHours,
                                                                                     taskdetails.UserId);
         if (update > 0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
        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...";
            }
        }