frmpicture.frm
来自「For Call Center Operators for the work t」· FRM 代码 · 共 343 行
FRM
343 行
VERSION 5.00
Object = "{899348F9-A53A-4D9E-9438-F97F0E81E2DB}#1.0#0"; "LVbuttons.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form frmPicture
BorderStyle = 3 'Fixed Dialog
Caption = "Add Picture"
ClientHeight = 4155
ClientLeft = 150
ClientTop = 435
ClientWidth = 4770
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4155
ScaleWidth = 4770
ShowInTaskbar = 0 'False
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton cmdPreviousPic
Caption = "Command1"
Height = 375
Left = 3000
TabIndex = 4
Top = 3480
Width = 1575
End
Begin VB.CommandButton cmdNextPic
Caption = "Command1"
Height = 375
Left = 720
TabIndex = 3
Top = 3600
Width = 1335
End
Begin LVbuttons.LaVolpeButton cmdExit
Height = 375
Left = 2640
TabIndex = 2
Top = 2760
Width = 1215
_ExtentX = 2143
_ExtentY = 661
BTYPE = 3
TX = "Exit"
ENAB = -1 'True
BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Verdana"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
COLTYPE = 1
BCOL = 13160660
FCOL = 0
FCOLO = 0
EMBOSSM = 12632256
EMBOSSS = 16777215
MPTR = 0
MICON = "frmPicture.frx":0000
ALIGN = 1
IMGLST = "(None)"
IMGICON = "(None)"
ICONAlign = 0
ORIENT = 0
STYLE = 0
IconSize = 2
SHOWF = -1 'True
BSTYLE = 0
End
Begin LVbuttons.LaVolpeButton cmdAdd
Height = 375
Left = 360
TabIndex = 1
Top = 2640
Width = 1575
_ExtentX = 2778
_ExtentY = 661
BTYPE = 3
TX = "Add New Image"
ENAB = -1 'True
BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Verdana"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
COLTYPE = 1
BCOL = 13160660
FCOL = 0
FCOLO = 0
EMBOSSM = 12632256
EMBOSSS = 16777215
MPTR = 0
MICON = "frmPicture.frx":001C
ALIGN = 1
IMGLST = "(None)"
IMGICON = "(None)"
ICONAlign = 0
ORIENT = 0
STYLE = 0
IconSize = 2
SHOWF = -1 'True
BSTYLE = 0
End
Begin VB.ListBox lstPeople
Height = 2205
ItemData = "frmPicture.frx":0038
Left = 120
List = "frmPicture.frx":003A
Sorted = -1 'True
TabIndex = 0
Top = 240
Width = 1935
End
Begin MSComDlg.CommonDialog dlgPicture
Left = 240
Top = 1920
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Image picPerson
BorderStyle = 1 'Fixed Single
Height = 2295
Left = 2280
Stretch = -1 'True
Top = 240
Width = 2055
End
End
Attribute VB_Name = "frmPicture"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_PATH = 260
Private m_DBConn As ADODB.Connection
Private Const BLOCK_SIZE = 10000
' Return a temporary file name.
Private Function TemporaryFileName() As String
Dim temp_path As String
Dim temp_file As String
Dim length As Long
' Get the temporary file path.
temp_path = Space$(MAX_PATH)
length = GetTempPath(MAX_PATH, temp_path)
temp_path = Left$(temp_path, length)
' Get the file name.
temp_file = Space$(MAX_PATH)
GetTempFileName temp_path, "per", 0, temp_file
TemporaryFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1)
End Function
Private Sub cmdAdd_Click()
Dim rs As ADODB.Recordset
Dim person_name As String
Dim file_num As String
Dim file_length As String
Dim bytes() As Byte
Dim num_blocks As Long
Dim left_over As Long
Dim block_num As Long
person_name = InputBox("Name")
If Len(person_name) = 0 Then Exit Sub
dlgPicture.Flags = _
cdlOFNFileMustExist Or _
cdlOFNHideReadOnly Or _
cdlOFNExplorer
dlgPicture.CancelError = True
dlgPicture.Filter = "Graphics Files|*.bmp;*.ico;*.jpg;*.gif"
On Error Resume Next
dlgPicture.ShowOpen
If Err.Number = cdlCancel Then
Exit Sub
ElseIf Err.Number <> 0 Then
MsgBox "Error " & Format$(Err.Number) & _
" selecting file." & vbCrLf & Err.Description
Exit Sub
End If
' Open the picture file.
file_num = FreeFile
Open dlgPicture.FileName For Binary Access Read As #file_num
file_length = LOF(file_num)
If file_length > 0 Then
num_blocks = file_length / BLOCK_SIZE
left_over = file_length Mod BLOCK_SIZE
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "Select Name, Picture, FileLength FROM People", m_DBConn
rs.AddNew
rs!Name = person_name
rs!FileLength = file_length
ReDim bytes(BLOCK_SIZE)
For block_num = 1 To num_blocks
Get #file_num, , bytes()
rs!Picture.AppendChunk bytes()
Next block_num
If left_over > 0 Then
ReDim bytes(left_over)
Get #file_num, , bytes()
rs!Picture.AppendChunk bytes()
End If
rs.Update
Close #file_num
lstPeople.AddItem person_name
lstPeople.Text = person_name
End If
End Sub
Private Sub cmdExit_Click()
Me.Hide
frmAdmin.Show
End Sub
Private Sub cmdNextPic_Click()
lstPeople.ListIndex = lstPeople.ListIndex + 1
End Sub
Private Sub cmdPreviousPic_Click()
lstPeople.ListIndex = lstPeople.ListIndex - 1
End Sub
Private Sub Form_Load()
Dim db_file As String
Dim rs As ADODB.Recordset
' Get the database file name.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
db_file = db_file & "dbpict.mdb"
' Open the database connection.
Set m_DBConn = New ADODB.Connection
m_DBConn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
' Get the list of people.
Set rs = m_DBConn.Execute("SELECT Name FROM People ORDER BY Name", , adCmdText)
Do While Not rs.EOF
lstPeople.AddItem rs!Name
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
lstPeople.ListIndex = 0
End Sub
Private Sub Form_Resize()
'lstPeople.Height = ScaleHeight
End Sub
' Display the clicked person.
Private Sub lstPeople_Click()
Dim rs As ADODB.Recordset
Dim bytes() As Byte
Dim file_name As String
Dim file_num As Integer
Dim file_length As Long
Dim num_blocks As Long
Dim left_over As Long
Dim block_num As Long
Dim hgt As Single
picPerson.Visible = False
Screen.MousePointer = vbHourglass
DoEvents
' Get the record.
Set rs = m_DBConn.Execute("SELECT * FROM People WHERE Name='" & _
lstPeople.Text & "'", , adCmdText)
If rs.EOF Then Exit Sub
' Get a temporary file name.
file_name = TemporaryFileName()
' Open the file.
file_num = FreeFile
Open file_name For Binary As #file_num
' Copy the data into the file.
file_length = rs!FileLength
num_blocks = file_length / BLOCK_SIZE
left_over = file_length Mod BLOCK_SIZE
For block_num = 1 To num_blocks
bytes() = rs!Picture.GetChunk(BLOCK_SIZE)
Put #file_num, , bytes()
Next block_num
If left_over > 0 Then
bytes() = rs!Picture.GetChunk(left_over)
Put #file_num, , bytes()
End If
Close #file_num
' Display the picture file.
picPerson.Picture = LoadPicture(file_name)
picPerson.Visible = True
frmAdmin.picPerson.Picture = LoadPicture(file_name)
' Width = picPerson.Left + picPerson.Width + Width - ScaleWidth
'hgt = picPerson.Top + picPerson.Height + Height - ScaleHeight
'If hgt < 1440 Then hgt = 1440
'Height = hgt
Kill file_name
Screen.MousePointer = vbDefault
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?