/// <summary> /// Initialize the edit form for a new flight (blank fields) or for editing of an existing flight /// </summary> /// <param name="idFlight">-1 for a new flight, otherwise the ID of the flight to load</param> /// <param name="fForceLoad">True to force load (e.g., an admin mode, or CFI editing a user's flight)</param> public void SetUpNewOrEdit(int idFlight, bool fForceLoad = false) { LogbookEntry le = new LogbookEntry() { User = Page.User.Identity.Name }; InitBasicControls(); // Initialize our logbook entry from the db or make it a new entry bool fAdminMode = CurrentUser.CanSupport && (util.GetStringParam(Request, "a").Length > 0); IsAdmin = fForceLoad || fAdminMode; FlightID = idFlight; if (!le.FLoadFromDB(FlightID, Page.User.Identity.Name, LogbookEntryCore.LoadTelemetryOption.LoadAll, IsAdmin)) { // if this isn't found, try again with a new flight (but tell the user of the error) lblError.Text = le.ErrorString; FlightID = (le = new LogbookEntry() { User = Page.User.Identity.Name }).FlightID; } // check for CFI signing mode if (fForceLoad && !le.IsNewFlight) { if (le.User.CompareOrdinal(Page.User.Identity.Name) != 0 && le.CanEditThisFlight(Page.User.Identity.Name)) { pnlPublic.Visible = pnlPictures.Visible = false; FlightUser = le.User; // save the name of the owner of the flight. } else { throw new MyFlightbookException(String.Format(CultureInfo.InvariantCulture, "attempt by {0} to edit non-owned flight (owned by {1}) by non-instructor!", Page.User.Identity.Name, le.User)); } } // Enable Admin Signature fix-up if (!le.IsNewFlight && le.CFISignatureState != LogbookEntryCore.SignatureState.None) { lblSigSavedHash.Text = le.DecryptedFlightHash; lblSigCurrentHash.Text = le.DecryptedCurrentHash; if (le.CFISignatureState == LogbookEntryCore.SignatureState.Invalid) { pnlSigEdits.Visible = true; LogbookEntry leNew = LogbookEntryBase.LogbookEntryFromHash(lblSigCurrentHash.Text); LogbookEntry leSaved = LogbookEntryBase.LogbookEntryFromHash(lblSigSavedHash.Text); rptDiffs.DataSource = leSaved.CompareTo(leNew, CurrentUser.UsesHHMM); rptDiffs.DataBind(); } if (fAdminMode) { LogbookEntryBase.SignatureSanityCheckState sscs = le.AdminSignatureSanityCheckState; pnlAdminFixSignature.Visible = true; lblSigSavedState.Text = le.CFISignatureState.ToString(); lblSigSanityCheck.Text = sscs.ToString(); } } // If the user has entered another flight this session, default to that date rather than today if (Session[keyLastEntryDate] != null && FlightID == LogbookEntryCore.idFlightNew) { le.Date = (DateTime)Session[keyLastEntryDate]; } // see if we have a pending in-progress flight if (FlightID == LogbookEntryCore.idFlightNew && Session[keySessionInProgress] != null) { le = (LogbookEntry)Session[keySessionInProgress]; } Session[keySessionInProgress] = null; // clear it out regardless. UseLastTail = true; // If a repeat or a reverse is requested, then clone and/or reverse it. le = CloneOrReverse(le); // If this is a shared flight, initialize from that. le = SharedFlight(le); InitializeHobbs(le); SetUpAircraftForFlight(le, false); InitFormFromLogbookEntry(le); bool fCanDoVideo = CanDoVideo(Page.User.Identity.Name); mfbMFUFlightImages.IncludeVideos = fCanDoVideo; mfbVideoEntry1.CanAddVideos = fCanDoVideo; mfbVideoEntry1.FlightID = le.FlightID; lblPixForFlight.Text = fCanDoVideo ? Resources.LogbookEntry.HeaderImagesVideosForFlight : Resources.LogbookEntry.HeaderImagesForFlight; FinalizeSetupForFlight(le); popmenuPending.Visible = le.IsNewFlight; mfbDate.Focus(); }