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 Component_AdvancedSearch_InventoryClass_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 (ic_code like '%" + keyword + "%' or ic_name like '%" + keyword + "%' or ic_id in (select parent_id from Base_InventoryClass)) ";
        }
        DataTable tb = new InventoryClassDAL().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 ic_id = dr["ic_id"].ToString();
            string parent_id = dr["parent_id"].ToString();
            string ic_code = dr["ic_code"].ToString(); 
            string ic_name = dr["ic_name"].ToString();
            dt.AddChildNode(ic_id, parent_id, ic_code + " " + ic_name, "javascript:SelectCategory(\\'" + ic_id + "\\')", "", "", "../../Scripts/dtree/images/folder.gif");
        }
        xview.Add("dtree", dt.GetTree());
    }
}
