protected override void OnInit(EventArgs e)
        {
            try
            {
                base.OnInit(e);

                if (!DelegationPermissionManager.DoesCurrentEmployeeHasDelegationPermission())
                {
                    SPUtility.HandleAccessDenied(new Exception(ResourceHelper.GetLocalizedString("AccessDeniedMessage", StringConstant.ResourcesFileWebPages, CultureInfo.CurrentUICulture.LCID)));
                }

                // Language
                this.isVietnameseLanguage = Page.LCID == PageLanguages.Vietnamese ? true : false;

                // Initialize objects
                InitObjects();

                // Initialize events
                InitEvents();

                // Initialize controls
                InitControls();
            }
            catch (Exception ex)
            {
                ULSLogging.LogError(ex);
            }
        }
示例#2
0
        public Delegation GetDelegatedTaskInfo(string Id)
        {
            Delegation delegation = new Delegation(null);

            int listItemId = 0;

            if (int.TryParse(Id, out listItemId))
            {
                string[] viewFields = new string[] { StringConstant.ChangeShiftList.DHField, StringConstant.CommonSPListField.ApprovalStatusField,
                                                     StringConstant.CommonSPListField.CommonDepartmentField };
                string queryStr = $@"<Where>
                                      <Eq>
                                         <FieldRef Name='ID' />
                                         <Value Type='Counter'>{listItemId}</Value>
                                      </Eq>
                                   </Where>";
                List <Biz.Models.ChangeShiftManagement> changeShiftManagementCollection = this.GetByQuery(queryStr, viewFields);
                if (changeShiftManagementCollection != null && changeShiftManagementCollection.Count > 0)
                {
                    Biz.Models.ChangeShiftManagement changeShiftManagement = changeShiftManagementCollection[0];

                    EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(this.SiteUrl);
                    EmployeeInfo    currentApprover  = _employeeInfoDAL.GetByADAccount(changeShiftManagement.DepartmentHead.ID);
                    if (currentApprover != null)
                    {
                        delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.ChangeShiftList.ListUrl, changeShiftManagement.ID);
                    }
                }
            }

            return(delegation);
        }
示例#3
0
        private bool IsDelegationNotApprovedYet(Delegation delegation, int currentUserInfoId, SPWeb web)
        {
            var isDelegationNotApprovedYet = false;

            string listUrl     = delegation.ListUrl;
            int    itemId      = delegation.ListItemID;
            var    queryString = $"<Where><Eq><FieldRef Name='ID'></FieldRef><Value Type='Integer'>{itemId.ToString(CultureInfo.InvariantCulture)}</Value></Eq></Where>";
            SPList list        = web.GetList(string.Format("{0}{1}", this.SiteUrl, listUrl));
            var    query       = new SPQuery {
                Query = queryString
            };
            var results = list.GetItems(query);

            if (results != null && results.Count > 0)
            {
                int fromEmployeeId    = 0;
                var delegatedEmployee = DelegationManager.GetCurrentEmployeeProcessing(listUrl, results[0], web);
                if (delegatedEmployee != null)
                {
                    fromEmployeeId = delegatedEmployee.LookupId;
                }
                if (fromEmployeeId > 0)
                {
                    var isDelegation = DelegationPermissionManager.IsDelegation(fromEmployeeId, currentUserInfoId, listUrl, itemId, this.SiteUrl);
                    if (isDelegation != null)
                    {
                        isDelegationNotApprovedYet = true;
                    }
                }
                return(isDelegationNotApprovedYet);
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// When have new task, check assignee who has delegation or no. If have, insert into delegations list.
        /// </summary>
        /// <param name="properties">The SPItemEventProperties object.</param>
        private void UpdateDelegationOfNewTask(SPItemEventProperties properties)
        {
            string     listUrl                   = properties.List.RootFolder.ServerRelativeUrl;
            int        taskFromEmployeeId        = 0;
            LookupItem currentEmployeeProcessing = DelegationManager.GetCurrentEmployeeProcessing(listUrl, properties.ListItem, properties.Web);

            if (currentEmployeeProcessing != null)
            {
                taskFromEmployeeId = currentEmployeeProcessing.LookupId;
            }

            if (taskFromEmployeeId > 0)
            {
                string webUrl = properties.WebUrl;
                var    delegationOfNewTasks = DelegationPermissionManager.HasDelegationOfNewTasks(taskFromEmployeeId, listUrl, webUrl);
                if (delegationOfNewTasks != null)
                {
                    foreach (var delegationOfNewTask in delegationOfNewTasks)
                    {
                        try
                        {
                            var delegationListItem = DelegationManager.GetDelegationListItem(listUrl, properties.ListItem, properties.Web);
                            if (delegationListItem != null)
                            {
                                List <int> toEmployeeIds       = delegationOfNewTask.ToEmployee.Select(e => e.LookupId).ToList();
                                bool       isDelegationExisted = DelegationManager.IsDelegationExisted(taskFromEmployeeId, toEmployeeIds, listUrl, properties.ListItemId, delegationOfNewTask.FromDate, delegationOfNewTask.ToDate, properties.Web.Url);
                                if (isDelegationExisted == true)
                                {
                                    return;
                                }

                                delegationListItem.FromDate     = delegationOfNewTask.FromDate;
                                delegationListItem.ToDate       = delegationOfNewTask.ToDate;
                                delegationListItem.FromEmployee = delegationOfNewTask.FromEmployee;
                                delegationListItem.ToEmployee   = delegationOfNewTask.ToEmployee;
                                StringBuilder toEmployeesBuilder = new StringBuilder();
                                foreach (var toEmployee in delegationListItem.ToEmployee)
                                {
                                    toEmployeesBuilder.AppendFormat("{0}; ", toEmployee.LookupValue);
                                }
                                delegationListItem.Title = string.Format("{0} - {1}", delegationListItem.FromEmployee.LookupValue, toEmployeesBuilder.ToString());
                                var delegationsDAL = new DelegationsDAL(webUrl);
                                int id             = delegationsDAL.SaveItem(delegationListItem);
                                if (id <= 0)
                                {
                                    ULSLogging.LogError(new Exception("Updating for new delegation was unsuccessfully."));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ULSLogging.LogError(ex);
                        }
                    }
                }
            }
        }
        //public override void ItemUpdated(SPItemEventProperties properties)
        //{
        //    base.ItemUpdated(properties);
        //    try
        //    {
        //        //_employeeInfoDAL = new EmployeeInfoDAL(properties.WebUrl);
        //        //var itemId = properties.ListItem.ID;
        //        //string modifiedByName = string.Empty;
        //        //var modifiedByString = Convert.ToString(properties.ListItem["Modified By"]);
        //        //SPFieldUser spUserField = (SPFieldUser)properties.ListItem.Fields.GetField("Modified By");
        //        //if (spUserField != null)
        //        //{
        //        //    SPFieldUserValue spNewUserFieldValue = (SPFieldUserValue)spUserField.GetFieldValue(modifiedByString);
        //        //    SPUser spModifiedByUser = properties.Web.EnsureUser(spNewUserFieldValue.LookupValue);
        //        //    var modifiedBy = _employeeInfoDAL.GetByADAccount(spModifiedByUser.ID);
        //        //    modifiedByName = modifiedBy != null ? modifiedBy.FullName : string.Empty;
        //        //}

        //        //SendEmailToApprover(properties.Web, itemId, modifiedByName);
        //    }
        //    catch (Exception ex)
        //    {
        //        ULSLogging.Log(new SPDiagnosticsCategory("STADA -  Shift Management Event Receiver - ItemUpdated fn",
        //            TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
        //        string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
        //    }
        //}

        private void SendEmailToApprover(SPWeb web, int itemId, string modifiedBy = "")
        {
            EmployeeInfoDAL    employeeInfoDAL    = new EmployeeInfoDAL(web.Url);
            EmailTemplateDAL   emailTemplateDAL   = new EmailTemplateDAL(web.Url);
            ShiftManagementDAL shiftManagementDAL = new ShiftManagementDAL(web.Url);

            var shiftManagementItem = shiftManagementDAL.GetByID(itemId);

            if (shiftManagementItem != null)
            {
                SPUser departmentHeadSPUser = web.EnsureUser(shiftManagementItem.ApprovedBy.UserName);

                var departmentHead = employeeInfoDAL.GetByADAccount(departmentHeadSPUser.ID);
                if (departmentHead != null)
                {
                    var requestEmailItem = emailTemplateDAL.GetByKey("ShiftManagement_Request");
                    if (requestEmailItem != null)
                    {
                        string emailBody = HTTPUtility.HtmlDecode(requestEmailItem.MailBody);
                        if (!string.IsNullOrEmpty(departmentHead.Email) && !string.IsNullOrEmpty(emailBody))
                        {
                            string link       = string.Format("{0}/SitePages/ShiftApproval.aspx?itemId={1}&Source={0}/_layouts/15/RBVH.Stada.Intranet.WebPages/ShiftManagement/ShiftManagementManager.aspx", web.Url, shiftManagementItem.ID);
                            var    department = DepartmentListSingleton.GetDepartmentByID(shiftManagementItem.Department.LookupId, web.Url);
                            emailBody = string.Format(emailBody, departmentHead.FullName, string.IsNullOrEmpty(modifiedBy) ? shiftManagementItem.Requester.LookupValue : modifiedBy, shiftManagementItem.Month,
                                                      shiftManagementItem.Year, shiftManagementItem.Department.LookupValue, department.VietnameseName);

                            emailBody = emailBody.Replace("#link", link);
                            _sendMailActivity.SendMail(web.Url, requestEmailItem.MailSubject, departmentHead.Email, true, false, emailBody);

                            List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(web.Url, departmentHead.ID, StringConstant.ShiftManagementList.ListUrl, shiftManagementItem.ID);
                            link = string.Format("{0}/SitePages/ShiftApproval.aspx?subSection=ShiftManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", web.Url, shiftManagementItem.ID);
                            if (toUsers != null)
                            {
                                foreach (var toUser in toUsers)
                                {
                                    try
                                    {
                                        if (!string.IsNullOrEmpty(toUser.Email))
                                        {
                                            emailBody = HTTPUtility.HtmlDecode(requestEmailItem.MailBody);
                                            emailBody = string.Format(emailBody, toUser.FullName, string.IsNullOrEmpty(modifiedBy) ? shiftManagementItem.Requester.LookupValue : modifiedBy, shiftManagementItem.Month,
                                                                      shiftManagementItem.Year, shiftManagementItem.Department.LookupValue, department.VietnameseName);
                                            emailBody = emailBody.Replace("#link", link);
                                            _sendMailActivity.SendMail(web.Url, requestEmailItem.MailSubject, toUser.Email, true, false, emailBody);
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                }
            }
        }
        public bool SendDelegationNotOverTimeRequestEmail(string notOvertimeItemId, string toRole)
        {
            try
            {
                int idValue;
                if (int.TryParse(notOvertimeItemId, out idValue))
                {
                    var notOvertimeManagementItem  = _notOvertimeMangementDAL.GetByID(idValue);
                    var notOvertimeRequestMailItem = _emailTemplateDAL.GetByKey("LOAbsence_Request");
                    if (notOvertimeRequestMailItem != null && notOvertimeManagementItem != null)
                    {
                        var    siteUrl = SPContext.Current.Site.Url;
                        string link    = string.Format(@"{0}/_layouts/15/RBVH.Stada.Intranet.WebPages/LeaveOfAbsenceManagement/LeaveOfAbsenceApprovalDelegation.aspx?itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", siteUrl, notOvertimeManagementItem.ID);

                        var dhUser = _employeeDAL.GetByADAccount(notOvertimeManagementItem.DH.ID);
                        List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteUrl, dhUser.ID, StringConstant.NotOvertimeList.ListUrl, notOvertimeManagementItem.ID);

                        if (toUsers != null)
                        {
                            foreach (var toUser in toUsers)
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(toUser.Email))
                                    {
                                        string emailBody = HTTPUtility.HtmlDecode(notOvertimeRequestMailItem.MailBody);
                                        emailBody = string.Format(emailBody, toUser.FullName, notOvertimeManagementItem.Requester.LookupValue,
                                                                  notOvertimeManagementItem.Date.ToString(StringConstant.DateFormatddMMyyyy2),
                                                                  notOvertimeManagementItem.Reason);
                                        emailBody = emailBody.Replace("#link", link);
                                        _sendMailActivity.SendMail(SPContext.Current.Web.Url, notOvertimeRequestMailItem.MailSubject, toUser.Email, true, false, emailBody);
                                    }
                                }
                                catch { }
                            }
                        }

                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendDelegationNotOverTimeRequestEmail fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
                return(false);
            }
        }
示例#7
0
        public DelegationModel GetDelegatedTaskInfo(string Id)
        {
            DelegationModel delegationModel = new DelegationModel();

            int listItemId = 0;

            if (int.TryParse(Id, out listItemId))
            {
                string[] viewFields = new string[] { StringConstant.BusinessTripManagementList.Fields.DH, StringConstant.BusinessTripManagementList.Fields.DirectBOD,
                                                     StringConstant.BusinessTripManagementList.Fields.BOD, StringConstant.BusinessTripManagementList.Fields.AdminDept,
                                                     StringConstant.CommonSPListField.ApprovalStatusField, StringConstant.CommonSPListField.CommonDepartmentField, CommonSPListField.CommonLocationField };
                string queryStr = $@"<Where>
                                      <Eq>
                                         <FieldRef Name='ID' />
                                         <Value Type='Counter'>{listItemId}</Value>
                                      </Eq>
                                   </Where>";
                string siteUrl  = SPContext.Current.Site.Url;
                List <Biz.Models.BusinessTripManagement> businessTripManagementCollection = _businessTripManagementDAL.GetByQuery(queryStr, viewFields);
                if (businessTripManagementCollection != null && businessTripManagementCollection.Count > 0)
                {
                    EmployeeInfo currentApprover = null;
                    Biz.Models.BusinessTripManagement businessTripManagement = businessTripManagementCollection[0];
                    StepManagementDAL _stepManagementDAL = new StepManagementDAL(siteUrl);
                    var currentStep = _stepManagementDAL.GetStepManagement(businessTripManagement.ApprovalStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                    if (currentStep != null)
                    {
                        currentApprover = _businessTripManagementDAL.GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, currentStep.StepNumber);
                    }

                    if (currentApprover != null)
                    {
                        Delegation delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.BusinessTripManagementList.Url, businessTripManagement.ID);
                        delegationModel = new DelegationModel(delegation);
                    }
                }
            }

            return(delegationModel);
        }
        public override void ItemAdded(SPItemEventProperties properties)
        {
            try
            {
                base.ItemAdded(properties);

                var siteURL = properties.WebUrl;
                var vehicleManagementDAL = new VehicleManagementDAL(siteURL);
                var ItemID      = properties.ListItemId;
                var currentItem = vehicleManagementDAL.GetByID(ItemID);

                taskManagementDAL = new TaskManagementDAL(siteURL);
                TaskManagement taskManagement = new TaskManagement();
                taskManagement.StartDate       = DateTime.Now;
                taskManagement.DueDate         = currentItem.RequestDueDate;
                taskManagement.PercentComplete = 0;
                taskManagement.ItemId          = currentItem.ID;
                taskManagement.ItemURL         = properties.List.DefaultDisplayFormUrl + "?ID=" + properties.ListItemId;
                taskManagement.ListURL         = properties.List.DefaultViewUrl;
                taskManagement.TaskName        = TASK_NAME;
                taskManagement.TaskStatus      = TaskStatusList.InProgress;
                taskManagement.StepModule      = StepModuleList.VehicleManagement.ToString();
                taskManagement.Department      = currentItem.CommonDepartment;
                taskManagement.AssignedTo      = currentItem.DepartmentHead;

                employeeInfoDAL = new EmployeeInfoDAL(siteURL);
                EmployeeInfo requesterInfo = employeeInfoDAL.GetByID(currentItem.Requester.LookupId);

                if ((int)Convert.ToDouble(requesterInfo.EmployeeLevel.LookupValue, CultureInfo.InvariantCulture.NumberFormat) == (int)StringConstant.EmployeeLevel.DepartmentHead)
                {
                    taskManagement.StepStatus = StepStatusList.BODApproval;
                }
                else
                {
                    taskManagement.StepStatus = StepStatusList.DHApproval;
                }

                DepartmentDAL _departmentDAL = new DepartmentDAL(siteURL);
                Department    departmentHR   = _departmentDAL.GetByCode("HR");
                if (departmentHR.ID == currentItem.CommonDepartment.LookupId)
                {
                    taskManagement.NextAssign = null;
                }
                else
                {
                    EmployeeInfo deptHeadOfHR = employeeInfoDAL.GetByPositionDepartment(StringConstant.EmployeePosition.DepartmentHead, requesterInfo.FactoryLocation.LookupId, departmentHR.ID).FirstOrDefault();
                    if (deptHeadOfHR != null)
                    {
                        taskManagement.NextAssign = deptHeadOfHR.ADAccount;
                    }
                }

                taskManagementDAL.SaveItem(taskManagement);

                var          mailDAL       = new EmailTemplateDAL(siteURL);
                var          emailTemplate = mailDAL.GetByKey("VehicleManagement_Request");
                EmployeeInfo assigneeInfo  = employeeInfoDAL.GetByADAccount(taskManagement.AssignedTo.ID);
                currentItem.ApprovalStatus = taskManagement.StepStatus;

                vehicleManagementDAL.SaveOrUpdate(currentItem);

                vehicleManagementDAL.SendEmail(currentItem, emailTemplate, null, assigneeInfo, VehicleTypeOfEmail.Request, siteURL);

                try
                {
                    List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteURL, assigneeInfo.ID, StringConstant.VehicleManagementList.ListUrl, currentItem.ID);
                    vehicleManagementDAL.SendDelegationEmail(currentItem, emailTemplate, toUsers, siteURL);
                }
                catch { }
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA -  Transportation Event Receiver - ItemAdded fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
            }
        }
        public bool IsDelegated(string fromApproverId, string itemId)
        {
            var approverInfo = _employeeInfoDAL.GetByADAccount(Convert.ToInt32(fromApproverId));

            return(DelegationPermissionManager.IsDelegation(approverInfo.ID, OverTimeManagementList.ListUrl, Convert.ToInt32(itemId)) != null);
        }
示例#10
0
 /// <summary>
 /// Check to show and hide buttons to precess on the form.
 /// </summary>
 private void DisplayButtonsControl()
 {
     if (formButtonsControlObject != null)
     {
         if (CurrentFormMode == Microsoft.SharePoint.WebControls.SPControlMode.New)
         {
             #region New Mode
             formButtonsControlObject.TdSaveAsDraft.Visible   = true;
             formButtonsControlObject.TdSaveAndSubmit.Visible = true;
             #endregion
         }
         else if (CurrentFormMode == Microsoft.SharePoint.WebControls.SPControlMode.Edit)
         {
             #region Edit Mode
             if (IsDraftStatus())
             {
                 if (approvalBaseManagerObject.IsEmployeeCreatorForThisItem())
                 {
                     formButtonsControlObject.TdSaveAsDraft.Visible   = true;
                     formButtonsControlObject.TdSaveAndSubmit.Visible = true;
                 }
             }
             else if (IsSubmittedStatus())
             {
                 var hasDelegationApprovalPermission = DelegationPermissionManager.DoesCurrentEmployeeHasApprovalPermission();
                 if (hasDelegationApprovalPermission || this.approvalBaseManagerObject.Creator.ID != this.approvalBaseManagerObject.CurrentEmployee.ID)
                 {
                     bool isEmployeeProcessing = approvalBaseManagerObject.IsEmployeeProcessing();
                     bool isEmployeeReAssigned = approvalBaseManagerObject.IsEmployeeReAssigned();
                     bool isEmployeeDelegated  = approvalBaseManagerObject.IsEmployeeDelegated();
                     if (isEmployeeProcessing || isEmployeeReAssigned || isEmployeeDelegated)
                     {
                         formButtonsControlObject.TdApprove.Visible = true;
                         // Duc.VoTan added on 21-March-2018. TFS #1466. Expired request need locking.
                         DateTime expiredDate;
                         var      isApprovalExpired = approvalBaseManagerObject.IsApprovalExpired(out expiredDate);
                         if (isApprovalExpired)
                         {
                             formButtonsControlObject.ApproveButon.Enabled = false;
                         }
                         formButtonsControlObject.TdReject.Visible = true;
                         // Duc.VoTan added on 21-March-2018. TFS #1466. Expired request need locking.
                         if (isApprovalExpired)
                         {
                             formButtonsControlObject.RejectButton.Enabled = false;
                         }
                         if (isEmployeeProcessing)
                         {
                             formButtonsControlObject.TdReAssign.Visible = true;
                         }
                     }
                 }
                 // Trạng thái: Submitted (WFStatus: In-Progress mà chưa có người approve) --> cho phép Cancel Workflow.
                 else
                 {
                     formButtonsControlObject.TdCancelWorkflow.Visible = true;
                 }
             }
             else if (IsRejectedStatus())
             {
                 // Nếu là người tạo thì mới cho phép re-submit và Terminate
                 if (this.approvalBaseManagerObject.Creator.ID == this.approvalBaseManagerObject.CurrentEmployee.ID)
                 {
                     formButtonsControlObject.TdSaveAndSubmit.Visible  = true;
                     formButtonsControlObject.TdCancelWorkflow.Visible = true;
                 }
             }
             else if (IsCompletedStatus())
             {
                 // Do nothing
             }
             else if (IsCancelWorkflowStatus())
             {
                 // Do nothing
             }
             else    // In-Progress status
             {
                 bool isEmployeeProcessing = approvalBaseManagerObject.IsEmployeeProcessing();
                 bool isEmployeeReAssigned = approvalBaseManagerObject.IsEmployeeReAssigned();
                 bool isEmployeeDelegated  = approvalBaseManagerObject.IsEmployeeDelegated();
                 if (isEmployeeProcessing || isEmployeeReAssigned || isEmployeeDelegated)
                 {
                     formButtonsControlObject.TdApprove.Visible = true;
                     // Duc.VoTan added on 21-March-2018. TFS #1466. Expired request need locking.
                     DateTime expiredDate;
                     var      isApprovalExpired = approvalBaseManagerObject.IsApprovalExpired(out expiredDate);
                     if (isApprovalExpired)
                     {
                         formButtonsControlObject.ApproveButon.Enabled = false;
                     }
                     if (this.CurrentItem[ApprovalFields.CurrentStep] != null)
                     {
                         formButtonsControlObject.TdReject.Visible = true;
                         // Duc.VoTan added on 21-March-2018. TFS #1466. Expired request need locking.
                         if (isApprovalExpired)
                         {
                             formButtonsControlObject.RejectButton.Enabled = false;
                         }
                     }
                     else
                     {
                         if (this.IsRejectionAllowableAtAdditionalStep())
                         {
                             formButtonsControlObject.TdReject.Visible = true;
                             // Duc.VoTan added on 21-March-2018. TFS #1466. Expired request need locking.
                             if (isApprovalExpired)
                             {
                                 formButtonsControlObject.RejectButton.Enabled = false;
                             }
                         }
                     }
                     if (isEmployeeProcessing)
                     {
                         formButtonsControlObject.TdReAssign.Visible = true;
                     }
                 }
             }
             #endregion
         }
         else if (CurrentFormMode == Microsoft.SharePoint.WebControls.SPControlMode.Display)
         {
             #region Display Mode
             // Do nothing
             #endregion
         }
     }
 }
示例#11
0
        public BusinessTripManagement RunWorkFlow(BusinessTripManagement businessTripManagement, TaskManagement taskOfPrevStep, EmployeeInfo approver, EmployeeInfo currentStepApprover)
        {
            if (businessTripManagement == null)
            {
                return(null);
            }

            TaskManagement taskManagement = new TaskManagement();

            taskManagement.StartDate       = DateTime.Now;
            taskManagement.DueDate         = businessTripManagement.RequestDueDate;
            taskManagement.PercentComplete = 0;
            taskManagement.ItemId          = businessTripManagement.ID;
            taskManagement.ItemURL         = taskOfPrevStep.ItemURL;
            taskManagement.ListURL         = taskOfPrevStep.ListURL;
            taskManagement.TaskName        = TASK_NAME;
            taskManagement.TaskStatus      = TaskStatusList.InProgress;
            taskManagement.StepModule      = StepModuleList.BusinessTripManagement.ToString();
            taskManagement.Department      = businessTripManagement.CommonDepartment.LookupId > 0 ? businessTripManagement.CommonDepartment : null;

            StepManagementDAL _stepManagementDAL = new StepManagementDAL(this.SiteUrl);
            User   assignee     = null;
            User   nextAssignee = null;
            string stepStatus   = string.Empty;

            if (businessTripManagement.Domestic == true) //Domestic Business Trip
            {
                StepManagement nextStep = null;

                if (currentStepApprover.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead &&
                    currentStepApprover.ADAccount.ID == businessTripManagement.DH.ID)
                {
                    nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                    if (businessTripManagement.TripHighPriority == true)
                    {
                        if (nextStep != null)
                        {
                            stepStatus = nextStep.StepStatus;
                            var approverAtStep = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                            if (approverAtStep != null)
                            {
                                assignee = approverAtStep.ADAccount;
                            }
                        }
                    }
                    else
                    {
                        if (nextStep != null)
                        {
                            nextStep = _stepManagementDAL.GetNextStepManagement(nextStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                            if (nextStep != null)
                            {
                                stepStatus = nextStep.StepStatus;
                                var approverAtStep = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                                if (approverAtStep != null)
                                {
                                    assignee = approverAtStep.ADAccount;
                                }
                            }
                        }
                    }
                }
                else
                {
                    nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                    if (nextStep != null)
                    {
                        stepStatus = nextStep.StepStatus;
                        var approverAtStep = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                        if (approverAtStep != null)
                        {
                            assignee = approverAtStep.ADAccount;
                        }
                    }
                }

                // get next approver
                if (nextStep != null)
                {
                    nextStep = _stepManagementDAL.GetNextStepManagement(nextStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                    if (nextStep != null)
                    {
                        var nextApprover = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                        if (nextApprover != null)
                        {
                            nextAssignee = nextApprover.ADAccount;
                        }
                    }
                }
            }
            else // Overseas Business Trip
            {
                StepManagement nextStep = null;
                if (currentStepApprover.ADAccount.ID == businessTripManagement.DirectBOD.ID)
                {
                    if (businessTripManagement.DirectBOD.ID != businessTripManagement.BOD.ID)
                    {
                        assignee   = businessTripManagement.BOD;
                        stepStatus = StepStatusList.BODApproval;
                        nextStep   = new StepManagement()
                        {
                            StepStatus = stepStatus, StepModule = StepModuleList.BusinessTripManagement.ToString()
                        };
                    }
                    else
                    {
                        nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                        if (nextStep != null)
                        {
                            stepStatus = nextStep.StepStatus;
                            var approverAtStep = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                            if (approverAtStep != null)
                            {
                                assignee = approverAtStep.ADAccount;
                            }
                        }
                    }
                }
                else
                {
                    nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                    if (nextStep != null)
                    {
                        stepStatus = nextStep.StepStatus;
                        var approverAtStep = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                        if (approverAtStep != null)
                        {
                            assignee = approverAtStep.ADAccount;
                        }
                    }
                }

                // get next approver
                if (nextStep != null)
                {
                    nextStep = _stepManagementDAL.GetNextStepManagement(nextStep.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);
                    if (nextStep != null)
                    {
                        var nextApprover = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                        if (nextApprover != null)
                        {
                            nextAssignee = nextApprover.ADAccount;
                        }
                    }
                }
            }

            taskManagement.AssignedTo = assignee;
            taskManagement.NextAssign = nextAssignee;
            taskManagement.StepStatus = stepStatus;

            EmployeeInfoDAL  _employeeInfoDAL  = new EmployeeInfoDAL(this.SiteUrl);
            EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(this.SiteUrl);

            if (assignee == null)
            {
                businessTripManagement.ApprovalStatus = StringConstant.ApprovalStatus.Approved.ToString();
                this.SaveOrUpdate(businessTripManagement);

                EmailTemplate emailTemplateRequester = _emailTemplateDAL.GetByKey("BusinessTripManagement_Approve");
                EmployeeInfo  toRequester            = _employeeInfoDAL.GetByID(businessTripManagement.Requester.LookupId);
                SendEmail(businessTripManagement, emailTemplateRequester, approver, toRequester, this.SiteUrl, false);

                if (businessTripManagement.TransportationType == ResourceHelper.GetLocalizedString("BusinessTripManagement_TransportationTypeCompanyTitle", StringConstant.ResourcesFileLists, 1033))
                {
                    EmailTemplate emailTemplateDriver = _emailTemplateDAL.GetByKey("BusinessTripManagement_Driver");
                    EmployeeInfo  toDriver            = _employeeInfoDAL.GetByID(businessTripManagement.Driver.LookupId);
                    SendEmail(businessTripManagement, emailTemplateDriver, approver, toDriver, this.SiteUrl, false);
                }

                if (!string.IsNullOrEmpty(businessTripManagement.CashRequestDetail))
                {
                    EmailTemplate emailTemplateAccountant = _emailTemplateDAL.GetByKey("BusinessTripManagement_Accountant");
                    EmployeeInfo  toAccountant            = _employeeInfoDAL.GetByID(businessTripManagement.Cashier.LookupId);
                    SendEmail(businessTripManagement, emailTemplateAccountant, approver, toAccountant, this.SiteUrl, false);
                }
            }
            else if (assignee != null)
            {
                TaskManagementDAL taskManagementDAL = new TaskManagementDAL(this.SiteUrl);
                int retId = taskManagementDAL.SaveItem(taskManagement);

                businessTripManagement.ApprovalStatus = taskManagement.StepStatus;
                this.SaveOrUpdate(businessTripManagement);

                EmailTemplate emailTemplate = _emailTemplateDAL.GetByKey("BusinessTripManagement_Request");
                EmployeeInfo  toUser        = _employeeInfoDAL.GetByADAccount(assignee.ID);
                SendEmail(businessTripManagement, emailTemplate, approver, toUser, this.SiteUrl, true);

                try
                {
                    List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(toUser.ID, StringConstant.BusinessTripManagementList.Url, businessTripManagement.ID);
                    SendDelegationEmail(businessTripManagement, emailTemplate, toUsers, this.SiteUrl);
                }
                catch { }
            }

            return(businessTripManagement);
        }
        public MessageResult ApproveVehicle(VehicleApprovalModel vehicleApprovalModel)
        {
            MessageResult msgResult = new MessageResult();

            try
            {
                SPWeb spWeb = SPContext.Current.Web;

                if (vehicleApprovalModel.Id > 0)
                {
                    Biz.Models.VehicleManagement vehicleManagement = _vehicleManagementDAL.GetByID(vehicleApprovalModel.Id);
                    string currentApprovalStatus = vehicleManagement.ApprovalStatus.ToLower();
                    if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower())
                    {
                        return(new MessageResult {
                            Code = (int)VehicleErrorCode.CannotApprove, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0
                        });
                    }

                    string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(vehicleManagement.RequestDueDate);
                    if (!string.IsNullOrEmpty(requestExpiredMsg))
                    {
                        return(new MessageResult {
                            Code = (int)VehicleErrorCode.CannotApprove, Message = requestExpiredMsg, ObjectId = 0
                        });
                    }

                    bool            hasApprovalPermission = HasApprovalPermission(vehicleApprovalModel.Id.ToString());
                    DelegationModel delegationModel       = GetDelegatedTaskInfo(vehicleApprovalModel.Id.ToString());
                    bool            isDelegated           = (delegationModel != null && delegationModel.Requester.LookupId > 0) ? true : false;
                    if (hasApprovalPermission == false && isDelegated == false)
                    {
                        return(msgResult);
                    }

                    EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(spWeb.Url);
                    EmployeeInfo    approverInfo     = _employeeInfoDAL.GetByADAccount(spWeb.CurrentUser.ID);

                    int assigneeId = hasApprovalPermission == true ? approverInfo.ADAccount.ID : (isDelegated == true ? delegationModel.FromEmployee.ID : 0);

                    TaskManagementDAL      _taskManagementDAL       = new TaskManagementDAL(spWeb.Url);
                    IList <TaskManagement> taskManagementCollection = _taskManagementDAL.GetRelatedTasks(vehicleManagement.ID, StepModuleList.VehicleManagement.ToString());
                    if (taskManagementCollection != null && taskManagementCollection.Count > 0)
                    {
                        TaskManagement        taskOfOriginalAssignee = _taskManagementDAL.GetTaskByAssigneeId(taskManagementCollection, assigneeId);
                        List <TaskManagement> relatedTasks           = taskManagementCollection.Where(t => t.ID != taskOfOriginalAssignee.ID).ToList();
                        User nextAssignee = taskOfOriginalAssignee.NextAssign;

                        if (hasApprovalPermission == true)
                        {
                            taskOfOriginalAssignee.TaskStatus      = TaskStatusList.Completed.ToString();
                            taskOfOriginalAssignee.PercentComplete = 1;
                            taskOfOriginalAssignee.TaskOutcome     = TaskOutcome.Approved.ToString();
                            taskOfOriginalAssignee.Description     = vehicleApprovalModel.Comment;
                            _taskManagementDAL.CloseTasks(relatedTasks);
                            _taskManagementDAL.SaveItem(taskOfOriginalAssignee);
                        }
                        else if (isDelegated == true)
                        {
                            TaskManagement clonedTask = _taskManagementDAL.CloneTask(taskOfOriginalAssignee);
                            clonedTask.AssignedTo      = approverInfo.ADAccount;
                            clonedTask.TaskStatus      = TaskStatusList.Completed.ToString();
                            clonedTask.PercentComplete = 1;
                            clonedTask.TaskOutcome     = TaskOutcome.Approved.ToString();
                            clonedTask.Description     = vehicleApprovalModel.Comment;
                            relatedTasks.Add(taskOfOriginalAssignee);
                            _taskManagementDAL.CloseTasks(relatedTasks);
                            _taskManagementDAL.SaveItem(clonedTask);
                        }

                        if (!string.IsNullOrEmpty(vehicleApprovalModel.Comment))
                        {
                            vehicleManagement.CommonComment = vehicleManagement.CommonComment.BuildComment(string.Format("{0}: {1}", approverInfo.FullName, vehicleApprovalModel.Comment));
                        }

                        if (nextAssignee == null)
                        {
                            vehicleManagement.ApprovalStatus = StringConstant.ApprovalStatus.Approved.ToString();
                            _vehicleManagementDAL.SaveOrUpdate(spWeb, vehicleManagement);

                            EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(spWeb.Url);
                            EmailTemplate    emailTemplate     = _emailTemplateDAL.GetByKey("VehicleManagement_Approve");
                            EmployeeInfo     toUser            = _employeeInfoDAL.GetByID(vehicleManagement.Requester.LookupId);
                            _vehicleManagementDAL.SendEmail(vehicleManagement, emailTemplate, approverInfo, toUser, VehicleTypeOfEmail.Approve, spWeb.Url);
                        }
                        else if (nextAssignee != null && taskManagementCollection != null && taskManagementCollection.Count > 0)
                        {
                            _vehicleManagementDAL.RunWorkFlow(vehicleManagement, taskOfOriginalAssignee);

                            EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(spWeb.Url);
                            EmailTemplate    emailTemplate     = _emailTemplateDAL.GetByKey("VehicleManagement_Request");
                            EmployeeInfo     toUser            = _employeeInfoDAL.GetByADAccount(nextAssignee.ID);
                            _vehicleManagementDAL.SendEmail(vehicleManagement, emailTemplate, approverInfo, toUser, VehicleTypeOfEmail.Request, spWeb.Url);

                            try
                            {
                                List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(toUser.ID, StringConstant.VehicleManagementList.ListUrl, vehicleManagement.ID);
                                _vehicleManagementDAL.SendDelegationEmail(vehicleManagement, emailTemplate, toUsers, spWeb.Url);
                            }
                            catch { }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msgResult.Code    = (int)VehicleErrorCode.Unexpected;
                msgResult.Message = ex.Message;
            }

            return(msgResult);
        }
示例#13
0
        public FreightManagement RunWorkFlow(FreightManagement freightManagement, TaskManagement taskOfPrevStep, EmployeeInfo approver, EmployeeInfo currentStepApprover)
        {
            if (freightManagement == null)
            {
                return(null);
            }

            TaskManagement taskManagement = new TaskManagement();

            taskManagement.StartDate       = DateTime.Now;
            taskManagement.DueDate         = freightManagement.RequestDueDate;
            taskManagement.PercentComplete = 0;
            taskManagement.ItemId          = freightManagement.ID;
            taskManagement.ItemURL         = taskOfPrevStep.ItemURL;
            taskManagement.ListURL         = taskOfPrevStep.ListURL;
            taskManagement.TaskName        = TASK_NAME;
            taskManagement.TaskStatus      = TaskStatusList.InProgress;
            taskManagement.StepModule      = StepModuleList.FreightManagement.ToString();
            taskManagement.Department      = freightManagement.Department.LookupId > 0 ? freightManagement.Department : null;

            StepManagementDAL _stepManagementDAL = new StepManagementDAL(this.SiteUrl);
            User   assignee     = null;
            User   nextAssignee = null;
            string stepStatus   = string.Empty;

            StepManagement nextStep = null;

            if (currentStepApprover.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead &&
                currentStepApprover.ADAccount.ID == freightManagement.DH.ID)
            {
                nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.FreightManagement, freightManagement.Department.LookupId);
                if (freightManagement.HighPriority == true)
                {
                    if (nextStep != null)
                    {
                        stepStatus = nextStep.StepStatus;
                        var approverAtStep = GetApproverAtStep(freightManagement.Department.LookupId, freightManagement.Location.LookupId, StepModuleList.FreightManagement, nextStep.StepNumber);
                        if (approverAtStep != null)
                        {
                            assignee = approverAtStep.ADAccount;
                        }
                    }
                }
                else
                {
                    if (nextStep != null)
                    {
                        nextStep = _stepManagementDAL.GetNextStepManagement(nextStep.StepStatus, StepModuleList.FreightManagement, freightManagement.Department.LookupId);
                        if (nextStep != null)
                        {
                            stepStatus = nextStep.StepStatus;
                            var approverAtStep = GetApproverAtStep(freightManagement.Department.LookupId, freightManagement.Location.LookupId, StepModuleList.FreightManagement, nextStep.StepNumber);
                            if (approverAtStep != null)
                            {
                                assignee = approverAtStep.ADAccount;
                            }
                        }
                    }
                }
            }
            else
            {
                nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.FreightManagement, freightManagement.Department.LookupId);
                if (nextStep != null)
                {
                    stepStatus = nextStep.StepStatus;
                    var approverAtStep = GetApproverAtStep(freightManagement.Department.LookupId, freightManagement.Location.LookupId, StepModuleList.FreightManagement, nextStep.StepNumber);
                    if (approverAtStep != null)
                    {
                        assignee = approverAtStep.ADAccount;
                    }
                }
            }

            // get next approver
            if (nextStep != null)
            {
                nextStep = _stepManagementDAL.GetNextStepManagement(nextStep.StepStatus, StepModuleList.FreightManagement, freightManagement.Department.LookupId);
                if (nextStep != null)
                {
                    var nextApprover = GetApproverAtStep(freightManagement.Department.LookupId, freightManagement.Location.LookupId, StepModuleList.FreightManagement, nextStep.StepNumber);
                    if (nextApprover != null)
                    {
                        nextAssignee = nextApprover.ADAccount;
                    }
                }
            }

            taskManagement.AssignedTo = assignee;
            taskManagement.NextAssign = nextAssignee;
            taskManagement.StepStatus = stepStatus;

            EmployeeInfoDAL  _employeeInfoDAL  = new EmployeeInfoDAL(this.SiteUrl);
            EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(this.SiteUrl);

            if (assignee == null)
            {
                freightManagement.ApprovalStatus = StringConstant.ApprovalStatus.Approved.ToString();
                this.SaveOrUpdate(freightManagement);

                EmailTemplate emailTemplate = _emailTemplateDAL.GetByKey("FreightManagement_Approve");
                EmployeeInfo  toUser        = _employeeInfoDAL.GetByID(freightManagement.Requester.LookupId);
                SendEmail(freightManagement, emailTemplate, approver, toUser, this.SiteUrl, false);
            }
            else if (assignee != null)
            {
                TaskManagementDAL taskManagementDAL = new TaskManagementDAL(this.SiteUrl);
                int retId = taskManagementDAL.SaveItem(taskManagement);

                freightManagement.ApprovalStatus = taskManagement.StepStatus;
                this.SaveOrUpdate(freightManagement);

                EmailTemplate emailTemplate = _emailTemplateDAL.GetByKey("FreightManagement_Request");
                EmployeeInfo  toUser        = _employeeInfoDAL.GetByADAccount(assignee.ID);
                SendEmail(freightManagement, emailTemplate, approver, toUser, this.SiteUrl, true);

                try
                {
                    List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(toUser.ID, StringConstant.FreightManagementList.ListUrl, freightManagement.ID);
                    SendDelegationEmail(freightManagement, emailTemplate, toUsers, this.SiteUrl);
                }
                catch { }
            }

            return(freightManagement);
        }
示例#14
0
        public FreightManagement StartWorkFlow(SPWeb spWeb, FreightManagement freightManagement, int freightId)
        {
            if (freightId == 0)
            {
                return(null);
            }

            SPList         freightList    = spWeb.TryGetSPList(spWeb.Url + this.ListUrl);
            TaskManagement taskManagement = new TaskManagement();

            taskManagement.StartDate       = DateTime.Now;
            taskManagement.DueDate         = freightManagement.RequestDueDate;
            taskManagement.PercentComplete = 0;
            taskManagement.ItemId          = freightManagement.ID;
            taskManagement.ItemURL         = freightList.DefaultDisplayFormUrl + "?ID=" + freightId;
            taskManagement.ListURL         = freightList.DefaultViewUrl;
            taskManagement.TaskName        = TASK_NAME;
            taskManagement.TaskStatus      = TaskStatusList.InProgress;
            taskManagement.StepModule      = StepModuleList.FreightManagement.ToString();
            taskManagement.Department      = freightManagement.Department.LookupId > 0 ? freightManagement.Department : null;

            EmployeeInfoDAL _employeeInfoDAL   = new EmployeeInfoDAL(this.SiteUrl);
            EmployeeInfo    departmentHeadInfo = _employeeInfoDAL.GetByADAccount(freightManagement.DH.ID);

            if (freightManagement.Requester.LookupId == departmentHeadInfo.ID)
            {
                taskManagement.StepStatus = StepStatusList.BODApproval;
                taskManagement.AssignedTo = freightManagement.BOD;
            }
            else
            {
                taskManagement.StepStatus = StepStatusList.DHApproval;
                taskManagement.AssignedTo = freightManagement.DH;
            }

            taskManagement.NextAssign = null;
            StepManagementDAL _stepManagementDAL = new StepManagementDAL(this.SiteUrl);
            var nextStep = _stepManagementDAL.GetNextStepManagement(taskManagement.StepStatus, StepModuleList.FreightManagement, freightManagement.Department.LookupId);

            if (nextStep != null)
            {
                var nextAssign = GetApproverAtStep(freightManagement.Department.LookupId, freightManagement.Location.LookupId, StepModuleList.FreightManagement, nextStep.StepNumber);
                if (nextAssign != null)
                {
                    taskManagement.NextAssign = nextAssign.ADAccount;
                }
            }

            TaskManagementDAL taskManagementDAL = new TaskManagementDAL(this.SiteUrl);
            int retId = taskManagementDAL.SaveItem(taskManagement);

            freightManagement.ApprovalStatus = taskManagement.StepStatus;
            freightManagement.Comment        = string.Empty;
            freightManagement.SecurityNotes  = string.Empty;
            freightManagement.IsFinished     = false;
            freightManagement.HighPriority   = false;

            this.SaveOrUpdate(freightManagement);

            EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(this.SiteUrl);
            EmailTemplate    emailTemplate     = _emailTemplateDAL.GetByKey("FreightManagement_Request");
            EmployeeInfo     toUser            = _employeeInfoDAL.GetByADAccount(taskManagement.AssignedTo.ID);

            SendEmail(freightManagement, emailTemplate, null, toUser, this.SiteUrl, true);

            try
            {
                List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(toUser.ID, StringConstant.FreightManagementList.ListUrl, freightManagement.ID);
                SendDelegationEmail(freightManagement, emailTemplate, toUsers, this.SiteUrl);
            }
            catch { }

            return(freightManagement);
        }
        public MessageResult Reject(NotOverTimeApprovalModel notOverTimeApprovalModel)
        {
            MessageResult msgResult = new MessageResult();

            try
            {
                SPWeb spWeb = SPContext.Current.Web;

                if (notOverTimeApprovalModel.Id > 0)
                {
                    Biz.Models.NotOvertimeManagement notOvertimeManagement = _notOvertimeManagementDAL.GetByID(notOverTimeApprovalModel.Id);
                    string currentApprovalStatus = !string.IsNullOrEmpty(notOvertimeManagement.ApprovalStatus) ? notOvertimeManagement.ApprovalStatus.ToLower() : string.Empty;
                    if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower())
                    {
                        return new MessageResult { Code = (int)NotOverTimeErrorCode.CannotReject, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0 };
                    }

                    string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(notOvertimeManagement.RequestDueDate);
                    if (!string.IsNullOrEmpty(requestExpiredMsg))
                    {
                        return new MessageResult { Code = (int)NotOverTimeErrorCode.CannotReject, Message = requestExpiredMsg, ObjectId = 0 };
                    }

                    bool hasRejectPermission = false;
                    EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(spWeb.Url);
                    int approverId = notOverTimeApprovalModel.ApproverId;
                    approverId = approverId > 0 ? approverId : notOvertimeManagement.DH.ID;
                    EmployeeInfo currentApprover = _employeeInfoDAL.GetByADAccount(approverId);
                    if (currentApprover != null)
                    {
                        if (currentApprover.ADAccount.ID == spWeb.CurrentUser.ID)
                        {
                            hasRejectPermission = true;
                        }
                        else
                        {
                            Delegation delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.NotOvertimeList.ListUrl, notOvertimeManagement.ID);
                            if (delegation != null)
                            {
                                hasRejectPermission = true;
                            }
                        }
                    }

                    if (hasRejectPermission == true)
                    {
                        notOvertimeManagement.ApprovalStatus = ApprovalStatus.Rejected;
                        notOvertimeManagement.Comment = notOverTimeApprovalModel.Comment;
                        var approver = spWeb.AllUsers.GetByID(approverId);
                        notOvertimeManagement.DH = new User
                        {
                            UserName = approver.LoginName,
                            FullName = approver.Name
                        };
                        _notOvertimeManagementDAL.SaveItem(notOvertimeManagement);

                        // Send reject email to employee
                        SendEmail(spWeb.Url, notOverTimeApprovalModel.Id, "LOAbsence_Reject", notOverTimeApprovalModel.ApproverName);
                    }
                }
            }
            catch (Exception ex)
            {
                msgResult.Code = (int)NotOverTimeErrorCode.Unexpected;
                msgResult.Message = ex.Message;
            }

            return msgResult;
        }
        public DelegationModel GetDelegatedTaskInfo(string Id)
        {
            DelegationModel delegationModel = new DelegationModel();

            int listItemId = 0;

            if (int.TryParse(Id, out listItemId))
            {
                string[] viewFields = new string[] { StringConstant.VehicleManagementList.DH, StringConstant.VehicleManagementList.BOD,
                                                     StringConstant.CommonSPListField.ApprovalStatusField, StringConstant.CommonSPListField.CommonDepartmentField };
                string queryStr = $@"<Where>
                                      <Eq>
                                         <FieldRef Name='ID' />
                                         <Value Type='Counter'>{listItemId}</Value>
                                      </Eq>
                                   </Where>";
                string siteUrl  = SPContext.Current.Site.Url;
                List <Biz.Models.VehicleManagement> vehicleManagementCollection = _vehicleManagementDAL.GetByQuery(queryStr, viewFields);
                if (vehicleManagementCollection != null && vehicleManagementCollection.Count > 0)
                {
                    Biz.Models.VehicleManagement vehicleManagement  = vehicleManagementCollection[0];
                    StepManagementDAL            _stepManagementDAL = new StepManagementDAL(siteUrl);
                    var currentStep = _stepManagementDAL.GetStepManagement(vehicleManagement.ApprovalStatus, StepModuleList.VehicleManagement, vehicleManagement.CommonDepartment.LookupId);
                    if (currentStep != null)
                    {
                        TaskManagementDAL     _taskManagementDAL       = new TaskManagementDAL(siteUrl);
                        string                taskQueryStr             = string.Format(@"<Where>
                                  <And>
                                     <Eq>
                                        <FieldRef Name='Status' />
                                        <Value Type='Choice'>{0}</Value>
                                     </Eq>
                                     <And>
                                        <Eq>
                                            <FieldRef Name='StepModule' />
                                            <Value Type='Choice'>{1}</Value>
                                        </Eq>
                                         <And>
                                            <Eq>
                                                <FieldRef Name='CurrentStepStatus' />
                                                <Value Type='Choice'>{2}</Value>
                                            </Eq>
                                            <Eq>
                                                <FieldRef Name='ItemId' />
                                                <Value Type='Number'>{3}</Value>
                                            </Eq>
                                         </And>
                                     </And>
                                  </And>
                               </Where>", TaskStatusList.InProgress.ToString(), StepModuleList.VehicleManagement.ToString(), vehicleManagement.ApprovalStatus, vehicleManagement.ID);
                        List <TaskManagement> taskManagementCollection = _taskManagementDAL.GetByQuery(taskQueryStr);
                        if (taskManagementCollection != null)
                        {
                            EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(siteUrl);
                            foreach (var taskManagement in taskManagementCollection)
                            {
                                EmployeeInfo assigneeInfo = _employeeInfoDAL.GetByADAccount(taskManagement.AssignedTo.ID);
                                Delegation   delegation   = DelegationPermissionManager.IsDelegation(assigneeInfo.ID, StringConstant.VehicleManagementList.ListUrl, vehicleManagement.ID);
                                delegationModel = new DelegationModel(delegation);
                                if (delegationModel.Requester.LookupId > 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(delegationModel);
        }
        public bool SendDelegationChangeShiftRequestMail(string changeshiftItemId, string toRole)
        {
            try
            {
                int idValue;
                if (int.TryParse(changeshiftItemId, out idValue))
                {
                    var changeShiftManagementItem  = _changeShiftManagementDAL.GetByID(idValue);
                    var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey("ChangeShift_Request");
                    if (changeshiftRequestMailItem != null && changeShiftManagementItem != null)
                    {
                        var siteUrl = SPContext.Current.Site.Url;
                        var link    = string.Format(@"{0}/_layouts/15/RBVH.Stada.Intranet.WebPages/ChangeShiftManagement/ChangeShiftApprovalDelegation.aspx?itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", siteUrl, idValue);

                        List <EmployeeInfo> toUsers = new List <EmployeeInfo>();
                        if (toRole.Equals("DH"))
                        {
                            var dhUser = _employeeDAL.GetByADAccount(changeShiftManagementItem.DepartmentHead.ID);
                            toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteUrl, dhUser.ID, StringConstant.ChangeShiftList.ListUrl, idValue);
                        }
                        else if (toRole.Equals("BOD"))
                        {
                            var bodUser = _employeeDAL.GetByADAccount(changeShiftManagementItem.BOD.ID);
                            toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(siteUrl, bodUser.ID, StringConstant.ChangeShiftList.ListUrl, idValue);
                        }

                        var shiftTimeList = _shiftTimeDAL.GetShiftTimes();

                        //lookup email
                        var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault();
                        var toShiftItem   = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault();

                        if (toUsers != null)
                        {
                            foreach (var toUser in toUsers)
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(toUser.Email))
                                    {
                                        string emailBody = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody);
                                        emailBody = string.Format(emailBody, toUser.FullName, changeShiftManagementItem.Requester.LookupValue,
                                                                  changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2),
                                                                  changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2),
                                                                  changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code);

                                        emailBody = emailBody.Replace("#link", link);
                                        _sendMailActivity.SendMail(siteUrl, changeshiftRequestMailItem.MailSubject, toUser.Email, true, false, emailBody);
                                    }
                                }
                                catch { }
                            }
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                ULSLogging.Log(new SPDiagnosticsCategory("STADA - Email Service - SendDelegationChangeShiftRequestMail fn",
                                                         TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected,
                               string.Format(CultureInfo.InvariantCulture, "{0}:{1}", ex.Message, ex.StackTrace));
                return(false);
            }
        }
        public MessageResult Approve(ChangeShiftApprovalModel changeShiftApprovalModel)
        {
            MessageResult msgResult = new MessageResult();

            try
            {
                SPWeb spWeb = SPContext.Current.Web;

                if (changeShiftApprovalModel.Id > 0)
                {
                    Biz.Models.ChangeShiftManagement changeShiftManagement = _changeShiftManagementDAL.GetByID(changeShiftApprovalModel.Id);
                    string currentApprovalStatus = !string.IsNullOrEmpty(changeShiftManagement.ApprovalStatus) ? changeShiftManagement.ApprovalStatus.ToLower() : string.Empty;
                    if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower())
                    {
                        return(new MessageResult {
                            Code = (int)ChangeShiftErrorCode.CannotApprove, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0
                        });
                    }

                    string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(changeShiftManagement.RequestDueDate);
                    if (!string.IsNullOrEmpty(requestExpiredMsg))
                    {
                        return(new MessageResult {
                            Code = (int)BusinessTripErrorCode.CannotApprove, Message = requestExpiredMsg, ObjectId = 0
                        });
                    }

                    bool            hasApprovalPermission = false;
                    EmployeeInfoDAL _employeeInfoDAL      = new EmployeeInfoDAL(spWeb.Url);
                    int             approverId            = changeShiftApprovalModel.ApproverId;
                    approverId = approverId > 0 ? approverId : changeShiftManagement.DepartmentHead.ID;
                    EmployeeInfo currentApprover = _employeeInfoDAL.GetByADAccount(approverId);
                    if (currentApprover != null)
                    {
                        if (currentApprover.ADAccount.ID == spWeb.CurrentUser.ID)
                        {
                            hasApprovalPermission = true;
                        }
                        else
                        {
                            Delegation delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.ChangeShiftList.ListUrl, changeShiftManagement.ID);
                            if (delegation != null)
                            {
                                hasApprovalPermission = true;
                            }
                        }
                    }

                    if (hasApprovalPermission == true)
                    {
                        changeShiftManagement.ApprovalStatus = ApprovalStatus.Approved;
                        changeShiftManagement.Comment        = changeShiftApprovalModel.Comment;
                        var approver = spWeb.AllUsers.GetByID(approverId);
                        changeShiftManagement.DepartmentHead = new User
                        {
                            UserName = approver.LoginName,
                            FullName = approver.Name
                        };
                        _changeShiftManagementDAL.SaveItem(changeShiftManagement);

                        // Send approval email to employee
                        SendEmail(spWeb.Url, changeShiftApprovalModel.Id, "ChangeShift_Approve", changeShiftApprovalModel.ApproverName);
                    }
                }
            }
            catch (Exception ex)
            {
                msgResult.Code    = (int)ChangeShiftErrorCode.Unexpected;
                msgResult.Message = ex.Message;
            }

            return(msgResult);
        }
示例#19
0
        public BusinessTripManagement StartWorkFlow(BusinessTripManagement businessTripManagement)
        {
            SPListItem     spListItem     = this.GetByIDToListItem(businessTripManagement.ID);
            TaskManagement taskManagement = new TaskManagement();

            taskManagement.StartDate       = DateTime.Now;
            taskManagement.DueDate         = businessTripManagement.RequestDueDate;
            taskManagement.PercentComplete = 0;
            taskManagement.ItemId          = businessTripManagement.ID;
            taskManagement.ItemURL         = spListItem.ParentList.DefaultDisplayFormUrl + "?ID=" + businessTripManagement.ID;
            taskManagement.ListURL         = spListItem.ParentList.DefaultViewUrl;
            taskManagement.TaskName        = TASK_NAME;
            taskManagement.TaskStatus      = TaskStatusList.InProgress;
            taskManagement.StepModule      = StepModuleList.BusinessTripManagement.ToString();
            taskManagement.Department      = businessTripManagement.CommonDepartment.LookupId > 0 ? businessTripManagement.CommonDepartment : null;

            EmployeeInfoDAL _employeeInfoDAL   = new EmployeeInfoDAL(this.SiteUrl);
            EmployeeInfo    departmentHeadInfo = _employeeInfoDAL.GetByADAccount(businessTripManagement.DH.ID);

            if (businessTripManagement.Requester.LookupId == departmentHeadInfo.ID)
            {
                taskManagement.StepStatus = StepStatusList.BODApproval;
                taskManagement.AssignedTo = businessTripManagement.DirectBOD.ID > 0 ? businessTripManagement.DirectBOD : businessTripManagement.BOD;
            }
            else
            {
                taskManagement.StepStatus = StepStatusList.DHApproval;
                taskManagement.AssignedTo = businessTripManagement.DH;
            }

            taskManagement.NextAssign = null;

            StepManagementDAL _stepManagementDAL = new StepManagementDAL(this.SiteUrl);
            var nextStep = _stepManagementDAL.GetNextStepManagement(taskManagement.StepStatus, StepModuleList.BusinessTripManagement, businessTripManagement.CommonDepartment.LookupId);

            if (nextStep != null)
            {
                var nextAssign = GetApproverAtStep(businessTripManagement.CommonDepartment.LookupId, businessTripManagement.CommonLocation.LookupId, StepModuleList.BusinessTripManagement, nextStep.StepNumber);
                if (nextAssign != null)
                {
                    taskManagement.NextAssign = nextAssign.ADAccount;
                }
            }

            TaskManagementDAL taskManagementDAL = new TaskManagementDAL(this.SiteUrl);
            int retId = taskManagementDAL.SaveItem(taskManagement);

            businessTripManagement.ApprovalStatus = taskManagement.StepStatus;
            this.SaveOrUpdate(businessTripManagement);

            EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(this.SiteUrl);
            EmailTemplate    emailTemplate     = _emailTemplateDAL.GetByKey("BusinessTripManagement_Request");
            EmployeeInfo     toUser            = _employeeInfoDAL.GetByADAccount(taskManagement.AssignedTo.ID);

            SendEmail(businessTripManagement, emailTemplate, null, toUser, this.SiteUrl, true);

            try
            {
                List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(toUser.ID, StringConstant.BusinessTripManagementList.Url, businessTripManagement.ID);
                SendDelegationEmail(businessTripManagement, emailTemplate, toUsers, this.SiteUrl);
            }
            catch { }

            return(businessTripManagement);
        }