开发实践教程1:试卷生成系统6.19用户备注(FormUserMemo)

Posted VB.Net

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发实践教程1:试卷生成系统6.19用户备注(FormUserMemo)相关的知识,希望对你有一定的参考价值。

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。

设置用户备注。

窗体设计如下:

 图1-29

具体代码如下:

Imports System.Data.SqlClient

Public Class FormUserMemo
    Dim UserId As Integer
    Dim UserName As String
    Dim UserTrueName As String
    Dim UserNumber As String
    Dim UserMemo As String

    Dim fUserList As New FormUserList

    Sub New(ByVal UserId As Integer, ByVal UserName As String, ByVal UserTrueName As String, ByVal UserNumber As String, ByVal UserMemo As String)

        InitializeComponent()

        Me.UserId = UserId
        Me.UserName = UserName
        Me.UserTrueName = UserTrueName
        Me.UserNumber = UserNumber
        Me.UserMemo = UserMemo

    End Sub
    Private Sub FormUserMemo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtName.Text = UserName
        txtTrueName.Text = UserTrueName
        txtNumber.Text = UserNumber
        txtMemo.Text = UserMemo

        fUserList = Me.Owner.ActiveMdiChild
    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        Dim newRemark As String
        newRemark = txtMemo.Text.Trim

        If newRemark = UserMemo Then
            MessageBox.Show("备注信息未修改,取消更新。")
            Exit Sub
        End If

        Dim connection As SqlConnection
        connection = New SqlConnection(databaseConnString)
        connection.Open()
        Dim command As New SqlCommand()
        command.Connection = connection
        command.CommandText = "update 用户表 set 备注信息='" & newRemark & "' where 编号=" & UserId
        Try
            command.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("更新操作时发生错误。错误原因:" & ex.Message)
            Exit Sub
        End Try

        fUserList.currentRemark = newRemark
        Me.Close()
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        fUserList.currentRemark = ""
        Me.Close()
    End Sub
End Class

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供的参考。

学习更多vb.net知识,请参看 vb.net 教程 目录

以上是关于开发实践教程1:试卷生成系统6.19用户备注(FormUserMemo)的主要内容,如果未能解决你的问题,请参考以下文章

开发实践教程1:试卷生成系统3 系统设计

开发实践教程1:试卷生成系统6.18用户查询(FormUserQuery)

开发实践教程1:试卷生成系统4 类

开发实践教程1:试卷生成系统6.12 试卷管理(FormTestPaperManager)

开发实践教程1:试卷生成系统6.21 用户信息(FormSelfInfo)

开发实践教程1:试卷生成系统 1 前言和目录