예제 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(this.User))
        {
            User = Page.User.Identity.Name;
        }

        if (ViewState[szKeyMiniMode] != null)
        {
            MiniMode = (Boolean)ViewState[szKeyMiniMode];
        }

        if (ViewState[szKeyAllowsPaging] != null)
        {
            AllowPaging = Convert.ToBoolean(ViewState[szKeyAllowsPaging], CultureInfo.InvariantCulture);
        }

        // need to do bind to the data every time or else the comments and images (dynamically added) disappear.
        // We also don't want to overuse viewstate - can get quite big quite quickly.
        // So we cache the logbook in the Session and use it on postbacks.
        // always hit the DB on a GET unless host page has already called RefreshData (in which case we have already hit the DB)
        if (!IsPostBack)
        {
            lblAddress.Text    = Pilot.Address;
            pnlAddress.Visible = Pilot.Address.Trim().Length > 0;

            if (!CacheFlushed)
            {
                FlushCache();
            }

            // Customer-facing utility function: if you add "dupesOnly=1" to the URL, we add a custom restriction that limits flights to ONLY flights that look like potential duplicates
            if (util.GetIntParam(Request, "dupesOnly", 0) != 0)
            {
                Restriction.EnumeratedFlights = LogbookEntry.DupeCandidatesForUser(Restriction.UserName);
                FlushCache();
                HasBeenBound = false;
            }

            ckCompactView.Checked   = m_isCompact;
            ckIncludeImages.Checked = m_showImagesInline;
            rblShowInPages.Checked  = gvFlightLogs.AllowPaging;
            rblShowAll.Checked      = !rblShowInPages.Checked;
            ckSelectFlights.Visible = IsViewingOwnFlights;

            decPageSize.IntValue          = gvFlightLogs.PageSize;
            decPageSize.EditBox.MaxLength = 2;

            // Refresh state from params.
            // fq is handled at the host level.
            string szLastSort = util.GetStringParam(Request, "so");
            if (!String.IsNullOrEmpty(szLastSort) && Enum.TryParse <SortDirection>(szLastSort, true, out SortDirection sortDirection))
            {
                LastSortDir = sortDirection;
            }
            string szSortExpr = util.GetStringParam(Request, "se");
            if (!String.IsNullOrEmpty(szSortExpr))
            {
                LastSortExpr = szSortExpr;
            }
            gvFlightLogs.PageIndex = util.GetIntParam(Request, "pg", gvFlightLogs.PageIndex);

            if (!String.IsNullOrEmpty(LastSortExpr) || gvFlightLogs.PageIndex > 0)
            {
                SortGridview(gvFlightLogs, Data as List <LogbookEntryDisplay>);
            }
        }

        if (!HasBeenBound && !String.IsNullOrEmpty(User))
        {
            BindData(Data);
        }

        gvFlightLogs.Columns[FindColumn(gvFlightLogs, Resources.LogbookEntry.FieldCFI)].Visible = Pilot.IsInstructor && !MiniMode;
        gvFlightLogs.Columns[FindColumn(gvFlightLogs, Resources.LogbookEntry.FieldSIC)].Visible = Pilot.TracksSecondInCommandTime && !MiniMode;
    }