public VehicleManagement RunWorkFlow(VehicleManagement vehicleManagement, TaskManagement taskOfPrevStep) { if (vehicleManagement == null) { return(null); } TaskManagement taskManagement = new TaskManagement(); taskManagement.StartDate = DateTime.Now; taskManagement.DueDate = vehicleManagement.RequestDueDate; taskManagement.PercentComplete = 0; taskManagement.ItemId = vehicleManagement.ID; taskManagement.ItemURL = taskOfPrevStep.ItemURL; taskManagement.ListURL = taskOfPrevStep.ListURL; taskManagement.TaskName = TASK_NAME; taskManagement.TaskStatus = TaskStatusList.InProgress; taskManagement.StepModule = StepModuleList.VehicleManagement.ToString(); taskManagement.Department = vehicleManagement.CommonDepartment.LookupId > 0 ? vehicleManagement.CommonDepartment : null; taskManagement.AssignedTo = taskOfPrevStep.NextAssign; taskManagement.NextAssign = null; StepManagementDAL _stepManagementDAL = new StepManagementDAL(this.SiteUrl); var nextStep = _stepManagementDAL.GetNextStepManagement(taskOfPrevStep.StepStatus, StepModuleList.VehicleManagement, vehicleManagement.CommonDepartment.LookupId); if (nextStep != null) { taskManagement.StepStatus = nextStep.StepStatus; ModuleBuilder moduleBuilder = new ModuleBuilder(this.SiteUrl); // TODO: Get location by vehicleManagement: var locationId = 2; var nextAssign = moduleBuilder.GetNextApproval(vehicleManagement.CommonDepartment.LookupId, locationId, StepModuleList.VehicleManagement, nextStep.StepNumber); if (nextAssign != null) { taskManagement.NextAssign = nextAssign.ADAccount; } } TaskManagementDAL taskManagementDAL = new TaskManagementDAL(this.SiteUrl); int retId = taskManagementDAL.SaveItem(taskManagement); vehicleManagement.ApprovalStatus = taskManagement.StepStatus; this.SaveOrUpdate(vehicleManagement); return(vehicleManagement); }
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); }
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 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 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); }