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

📄 form1.vb

📁 基于vb.net的简单通信录
💻 VB
📖 第 1 页 / 共 5 页
字号:
        newcustom.tel = tel
        newcustom.movebal = movebal
        newcustom.email = email
        newcustom.address = address
        newcustom.age = age
        newcustom.birthday = birthday
        newcustom.sex = sex
        newcustom.company = company
        newcustom.qq = qq
        Try
            _customers.Insert(intcount, newcustom)
            ' custromCollection.add(newcustom)          '//查询
            'ListBox1.Items.Add(newcustom.name)
            ListBox1.Items.Insert(intcount, newcustom.name)
            'showCustom(newcustom)
            Return newcustom
        Catch
        End Try
    End Function
    Private Sub ClearText()  '//置空
        txtName.Text = ""
        txtTel.Text = ""
        txtmovebal.Text = ""
        txtaddress.Text = ""
        txtEmail.Text = ""
        txtbirthday.Text = ""
        txtage.Text = ""
        txtSex.Text = ""
        txtCompany.Text = ""
        txtQQ.Text = ""
    End Sub
    Private Sub LockText()   '//锁定
        txtName.ReadOnly = True
        txtTel.ReadOnly = True
        txtmovebal.ReadOnly = True
        txtaddress.ReadOnly = True
        txtEmail.ReadOnly = True
        txtbirthday.ReadOnly = True
        txtage.ReadOnly = True
        txtSex.ReadOnly = True
        txtCompany.ReadOnly = True
        txtQQ.ReadOnly = True
    End Sub
    Private Sub UnLockText()  '//解锁
        txtName.ReadOnly = False
        txtTel.ReadOnly = False
        txtmovebal.ReadOnly = False
        txtaddress.ReadOnly = False
        txtEmail.ReadOnly = False
        txtbirthday.ReadOnly = False
        txtage.ReadOnly = False
        txtSex.ReadOnly = False
        txtCompany.ReadOnly = False
        txtQQ.ReadOnly = False
    End Sub
    Public Function FindFile()           '//查找文件
        ' Dim a As String
        'On Error Resume Next
        ' FileOpen(1, "save.txt", OpenMode.Input)
        'Do While Not EOF(1)
        'Inp'ut(1, a)
        'ListBox1.Items.Add(a)
        'TextBox1.Text = a
        'Loop
        'ListBox1.Items.Add(System.Reflection.Assembly.GetExecutingAssembly.Location())
        'FileClose()
        Dim _form As New Form3
        '_name = _form.ComboBox1.Items.Item(0)
        Dim nameonly As String
        nameonly = Application.StartupPath & "\save\" & _name & "save.snm"
        Dim fileinfo As New FileInfo(nameonly)
        If fileinfo.Exists = True Then               '//判断文件是否存在
            Return True
        Else
            Return False
        End If

    End Function
    Public Sub readFile()
        Dim _allname As String
        Dim _tel As String
        Dim _movebal As String
        Dim _email As String
        Dim _address As String
        Dim _age As Integer
        Dim _birthday As String
        Dim _sex As String
        Dim _company As String
        Dim _qq As String
        Dim intposion As Integer
        Dim filename As String
        filename = Application.StartupPath & "\save\" & _name & "save.snm"
        '//读写文件
        Try
            FileOpen(1, filename, OpenMode.Input)
            Do While Not EOF(1)
                Input(1, _allname)
                Input(1, _tel)
                Input(1, _movebal)
                Input(1, _email)
                Input(1, _address)
                Input(1, _age)
                Input(1, _birthday)
                Input(1, _sex)
                Input(1, _company)
                Input(1, _qq)
                'Input(1, intposion)
                addfile(_allname, _tel, _movebal, _email, _address, _age, _birthday, _sex, _company, _qq)
            Loop
            FileClose(1)
        Catch
            Exit Sub
        End Try
    End Sub
    Public Function addfile(ByVal _allname As String, ByVal _tel As String _
    , ByVal _movebal As String, ByVal _email As String, ByVal _address As String _
    , ByVal _age As Integer, ByVal _birthday As String, ByVal _sex As String, ByVal _company As String, ByVal _qq As String)
        '//添加信息到列表
        CreatCustom(_allname, _tel, _movebal, _email, _address, _age, _birthday, _sex, _company, _qq)
    End Function
    Public Sub savefile()
        '//保存函数
        Dim _savefile As String
        Dim filename As String
        _savefile = txtName.Text & "," & txtTel.Text & "," & txtmovebal.Text & "," & txtEmail.Text & "," & _
        txtaddress.Text & "," & txtage.Text & "," & txtbirthday.Text & "," & txtSex.Text & "," & txtCompany.Text & "," & txtQQ.Text  '& vbCrLf '+ vbCrLf
        filename = Application.StartupPath & "\save\" & _name & "save.snm"
        FileOpen(2, filename, OpenMode.Append)
        PrintLine(2, _savefile) '& Chr(10) + Chr(13))            '//以行的形式写入
        FileClose()
    End Sub
    Public Sub loadfile(ByVal _filename As String)
        Dim per As New persons
        Dim i As Integer
        Dim customer() As Custom
        If infofile = "Binary" Then
            Dim derstior As New SerializationBinary
            per = derstior.DeserialiaeIt(_filename)
            customer = per.ArrayPerson
            For i = 0 To customer.Length
                _customers.Add(customer(i))
                ListBox1.Items.Add(customer(i).name)
            Next
        ElseIf infofile = "XML" Then
            Dim derstior As New SerializationXML
            per = derstior.DeserialiaeIt(_filename)
            customer = per.ArrayPerson
            For i = 0 To customer.Length
                _customers.Add(customer(i))
                ListBox1.Items.Add(customer(i).name)
            Next
        ElseIf infofile = "Soap" Then
            Dim derstior As New SerializationSoap
            per = derstior.DeserialiaeIt(_filename)
            customer = per.ArrayPerson
            For i = 0 To customer.Length
                _customers.Add(customer(i))
                ListBox1.Items.Add(customer(i).name)
            Next
        End If
        'CreatCustom("hongye", "07967851414", "135", "hongyelzg@yahoo.com.cn", "南昌市", 20, "1984.10.23", "男", "南昌市")
        
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim newcustom As Custom
        On Error Resume Next
        Dim form As New Form3
        Dim form1 As New Form1
        'form.Focus()
        'form.Close()
        'form.ActiveForm.Close()
        Dim frm As New frmSave
        Dim info As New frmSave.配置信息
        Dim Der As New frmSave.SerializationBinary
        Dim file_name As String = Application.StartupPath & "\save\配置文件.ini"
        Dim file_info As New FileInfo(file_name)
        If file_info.Exists Then
            info = Der.DeserialiaeIt(file_name)
            infofile = info.保存设置
            If infofile = "" Then
                infofile = "Binary"
            End If
            'Debug.WriteLine(infofile)
        Else
            infofile = "Binary"
        End If

        Dim filename As String = Application.StartupPath & "\Save"
        Dim fileinfo As New FileInfo(filename)
        If fileinfo.Exists = False Then
            MkDir(Application.StartupPath & "\save")
            File.SetAttributes(Application.StartupPath & "\save", FileAttributes.Hidden) '+ FileAttributes.Hidden + FileAttributes.ReadOnly)
        Else
            '//
        End If
        ListBox1.Items.Clear()      '//清空列表
        ClearText()                '//将文本框置空
        LockText()                 '//锁定文本框
        Sta.Panels.Item(2).Text = System.DateTime.Today
        Sta.Panels.Item(1).Text = "欢迎使用红叶通讯录"
        form.ShowDialog()
        If isok = True Then
errline:    _name = form.ComboBox1.Text         '//重新读入 errline
            Dim _filename As String = filename & "\" & _name & "save.snm"
            If FindFile() = True Then
                '***///readFile()                  '//读入文件
                loadfile(_filename)
                'showCustom(_customers.Item(0))
                showCustom(_customers.Item(0))
                intcount = 0             '//初始化
                'custromCollection.add()

                ListBox1.SetSelected(0, True)
            Else
                '//Exit Sub
                UnLockText()
            End If
            FileClose()
            mnuAddOk.Enabled = False
            mnuInsertOk.Enabled = False
            'mnuremove
            mnuZiuGaiOk.Enabled = False
            ToolBar1.Buttons.Item(1).Enabled = False
            ToolBar1.Buttons.Item(4).Enabled = False
            ToolBar1.Buttons.Item(7).Enabled = False
        Else
            form.ShowDialog()
            If isok = False Then
                If MessageBox.Show("由于密码错误,按确定将进入界面不显示任何信息,,按取消退出程序", "密码错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) = DialogResult.OK Then
                    '//进入界面
                    '//
                    _name = ""
                    '//变量为空
                    form1.ActiveForm.Enabled = False
                    '//防止更改记录
                Else
                    End              '//退出
                End If
            Else
                GoTo errline         '//密码正确读入数据
            End If
        End If
        'form.ShowDialog()
        'form1.Text = "红叶通讯录—" & _name
    End Sub
    Public Sub showCustom(ByVal newcustom As Custom)
        '//显示查询用户
        txtName.Text = newcustom.name
        txtTel.Text = newcustom.tel
        txtmovebal.Text = newcustom.movebal
        txtaddress.Text = newcustom.address
        txtEmail.Text = newcustom.email
        txtbirthday.Text = newcustom.birthday
        txtage.Text = newcustom.age
        txtSex.Text = newcustom.sex
        txtCompany.Text = newcustom.company
        txtQQ.Text = newcustom.qq
    End Sub

    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        '//查找
        Dim findname As String
        Dim foundcustom As Custom
        findname = InputBox("该搜索是以姓名为索引的" & Chr(10) + Chr(13) & "请输入要搜索的姓名", "搜索")
        If findname = "" Then
            MessageBox.Show("查询项为空或选择了取消,查询失败!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If
        Dim i As Integer
        Dim intfind As Integer
        Dim strfind As Boolean = False
        For i = 0 To ListBox1.Items.Count - 1
            ListBox1.SetSelected(i, True)
            If ListBox1.Items.Item(i) = findname Then
                strfind = True
                intfind = i
                Exit For
            End If
        Next
        If strfind = True Then
            foundcustom = _customers.Item(intfind)
            If MessageBox.Show("姓名为" & findname & "用户已找到,是否显示结果", "已查找到", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then
                showCustom(foundcustom)           '//显示记录
                LockText()
            Else
                '//doevents()
            End If
        Else
            MessageBox.Show("姓名为" & findname & "的用户不存在.", "未查找到", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        End If
    End Sub


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        ClearText()
        UnLockText()
        txtName.Focus()
    End Sub


    Private Sub btnAddOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddOk.Click
        'CreatCustom("hongye", "07967851414", "135", "hongyelzg@yahoo.com.cn", "南昌市", 20, "1984.10.23")
        Try
            Dim j As Integer
            j = Val(txtage.Text)
        Catch ex As Exception
            MessageBox.Show("年龄输入有误或非法年龄,请重新输入.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
            tblAddOk.Enabled = True
            Exit Sub
        End Try
        If txtSex.Text = "男" Or txtSex.Text = "女" Then
            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)
                    intcount = ListBox1.Items.Count - 1
                    ListBox1.SetSelected(intcount, True)
                    ' savefile()                            '//保存
                    Sta.Panels.Item(1).Text = "请及时保存更改"
                    LockText()

⌨️ 快捷键说明

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