Пример #1
0
        protected void btnSaveRoot_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtRootCode.Text.Trim()))
            {
                lblrootMessage.Text = "代码不能为空!";
                return;
            }

            if (string.IsNullOrEmpty(txtRootName.Text.Trim()))
            {
                lblrootMessage.Text = "名称不能为空!";
                return;
            }

            using (var edm = new GoldEntities())
            {
                var tmp = edm.CreateObject <DataDict>();
                tmp.Name     = txtRootName.Text.Trim();
                tmp.Code     = txtRootCode.Text.Trim();
                tmp.Category = "root";
                tmp.Enabled  = true;

                edm.AddToDataDict(tmp);
                edm.SaveChanges();

                TreeNode node = new TreeNode();
                node.Value = tmp.Code;
                node.Text  = tmp.Name;
                TreeView1.Nodes.Add(node);

                txtRootCode.Text    = "";
                txtRootName.Text    = "";
                lblrootMessage.Text = "保存成功!";
            }
        }
Пример #2
0
        private void InitTree()
        {
            TreeView1.Nodes.Clear();

            using (var edm = new GoldEntities())
            {
                var query = from p in edm.Department
                            where p.DepartmentCode == "root"
                            select p;

                Department root;
                if (query.Count <Department>() == 0)
                {
                    var tmp = edm.CreateObject <Department>();
                    tmp.DepartmentCode = "root";
                    tmp.DepartmentName = "深圳金币";
                    tmp.Parent         = "0";

                    edm.AddToDepartment(tmp);
                    edm.SaveChanges();

                    root = tmp;
                }
                else
                {
                    root = query.First();
                }

                TreeNode rootNode = new TreeNode();
                rootNode.Text  = root.DepartmentName;
                rootNode.Value = root.DepartmentCode;
                CreatChildNodes(rootNode, root, edm);
                TreeView1.Nodes.Add(rootNode);
                rootNode.ExpandAll();

                if (TreeView1.SelectedNode == null)
                {
                    rootNode.Select();
                    GridViewBind();//显示全部用户
                }
            }
        }
Пример #3
0
        protected void btnSaveValue_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtValueCode.Text.Trim()))
            {
                lblMessage2.Text = "代码不能为空!";
                return;
            }

            if (string.IsNullOrEmpty(txtValueName.Text.Trim()))
            {
                lblMessage2.Text = "名称不能为空!";
                return;
            }


            using (var edm = new GoldEntities())
            {
                var tmp = edm.CreateObject <DataDict>();
                tmp.Name = txtValueName.Text.Trim();
                tmp.Code = txtValueCode.Text.Trim();
                int x;
                if (!string.IsNullOrEmpty(txtValueOrder.Text.Trim()) &&
                    int.TryParse(txtValueOrder.Text.Trim(), out x))
                {
                    tmp.Order = x;
                }

                tmp.Category = TreeView1.SelectedNode.Value;
                tmp.Enabled  = true;

                edm.AddToDataDict(tmp);
                edm.SaveChanges();

                GridView1.DataBind();

                txtValueCode.Text  = "";
                txtValueName.Text  = "";
                txtValueOrder.Text = "";
                lblMessage2.Text   = "保存成功!";
            }
        }