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

📄 frmaddtradecategory.frm

📁 这是一个用VB编写的用于外贸行业的供应商信息管理系统。
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmAddTradeCategory 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "AddTradeCategory"
   ClientHeight    =   5160
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8400
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5160
   ScaleWidth      =   8400
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton btnBack 
      Caption         =   "Back"
      Height          =   375
      Left            =   4800
      TabIndex        =   10
      Top             =   4680
      Width           =   1095
   End
   Begin VB.OptionButton Option2 
      Caption         =   "&category"
      Height          =   375
      Left            =   3600
      TabIndex        =   7
      Top             =   3000
      Width           =   1095
   End
   Begin VB.OptionButton Option1 
      Caption         =   "&trade"
      Height          =   255
      Left            =   3600
      TabIndex        =   6
      Top             =   2400
      Value           =   -1  'True
      Width           =   855
   End
   Begin VB.CommandButton btnAdd 
      Caption         =   "Add"
      Default         =   -1  'True
      Height          =   375
      Left            =   2280
      TabIndex        =   8
      Top             =   4680
      Width           =   1095
   End
   Begin VB.ListBox lstTrade 
      Height          =   3300
      Left            =   480
      TabIndex        =   2
      Top             =   1200
      Width           =   2895
   End
   Begin VB.TextBox txtCategoryName 
      Height          =   375
      Left            =   5760
      TabIndex        =   4
      Top             =   600
      Width           =   2055
   End
   Begin VB.ListBox lstCategory 
      Height          =   3300
      Left            =   4800
      TabIndex        =   5
      Top             =   1200
      Width           =   3015
   End
   Begin VB.TextBox txtTradeName 
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Top             =   600
      Width           =   1935
   End
   Begin VB.Label Label5 
      Caption         =   "Add Trade or Category"
      BeginProperty Font 
         Name            =   "Lucida Calligraphy"
         Size            =   14.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1920
      TabIndex        =   9
      Top             =   120
      Width           =   4455
   End
   Begin VB.Label Label2 
      Caption         =   "category_name:"
      Height          =   375
      Left            =   4440
      TabIndex        =   3
      Top             =   720
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "trade_name:"
      Height          =   375
      Left            =   360
      TabIndex        =   0
      Top             =   720
      Width           =   1095
   End
End
Attribute VB_Name = "frmAddTradeCategory"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public cn As New ADODB.Connection
Public rs1 As New ADODB.Recordset
Public rs2 As New ADODB.Recordset
Dim curPoint As Integer
Dim curPoint1 As Integer
Dim tradeName As String
Dim categoryName As String



Private Sub showTradeData()
    Dim i As Integer
    rs1.Open "trade", cn, adOpenKeyset, adLockOptimistic, adCmdTable
    For i = 1 To rs1.RecordCount
        lstTrade.AddItem (rs1.Fields("trade_name"))
        rs1.MoveNext
    Next i
    rs1.Close
End Sub

Private Sub showCategoryData()
    tradeName = lstTrade.List(curPoint)
    txtTradeName.Text = tradeName
    'clear listbox
    lstCategory.Clear
    'add fit's  items
    rs2.Open "select * from category where trade_name='" & tradeName & "'", cn, adOpenDynamic
    While Not rs2.EOF
        lstCategory.AddItem (rs2.Fields("category_name"))
        rs2.MoveNext
    Wend
    rs2.Close
    txtCategoryName.Text = lstCategory.List(curPoint1)
    categoryName = txtCategoryName.Text
End Sub

Private Sub btnAdd_Click()
    rs1.Open "trade", cn, adOpenKeyset, adLockOptimistic, adCmdTable
    rs2.Open "category", cn, adOpenKeyset, adLockOptimistic, adCmdTable
    If Option1.Value = True Then
        If txtTradeName.Text > "" Then
            rs1.Find "trade_name='" & txtTradeName.Text & "'"
            If Not rs1.EOF Then
                MsgBox "This trade is already exist, can not be added!", vbExclamation, "add error"
                rs1.Close
                rs2.Close
                Exit Sub
            End If
            rs1.AddNew
            rs1.Fields("trade_name") = txtTradeName.Text
            rs1.Update
            lstTrade.AddItem (txtTradeName.Text)
            txtTradeName.Text = ""
            txtTradeName.SetFocus
        End If
    Else
        If txtCategoryName.Text > "" Then
            rs2.Find "category_name='" & txtCategoryName.Text & "'"
            If Not rs2.EOF Then
                If rs2.Fields("trade_name") = txtTradeName.Text Then
                    MsgBox "This category is already exist, can not be added!", vbExclamation, "add error"
                    rs1.Close
                    rs2.Close
                    Exit Sub
                End If
            End If
            rs2.AddNew
            rs2.Fields("category_name") = txtCategoryName.Text
            rs2.Fields("trade_name") = txtTradeName.Text
            rs2.Update
            lstCategory.AddItem (txtCategoryName.Text)
            txtCategoryName.Text = ""
            txtCategoryName.SetFocus
        End If
    End If
    rs1.Close
    rs2.Close
End Sub

Private Sub btnBack_Click()
    Unload Me
End Sub

Private Sub Form_Activate()
    curPoint1 = 0
    curPoint = 0
    Set cn = New ADODB.Connection
    cn.Open strCn
    Set rs1 = New ADODB.Recordset
    Set rs2 = New ADODB.Recordset
    showTradeData
    showCategoryData
    canTrade
End Sub

Private Sub canCategory()
    txtTradeName.Enabled = False
    txtCategoryName.Enabled = True
    txtCategoryName.SetFocus
End Sub

Private Sub canTrade()
    txtTradeName.Enabled = True
    txtCategoryName.Enabled = False
    txtTradeName.SetFocus
End Sub

Private Sub Form_Unload(Cancel As Integer)
    cn.Close
End Sub

Private Sub lstCategory_Click()
    curPoint1 = lstCategory.ListIndex
    txtCategoryName.Text = lstCategory.List(curPoint1)
End Sub

Private Sub lstTrade_Click()
    curPoint = lstTrade.ListIndex
    showCategoryData
End Sub

Private Sub Option1_Click()
    If Option1.Value = True Then
        canTrade
    ElseIf Option2.Value = True Then
        canCategory
    End If
End Sub

Private Sub Option2_Click()
    If Option1.Value = True Then
        canTrade
    ElseIf Option2.Value = True Then
        canCategory
    End If
End Sub

Private Sub txtCategoryName_GotFocus()
    txtCategoryName.SelStart = 0
    txtCategoryName.SelLength = Len(txtCategoryName.Text)
End Sub

Private Sub txtTradeName_GotFocus()
    txtTradeName.SelStart = 0
    txtTradeName.SelLength = Len(txtTradeName.Text)
End Sub
Private Sub txtTradename_LostFocus()
    If Len(txtTradeName.Text) > 50 Then
        MsgBox "the length of tradename need less 50.", vbCritical, "over length error"
    End If
End Sub

Private Sub txtCategoryName_LostFocus()
    If Len(txtCategoryName.Text) > 50 Then
        MsgBox "the length of categoryname need less 50.", vbCritical, "over length error"
    End If
End Sub

⌨️ 快捷键说明

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