eXpressApp Framework (以下简称XAF)是Devexpress公司开发的一套基于.net平台的O/R M快速开发应用架构,其特点是可以快速的开发出基于web和winform的数据库应用程序,在XAF的实际应用开发过程中,我们难免要实现单据编号的自动生成和管理,传统的很多应用系统都是利用存储过程来实现这一目的的,我们知道XAF的是用XPO来和数据库存储系统交互的,有没有办法不用存储过程而直接用XPO来生成和管理应用系统的单据编号呢?经过本人的尝试,答案是肯定的,下面我就把这个实现的实体类和相应的实现函数共享出来,给大家参考,由于水平和时间的关系,代码可能没有那么的顺眼,请大家批评指正:
先给个效果图看看吧:
1.单据编号设定实体类
Imports System
Imports System.ComponentModel
Imports DevExpress.Xpo
Imports DevExpress.ExpressApp
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.Persistent.Validation
<DefaultClassOptions()> _
<System.ComponentModel.DisplayName("单据编号设定")> _
Public Class B_BILLCODEPREX
Inherits BaseObject
Public Sub New(ByVal session As Session)
MyBase.New(session)
End Sub
Private FTBNAME As String
<DevExpress.Xpo.DisplayName("表")> _
<Custom("AllowEdit", "False")> _
Public Property TBNAME() As String
Get
Return FTBNAME
End Get
Set(ByVal value As String)
SetPropertyValue("TBNAME", FTBNAME, value)
End Set
End Property
Private FTBCAPTION As String
<DevExpress.Xpo.DisplayName("表名称")> _
<Custom("AllowEdit", "False")> _
Public Property TBCAPTION() As String
Get
Return FTBCAPTION
End Get
Set(ByVal value As String)
SetPropertyValue("TBCAPTION", FTBCAPTION, value)
End Set
End Property
Private FPREX As String
<DevExpress.Xpo.DisplayName("单据编号前缀")> _
Public Property PREX() As String
Get
Return FPREX
End Get
Set(ByVal value As String)
SetPropertyValue("PREX", FPREX, value)
End Set
End Property
Private FLENTH As Integer = 5
<DevExpress.Xpo.DisplayName("流水号位数")> _
Public Property LENTH() As Integer
Get
Return FLENTH
End Get
Set(ByVal value As Integer)
SetPropertyValue("LENTH", FLENTH, value)
End Set
End Property
Private FINTERVAL As String = "-"
<DevExpress.Xpo.DisplayName("分隔符")> _
Public Property INTERVAL() As String
Get
Return FINTERVAL
End Get
Set(ByVal value As String)
SetPropertyValue("INTERVAL", FINTERVAL, value)
End Set
End Property
Public Enum EPREX
无
年
年月
年月日
End Enum
Private FDPREX As EPREX
<DevExpress.Xpo.DisplayName("日期段")> _
Public Property DPREX() As EPREX
Get
Return FDPREX
End Get
Set(ByVal value As EPREX)
SetPropertyValue("DPREX", FDPREX, value)
End Set
End Property
End Class
2.单据编号生成函数
1 Public Function UPDATEBILLCODE(ByVal FBCODE As String, ByVal BO As Object)
2 Dim BILLCODEPREX As B_BILLCODEPREX = Session.FindObject(Of B_BILLCODEPREX)(New BinaryOperator("TBNAME", BO.GetType.Name))
3 If BILLCODEPREX IsNot Nothing Then
4 If BILLCODEPREX.TBNAME IsNot Nothing Then
5 If BO.GetType.Name = BILLCODEPREX.TBNAME.Trim Then
6 Dim BB As String = ""
7 Dim PRE As String = ""
8 If BILLCODEPREX.INTERVAL Is Nothing Then
9 BB = ""
10 Else
11 BB = BILLCODEPREX.INTERVAL.Trim
12 End If
13 If Not BILLCODEPREX.PREX.Trim = Nothing Then
14 PRE = BILLCODEPREX.PREX.ToUpper.Trim & BB
15 Else
16 PRE = ""
17 End If
18 Dim CC As String = ""
19 If Not BILLCODEPREX.DPREX = Nothing Then
20 Select Case BILLCODEPREX.DPREX
21 Case B_BILLCODEPREX.EPREX.年
22 CC = Format(Now.Year, "00").ToString & BB
23 Case B_BILLCODEPREX.EPREX.年月
24 CC = Format(Now.Year, "00").ToString & BB & Format(Now.Month, "00").ToString & BB
25 Case B_BILLCODEPREX.EPREX.年月日
26 CC = Format(Now.Year, "00").ToString & BB & Format(Now.Month, "00").ToString & BB & Format(Now.Day, "00").ToString & BB
27 Case B_BILLCODEPREX.EPREX.无
28 CC = ""
29 End Select
30 Else
31 CC = ""
32 End If
33 Dim fLOWlenth As Integer = 4
34 Dim AA As String = ""
35 If BILLCODEPREX.LENTH > 0 Then
36 fLOWlenth = BILLCODEPREX.LENTH
37 End If
38 For I = 1 To fLOWlenth Step 1
39 AA &= "0"
40 Next
41 FBCODE = PRE & CC & Format(DistributedIdGeneratorHelper.Generate(BO.Session.DataLayer, BO.[GetType]().FullName, CC), AA)
42 Else
43 FBCODE = Format(DistributedIdGeneratorHelper.Generate(BO.Session.DataLayer, BO.[GetType]().FullName, "ERP"), "00000000")
44 End If
45 Else
46 FBCODE = Format(DistributedIdGeneratorHelper.Generate(BO.Session.DataLayer, BO.[GetType]().FullName, "ERP"), "00000000")
47 End If
48 Else
49 FBCODE = Format(DistributedIdGeneratorHelper.Generate(BO.Session.DataLayer, BO.[GetType]().FullName, "ERP"), "00000000")
50
51 End If
52 Return FBCODE
53 End Function
54
3.调用方法代码
1 Public Overloads Overrides Sub AfterConstruction()
2 MyBase.AfterConstruction()
3 FBILLCODE = UPDATEBILLCODE(FBILLCODE, Me)
4 BKBILLCODE = FBILLCODE
5
6 End Sub
7 Private FBILLCODE As String
8 <Indexed(unique:=True), DevExpress.Xpo.DisplayName("单据编号")> _
9 <VisibleInListView(True)> _
10 Public Property BILLCODE() As String
11 Get
12 Return FBILLCODE
13 End Get
14 Set(ByVal value As String)
15 SetPropertyValue("BILLCODE", FBILLCODE, value)
16 End Set
17 End Property
相关产品:eXpressApp Framework