Imports System.Xml Public Class frmRemoveLink 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 txtFile As System.Windows.Forms.TextBox Friend WithEvents tvwGroups As System.Windows.Forms.TreeView Friend WithEvents panelHeader As System.Windows.Forms.Panel Friend WithEvents btnClose As System.Windows.Forms.Button Friend WithEvents panelFile As System.Windows.Forms.Panel Friend WithEvents lblFile As System.Windows.Forms.Label Friend WithEvents panelFooter As System.Windows.Forms.Panel Friend WithEvents btnRemove As System.Windows.Forms.Button Friend WithEvents lblHeader As System.Windows.Forms.Label Friend WithEvents ToolTip As System.Windows.Forms.ToolTip Friend WithEvents UsrLogo1 As SmartLink.usrLogo Friend WithEvents ImageList1 As System.Windows.Forms.ImageList <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmRemoveLink)) Me.panelHeader = New System.Windows.Forms.Panel Me.btnClose = New System.Windows.Forms.Button Me.lblHeader = New System.Windows.Forms.Label Me.panelFile = New System.Windows.Forms.Panel Me.lblFile = New System.Windows.Forms.Label Me.txtFile = New System.Windows.Forms.TextBox Me.panelFooter = New System.Windows.Forms.Panel Me.UsrLogo1 = New SmartLink.usrLogo Me.btnRemove = New System.Windows.Forms.Button Me.tvwGroups = New System.Windows.Forms.TreeView Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components) Me.ToolTip = New System.Windows.Forms.ToolTip(Me.components) Me.panelHeader.SuspendLayout() Me.panelFile.SuspendLayout() Me.panelFooter.SuspendLayout() Me.SuspendLayout() ' '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(400, 44) Me.panelHeader.TabIndex = 23 ' '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(376, 13) Me.btnClose.Name = "btnClose" Me.btnClose.Size = New System.Drawing.Size(17, 16) Me.btnClose.TabIndex = 20 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.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft Me.lblHeader.Location = New System.Drawing.Point(8, 11) Me.lblHeader.Name = "lblHeader" Me.lblHeader.Size = New System.Drawing.Size(99, 20) Me.lblHeader.TabIndex = 18 Me.lblHeader.Text = "Remove Link" Me.lblHeader.TextAlign = System.Drawing.ContentAlignment.MiddleLeft ' 'panelFile ' Me.panelFile.BackColor = System.Drawing.Color.Transparent Me.panelFile.Controls.Add(Me.lblFile) Me.panelFile.Controls.Add(Me.txtFile) Me.panelFile.Location = New System.Drawing.Point(2, 48) Me.panelFile.Name = "panelFile" Me.panelFile.Size = New System.Drawing.Size(400, 52) Me.panelFile.TabIndex = 24 ' 'lblFile ' Me.lblFile.AutoSize = True Me.lblFile.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblFile.ForeColor = System.Drawing.SystemColors.ControlText Me.lblFile.Location = New System.Drawing.Point(16, 7) Me.lblFile.Name = "lblFile" Me.lblFile.Size = New System.Drawing.Size(25, 17) Me.lblFile.TabIndex = 19 Me.lblFile.Text = "File" ' 'txtFile ' Me.txtFile.BackColor = System.Drawing.Color.White Me.txtFile.Location = New System.Drawing.Point(53, 9) Me.txtFile.Multiline = True Me.txtFile.Name = "txtFile" Me.txtFile.ReadOnly = True Me.txtFile.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.txtFile.Size = New System.Drawing.Size(339, 34) Me.txtFile.TabIndex = 10 Me.txtFile.Text = "" Me.ToolTip.SetToolTip(Me.txtFile, "Seleted File") ' '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.btnRemove) Me.panelFooter.Location = New System.Drawing.Point(2, 293) Me.panelFooter.Name = "panelFooter" Me.panelFooter.Size = New System.Drawing.Size(400, 41) Me.panelFooter.TabIndex = 25 ' '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 ' 'btnRemove ' Me.btnRemove.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.btnRemove.BackColor = System.Drawing.Color.Transparent Me.btnRemove.FlatStyle = System.Windows.Forms.FlatStyle.Popup Me.btnRemove.Location = New System.Drawing.Point(320, 8) Me.btnRemove.Name = "btnRemove" Me.btnRemove.Size = New System.Drawing.Size(72, 24) Me.btnRemove.TabIndex = 4 Me.btnRemove.Text = "&Remove" Me.ToolTip.SetToolTip(Me.btnRemove, "Remove") ' 'tvwGroups ' Me.tvwGroups.BackColor = System.Drawing.Color.White Me.tvwGroups.BorderStyle = System.Windows.Forms.BorderStyle.None Me.tvwGroups.CheckBoxes = True Me.tvwGroups.ImageList = Me.ImageList1 Me.tvwGroups.Location = New System.Drawing.Point(2, 100) Me.tvwGroups.Name = "tvwGroups" Me.tvwGroups.Size = New System.Drawing.Size(400, 192) Me.tvwGroups.TabIndex = 26 Me.ToolTip.SetToolTip(Me.tvwGroups, "Groups") ' 'ImageList1 ' Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer) Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent ' 'frmRemoveLink ' 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(404, 336) Me.Controls.Add(Me.tvwGroups) Me.Controls.Add(Me.panelFooter) Me.Controls.Add(Me.panelFile) Me.Controls.Add(Me.panelHeader) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None Me.Name = "frmRemoveLink" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Remove Link" Me.panelHeader.ResumeLayout(False) Me.panelFile.ResumeLayout(False) Me.panelFooter.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region #Region "Event Handlers" Private Sub frmRemoveLink_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Call LoadXML() If LinkPresent() = True Then Call LoadControls() Call LoadGroups() Else Dim frm As New frmMessage("File '" & FILENAME & "' is not linked with any Group") frm.ShowDialog() 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 btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click Dim IsNodeChecked As Boolean For Each Node As TreeNode In tvwGroups.Nodes If Node.Checked = True Then IsNodeChecked = True Exit For End If Next If IsNodeChecked = True Then Call RemoveLink() Call LoadXML() Call LoadGroups() Else Dim frm As New frmMessage("Select atleast one Group") frm.ShowDialog() End If 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 txtFile.Text = FILENAME Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub LoadGroups() Try Me.Cursor = Cursors.WaitCursor Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("Group") tvwGroups.Nodes.Clear() For Each Node As XmlNode In GroupNodes For Each ChildNode As XmlNode In Node.ChildNodes Dim GroupName As String Select Case ChildNode.Name Case "GroupName" GroupName = ChildNode.InnerText Case "File" If ChildNode.InnerText = FILENAME Then tvwGroups.Nodes.Add(GroupName) Exit For End If End Select Next Next If tvwGroups.Nodes.Count = 0 Then Dim frm As New frmMessage("File '" & FILENAME & "' is not linked with any Group") frm.ShowDialog() Me.Close() End End If Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) Finally Me.Cursor = Cursors.Default End Try End Sub Private Sub RemoveLink() Try Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("Group") Dim RemovedMsg As New System.Text.StringBuilder For cnt As Integer = 0 To tvwGroups.Nodes.Count - 1 If tvwGroups.Nodes(cnt).Checked = True Then For Each Node As XmlNode In GroupNodes For Each ChildNode As XmlNode In Node Dim RemoveFile As Boolean Dim GroupName As String Select Case ChildNode.Name Case "GroupName" If ChildNode.InnerText = tvwGroups.Nodes(cnt).Text Then GroupName = ChildNode.InnerText RemoveFile = True End If Case "File" If RemoveFile = True And ChildNode.InnerText = FILENAME Then Node.RemoveChild(ChildNode) RemoveFile = False RemovedMsg.Append("File '" & FILENAME & "' is removed from '" & GroupName & "' Group") RemovedMsg.Append(ControlChars.NewLine) End If End Select Next Next End If Next If RemovedMsg.ToString <> "" Then Dim frm As New frmMessage(RemovedMsg.ToString) frm.ShowDialog() End If XMLDOC.Save(Application.StartupPath & "/Data.xml") Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub #End Region #Region "Functions" Private Function LinkPresent() As Boolean Try Dim GroupNodes As XmlNodeList = XMLDOC.GetElementsByTagName("Group") For Each Node As XmlNode In GroupNodes For Each ChildNode As XmlNode In Node.ChildNodes If ChildNode.InnerText = FILENAME Then Return True End If 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 use 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.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Skills that self-taught computer programmers lack