⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmpublisher.frm

📁 library system for students..these is very useful system.....
💻 FRM
字号:
VERSION 5.00
Object = "{D76D7128-4A96-11D3-BD95-D296DC2DD072}#1.0#0"; "Vsflex7.ocx"
Begin VB.Form frmPublisher 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Publisher"
   ClientHeight    =   4470
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7050
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4470
   ScaleWidth      =   7050
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame3 
      Height          =   855
      Left            =   120
      TabIndex        =   6
      Top             =   3480
      Width           =   6855
      Begin VB.CommandButton cmdlClose 
         Caption         =   "Cl&ose"
         Height          =   495
         Left            =   6000
         TabIndex        =   12
         Top             =   240
         Width           =   735
      End
      Begin VB.CommandButton cmdCancel 
         Caption         =   "Cancel"
         Height          =   495
         Left            =   3000
         TabIndex        =   11
         Top             =   240
         Width           =   735
      End
      Begin VB.CommandButton cmdSave 
         Caption         =   "&Save"
         Height          =   495
         Left            =   2280
         TabIndex        =   10
         Top             =   240
         Width           =   735
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "&Delete"
         Height          =   495
         Left            =   1560
         TabIndex        =   9
         Top             =   240
         Width           =   735
      End
      Begin VB.CommandButton cmdEdit 
         Caption         =   "&Edit"
         Height          =   495
         Left            =   840
         TabIndex        =   8
         Top             =   240
         Width           =   735
      End
      Begin VB.CommandButton cmdAdd 
         Caption         =   "&Add"
         Height          =   495
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   735
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Publisher Details"
      Height          =   3375
      Left            =   3240
      TabIndex        =   2
      Top             =   120
      Width           =   3735
      Begin VB.TextBox txtName 
         Height          =   285
         Left            =   960
         TabIndex        =   5
         Top             =   720
         Width           =   2535
      End
      Begin VB.Label lblID 
         BorderStyle     =   1  'Fixed Single
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   960
         TabIndex        =   13
         Top             =   240
         Width           =   2535
      End
      Begin VB.Label Label2 
         Caption         =   "Name:"
         Height          =   375
         Left            =   120
         TabIndex        =   4
         Top             =   720
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "ID:"
         Height          =   375
         Left            =   240
         TabIndex        =   3
         Top             =   360
         Width           =   615
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "List of Publishers"
      Height          =   3375
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   3015
      Begin VSFlex7Ctl.VSFlexGrid grdPublisher 
         Height          =   3015
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   2775
         _cx             =   4895
         _cy             =   5318
         _ConvInfo       =   1
         Appearance      =   1
         BorderStyle     =   1
         Enabled         =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         MousePointer    =   0
         BackColor       =   -2147483643
         ForeColor       =   -2147483640
         BackColorFixed  =   -2147483633
         ForeColorFixed  =   -2147483630
         BackColorSel    =   -2147483635
         ForeColorSel    =   -2147483634
         BackColorBkg    =   -2147483636
         BackColorAlternate=   -2147483643
         GridColor       =   -2147483633
         GridColorFixed  =   -2147483632
         TreeColor       =   -2147483632
         FloodColor      =   192
         SheetBorder     =   -2147483642
         FocusRect       =   2
         HighLight       =   1
         AllowSelection  =   -1  'True
         AllowBigSelection=   0   'False
         AllowUserResizing=   0
         SelectionMode   =   0
         GridLines       =   1
         GridLinesFixed  =   2
         GridLineWidth   =   1
         Rows            =   1
         Cols            =   2
         FixedRows       =   1
         FixedCols       =   0
         RowHeightMin    =   0
         RowHeightMax    =   0
         ColWidthMin     =   0
         ColWidthMax     =   0
         ExtendLastCol   =   -1  'True
         FormatString    =   $"frmPublisher.frx":0000
         ScrollTrack     =   0   'False
         ScrollBars      =   3
         ScrollTips      =   0   'False
         MergeCells      =   0
         MergeCompare    =   0
         AutoResize      =   -1  'True
         AutoSizeMode    =   0
         AutoSearch      =   1
         AutoSearchDelay =   2
         MultiTotals     =   -1  'True
         SubtotalPosition=   1
         OutlineBar      =   0
         OutlineCol      =   0
         Ellipsis        =   0
         ExplorerBar     =   0
         PicturesOver    =   0   'False
         FillStyle       =   0
         RightToLeft     =   0   'False
         PictureType     =   0
         TabBehavior     =   0
         OwnerDraw       =   0
         Editable        =   0
         ShowComboButton =   -1  'True
         WordWrap        =   0   'False
         TextStyle       =   0
         TextStyleFixed  =   0
         OleDragMode     =   0
         OleDropMode     =   0
         DataMode        =   0
         VirtualData     =   -1  'True
         DataMember      =   ""
         ComboSearch     =   3
         AutoSizeMouse   =   -1  'True
         FrozenRows      =   0
         FrozenCols      =   0
         AllowUserFreezing=   0
         BackColorFrozen =   0
         ForeColorFrozen =   0
         WallPaperAlignment=   9
      End
   End
End
Attribute VB_Name = "frmPublisher"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Enum colPublisher
    colID = 0
    colName = 1
End Enum

Dim enumDBOperation As DatabaseOperation

Private Function CreateNewPublisherID() As Integer
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    cn.Open gblConnectionString
    
    With rs
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "SELECT MAX(PublisherID) as PublisherID FROM Publisher"
        
        If .RecordCount > 0 Then
            CreateNewPublisherID = rs!PublisherID + 1
        Else
            CreateNewPublisherID = 1
        End If
        
    End With
    
    Set cn = Nothing
    Set rs = Nothing
End Function

Private Function IsDuplicatePublisher() As Boolean
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    cn.Open gblConnectionString
    
    With rs
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        If enumDBOperation = Add Then
            .Open "SELECT PublisherID, PublisherName FROM Publisher WHERE UPPER(PublisherName)='" & UCase(Me.txtName.Text) & "'"
        Else
            .Open "SELECT PublisherID, PublisherName FROM Publisher WHERE UPPER(PublisherName)='" & UCase(Me.txtName.Text) & "' AND PublisherID <> " & Me.lblID.Caption
        End If
        
        IsDuplicatePublisher = False
        If .RecordCount > 0 Then
            IsDuplicatePublisher = True
        End If
    
    End With
    
    Set cn = Nothing
    Set rs = Nothing
End Function

Private Sub DeletePublisher()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    cn.Open gblConnectionString
    
    With rs
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "SELECT PublisherID, PublisherName FROM Publisher WHERE PublisherID=" & Me.lblID.Caption

        .Delete
        
    End With
    
    Set cn = Nothing
    Set rs = Nothing
End Sub

Private Sub UpdatePublisher()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    cn.Open gblConnectionString
    
    With rs
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "SELECT PublisherID, PublisherName FROM Publisher WHERE PublisherID=" & Me.lblID.Caption
        
        rs!PublisherName = UCase(Me.txtName.Text)
        .Update
        
    End With
    
    Set cn = Nothing
    Set rs = Nothing
End Sub

Private Sub SavePublisher()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    cn.Open gblConnectionString
    
    With rs
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "SELECT PublisherID, PublisherName FROM Publisher WHERE 1=0"
        
        .AddNew
        rs!PublisherID = Me.lblID.Caption
        rs!PublisherName = UCase(Me.txtName.Text)
        .Update
        
    End With
    
    Set cn = Nothing
    Set rs = Nothing
End Sub

Private Sub SetupControls()
    If enumDBOperation = None Then
        Me.grdPublisher.Enabled = True
        Me.txtName.Enabled = False
       
        Me.lblID.Caption = ""
        Me.txtName.Text = ""
    
        Me.cmdAdd.Enabled = True
        Me.cmdEdit.Enabled = True
        Me.cmdDelete.Enabled = True
        Me.cmdSave.Enabled = False
        Me.cmdCancel.Enabled = False
    
    ElseIf enumDBOperation = Add Then
        Me.grdPublisher.Enabled = False
        Me.txtName.Enabled = True
       
        Me.lblID.Caption = ""
        Me.txtName.Text = ""
    
        Me.cmdAdd.Enabled = False
        Me.cmdEdit.Enabled = False
        Me.cmdDelete.Enabled = False
        Me.cmdSave.Enabled = True
        Me.cmdCancel.Enabled = True
        
    ElseIf enumDBOperation = Edit Then
        Me.grdPublisher.Enabled = False
        Me.txtName.Enabled = True
       
        Me.cmdAdd.Enabled = False
        Me.cmdEdit.Enabled = False
        Me.cmdDelete.Enabled = False
        Me.cmdSave.Enabled = True
        Me.cmdCancel.Enabled = True
            
    End If
End Sub

Private Sub LoadPublisher()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim intRow As Integer
    
    cn.Open gblConnectionString
    
    With rs
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "SELECT PublisherID, PublisherName FROM Publisher"
    End With
    
    With grdPublisher
        .Rows = rs.RecordCount + 1
        For intRow = 1 To rs.RecordCount
            .TextMatrix(intRow, colID) = Format(rs!PublisherID, "000")
            .TextMatrix(intRow, colName) = rs!PublisherName
            rs.MoveNext
        Next intRow
    End With
    
    Set cn = Nothing
    Set rs = Nothing
End Sub


Private Sub cmdAdd_Click()
    enumDBOperation = Add
    SetupControls
    Me.lblID.Caption = Format(CreateNewPublisherID, "000")
End Sub

Private Sub cmdCancel_Click()
    Form_Load
End Sub

Private Sub cmdDelete_Click()
    If Me.lblID.Caption = "" Then
        MsgBox "Please select publisher to delete.", vbInformation + vbOKOnly, App.ProductName
        Exit Sub
    End If
    
    DeletePublisher
    MsgBox "Record Deleted.", vbInformation + vbOKOnly, App.ProductName
    
    Form_Load
End Sub

Private Sub cmdEdit_Click()
    If Me.lblID.Caption = "" Then
        MsgBox "Please select publisher to edit.", vbInformation + vbOKOnly, App.ProductName
        Exit Sub
    End If
    
    enumDBOperation = Edit
    SetupControls
End Sub

Private Sub cmdlClose_Click()
    Unload Me
End Sub

Private Sub cmdSave_Click()
    If Trim(Me.txtName.Text) = "" Then
        MsgBox "Publisher Name required.", vbInformation + vbOKOnly, App.ProductName
        Me.txtName.SetFocus
        Exit Sub
    ElseIf IsDuplicatePublisher = True Then
        MsgBox "Publisher Name already exists.", vbInformation + vbOKOnly, App.ProductName
        Me.txtName.SetFocus
        Exit Sub
    End If
    
    If enumDBOperation = Add Then
        SavePublisher
        MsgBox "Record Saved.", vbInformation + vbOKOnly, App.ProductName
    Else
        UpdatePublisher
        MsgBox "Record Updated.", vbInformation + vbOKOnly, App.ProductName
    End If
    
    Form_Load
End Sub

Private Sub Form_Load()
    enumDBOperation = None
    SetupControls
    LoadPublisher
End Sub

Private Sub grdPublisher_Click()
    With grdPublisher
        Me.lblID.Caption = .TextMatrix(.Row, colID)
        Me.txtName.Text = .TextMatrix(.Row, colName)
    End With
End Sub

Private Sub grdPublisher_EnterCell()
    grdPublisher_Click
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -