njlxp
Imports System.Data.oracleclient
Imports System.Data
Public Class page_paper
    Public Sub New()
    End Sub 
\'New
    \'
    \' TODO: 在此处添加构造函数逻辑
    \'
    Private page_size As Integer \'页尺寸
    Private orderby_tag As Integer \'排序方式(0为asc,1为desc)
    Private tb_name As String \'表名
    Private field_list As String \'字段列表
    Private page_no As Integer = 0 \'页码
    Private condition_str As String \'条件字段串(不加where)
    Private primary_key As String \' 主键(必须而且要自动编号无重复)

    Public Property pagesize() As Integer 
\'pagesize 属性
        Get
            Return page_size
        End Get
        Set(ByVal Value As Integer)
            page_size 
= Value
        End Set
    End Property

    Public Property orderbytag() As Integer 
\'排序标志 属性(0为正序1为倒序)
        Get
            Return orderby_tag
        End Get
        Set(ByVal Value As Integer)
            orderby_tag 
= Value
        End Set
    End Property


    Public Property tbname() As String 
\'表名 属性
        Get
            Return tb_name
        End Get
        Set(ByVal Value As String)
            tb_name 
= Value
        End Set
    End Property

    Public Property fieldlist() As String 
\'字段列表 属性
        Get
            Return field_list
        End Get
        Set(ByVal Value As String)
            field_list 
= Value
        End Set
    End Property


    Public Property pageno() As Integer 
\'页码 属性

        Get
            Return page_no
        End Get
        Set(ByVal Value As Integer)
            If Value 
<> 0 Then
                page_no 
= Value
            Else
                page_no 
= 1
            End If
        End Set
    End Property


    Public Property condition() As String 
\'条件 属性
        Get
            Return condition_str
        End Get
        Set(ByVal Value As String)
            condition_str 
= Value
        End Set
    End Property


    Public Property primarykey() As String 
\'关键字 属性
        Get
            Return primary_key
        End Get
        Set(ByVal Value As String)
            primary_key 
= Value
        End Set
    End Property


    
\'组合查询语句
    Public Function page_tb() As System.Data.DataTable
        Dim condition_tag As String 
\'存放按最大ID或最小ID查询
        Dim orderbystr As String \'存放orderby字符串
        Dim strsql As String \'组合后的查询字符串
        If Me.orderbytag = 0 Then
            orderbystr 
= " order by " & Me.primarykey & " asc "
        Else
            orderbystr 
= " order by " & Me.primarykey & " desc "
        End If
        If Me.pageno 
= 1 Then
            If Me.condition 
= "" Then

                strsql 
+= "  SELECT A.* FROM "
                strsql 
+= " ( SELECT " & Me.fieldlist & " FROM " & Me.tbname & orderbystr
                strsql 
+= "  ) A  WHERE rownum <= " & (Me.pageno) * Me.pagesize
            Else

                strsql 
+= "   SELECT A.* FROM "
                strsql 
+= " ( SELECT " & Me.fieldlist & " FROM " & Me.tbname & " where " & Me.condition & " " & orderbystr
                strsql 
+= "  ) A  WHERE rownum <= " & (Me.pageno) * Me.pagesize

            End If

        Else
            If Me.condition 
= "" Then
                strsql 
= "SELECT * FROM"
                strsql 
+= " (  SELECT A.*, rownum r FROM "
                strsql 
+= " ( SELECT " & Me.fieldlist & " FROM " & Me.tbname & orderbystr
                strsql 
+= "  ) A  "
                strsql 
+= ") B"
                strsql 
+= " WHERE (r > " & (Me.pageno - 1* Me.pagesize & ") and (r< " & Me.pageno * Me.pagesize & ")"
            Else
                strsql 
= "SELECT * FROM"
                strsql 
+= " (  SELECT A.*, rownum r FROM "
                strsql 
+= " ( SELECT " & Me.fieldlist & " FROM " & Me.tbname & " where " & Me.condition & " " & orderbystr
                strsql 
+= "  ) A    "
                strsql 
+= ") B"
                strsql 
+= " WHERE (r > " & (Me.pageno - 1* Me.pagesize & ") and (r< " & Me.pageno * Me.pagesize & ")"
            End If
        End If
        
\'System.Web.HttpContext.Current.Response.Write(strsql)
        \'System.Web.HttpContext.Current.Response.End()

        Dim db_op As New db_operate
        If db_op.oracleconn.State.ToString() 
= "Closed" Then
            db_op.open_conn()
        End If
        Dim ds As New DataSet
        Try

            Dim adp As New System.Data.OracleClient.OracleDataAdapter(strsql, db_op.oracleconn)
            adp.Fill(ds)
            Return ds.Tables(
0)
        Catch e As Exception
            System.Web.HttpContext.Current.Response.Write(e.Message)
            db_op.close_conn()
            Return New DataTable
        Finally
            db_op.close_conn()
        End Try
    End Function

    
\'返回总行数
    Public Function recordcount() As Long
        Dim strsql As String
        If Me.condition.ToString() 
<> "" Then
            strsql 
= "Select Count(" & Me.primarykey & ")  as counts from " & Me.tbname & " where " & Me.condition.ToString()
        Else
            strsql 
= "Select Count(" & Me.primarykey & ")  as counts from " & Me.tbname
        End If
        Dim db_op As New db_operate
        If db_op.oracleconn.State.ToString() 
= "Closed" Then
            db_op.open_conn()
        End If
        Dim cmd As New OracleCommand
        cmd.CommandText 
= strsql
        cmd.Connection 
= db_op.oracleconn
        Dim rd As OracleDataReader
        Try
            rd 
= cmd.ExecuteReader()
            If rd.HasRows 
= True Then
                rd.Read()
                Return Long.Parse(rd(
"counts").ToString())
            Else
                Return 
0
            End If
        Catch e As Exception
            System.Web.HttpContext.Current.Response.Write(e.Message)
            db_op.close_conn()
            cmd.Dispose()
            Return 
0
        Finally
            db_op.close_conn()
        End Try
    End Function

End Class

博客网速度太慢.发一个贴子要两分钟.

bbs.njlxp.com

分类:

技术点:

相关文章: