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

📄 form1.vb

📁 小小通讯录程序 用Access作为数据库
💻 VB
📖 第 1 页 / 共 4 页
字号:
        '
        Me.MenuItem10.Index = 2
        Me.MenuItem10.Text = "上一条(&P)"
        '
        'MenuItem11
        '
        Me.MenuItem11.Index = 3
        Me.MenuItem11.Text = "下一条(&T)"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 2
        Me.MenuItem3.Text = "About..."
        '
        'MenuItem13
        '
        Me.MenuItem13.Index = 3
        Me.MenuItem13.Text = ""
        '
        'RichTextBox1
        '
        Me.RichTextBox1.Location = New System.Drawing.Point(8, 288)
        Me.RichTextBox1.Name = "RichTextBox1"
        Me.RichTextBox1.ReadOnly = True
        Me.RichTextBox1.Size = New System.Drawing.Size(312, 104)
        Me.RichTextBox1.TabIndex = 26
        Me.RichTextBox1.TabStop = False
        Me.RichTextBox1.Text = ""
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(120, 400)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(80, 24)
        Me.Button2.TabIndex = 27
        Me.Button2.Text = "关闭查看"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(264, 256)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(56, 24)
        Me.Button3.TabIndex = 28
        Me.Button3.TabStop = False
        Me.Button3.Text = "退出(&Q)"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(200, 256)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(56, 24)
        Me.Button4.TabIndex = 29
        Me.Button4.TabStop = False
        Me.Button4.Text = "取消(&U)"
        '
        'OleDbCommand2
        '
        Me.OleDbCommand2.Connection = Me.OleDbConnection1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(328, 286)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.RichTextBox1)
        Me.Controls.Add(Me.TextBox11)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox10)
        Me.Controls.Add(Me.TextBox9)
        Me.Controls.Add(Me.TextBox8)
        Me.Controls.Add(Me.TextBox7)
        Me.Controls.Add(Me.TextBox6)
        Me.Controls.Add(Me.TextBox5)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ToolBar1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "通讯录"
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public shar As New about
    Dim i As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        OleDbDataAdapter1.Fill(DataSet11)
        TextBox11.Focus()
    End Sub

    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case 0
                TextBox1.ReadOnly = False
                TextBox2.ReadOnly = False
                TextBox3.ReadOnly = False
                TextBox4.ReadOnly = False
                TextBox5.ReadOnly = False
                TextBox6.ReadOnly = False
                TextBox7.ReadOnly = False
                TextBox8.ReadOnly = False
                TextBox9.ReadOnly = False
                TextBox10.ReadOnly = False
                Me.BindingContext(DataSet11, "Ad_book").AddNew()
                i = 0
            Case 1

                If TextBox1.ReadOnly = False Then
                    Select Case i
                        Case 0
                            If TextBox1.Text = "" Then
                                MsgBox("姓名不能为空哦")
                                Exit Sub
                            Else
                                Me.OleDbConnection1.Open()
                                Me.OleDbCommand2.CommandText = String.Format("INSERT INTO Ad_book(姓名,年龄,生日,性别,联系电话,email,工作单位,地址,手机,QQ) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text, TextBox6.Text, TextBox7.Text)
                                Try
                                    Me.OleDbCommand2.ExecuteNonQuery()
                                    MsgBox("保存成功")
                                Catch ex As Exception
                                    MsgBox(ex.Message)
                                Catch ex As Exception
                                End Try
                                Me.OleDbConnection1.Close()
                                TextBox1.ReadOnly = True
                                TextBox2.ReadOnly = True
                                TextBox3.ReadOnly = True
                                TextBox4.ReadOnly = True
                                TextBox5.ReadOnly = True
                                TextBox6.ReadOnly = True
                                TextBox7.ReadOnly = True
                                TextBox8.ReadOnly = True
                                TextBox9.ReadOnly = True
                                TextBox10.ReadOnly = True
                            End If
                        Case 1
                            Me.OleDbConnection1.Open()
                            Try
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 姓名= ('{0}')", TextBox1.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 年龄= ('{0}')", TextBox2.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 生日= ('{0}')", TextBox3.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 性别= ('{0}')", TextBox4.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 联系电话= ('{0}')", TextBox5.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET email= ('{0}')", TextBox8.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 工作单位= ('{0}')", TextBox9.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 地址= ('{0}')", TextBox10.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET 手机= ('{0}')", TextBox6.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                                Me.OleDbCommand2.CommandText = String.Format("UPDATE Ad_book SET QQ= ('{0}')", TextBox7.Text)
                                Me.OleDbCommand2.ExecuteNonQuery()
                            
                            Catch ex As Exception
                            End Try
                            Me.OleDbConnection1.Close()
                            MsgBox("保存成功")
                            TextBox1.ReadOnly = True
                            TextBox2.ReadOnly = True
                            TextBox3.ReadOnly = True
                            TextBox4.ReadOnly = True
                            TextBox5.ReadOnly = True
                            TextBox6.ReadOnly = True
                            TextBox7.ReadOnly = True
                            TextBox8.ReadOnly = True
                            TextBox9.ReadOnly = True
                            TextBox10.ReadOnly = True

                    End Select
                End If





                    Case 2
                    If TextBox1.Text <> "" Then
                        TextBox1.ReadOnly = False
                        TextBox2.ReadOnly = False
                        TextBox3.ReadOnly = False
                        TextBox4.ReadOnly = False
                        TextBox5.ReadOnly = False
                        TextBox6.ReadOnly = False
                        TextBox7.ReadOnly = False
                        TextBox8.ReadOnly = False
                        TextBox9.ReadOnly = False
                        TextBox10.ReadOnly = False
                        i = 1
                    End If

                    Case 3
                If Me.BindingContext(DataSet11, "Ad_book").Count <> 0 Then
                    If MsgBox("是否删除该记录", MsgBoxStyle.OKCancel, "删除") = MsgBoxResult.OK Then

                        Me.OleDbConnection1.Open()
                        Try
                            Me.OleDbCommand2.CommandText = String.Format("DELETE FROM Ad_book WHERE 姓名= ('{0}')", TextBox1.Text)
                            Me.OleDbCommand2.ExecuteNonQuery()
                        Catch ex As Exception
                            MsgBox(ex.Message)
                        Catch ex As Exception
                        End Try
                        Me.OleDbConnection1.Close()
                        DataSet11.Clear()
                        OleDbDataAdapter1.Fill(DataSet11)
                    End If
                End If
                    Case 4
                    If TextBox1.ReadOnly = True Then
                        Me.BindingContext(DataSet11, "Ad_book").Position = 0
                    End If
                    Case 5
                 
                    If TextBox1.ReadOnly = True Then
                        Try
                            Me.BindingContext(DataSet11, "Ad_book").Position -= 1
                        Catch a As Exception
                        End Try
                    End If

                    Case 6
                 
                    If TextBox1.ReadOnly = True Then
                        Try
                            Me.BindingContext(DataSet11, "Ad_book").Position += 1
                        Catch a As Exception
                        End Try
                    End If

                    Case 7
                    If TextBox1.ReadOnly = True Then
                        Me.BindingContext(DataSet11, "Ad_book").Position = Me.BindingContext(DataSet11, "Ad_book").Count - 1
                    End If
                End Select

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        OleDbDataAdapter1.Fill(DataSet11)
        Dim fd As String = TextBox11.Text
        Dim dr As DataRow = DataSet11.Ad_book.Rows.Find(fd)
        If dr Is Nothing Then
            MsgBox("没有该联系人")
        Else
            RichTextBox1.Text = ""
            Me.Height = 472
            RichTextBox1.Text = "姓名:" & dr("姓名") & Chr(10) & "性别:" & dr("性别") & Chr(10) & "年龄:" & dr("年龄") & Chr(10) _
          & "生日:" & dr("生日") & Chr(10) & "联系电话:" & dr("联系电话") & Chr(10) & "手机:" & dr("手机") & Chr(10) & "QQ:" & dr("QQ") & Chr(10) & "E-mail:" & dr("email") & Chr(10) & "工作单位:" & dr("工作单位") & Chr(10) & "地址:" & dr("地址") & Chr(10)
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

⌨️ 快捷键说明

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