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_IOType_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 (Request["iot_flag"] != null && !Request["iot_flag"].Equals(""))
        {
            string iot_flag = Request.QueryString["iot_flag"];
            where += " and iot_flag=" + iot_flag + " ";
        }
        if (!keyword.Equals(""))
        {
            //只搜索末级
            where += " and (iot_code like '%" + keyword + "%' or iot_name like '%" + keyword + "%' or iot_id in (select parent_id from Base_IOType)) "; 
        }
        DataTable tb = new IOTypeDAL().GetListAll(where);
        DTree dt = new DTree("dt");
        dt.AddParentNode("0", "-1", "选择收发类型");
        foreach (DataRow dr in tb.Rows)
        {
            string iot_id = dr["iot_id"].ToString();
            string parent_id = dr["parent_id"].ToString();
            string iot_code = dr["iot_code"].ToString(); 
            string iot_name = dr["iot_name"].ToString();
            dt.AddChildNode(iot_id, parent_id, iot_code + " " + iot_name, "javascript:SelectCategory(\\'" + iot_id + "\\')", "", "", "../../Scripts/dtree/images/folder.gif");
        }
        xview.Add("dtree", dt.GetTree());
    }
}
