-
资源名称:ERPSYS.zip [点击查看]
上传用户:zhpu1995
上传日期:2013-09-06
资源大小:61151k
文件大小:52k
源码类别:
企业管理
开发平台:
Visual Basic
- Attribute VB_Name = "XtsyModule"
- '系统私有模块用来放置一些子系统独有的过程与函数
- Public str_Code As String '存储列内容参数
- Public sParam As String
- Public Const DATA_NUMERIC As Integer = 5 '数字行
- Public Const DATA_STRING As Integer = 0 '字符型
- Public Const DATA_DATE As Integer = 7 '日期型
- Const PRINTSTYLE_ONETITLE = 0 '每页打印表头
- Const PRINTSTYLE_ALLTITLE = 1 '每行打印表头
- Public Sub Drxtztcs() '读入系统帐套参数
- Dim Ztcsbrec As New ADODB.Recordset
- Dim RecTemp As New ADODB.Recordset
- Dim Sqlstr As String
- With Ztcsbrec
- '金额总位数
- .Open "Select * From Gy_AccInformation Where SystemCode='Cwzz'", Cw_DataEnvi.DataConnect, adOpenDynamic, adLockOptimistic
- .MoveFirst
- .Find "itemcode='cwjezws'"
- If Not Ztcsbrec.EOF Then
- Xtjezws = Val(Trim(Ztcsbrec.Fields("itemvalue")))
- End If
- '数量总位数
- .MoveFirst
- .Find "itemcode='cwslzws'"
- If Not Ztcsbrec.EOF Then
- Xtslzws = Val(Trim(Ztcsbrec.Fields("itemvalue")))
- End If
- '单价总位数
- .MoveFirst
- .Find "itemcode='cwdjzws'"
- If Not Ztcsbrec.EOF Then
- Xtdjzws = Val(Trim(Ztcsbrec.Fields("itemvalue")))
- End If
- '金额小数位数
- .MoveFirst
- .Find "itemcode='cwjexsws'"
- If Not Ztcsbrec.EOF Then
- Xtjexsws = Val(Trim(Ztcsbrec.Fields("itemvalue")))
- End If
- '数量小数位数
- .MoveFirst
- .Find "itemcode='cwslxsws'"
- If Not Ztcsbrec.EOF Then
- Xtslxsws = Val(Trim(Ztcsbrec.Fields("itemvalue")))
- End If
- '单价小数位数
- .MoveFirst
- .Find "itemcode='cwdjxsws'"
- If Not Ztcsbrec.EOF Then
- Xtdjxsws = Val(Trim(Ztcsbrec.Fields("itemvalue")))
- End If
- .Close
- End With
- End Sub
- '******************************************************************
- '* 模 块 名 称 :私有模块
- '* 功 能 描 述 :
- '* 程序员姓名 :苗鹏
- '* 最后修改人 :苗鹏
- '* 最后修改时间:2002/01/01
- '* 备 注:
- '******************************************************************
- Public Function GetTableField(sExec As String, sTableName As String, sFieldName As String, s As String) As Integer
- '分离表名和字段名,s为分隔符
- On Error GoTo ErrCtrl
- Dim i As Integer
- For i = 1 To Len(sExec)
- If Mid(sExec, i, 1) = s Then
- sTableName = Left(sExec, i - 1)
- sFieldName = Right(sExec, Len(sExec) - i)
- Exit For
- End If
- Next i
- If i <= Len(sExec) Then
- GetTableField = 1
- Else
- GetTableField = 0
- End If
- Exit Function
- ErrCtrl:
- GetTableField = -1
- End Function
- Public Function InitView(tv As TreeView, Optional Ssql As String = " 1=1 ")
- '初始化字段树
- ' On Error GoTo ErrCtrl
- Dim rs As New ADODB.Recordset
- Dim s As String
- Dim nodX As Node
- If Ssql = "" Then
- Ssql = " 1=1 "
- End If
- tv.Nodes.Clear
- Set nodX = tv.Nodes.Add(, , "R", "备选项目")
- '读取表
- s = "select distinct TableName as TableFrom from Rs_Items where " & Ssql
- Set rs = Cw_DataEnvi.DataConnect.Execute(s)
- With rs
- If .EOF() Then
- Exit Function
- End If
- Do While Not .EOF()
- Set nodX = tv.Nodes.Add("R", tvwChild, UCase(Trim(!TableFrom)), GetTableNameC(Trim(!TableFrom)))
- nodX.EnsureVisible
- .MoveNext
- Loop
- End With
- '读取字段
- s = "select FieldName as FieldName,CHName as FieldNameC,TableName as TableFrom " & Chr(10) _
- & ",Correlation as FieldRelation,CorTable as CorTable ,IndexCode as TCode,IndexName as TName,AddMinusItem " & Chr(10) _
- & " from Rs_Items where " & Ssql 'TableName is not Null "
- Set rs = Cw_DataEnvi.DataConnect.Execute(s)
- With rs
- If .EOF() Then
- Exit Function
- End If
- Do While Not .EOF()
- '末级节点的Tag值为此字段的英文全名
- If !AddMinusItem = 1 And Trim(Ssql) = Trim("1=1") Then
- '如果是选入工资表的字段,添加工资表节点
- Set nodX = tv.Nodes.Add(UCase("PM_PayRoll"), tvwChild, UCase("PM_PayRoll") & "." & UCase(Trim(!FieldName)), UCase(Trim(!FieldNameC)))
- If Trim(!CorTable & "") <> "" And Trim(!TCode & "") <> "" And Trim(!TName & "") <> "" Then
- nodX.Tag = Trim(!FieldRelation & "") & "@" & Trim(!CorTable & "") & "@" & Trim(!TCode & "") & "@" & Trim(!TName & "")
- End If
- End If
- Set nodX = tv.Nodes.Add(UCase(Trim(!TableFrom)), tvwChild, UCase(Trim(!TableFrom) & "." & Trim(!FieldName)), UCase(Trim(!FieldNameC)))
- If Trim(!CorTable & "") <> "" And Trim(!TCode & "") <> "" And Trim(!TName & "") <> "" Then
- nodX.Tag = Trim(!FieldRelation & "") & "@" & Trim(!CorTable & "") & "@" & Trim(!TCode & "") & "@" & Trim(!TName & "")
- End If
- .MoveNext
- Loop
- End With
- '添加会计年,会计期间,工资类别到工资表节点
- If IsNodeExist("PM_PayRoll", tv) Then
- Set nodX = tv.Nodes.Add(UCase("PM_PayRoll"), tvwChild, UCase("PM_PayRoll.KjYear"), "会计年")
- Set nodX = tv.Nodes.Add(UCase("PM_PayRoll"), tvwChild, UCase("PM_PayRoll.Period"), "会计月")
- Set nodX = tv.Nodes.Add(UCase("PM_PayRoll"), tvwChild, UCase("PM_PayRoll.SortID"), "工资类别")
- nodX.Tag = "0@PM_Sort@SortID@SortName"
- End If
- '添加会计年,会计期间到考勤表节点
- If IsNodeExist("PM_AttendRecord", tv) Then
- Set nodX = tv.Nodes.Add(UCase("PM_AttendRecord"), tvwChild, UCase("PM_AttendRecord.KjYear"), "会计年")
- Set nodX = tv.Nodes.Add(UCase("PM_AttendRecord"), tvwChild, UCase("PM_AttendRecord.Period"), "会计月")
- End If
- Set rs = Nothing
- Exit Function
- ErrCtrl:
- Set rs = Nothing
- Dim smsg As String
- Dim smsgSys As String
- smsg = GetError(Err.Number)
- smsgSys = Err.Number & Err.Description & "!"
- MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
- End Function
- Public Function GetFieldHelp(sExp As String, sID As String, sTable As String, sCode As String, sName As String)
- Dim i As Integer
- Dim j As Integer
- Dim k As Integer
- Dim s(3) As String
- If sExp = "" Then
- Exit Function
- End If
- j = 1
- k = 0
- '取ID,关联表,编码,名称
- Do While i <= Len(sExp)
- For i = j To Len(sExp)
- If Mid(sExp, i, 1) = "@" Then
- s(k) = Mid(sExp, j, i - j)
- j = i + 1
- k = k + 1
- Exit For
- End If
- Next i
- If i > Len(sExp) Then
- sName = Mid(sExp, j, i - j)
- End If
- Loop
- sID = s(0)
- sTable = s(1)
- sCode = s(2)
- End Function
- Public Function GetError(iNum As Long) As String
- ' On Error Resume Next
- Dim msg As String
- Select Case iNum
- Case -2147217873
- msg = "违反唯一性或者编码已经使用!"
- Case -2147217913
- msg = "录入了错误的日期格式,正确格式为 2001-09-12" & Chr(10) _
- & "或者录入了错误的数字格式,正确格式为 123456789.12"
- Case -2147217900
- msg = "语法错误!"
- Case Else
- msg = ""
- End Select
- GetError = msg
- End Function
- Public Function ReplByPos(sExepress As String, sReplace As String, Optional iStart As Integer = 0, Optional iEnd As Integer = 0) As String
- '把sExepress的第iStart字起到iEnd结束的字符替换成sReplace
- Dim i As Integer
- Dim j As Integer
- Dim sLeft As String
- Dim sRight As String
- If iStart > Len(sExepress) Then
- MsgBox "开始位置超出字符长度", vbOKOnly + vbCritical
- Exit Function
- End If
- If iStart > iEnd Then
- MsgBox "开始位置超出结束位置", vbOKOnly + vbCritical
- Exit Function
- End If
- sLeft = Left(sExepress, iStart - 1)
- sRight = Right(sExepress, Len(sExepress) - iEnd + 1)
- ReplByPos = sLeft & sReplace & sRight
- End Function
- Public Function IsItemExist(sName As String, coll As Collection, Optional iType As Integer = 0) As Integer
- 'itype=0 不区分大小写 1 区分大小写
- '返回sName的位置或-1
- Dim i As Integer
- With coll
- If .count = 0 Then
- IsItemExist = -1
- Exit Function
- End If
- If iType = 0 Then
- For i = 1 To .count
- If UCase(sName) = UCase(.Item(1)) Then
- Exit For
- End If
- Next i
- Else
- For i = 1 To .count
- If sName = .Item(1) Then
- Exit For
- End If
- Next i
- End If
- If i > .count Then
- IsItemExist = -1
- Else
- IsItemExist = i
- End If
- End With
- End Function
- Public Function GetSQLFrom(coll As Collection, sPriTableName As String) As String
- '根据所提供的表名,连接成From语句
- Dim s As String
- Dim st As String
- Dim i As Integer
- Dim j As Integer
- Dim k As Integer
- ' On Error GoTo ErrCtrl
- If sPriTableName = "" Then
- MsgBox "请输入主表名"
- Exit Function
- End If
- s = ""
- With coll
- If .count = 0 Then
- s = " " & sPriTableName & Chr(10) & " "
- GetSQLFrom = s
- Exit Function
- End If
- Select Case UCase(sPriTableName)
- Case UCase("PM_PayRoll")
- s = " PM_PayRoll left outer join PM_AttendRecord " & Chr(10) _
- & " on PM_PayRoll.EmpID=PM_AttendRecord.EmpID and PM_PayRoll.Period=PM_AttendRecord.Period and PM_PayRoll.KjYear=PM_AttendRecord.KjYear " & Chr(10) _
- & " Left Outer Join PM_TaxData " & Chr(10) _
- & " on PM_PayRoll.EmpID=PM_TaxData.EmpID and PM_PayRoll.Period=PM_TaxData.Period and PM_PayRoll.KjYear=PM_TaxData.KjYear and PM_PayRoll.SortID=PM_TaxData.SortID " & Chr(10)
- Case UCase("PM_AttendRecord")
- s = " PM_AttendRecord left outer join PM_PayRoll " & Chr(10) _
- & " on PM_PayRoll.EmpID=PM_AttendRecord.EmpID and PM_PayRoll.Period=PM_AttendRecord.Period and PM_PayRoll.KjYear=PM_AttendRecord.KjYear " & Chr(10) _
- & " Left Outer Join PM_TaxData " & Chr(10) _
- & " on PM_AttendRecord.EmpID=PM_TaxData.EmpID and PM_AttendRecord.Period=PM_TaxData.Period and PM_AttendRecord.KjYear=PM_TaxData.KjYear " & Chr(10)
- Case UCase("PM_TaxData")
- s = " PM_TaxData left outer join PM_AttendRecord " & Chr(10) _
- & " on PM_TaxData.EmpID=PM_AttendRecord.EmpID and PM_TaxData.Period=PM_AttendRecord.Period and PM_TaxData.KjYear=PM_AttendRecord.KjYear " & Chr(10) _
- & " Left Outer Join PM_PayRoll " & Chr(10) _
- & " on PM_PayRoll.EmpID=PM_TaxData.EmpID and PM_PayRoll.Period=PM_TaxData.Period and PM_PayRoll.KjYear=PM_TaxData.KjYear and PM_PayRoll.SortID=PM_TaxData.SortID " & Chr(10)
- Case Else
- s = sPriTableName & " Left Outer Join PM_PayRoll on " & Chr(10) _
- & sPriTableName & ".EmpID=PM_PayRoll.EmpID " & Chr(10) _
- & " left outer join PM_AttendRecord " & Chr(10) _
- & " on PM_PayRoll.EmpID=PM_AttendRecord.EmpID and PM_PayRoll.Period=PM_AttendRecord.Period and PM_PayRoll.KjYear=PM_AttendRecord.KjYear " & Chr(10) _
- & " Left Outer Join PM_TaxData " & Chr(10) _
- & " on PM_PayRoll.EmpID=PM_TaxData.EmpID and PM_PayRoll.Period=PM_TaxData.Period and PM_PayRoll.KjYear=PM_TaxData.KjYear and PM_PayRoll.SortID=PM_TaxData.SortID " & Chr(10)
- End Select
- '连接剩下的表
- For k = 1 To .count
- If UCase(sPriTableName) <> UCase(.Item(k)) And _
- Trim(UCase(.Item(k))) <> "" And _
- Trim(UCase(.Item(k))) <> UCase("PM_PayRoll") And _
- Trim(UCase(.Item(k))) <> UCase("PM_AttendRecord") And _
- Trim(UCase(.Item(k))) <> UCase("PM_TaxData") Then
- s = s & " left outer join " & Trim(.Item(k)) & " on " & Trim(.Item(k)) & ".EmpID=" & sPriTableName & ".EmpID " & Chr(10)
- End If
- Next k
- End With
- GetSQLFrom = s
- Exit Function
- ErrCtrl:
- Dim smsg As String
- Dim smsgSys As String
- smsg = GetError(Err.Number)
- smsgSys = Err.Number & Err.Description & "!"
- MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
- End Function
- Public Function AddTableFrom(coll As Collection, sName As String)
- '添加用户查询必须的表
- On Error GoTo ErrCtrl
- Dim i As Integer
- '如果没有定义查询条件,简单添加表名
- '如果表名集合第一项为“”,则删除第一项
- With coll
- If coll.count = 0 Then
- .Add UCase(sName)
- Exit Function
- End If
- If Trim(.Item(1)) = "" Then
- .Remove (1)
- End If
- For i = 1 To .count
- If UCase(.Item(i)) = UCase(sName) Then
- Exit For
- End If
- Next
- If i > .count Then
- .Add UCase(sName)
- End If
- End With
- Exit Function
- ErrCtrl:
- Dim smsg As String
- Dim smsgSys As String
- smsg = GetError(Err.Number)
- smsgSys = Err.Number & Err.Description & "!"
- MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
- End Function
- Public Function IsNodeExist(skey As String, tv As TreeView) As Boolean
- '测试树是否包含Key为skey的节点
- On Error GoTo ErrCtrl
- Dim i As Integer
- With tv
- For i = 1 To .Nodes.count
- If UCase(.Nodes(i).Key) = UCase(skey) Then
- IsNodeExist = True
- Exit Function
- End If
- Next
- End With
- IsNodeExist = False
- Exit Function
- ErrCtrl:
- Dim smsg As String
- Dim smsgSys As String
- smsg = GetError(Err.Number)
- smsgSys = Err.Number & Err.Description & "!"
- MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
- End Function
- Public Function FillValue2TV(sCond As String, tv As TreeView)
- '填充字段的可能值,sCond 的格式为 数字@表名@编码@名称
- On Error GoTo ErrCtrl
- tv.Nodes.Clear
- If Trim(sCond) = "" Then
- Exit Function
- End If
- Dim sID As String
- Dim sTable As String
- Dim sCode As String
- Dim sName As String
- Dim rs As New ADODB.Recordset
- Dim s As String
- tv.Nodes.Clear
- GetFieldHelp sCond, sID, sTable, sCode, sName
- With tv
- If UCase(sTable) = UCase("GY_Department") Then
- FillDept2TV "RsPmFlag", tv, Cw_DataEnvi.DataConnect
- Else
- If Trim(sID) = "" Or Trim(sTable) = "" Or Trim(sCode) = "" Or Trim(sName) = "" Then
- Set rs = Nothing
- MsgBox "字段帮助出现错误!", vbOKOnly + vbCritical
- Exit Function
- End If
- If Trim(sID) = "0" Then
- s = "select " & sCode & " as TCode, " & sName & " as TName from " & sTable
- Else
- s = "select " & sCode & " as TCode, " & sName & " as TName from " & sTable & " where SortID='" & sID & "'"
- End If
- Set rs = Cw_DataEnvi.DataConnect.Execute(s)
- If Not rs.EOF() Then
- .Nodes.Add , , "R", "备选值"
- Do While Not rs.EOF()
- .Nodes.Add "R", tvwChild, "R" & Trim(rs!TCode), Trim(rs!TName)
- rs.MoveNext
- Loop
- End If
- End If
- End With
- Exit Function
- ErrCtrl:
- Set rs = Nothing
- Dim smsg As String
- Dim smsgSys As String
- smsg = GetError(Err.Number)
- smsgSys = Err.Number & Err.Description & "!"
- MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
- End Function
- Public Function FillDept2TV(sSysCode As String, tv As TreeView, cn As Connection)
- '填充部门树
- On Error GoTo ErrCtrl
- Dim s As String
- Dim rs As New ADODB.Recordset
- Dim nod As Node
- tv.Enabled = False
- tv.Nodes.Clear
- tv.Nodes.Add , , "R", "部门"
- s = "Select DeptCode,DeptName ,ParentCode from GY_Department where " & sSysCode & "=1 order by CodeLevel"
- Set rs = Cw_DataEnvi.DataConnect.Execute(s)
- With rs
- Do While Not .EOF()
- Set nod = tv.Nodes.Add("R" & Trim(!ParentCode & ""), tvwChild, "R" & Trim(!DeptCode & ""), Trim(!DeptName & ""))
- nod.Tag = Trim(!DeptCode & "")
- If Trim(!ParentCode & "") = "" Then
- nod.EnsureVisible
- End If
- .MoveNext
- Loop
- End With
- Set rs = Nothing
- Set nod = Nothing
- tv.Enabled = True
- Exit Function
- ErrCtrl:
- Set nod = Nothing
- Set rs = Nothing
- tv.Enabled = True
- Dim smsg As String
- Dim smsgSys As String
- smsg = GetError(Err.Number)
- smsgSys = Err.Number & Err.Description & "!"
- MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
- End Function
- Public Function GetTableNameC(sTableName As String) As String
- '设置表的汉语名称
- Dim s As String
- Select Case UCase(sTableName)
- Case UCase("PM_PayRoll")
- s = "工资"
- Case UCase("Rs_BasicInfo")
- s = "基本"
- Case UCase("Rs_ExtendInfo")
- s = "扩展"
- Case UCase("PM_AttendRecord")
- s = "考勤"
- Case Else
- MsgBox "不存在此表"
- End Select
- GetTableNameC = s
- End Function
- Public Function GetCol(sFields() As CFieldValue, iNoCol As Integer, iNameCol As Integer, Optional iBeginCol As Integer = 0) As Integer
- '成功找到工号或者姓名返回1,没有找到返回0,错误返回-1
- On Error GoTo ErrCtrl
- Dim i As Integer
- iNoCol = -1
- iNameCol = -1
- GetCol = -1
- For i = LBound(sFields) To UBound(sFields)
- If Len(sFields(i).FieldName) >= 5 Then
- If UCase(Right(sFields(i).FieldName, 5)) = UCase("EmpNo") Then
- iNoCol = i + iBeginCol
- Else
- If Len(sFields(i).FieldName) >= 7 Then
- If UCase(Right(sFields(i).FieldName, 7)) = UCase("EmpName") Then
- iNameCol = i + iBeginCol
- End If
- End If
- End If
- End If
- If iNameCol >= 0 And iNoCol >= 0 Then
- Exit For
- End If
- Next i
- If iNameCol >= 0 Or iNoCol >= 0 Then
- GetCol = 1
- Else
- GetCol = 0
- End If
- Exit Function
- ErrCtrl:
- GetCol = -1
- End Function
- Public Function LenByte(str1 As String) As Long
- '计算字符串的字节数
- Dim i As Long
- Dim chr1 As String
- LenByte = 0
- str1 = Trim(str1)
- For i = 1 To Len(str1)
- chr1 = Mid(str1, i, 1)
- If Asc(chr1) >= 0 And Asc(chr1) <= 255 Then
- LenByte = LenByte + 1
- ElseIf Asc(chr1) < 0 Then '汉字
- LenByte = LenByte + 2
- End If
- Next
- End Function
- Public Function PrintGrid(vs As vsFlexGrid, iVsBeginCol As Integer, iVsSumEndCol As Integer, sRCode As String, frmSetup As DY_Dyymsz, Optional bPrint As Boolean = False)
- '打印网格
- On Error GoTo ErrCtrl
- Dim i As Long
- Dim j As Long
- Dim k As Long
- Dim m As Long
- Dim n As Long
- Dim s As String
- Dim bNext As Boolean '临时变量
- Dim bSumRow As Boolean '是否是合计行
- Dim iStartCol As Long '打印数据开始列
- Dim rs As New ADODB.Recordset
- '--------------------------------------------------控制信息-------------------------------------------------
- Dim iPrintStyle As Integer '打印方式 0每页输出一个表头 1每行输出一个表头
- Dim iSumPerPage As Integer '1每页输出合计
- Dim iSplitPage As Integer '1分页打印
- Dim sRTitle As String '标题
- Dim iShowAllCols As Integer '1 显示所有可见网格列
- s = "select * from PM_ReportSort where RCode='" & sRCode & "'"
- Set rs = Cw_DataEnvi.DataConnect.Execute(s)
- With rs
- If Not .EOF() Then
- iPrintStyle = !PrintStyle
- iSumPerPage = !SumPerPage
- iSplitPage = !SplitPage
- iShowAllCols = !ShowAllCols
- sRTitle = Trim(!RTitle)
- Else
- MsgBox "当前报表已被删除,无法读取格式!", vbOKOnly + vbCritical
- Exit Function
- End If
- End With
- Set rs = Nothing
- '--------------------------------------------------控制信息完成-------------------------------------------------
- '--------------------------------------------------打印参数-------------------------------------------------
- '设置打印参数
- If Not SetupPage(frmSetup, DY_Tybbyldy) Then
- MsgBox "打印设置失败!", vbOKOnly + vbCritical
- Exit Function
- End If
- '读取打印设置
- Dim sDataFontName As String '数据字体名称
- Dim sTitleFontName As String '表头字体名称
- Dim iDataFontSize As Long '数据字体大小
- Dim iTitleFontSize As Long '表头字体大小
- Dim iRowsPerPage As Long '每行显示数据行数
- Dim bLimitRowPerPage As Boolean '是否每页限制行数
- Dim iLimitRowsPerPage As Long '每页限制行数
- Dim iClientHeight As Long '页面可用高度
- Dim iPageLeft As Long '左边界
- Dim iClientWidth As Long '页面可用宽度
- Dim iPageTop As Long '上边界
- Dim iTitleFontHeight As Long '标题高度
- Dim iDataFontHeight As Long '数据高度
- With frmSetup
- sTitleFontName = .Btztlabel.Caption
- sDataFontName = .SjztLabel.Caption
- iTitleFontSize = Val(.Btzhlabel.Caption)
- iDataFontSize = Val(.Sjzhlabel.Caption)
- bLimitRowPerPage = .ZdhsCheck.Value
- iLimitRowsPerPage = Val(.BbhsText)
- End With
- With DY_Tybbyldy.Tydy
- .StartDoc
- .FontName = sTitleFontName
- .FontSize = iTitleFontSize
- .CalcText = "测试"
- iTitleFontHeight = .TextHei
- .FontName = sDataFontName
- .FontSize = iDataFontSize
- .CalcText = "测试"
- iDataFontHeight = .TextHei
- .EndDoc
- .KillDoc
- iPageHeight = .PageHeight
- iClientHeight = .PageHeight - .MarginBottom - .MarginTop
- iPageTop = .MarginTop
- iClientWidth = .PageWidth - .MarginLeft - .MarginRight
- iPageLeft = .MarginLeft
- End With
- '--------------------------------------------------打印参数完成-------------------------------------------------
- '--------------------------------------------------读取数据信息-------------------------------------------------
- '定义打印开始列
- If iShowAllCols = 1 Then
- iStartCol = iVsBeginCol
- Else
- iStartCol = iVsSumEndCol + 1
- End If
- '读取有效数据
- Dim sData() As String '网格表体数据
- Dim sTitle() As String '表头数据
- Dim iPages() As Long '打印分页信息,第i页结束行在sData()中的位置是iPages(i)
- Dim iTitleRows() As String '打印的表头行值
- Dim iDataRows() As String '打印的数据行值
- Dim iColsPerPage() As Long '每行在页面上的折行信息 第i行的结束列对应sData()中的iColsPerPage(i)列
- Dim iCols() As Long '需要打印的列值
- Dim iColWidth() As Long '需要打印的列款
- Dim iColType() As Long '需要打印的列数据类型
- Dim iColFormat() As String '需要打印的列格式
- With vs
- '读取有效列
- ReDim iCols(0)
- iCols(0) = 0
- ReDim iColWidth(0)
- iColWidth(0) = 0
- ReDim iColType(0)
- iColType(0) = 0
- ReDim iColFormat(0)
- iColFormat(0) = ""
- For i = 0 To .Cols - 1
- If Not .ColHidden(i) Then
- ReDim Preserve iCols(UBound(iCols) + 1)
- iCols(UBound(iCols)) = i
- ReDim Preserve iColWidth(UBound(iColWidth) + 1)
- If .ColWidth(i) >= iClientWidth Then
- MsgBox "纸张宽度太小不能输出报表,请重新设置!", vbOKOnly + vbCritical
- Exit Function
- End If
- iColWidth(UBound(iColWidth)) = .ColWidth(i)
- ReDim Preserve iColType(UBound(iColType) + 1)
- iColType(UBound(iColType)) = Val(.TextMatrix(0, i))
- ReDim Preserve iColFormat(UBound(iColFormat) + 1)
- iColFormat(UBound(iColFormat)) = .ColFormat(i)
- End If
- Next i
- If UBound(iCols) = 0 Then
- Exit Function
- End If
- '读取有效表头行
- ReDim iTitleRows(0)
- iTitleRows(0) = 0
- For i = 0 To .FixedRows - 1
- If .RowHidden(i) = False Then
- ReDim Preserve iTitleRows(UBound(iTitleRows) + 1)
- iTitleRows(UBound(iTitleRows)) = i
- End If
- Next i
- If UBound(iTitleRows) = 0 Then
- Exit Function
- End If
- '读取有效数据行
- ReDim iDataRows(0)
- iDataRows(0) = 0
- For i = .FixedRows To .Rows - 1
- If .RowHidden(i) = False Then
- ReDim Preserve iDataRows(UBound(iDataRows) + 1)
- iDataRows(UBound(iDataRows)) = i
- End If
- Next i
- If UBound(iDataRows) = 0 Then
- Exit Function
- End If
- '读取表头数据
- ReDim sTitle(UBound(iTitleRows) - 1, UBound(iCols) - 1)
- For i = LBound(iTitleRows) + 1 To UBound(iTitleRows)
- For j = LBound(iCols) + 1 To UBound(iCols)
- sTitle(i - LBound(iTitleRows) - 1, j - LBound(iCols) - 1) = .TextMatrix(iTitleRows(i), iCols(j))
- Next j
- Next i
- '读取表体数据
- ReDim sData(UBound(iDataRows) - 1, UBound(iCols) - 1)
- For i = LBound(iDataRows) + 1 To UBound(iDataRows)
- For j = LBound(iCols) + 1 To UBound(iCols)
- sData(i - LBound(iDataRows) - 1, j - LBound(iCols) - 1) = .TextMatrix(iDataRows(i), iCols(j))
- Next j
- Next i
- '--------------------------------------------------读取数据信息完成-------------------------------------------------
- '--------------------------------------------------计算打印信息-------------------------------------------------
- '计算数据行折行信息
- ReDim iColsPerPage(0)
- iColsPerPage(0) = iStartCol
- Dim iWidth As Long
- iWidth = 0
- For i = LBound(iColWidth) + 1 + iStartCol To UBound(iColWidth)
- iWidth = iWidth + iColWidth(i)
- If iWidth > iClientWidth Then
- iWidth = 0
- i = i - 1
- ReDim Preserve iColsPerPage(UBound(iColsPerPage) + 1)
- iColsPerPage(UBound(iColsPerPage)) = i
- End If
- Next i
- If iWidth <> 0 Then
- ReDim Preserve iColsPerPage(UBound(iColsPerPage) + 1)
- iColsPerPage(UBound(iColsPerPage)) = UBound(sData, 2) + 1
- End If
- '计算每页可以打印的行数
- If iSumPerPage = 1 Then
- i = 1
- Else
- i = 0
- End If
- j = UBound(sTitle) + 2
- If iPrintStyle = PRINTSTYLE_ONETITLE Then
- iRowsPerPage = (iClientHeight - iTitleFontHeight - iDataFontHeight - 1000) (UBound(iColsPerPage) * (iDataFontHeight + 100)) - i
- Else
- j = UBound(sTitle) + 2
- iRowsPerPage = (iClientHeight - iTitleFontHeight - iDataFontHeight - 1000) (UBound(iColsPerPage) * j * (iDataFontHeight + 250)) - i
- End If
- If bLimitRowPerPage = True Then
- If iRowsPerPage > iLimitRowsPerPage Then
- iRowsPerPage = iLimitRowsPerPage
- End If
- End If
- '计算分页信息
- ReDim iPages(0)
- iPages(0) = -1
- If iVsSumEndCol = -1 Or iSplitPage = 0 Then '如果没有分页情况,只需判断本页最多能够打印的行数
- For i = LBound(sData) To UBound(sData)
- If i Mod iRowsPerPage = iRowsPerPage - 1 Then
- ReDim Preserve iPages(UBound(iPages) + 1)
- iPages(UBound(iPages)) = i
- End If
- Next i
- Else
- '如果有分页情况,则首先判断是否是分页行,然后循环判断下边的行
- '如果是合计行则加入本页(在数据行数小于可打印行数的情况下)
- For i = LBound(sData) To UBound(sData) '数据行数达到最大行
- If (i - iPages(UBound(iPages))) Mod iRowsPerPage = 0 And i <> 0 Then
- ReDim Preserve iPages(UBound(iPages) + 1)
- iPages(UBound(iPages)) = i
- If Len(sData(i, iVsSumEndCol)) >= 3 Then
- s = Right(sData(i, iVsSumEndCol), 3)
- Else
- s = ""
- End If
- If s = "合计:" Or s = "小计:" Then
- bSumRow = True
- End If
- Else '合计分行
- If Len(sData(i, iVsSumEndCol)) >= 3 Then
- s = Right(sData(i, iVsSumEndCol), 3)
- Else
- s = ""
- End If
- If s = "合计:" Or s = "小计:" Or bSumRow = True Then
- bNext = False
- bSumRow = False
- For j = iVsSumEndCol To iVsBeginCol + 1 Step -1
- If Len(sData(i + 1, j - 1)) >= 3 Then
- s = Right(sData(i + 1, j - 1), 3)
- Else
- s = ""
- End If
- If s = "合计:" Or s = "小计:" Then
- bNext = True
- i = i + 1
- '如果当前行达到最大行,分页
- If (i - iPages(UBound(iPages))) Mod iRowsPerPage = 0 Then
- ReDim Preserve iPages(UBound(iPages) + 1)
- iPages(UBound(iPages)) = i
- bNext = False
- End If
- End If
- Next j
- '因为如果bNext=true 则数据行多移动了一行,减去
- If bNext = True Then
- i = i - 1
- End If
- '判断起始列的合计情况
- bNext = False
- Do While True
- If i < UBound(sData) Then
- If Len(sData(i + 1, iVsBeginCol)) >= 3 Then
- s = Right(sData(i + 1, iVsBeginCol), 3)
- Else
- s = ""
- End If
- If s = "小计:" Or s = "合计:" Then
- i = i + 1
- bNext = True
- Else
- Exit Do
- End If
- Else
- Exit Do
- End If
- Loop
- If bNext = True Then
- ReDim Preserve iPages(UBound(iPages) + 1)
- iPages(UBound(iPages)) = i
- End If
- End If
- End If
- Next i
- End If
- '剩下的行也要占一页
- If iPages(UBound(iPages)) <> UBound(sData) Then
- ReDim Preserve iPages(UBound(iPages) + 1)
- iPages(UBound(iPages)) = UBound(sData)
- End If
- End With
- '合计每行的数据形成本页合计
- Dim sTotal() As String
- ReDim sTotal(0, 0)
- If iSumPerPage = 1 Then
- If UBound(iPages) >= 1 Then
- ReDim sTotal(UBound(iPages) - 1, UBound(sData, 2))
- For i = 0 To UBound(sTotal) '行
- For j = LBound(iCols) + 1 To UBound(iCols) '列
- If iColType(j) = DATA_NUMERIC Then
- For n = iPages(i) + 1 To iPages(i + 1)
- bNext = False
- '合计行的信息不加入本页合计
- For m = iVsBeginCol To iVsSumEndCol
- If Len(sData(n, m)) >= 3 Then
- s = Right(sData(n, m), 3)
- Else
- s = ""
- End If
- If s = "合计:" Or s = "小计:" Then
- bNext = True
- Exit For
- End If
- Next m
- If bNext = False Then
- sTotal(i, j - 1) = Val(sTotal(i, j - 1)) + Val(Replace(sData(n, j - 1), ",", ""))
- End If
- Next n
- End If
- Next j
- Next i
- End If
- End If
- '格式化合计信息
- If iShowAllCols = 0 Then
- For i = LBound(sData) To UBound(sData)
- For j = iVsSumEndCol To LBound(sData, 2) Step -1
- If Len(sData(i, j)) >= 3 Then
- s = Right(sData(i, j), 3)
- Else
- s = ""
- End If
- If s = "小计:" Then
- If i - 1 >= 0 Then
- sData(i, iVsSumEndCol + 1) = sData(i - 1, j) & s
- End If
- End If
- If sData(i, j) = "合计:" Then
- sData(i, iVsSumEndCol + 1) = "合计:"
- End If
- Next j
- Next i
- End If
- '--------------------------------------------------计算打印信息-------------------------------------------------
- '--------------------------------------------------打印数据-------------------------------------------------
- '输送数据
- Dim dy As Long
- dy = 0
- With DY_Tybbyldy.Tydy
- .StartDoc
- For i = LBound(iPages) + 1 To UBound(iPages)
- .FontName = sTitleFontName
- .FontSize = iTitleFontSize
- .CalcText = sRTitle
- .CurrentX = (iClientWidth - .TextWid) / 2 + iPageLeft
- .CurrentY = iPageTop
- DY_Tybbyldy.Tydy = sRTitle
- .CurrentX = (iClientWidth - .TextWid) / 2 + iPageLeft - 500
- .CurrentY = .CurrentY + 100
- .CalcText = sRTitle
- .DrawLine .CurrentX, .CurrentY, (iClientWidth + .TextWid) / 2 + iPageLeft + 500, .CurrentY
- .CurrentY = .CurrentY + 200
- .CurrentX = .MarginLeft
- .FontName = sDataFontName
- .FontSize = iDataFontSize
- dy = .CurrentY
- '打印分组信息
- If iSplitPage = 1 And iVsSumEndCol <> -1 Then
- If Len(sData(iPages(i - 1) + 1, iVsSumEndCol)) >= 3 Then
- If Right(sData(iPages(i - 1) + 1, iVsSumEndCol), 3) = "小计:" Then
- If iPages(i - 1) >= 0 Then
- DY_Tybbyldy.Tydy = sTitle(UBound(sTitle), iVsSumEndCol) & ":" & sData(iPages(i - 1) + 1 - 1, iVsSumEndCol)
- End If
- Else
- DY_Tybbyldy.Tydy = sTitle(UBound(sTitle), iVsSumEndCol) & ":" & sData(iPages(i - 1) + 1, iVsSumEndCol)
- End If
- Else
- DY_Tybbyldy.Tydy = sTitle(UBound(sTitle), iVsSumEndCol) & ":" & sData(iPages(i - 1) + 1, iVsSumEndCol)
- End If
- End If
- .CurrentX = .PageWidth - .MarginRight - .TextWidth("第100页 共100页 ")
- .CurrentY = dy
- DY_Tybbyldy.Tydy = "第" & i & "页 共" & UBound(iPages) & "页 "
- If iPrintStyle = PRINTSTYLE_ONETITLE Then '只输出一个表头
- For j = LBound(iColsPerPage) + 1 To UBound(iColsPerPage)
- .CurrentX = .MarginLeft
- .CurrentY = .CurrentY + 100
- .StartTable
- '设置表格属性
- .TableCell(tcRows) = iPages(i) - iPages(i - 1) + UBound(sTitle) + 1
- .TableCell(tcCols) = iColsPerPage(j) - iColsPerPage(j - 1)
- For m = 1 To .TableCell(tcRows) '行高
- .TableCell(tcRowHeight, m) = iDataFontHeight + 100
- Next m
- For m = 1 To .TableCell(tcCols) '列宽
- .TableCell(tcColWidth, , m) = iColWidth(m + iColsPerPage(j - 1))
- Next m
- '填充表头
- For m = 1 To UBound(sTitle) + 1
- For k = 1 To .TableCell(tcCols)
- .TableCell(tcAlign, m, k) = 6
- .TableCell(tcText, m, k) = Trim(sTitle(m - 1, k + iColsPerPage(j - 1) - 1))
- .CalcText = .TableCell(tcText, m, k)
- If (.TableCell(tcColWidth, , k) - .TextWid - 100) > 0 Then
- .TableCell(tcText, m, k) = Space((.TableCell(tcColWidth, , k) - .TextWid - 100) / .TextWidth("测试")) & .TableCell(tcText, m, k)
- End If
- Next k
- Next m
- '填充数据
- For m = UBound(sTitle) + 1 + 1 To .TableCell(tcRows)
- For k = 1 To .TableCell(tcCols)
- If iColType(k + iColsPerPage(j - 1)) = DATA_NUMERIC Then
- .TableCell(tcAlign, m, k) = 8 'RightMiddle
- Else
- .TableCell(tcAlign, m, k) = 6 'LeftMiddle
- End If
- If Len(sData(m + iPages(i - 1) - 1, k + iColsPerPage(j - 1) - 1)) >= 3 Then
- If Right(sData(m + iPages(i - 1) - 1, k + iColsPerPage(j - 1) - 1), 3) <> "小计:" And _
- Right(sData(m + iPages(i - 1) - 1, k + iColsPerPage(j - 1) - 1), 3) <> "合计:" Then
- s = sData(m + iPages(i - 1) - 1, k + iColsPerPage(j - 1) - 1)
- End If
- End If
- .TableCell(tcText, m, k) = Format(sData(m + iPages(i - 1) - 1, k + iColsPerPage(j - 1) - 1), iColFormat(k + iColsPerPage(j - 1)))
- Next k
- Next m
- '填充合计信息
- If iSumPerPage = 1 And UBound(sTotal) > 0 Then
- .TableCell(tcRows) = .TableCell(tcRows) + 1
- .TableCell(tcRowHeight, .TableCell(tcRows)) = iDataFontHeight + 100
- For k = 1 To .TableCell(tcCols)
- If iColType(k + iColsPerPage(j - 1)) = DATA_NUMERIC Then
- .TableCell(tcAlign, .TableCell(tcRows), k) = 8 'RightMiddle
- Else
- .TableCell(tcAlign, .TableCell(tcRows), k) = 6 'LeftMiddle
- End If
- .TableCell(tcText, .TableCell(tcRows), k) = Format(sTotal(i - 1, k + iColsPerPage(j - 1) - 1), iColFormat(k + iColsPerPage(j - 1)))
- Next k
- If j = 1 Then
- .TableCell(tcText, .TableCell(tcRows), 1) = "本页小计:"
- End If
- End If
- .EndTable
- Next j
- Else '每行数据输出表头
- For n = iPages(i - 1) + 1 To iPages(i) 'n为数据行
- For j = LBound(iColsPerPage) + 1 To UBound(iColsPerPage) 'j为一个数据行分的断
- .CurrentX = .MarginLeft
- .CurrentY = .CurrentY + 100
- .StartTable
- '设置表格属性
- .TableCell(tcRows) = UBound(sTitle) + 1 + 1
- .TableCell(tcCols) = iColsPerPage(j) - iColsPerPage(j - 1)
- For m = 1 To .TableCell(tcRows) '行高
- .TableCell(tcRowHeight, m) = iDataFontHeight + 100
- Next m
- For m = 1 To .TableCell(tcCols) '列宽
- .TableCell(tcColWidth, , m) = iColWidth(m + iColsPerPage(j - 1))
- Next m
- '填充表头
- For m = 1 To UBound(sTitle) + 1
- For k = 1 To .TableCell(tcCols)
- .TableCell(tcAlign, m, k) = 6
- .TableCell(tcText, m, k) = Trim(sTitle(m - 1, k + iColsPerPage(j - 1) - 1))
- .CalcText = .TableCell(tcText, m, k)
- If (.TableCell(tcColWidth, , k) - .TextWid - 100) > 0 Then
- .TableCell(tcText, m, k) = Space((.TableCell(tcColWidth, , k) - .TextWid - 100) / .TextWidth("测试")) & .TableCell(tcText, m, k)
- End If
- Next k
- Next m
- '填充数据
- For k = 1 To .TableCell(tcCols)
- If iColType(k + iColsPerPage(j - 1)) = DATA_NUMERIC Then
- .TableCell(tcAlign, m, k) = 8 'RightMiddle
- Else
- .TableCell(tcAlign, m, k) = 6 'LeftMiddle
- End If
- .TableCell(tcText, .TableCell(tcRows), k) = Format(sData(n, k + iColsPerPage(j - 1) - 1), iColFormat(k + iColsPerPage(j - 1) - 1))
- Next k
- .EndTable
- Next j
- '如果不是本页的最后一行并且后边没有本业合计,添加分隔线
- If n <> iPages(i) Or iSumPerPage = 1 Then
- .CurrentY = .CurrentY + 200
- .CurrentX = .MarginLeft
- .PenStyle = psDash
- .DrawLine .CurrentX, .CurrentY, .PageWidth - .MarginRight, .CurrentY
- .PenStyle = psSolid
- End If
- Next n
- '添加本页合计信息
- If iSumPerPage = 1 Then
- For j = LBound(iColsPerPage) + 1 To UBound(iColsPerPage) 'j为一个数据行分的断
- .CurrentX = .MarginLeft
- .CurrentY = .CurrentY + 100
- .StartTable
- '设置表格属性
- .TableCell(tcRows) = UBound(sTitle) + 1 + 1
- .TableCell(tcCols) = iColsPerPage(j) - iColsPerPage(j - 1)
- For m = 1 To .TableCell(tcRows) '行高
- .TableCell(tcRowHeight, m) = iDataFontHeight + 100
- Next m
- For m = 1 To .TableCell(tcCols) '列宽
- .TableCell(tcColWidth, , m) = iColWidth(m + iColsPerPage(j - 1))
- Next m
- '填充表头
- For m = 1 To UBound(sTitle) + 1
- For k = 1 To .TableCell(tcCols)
- .TableCell(tcAlign, m, k) = 6
- .TableCell(tcText, m, k) = Trim(sTitle(m - 1, k + iColsPerPage(j - 1) - 1))
- .CalcText = .TableCell(tcText, m, k)
- If (.TableCell(tcColWidth, , k) - .TextWid - 100) > 0 Then
- .TableCell(tcText, m, k) = Space((.TableCell(tcColWidth, , k) - .TextWid - 100) / .TextWidth("测试")) & .TableCell(tcText, m, k)
- End If
- Next k
- Next m
- '填充数据
- For k = 1 To .TableCell(tcCols)
- If iColType(k + iColsPerPage(j - 1)) = DATA_NUMERIC Then
- .TableCell(tcAlign, m, k) = 8 'RightMiddle
- Else
- .TableCell(tcAlign, m, k) = 6 'LeftMiddle
- End If
- .TableCell(tcText, .TableCell(tcRows), k) = Format(sTotal(i - 1, k + iColsPerPage(j - 1) - 1), iColFormat(k + iColsPerPage(j - 1)))
- Next k
- If j = LBound(iColsPerPage) + 1 Then
- .TableCell(tcText, .TableCell(tcRows), 1) = "本页小计:"
- End If
- .EndTable
- Next j
- End If
- End If
- If i <> UBound(iPages) Then
- .NewPage
- End If
- Next i
- .EndDoc
- DY_Tybbyldy.PageHScroll.Max = .Pagecount
- DY_Tybbyldy.PageHScroll.Min = 1
- DY_Tybbyldy.PageHScroll.Value = 1
- End With
- If bPrint = False Then
- DY_Tybbyldy.Show 1
- Else
- DY_Tybbyldy.Tydy.PrintDoc
- End If
- Exit Function
- ErrCtrl:
- Set rs = Nothing
- End Function
- Public Function SetupPage(frmSetup As DY_Dyymsz, frmPrint As DY_Tybbyldy) As Boolean
- Dim Tsxx As String
- Dim Papername(1 To 70) As String
- Papername(1) = "Letter, 8 1/2 x 11 英寸"
- Papername(2) = "Letter Small, 8