using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
namespace ComResProSystem
{
    public partial class SelectPerson:BasePage
    {
        UserBll bll = new UserBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = bll.gettable("SELECT DISTINCT  Part FROM Users");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TreeView1.Nodes.Add(new TreeNode(dt.Rows[i]["Part"].ToString(), dt.Rows[i]["Part"].ToString()));
                }
            }
        }

        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            if (TreeView1.SelectedNode.Depth == 0)
            {
                string Part = TreeView1.SelectedValue;
                DataTable dt = bll.gettable("SELECT UserName FROM dbo.Users WHERE Part='" + Part + "'");
                TreeNode node = TreeView1.SelectedNode;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
            
                    node.ChildNodes.Add(new TreeNode(dt.Rows[i]["UserName"].ToString(), dt.Rows[i]["UserName"].ToString()));
                }
            }
            if ((TreeView1.SelectedNode.Depth == 1))
            {
                string value = TreeView1.SelectedValue;
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "close", "window.parent.returnValue='"+value+"';window.close();", true);

            }
        }
    }
}