Example #1
0
        private List <MenuModel> GetSubMenu(string code, int deep, out bool isSelect)
        {
            bool temp = false;

            isSelect = false;
            List <string>    moduleList = new List <string>();
            List <MenuModel> menuList   = new List <MenuModel>();
            ModuleDA         moduleDA   = null;
            DataTable        dt         = new DataTable();

            try
            {
                moduleDA = new ModuleDA();
                dt       = moduleDA.GetMenuByCodeAndUserID(code, UserUID, Operation);


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];

                    if ("".Equals(CommUtil.ConvertObjectToString(dr["ModuleCode"])) || moduleList.Contains(CommUtil.ConvertObjectToString(dr["ModuleCode"])))
                    {
                        continue;
                    }
                    else
                    {
                        moduleList.Add(CommUtil.ConvertObjectToString(dr["ModuleCode"]));
                    }

                    MenuModel mm = new MenuModel();
                    mm.ModuleCode       = CommUtil.ConvertObjectToString(dr["ModuleCode"]);
                    mm.ModuleName       = CommUtil.ConvertObjectToString(dr["ModuleName"]);
                    mm.ModuleController = CommUtil.ConvertObjectToString(dr["ModuleController"]);
                    mm.ModuleAction     = CommUtil.ConvertObjectToString(dr["ModuleAction"]);
                    mm.IsFatherNode     = CommUtil.ConvertObjectToBool(dr["IsFatherNode"]);

                    if (mm.IsFatherNode && deep <= 5)
                    {
                        mm.SubMenu = GetSubMenu(mm.ModuleCode, deep + 1, out isSelect);
                    }
                    else
                    {
                        isSelect = CheckMenuSelected(mm.ModuleController, mm.ModuleAction);
                    }

                    mm.IsSelect = isSelect;

                    //subMenu is selected
                    if (isSelect)
                    {
                        temp = true;
                    }

                    menuList.Add(mm);
                }

                //if submenu is selectd father menu is selected
                if (temp)
                {
                    isSelect = true;
                }
            }
            finally
            {
                if (moduleDA != null)
                {
                    moduleDA.CloseConnection();
                }
            }

            return(menuList);
        }