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

📄 form1.vb

📁 基于vb.net的简单通信录
💻 VB
📖 第 1 页 / 共 5 页
字号:
                Else
                    If txtName.Text = "" Then
                        MessageBox.Show("名字不能为空,请填写名字", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                        txtName.Focus()
                        Exit Sub
                    ElseIf txtTel.Text = "" Then
                        MessageBox.Show("电话号码不能为空,请添加电话号码", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                        txtName.Focus()
                        Exit Sub
                    End If
                    If txtTel.Text.Length <> 12 Or txtTel.Text.Length <> 11 Then
                        MessageBox.Show("非法电话号码,电话号码应为11位数,请重新填写电话号码", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                        'txtTel.a '//获得焦点
                        txtTel.Text = ""
                        txtTel.Focus()
                        Exit Sub
                    End If
                End If
            Else
                '//
                MessageBox.Show("非法年龄或没有添加,请重新修改或添加年龄", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtage.Text = ""
                txtage.Focus()
            End If
        Else
            MessageBox.Show("非法性别或为空,请重新填写性别", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If
    End Sub

    Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
        If intcount >= 1 Then
            showCustom(_customers.Item(intcount - 1))
            ListBox1.SetSelected(intcount - 1, True)            '//设置被选中
            intcount = intcount - 1
        Else
            Try
                intcount = ListBox1.Items.Count - 1
                showCustom(_customers.Item(intcount))
                ListBox1.SetSelected(intcount, True)             '//设置被选中
                'intcount = intcount - 1
            Catch
                '//
            End Try
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If intcount < ListBox1.Items.Count - 1 Then
            showCustom(_customers.Item(intcount + 1))
            ListBox1.SetSelected(intcount + 1, True)         '//设置被选中
            intcount = intcount + 1
        Else
            Try
                intcount = 0
                showCustom(_customers.Item(intcount))
                ListBox1.SetSelected(intcount, True)             '//设置被选中
                'intcount = intcount - 1
            Catch
                '//
            End Try
        End If
    End Sub

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        btnAdd_Click(Nothing, Nothing)
    End Sub




    Private Sub btnInsertOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertOk.Click
        '//插入操作
        Dim customer As Custom
        Dim i As Integer
        If txtSex.Text <> "男" And txtSex.Text <> "女" Then
            MessageBox.Show("非法性别或为空,请重新填写性别", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If
        Try
            Dim j As Integer
            j = Val(txtage.Text)
        Catch ex As Exception
            MessageBox.Show("年龄输入有误或非法年龄,请重新输入.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
            tblInsertOk.Enabled = True
            Exit Sub
        End Try
        If Val(txtage.Text) < 120 And Val(txtage.Text) > 0 Then
            If txtName.Text <> "" And txtTel.Text <> "" And txtTel.Text.Length = 12 Or txtTel.Text.Length = 11 Then
                ischange = True
                _CreatCustom(txtName.Text, txtTel.Text, txtmovebal.Text, txtEmail.Text, txtaddress.Text, txtage.Text, txtbirthday.Text, txtSex.Text, txtCompany.Text, txtQQ.Text)
                '//插入
                ListBox1.SetSelected(intcount, True) '//被选中
                'savefile()
                _customers.TrimToSize()         '//重新排列
                'Kill(Application.StartupPath & "\" & _name & "save.snm")      '//删除原始文件
                'For i = 0 To ListBox1.Items.Count - 1
                'printfile(_customers.Item(i))           '//重写记录
                '//调用创建用户函数/方法
                'Next i
                Sta.Panels.Item(1).Text = "请及时保存更改"
                LockText()
            Else
                If txtName.Text = "" Then
                    MessageBox.Show("名字不能为空,请添加名字", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    txtName.Focus()
                    Exit Sub
                ElseIf txtTel.Text = "" Then
                    MessageBox.Show("电话号码不能为空,请添加电话号码", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    txtTel.Focus()
                    Exit Sub
                End If
                If txtTel.Text.Length <> 11 Then
                    MessageBox.Show("非法电话号码,电话号码应为11位数,请重新填写电话号码", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    'txtTel.a '//获得焦点
                    txtTel.Text = ""
                    txtTel.Focus()
                    Exit Sub
                End If
            End If
        Else
            '//
            MessageBox.Show("非法年龄或没有添加,请重新修改或添加年龄", "添加错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtage.Text = ""
            txtage.Focus()
        End If
    End Sub



    Private Sub txtName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtName.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 13 Then
            txtage.Focus()
            txtage.SelectAll() ' = txtbirthday.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub txtTel_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTel.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 13 Then
            txtmovebal.Focus()
            txtmovebal.SelectAll() ' = txtmovebal.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub txtmovebal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtmovebal.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 13 Then
            txtEmail.Focus()
            txtEmail.SelectAll() ' = txtEmail.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub txtEmail_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEmail.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 13 Then
            txtaddress.Focus()
            txtaddress.SelectAll() ' = txtaddress.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub txtaddress_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtaddress.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 13 Then
            txtQQ.Focus()
            txtQQ.SelectAll() ' = txtage.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub txtage_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtage.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        If KeyAscii = 13 Then
            txtbirthday.Focus()
            txtbirthday.SelectAll() ' = txtName.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub mnuLook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLook.Click
        '//查看
        If ListBox1.SelectedIndex <> -1 Then
            ListBox1_Click(Nothing, Nothing)
        Else
            MessageBox.Show("无法查看,没有选中查看项", "查看", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        End If
        'showCustom(_customers.Item(ListBox1.SelectedIndex))
        'intcount = ListBox1.SelectedIndex
    End Sub


    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        '//重置记录
        If ListBox1.Items.Count >= 1 Then
            If MessageBox.Show("是否清除所有记录,清除后将不可恢复", "清空", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
errline:        Try
                    ListBox1.Items.Clear()            '//全部置空
                    _customers.Clear()
                    intcount = 0
                    Kill(Application.StartupPath & "\save\" & _name & "save.snm")    '//删除文件
                    ClearText()
                Catch
                    '//
                    If MessageBox.Show("操作失败,要重试请按重试,否则请按取消。", "重试", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) = DialogResult.Retry Then
                        GoTo errline
                    Else
                        '//
                    End If
                End Try
            Else
                '//取消操作
            End If
        Else
            '//集合无记录
            MessageBox.Show("无记录轻空失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click
        btnAdd_Click(Nothing, Nothing)
        LockEnable()
        mnuAddOk.Enabled = True
        ToolBar1.Buttons.Item(1).Enabled = True
    End Sub

    Private Sub mnuAddOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddOk.Click
        btnAddOk_Click(Nothing, Nothing)
        LockEnable()
        mnuAddOk.Enabled = False
        ToolBar1.Buttons.Item(1).Enabled = False
    End Sub

    Private Sub mnuInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInsert.Click
        btnInsert_Click(Nothing, Nothing)
        LockEnable()
        mnuInsertOk.Enabled = True
        ToolBar1.Buttons.Item(4).Enabled = True
    End Sub

    Private Sub mnuInsertOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInsertOk.Click
        btnInsertOk_Click(Nothing, Nothing)
        LockEnable()
        mnuInsertOk.Enabled = False
        ToolBar1.Buttons.Item(4).Enabled = False
    End Sub
    Public Sub printfile(ByVal customer As Custom)
        FileOpen(1, Application.StartupPath & "\save\" & _name & "save.snm", OpenMode.Append)
        '//追加式写入文件
        PrintLine(1, customer.name & "," & customer.tel & "," & customer.movebal & "," & customer.email & "," & _
 customer.address & "," & customer.age & "," & customer.birthday & "," & customer.sex & "," & customer.company & "," & customer.qq)
        FileClose()
    End Sub
    Private Sub mnuRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRemove.Click
        '//删除当前项
        'On Error Resume Next
        Dim filename As String = Application.StartupPath & "\save\" & _name & "save.snm"
        'Dim reader As StreamReader = New StreamReader(filename)
        Dim userfile As String
        Dim i As Integer
        Dim _intcount = ListBox1.Items.Count - 1
        '//更改信息
        If ListBox1.SelectedIndex <> -1 Then
            Try
                If MessageBox.Show("是否删除" & ListBox1.Items.Item(intcount) & "这个记录,删除后将不可恢复", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
                    ListBox1.Items.RemoveAt(intcount)    '//从列表中删除
                    _customers.RemoveAt(intcount)
                    _customers.TrimToSize()             '//重新排列
                    'Try                                                 '//错误处理
                    ' FileOpen(4, filename, OpenMode.Output)
                    ' Kill(filename)                        '//删除原始文件
                    'For i = 0 To _intcount - 1
                    'userfile = '_customers.GetEnumerator.Current
                    'Print(1, userfile)
                    'printfile(_customers.Item(i))       '//写入文件
                    'Next
                    'FileClose()
                    ischange = True                      '//改动为真
                    intcount = 0
                    ListBox1.SetSelected(0, True)
                    showCustom(_customers.Item(intcount))
                    'Catch

                    'End Try
                Else            '//取消删除操作
                End If
            Catch
                '//
                ClearText()
                Exit Sub
    

⌨️ 快捷键说明

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