ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 5 4

7 ѹҤ ..2549
109 Users On-Line.
Visitors - Page views
 8 9 7 3 8 9 7
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

Visual Basic 6.0 Ѻ÷§ҹ Active Report ͹ 2

Category »  VB 6/VB.Net
: Webmaster 12/2/2551 12:00:00
(ҹ : 37936) 
Ѻ͹ ҹʹǷҧ Ը 㹡äǺʴŢͧ§ҹ 鴨ԧ ǻСͺ ʴ᷹ҧ ... ... ÷§ҹٻẺ¤֧ѹ 繵ͧҹ͡Ẻҡ Designer ¡仹ФѺ ö˹ͧ (ͧ Ҩҧ) ¡ӧҹѡɳТͧ Run-Time 蹤 ͧ繼Ѿѹҹ Ҽ١͹ŵԴµǡѺŴͧҹŹ (Design Time) ͧҡТҴ״· ǺʹҧҹʹѺҹ ѡ ͧͧèѴ (Group) ¡§ҹ͡Ǵ ¡ Designer § ѹ ... й͡ҡǹ ͧ繶֧äӹdzҤҷҧԵʵ ͧٵ (ա ˹ҹǤǢǴ µչҢ˹ѵѵ ... 55555) ¡á˹ŧ㹵᷹ ... ͹Ѻҹ 鴵Ẻͧ Visual Basic ǹ ... Ҷ֧ ç ͡Ҥسöѹ任ءҹ;ʹҤ ¡ë͢ҧҡ¤Ѻ ... ͧ

ǹ㹵͹ ù ComboBox ͹㹡͡ҹ


ҡ Designer ҡ鹡͡ Insert Group Header


ҡ GroupHeader GroupFooter 繢ͧѹ
ҡ͹ 1 ͧͧǹǢͧ§ҹ GroupHeader
lblGroupData ҹ§ҹẺ


ǹͧ GroupFooter TextBox (txtSumSalary) ͷзӡӹǹԹ͹ѡҹ


§ҹª;ѡҹ


¡Ἱ - DepartmentName


¡˹ - PositionName

ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴ Microsoft Data Access Object (MDAC) Jet 4.0 Update

ǹͧ frmPrintEmployee

Private Sub Form_Load()
On Error GoTo ErrorHandler
    Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    ' Ͱҹ
    Call OpenDataBase
    
    '  ComboBox ͹㹡þ§ҹ
    cmbPrint.Clear
    cmbPrint.AddItem " ª;ѡҹ"
    cmbPrint.AddItem " §ҹἹ"
    cmbPrint.AddItem " §ҹ˹"
    cmbPrint.ListIndex = 0

ExitProc:
    Exit Sub
    
ErrorHandler:
    MsgBox "Error : " & Err.Number & vbCrLf & Err.Description, vbOKOnly + vbExclamation, "§ҹԴҴ"
    Resume ExitProc
End Sub

Private Sub cmdPreview_Click()
    Set RS = New ADODB.Recordset
    ' ¡ҧͧѹẺͧѺѹФѺ
    ' ѹԧҧͧԹ͹ ҡö÷ Group Ҥ Sum ᷹
    ' ͧͧСѹ
    Statement = "SELECT tblEmployee.EmployeePK, tblEmployee.EmployeeID, " & _
                            " tblEmployee.EmployeeName, tblEmployee.DateStart, " & _
                            " tblPosition.PositionName, tblDepartment.DepartmentName, " & _
                            " tblEmployee.Salary " & _
                            " FROM (tblPosition INNER JOIN tblEmployee ON tblPosition.PositionPK = " & _
                            " tblEmployee.PositionFK) INNER JOIN " & _
                            " tblDepartment ON tblEmployee.DepartmentFK = tblDepartment.DepartmentPK "
                            
    ' ͧѺ ... ÷ӡ Ѻ  ORDER ѹդѹѹФѺ
    ' µ¤ѡоҴçẺ ... ͼͧͺ
    ' ҡس ORDER çѺͧ ѾԴâҺҧ
    Select Case cmbPrint.ListIndex
        ' ʴžѡҹ
        Case 0
            Statement = Statement & " ORDER BY EmployeeID "
        ' ʴ§ҹ˹
        Case 1
            Statement = Statement & " ORDER BY DepartmentName, EmployeeID "
        ' ʴ§ҹἹ
        Case 2
            Statement = Statement & " ORDER BY PositionName, EmployeeID "
    End Select
    
    RS.Open Statement, ConnDB, adOpenForwardOnly, adLockReadOnly, adCmdText
    
    ' ǹӤѭ㹡÷§ҹ Active Report
    ' 駤  ü١§ҹҡѺ Object
    Set rptPrint = New arEmployeeListGroup   ' Ҩҡ§ҹ (Designer)
    
    ' ARViewEmployeeList ǹ Control ҧ躹 frmPrintEmployee
    Set Me.ARViewEmployeeList.object = rptPrint
    
    ' ١ҹ (Bound Control) Ẻ Run Time ҡѺ Object
    ' dcRptData ǹѹẺʴŢͧ ActiveReport ФѺ
    Set rptPrint.dcRptData.Recordset = RS
End Sub
ǹͧ Report Designer - arEmployeeListGroup

Option Explicit

Private bLastPage As Boolean
' Сȵ i  ¹Ẻ Public Ѻ§ҹ
' ¤㹷ء¢ͧ§ҹҹ ͧ繵÷С麹ش
' §ҹ蹹ѹͧ͡Ѻ ... ͧ
Private i As Integer
Private SumSalary As Double
'  ѹЫ  ... СȵẺ Private ѹҺ͡ Public

' ǹǹͧҹҷ¡
' ͡ҡ GroupHeader1.GroupValue   èѴ§ҹ
Private Sub ActiveReport_FetchData(eof As Boolean)
    ' ҡ bLastPage դ繨ԧ
    bLastPage = dcRptData.Recordset.eof
    
    If Not eof Then
        ' ӹǹùѺͧӴѺ
        i = i + 1
        Select Case frmPrintEmployee.cmbPrint.ListIndex
            Case 0  ' ʴ¡÷
            Case 1  ' ¡Ἱ
                GroupHeader1.GroupValue = dcRptData.Recordset("DepartmentName")
            Case 2  ' ¡˹
                GroupHeader1.GroupValue = dcRptData.Recordset("PositionName")
        End Select
    End If
End Sub

' ǹͧ÷ӡ ӡ駼ѹ§ҹ ??????
Private Sub GroupHeader1_Format()
    Select Case frmPrintEmployee.cmbPrint.ListIndex
        Case 0  ' ʴ¡÷
            lblGroupData.Caption = "§ҹª;ѡҹ:"
            lblDepartment.Alignment = ddTXLeft
            lblDepartment.Caption = "Ἱ"
        Case 1  ' ¡Ἱ
            lblGroupData.Caption = "Ἱ: " & dcRptData.Recordset("DepartmentName")
            ' ҹ Control  ¡á˹㹢 Run-Time
            lblDepartment.Alignment = ddTXRight
            lblDepartment.Caption = "Թ͹"
        Case 2  ' ¡˹
            lblGroupData.Caption = "˹: " & dcRptData.Recordset("PositionName")
            ' ҹ Control  ¡á˹㹢 Run-Time
            lblPosition.Caption = "Ἱ"
            lblPosition.Alignment = ddTXLeft
            lblDepartment.Caption = "Թ͹"
            txtDepartment.Alignment = ddTXRight
    End Select
End Sub

' ´ҧйʴ Detail 
Private Sub Detail_Format()
    ' ǹ i ҡ Group ᷹
    txtItem.Text = i & "."
    
    txtEmployeeID.Text = "" & Trim(dcRptData.Recordset("EmployeeID"))
    txtName.Text = "" & Trim(dcRptData.Recordset("EmployeeName"))
    txtPosition.Text = "" & Trim(dcRptData.Recordset("PositionName"))
    ' Ǩͺ͹䢢ͧþ
    Select Case frmPrintEmployee.cmbPrint.ListIndex
        Case 0
            ' §ҹ͡
            txtDepartment.Text = "" & Trim(dcRptData.Recordset("DepartmentName"))
        Case 1
            ' ҪἹǹ§ҹ (GroupHeader) ѧ鹼Թ͹
            ' ѴªἹ᷹ ... (ҹ Control )
            txtDepartment.Text = Format(Trim(dcRptData.Recordset("Salary")), "#,##0.00")
            txtDepartment.Alignment = ddTXRight
        Case 2
            ' ǹӪἹç˹觫 ǹԹ͹Ἱ᷹ ... 
            txtPosition.Text = "" & Trim(dcRptData.Recordset("DepartmentName"))
            txtDepartment.Text = Format(Trim(dcRptData.Recordset("Salary")), "#,##0.00")
    End Select
    
    txtDateStart.Text = FormatDateTime(dcRptData.Recordset("DateStart"), vbShortDate)
    
    ' ֧͡ҹТʹբͧ Active Report ѹ¹ҡ VB 
    ' Ѻʹ    ... 
    ' ͧٵ µ㹡纤᷹
    SumSalary = SumSalary + dcRptData.Recordset("Salary")
    ' ҹйʴ͹§ҹ  GroupFooter Ѻͧ
    ' صἹվѡҹ 10  §ҹ (Detail) ǹ Loop 价
    ' ActiveReport_FetchData(eof As Boolean) 10 ͺ ͷӡʴ§ҹ
    ' ͺзӡúǡӹǹԹ͹ͧѡҹФ SumSalary
End Sub

Private Sub GroupFooter1_Format()
    ' óշª;ѡҹ͡ҷ ѧ ...
    ' ʴӹǹԹ͹͡ ˹٧ͧǹ 0
    '  ... Դ 55555
    If frmPrintEmployee.cmbPrint.ListIndex = 0 Then GroupFooter1.Height = 0
    
    ' ó͡÷§ҹἹ  ˹ ٧դһ ҡѺ͹ Design
    ' ͧԹ͹лҡ͡  ...
    ' Ӥҷҡúǡ (Sum)  Detail ʴŵ͹§ҹ (GroupFooter)
    txtSumSalary.Text = "ӹǹԹ͹: " & Format(SumSalary, "#,##0.00")
    ' ѹǡ SQL Statement ͧͧ Group ᷹ ... ͧ
    
    ' óշ Group
    ' ;ѾСº ӡ
    i = 1:  SumSalary = 0
End Sub
Conclusion:
͹ ... ͧ¤Ѻ ... Ӿѧ§鴨ԧͧ仹͹ʹͺ ѹ·ͧöѲҷѡբ͡Ѻ ҡԹԨ Ԩó§÷ӧҹ Ӥҧͧ ( Trace Step Into ¡á F8 ٤Ѻ) ͧԴԹҡô٫ԤѺҨͧ任Ѻءҹҧúҧ ҡԴ͡ ͧ⨷令Դ٤Ѻ ... ͧ Query ¡Ἱ (Department) ComboBox ѹ͡¡¡͡Ἱ٫ԤѺ ... !!! ... èз͹ѹ
͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560