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
代码见应用类代码和辅助类代码
这个类使处理登录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
相关文章推荐
- C#下WinForm编程:登录窗体的设计
- Winform的登录窗体设计思路
- C#-winform-设计登录窗体
- winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)
- C#下WinForm编程:登录窗体的设计
- .NET Winform登录窗体编程设计及数据库表
- winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)
- winform 登录窗体设计
- C#下WinForm编程:登录窗体的设计
- SQL SERVER SA密码忘记,windows集成身份验证都登录不了不怎么办
- 线程与WinForm设计,防冻结,卡住窗体
- 用自定义代码扩展 Microsoft SQL Server Reporting Services (RDL设计器,RDL,扩展代码)
- 《Microsoft SQL Server 2008 Analysis Services Step by Step》学习笔记七:高级维度设计
- 【Visual Studio风格开发系列 - WinForm设计时异常】关于VS.NET中窗体设计器初始化控件引发的设计时异常
- SQL Server ReportService 报表管理器匿名登录小工具
- C# Winform程序设置登录窗体先启动
- 设计登录窗体的问题
- Winform中多国语言窗体的设计以及.NET中资源文件的使用[转]
- WinForm下窗体权限设计【转】
- 存储图片(C#+Winform+SQL Server)