예제 #1
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            menuID   = TranslateUtils.ToInt(GetQueryString("menuID"));
            parentID = TranslateUtils.ToInt(GetQueryString("parentID"));

            if (Request.QueryString["Delete"] != null && menuID > 0)
            {
                DataProviderWX.MenuDAO.Delete(menuID);
                SuccessMessage("菜单删除成功!");
            }
            if (Request.QueryString["Subtract"] != null && menuID > 0)
            {
                DataProviderWX.MenuDAO.UpdateTaxisToUp(parentID, menuID);
                SuccessMessage("菜单排序成功!");
            }
            if (!IsPostBack)
            {
                BreadCrumb(AppManager.WeiXin.LeftMenu.ID_Accounts, AppManager.WeiXin.LeftMenu.Function.ID_Menu, string.Empty, AppManager.WeiXin.Permission.WebSite.Menu);
                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);
                if (EWXAccountTypeUtils.Equals(accountInfo.AccountType, EWXAccountType.Subscribe))
                {
                    PageUtils.RedirectToErrorPage(@"您的微信公众账号类型为订阅号(非认证),微信目前不支持订阅号自定义菜单。如果您的公众账号类型不是订阅号,请到账户信息中设置微信绑定账号。");
                    return;
                }

                ltlIFrame.Text = @"<iframe frameborder=""0"" id=""menu"" name=""menu"" width=""100%"" height=""500""></iframe>";

                var menuInfoList = DataProviderWX.MenuDAO.GetMenuInfoList(PublishmentSystemID, 0);

                var builder = new StringBuilder();

                foreach (var menuInfo in menuInfoList)
                {
                    var subMenuInfoList = DataProviderWX.MenuDAO.GetMenuInfoList(PublishmentSystemID, menuInfo.MenuID);

                    var subBuilder = new StringBuilder();

                    if (subMenuInfoList.Count < 5)
                    {
                        var addSubUrl = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, menuInfo.MenuID, 0);
                        subBuilder.AppendFormat(@"
                            <dd class=""add"">
                              <a href=""{0}"" target=""menu""><font>新增菜单</font></a>
                            </dd>", addSubUrl);
                    }

                    var i = 0;
                    foreach (var subMenuInfo in subMenuInfoList)
                    {
                        i++;

                        var ddClass        = i == subMenuInfoList.Count ? "last" : string.Empty;
                        var editSubUrl     = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, subMenuInfo.ParentID, subMenuInfo.MenuID);
                        var deleteSubUrl   = GetDeleteRedirectUrl(PublishmentSystemID, subMenuInfo.ParentID, subMenuInfo.MenuID);
                        var subtractSubUrl = GetSubtractRedirectUrl(PublishmentSystemID, subMenuInfo.ParentID, subMenuInfo.MenuID);


                        subBuilder.AppendFormat(@"                                                                   
                            <dd class=""{0}"">
                              <a href=""{1}"" target=""menu""><font>{2}</font></a>
                              <a href=""{3}"" onclick=""javascript:return confirm('此操作将删除子菜单“{2}”,确认吗?');"" class=""delete""><img src=""images/iphone-btn-delete.png""></a>
                              <a href=""{4}"" style='top:20px;' class=""delete""><img src=""images/iphone-btn-up.png""></a>
                            </dd>", ddClass, editSubUrl, subMenuInfo.MenuName, deleteSubUrl, subtractSubUrl);
                    }

                    var editUrl      = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, menuInfo.ParentID, menuInfo.MenuID);
                    var subMenuStyle = parentID == menuInfo.MenuID ? string.Empty : "display:none";
                    var deleteUrl    = GetDeleteRedirectUrl(PublishmentSystemID, menuInfo.ParentID, menuInfo.MenuID);
                    builder.AppendFormat(@"
                    <li class=""secondMenu"">
                        <a href=""{0}"" class=""mainMenu"" target=""menu""><font>{1}</font></a>
                        <dl class=""subMenus"" style=""{2}"">
                            <span>
                                <img width=""9"" height=""6"" src=""images/iphone-btn-tri.png"">
                            </span>
                            {3}
                        </dl>
                        <a href=""{4}"" onclick=""javascript:return confirm('此操作将删除主菜单“{1}”,确认吗?');"" class=""delete""><img src=""images/iphone-btn-delete.png""></a>
                    </li>", editUrl, menuInfo.MenuName, subMenuStyle, subBuilder.ToString(), deleteUrl);
                }

                if (menuInfoList.Count < 3)
                {
                    var addUrl = BackgroundMenuAdd.GetRedirectUrl(PublishmentSystemID, 0, 0);
                    builder.AppendFormat(@"
                    <li class=""secondMenu addMain"">
                        <a href=""{0}"" class=""mainMenu"" target=""menu""><font>新增菜单</font></a>
                    </li>", addUrl);
                }

                ltlMenu.Text = builder.ToString();
            }
        }