php 树形列表

TreeView.php

<?php
class TreeView {
    public $childName = "child";
    public $parentid;
    public $id;
    public $nameColumn;
    function __construct($parentid, $id,$nameColumn) {
        $this->parentid = $parentid;
        $this->id = $id;
        $this->nameColumn=$nameColumn;
    }
    
    public function display($Nodes) {
        echo '<div class="TreeView"><ul>';
        $GroupNodes = $this->buildTree($Nodes->list, $this->parentid, $this->id);
        $this->showTree($GroupNodes);
        echo '</ul>';
    }

    function buildTree($temp, $parentid, $idKey) {
        $grouped = $this->reGroup($temp, $parentid, $idKey);
        $fnBuilder = function ($siblings) use(&$fnBuilder, $grouped, $idKey) {
            foreach ($siblings as $k => $sibling) {
                $id = $sibling[$idKey];
                if (isset($grouped[$id])) {
                    $sibling[$this->childName] = $fnBuilder($grouped[$id]);
                }
                $siblings[$k] = $sibling;
            }
            return $siblings;
        };
        $tree = $fnBuilder($grouped[0]);
        return $tree;
    }


    function showTree($grouped) {
       foreach($grouped as $subGroupKey=>$subGroup){
           if(is_array($subGroup)){              
               if($subGroupKey===$this->childName){
                   //当前有子集
                   echo '<ul>';
                   $this->showTree($subGroup);
                   echo '</ul></li>';
               }else{
                   echo '</li>';
                   $this->showTree($subGroup);
               }
           }else{
               if($subGroupKey===$this->nameColumn){
                   echo '<li><div class="clickOnCollpose"><div class="title"><a>'.$subGroup.'</a></div></div>';
               }
           }
       }
    }
   
    function reGroup($temp, $parentid, $id) {
        $group = array();
        foreach ($temp as $item) {
            $key = $item[$parentid];
            $group[$key][] = $item;
        }
        return $group;
    }
    
}
class Nodes{
    public $list;

    function __construct(){
        $this->list=array();
    }

    public function add($Node) {
        array_push($this->list, $Node);
    }
    public function removeByNode($Node) {
        for ($i = 0;$i < count($this->list);$i++) {
            if ($this->list[$i] === $Node) {
                $this->remove($i);
            }
        }
    }
    public function removeByIndex($startIndex, $length = 0) {
        array_splice($this->list, $startIndex, $lenght);
    }
    public function clear() {
        unset($this->list);        
    }    
}

?>

TreeView.css

ul{
    list-style:none;
    padding-left: 1em;
}
.clickOnCollpose{
    display: inline-block;
    background-color: #eee;
    width:100%;
    margin:4px 0px 4px 0px;
    border-radius: 6px;
    border-width: 1px;
    border-color: #aaa;
    border-style: solid;
    padding:4px;
}

.clickOnCollpose:hover{
    background-color: #337ABC;
    color:#FFFFFF;
    padding:4px;
    border-color:#FFF;
}

.title{
    float:left;
    text-indent: 10px;
}
.count-near{
    background-color:#FF0000;
    border-radius:20px;
    color:#FFF;
    font-weight:bold;
    width:20px;
    height:20px;
    text-align:center;
    float:left;
    margin-left:20px;
}
.count-far{
    background-color:#FF0000;
    border-radius:20px;
    color:#FFF;
    font-weight:bold;
    width:20px;
    height:20px;
    text-align:center;
    float:right;
}


li{
    cursor:hand;
}
.treeview{
   width:100%;
}

TreeView.js

$(document).ready(function(){
    //默认从第2级隐藏
    $(".treeView ul li").find("ul").toggle();
 
    $(".clickOnCollpose").on('click',function(){    
        //展开/收缩下级
        $(this).parent().find("ul").toggle();  
 
        //展开/收缩下下级
        $(this).parent().find("ul li ul").toggle();        
    })
 
    $(".clickOnCollpose").mouseenter(function(){
        var count=$(this).next().children().length;
        //if(count>0){
            //class修改成 count-near 更改样式
            $(this).append("<div class='count-far'> "+count+" </div>");       
        //}
    })
 
    $(".clickOnCollpose").mouseleave(function(){     
        //class修改成 count-near 更改样式
         $(this).find(".count-far").remove();
    })
 
})

==============================================================

Demo.php

<?php
require_once("TreeView.php");
?>

<html>
<head>
<title>测试</title>
<link rel="stylesheet" href="./TreeView.css" type="text/css"/>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="./TreeView.js"></script>
</head>
<body>

<?php

$n=new Nodes();
$n->add( ["id" => 1, "name" => "name0-1", "parentid" => 0]);
$n->add( ["id" => 2, "name" => "name1-2", "parentid" => 1]);
$n->add( ["id" => 3, "name" => "name1-3", "parentid" => 1]);
$n->add( ["id" => 4, "name" => "name2-4", "parentid" => 2]);
$n->add( ["id" => 5, "name" => "name2-5", "parentid" => 2]);
$n->add( ["id" => 6, "name" => "name4-6", "parentid" => 4]);
$n->add( ["id" => 7, "name" => "name1-7", "parentid" => 1]);
$n->add( ["id" => 8, "name" => "name2-8", "parentid" => 2]);
$n->add( ["id" => 9, "name" => "name2-9", "parentid" => 2]);
$n->add( ["id" => 10, "name" => "name2-10", "parentid" => 2]);
$n->add( ["id" => 11, "name" => "name8-11", "parentid" => 8]);
$n->add( ["id" => 12, "name" => "name8-12", "parentid" => 8]);
$n->add( ["id" => 13, "name" => "name11-13", "parentid" => 11]);
$n->add( ["id" => 14, "name" => "name0-14", "parentid" => 0]);
$n->add( ["id" => 15, "name" => "name0-15", "parentid" => 0]);


$treeview=new TreeView("parentid","id","name");
//可写作$treeview=new TreeView(2,0,1);
$treeview->display($n);
?>
</body>
</html>

 

addhanderl与handels区别

遇到一个问题。addhandler 与 handels的区别是什么

举例:如下语句运行成功

 Private Sub 供货商IDSearchLookUpEdit_TextChanged(sender As Object, e As EventArgs) Handles 供货商IDSearchLookUpEdit.TextChanged
        MsgBox(sender.name, MsgBoxStyle.OkCancel, "测试")
End Sub

如下语句不成功

Private Sub 主界面_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AddHandler 供货商IDSearchLookUpEdit.TextChanged, AddressOf 供货商IDSearchLookUpEdit_TextChanged
end sub

Private Sub 供货商IDSearchLookUpEdit_TextChanged(sender As Object, e As EventArgs)
        'Handles 供货商IDSearchLookUpEdit.TextChanged
        MsgBox(sender.name, MsgBoxStyle.OkCancel, "测试")
End Sub

 

使用微软语言包实现汉字(还其他非汉字字符)转拼音

微软官方语言包下载地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn

备份下载地址:链接: http://pan.baidu.com/s/1dF4oTfr 密码: dx4h

使用方法:完成之后在项目中引用安装目录中的ChnCharInfo.dll即可

实现汉字转拼音demo(原创)

Imports Microsoft.International.Converters.PinYinConverter
Module Demo
Public Enum 拼音格式
        首字母 = 0
        全拼 = 1
    End Enum

    Public Function 获取拼音码(ByVal inputText As String, Optional 拼音格式 As 拼音格式 = 拼音格式.首字母) As String
        if inputText is Nothing or inputText="" then 
            return Nothing
        end if
        Dim PY As String = ""
        For Each Cha In inputText.Trim()
            Try
                Dim chinesechar As ChineseChar = New ChineseChar(Cha)
                Select Case 拼音格式
                    Case 拼音格式.首字母
                        PY += chinesechar.Pinyins(0).Substring(0, 1).ToLower
                    Case 拼音格式.全拼
                        PY += chinesechar.Pinyins(0).ToLower
                End Select
            Catch ex As System.NotSupportedException
                PY += Cha         ‘遇到非中文字符,直接原样返回
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Next
        Return PY
End Function
End Module

多音字不知如何处理,比如:蹲(dūn、cún )的结果为cún

【VB.NET】TabControl有关事件

事件: Deselecting               e.TabPage.Text=TabPage1
标签: SelectedTab               TabPage1
——————–
事件: Deselected               e.TabPage.Text=TabPage1
标签: SelectedTab               TabPage1
——————–
事件: Selecting               e.TabPage.Text=TabPage2
标签: SelectedTab               TabPage2
——————–
事件: Selected               e.TabPage.Text=TabPage2
标签: SelectedTab               TabPage2
——————–
事件: SelectedIndexChanged               TabPage2
标签: SelectedTab               TabPage2

【VB.NET】自定义TextBox类,添加显示下划线属性

实现功能:
a.ShowLine 参数:设置下划线是否可见
b.LineColor参数:设置下划线颜色
c.LineWidth参数:设置下划线粗细
d.LineOffset参数:设置下划线偏移量

Imports System.ComponentModel

<ToolboxBitmap(GetType(System.Windows.Forms.TextBox))>
Public Class TextBoxEx
    Inherits System.Windows.Forms.TextBox

    Protected _lineColor As Color = Color.Black
    Protected _lineWidth As Integer = 1
    Protected _lineOffset As Integer = 3
    Protected _showLine As Boolean = False
    Protected WithEvents Line As New Control()

    <DefaultValue(GetType(Color), "Black")>
    <Description("下划线颜色")>
    Public Property LineColor As Color
        Get
            Return _lineColor
        End Get
        Set(value As Color)
            If _lineColor <> value Then
                _lineColor = value
                RaiseEvent LineColorChanged(Me, Nothing)
            End If
        End Set
    End Property

    <DefaultValue(1)>
    <Description("下划线宽度")>
    Public Property LineWidth As Integer
        Get
            Return _lineWidth
        End Get
        Set(value As Integer)
            If _lineWidth <> value Then
                _lineWidth = value
                RaiseEvent LineWidthChanged(Me, Nothing)
            End If
        End Set
    End Property

    <DefaultValue(3)>
    <Description("下划线偏移量")>
    Public Property LineOffset As Integer
        Get
            Return _lineOffset
        End Get
        Set(value As Integer)
            If _lineOffset <> value Then
                _lineOffset = value
                RaiseEvent LineOffsetChanged(Me, Nothing)
            End If
        End Set
    End Property

    <DefaultValue(False)>
    <Description("指示控件是否显示下划线")>
    Public Property ShowLine As Boolean
        Get
            Return _showLine
        End Get
        Set(value As Boolean)
            _showLine = value
            RaiseEvent ShowLineChanged(Me, Nothing)
        End Set
    End Property

    ''' <summary>
    ''' 在 TextBoxEx.LineColor 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event LineColorChanged(ByVal sender As Object, e As EventArgs)

    ''' <summary>
    ''' 在 TextBoxEx.LineWidth 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event LineWidthChanged(ByVal sender As Object, e As EventArgs)

    ''' <summary>
    ''' 在 TextBoxEx.ShowLine 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event ShowLineChanged(ByVal sender As Object, e As EventArgs)
    ''' <summary>
    ''' 在 TextBoxEx.LineOffset 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event LineOffsetChanged(ByVal sender As Object, e As EventArgs)

    Public Sub onLineWidthChanged(ByVal sender As Object, e As EventArgs) Handles Me.LineWidthChanged, Me.LineOffsetChanged, Me.LineColorChanged
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub

    Public Sub onShowLineChanged() Handles Me.ShowLineChanged
        If Me.ShowLine Then
            BorderStyle = BorderStyle.None
            BackColor = Color.FromKnownColor(KnownColor.Control)
            rePosLine()
        Else
            BorderStyle = BorderStyle.Fixed3D
            BackColor = Color.FromKnownColor(KnownColor.Window)
            If Not IsNothing(Line) Then
                Line.Visible = False
            End If
        End If
    End Sub

    Protected Overrides Sub OnParentChanged(e As EventArgs)
        MyBase.OnParentChanged(e)
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub

    Protected Overrides Sub OnLocationChanged(e As EventArgs)
        MyBase.OnLocationChanged(e)
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub

    Protected Sub rePosLine()
        If Not IsNothing(Me.Parent) Then
            If Not Me.Parent.Controls.Contains(Line) Then
                Me.Parent.Controls.Add(Line)
            End If
            Line.Width = Me.Width
            Line.Height = Me.LineWidth
            Line.BackColor = Me.LineColor
            Line.Location = New Point(Me.Location.X, Me.Location.Y + Me.Height + Me.LineOffset)
            Line.Visible = True
            Line.BringToFront()
        End If
    End Sub

    Protected Overrides Sub Dispose(disposing As Boolean)
        MyBase.Dispose(disposing)
        If disposing Then
            If Not IsNothing(Line) Then
                Line.Dispose()
            End If
        End If
    End Sub

    Protected Overrides Sub OnLayout(levent As LayoutEventArgs)
        MyBase.OnLayout(levent)
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub
End Class

 

【iebook 超级精灵系列教程 2】制作片头

最近在群里看到有些人问如何让自己制作的flash片头在iebook里居中显示。印象中官方提供的帮助文档有说明的。

经过试验,个人觉得官方的制作介绍有些不清楚、不完善的地方,所以就自己写一篇供大家参考。如果有什么疏漏,请不吝赐教。: )

继续阅读【iebook 超级精灵系列教程 2】制作片头