📄 frmmain.frm
字号:
VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 3 'Fixed Dialog
Caption = "数据新建"
ClientHeight = 3570
ClientLeft = 45
ClientTop = 330
ClientWidth = 3930
Icon = "frmMain.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 238
ScaleMode = 3 'Pixel
ScaleWidth = 262
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtDBName
Height = 270
Left = 1680
TabIndex = 10
Text = "SuperMarketdb"
Top = 2400
Width = 2055
End
Begin VB.CommandButton cmdCreat
Caption = "新建"
Height = 315
Left = 2640
TabIndex = 9
Top = 3120
Width = 1095
End
Begin VB.CheckBox Ch2
Caption = "新建测试数据"
Height = 255
Left = 240
TabIndex = 8
Top = 2760
Value = 1 'Checked
Width = 2175
End
Begin VB.CheckBox Ch1
Caption = "新建数据库:"
Height = 255
Left = 240
TabIndex = 7
Top = 2400
Value = 1 'Checked
Width = 1935
End
Begin VB.CommandButton cmdLogin
Caption = "登陆"
Default = -1 'True
Height = 315
Left = 2640
TabIndex = 6
Top = 1680
Width = 1095
End
Begin VB.TextBox txtPW
Height = 270
IMEMode = 3 'DISABLE
Left = 1320
PasswordChar = "*"
TabIndex = 5
Text = "jszx"
Top = 1200
Width = 2415
End
Begin VB.TextBox txtUser
Height = 270
Left = 1320
TabIndex = 3
Text = "sa"
Top = 720
Width = 2415
End
Begin VB.TextBox txtSQL
Height = 270
Left = 1320
TabIndex = 1
Text = "172.27.2.249"
Top = 240
Width = 2415
End
Begin VB.Line Line1
X1 = 16
X2 = 248
Y1 = 144
Y2 = 144
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "密码:"
Height = 180
Left = 240
TabIndex = 4
Top = 1260
Width = 450
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "登录名:"
Height = 180
Left = 240
TabIndex = 2
Top = 780
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "SQL服务器:"
Height = 180
Left = 240
TabIndex = 0
Top = 300
Width = 900
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cnMain As New ADODB.Connection
Private Sub cmdCreat_Click()
On Error GoTo aaaa
Dim b As Boolean
Dim sql As String, s() As String, i As Long
'建立数据库
If Ch1.Value = 1 Then
Dim rs As New ADODB.Recordset
rs.Open "sp_helpdb", cnMain, adOpenDynamic, adLockOptimistic
While Not rs.EOF
If StrComp(CStr(rs.Fields("name")), txtDBName, 1) = 0 Then
MsgBox "数据库 " & txtDBName & " 已经存在!", vbInformation
rs.Close
Exit Sub
End If
rs.MoveNext
Wend
cnMain.Execute "create database " & txtDBName
cnMain.Execute "ALTER DATABASE " & txtDBName & " modify file ( Name='" & txtDBName & "',Size=30MB )"
cnMain.Close
sql = "provider=sqloledb;server=" & Trim(txtSQL) & ";user id=" & Trim(txtUser) & ";password=" & Trim(txtPW) & ";database=" & txtDBName
cnMain.Open sql
'建立表
sql = ReadFile(GetApp & "DDL.sql")
s = Split(sql, "<->")
For i = 0 To UBound(s)
cnMain.Execute s(i)
Next
MsgBox "成功建立数据库 " & txtDBName, vbInformation
b = True
End If
'新建测试数据
If Ch2.Value = 1 Then
sql = ReadFile(GetApp & "Data.sql")
s = Split(sql, vbCrLf)
For i = 0 To UBound(s)
If Trim(s(i)) <> "" Then cnMain.Execute s(i)
Next
MsgBox "成功新建测试数据。", vbInformation
b = True
End If
If b = False Then MsgBox "没有选择操作!", vbExclamation
Exit Sub
aaaa:
MsgBox Err.Description, vbCritical
End Sub
Private Sub cmdLogin_Click()
On Error GoTo aaaa
Dim sql As String
sql = "provider=sqloledb;server=" & Trim(txtSQL) & ";user id=" & Trim(txtUser) & ";password=" & Trim(txtPW)
cnMain.Open sql
Height = 3975
Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 - 300
cmdLogin.Enabled = False
cmdLogin.Default = False
Exit Sub
aaaa:
MsgBox Err.Description, vbCritical
End Sub
Private Sub Form_Load()
Height = 2505
Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 - 300
End Sub
'获得程序所在目录
Public Function GetApp() As String
GetApp = App.Path
If Right$(GetApp, 1) <> "\" Then GetApp = GetApp & "\"
End Function
'读取TXT
Public Function ReadFile(ByVal strFile As String) As String
On Error GoTo aaaa
Open strFile For Input As #1
ReadFile = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
Exit Function
aaaa:
ReadFile = ""
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -