|  | 
	                
  
    |  |  
    | 
        
        กรุณาช่วยหนูด้วยนะค่ะ เกี่ยวกับเงื่อไขที่โค้ด ส้รางเมนูด้วยโคด้     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | Code (VB.NET) 
 Imports System.IO
Imports System.Collections.Generic
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data
Imports System.Data.SqlClient
Public Class Site
    Inherits System.Web.UI.MasterPage
    Dim PathMSDS As String = "C:\Users\TiP-ToP\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\REPORT"
    Dim myDirInfo As DirectoryInfo
    Dim myFolderInfo As DirectoryInfo
    Dim arrFolderInfo As Array
    Dim _dirFile As String
    Dim RootMaster = New Menu
    Dim RootMenu = New MenuItem
    Dim RootTmp = New MenuItem
    Dim SubTmp = New MenuItem
    Dim arrMenu() As String
    Dim tarray As New ArrayList()
    Dim SearchPath As String = "C:\MSDS\"
    Sub BuildTree(ByVal s As String)
        Dim strName As String = HttpContext.Current.User.Identity.Name.ToString
        Dim rootdir = New DirectoryInfo("C:\Users\TiP-ToP\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\REPORT\" & s)
        Dim rootnode = New TreeNode(rootdir.Name, rootdir.FullName)
        Dim rootSub = New MenuItem(rootdir.Name, rootdir.FullName)
        'DocumentMenu.Items.Add(rootSub)
        NavigationMenu.Items.Add(rootSub)
        'RecursiveSearch(rootdir, rootSub)
        RecursiveSearch2(rootdir, rootSub)
        'TreeView1.Nodes.Add(rootnode)
        'traversetree(rootdir, rootnode)
    End Sub
    'Private Sub RecursiveSearch(ByRef CurrentMenu, ByRef CurrentSubMenu)
    '    Dim dir As DirectoryInfo
    '    For Each dir In CurrentMenu.GetDirectories
    '        Dim SubMenu As New MenuItem(dir.Name, dir.FullName)
    '        'Dim LstFiles() As String
    '        'LstFiles = Directory.GetFiles("path ")
    '        'For i As Int32 = 0 To LstFiles.Length - 1
    '        '    nuItem(Days.name, )
    '        'Next
    '        CurrentSubMenu.Childitems.add(SubMenu)
    '        RecursiveSearch(dir, SubMenu)
    '    Next
    '    Dim myFile As FileInfo
    '    For Each myFile In CurrentMenu.GetFiles
    '        Dim MenuFile As New MenuItem(Mid(myFile.Name, 1, Len(myFile.Name) - 4), myFile.FullName)
    '        'MsgBox(Menu1.Items.Count)
    '        'MenuFile.NavigateUrl = myFile.FullName
    '        CurrentSubMenu.Childitems.Add(MenuFile)
    '    Next
    'End Sub
    Private Sub RecursiveSearch2(ByRef CurrentMenu, ByRef CurrentSubMenu)
        'Dim dir As DirectoryInfo
        'For Each dir In CurrentMenu.GetDirectories
        '    Dim SubMenu As New MenuItem(dir.Name, dir.FullName)
        '    CurrentSubMenu.Childitems.add(SubMenu)
        '    RecursiveSearch(dir, SubMenu)
        'Next
        Dim myFile As FileInfo
        For Each myFile In CurrentMenu.GetFiles
            Dim MenuFile As New MenuItem(Mid(myFile.Name, 1, Len(myFile.Name) - 4), myFile.FullName)
            'MsgBox(Menu1.Items.Count)
            
            MenuFile.NavigateUrl = "viewreport.aspx"
            CurrentSubMenu.Childitems.Add(MenuFile)
        Next
    End Sub
    'Private Sub traversetree(ByRef CurrentDir, ByRef CurrentNode)
    '    Dim dir As DirectoryInfo
    '    For Each dir In CurrentDir.GetDirectories
    '        Dim node As New TreeNode(dir.Name, dir.FullName)
    '        CurrentNode.ChildNodes.Add(node)
    '        traversetree(dir, node)
    '    Next
    '    Dim myFile As FileInfo
    '    For Each myFile In CurrentDir.GetFiles
    '        Dim newNode As TreeNode = New TreeNode(myFile.Name, myFile.FullName)
    '        newNode.NavigateUrl = "viewreport.aspx"
    '        'myFile.FullName
    '        CurrentNode.ChildNodes.Add(newNode)
    '    Next
    'End Sub
    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        'Dim objConn As New SqlConnection
        'Dim objCmd As New SqlCommand
        'Dim dtAdapter As New SqlDataAdapter
        'Dim ds As New DataSet
        'Dim dt As DataTable
        'Dim strConnString, strSQL As String
        'strConnString = "Server=LAPTOP-IT\SQLEXPRESS;UID=sa;PASSWORD=apcbkk2000;database=APC;Max Pool Size=400;Connect Timeout=600;"
        'strSQL = "SELECT * FROM APC  "
        'objConn.ConnectionString = strConnString
        'With (objCmd)
        '    .Connection = objConn
        '    .CommandText = strSQL
        '    .CommandType = CommandType.Text
        'End With  
        'dtAdapter.SelectCommand = objCmd
        'dtAdapter.Fill(ds, "APCSaleCode")
        'dt = ds.Tables(0)
        'dtAdapter = Nothing
        'objConn.Close()
        'objConn = Nothing
        'Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        'rpt.Load(Server.MapPath("/report/Marketing/M05-D5005-2-Sale Order Report By Product.rpt"))
        'CrystalReportViewer1.ReportSource = rpt
        'CrystalReportViewer1.RefreshReport()
        'Dim crp = New CrystalReport1()
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            BuildTree("Account")
            BuildTree("Bill Collector")
            BuildTree("Finance")
            BuildTree("IT")
            BuildTree("Marketing")
            BuildTree("Purchase")
            BuildTree("Terminal")
        End If
        'Dim Fd1 As String
        'Dim Fd2 As String
        'Dim Fd3 As String
        'Dim TmpFile As String
        'Dim DS1, DS2 As String
        'Dim S1, S2 As String
        'Dim P1, P2 As String
        'Dim a1 As String
        'Dim ArrFile As Array
        'Dim MIndex As String
        'Dim file1 As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        'Dim myDirInfo As DirectoryInfo
        'file1.Load(Server.MapPath("/report/Marketing/*.rpt", myDirInfo))
        'ReDim ArrFile(1 To 50) As Dat
        'Dim i As Integer
        'i = 1
        'Do While file1 <> ""
        '    If file1 <> "." And file1 <> ".." Then
        '        ArrFile(i).Fd1 = Mid(file1, 1, Len(file1) - 4)
        '        ArrFile(i).Fd2 = Mid(file1, 5, 1)
        '        ArrFile(i).Fd3 = Mid(file1, 11, 1)
        '        i = i + 1
        '    End If
        '    file1 = Dir()   ' Get next entry.
        'Loop
        ''ReDim ArrFile(1 To vbDirectory - 1) As Dat
        ''For i = 1 To File1.ListCount  ' Add 3 new items to the menu
        ''    ArrFile(i).Fd1 = Mid(File1.List(i - 1), 1, Len(File1.List(i - 1)) - 4)
        ''    ArrFile(i).Fd2 = Mid(File1.List(i - 1), 5, 1)
        ''    ArrFile(i).Fd3 = Mid(File1.List(i - 1), 11, 1)
        ''Next i
        'i = 1
        'D = 1
        'M = 1
        'w = 1
        'Do
        '    If ArrFile(i).Fd2 = "D" Then
        '        If ArrFile(i).Fd3 >= User(0).Fd2 Then
        '            Load(RptAccD(D))  ' Load new menu item
        '            RptAccD(D).Caption = ArrFile(i).Fd1
        '            D = D + 1
        '        End If
        '    ElseIf ArrFile(i).Fd2 = "W" Then
        '        If ArrFile(i).Fd3 >= User(0).Fd2 Then
        '            Load(RptAccW(w))  ' Load new menu item
        '            RptAccW(w).Caption = ArrFile(i).Fd1
        '            w = w + 1
        '        End If
        '    ElseIf ArrFile(i).Fd2 = "M" Then
        '        If ArrFile(i).Fd3 >= User(0).Fd2 Then
        '            Load(RptAccM(M))  ' Load new menu item
        '            RptAccM(M).Caption = ArrFile(i).Fd1
        '            M = M + 1
        '        End If
        '    End If
        '    i = i + 1
        'Loop Until ArrFile(i).Fd1 = ""
        'RptAccD(0).Visible = False
        'RptAccM(0).Visible = False
        'RptAccW(0).Visible = False
  End Sub
    Private Sub DocumentMenu_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs)
        MsgBox(sender.ToString & "  " & e.Item.Value)
        'Select Case UCase(Right(e.Item.Value, 4))
        '    Case ".PDF"
        '        Response.ContentType = "Application/pdf"
        '    Case ".DOC"
        '    Case Else
        'End Select
        'frame1.Attributes.Add("src", e.Item.Value)
        'Me.frame1.InnerHtml = e.Item.Value
    End Sub
    'Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick
    '    'If UCase(Right(e.Item.Value)) = ".PDF" Then
    '    '    MultiView1.ActiveViewIndex = 1
    '    '    frame1.Attributes.Add("src", e.Item.Value)
    '    'Else
    '    '     "")
    '    'End If
    '    'frame1.Attributes.Add("src", ViewReport)
    'End Sub
    'Protected Sub lkButtonBack_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkButtonBack.Click
    '    'MultiView1.ActiveViewIndex = 0
    'End Sub
    Protected Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles NavigationMenu.MenuItemClick
    End Sub
End Class
 จากโค้ดอยากเพิ่มเงื่อนไขโดยไฟลล์ตามพาธถ้า ไฟล์คริสตัลรีพอตในพาธ มี D ถ้าชื่อมีd แล้ว เมนูจะส้รางเพื่อแยกประเภทเป็น day ให้เมนูสร้างโฟลล์เดอร์เพิ่มขึ้นมาแล้วแยกประเภทด้วย จะมี day week month ดป็นโฟลล์เดอร์ที่ต้องการสร้างต่าจากเมนูหลักก่อนที่จะคลิกแล้วโชว์คริสตัลรีพอต สอนวิธีการโชว์คริสตัลรีพอตด้วยนะค่ะ เมื่อคลิกที่เมนู เมนูส้รางมาจาก code นะค่ะ ไม่ใช่tool
 อยากได้ตามรูปเลยค่ะ และเมื่อคลิกcrsytal repot show จะดีมากค่ะ
 อยากได้ตามนี้ค่ะ
 
 
  
 
 
 Tag : .NET, Web (ASP.NET), Win (Windows App)
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2012-05-17 13:29:29 | By :
                          belletempo | View :
                          1204 | Reply :
                          1 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ใช้พวก IF เข้าช่วยไม่ได้เหรอครับ แนะนำว่าในแต่ล่ะ Report ควรสร้างเป็น Sub ใคร Sub มันครับ และใน Page_Load ก็ตรวจสอบว่ามันควรจะเข้า Sub ไหน 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-05-17 14:31:11 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |