Click here to Skip to main content
15,881,281 members
Articles / Programming Languages / Visual Basic

SmartLink

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
16 Dec 2006CPOL2 min read 58.5K   1.2K   31  
SmartLink allows to group together the files across the network in logical folders, Groups
Imports System.Xml
Imports System.IO

Public Class frmLink
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lblFile As System.Windows.Forms.Label
    Friend WithEvents lblGroup As System.Windows.Forms.Label
    Friend WithEvents cboGroup As System.Windows.Forms.ComboBox
    Friend WithEvents btnLink As System.Windows.Forms.Button
    Friend WithEvents txtFileName As System.Windows.Forms.TextBox
    Friend WithEvents panelHeader As System.Windows.Forms.Panel
    Friend WithEvents btnClose As System.Windows.Forms.Button
    Friend WithEvents panelMain As System.Windows.Forms.Panel
    Friend WithEvents panelFooter As System.Windows.Forms.Panel
    Friend WithEvents lblHeader As System.Windows.Forms.Label
    Friend WithEvents ToolTip As System.Windows.Forms.ToolTip
    Friend WithEvents UsrLogo1 As SmartLink.usrLogo
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmLink))
        Me.lblFile = New System.Windows.Forms.Label
        Me.lblGroup = New System.Windows.Forms.Label
        Me.cboGroup = New System.Windows.Forms.ComboBox
        Me.btnLink = New System.Windows.Forms.Button
        Me.txtFileName = New System.Windows.Forms.TextBox
        Me.panelHeader = New System.Windows.Forms.Panel
        Me.btnClose = New System.Windows.Forms.Button
        Me.lblHeader = New System.Windows.Forms.Label
        Me.panelMain = New System.Windows.Forms.Panel
        Me.panelFooter = New System.Windows.Forms.Panel
        Me.UsrLogo1 = New SmartLink.usrLogo
        Me.ToolTip = New System.Windows.Forms.ToolTip(Me.components)
        Me.panelHeader.SuspendLayout()
        Me.panelMain.SuspendLayout()
        Me.panelFooter.SuspendLayout()
        Me.SuspendLayout()
        '
        'lblFile
        '
        Me.lblFile.AutoSize = True
        Me.lblFile.Location = New System.Drawing.Point(8, 8)
        Me.lblFile.Name = "lblFile"
        Me.lblFile.Size = New System.Drawing.Size(23, 16)
        Me.lblFile.TabIndex = 0
        Me.lblFile.Text = "File"
        '
        'lblGroup
        '
        Me.lblGroup.AutoSize = True
        Me.lblGroup.Location = New System.Drawing.Point(8, 48)
        Me.lblGroup.Name = "lblGroup"
        Me.lblGroup.Size = New System.Drawing.Size(36, 16)
        Me.lblGroup.TabIndex = 2
        Me.lblGroup.Text = "Group"
        '
        'cboGroup
        '
        Me.cboGroup.Location = New System.Drawing.Point(64, 48)
        Me.cboGroup.Name = "cboGroup"
        Me.cboGroup.Size = New System.Drawing.Size(352, 21)
        Me.cboGroup.TabIndex = 3
        Me.ToolTip.SetToolTip(Me.cboGroup, "Enter/Select Group")
        '
        'btnLink
        '
        Me.btnLink.BackColor = System.Drawing.Color.Transparent
        Me.btnLink.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.btnLink.Location = New System.Drawing.Point(346, 8)
        Me.btnLink.Name = "btnLink"
        Me.btnLink.Size = New System.Drawing.Size(72, 24)
        Me.btnLink.TabIndex = 0
        Me.btnLink.Text = "&Link"
        Me.ToolTip.SetToolTip(Me.btnLink, "Link")
        '
        'txtFileName
        '
        Me.txtFileName.BackColor = System.Drawing.Color.White
        Me.txtFileName.Location = New System.Drawing.Point(64, 8)
        Me.txtFileName.Multiline = True
        Me.txtFileName.Name = "txtFileName"
        Me.txtFileName.ReadOnly = True
        Me.txtFileName.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtFileName.Size = New System.Drawing.Size(352, 32)
        Me.txtFileName.TabIndex = 1
        Me.txtFileName.Text = ""
        Me.ToolTip.SetToolTip(Me.txtFileName, "Selected File")
        '
        'panelHeader
        '
        Me.panelHeader.BackColor = System.Drawing.Color.CornflowerBlue
        Me.panelHeader.BackgroundImage = CType(resources.GetObject("panelHeader.BackgroundImage"), System.Drawing.Image)
        Me.panelHeader.Controls.Add(Me.btnClose)
        Me.panelHeader.Controls.Add(Me.lblHeader)
        Me.panelHeader.Location = New System.Drawing.Point(2, 2)
        Me.panelHeader.Name = "panelHeader"
        Me.panelHeader.Size = New System.Drawing.Size(426, 44)
        Me.panelHeader.TabIndex = 0
        '
        'btnClose
        '
        Me.btnClose.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.btnClose.BackColor = System.Drawing.SystemColors.Window
        Me.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.btnClose.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnClose.Location = New System.Drawing.Point(400, 13)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(17, 16)
        Me.btnClose.TabIndex = 1
        Me.btnClose.Text = "�"
        Me.ToolTip.SetToolTip(Me.btnClose, "Exit")
        '
        'lblHeader
        '
        Me.lblHeader.AutoSize = True
        Me.lblHeader.BackColor = System.Drawing.Color.Transparent
        Me.lblHeader.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblHeader.ForeColor = System.Drawing.Color.White
        Me.lblHeader.Location = New System.Drawing.Point(8, 11)
        Me.lblHeader.Name = "lblHeader"
        Me.lblHeader.Size = New System.Drawing.Size(68, 20)
        Me.lblHeader.TabIndex = 0
        Me.lblHeader.Text = "Add Link"
        Me.lblHeader.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'panelMain
        '
        Me.panelMain.BackColor = System.Drawing.Color.White
        Me.panelMain.Controls.Add(Me.txtFileName)
        Me.panelMain.Controls.Add(Me.lblFile)
        Me.panelMain.Controls.Add(Me.lblGroup)
        Me.panelMain.Controls.Add(Me.cboGroup)
        Me.panelMain.Location = New System.Drawing.Point(2, 48)
        Me.panelMain.Name = "panelMain"
        Me.panelMain.Size = New System.Drawing.Size(426, 79)
        Me.panelMain.TabIndex = 1
        '
        'panelFooter
        '
        Me.panelFooter.BackColor = System.Drawing.Color.GhostWhite
        Me.panelFooter.BackgroundImage = CType(resources.GetObject("panelFooter.BackgroundImage"), System.Drawing.Image)
        Me.panelFooter.Controls.Add(Me.UsrLogo1)
        Me.panelFooter.Controls.Add(Me.btnLink)
        Me.panelFooter.Location = New System.Drawing.Point(2, 128)
        Me.panelFooter.Name = "panelFooter"
        Me.panelFooter.Size = New System.Drawing.Size(426, 40)
        Me.panelFooter.TabIndex = 2
        '
        'UsrLogo1
        '
        Me.UsrLogo1.BackgroundImage = CType(resources.GetObject("UsrLogo1.BackgroundImage"), System.Drawing.Image)
        Me.UsrLogo1.Location = New System.Drawing.Point(8, 6)
        Me.UsrLogo1.Name = "UsrLogo1"
        Me.UsrLogo1.Size = New System.Drawing.Size(96, 28)
        Me.UsrLogo1.TabIndex = 6
        '
        'frmLink
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(430, 170)
        Me.ControlBox = False
        Me.Controls.Add(Me.panelFooter)
        Me.Controls.Add(Me.panelMain)
        Me.Controls.Add(Me.panelHeader)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmLink"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Add Link"
        Me.panelHeader.ResumeLayout(False)
        Me.panelMain.ResumeLayout(False)
        Me.panelFooter.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Event Handlers"
    Private Sub frmLink_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call LoadControls()
        Call LoadXML()
        Call LoadGroups()
        cboGroup.Focus()
        cboGroup.Select()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
        End
    End Sub

    Private Sub btnLink_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLink.Click
        Try
            If Trim(cboGroup.Text) = "" Then
                Dim frmMessage As New frmMessage("Enter/Select a Group")
                frmMessage.ShowDialog()
            ElseIf LinkPresent() = True Then
                Dim frmMessage As New frmMessage("File '" & FILENAME & "' is already present in '" & Trim(cboGroup.Text) & "' Group")
                frmMessage.ShowDialog()
            Else
                If GroupPresent() = True Then
                    Call UpdateGroup()
                Else
                    Call NewGroup()
                End If

                Me.Close()
                End
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
        End
    End Sub
#End Region

#Region "Procedures"
    Private Sub LoadControls()
        Try
            txtFileName.Text = FILENAME
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub LoadGroups()
        Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("GroupName")

        For Each Node As XmlNode In GroupNodes
            If Node.InnerText <> "" Then
                cboGroup.Items.Add(Node.InnerText)
            End If
        Next

    End Sub

    Private Sub UpdateGroup()
        Try
            Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("GroupName")

            For Each Node As XmlNode In GroupNodes
                If Node.ChildNodes.Count <> 0 Then
                    If Node.ChildNodes(0).InnerText = Trim(cboGroup.Text) Then
                        Dim FileNode As XmlNode = XMLDOC.CreateNode(XmlNodeType.Element, "File", "")
                        FileNode.InnerText = FILENAME

                        Node.ParentNode.AppendChild(FileNode)
                        XMLDOC.Save(Application.StartupPath & "/Data.xml")
                        Exit For
                    End If
                End If
            Next

            Dim frmMessage As New frmMessage("File '" & FILENAME & "' is added to '" & Trim(cboGroup.Text) & "' Group")
            frmMessage.ShowDialog()

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub NewGroup()
        Try
            Dim GroupNode As XmlNode = XMLDOC.CreateNode(XmlNodeType.Element, "Group", "")

            Dim GroupNameNode As XmlNode = XMLDOC.CreateNode(XmlNodeType.Element, "GroupName", "")
            GroupNameNode.InnerText = Trim(cboGroup.Text)
            Dim DateTimeNode As XmlNode = XMLDOC.CreateNode(XmlNodeType.Element, "DateTime", "")
            DateTimeNode.InnerText = DateTime.Today.ToString
            Dim FileNode As XmlNode = XMLDOC.CreateNode(XmlNodeType.Element, "File", "")
            FileNode.InnerText = FILENAME

            GroupNode.AppendChild(GroupNameNode)
            GroupNode.AppendChild(DateTimeNode)
            GroupNode.AppendChild(FileNode)

            XMLDOC.DocumentElement.AppendChild(GroupNode)
            XMLDOC.Save(Application.StartupPath & "/Data.xml")

            Dim frmMessage As New frmMessage("File '" & FILENAME & "' is added to '" & Trim(cboGroup.Text) & "' Group")
            frmMessage.ShowDialog()

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
#End Region

#Region "Functions"
    Private Function GroupPresent() As Boolean
        Try
            Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("GroupName")

            For Each Node As XmlNode In GroupNodes
                If Node.InnerText = Trim(cboGroup.Text) Then
                    Return True
                End If
            Next

            Return False
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Private Function LinkPresent() As Boolean
        Try
            Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("Group")
            Dim IsGroupPresent As Boolean
            IsGroupPresent = False

            For Each Node As XmlNode In GroupNodes
                For Each ChildNode As XmlNode In Node.ChildNodes

                    Select Case ChildNode.Name
                        Case "GroupName"
                            If ChildNode.InnerText = Trim(cboGroup.Text) Then
                                IsGroupPresent = True
                            End If

                        Case "File"
                            If IsGroupPresent = True And ChildNode.InnerText = FILENAME Then
                                Return True
                            End If
                    End Select
                Next
            Next

            Return False
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Function
#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Hey, this is Shirish a software guy by profession. Along with my hectic job schedule, I like to work on different ideas. I am in total love with all the GUI related things. I also like to work with the databases. I enjoy, to develop some simple tools which can be useful to other software professionls like me as well the normal users.

Please feel free to contact me with suggestions/ideas, at mentioned email address.
shirish.wagh@yahoo.com

Comments and Discussions