XAF 如何给記錄增加版本控制?

 

using System;
using System.ComponentModel;
 
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
 
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
 
namespace DXExample.Module
{
    [DefaultClassOptions]
     public  class PO : BaseObject
    {
         public PO(Session session)
            :  base(session)
        {
             //  This constructor is used when an object is loaded from a persistent storage.
            
//  Do not place any code here or place it only when the IsLoading property is false:
            
//  if (!IsLoading){
            
//     It is now OK to place your initialization code here.
            
//  }
            
//  or as an alternative, move your initialization code into the AfterConstruction method.
        }
 
         private  string _PONO;
         public  string PONO
        {
             get
            {
                 return _PONO;
            }
             set
            {
                SetPropertyValue( " PONO "ref _PONO, value);
                 if (!IsLoading)
                {
               // 如果更改订单号,需重置Version
                    _Version =  0;
                }
            }
        }
 
         private  int _Version;
        [Custom( " AllowEdit ", " False ")]
         public  int Version
        {
             get
            {
                 return _Version;
            }
             set
            {
                SetPropertyValue( " Version "ref _Version, value);
            }
        }
 
         private  string _Note;
         public  string Note
        {
             get
            {
                 return _Note;
            }
             set
            {
                SetPropertyValue( " Note "ref _Note, value);
            }
        }
 
         private DateTime _CreateOn = DateTime.Now;
        [Custom( " AllowEdit "" False ")]
         public DateTime CreateOn
        {
             get
            {
                 return _CreateOn;
            }
             set
            {
                SetPropertyValue( " CreateOn "ref _CreateOn, value);
            }
        }
         public  override  void AfterConstruction()
        {
             base.AfterConstruction();
            Version =  0;
        }
 
       
         private  int GetPoNoNewVersion()
        {
             int ver =  1;
            ver = Utility.GetNewVersion<PO>( new BinaryOperator( " PONO ", PONO), Session,  " Version "" CreateOn ");
             return ver;
        }
         protected  override  void OnSaving()
        {
             base.OnSaving();
            _Version = Version !=  0 ? _Version : GetPoNoNewVersion();
        }
    }
 
     public  static  class Utility
    {
         ///   <summary>
        
///  Get Version
        
///  Tonyyang
        
///  2011-03-23
        
///   </summary>
        
///   <typeparam name="T"> BO </typeparam>
        
///   <param name="criteriaOperator"></param>
        
///   <param name="session"></param>
        
///   <param name="propertyName"></param>
        
///   <param name="sortPropertyName"></param>
        
///   <returns></returns>
         public  static  int GetNewVersion<T>(CriteriaOperator criteriaOperator, Session session,  string propertyName,  string sortPropertyName)  where T : XPCustomObject
        {
             int ver =  1;
            XPCollection<T> xpc =  new XPCollection<T>(session) { Criteria = criteriaOperator };
            xpc.Sorting.Clear();
            xpc.Sorting.Add( new SortProperty(sortPropertyName, DevExpress.Xpo.DB.SortingDirection.Descending));
             if (xpc.IsLoaded !=  true)
                xpc.Load();
 
            ver = xpc.Count ==  0 ? ver : ( int)xpc[ 0].GetMemberValue(propertyName) +  1;
             return ver;
        }
    }
 
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值