Example #1
0
        //子节点
        private void ResolveSubTree(Dos.Model.Manager_Role model, TreeNode treeNode, string AuthItem)
        {
            //using (WXDBEntities db = new WXDBEntities())
            //{
            var list = DbSession.Default.From <Dos.Model.Manager_Role>()
                       .Where(s => s.Status.Equals(0) && s.ParentId.Equals(model.Id))
                       .OrderBy(s => s.Orders).ToList();

            // db.Manager_Role.Where(s => s.Status.Equals(0) && s.ParentId.Equals(model.Id)).OrderBy(s => s.Orders).ToList();
            if (list.Count > 0)
            {
                foreach (var item in list)
                {
                    TreeNode node = new TreeNode();
                    node.Text        = item.MenuText;
                    node.Value       = item.Id + "";
                    node.NavigateUrl = item.Id + "";
                    if (AuthItem.IndexOf(item.Id + "") > -1)
                    {
                        node.Checked = true;
                    }
                    node.SelectAction = TreeNodeSelectAction.None;
                    treeNode.ChildNodes.Add(node);
                    ResolveSubTree(item, node, AuthItem);
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Dos.Model.Manager_Role model = null;
            if (string.IsNullOrEmpty(nodeID) || nodeID == "0" || string.IsNullOrEmpty(iszjd) || iszjd == "0")
            {//根目录传过来的值
                model          = new Dos.Model.Manager_Role();
                model.AddUser  = loginname;
                model.AddTime  = DateTime.Now;
                model.Status   = 0;
                model.Orders   = 0;
                model.PagePath = "";
                model.Remark   = "";
                model.Name     = "";
            }
            else
            {//修改
                var tmpid = Convert.ToInt32(nodeID);
                model = DbSession.Default.From <Dos.Model.Manager_Role>().Where(s => s.Id.Equals(tmpid) && s.Status.Equals(0)).ToFirstDefault();
            }
            model.MenuText   = txt_MenuNameC.Value.Trim();
            model.Orders     = string.IsNullOrEmpty(txt_MenuOrder.Value.Trim()) ? 0 : Convert.ToInt32(txt_MenuOrder.Value.Trim());
            model.MenuPath   = txt_MenuUrl.Value.Trim();
            model.UpdateTime = DateTime.Now;
            model.UpdateUser = loginname;
            model.ParentId   = (string.IsNullOrEmpty(nodeID) || nodeID == "0") ? 0 : Convert.ToInt32(nodeID);
            int result = 0;

            if (Convert.ToInt32(nodeValue) >= 0)
            {
                try
                {
                    //数据
                    int ts = DbSession.Default.Insert <Dos.Model.Manager_Role>(model);
                    Logger.Default.Info("新增数据成功");
                    BindData();
                    ScriptManager.RegisterClientScriptBlock(btnSave, GetType(), "", "alert('操作成功!');parent.window.document.getElementById('leftFrame').src = 'sys_Module_Menu.aspx'", true);
                }
                catch (Exception ex)
                {
                    string Details = "出错!!!方法:" + ex.TargetSite + ",异常消息:" + ex.Message + ",出错的应用程序或对象名称:" + ex.Source;

                    Logger.Default.Info("新增数据失败", Details);
                    ScriptManager.RegisterClientScriptBlock(btnSave, GetType(), "", "alert('操作失败,请重新操作!');", true);
                }
            }
        }
        //子节点
        private void ResolveSubTree(Dos.Model.Manager_Role model, TreeNode treeNode)
        {
            var list = DbSession.Default.From <Dos.Model.Manager_Role>()
                       .Where(s => s.ParentId.Equals(model.Id) && s.Status.Equals(0))
                       .OrderBy(s => s.Orders).ToList();

            //db.Manager_Role.Where(s => s.ParentId.Equals(model.Id) && s.Status.Equals(0)).OrderBy(s => s.Orders).ToList();
            if (list.Count() > 0)
            {
                foreach (var item in list)
                {
                    TreeNode node  = new TreeNode();
                    var      count = DbSession.Default.From <Dos.Model.Manager_Role>().Where(s => s.ParentId.Equals(item.Id) && s.Status.Equals(0)).Count();
                    if (count > 0)
                    {//有子节点
                        node.NavigateUrl = "javascript:editshow('" + item.MenuText + "',1," + item.Id + ",'NO');";
                    }
                    else
                    {//没有字节点
                        node.NavigateUrl = "javascript:editshow('" + item.MenuText + "',1," + item.Id + ",'YES');";
                    }
                    node.Text  = item.MenuText;
                    node.Value = item.Id + "";
                    treeNode.ChildNodes.Add(node);
                    ResolveSubTree(item, node);
                    //node.NavigateUrl = "javascript:editshow('" + item.MenuText + "',1," + item.Id + ",'YES','isno');";
                    ////if (dt.Select("ParentId=" + row["Id"].ToString()).Count() > 0)
                    ////{//有子节点
                    ////    node.NavigateUrl = "javascript:editshow('" + row["MenuText"].ToString() + "',1," + row["Id"].ToString() + ",'NO');";
                    ////}
                    ////else
                    ////{//没有字节点

                    ////}
                    //node.Text = item.MenuText;
                    //node.Value = item.Id + "";
                    //treeNode.ChildNodes.Add(node);
                    //ResolveSubTree(row, node, dt);
                }
            }
        }