Пример #1
0
        private void InitializeUnit()
        {
            UnitDal unitDal = new UnitDal();
            DataTable classTable = unitDal.GetUnitClass();
            DataTable unitTable = unitDal.GetUnit();

            foreach (DataRow classRow in classTable.Rows)
            {
                TreeNode classNode = new TreeNode();
                classNode.Name = classRow["UNITCLASSCODE"].ToString();
                classNode.Text = string.Format("{0}[{1}]", classRow["UNITCLASSNAME"], classRow["UNITCLASSCODE"]);
                classNode.Tag = classRow["UNITCLASSNAME"];

                DataRow[] unitRows = unitTable.Select(string.Format("UNITCLASS='{0}'", classRow["UNITCLASSCODE"]));
                foreach (DataRow unitRow in unitRows)
                {
                    TreeNode unitNode = new TreeNode();
                    unitNode.Name = unitRow["UNITCODE"].ToString();
                    unitNode.Text = string.Format("{0}[{1}]", unitRow["UNITNAME"], unitRow["UNITCODE"].ToString().Trim());
                    unitNode.Tag = unitRow["UNITNAME"];
                    classNode.Nodes.Add(unitNode);
                }

                tvUnit.Nodes.Add(classNode);
            }
        }
Пример #2
0
        private void pnlMain_ParentChanged(object sender, EventArgs e)
        {
            if (!hasInitialize)
            {
                UnitDal unitDal = new UnitDal();
                DataTable classTable = unitDal.GetUnitClass();
                unitTable = unitDal.GetUnit();

                foreach (DataRow classRow in classTable.Rows)
                {
                    TreeNode classNode = new TreeNode();
                    classNode.Name = classRow["UNITCLASSCODE"].ToString();
                    classNode.Text = string.Format("{0}[{1}]", classRow["UNITCLASSNAME"], classRow["UNITCLASSCODE"]);
                    classNode.Tag = classRow["UNITCLASSNAME"];

                    DataRow[] unitRows = unitTable.Select(string.Format("UNITCLASS='{0}'", classRow["UNITCLASSCODE"]));
                    foreach (DataRow unitRow in unitRows)
                    {
                        TreeNode unitNode = new TreeNode();
                        unitNode.Name = unitRow["UNITCODE"].ToString();
                        unitNode.Text = string.Format("{0}[{1}]", unitRow["UNITNAME"], unitRow["UNITCODE"].ToString().Trim());
                        unitNode.Tag = unitRow;
                        classNode.Nodes.Add(unitNode);
                    }

                    tvLeft.Nodes.Add(classNode);
                }
                hasInitialize = true;
                tvLeft.ExpandAll();
                tvLeft.Focus();
            }
        }