程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB.NET >> eXpressApp Framework生成單據編號的解決方案(vb.net)

eXpressApp Framework生成單據編號的解決方案(vb.net)

編輯:VB.NET

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()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()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()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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved