Beispiel #1
0
        public void RequreTest()
        {
            var json  = TreeStructResult;
            var names = new string[] { "A", "B", "a1", "a2" };
            var tree  = new treeItem()
            {
                Name = "A", Next = new treeItem()
                {
                    Name = "B"
                },
                Child = new treeItem()
                {
                    Name = "a1", Next = new treeItem()
                    {
                        Name = "a2"
                    }
                }
            };

            //requre link
            tree.Child.Next.Child = tree;
            //non requre link
            tree.Next.Child = tree.Child;

            var result = JsonConverter.SerializeObject(tree, Formatting.Indented | Formatting.IncludeTypeName | Formatting.BreakReqursion);

            Assert.AreEqual(json, result);
        }
Beispiel #2
0
        public JsonResult gettree()
        {
            try
            {
                string account = User.Identity.Name;
                if (string.IsNullOrEmpty(account))
                {
                    account = "malkin";
                }
                var tu = new treeutil();

                var data  = new DataTable();
                var cnstr = Program.isPostgres ? Program.AppConfig["cns"] : Program.AppConfig["mscns"];
                var sql   = "select a.* , fn_getmenuimageid(a.caption) idimage from fn_mainmenu('ALL', @Account) a order by a.ordmenu, idmenu";
                if (!Program.isPostgres)
                {
                    //sql = "select a.* , dbo.fn_getmenuimageid(a.caption) idimage from fn_mainmenu('ALL', @Account) a order by a.ordmenu, idmenu";
                    sql = "exec p_fn_getmenuimageid @Account";
                }
                if (Program.isPostgres)
                {
                    var da = new NpgsqlDataAdapter(sql, cnstr);
                    da.SelectCommand.Parameters.AddWithValue("@Account", account);
                    da.Fill(data);
                }
                else
                {
                    var da = new SqlDataAdapter(sql, cnstr);
                    da.SelectCommand.Parameters.AddWithValue("@Account", account);
                    da.Fill(data);
                }

                var rootItem = new treeItem("root");
                rootItem.children = new List <object>();

                tu.CreateItems("Root/", rootItem, data);
                return(Json(rootItem.children));
            }
            catch (Exception e)
            {
                return(Json(new object[] { new { text = e.Message } }));
            }
        }