Пример #1
0
        private void SetTaskToUI(PTTask myTask)
        {
            if (myTask != null)
            {
                txtTaskTitle.Text = myTask.Title;
                txtTaskNote.Text  = myTask.Notes;
                txtDueDate.Text   = myTask.DueDate != null?Convert.ToDateTime(myTask.DueDate).ToShortDateString() : "";

                ddlAssignTo.SelectedValue = myTask.BiostatId.ToString();

                ddlTaskStatus.ClearSelection();
                if (myTask.TaskStatus != null)
                {
                    var status = ddlTaskStatus.Items.FindByText(myTask.TaskStatus);
                    if (status != null)
                    {
                        status.Selected = true;
                    }
                }

                ddlTaskPriority.ClearSelection();
                if (myTask.TaskPriority != null)
                {
                    var status = ddlTaskPriority.Items.FindByText(myTask.TaskPriority);
                    if (status != null)
                    {
                        status.Selected = true;
                    }
                }
            }
        }
Пример #2
0
        private void ClearEditForm()
        {
            PTTask ptTask = new PTTask();

            ptTask.Id        = -1;
            ptTask.ProjectId = -1;
            ptTask.BiostatId = -1;
            //ptTask.DueDate = null;

            BindTask(ptTask);

            BindTaskHistory(0);
        }
Пример #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int taskId = 0;

            Int32.TryParse(lblTaskId.Text, out taskId);

            PTTask myTask = GetTaskFromUI(taskId);

            taskId = SaveTask(myTask);

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                    "ModalScript", PageUtility.LoadEditScript(false), false);

            BindTaskAll();
        }
Пример #4
0
        private PTTask GetTaskFromUI(int taskId)
        {
            DateTime dt;
            int      ddlValue;
            PTTask   myTask = new PTTask()
            {
                Id           = taskId,
                BiostatId    = Int32.TryParse(ddlAssignTo.SelectedValue, out ddlValue) ? ddlValue : -1,
                ProjectId    = -1,
                TaskStatus   = ddlTaskStatus.SelectedItem.Text,
                TaskPriority = ddlTaskPriority.SelectedItem.Text,
                DueDate      = DateTime.TryParse(txtDueDate.Text, out dt) ? dt : DateTime.Now,
                Title        = txtTaskTitle.Text,
                Notes        = txtTaskNote.Text,
                Creator      = Page.User.Identity.Name,
                CreateDate   = DateTime.Now
            };

            return(myTask);
        }
Пример #5
0
        private void BindTask(PTTask ptTask)
        {
            if (ptTask != null)
            {
                lblTaskId.Text    = ptTask.Id > 0 ? ptTask.Id.ToString() : string.Empty;
                txtTaskTitle.Text = ptTask.Title;
                txtTaskNote.Text  = ptTask.Notes;
                txtDueDate.Text   = ptTask.DueDate != null?Convert.ToDateTime(ptTask.DueDate).ToShortDateString() : "";

                if (ptTask.BiostatId > 0)
                {
                    ddlAssignTo.SelectedValue = ptTask.BiostatId.ToString();
                }
                else
                {
                    ddlAssignTo.ClearSelection();
                }

                ddlTaskStatus.ClearSelection();
                if (ptTask.TaskStatus != null)
                {
                    var taskStatus = ddlTaskStatus.Items.FindByText(ptTask.TaskStatus);
                    if (taskStatus != null)
                    {
                        taskStatus.Selected = true;
                    }
                }

                ddlTaskPriority.ClearSelection();
                if (ptTask.TaskPriority != null)
                {
                    var taskPriority = ddlTaskPriority.Items.FindByText(ptTask.TaskPriority);
                    if (taskPriority != null)
                    {
                        taskPriority.Selected = true;
                    }
                }
            }
        }
Пример #6
0
        protected void rptTask_ItemCommand(Object sender, RepeaterCommandEventArgs e)
        {
            if (((Button)e.CommandSource).Text.Equals("Edit"))
            {
                lblTaskId.Text = ((Button)e.CommandSource).CommandArgument;

                int taskId = 0;
                int.TryParse(lblTaskId.Text, out taskId);

                if (taskId > 0)
                {
                    PTTask myTask = GetPTTaskById(taskId);

                    if (myTask != null)
                    {
                        BindEditModal(myTask);

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                                "ModalScript", PageUtility.LoadEditScript(true), false);
                    }
                }
            }
        }
Пример #7
0
        private void BindEditModal(PTTask myTask)
        {
            SetTaskToUI(myTask);

            BindTaskHistory(myTask.Id);
        }
Пример #8
0
        private int SaveTask(PTTask myTask)
        {
            using (ProjectTrackerContainer db = new ProjectTrackerContainer())
            {
                if (myTask.Id > 0) //update
                {
                    var prevTask = db.PTTasks.FirstOrDefault(t => t.Id == myTask.Id);

                    if (prevTask != null)
                    {
                        //create a history
                        StringBuilder sb = new StringBuilder();

                        if (prevTask.BiostatId != myTask.BiostatId)
                        {
                            sb.AppendFormat("Assign To: {0}; ", prevTask.BioStat.Name);
                        }

                        if (prevTask.TaskStatus != myTask.TaskStatus)
                        {
                            sb.AppendFormat("Status: {0}; ", prevTask.TaskStatus);
                        }

                        if (prevTask.TaskPriority != myTask.TaskPriority)
                        {
                            sb.AppendFormat("Priority: {0}", prevTask.TaskPriority);
                        }

                        if (prevTask.Notes != myTask.Notes)
                        {
                            sb.AppendFormat("Note: {0}", prevTask.Notes);
                        }

                        if (!sb.ToString().Equals(string.Empty))
                        {
                            TaskHistory taskHistory = new TaskHistory()
                            {
                                TaskId     = prevTask.Id,
                                TaskValue  = sb.ToString(),
                                Creator    = Page.User.Identity.Name,
                                CreateDate = DateTime.Now
                            };

                            db.TaskHistories.Add(taskHistory);

                            BindTaskHistory(myTask.Id);
                        }

                        db.Entry(prevTask).CurrentValues.SetValues(myTask);
                    }
                }
                else //new
                {
                    db.PTTasks.Add(myTask);
                }

                db.SaveChanges();
            }

            return(myTask.Id);
        }