using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using SysCore;
using SysCore.Control;
using SysCore.Model;
using SysCore.DAL;

public partial class Base_VendorClass_VendorClass_Tree : System.Web.UI.Page
{
    public Hashtable xview = new Hashtable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            CreateTree();
        }
    }
    /// <summary>
    /// 绑定控件数据源
    /// </summary>
    public void CreateTree()
    {
        string where = "where 1=1";
        string keyword = Request.QueryString["keyword"];
        if (!keyword.Equals(""))
        {
            //只搜索末级
            where += " and (vc_code like '%" + keyword + "%' or vc_name like '%" + keyword + "%' or vc_id in (select parent_id from Base_VendorClass)) ";
        }
        DataTable tb = new VendorClassDAL().GetListAll(where);
        DTree dt = new DTree("dt");
        dt.AddChildNode("0", "-1", "客户分类", "javascript:SelectCategory(\\'0\\')", "", "", "../../Scripts/dtree/images/folder.gif");
        foreach (DataRow dr in tb.Rows)
        {
            string vc_id = dr["vc_id"].ToString();
            string parent_id = dr["parent_id"].ToString();
            string vc_code = dr["vc_code"].ToString(); 
            string vc_name = dr["vc_name"].ToString();
            dt.AddChildNode(vc_id, parent_id, vc_code + " " + vc_name, "javascript:SelectCategory(\\'" + vc_id + "\\')", "", "", "../../Scripts/dtree/images/folder.gif");
        }
        xview.Add("dtree", dt.GetTree());
    }
}
