📄 main.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Main
Caption = "数据库操作"
ClientHeight = 6720
ClientLeft = 60
ClientTop = 405
ClientWidth = 8415
LinkTopic = "Form1"
ScaleHeight = 448
ScaleMode = 3 'Pixel
ScaleWidth = 561
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame9
Height = 3015
Left = 6360
TabIndex = 13
Top = 120
Width = 1935
Begin VB.CheckBox Check1
Caption = "SQL/SyBase类型"
Height = 255
Left = 120
TabIndex = 18
Top = 2160
Width = 1575
End
Begin VB.TextBox Text6
Height = 270
Left = 120
TabIndex = 17
Text = "总记录数"
Top = 2640
Width = 1695
End
Begin VB.CommandButton Command3
Caption = "保存设置"
BeginProperty Font
Name = "黑体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 120
TabIndex = 14
Top = 1440
Width = 1695
End
Begin VB.CommandButton Command2
Caption = "执行语句"
BeginProperty Font
Name = "黑体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 120
TabIndex = 15
Top = 840
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "连接数据库"
BeginProperty Font
Name = "黑体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 120
TabIndex = 16
Top = 240
Width = 1695
End
End
Begin VB.Frame Frame1
Caption = "连接设置"
BeginProperty Font
Name = "黑体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1215
Left = 120
TabIndex = 4
Top = 120
Width = 6135
Begin VB.Frame Frame5
Caption = "服务器名"
Height = 615
Left = 120
TabIndex = 11
Top = 360
Width = 1335
Begin VB.TextBox Text1
Height = 270
Left = 120
TabIndex = 12
Text = "zb"
Top = 240
Width = 1095
End
End
Begin VB.Frame Frame6
Caption = "数据库名"
Height = 615
Left = 1560
TabIndex = 9
Top = 360
Width = 1335
Begin VB.TextBox Text2
Height = 270
Left = 120
TabIndex = 10
Text = "zbserver"
Top = 240
Width = 1095
End
End
Begin VB.Frame Frame7
Caption = "用户名"
Height = 615
Left = 3000
TabIndex = 7
Top = 360
Width = 1335
Begin VB.TextBox Text3
Height = 270
Left = 120
TabIndex = 8
Text = "sa"
Top = 240
Width = 1095
End
End
Begin VB.Frame Frame8
Caption = "密码"
Height = 615
Left = 4440
TabIndex = 5
Top = 360
Width = 1335
Begin VB.TextBox Text4
Height = 270
IMEMode = 3 'DISABLE
Left = 120
PasswordChar = "X"
TabIndex = 6
Top = 240
Width = 1095
End
End
End
Begin VB.Frame Frame3
Caption = "语句输入"
BeginProperty Font
Name = "黑体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1695
Left = 120
TabIndex = 1
Top = 1440
Width = 6135
Begin VB.TextBox Text5
Height = 1215
Left = 120
TabIndex = 2
Text = "select * from gds"
Top = 360
Width = 5895
End
End
Begin VB.Frame Frame2
Caption = "结果显示"
BeginProperty Font
Name = "黑体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3375
Left = 120
TabIndex = 0
Top = 3240
Width = 8175
Begin MSComctlLib.ListView ListView1
Height = 2895
Left = 120
TabIndex = 3
Top = 360
Width = 7935
_ExtentX = 13996
_ExtentY = 5106
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
GridLines = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
NumItems = 0
End
End
End
Attribute VB_Name = "Main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command3_Click()
'加密过程(ansi字符代码方式)
'----------------
Dim tw, pw As String
Dim ln, x As Integer
ln = Len(Text4.Text)
For x = 1 To ln
tw = Mid(Text4.Text, x, 1)
pw = pw & "+" & Asc(tw)
Next x
'----------------
WritePrivateProfileString "Connect", "SRVR", Text1.Text, App.Path & "\" & App.EXEName & ".ini"
WritePrivateProfileString "Connect", "DB", Text2.Text, App.Path & "\" & App.EXEName & ".ini"
WritePrivateProfileString "Connect", "UID", Text3.Text, App.Path & "\" & App.EXEName & ".ini"
WritePrivateProfileString "Connect", "PWD", pw, App.Path & "\" & App.EXEName & ".ini"
WritePrivateProfileString "Connect", "TYPE", CStr(Check1.Value), App.Path & "\" & App.EXEName & ".ini"
'WritePrivateProfileString "Connect", "DEL", Text5.Text, App.Path & "\" & App.EXEName & ".ini"
'Unload Me
Open App.Path + "/" + App.EXEName + ".txt" For Output As #1
Print #1, Text5.Text + Chr$(0)
Close #1
MsgBox "保存完毕!下次启动自动载入设置.", 64, "保存设置"
'End
End Sub
Private Sub Form_Load()
'判断程序是否已经运行 如果运行则退出再次的调用
If App.PrevInstance Then
End
End If
'判断是否存在设置文件 有则载入 没有则使用默认
If Dir(App.Path & "\" & App.EXEName & ".ini") <> "" Then
Dim buff As String
buff = Space$(254)
'读取连接设置
GetPrivateProfileString "Connect", "TYPE", "", buff, Len(buff) + 1, App.Path & "\" & App.EXEName & ".ini"
If Left(Trim(buff), Len(Trim(buff)) - 1) = "1" Then
Check1.Value = 1
Else
Check1.Value = 0
End If
buff = Space(254)
GetPrivateProfileString "Connect", "SRVR", "", buff, Len(buff) + 1, App.Path & "\" & App.EXEName & ".ini"
Text1.Text = Left(Trim(buff), Len(Trim(buff)) - 1)
buff = Space(254)
GetPrivateProfileString "Connect", "DB", "", buff, Len(buff) + 1, App.Path & "\" & App.EXEName & ".ini"
Text2.Text = Left(Trim(buff), Len(Trim(buff)) - 1)
buff = Space(254)
GetPrivateProfileString "Connect", "UID", "", buff, Len(buff) + 1, App.Path & "\" & App.EXEName & ".ini"
Text3.Text = Left(Trim(buff), Len(Trim(buff)) - 1)
buff = Space(254)
GetPrivateProfileString "Connect", "PWD", "", buff, Len(buff) + 1, App.Path & "\" & App.EXEName & ".ini"
'解密过程(ansi字符代码方式)
'----------------
Dim tw, pw As String
Dim ln, x, x1, x2 As Integer
tw = Left(Trim(buff), Len(Trim(buff)) - 1)
x1 = 1
x2 = 1
Do While InStr(x1, tw, "+") <> 0
x1 = InStr(x1, tw, "+", vbTextCompare)
x2 = InStr(x1 + 1, tw, "+", vbTextCompare)
If x2 = 0 Then x2 = Len(tw) + 1
pw = pw & Chr(Mid(tw, x1 + 1, x2 - (x1 + 1)))
x1 = x2
Loop
'-------------------
pd = pw
Text4.Text = pd 'Left(Trim(buff), Len(Trim(buff)) - 1)
buff = Space(254)
Else
MsgBox "未发现设置文件!启用默认设置.", 64, "载入设置"
End If
Open App.Path + "/" + App.EXEName + ".txt" For Binary As #1
Text5.Text = Input(LOF(1), #1)
Close #1
Command2.Enabled = False
Call Command1_Click
'Me.Hide
End Sub
Private Sub Command1_Click()
'调用连接目标数据库
If ConnectSybase(Text1.Text, Text2.Text, Text3.Text, Text4.Text, Check1.Value) Then
'MsgBox "连接数据库成功!", 64
'StatusBar1.Panels(1).Text = "状态:" & "连接数据库成功!"
'StatusBar1.Panels(3).Text = "数据库:" & Text2.Text
'StatusBar1.Panels(4).Text = "用户:" & Text3.Text
Command2.Enabled = True
Else
'MsgBox "连接数据库失败!", 16
Exit Sub
End If
End Sub
Private Sub Command2_Click()
'调用语句执行处理
If USESQL(1, Text5.Text) Then
'MsgBox "语句执行成功!", 64
Else
MsgBox "语句执行失败!", 16
Exit Sub
End If
'------------------------------------------------
'处理结果
On Error GoTo ErrMsg
ListView1.ColumnHeaders.Clear
ListView1.ListItems.Clear
'获取所有字段先
For i = 0 To Rsbdata.Fields.Count - 1
ListView1.ColumnHeaders.Add , , Rsbdata.Fields(i).Name '最后可加长度值
Next i
'总记录数
Text6.Text = Rsbdata.RecordCount
'VScroll1.Max = Rsbdata.RecordCount
'循环取得所有数据
Do Until Rsbdata.EOF 'x < 100
'Do while Rsbdata.EOF
'建立行头先
ListView1.ListItems.Add , , Rsbdata.Fields(0)
'DoEvents
'每一次循环得到的数据
For i = 1 To Rsbdata.Fields.Count - 1
ListView1.ListItems(Rsbdata.AbsolutePosition).SubItems(i) = Format(Rsbdata.Fields(i).Value, "")
Next i
Rsbdata.MoveNext
'x = x + 1
Loop
'MsgBox "数据处理完毕!", 64
Rsbdata.Close '关闭记录集
'--------------------------------------
Exit Sub
ErrMsg:
MsgBox "数据处理失败!", 16
End Sub
Private Sub Form_Resize()
'On Error Resume Next
Frame2.Height = Me.ScaleHeight - Frame9.Height - 24
Frame2.Width = Me.ScaleWidth - 16
ListView1.Height = Frame2.Height * 15 - 500
ListView1.Width = Frame2.Width * 15 - 300
'Frame1.Width = Me.ScaleWidth - Frame2.Width - 24
'Frame2.Height = Me.Height
'ListView1.Height = Me.Height
'Frame2.Width = Me.Width
'ListView1.Width = Me.Width
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -