コード例 #1
0
 /// <summary>
 /// 获取菜单按钮类型
 /// </summary>
 /// <param name="menu"></param>
 /// <returns></returns>
 private Button GetButton(DefineMenu menu)
 {
     if (menu.type.Equals("click"))
     {
         return new KeyButton()
                {
                    name = menu.name, key = menu.key_val, type = menu.type
                }
     }
     ;
     else
     {
         return new UrlButton()
                {
                    name = menu.name, url = menu.key_val.Replace("&", "%26"), type = menu.type
                }
     };
 }
コード例 #2
0
        /// <summary>
        /// 保存自定义菜单
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="groupMenu"></param>
        /// <returns></returns>
        public StateCode SaveBuild(long user_id, DefineMenuGroup groupMenu)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    s.StartTransaction();

                    //现有的菜单
                    List <DefineMenu> old_menus = s.List <DefineMenu>("where group_id = @0", groupMenu.id);
                    //临时菜单数据
                    List <DefineMenu> tmp_menus = new List <DefineMenu>();

                    if (groupMenu.id == 0)
                    {
                        groupMenu.created_date    = DateTime.Now;
                        groupMenu.created_user_id = user_id;
                        s.Insert(groupMenu);
                    }
                    else
                    {
                        groupMenu.updated_date    = DateTime.Now;
                        groupMenu.updated_user_id = user_id;
                        s.Update(groupMenu);
                    }

                    //获取主菜单
                    List <DefineMenu> p_menus = groupMenu.buttons.Where(m => m.tmp_parent_id == 0).ToList();
                    List <DefineMenu> c_menus = groupMenu.buttons.Where(m => m.tmp_parent_id != 0).ToList();
                    foreach (DefineMenu menu in p_menus)
                    {
                        //是否在原有的集合存在
                        DefineMenu omenu = old_menus.Where(m => m.id == menu.id).SingleOrDefault();
                        menu.parent_id = 0;
                        menu.group_id  = groupMenu.id;
                        if (omenu == null)
                        {
                            s.Insert(menu);
                        }
                        else
                        {
                            tmp_menus.Add(menu);
                            s.Update(menu);
                        }

                        //子菜单
                        foreach (DefineMenu cmenu in c_menus)
                        {
                            //是否在原有的集合存在
                            DefineMenu cm = old_menus.Where(m => m.id == cmenu.id).SingleOrDefault();
                            //父级ID
                            cmenu.parent_id = menu.id;
                            //组ID
                            cmenu.group_id = groupMenu.id;

                            if (cmenu.tmp_parent_id == menu.tmp_id)
                            {
                                if (cm == null)
                                {
                                    s.Insert(cmenu);
                                }
                                else
                                {
                                    tmp_menus.Add(cmenu);
                                    s.Update(cmenu);
                                }
                            }
                        }
                    }


                    #region  除页面已删除的菜单

                    //筛选出删除的商品规格
                    foreach (DefineMenu omenu in old_menus)
                    {
                        bool is_delete = true;
                        foreach (DefineMenu tmenu in tmp_menus)
                        {
                            if (tmenu.id == omenu.id)
                            {
                                is_delete = false;
                                break;
                            }
                        }
                        if (is_delete)
                        {
                            s.ExcuteUpdate("delete tb_wx_menu where id = @0 ", omenu.id);
                        }
                    }

                    #endregion

                    s.Commit();
                }
                catch (Exception ex)
                {
                    s.RollBack();
                    return(StateCode.State_500);
                }
                return(StateCode.State_200);
            }
        }