/**
  * Add a reference to the corresponding logbook entry. This creates a personal logbook for this kerbal.
  * */
 public void AddLogRef(LogbookEntry lbentry)
 {
     logbook.Add(lbentry);
     if (logtext.Length > 0)
     {
         logtext.Append("\n");
     }
     logtext.Append(lbentry.ToString());
 }
Esempio n. 2
0
    protected void CopyToInstructor(LogbookEntry le)
    {
        // Now make it look like the CFI's: their username, swap DUAL for CFI time, ensure that PIC time is present.
        le.FlightID = LogbookEntry.idFlightNew;
        string szStudentName = MyFlightbook.Profile.GetUser(le.User).UserFullName;
        List <CustomFlightProperty> lstProps = new List <CustomFlightProperty>(le.CustomProperties);

        lstProps.ForEach(cfp => cfp.FlightID = le.FlightID);

        // Add the student's name as a property
        lstProps.RemoveAll(cfp => cfp.PropTypeID == (int)CustomPropertyType.KnownProperties.IDPropStudentName);
        lstProps.Add(new CustomFlightProperty(new CustomPropertyType(CustomPropertyType.KnownProperties.IDPropStudentName))
        {
            FlightID = le.FlightID, TextValue = szStudentName
        });

        le.Comment = String.IsNullOrEmpty(le.Comment) ? txtComments.Text : String.Format(CultureInfo.CurrentCulture, Resources.SignOff.StudentNameTemplate, le.Comment, txtComments.Text);
        le.User    = CFIProfile.UserName;  // Swap username, of course, but do so AFTER adjusting the comment above (where we had the user's name)
        le.PIC     = le.CFI = Flight.Dual; // Assume you were PIC for the time you were giving instruction.
        le.Dual    = 0.0M;

        // Swap ground instruction given/ground-instruction received
        CustomFlightProperty cfpGIReceived = lstProps.FirstOrDefault(cfp => cfp.PropTypeID == (int)CustomPropertyType.KnownProperties.IDPropGroundInstructionReceived);

        if (cfpGIReceived != null)
        {
            CustomFlightProperty cfpGIGiven = lstProps.FirstOrDefault(cfp => cfp.PropTypeID == (int)CustomPropertyType.KnownProperties.IDPropGroundInstructionGiven);
            if (cfpGIGiven == null)
            {
                cfpGIGiven = new CustomFlightProperty(new CustomPropertyType(CustomPropertyType.KnownProperties.IDPropGroundInstructionGiven));
            }
            cfpGIGiven.DecValue = cfpGIReceived.DecValue;
            cfpGIGiven.FlightID = le.FlightID;
            cfpGIReceived.DeleteProperty();
            lstProps.Remove(cfpGIReceived);
            lstProps.Add(cfpGIGiven);
        }
        le.CustomProperties = lstProps.ToArray();

        // Add this aircraft to the user's profile if needed
        UserAircraft ua = new UserAircraft(CFIProfile.UserName);
        Aircraft     ac = new Aircraft(le.AircraftID);

        if (!ua.CheckAircraftForUser(ac))
        {
            ua.FAddAircraftForUser(ac);
        }

        bool result = le.FCommit(true);

        if (!result || le.LastError != LogbookEntry.ErrorCode.None)
        {
            util.NotifyAdminEvent("Error copying flight to instructor's logbook",
                                  String.Format(CultureInfo.CurrentCulture, "Flight: {0}, CFI: {1}, Student: {2}, ErrorCode: {3}, Error: {4}", le.ToString(), le.User, szStudentName, le.LastError, le.ErrorString),
                                  ProfileRoles.maskSiteAdminOnly);
        }
    }