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

📄 form1.vb

📁 采用VB编写的机房管理系统
💻 VB
字号:
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading

Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim socket As Socket
    Dim logined As Boolean = False

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents BtLogin As System.Windows.Forms.Button
    Friend WithEvents BtCancel As System.Windows.Forms.Button
    Friend WithEvents TxtIDOrder As System.Windows.Forms.TextBox
    Friend WithEvents TxtPassword As System.Windows.Forms.TextBox
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents NotifyIcon1 As System.Windows.Forms.NotifyIcon
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.BtLogin = New System.Windows.Forms.Button
        Me.BtCancel = New System.Windows.Forms.Button
        Me.TxtIDOrder = New System.Windows.Forms.TextBox
        Me.TxtPassword = New System.Windows.Forms.TextBox
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(296, 208)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 32)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "编号"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(296, 280)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 32)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "密码"
        '
        'BtLogin
        '
        Me.BtLogin.Location = New System.Drawing.Point(296, 360)
        Me.BtLogin.Name = "BtLogin"
        Me.BtLogin.Size = New System.Drawing.Size(96, 40)
        Me.BtLogin.TabIndex = 2
        Me.BtLogin.Text = "登陆"
        '
        'BtCancel
        '
        Me.BtCancel.Location = New System.Drawing.Point(464, 360)
        Me.BtCancel.Name = "BtCancel"
        Me.BtCancel.Size = New System.Drawing.Size(104, 40)
        Me.BtCancel.TabIndex = 3
        Me.BtCancel.Text = "退出"
        '
        'TxtIDOrder
        '
        Me.TxtIDOrder.Location = New System.Drawing.Point(416, 208)
        Me.TxtIDOrder.Name = "TxtIDOrder"
        Me.TxtIDOrder.Size = New System.Drawing.Size(168, 21)
        Me.TxtIDOrder.TabIndex = 4
        Me.TxtIDOrder.Text = ""
        '
        'TxtPassword
        '
        Me.TxtPassword.Location = New System.Drawing.Point(416, 288)
        Me.TxtPassword.Name = "TxtPassword"
        Me.TxtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TxtPassword.Size = New System.Drawing.Size(168, 21)
        Me.TxtPassword.TabIndex = 5
        Me.TxtPassword.Text = ""
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        '
        'NotifyIcon1
        '
        Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"), System.Drawing.Icon)
        Me.NotifyIcon1.Text = "NotifyIcon1"
        Me.NotifyIcon1.Visible = True
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(632, 424)
        Me.Controls.Add(Me.TxtPassword)
        Me.Controls.Add(Me.TxtIDOrder)
        Me.Controls.Add(Me.BtCancel)
        Me.Controls.Add(Me.BtLogin)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "Form1"
        Me.Text = "此机房只用于学习"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        Me.ResumeLayout(False)

    End Sub

#End Region

    Sub establistsocket(ByVal state As Object)
        Dim serveradd As IPAddress = Dns.Resolve("127.0.0.1").AddressList(0)
        Dim enpoint As New IPEndPoint(serveradd, 50)
        Dim temp As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        temp.Blocking = True
        temp.Connect(enpoint)
        socket = temp
        socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000)
        socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 5000)
        If socket.Connected Then
            Dim info As String
            info = "L" & TxtIDOrder.Text.PadRight(6) & TxtPassword.Text.PadRight(10)
            sendinfo(info)


        End If

    End Sub

    Public Sub processinfo(ByVal info As String)
        Dim flag As String
        flag = info.Substring(0, 2)
        Select Case flag
            Case "MM"
                MsgBox(info.Substring(2, Len(info) - 2))
            Case "L0"
                MsgBox("密码或编号错误,重新输入")

            Case "L1"
                MsgBox("登陆成功", MsgBoxStyle.Exclamation, Me.Text)
                Me.Hide()
            Case "L2"
                MsgBox("机时少于0 ,登陆失败", MsgBoxStyle.Exclamation, Me.Text)
            Case "E0"
                MsgBox("编号或密码错误,重新输入", MsgBoxStyle.Exclamation, Me.Text)
            Case "E1"
                MsgBox("退出成功")

                Me.Close()
            Case "E2"
                MsgBox("机时少于0 ,请续机时,退出成功", , Me.Text)
                Me.Close()



        End Select
    End Sub
    Function sendinfo(ByVal info As String)
        Dim ASCII As System.Text.Encoding = System.Text.Encoding.ASCII
        Dim bytesend As Byte()
        bytesend = ASCII.GetBytes(info)
        socket.Send(bytesend, bytesend.Length, 1)

    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub BtLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtLogin.Click

        If Trim(TxtIDOrder.Text) = "" Then
            MsgBox("编号不能空", MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub

        End If

        If Trim(TxtPassword.Text) = "" Then
            MsgBox("密码不能空", MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub

        End If

        If logined = True Then
            Dim info As String
            info = "L" & TxtIDOrder.Text.PadRight(6) & TxtPassword.Text.PadRight(10)
            sendinfo(info)
        Else
            ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf establistsocket))



        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim ASCII As System.Text.Encoding = System.Text.Encoding.ASCII
        Dim receivebyte(20) As Byte
        Dim receivepage As String = String.Empty
        If Not socket Is Nothing Then
            If socket.Available <> 0 Then
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000)
                Dim bytes As Int32 = socket.Receive(receivebyte, receivebyte.Length, 0)
                receivepage = ASCII.GetString(receivebyte, 0, bytes)
                Processinfo(receivepage)

            End If
        End If
    End Sub

    Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
        Dim info As String
        info = "E" & TxtIDOrder.Text.PadRight(6) & TxtPassword.Text.PadRight(10)
        sendinfo(info)


    End Sub

    Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
        Me.Show()

    End Sub
End Class

⌨️ 快捷键说明

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