您的位置:首页 > 数据库

WinForm设计之SQLServer登录窗体

2006-12-08 15:31 253 查看
Author:水如烟

代码见应用类代码辅助类代码

这个类使处理登录SqlServer服务器显得非常简单。

示例代码:

Public Class MainForm

Private gConnectionString As String

'初始
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mLoginInformation As New LzmTW.uSystem.uData.uSql.LoginInformation
With mLoginInformation
.ServerName = "192.168.0.250,9001" '服务器名称+端口号
.Database = "Northwind"
.Save() '保存至 x:/Documents and Settings/{用户}/Application Data/{组织名称}/{程序名称}/{版本号}/LoginInformation.dat
End With
End Sub

'一般使用,它从配置文件中读取参数
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
With mSqlLoginService

If .TestConnect() Then '如果连接不成功,弹出设置窗体
Me.gConnectionString = mSqlLoginService.LoginInformation.ConnectionStringBuilder.ConnectionString
Console.WriteLine(Me.gConnectionString)
'continue
Else
'exit ?
End If
End With
End Sub

'重置登录信息
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
mSqlLoginService.ResetLoginInformation()
End Sub
End Class

重置效果:



如果要启用初始窗体,即SplashScreenForm,那么,代码示意如下:

Public Class MainForm

Private gConnectionString As String

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage("正在尝试连接数据库....")
Threading.Thread.Sleep(1000)

Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService

With mSqlLoginService

If .TestConnect() Then
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage("连接成功。")
Me.gConnectionString = mSqlLoginService.LoginInformation.ConnectionStringBuilder.ConnectionString
Threading.Thread.Sleep(1000)
Else
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage("连接数据库失败,请与系统管理员联系。程序将退出。")
Threading.Thread.Sleep(1000)

Me.Close()
End If
End With
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
mSqlLoginService.ResetLoginInformation()
End Sub

End Class
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: