@Aiti
2017-04-20T04:54:19.000000Z
字数 1237
阅读 251
未分类
在基类(父类)中用virtual修饰符声明一个虚方法,然后在在派生类(子类)中用override修饰符覆盖基类虚方法。表明是对基类的虚方法重载。
这种优势在于它可以在程序运行时再决定调用哪一个方法,这就是所谓的“运行时多态”
或者称动态绑定。
基类中继承了一个接口实现的方法:
[DisplayName("流程编码")]
public virtual string FlowCode => "TunnelTest";
子类中想要重新赋值:
[DisplayName("流程编码")]
public override string FlowCode => "PrimarySupport";
可对数据重新赋值、计算保存到数据库!
protected override void OnSaving()
{
base.OnSaving();
if (Properties.Contains("4") && Content.Contains("Images/")&&Preview==null)
{
// 查找文章中第一次出现的字符串(第一个字符)的位置;并将长度的字符串取出
int start = Content.IndexOf("Images/") + 7;
int end = Content.IndexOf("alt") - 2;
var p = Content.Substring(start, end - start);
if (p != null)
Preview = "../News/Images/" + p;
}
if (Oid < 0)
{
Creator = Session.FindObject<CsUser>(CriteriaOperator.Parse("LoginName=?", HttpContext.Current.User.Identity.Name));
Department = ScopeHelper.GetScope(Creator.Department);
}
}
删除时如果有关联表;需要先删除关联表信息;在删除信息
protected override void OnDeleting()
{
var views = new XPCollection<View>(Session, CriteriaOperator.Parse("Article.Oid=?", Oid));
Session.Delete(views);
Session.Save(views);
var approvals = new XPCollection<ApprovalRecord>(Session, CriteriaOperator.Parse("[Type]=? AND TargetId=?", FlowCode, Oid));
Session.Delete(approvals);
Session.Save(approvals);
base.OnDeleting();
}