📄 frm_printdaima.frm
字号:
Height = 375
Left = 4920
TabIndex = 1
Top = 4320
Width = 1695
End
Begin VB.CommandButton cmd_print
Caption = "打印输出(&P)"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2520
TabIndex = 0
Top = 4320
Width = 1695
End
End
Attribute VB_Name = "frm_printdaima"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public xiang As String
Public zhen As String
Function convert_str(mystring As String) As Integer
Dim i As Integer
Dim temp As String
Dim count_hz As Integer
temp = ""
count_hz = 0
For i = 0 To Len(mystring) - 1
If Asc(Mid(mystring, i + 1, 1)) < 0 Then
count_hz = count_hz + 1
End If
Next
convert_str = count_hz
End Function
Private Sub adotemp_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
MsgBox "数据库连接失败!!!", vbInformation
fCancelDisplay = True
Unload Me
End Sub
Private Sub cmd_close_Click()
Unload Me
End Sub
Private Sub cmd_find_Click()
Dim i As Integer
Dim xitem As ListItem
Dim start As String
Dim end_s As String
If Option3.Value = True Then
start = ""
end_s = ""
If Len(Trim(txt_from.Text)) = 0 Then
start = "0000"
Else
start = Format(txt_from.Text, "0###")
End If
If Option1.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],[user].[juhao] as [局号] from user inner join (village inner join town on village.townid=town.id ) on user.villid= village.id where village.name='" & Trim(txt_vill.Text) & "' order by [user].[usercode] asc"
adotemp.Refresh
End If
If Option4.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],[user].[juhao] as [局号] from user inner join (village inner join town on village.townid=town.id ) on user.villid= village.id where village.name='" & Trim(Combo_vill.Text) & "' and town.name='" & Trim(Combo_town.Text) & "' order by [user].[usercode] asc"
adotemp.Refresh
End If
If Len(Trim(txt_to.Text)) = 0 Then
end_s = Format(adotemp.Recordset.RecordCount, "0###")
Else
end_s = Format(txt_to.Text, "0###")
End If
End If
If Option4.Value = True Then
If Option2.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],[user].[juhao] as [局号] from user inner join (village inner join town on village.townid=town.id ) on user.villid= village.id where village.name='" & Trim(Combo_vill.Text) & "' and town.name='" & Trim(Combo_town.Text) & "' order by [user].[usercode] asc"
adotemp.Refresh
End If
If Option3.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],[user].[juhao] as [局号] from user inner join (village inner join town on village.townid=town.id ) on user.villid= village.id where village.name='" & Trim(Combo_vill.Text) & "' and town.name='" & Trim(Combo_town.Text) & "'and user.usercode >= '" & start & "' and user.usercode <='" & end_s & "' order by [user].[usercode] asc"
adotemp.Refresh
End If
If adotemp.Recordset.RecordCount = 0 Then
MsgBox "没有检索到数据!", vbCritical
End If
xiang = Trim(Combo_town.Text)
zhen = Trim(Combo_vill.Text)
End If
If Option1.Value = True Then
If Option2.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],[user].[juhao] as [局号] from user inner join (village inner join town on village.townid=town.id ) on user.villid= village.id where village.name='" & Trim(txt_vill.Text) & "' order by [user].[usercode] asc"
adotemp.Refresh
End If
If Option3.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],[user].[juhao] as [局号] from user inner join (village inner join town on village.townid=town.id ) on user.villid= village.id where village.name='" & Trim(txt_vill.Text) & "'and user.usercode >= '" & start & "' and user.usercode <='" & end_s & "' order by [user].[usercode] asc"
adotemp.Refresh
End If
If adotemp.Recordset.RecordCount = 0 Then
MsgBox "没有检索到数据!", vbCritical
txt_vill.SelStart = 0
txt_vill.SelLength = Len(txt_vill.Text)
End If
zhen = Trim(txt_vill.Text)
End If
If adotemp.Recordset.RecordCount <> 0 Then
cmd_print.Enabled = True
Else
cmd_print.Enabled = False
End If
Set mgrid.DataSource = adotemp
End Sub
Private Sub cmd_print_Click()
Dim i As Integer
Dim j As Integer
Dim temp0 As String
Dim temp1 As String
Dim temp2 As String
Dim temp3 As String
Dim temp4 As String
Dim temp5 As String
i = 0
j = 0
On Error GoTo hander
Call printer_init
' Printer.PaperSize '自定义打印大小
adotemp.Refresh
With adotemp.Recordset
If .RecordCount <> 0 Then
Printer.FontSize = 14
Printer.Print Space(7) & xiang & zhen & "用户对照表" & Space(10) '& "局号:" & No_juhao
Printer.FontSize = 10
Printer.Print
'─││┆┈┄┆┊┌┐└┘├┤┬┴┼╱╲「」
Printer.FontSize = 12
Printer.Print Space(10) & "制表日期:" & Date & Space(30) & "第" & Printer.Page; "页"
Printer.FontSize = 11
Printer.Print "┌────┬──────────────┬─────┬────┬──────────────┬─────┐"
Printer.Print "│ 编 号│ 用 户 名 │ 局 号 │ 编 号 │ 用 户 名 │ 局 号 │"
Printer.Print "├────┼──────────────┼─────┼────┼──────────────┼─────┤"
'Printer.Print "└────┴──────────────┴─────┴────┴──────────────┴─────┘"
Do Until .EOF
i = i + 1
Select Case (i Mod 2)
Case 1:
temp0 = .Fields("用户编码")
temp1 = .Fields("用户名")
temp4 = .Fields("局号")
Case 0:
temp2 = .Fields("用户编码")
temp3 = .Fields("用户名")
temp5 = .Fields("局号")
End Select
If (i Mod 2) = 0 Then
j = j + 1
If j < 28 Then
Printer.Print "│" & Space(2) & Left(temp0 & Space(8), 6) & "│" & temp1 & Left(Space(40), 28 - Len(temp1) - convert_str(temp1)) & "│" & Space(1) & Left(temp4 & Space(10), 9) & "│" & Space(2) & Left(temp2 & Space(8), 6) & "│" & temp3 & Left(Space(40), 28 - Len(temp3) - convert_str(temp3)) & "│" & Space(1) & Left(temp5 & Space(10), 9) & "│"
Printer.Print "├────┼──────────────┼─────┼────┼──────────────┼─────┤"
Else
Printer.Print "│" & Space(2) & Left(temp0 & Space(8), 6) & "│" & temp1 & Left(Space(40), 28 - Len(temp1) - convert_str(temp1)) & "│" & Space(1) & Left(temp4 & Space(10), 9) & "│" & Space(2) & Left(temp5 & Space(8), 6) & "│" & temp3 & Left(Space(40), 28 - Len(temp3) - convert_str(temp3)) & "│" & Space(1) & Left(temp5 & Space(10), 9) & "│"
Printer.Print "└────┴──────────────┴─────┴────┴──────────────┴─────┘"
Printer.NewPage
j = 0
i = 0
Printer.FontSize = 14
Printer.Print Space(7) & xiang & zhen & "用户代码对照表" '& Space(10) & "局号:" & No_juhao
Printer.FontSize = 10
Printer.Print
Printer.Print
'─││┆┈┄┆┊┌┐└┘├┤┬┴┼╱╲「」
Printer.FontSize = 12
Printer.Print Space(10) & "制表日期:" & Date & Space(30) & "第" & Printer.Page; "页"
Printer.FontSize = 11
Printer.Print "┌────┬──────────────┬─────┬────┬──────────────┬─────┐"
Printer.Print "│ 编 号│ 用 户 名 │ 局 号 │ 编 号 │ 用 户 名 │ 局 号 │"
Printer.Print "├────┼──────────────┼─────┼────┼──────────────┼─────┤"
End If
temp0 = ""
temp1 = ""
temp2 = ""
temp3 = ""
temp4 = ""
temp5 = ""
End If
.MoveNext
Loop
If (i Mod 2) = 1 Then
Printer.Print "│" & Space(2) & Left(temp0 & Space(8), 6) & "│" & temp1 & Left(Space(40), 28 - Len(temp1) - convert_str(temp1)) & "│" & Space(1) & Left(temp4 & Space(10), 9) & "│" & Space(2) & Left(temp5 & Space(8), 6) & "│" & temp3 & Left(Space(40), 28 - Len(temp3) - convert_str(temp3)) & "│" & Space(1) & Left(temp5 & Space(10), 9) & "│"
Printer.Print "└────┴──────────────┴─────┴────┴──────────────┴─────┘"
Else
End If
Printer.EndDoc
Else
MsgBox "没有数据要打印!", vbInformation
Screen.MousePointer = 0
Exit Sub
End If
End With
hander:
Select Case Err.Number
Case 482:
MsgBox "打印机错误!", vbCritical
Exit Sub
Case Else
Resume Next
End Select
End Sub
Private Sub combo_town_Click()
Dim i As Integer
adotemp.RecordSource = "select village.name as [村] from village inner join town on village.townid=town.id where town.name ='" & Trim(Combo_town.Text) & "'"
adotemp.Refresh
Combo_vill.Clear
With adotemp.Recordset
If .RecordCount <> 0 Then
For i = 0 To .RecordCount - 1
Combo_vill.AddItem .Fields("村")
If .AbsolutePosition = .RecordCount Then
.MoveLast
Else
.MoveNext
End If
Next
Combo_vill.ListIndex = 0
End If
End With
End Sub
Private Sub Combo_vill_Click()
cmd_find.Enabled = True
'Option2.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
On Error Resume Next
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 - 700
adotemp.ConnectionString = "DBQ=" & data_basename & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;PWD=d^j&d*s!j~;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
adotemp.RecordSource = "select name as [乡镇] from town"
adotemp.Refresh
mgrid.ColWidth(0) = 1000
mgrid.ColWidth(1) = 2000
With adotemp.Recordset
If .RecordCount <> 0 Then
For i = 0 To .RecordCount - 1
Combo_town.AddItem .Fields("乡镇")
If .AbsolutePosition = .RecordCount Then
.MoveLast
Else
.MoveNext
End If
Next
Combo_town.ListIndex = 0
End If
End With
txt_vill.Enabled = False
cmd_print.Enabled = False
txt_from.Enabled = False
txt_to.Enabled = False
'Option2.Enabled = False
'Option3.Enabled = False
cmd_print.Enabled = False
End Sub
Private Sub Option1_Click()
cmd_print.Enabled = False
Combo_town.Enabled = False
Combo_vill.Enabled = False
txt_vill.Enabled = True
End Sub
Private Sub Option2_Click()
txt_from.Enabled = False
txt_to.Enabled = False
End Sub
Private Sub Option3_Click()
txt_from.Enabled = True
txt_to.Enabled = True
End Sub
Private Sub Option4_Click()
txt_vill.Enabled = False
Combo_vill.Enabled = True
Combo_town.Enabled = True
End Sub
Private Sub txt_to_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Len(Trim(txt_to.Text)) <> 0 Then
If CLng((txt_from.Text)) - CLng(Trim(txt_to.Text)) > 0 Then
MsgBox "范围输入错误!起始范围大于结束范围!请重输.", vbCritical
Exit Sub
End If
End If
End If
End Sub
Private Sub txt_vill_Change()
If Len(Trim(txt_vill.Text)) <> 0 Then
cmd_find.Enabled = True
cmd_print.Enabled = False
txt_from.Enabled = False
txt_to.Enabled = False
Option2.Enabled = True
Option3.Enabled = True
Else
cmd_print.Enabled = False
txt_from.Enabled = False
txt_to.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -