07-06-14, 10:08 PM
السلام عليكم
ممكن شرح هذه الاكود
اولا موديول
الفورم
هذا المشروع
عبارة عن عرض البيانات فى treeview باستخدام ado لاكن ممكن احد يشرحلى الاكواد او تبسيط الاكواد بحيث استغنى عن الموديول
ممكن شرح هذه الاكود
اولا موديول
كود :
Imports System.Data
Imports System.Data.OleDb
Imports System.Management
Module btlanmdule
'Public ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\sys322.dll;Persist Security Info=True;Jet OLEDB:Database Password=omar911"
Public ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\sys744.dll;Jet OLEDB:Database Password=omar911"
Public Conn As New OleDbConnection(ConStr)
Public AccountDataSet1 As New DataSet 'tre
Public AccountDataSet2 As New DataSet 'low5
Public AccountDataSet3 As New DataSet 'low6
Public AccountDataSet4 As New DataSet 'sharh
Public SQLstr As String = "SELECT * FROM tre"
Public countword As Integer = 0
Public countprint As Integer = 0
Public searchresults As New ArrayList
Public position As Integer = 0
Public Function FindInternal(ByVal key As String, ByVal searchAllChildren As Boolean, ByVal treeNodeCollectionToLookIn As TreeNodeCollection, ByVal foundTreeNodes As ArrayList) As ArrayList
If ((treeNodeCollectionToLookIn Is Nothing) OrElse (foundTreeNodes Is Nothing)) Then
Return Nothing
End If
Dim i As Integer
For i = 0 To treeNodeCollectionToLookIn.Count - 1
If ((Not treeNodeCollectionToLookIn.Item(i) Is Nothing) AndAlso SafeCompareStrings(treeNodeCollectionToLookIn.Item(i).Text, key, True)) Then
foundTreeNodes.Add(treeNodeCollectionToLookIn.Item(i))
End If
Next i
If searchAllChildren Then
Dim j As Integer
For j = 0 To treeNodeCollectionToLookIn.Count - 1
If (((Not treeNodeCollectionToLookIn.Item(j) Is Nothing) AndAlso (Not treeNodeCollectionToLookIn.Item(j).Nodes Is Nothing)) AndAlso (treeNodeCollectionToLookIn.Item(j).Nodes.Count > 0)) Then
foundTreeNodes = FindInternal(key, searchAllChildren, treeNodeCollectionToLookIn.Item(j).Nodes, foundTreeNodes)
End If
Next j
End If
Return foundTreeNodes
End Function
Public Function SafeCompareStrings(ByVal string1 As String, ByVal string2 As String, ByVal ignoreCase As Boolean) As Boolean
If ((string1 Is Nothing) OrElse (string2 Is Nothing)) Then
Return False
End If
Return ((string1.ToLower.Contains(string2.ToLower)))
End Function
End Module
الفورم
كود :
Imports System.Data.OleDb
Imports System.Data
Public Class btlan_tree
Dim WithEvents oBinding As Binding
Dim WithEvents oBinding3 As Binding
Dim WithEvents oBinding4 As Binding
Private Sub oBinding_Format(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs) Handles oBinding.Format
On Error Resume Next
If Not e.Value = Nothing Then e.Value = Decrypt(e.Value, True)
End Sub
Private Sub treemain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
' RichTextBox1.ForeColor = My.Settings.rtf1colorfontdefult
' RichTextBox1.Font = My.Settings.rtf1font
' RichTextBox1.BackColor = My.Settings.rtf1backcolor
''''''''''''''''
''''''''''''''''''
' TreeView1.ForeColor = My.Settings.treforcolor
'TreeView1.BackColor = My.Settings.trebackcolor
' TreeView1.Font = My.Settings.trefont
Dim datab1 As New OleDbDataAdapter(SQLstr, ConStr)
AccountDataSet1.Clear()
datab1.Fill(AccountDataSet1, "tre")
' Me.BindingContext(AccountDataSet1, "tre").Position = 0
CreateTree()
Application.DoEvents()
searchresults.Clear()
searchresults = FindInternal("تعريــف البطــلان", True, TreeView1.Nodes, New ArrayList)
If position > searchresults.Count - 1 Then position = 0 : Return
TreeView1.SelectedNode = searchresults(position)
TreeView1.Focus()
' Me.BindingContext(AccountDataSet1, "tre").Position = 4
oBinding = New Binding("Text", AccountDataSet2, "low5.text")
RichTextBox1.DataBindings.Add(oBinding)
RichTextBox1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub CreateTree()
Try
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
Dim MainHeader As New TreeNode(Me.Text)
MainHeader.Tag = "0_"
MainHeader.Name = "0_"
' MainHeader.ForeColor = Color.Red
TreeView1.Nodes.Add(MainHeader)
AddSubNode(MainHeader)
TreeView1.EndUpdate()
Application.DoEvents()
TreeView1.Visible = False
TreeView1.ExpandAll()
TreeView1.Visible = True
TreeView1.Select()
'' searchresults.Clear()
'' searchresults = FindInternal("1", True, TreeView1.Nodes, New ArrayList)
'' If position > searchresults.Count - 1 Then position = 0 : Return
'' TreeView1.SelectedNode = searchresults(position)
'' TreeView1.Focus()
RichTextBox1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub AddSubNode(ByVal Node As TreeNode)
Try
Dim dv1 As DataView = AccountDataSet1.Tables("tre").DefaultView
dv1.RowFilter = "parentkey ='" & CType(Node.Tag, String) & "'"
dv1.Sort = "id ASC"
For Each drLine As DataRowView In dv1
Dim SubNode As New TreeNode(drLine("titel"))
' SubNode.ForeColor = Color.Black
SubNode.Tag = drLine("key").ToString
SubNode.Name = drLine("key").ToString
SubNode.ImageIndex = CType(drLine("image"), Integer)
SubNode.SelectedImageIndex = CType(drLine("imageselect"), Integer)
Node.Nodes.Add(SubNode)
Application.DoEvents()
If Not CType(Node.Tag, String) Is String.Empty Then
AddSubNode(SubNode)
End If
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Try
If e.Node.GetNodeCount(True) Then Exit Sub
Dim datab2 As New OleDbDataAdapter("SELECT * FROM low5 where key = '" & e.Node.Name & "'", ConStr)
AccountDataSet2.Clear()
datab2.Fill(AccountDataSet2, "low5")
If SplitContainer1.Panel1Collapsed = True Then
SplitContainer1.Panel1Collapsed = False
ToolStripButton5.Text = "توسيع مساحة عرض الفهرس"
' ToolStripButton5.Image = My.Resources.previous_set_2
End If
If ToolStripTextBox1.Text.Trim <> "" Then
findrtf(RichTextBox1, ToolStripTextBox1.Text)
AccountDataSet2.RejectChanges()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
هذا المشروع
عبارة عن عرض البيانات فى treeview باستخدام ado لاكن ممكن احد يشرحلى الاكواد او تبسيط الاكواد بحيث استغنى عن الموديول