最近做项目用到继承,说实话以前没有具体的用到过, 所以在开始的时候有点懵逼; 后来还是我们老大给的模板, 有点惭愧, 哈哈。
这是我项目中用到后积累的, 肯定不完整,有什么不足和错误的地方 欢迎大神们提点。
下面是基类。
1 public interface IWorkflowProcess 2 { 3 List<System.Web.Mvc.SelectListItem> GetNextOperator(int id, int projectId); 4 List<System.Web.Mvc.SelectListItem> GetNextWF(int projectId); 5 } 6 public class WorkflowProcess : IWorkflowProcess 7 { 8 public int ID { get; set; } 9 public string Name { get; set; } 10 public string Description { get; set; } 11 public string Controller { get; set; } 12 public WorkflowProcess() 13 { 14 } 15 public bool CanGetPrerepotNo() 16 { 17 return (int)enumUserRole.Reviewer == REASContext.CurrentUser.RoleID || ((int)enumDepartment.EvalueDepartmentTwo == REASContext.CurrentUser.DepartmentID); 18 } 19 public bool CanGetRepotNo() 20 { 21 return (int)enumUserRole.Reviewer == REASContext.CurrentUser.RoleID; 22 } 23 public virtual List<System.Web.Mvc.SelectListItem> GetNextWF(int projectId) 24 { 25 var nextprocess = WorkflowManager.NextOf(WorkflowManager.GetByID(ID)); 26 return new List<System.Web.Mvc.SelectListItem>() 27 { WorkflowManager.GetSelectListItem(nextprocess) 28 }; 29 } 30 public virtual List<System.Web.Mvc.SelectListItem> GetNextOperator(int id, int projectId) 31 { 32 return bll_Common.GetOperatorByDepartmentSelectList(); 33 } 34 }
子类:
例1、
4 public class WF_ReportApprove : WorkflowProcess, IWorkflowProcess 5 { 6 public override List<SelectListItem> GetNextOperator(int id, int projectId) 7 { 8 return bll_Common.GetBeforOperatorSelectList(projectId); 9 } 10 } 11
例二、
4 15 public class WF_Balance : WorkflowProcess, IWorkflowProcess 5 16 { 7 18 public override List<SelectListItem> GetNextWF(int projectId) 8 19 { 10 21 return new List<System.Web.Mvc.SelectListItem>() 11 22 { 12 23 new System.Web.Mvc.SelectListItem() 13 24 { 14 25 Text = 15 26 WorkflowManager.GetByControllerName(enum_WorkflowProcess.WF_Preestimate.GetDescription()).Name, 16 27 Value = ((int) enum_WorkflowProcess.WF_Preestimate).ToString(), 17 28 Selected = true 18 29 }, 19 30 20 31 new System.Web.Mvc.SelectListItem() 21 32 { 22 33 Text = WorkflowManager.GetByControllerName(enum_WorkflowProcess.WF_Archive.GetDescription()).Name, 23 34 Value = ((int) enum_WorkflowProcess.WF_Archive).ToString() 24 35 } 25 36 }; 27 38 } 28 39 29 40 public override List<SelectListItem> GetNextOperator(int id, int projectId) 30 41 { 31 42 if (id == (int)enum_WorkflowProcess.WF_Preestimate) 32 43 if (REASContext.CurrentUser.DeparmentTypeID == (int)enumDepartmentType.BranchOffice) 33 44 { 34 45 var user = bll_LoginUser.GetAll().First(p => p.ManageDepID.HasValue && p.ManageDepID.Value == REASContext.CurrentUser.DepartmentID); 35 46 return new List<SelectListItem>() 36 47 { 37 48 new SelectListItem() 38 49 { 39 50 Text = user.DisplayName, 40 51 Value = user.ID.ToString() 41 52 } 42 53 }; 43 54 } 44 55 45 56 return base.GetNextOperator(id, projectId); 46 57 } 47 58 48 59 }
例三、
public class WF_Archive : WorkflowProcess, IWorkflowProcess { }
例子中主要继承的方法为:GetNextWF(int projectId) ,GetNextOperator(int id , int projectId)
例一的返回的是子类的GetNextOperator()方法和基类的 GetNextWF(),
例二返回的是子类的GetNextOperator()和GetNextWF()
例三返回的是基类的GetNextOperator()和GetNextWF()