Beispiel #1
0
        //tik
        public JsonResult json_getTopics()
        {
            sqlServer db = new sqlServer(ConfigurationManager.ConnectionStrings["winhostConnection"].ConnectionString);
            DataTable dt = db.fetch(
                "select topic_id as type_id,topic_title as type_title, topic_details as type_detail, topic_parent_id as parent_type_id,topic_title as type_name,is_active " +
                " from saeid.topic  where is_active=1 order by datetime").Tables[0];

            List <menu> tree = new List <menu> {
            };

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["parent_type_id"].ToString() == "")
                {
                    var node = new menu()
                    {
                        id             = dt.Rows[i]["type_id"].ToString(),
                        iconCls        = "treei",
                        type_name      = dt.Rows[i]["type_name"].ToString(),
                        parent_type_id = dt.Rows[i]["parent_type_id"].ToString(),
                        type_title     = dt.Rows[i]["type_title"].ToString(),
                        type_detail    = dt.Rows[i]["type_detail"].ToString(),

                        children = new List <menu>()
                    };
                    tree.Add(node);
                }
            }

            for (int j = 0; j < tree.Count; j++)
            {
                Rec(tree[j], dt);
            }

            return(Json(tree, JsonRequestBehavior.AllowGet));
        }
        public void Rec(menu node,DataTable dt)
        {
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                if (dt.Rows[j]["parent_type_id"].ToString() == node.id)
                {
                    var _node = new menu()
                    {
                        id = dt.Rows[j]["type_id"].ToString(),
                        iconCls = "treei",
                        type_name = dt.Rows[j]["type_name"].ToString(),
                        parent_type_id  = dt.Rows[j]["parent_type_id"].ToString(),
                        type_title = dt.Rows[j]["type_title"].ToString(),
                        type_detail = dt.Rows[j]["type_detail"].ToString(),

                        children        = new List<menu>()
                    };
                    node.children.Add(_node);
                }
            }
            for (int j = 0; j < node.children.Count; j++)
                Rec(node.children[j], dt);
        }
        //tik
        public JsonResult json_getTopics()
        {
            sqlServer db = new sqlServer(ConfigurationManager.ConnectionStrings["winhostConnection"].ConnectionString);
            DataTable dt = db.fetch(
                "select topic_id as type_id,topic_title as type_title, topic_details as type_detail, topic_parent_id as parent_type_id,topic_title as type_name,is_active " +
                " from saeid.topic  where is_active=1 order by datetime").Tables[0];

            List<menu> tree = new List<menu> { };
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["parent_type_id"].ToString() == "")
                {
                    var node = new menu()
                    {
                        id = dt.Rows[i]["type_id"].ToString(),
                        iconCls = "treei",
                        type_name = dt.Rows[i]["type_name"].ToString(),
                        parent_type_id = dt.Rows[i]["parent_type_id"].ToString(),
                        type_title = dt.Rows[i]["type_title"].ToString(),
                        type_detail = dt.Rows[i]["type_detail"].ToString(),

                        children        = new List<menu>()
                    };
                    tree.Add(node);
                }
            }

            for (int j = 0; j < tree.Count; j++)
                Rec(tree[j], dt);

            return Json(tree, JsonRequestBehavior.AllowGet);
        }