Ejemplo n.º 1
0
        /// <summary>
        /// Returns the update statement to update the specified TaskItem based on the selected view
        /// </summary>
        /// <param name="t"></param>
        /// <param name="vw"></param>
        public static string QueryUpdateTaskEdit(TaskItem t, View vw,
                                            bool bIsAssignedUser, bool bIsManagerUser)
        {

            const string updatefragmentAssigned = "<Method ID='taskid{0}' Cmd='Update'>" +
                                                  "<Field Name='ID'>{0}</Field>" +
                                                  "<Field Name='owshiddenversion'>{1}</Field>" +
                                                  "<Field Name='" + STATUS_COLUMN + "'>{2}</Field>" +
                                                  "<Field Name='" + COMMENTS_COLUMN + "'>{3}</Field>" +
                                                  "<Field Name='" + KPI_COLUMN + "'>{4}</Field>" +
                                                  "<Field Name='" + ALERTTIME_COLUMN + "'>{5}</Field>" +
                                                  "<Field Name='" + ASSIGNTO_COLUMN + "'>{6}</Field>" +
                                                  "<Field Name='" + TIMETOCOMPLETE_COLUMN + "'>{7}</Field>" +
                                                  "<Field Name='" + LATEINCOMPLETE_REASON_COLUMN + "'>{8}</Field>" +
                                                  "<Field Name='" + SYSTEM_OUTRAGE_COLUMN + "'>{9}</Field>" +
                                                  "<Field Name='" + COMPLETEDBY_COLUMN + "'>{10}</Field>" +
                                                  "</Method>";

            const string updatefragmentManaged = "<Method ID='taskid{0}' Cmd='Update'>" +
                                                 "<Field Name='ID'>{0}</Field>" +
                                                 "<Field Name='owshiddenversion'>{1}</Field>" +
                                                 "<Field Name='" + STATUS_COLUMN + "'>{2}</Field>" +
                                                 "<Field Name='" + MANAGEMENT_SIGNOFF_COLUMN + "'>{3}</Field>" +
                //"<Field Name='" + NAME_COLUMN + "'>{4}</Field>" +
                //"<Field Name='" + DESCRIPTION_COLUMN  + "'>{5}</Field>" +
                                                 "<Field Name='" + COMMENTS_COLUMN + "'>{6}</Field>" +
                                                 "<Field Name='" + KPI_COLUMN + "'>{7}</Field>" +
                                                 "<Field Name='" + MATRIX_COLUMN + "'>{8}</Field>" +
                                                 "<Field Name='" + DUEDATE_COLUMN + "'>{9}</Field>" +
                                                 "<Field Name='" + ESCALATIONTIME_COLUMN + "'>{10}</Field>" +
                                                 "<Field Name='" + LINKTOPROCESS_COLUMN + "'>{11}</Field>" +
                                                 "<Field Name='" + ASSIGNTO_COLUMN + "'>{12}</Field>" +
                                                 "<Field Name='" + ALERTTIME_COLUMN + "'>{13}</Field>" + //sep 20
                                                 "<Field Name='" + MANAGER_COLUMN + "'>{14}</Field>" +
                                                 "<Field Name='" + TIMETOCOMPLETE_COLUMN + "'>{15}</Field>" +
                                                 "<Field Name='" + LATEINCOMPLETE_REASON_COLUMN + "'>{16}</Field>" +
                                                 "<Field Name='" + SYSTEM_OUTRAGE_COLUMN + "'>{17}</Field>" +
                                                 "<Field Name='" + COMPLETEDBY_COLUMN + "'>{18}</Field>" +
                                                 "</Method>";

            bool bIsDirectApprove = false;//this variable will be evalated in the next steps
            bool flag = true;
            bool bIsUserCompleting = false;
            string updatestmnt = "";
            if ((t.Status == COMPLETED_STATUS) && (!t.GetOriginalValue("Status").Equals(COMPLETED_STATUS)))
            {
                bIsUserCompleting = true;
            }
            while (flag && bIsUserCompleting)
            {
                flag = false;
                if (t.IsBypassApprovalAllowed)
                {
                    bIsDirectApprove = true;
                    break;
                }
                if ((bIsAssignedUser) && (bIsManagerUser) && (t.IsManagerSelfApprovalAllowed))
                {
                    bIsDirectApprove = true;
                    break;
                }
            }

            if (bIsDirectApprove)
            {
                t.ManagementSignOff = APPROVED_SIGNOFF;
                updatestmnt = string.Format(updatefragmentManaged,
                        t.ID, t.Version, t.Status,
                        t.ManagementSignOff,
                        "", //task name - encoding!
                        "",//description - encoding!
                        "",//comments - encoding!
                        t.Kri,
                        "", //matrix definiton - encoding!
                        t.DueTime, t.EscalationTime,
                        "",//link to process - encoding!
                        "",////Aug 2,use XML encoding for assigned to ,
                        t.AlertTime,
                        "",
                        t.TimeForCompletion,
                        t.LateIncompleteReason,
                        t.SystemOutrage,
                        t.CompletedBy // Jun 2014 for Assignee manager approval verification
                        );
                updatestmnt = InsertEncodedTextInXml(updatestmnt, t);

            }

            if (((vw & View.vwAssignedTasks) > 0) && (bIsDirectApprove == false))
            {
                updatestmnt = string.Format(updatefragmentAssigned,
                        t.ID, t.Version, t.Status, "", t.Kri,
                        t.AlertTime, "", t.TimeForCompletion, t.LateIncompleteReason, t.SystemOutrage, t.CompletedBy
                        );//Aug 2,use XML encoding for assigned to

                updatestmnt = InsertEncodedTextInXml(updatestmnt, t);
            }

            if (((vw & View.vwManagedTasks) > 0) && (bIsDirectApprove == false))
            {
                string status = t.Status;

                /*
                 * if updating as manager
                 * then
                 * update MANAGEMENTSIGNOFF only when user is attempting to udpate this field
                 * if user is attempting to update MANAGEMENTSIGNOFF then update status accordingly
                */
                if (!t.ManagementSignOff.Equals(t.GetOriginalValue("ManagementSignOff")))
                {
                    if (t.ManagementSignOff.Equals(REJECTED_SIGNOFF))
                    {
                        status = IN_PROGRESS_STATUS;
                    }
                    if (t.ManagementSignOff.Equals(APPROVED_SIGNOFF))
                    {
                        status = COMPLETED_STATUS;
                    }
                }

                updatestmnt = string.Format(updatefragmentManaged,
                        t.ID, t.Version, status,
                        t.ManagementSignOff,
                        "", //task name - encoding!
                        "",//description - encoding!
                        "",//comments - encoding!
                        t.Kri,
                        "", //matrix definiton - encoding!
                        t.DueTime, t.EscalationTime,
                        "",//link to process - encoding!
                        "",////Aug 2,use XML encoding for assigned to ,
                        t.AlertTime,
                        "",
                        t.TimeForCompletion,
                        t.LateIncompleteReason,
                        t.SystemOutrage,
                        t.CompletedBy // Jun 2014 for Assignee manager approval verification
                        );
                updatestmnt = InsertEncodedTextInXml(updatestmnt, t);
            }

            var sb = new StringBuilder();
            sb.Append("<Batch OnError='Continue'  ViewName=''>");
            //Add the TaskOwner xml fragment if user is Completing the Task
            if (bIsUserCompleting)
            {
                const string taskownerFragment = "<Field Name='" + TASKOWNER_COLUMN + "'>{0}</Field>";
                string taskownerStmnt = string.Format(taskownerFragment, ViewModel.Current.WssUserId);
                XElement owner = XElement.Parse(taskownerStmnt);
                XElement wss = XElement.Parse(updatestmnt);
                wss.Add(owner);
                updatestmnt = wss.ToString();
            }
            sb.Append(updatestmnt);
            sb.Append("</Batch>");

            return sb.ToString();
        }
Ejemplo n.º 2
0
        public void UpdateTask(TaskItem t)
        {
            try
            {
                //if user trying to approve, then check that the Task is complete, April 26
                if (!t.ManagementSignOff.Equals(t.GetOriginalValue("ManagementSignOff")))
                {
                    if (t.ManagementSignOff.Equals(CamlHelper.APPROVED_SIGNOFF))
                    {
                        if (!t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                        {
                            throw new Exception("The selected Task requires completion before approval");
                        }
                    }
                }
                int role = 0x0; //use bit mask. 0x1=assigned, 0x2=manager

                if (TaskItem.IsUserInAssignedTo(this.wssUserId, t)) role = role | 0x1;//sep 20
                if (TaskItem.IsUserManager(this.wssUserId, t)) role = role | 0x2;//sep 20
                if (role == 0x0)
                {
                    string errormsg = string.Format("The Task '{0}' cannot be udpated because the user is neither an assigned to or a manager", t.TaskName);
                    this.Status.AddToLog(errormsg, false);
                    throw new InvalidOperationException(errormsg);
                }

                ///Added in Jun 2014 for Assignee/Manager Bypas approval verification by Nilav Ghosh
                if (t.CompletedBy != null && t.CompletedBy != "")
                {
                    if (t.CompletedBy == this.wssUserId.ToString())
                    {
                        if (t.IsBypassApprovalAllowed == false && t.IsManagerSelfApprovalAllowed == false)
                        {
                            if (!t.ManagementSignOff.Equals(t.GetOriginalValue("ManagementSignOff")))
                            {
                                if (t.ManagementSignOff.Equals(CamlHelper.APPROVED_SIGNOFF))
                                {
                                    if (t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                                    {
                                        MessageBox.Show("The same who completed the task cannot approve the task as Manager self approval or Bypass Manager approval is not allowed.", bCheckConstants.MSGBOXTITLE, MessageBoxButton.OK);
                                        return;
                                    }
                                    else
                                    {
                                        MessageBox.Show("The selected Task requires completion before approval", bCheckConstants.MSGBOXTITLE, MessageBoxButton.OK);
                                        return;
                                    }
                                }
                            }
                        }
                        if (!t.Status.Equals(t.GetOriginalValue("Status")))
                        {
                            if (t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                            {
                                t.CompletedBy = this.wssUserId.ToString();
                            }
                            else
                            {
                                t.CompletedBy = null;
                            }
                        }
                        this.IsUpdating = true;
                        this.Provider.TaskUpdateCompleteEvent += TaskEditUpdateCompleteEvent;
                        Provider.UpdateTaskItem(t);
                        return;
                    }
                    else
                    {
                        if (!t.ManagementSignOff.Equals(t.GetOriginalValue("ManagementSignOff")))
                        {
                            if (t.ManagementSignOff.Equals(CamlHelper.APPROVED_SIGNOFF))
                            {
                                if (!t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                                {
                                    throw new Exception("The selected Task requires completion before approval");
                                }
                            }
                        }
                        if (!t.Status.Equals(t.GetOriginalValue("Status")))
                        {
                            if (t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                            {
                                t.CompletedBy = this.wssUserId.ToString();
                            }
                            else
                            {
                                t.CompletedBy = null;
                            }
                        }
                        this.IsUpdating = true;
                        this.Provider.TaskUpdateCompleteEvent += TaskEditUpdateCompleteEvent;
                        Provider.UpdateTaskItem(t);
                        return;
                    }
                }
                else
                {
                    if (t.IsBypassApprovalAllowed == false && t.IsManagerSelfApprovalAllowed == false)
                    {
                        if (!t.ManagementSignOff.Equals(t.GetOriginalValue("ManagementSignOff")))
                        {
                            if (t.ManagementSignOff.Equals(CamlHelper.APPROVED_SIGNOFF))
                            {
                                if (t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                                {
                                    MessageBox.Show("The same who completed the task cannot approve the task as Manager self approval or Bypass Manager approval is not allowed.", bCheckConstants.MSGBOXTITLE, MessageBoxButton.OK);
                                    return;
                                }
                                else
                                {
                                    MessageBox.Show("The selected Task requires completion before approval", bCheckConstants.MSGBOXTITLE, MessageBoxButton.OK);
                                    return;
                                }
                            }
                        }
                    }
                    if (!t.Status.Equals(t.GetOriginalValue("Status")))
                    {
                        if (t.Status.Equals(CamlHelper.COMPLETED_STATUS))
                        {
                            t.CompletedBy = this.wssUserId.ToString();
                        }
                        else
                        {
                            t.CompletedBy = null;
                        }
                    }
                    this.IsUpdating = true;
                    this.Provider.TaskUpdateCompleteEvent += TaskEditUpdateCompleteEvent;
                    Provider.UpdateTaskItem(t);
                    return;
                }

#if DEPRECATED_SECURITY_LOGIC
                if ((SelectedView & View.vwCustomSearch) > 0)
                {
                    //this.IsUpdating = true;
                    //this.Provider.TaskUpdateCompleteEvent += new TaskUpdateComplete(TaskEditUpdateCompleteEvent);
                    //this.Provider.UpdateManagedTaskItem(t);
                    //return;


                    //if manager has been specified in custom search, then ensure that the user cannot 
                    //update the Management Sign off field for those tasks where he/she is in the assigned to
                    if (this.SearchParams.Manager.IsResolved)
                    {

                        /*
                         * the Task Edit dialog would have already done a check whether the logged in user is in the 
                         * assigned to list. 
                         * May 28
                         * 
                         */ 
                        //int currentUser = this.wssUserId;
                        //foreach (TaskItem task in this.Tasks.DirtyObjects)
                        //{
        //                if (TaskItem.IsUserInAssignedTo(currentUser, t))
        //                    {
        //                        string unpermittedtaskmsg = string.Format(
        //"The task {0} with with description \"{1}\" cannot be updated due to access restrictions. The logged in user is also an assigned user. Cannot Sign off this task. No tasks will be updated",
        //                                    t.TaskName, t.TaskDescription);
        //                        TaskItemUpdateCompleteEventArgs args = new TaskItemUpdateCompleteEventArgs();
        //                        args.Errors.Add(unpermittedtaskmsg);
        //                        this.TaskUpdateCompleteEvent(this, args);
        //                        return;
        //                    }
                        //}

                        this.IsUpdating = true;
                        this.Provider.TaskUpdateCompleteEvent += new TaskUpdateComplete(TaskEditUpdateCompleteEvent);
                        this.Provider.UpdateManagedTaskItem(t);
                    }
                    else
                    {
                        this.IsUpdating = true;
                        this.Provider.TaskUpdateCompleteEvent += new TaskUpdateComplete(TaskEditUpdateCompleteEvent);
                        this.Provider.UpdateAssignedTaskItem(t);
                    }
                    return;

                }
                System.Diagnostics.Debug.Assert(false, "Invalid view"); 
#endif
            }

            catch (Exception ex)
            {
                IsUpdating = false;
                throw new Exception("Error while updating:\r\n" + ex.Message, ex);
            }
        }