private Ext.Net.NodeCollection BuildTree(Ext.Net.NodeCollection nodes)
    {
        if (nodes == null)
        {
            nodes = new Ext.Net.NodeCollection();
        }
        Ext.Net.Node root = new Ext.Net.Node();
        root.Text = "Root";
        nodes.Add(root);



        int depid = 0, tem = 0;

        if (common.IntSafeConvert(cmbdept.SelectedItem.Value) > 0)
        {
            depid = common.IntSafeConvert(cmbdept.SelectedItem.Value);
        }
        string year = cmbyear.SelectedItem.Value ?? DateTime.Now.Year.ToString();

        string month = cmbmonth.SelectedItem.Value ?? DateTime.Now.Month.ToString();

        month = month.Length == 1 ? "0" + month : month;
        string yearMonth = year + "-" + month;

        string precmb = (common.IntSafeConvert(month) - 1).ToString();

        precmb = precmb.Length == 1 ? "0" + precmb : precmb;
        string preYearMonth = year + "-" + precmb;
        //yearMonth = "2015-02";
        //preYearMonth = "2015-01";
        //DataTable dtpiidTable = ExecuteNewLogic.GetDtPiidList(depid, yearMonth, tem);
        //DataTable predtpiidTable = ExecuteNewLogic.GetDtPiidList(depid, preYearMonth, tem);

        // DataTable dt = BG_PayIncomeLogic.GetDtPayIncomeByPIID(tem);
        DataTable dt = ExecuteNewLogic.GetDtAllPiidList(depid, yearMonth, preYearMonth);

        if (dt.Rows.Count == 0)
        {
            X.Msg.Alert("系统提示", "本月没有执行相关数据").Show();
            root.EmptyChildren = true;
            return(nodes);
        }
        DataTable dtroot   = dt.DefaultView.ToTable("dtroot", true, new string[] { "PIID", "ParentPIEcoSubName" });
        string    piidList = "";

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int piid = common.IntSafeConvert(dt.Rows[i]["ChildID"]);
                piidList += piid + ",";
            }
        }
        piidList = piidList.TrimEnd(',');
        DataTable dtcashier = ExecuteNewLogic.GetCashierData(depid, yearMonth, piidList);
        DataTable pMoney    = ExecuteNewLogic.GetReceiptsData(depid, preYearMonth, piidList, 0);
        DataTable pMoney1   = ExecuteNewLogic.GetReceiptsData(depid, preYearMonth, piidList, 1);
        DataTable pMoney2   = ExecuteNewLogic.GetReceiptsData(depid, preYearMonth, piidList, 2);
        DataTable rpMoney   = ExecuteNewLogic.GetReceiptsData(depid, yearMonth, piidList, 0);
        DataTable rpMoney1  = ExecuteNewLogic.GetReceiptsData(depid, yearMonth, piidList, 1);
        DataTable rpMoney2  = ExecuteNewLogic.GetReceiptsData(depid, yearMonth, piidList, 2);
        DataTable totalMon  = ExecuteNewLogic.GetBudgetAllocationData(depid, year, piidList);
        DataTable newTable  = new DataTable();

        newTable.Columns.Add("PIID");
        newTable.Columns.Add("ChildID");
        newTable.Columns.Add("PIEcoSubName");
        newTable.Columns.Add("totalMon");
        newTable.Columns.Add("BQMon");
        newTable.Columns.Add("CashierBalance");
        newTable.Columns.Add("PMoney");
        newTable.Columns.Add("PMoney1");
        newTable.Columns.Add("PMoney2");
        newTable.Columns.Add("RpMoney");
        newTable.Columns.Add("RpMoney1");
        newTable.Columns.Add("RpMoney2");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow drRow = newTable.NewRow();
            int     piid  = common.IntSafeConvert(dt.Rows[i]["ChildID"]);
            if (dtcashier.Rows.Count > 0)
            {
                DataRow[] dtca = dtcashier.Select("piid=" + piid);
                if (dtca.Length > 0)
                {
                    drRow["BQMon"]          = dtca[0]["BQMon"];
                    drRow["CashierBalance"] = dtca[0]["CashierBalance"];
                }
            }
            if (rpMoney.Rows.Count > 0)
            {
                DataRow[] dtrp = rpMoney.Select("piid=" + piid);
                if (dtrp.Length > 0)
                {
                    drRow["RpMoney"] = dtrp[0]["RpMoney"];
                }
            }
            if (rpMoney1.Rows.Count > 0)
            {
                DataRow[] dtrp1 = rpMoney1.Select("piid=" + piid);
                if (dtrp1.Length > 0)
                {
                    drRow["RpMoney1"] = dtrp1[0]["RpMoney"];
                }
            }
            if (rpMoney2.Rows.Count > 0)
            {
                DataRow[] dtrp2 = rpMoney2.Select("piid=" + piid);
                if (dtrp2.Length > 0)
                {
                    drRow["RpMoney2"] = dtrp2[0]["RpMoney"];
                }
            }
            if (pMoney.Rows.Count > 0)
            {
                {
                    DataRow[] dtp = pMoney.Select("piid=" + piid);
                    if (dtp.Length > 0)
                    {
                        drRow["PMoney"] = dtp[0]["RpMoney"];
                    }
                }
            }
            if (pMoney1.Rows.Count > 0)
            {
                DataRow[] dtp1 = pMoney1.Select("piid=" + piid);
                if (dtp1.Length > 0)
                {
                    drRow["PMoney1"] = dtp1[0]["RpMoney"];
                }
            }
            if (pMoney2.Rows.Count > 0)
            {
                DataRow[] dtp2 = pMoney2.Select("piid=" + piid);
                if (dtp2.Length > 0)
                {
                    drRow["PMoney2"] = dtp2[0]["RpMoney"];
                }
            }
            if (totalMon.Rows.Count > 0)
            {
                DataRow[] dttotalMon = totalMon.Select("piid=" + piid);
                if (dttotalMon.Length > 0)
                {
                    drRow["totalMon"] = dttotalMon[0]["total"];
                }
            }
            drRow["PIEcoSubName"] = dt.Rows[i]["PIEcoSubName"].ToString();
            drRow["ChildID"]      = dt.Rows[i]["ChildID"].ToString();
            drRow["PIID"]         = dt.Rows[i]["PIID"].ToString();
            newTable.Rows.Add(drRow);
        }

        for (int i = 0; i < dtroot.Rows.Count; i++)
        {
            Node   newNode = new Node();
            string piid    = dtroot.Rows[i]["piid"].ToString();
            newNode.NodeID = piid;
            newNode.Text   = dtroot.Rows[i]["ParentPIEcoSubName"].ToString();
            newNode.Icon   = Icon.Folder;
            decimal   BQMon = 0, CashierBalance = 0, PMoney = 0, PMoney1 = 0, PMoney2 = 0, RpMoney = 0, RpMoney1 = 0, RpMoney2 = 0, total = 0;
            DataRow[] drrowsleaf = newTable.Select("PIID=" + piid);
            if (drrowsleaf.Length > 0)
            {
                for (int j = 0; j < drrowsleaf.Length; j++)
                {
                    Node nodenew = new Node();
                    nodenew.NodeID = drrowsleaf[j]["ChildID"].ToString();
                    nodenew.Text   = drrowsleaf[j]["PIEcoSubName"].ToString();
                    //nodenew.CustomAttributes.Add(new ConfigItem("PIID",drRows[j]["PIEcoSubName"].ToString(), ParameterMode.Value));
                    //nodenew.CustomAttributes.Add(new ConfigItem("PIEcoSubName",drRows[j]["PIEcoSubName"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("BQMon", drrowsleaf[j]["BQMon"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("CashierBalance", drrowsleaf[j]["CashierBalance"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("PMoney", drrowsleaf[j]["PMoney"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("PMoney1 ", drrowsleaf[j]["PMoney1"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("PMoney2 ", drrowsleaf[j]["PMoney2"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("RpMoney ", drrowsleaf[j]["RpMoney"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("RpMoney1 ", drrowsleaf[j]["RpMoney1"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("RpMoney2 ", drrowsleaf[j]["RpMoney2"].ToString(), ParameterMode.Value)); nodenew.CustomAttributes.Add(new ConfigItem("totalMon ", drrowsleaf[j]["totalMon"].ToString(), ParameterMode.Value));
                    nodenew.Leaf = true;
                    nodenew.Icon = Icon.Anchor;
                    newNode.Children.Add(nodenew);
                    BQMon          += ParToDecimal.ParToDel(drrowsleaf[j]["BQMon"].ToString());
                    CashierBalance += ParToDecimal.ParToDel(drrowsleaf[j]["CashierBalance"].ToString());
                    PMoney         += ParToDecimal.ParToDel(drrowsleaf[j]["PMoney"].ToString());
                    PMoney1        += ParToDecimal.ParToDel(drrowsleaf[j]["PMoney1"].ToString());
                    PMoney2        += ParToDecimal.ParToDel(drrowsleaf[j]["PMoney2"].ToString());
                    RpMoney        += ParToDecimal.ParToDel(drrowsleaf[j]["RpMoney"].ToString());
                    RpMoney1       += ParToDecimal.ParToDel(drrowsleaf[j]["RpMoney1"].ToString());
                    RpMoney2       += ParToDecimal.ParToDel(drrowsleaf[j]["RpMoney2"].ToString());
                    total          += ParToDecimal.ParToDel(drrowsleaf[j]["totalMon"].ToString());
                }
            }
            else
            {
                newNode.EmptyChildren = true;
            }
            newNode.CustomAttributes.Add(new ConfigItem("BQMon", BQMon.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("CashierBalance", CashierBalance.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("PMoney", PMoney.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("PMoney1 ", PMoney1.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("PMoney2 ", PMoney2.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("RpMoney ", RpMoney.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("RpMoney1 ", RpMoney1.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("RpMoney2 ", RpMoney2.ToString(), ParameterMode.Value));
            newNode.CustomAttributes.Add(new ConfigItem("totalMon ", total.ToString(), ParameterMode.Value));
            root.Children.Add(newNode);
        }

        return(nodes);
    }
    private Ext.Net.NodeCollection BuildTree(Ext.Net.NodeCollection nodes)
    {
        if (nodes == null)
        {
            nodes = new Ext.Net.NodeCollection();
        }
        Ext.Net.Node root = new Ext.Net.Node();
        root.Text = "Root";
        nodes.Add(root);



        int depid = 0, tem = 0;

        if (common.IntSafeConvert(cmbdept.SelectedItem.Value) > 0)
        {
            depid = common.IntSafeConvert(cmbdept.SelectedItem.Value);
        }
        string year = cmbyear.SelectedItem.Value ?? DateTime.Now.Year.ToString();


        DataTable dt = ExecuteNewLogic.GetDtAllPiidListyear(depid, year);

        if (dt.Rows.Count == 0)
        {
            X.Msg.Alert("系统提示", "本月没有执行相关数据").Show();
            root.EmptyChildren = true;
            return(nodes);
        }
        DataTable dtroot   = dt.DefaultView.ToTable("dtroot", true, new string[] { "PIID", "ParentPIEcoSubName" });
        string    piidList = "";

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int piid = common.IntSafeConvert(dt.Rows[i]["ChildID"]);
                piidList += piid + ",";
            }
        }
        piidList = piidList.TrimEnd(',');
        DataTable dtcashier = ExecuteNewLogic.GetCashierDatayear(depid, year, piidList);
        DataTable RpMoney   = ExecuteNewLogic.GetReceiptsDatayear(depid, year, piidList, 2);
        DataTable totalMon  = ExecuteNewLogic.GetBudgetAllocationData(depid, year, piidList);
        DataTable newTable  = new DataTable();

        newTable.Columns.Add("PIID");
        newTable.Columns.Add("ChildID");
        newTable.Columns.Add("PIEcoSubName");
        newTable.Columns.Add("totalMon");
        newTable.Columns.Add("BQMon");
        newTable.Columns.Add("RpMoney");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow drRow = newTable.NewRow();
            int     piid  = common.IntSafeConvert(dt.Rows[i]["ChildID"]);
            if (dtcashier.Rows.Count > 0)
            {
                DataRow[] dtca = dtcashier.Select("piid=" + piid);
                if (dtca.Length > 0)
                {
                    drRow["BQMon"] = dtca[0]["BQMon"];
                    //drRow["CashierBalance"] = dtca[0]["CashierBalance"];
                }
            }
            if (RpMoney.Rows.Count > 0)
            {
                DataRow[] dtp2 = RpMoney.Select("piid=" + piid);
                if (dtp2.Length > 0)
                {
                    drRow["RpMoney"] = dtp2[0]["RpMoney"];
                }
            }
            if (totalMon.Rows.Count > 0)
            {
                DataRow[] dttotalMon = totalMon.Select("piid=" + piid);
                if (dttotalMon.Length > 0)
                {
                    drRow["totalMon"] = dttotalMon[0]["total"];
                }
            }
            drRow["PIEcoSubName"] = dt.Rows[i]["PIEcoSubName"].ToString();
            drRow["ChildID"]      = dt.Rows[i]["ChildID"].ToString();
            drRow["PIID"]         = dt.Rows[i]["PIID"].ToString();
            newTable.Rows.Add(drRow);
        }

        for (int i = 0; i < dtroot.Rows.Count; i++)
        {
            Node   newNode = new Node();
            string piid    = dtroot.Rows[i]["piid"].ToString();
            newNode.NodeID = piid;
            newNode.Text   = dtroot.Rows[i]["ParentPIEcoSubName"].ToString();
            newNode.Icon   = Icon.Folder;
            // newNode.Leaf = true;
            decimal   BQMond = 0, RpMoneyd = 0, totalMond = 0;
            DataRow[] drrowsleaf = newTable.Select("PIID=" + piid);
            if (drrowsleaf.Length > 0)
            {
                NodeCollection nc = new NodeCollection();
                for (int j = 0; j < drrowsleaf.Length; j++)
                {
                    Node nodenew = new Node();
                    nodenew.NodeID = drrowsleaf[j]["ChildID"].ToString();
                    nodenew.Text   = drrowsleaf[j]["PIEcoSubName"].ToString();
                    //nodenew.CustomAttributes.Add(new ConfigItem("PIID",drRows[j]["PIEcoSubName"].ToString(), ParameterMode.Value));
                    //nodenew.CustomAttributes.Add(new ConfigItem("PIEcoSubName",drRows[j]["PIEcoSubName"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("BQMon", drrowsleaf[j]["BQMon"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("RpMoney ", drrowsleaf[j]["RpMoney"].ToString(), ParameterMode.Value));
                    nodenew.CustomAttributes.Add(new ConfigItem("totalMon ", drrowsleaf[j]["totalMon"].ToString(), ParameterMode.Value));
                    nodenew.Leaf = true;
                    nodenew.Icon = Icon.Anchor;
                    nc.Add(nodenew);

                    BQMond    += ParToDecimal.ParToDel(drrowsleaf[j]["BQMon"].ToString());
                    RpMoneyd  += ParToDecimal.ParToDel(drrowsleaf[j]["RpMoney"].ToString());
                    totalMond += ParToDecimal.ParToDel(drrowsleaf[j]["totalMon"].ToString());
                }
                newNode.CustomAttributes.Add(new ConfigItem("BQMon", BQMond.ToString(), ParameterMode.Value));
                newNode.CustomAttributes.Add(new ConfigItem("RpMoney ", RpMoneyd.ToString(), ParameterMode.Value));
                newNode.CustomAttributes.Add(new ConfigItem("totalMon ", totalMond.ToString(), ParameterMode.Value));

                root.Children.Add(newNode);
                newNode.Children.AddRange(nc);
            }
            else
            {
                newNode.EmptyChildren = true;
            }
        }

        return(nodes);
    }