public static IEnumerable <CurrencyStatusItem> AircraftInspectionWarningsForUser(string szUser, IEnumerable <DeadlineCurrency> aircraftDeadlines) { Aircraft[] rgar = MaintenanceLog.AircraftMaintainedByUser(szUser); List <CurrencyStatusItem> arcs = new List <CurrencyStatusItem>(); List <DeadlineCurrency> lstDeadlines = (aircraftDeadlines == null) ? new List <DeadlineCurrency>() : new List <DeadlineCurrency>(aircraftDeadlines); if (rgar != null) { foreach (Aircraft ar in rgar) { MaintenanceRecord mr = ar.Maintenance; AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyAltimeter, mr.NextAltimeter, ar.AircraftID, 30); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyAnnual, mr.NextAnnual, ar.AircraftID, 30); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyELT, mr.NextELT, ar.AircraftID, 30); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyPitot, mr.NextStatic, ar.AircraftID, 30); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyXPonder, mr.NextTransponder, ar.AircraftID, 30); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyVOR, mr.NextVOR, ar.AircraftID, 4); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyRegistration, mr.RegistrationExpiration, ar.AircraftID, 30); arcs.AddRange(DeadlineCurrency.CurrencyForDeadlines(lstDeadlines.FindAll(dc => ar.AircraftID == dc.AircraftID))); } } return(arcs); }
protected void gvDeadlines_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } DeadlineCurrency dc = UserDeadlines[e.RowIndex]; DeadlineCurrency dcOriginal = new DeadlineCurrency(); util.CopyObject(dc, dcOriginal); Controls_mfbTypeInDate typeinNew = (Controls_mfbTypeInDate)gvDeadlines.Rows[e.RowIndex].FindControl("mfbUpdateDeadlineDate"); Controls_mfbDecimalEdit typeinNewHours = (Controls_mfbDecimalEdit)gvDeadlines.Rows[e.RowIndex].FindControl("decNewHours"); if (dc.AircraftHours > 0) { dc.AircraftHours = dc.NewHoursBasedOnHours(typeinNewHours.Value); } else { dc.Expiration = dc.NewDueDateBasedOnDate(typeinNew.Date); } if (dc.IsValid() && dc.FCommit()) { gvDeadlines.EditIndex = -1; ForceRefresh(); DeadlineUpdated?.Invoke(this, new DeadlineEventArgs(dcOriginal, dc)); } }
public static IEnumerable <CurrencyStatusItem> AircraftInspectionWarningsForUser(string szUser, IEnumerable <DeadlineCurrency> aircraftDeadlines) { Aircraft[] rgar = AircraftMaintainedByUser(szUser); List <CurrencyStatusItem> arcs = new List <CurrencyStatusItem>(); List <DeadlineCurrency> lstDeadlines = (aircraftDeadlines == null) ? new List <DeadlineCurrency>() : new List <DeadlineCurrency>(aircraftDeadlines); if (rgar != null) { int maxWindow = (int)Profile.GetUser(szUser).GetPreferenceForKey <Int64>(MFBConstants.keyWindowAircraftMaintenance, MFBConstants.DefaultMaintenanceWindow); foreach (Aircraft ar in rgar) { MaintenanceRecord mr = ar.Maintenance; AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyAltimeter, mr.NextAltimeter, ar.AircraftID, 30, maxWindow); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyAnnual, mr.NextAnnual, ar.AircraftID, 30, maxWindow); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyELT, mr.NextELT, ar.AircraftID, 30, maxWindow); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyPitot, mr.NextStatic, ar.AircraftID, 30, maxWindow); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyXPonder, mr.NextTransponder, ar.AircraftID, 30, maxWindow); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyVOR, mr.NextVOR, ar.AircraftID, 4, maxWindow); AddPendingInspection(arcs, ar.TailNumber + Resources.Aircraft.CurrencyRegistration, mr.RegistrationExpiration, ar.AircraftID, 30, maxWindow); arcs.AddRange(DeadlineCurrency.CurrencyForDeadlines(lstDeadlines.FindAll(dc => ar.AircraftID == dc.AircraftID && (maxWindow < 0 || dc.Expiration.Subtract(DateTime.Now).TotalDays <= maxWindow)))); } } return(arcs); }
protected void gvDeadlines_RowCommand(object sender, CommandEventArgs e) { if (e != null && String.Compare(e.CommandName, "_Delete", StringComparison.OrdinalIgnoreCase) == 0) { int id = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture); DeadlineCurrency dc = UserDeadlines.Find(d => id == d.ID); if (dc != null) { dc.FDelete(); ForceRefresh(); } } }
protected void btnAddDeadline_Click(object sender, EventArgs e) { int regenspan; DeadlineCurrency.RegenUnit ru = rbRegenManual.Checked ? DeadlineCurrency.RegenUnit.None : (ckDeadlineUseHours.Checked ? DeadlineCurrency.RegenUnit.Hours : (DeadlineCurrency.RegenUnit)Enum.Parse(typeof(DeadlineCurrency.RegenUnit), cmbRegenRange.SelectedValue)); switch (ru) { default: case DeadlineCurrency.RegenUnit.None: regenspan = 0; break; case DeadlineCurrency.RegenUnit.Days: case DeadlineCurrency.RegenUnit.CalendarMonths: case DeadlineCurrency.RegenUnit.Hours: regenspan = decRegenInterval.IntValue; break; } decimal aircraftHours = decDueHours.Value; int idAircraft = 0; if (CreateShared) { idAircraft = AircraftID; } else { if (!String.IsNullOrEmpty(cmbDeadlineAircraft.SelectedValue)) { idAircraft = Convert.ToInt32(cmbDeadlineAircraft.SelectedValue, CultureInfo.InvariantCulture); } } DeadlineCurrency dc = new DeadlineCurrency(CreateShared ? null : UserName, txtDeadlineName.Text, mfbDeadlineDate.Date, regenspan, ru, idAircraft, aircraftHours); if (dc.IsValid() && dc.FCommit()) { ForceRefresh(); ResetDeadlineForm(); Refresh(); if (DeadlineAdded != null) { DeadlineAdded(this, new DeadlineEventArgs(null, dc)); } } else { lblErrDeadline.Text = dc.ErrorString; } }
/// <summary> /// Deletes an aircraft from the user's list. Does NOT remove the underlying aircraft. /// </summary> /// <param name="AircraftID">The ID of the aircraft to delete</param> /// <returns>The updated list of aircraft for the user.</returns> public Aircraft[] FDeleteAircraftforUser(int AircraftID) { if (String.IsNullOrEmpty(User)) { throw new MyFlightbookException("No user specified for Deleteaircraft"); } AircraftStats acs = new AircraftStats(User, AircraftID); // if the user has no flights with this aircraft, simply remove it from their list and be done if (acs.UserFlights != 0) { throw new MyFlightbookException(Resources.Aircraft.errAircraftInUse); } else { new DBHelper().DoNonQuery("DELETE FROM useraircraft WHERE userName=?username AND idAircraft=?aircraftID", (comm) => { comm.Parameters.AddWithValue("username", User); comm.Parameters.AddWithValue("aircraftID", AircraftID); } ); InvalidateCache(); } // Delete any deadlines associated with this aircraft foreach (DeadlineCurrency dc in DeadlineCurrency.DeadlinesForUser(User, AircraftID)) { dc.FDelete(); } // And delete any custom currencies associated with the aircraft foreach (CustomCurrency cc in CustomCurrency.CustomCurrenciesForUser(User)) { List <int> ids = new List <int>(cc.AircraftRestriction); if (ids.Contains(AircraftID)) { ids.Remove(AircraftID); cc.AircraftRestriction = ids; cc.FCommit(); } } // we don't actually delete the aircraft; no need to do so, even if it's not used by anybody because // (a) we can't force caches of aircraft lists to be invalid and, // (b) no harm from keeping it - if somebody re-uses the tailnumber, it will re-use the existing flight. return(GetAircraftForUser()); }
protected void gvDeadlines_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } DeadlineCurrency dc = UserDeadlines[e.RowIndex]; DeadlineCurrency dcOriginal = new DeadlineCurrency(); util.CopyObject(dc, dcOriginal); Controls_mfbTypeInDate typeinNew = (Controls_mfbTypeInDate)gvDeadlines.Rows[e.RowIndex].FindControl("mfbUpdateDeadlineDate"); Controls_mfbDecimalEdit typeinNewHours = (Controls_mfbDecimalEdit)gvDeadlines.Rows[e.RowIndex].FindControl("decNewHours"); if (dc.AircraftHours > 0) { dc.AircraftHours = dc.NewHoursBasedOnHours(typeinNewHours.Value); } else { dc.Expiration = dc.NewDueDateBasedOnDate(typeinNew.Date); } if (dc.IsValid() && dc.FCommit()) { gvDeadlines.EditIndex = -1; ForceRefresh(); if (dc.AircraftID > 0) { string szDiff = dc.DifferenceDescription(dcOriginal); if (!String.IsNullOrEmpty(szDiff)) { MaintenanceLog ml = new MaintenanceLog() { AircraftID = dc.AircraftID, ChangeDate = DateTime.Now, User = UserName, Description = szDiff, Comment = string.Empty }; ml.FAddToLog(); } } if (DeadlineUpdated != null) { DeadlineUpdated(this, new DeadlineEventArgs(dcOriginal, dc)); } } }
protected void gvDeadlines_RowDataBound(object sender, GridViewRowEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) { Controls_mfbTypeInDate typeindate = (Controls_mfbTypeInDate)e.Row.FindControl("mfbUpdateDeadlineDate"); Controls_mfbDecimalEdit decEdit = (Controls_mfbDecimalEdit)e.Row.FindControl("decNewHours"); DeadlineCurrency dc = UserDeadlines[e.Row.RowIndex]; if (dc.UsesHours) { decEdit.Value = dc.AircraftHours; } else { typeindate.Date = typeindate.DefaultDate = dc.Expiration.LaterDate(DateTime.Now); } } } }
/// <summary> /// Replaces one aircraft for another for the user. The old aircraft is not migrated if any existing flights use it. /// </summary> /// <param name="acNew">The new aircraft</param> /// <param name="acOld">The old aircraft</param> /// <param name="fMigrateFlights">True to migrate any existing flights. If false, the old flights (and the old aircraft) may remain.</param> public void ReplaceAircraftForUser(Aircraft acNew, Aircraft acOld, bool fMigrateFlights) { if (acNew == null) { throw new ArgumentNullException("acNew"); } if (acOld == null) { throw new ArgumentNullException("acOld"); } if (acNew.AircraftID == acOld.AircraftID) { return; } // Add the new aircraft first FAddAircraftForUser(acNew); // Migrate any flights, if necessary... if (fMigrateFlights) { List <Aircraft> lstAc = new List <Aircraft>(GetAircraftForUser()); // make sure we are populated with both old and new so that UpdateFlightAircraftForUser works. // (This can happen if you have one version of an aircraft and you go to add another version of it; // they won't both be there, but the query used in UpdateFlightAircraftForUser wants them both present. if (!lstAc.Exists(ac => ac.AircraftID == acNew.AircraftID)) { lstAc.Add(acNew); } if (!lstAc.Exists(ac => ac.AircraftID == acOld.AircraftID)) { lstAc.Add(acOld); } CachedAircraft = lstAc.ToArray(); // we'll nullify the cache below. LogbookEntry.UpdateFlightAircraftForUser(this.User, acOld.AircraftID, acNew.AircraftID); // Migrate any custom currencies associated with the aircraft foreach (CustomCurrency cc in CustomCurrency.CustomCurrenciesForUser(User)) { List <int> lst = new List <int>(cc.AircraftRestriction); for (int i = 0; i < lst.Count; i++) { if (lst[i] == acOld.AircraftID) { lst[i] = acNew.AircraftID; cc.AircraftRestriction = lst; cc.FCommit(); break; } } } // And migrate any deadlines associated with the aircraft foreach (DeadlineCurrency dc in DeadlineCurrency.DeadlinesForUser(User, acOld.AircraftID)) { dc.AircraftID = acNew.AircraftID; dc.FCommit(); } try { // Then delete the old aircraft. Ignore any errors FDeleteAircraftforUser(acOld.AircraftID); } catch (MyFlightbookException) { InvalidateCache(); } } }