Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.SelectedTab = tabID.actMyClubs;

        if (Request.PathInfo.Length > 0 && Request.PathInfo.StartsWith("/", StringComparison.OrdinalIgnoreCase))
        {
            if (!IsPostBack)
            {
                try
                {
                    CurrentClub = Club.ClubWithID(Convert.ToInt32(Request.PathInfo.Substring(1), CultureInfo.InvariantCulture));
                    if (CurrentClub == null)
                    {
                        throw new MyFlightbookException(Resources.Club.errNoSuchClub);
                    }

                    Master.Title       = CurrentClub.Name;
                    lblClubHeader.Text = CurrentClub.Name;

                    ClubMember cm = CurrentClub.GetMember(Page.User.Identity.Name);

                    DateTime dtClub = ScheduledEvent.FromUTC(DateTime.UtcNow, CurrentClub.TimeZone);
                    lblCurTime.Text      = String.Format(CultureInfo.InvariantCulture, Resources.LocalizedText.LocalizedJoinWithSpace, dtClub.ToShortDateString(), dtClub.ToShortTimeString());
                    lblTZDisclaimer.Text = String.Format(CultureInfo.CurrentCulture, Resources.Club.TimeZoneDisclaimer, CurrentClub.TimeZone.StandardName);

                    bool fIsAdmin = util.GetIntParam(Request, "a", 0) != 0 && (MyFlightbook.Profile.GetUser(Page.User.Identity.Name)).CanManageData;
                    if (fIsAdmin && cm == null)
                    {
                        cm = new ClubMember(CurrentClub.ID, Page.User.Identity.Name, ClubMember.ClubMemberRole.Admin);
                    }
                    bool fIsManager = fIsAdmin || (cm != null && cm.IsManager);
                    lnkManageClub.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "~/Member/ClubManage.aspx/{0}", CurrentClub.ID);
                    mvMain.SetActiveView(cm == null ? vwMainGuest : vwSchedules);
                    mvTop.SetActiveView(cm == null ? vwTopGuest : (fIsManager ? vwTopAdmin : vwTopMember));

                    if (cm == null)
                    {
                        accClub.SelectedIndex = 0;
                        acpMembers.Visible    = acpSchedules.Visible = false;
                    }

                    pnlLeaveGroup.Visible = (cm != null && !cm.IsManager);

                    switch (CurrentClub.Status)
                    {
                    case Club.ClubStatus.Promotional:
                        mvPromoStatus.SetActiveView(vwPromotional);
                        string szTemplate = (Page.User.Identity.Name.CompareOrdinal(Page.User.Identity.Name) == 0) ? Resources.Club.clubStatusTrialOwner : Resources.Club.clubStatusTrial;
                        lblPromo.Text = String.Format(CultureInfo.CurrentCulture, Branding.ReBrand(szTemplate), CurrentClub.ExpirationDate.Value.ToShortDateString());
                        break;

                    case Club.ClubStatus.Expired:
                    case Club.ClubStatus.Inactive:
                        mvPromoStatus.SetActiveView(vwInactive);
                        lblInactive.Text = Branding.ReBrand(CurrentClub.Status == Club.ClubStatus.Inactive ? Resources.Club.errClubInactive : Resources.Club.errClubPromoExpired);
                        break;

                    default:
                        mvPromoStatus.Visible = false;
                        break;
                    }

                    // Initialize from the cookie, if possible.
                    rbScheduleMode.SelectedValue = SchedulePreferences.DefaultScheduleMode.ToString();

                    if (CurrentClub.PrependsScheduleWithOwnerName)
                    {
                        mfbEditAppt1.DefaultTitle = MyFlightbook.Profile.GetUser(Page.User.Identity.Name).UserFullName;
                    }

                    RefreshAircraft();

                    if (cm != null)
                    {
                        gvMembers.DataSource = CurrentClub.Members;
                        gvMembers.DataBind();
                        // Hack - trim the last column if not showing mobiles.  This is fragile.
                        if (CurrentClub.HideMobileNumbers)
                        {
                            gvMembers.Columns[gvMembers.Columns.Count - 1].Visible = false;
                        }
                    }
                }
                catch (MyFlightbookException ex)
                {
                    lblErr.Text = ex.Message;
                }
            }

            // Do this every time - if it's a postback in an update panel, it's a non-issue, but if it's full-page, this keeps things from going away.
            RefreshSummary();
        }
    }