/* * Методы */ #region public ActualStateRecord() /// <summary> /// Создает воздушное судно без дополнительной информации /// </summary> public ActualStateRecord() { ItemId = -1; _workRegime = FlightRegime.UNK; _workRegimeType = SmartCoreType.FlightRegime; SmartCoreObjectType = SmartCoreType.ActualStateRecord; }
/// <summary> /// Возвращает самую близкую к указанной дате запись, дата которой меньше либо равна указанной дате, /// <br/> а режим совпадает с заданным /// </summary> /// <param name="date"></param> /// <param name="flightRegime"></param> /// <returns>Запись удовлетворяющая заданным параметрам или null</returns> public ActualStateRecord GetLastKnownRecord(DateTime date, IWorkRegime flightRegime) { if (flightRegime == null) { flightRegime = FlightRegime.UNK; } date = date.Date; return(Items.OrderByDescending(r => r.RecordDate.Date) .FirstOrDefault(r => r.RecordDate.Date <= date && r.WorkRegime.Equals(flightRegime))); }
/// <summary> /// Возвращает самую близкую к указанной дате запись, дата которой больше либо равна указанной дате. /// <br/>а режим работы совпадает с заданным /// </summary> /// <param name="date"></param> /// <param name="flightRegime"></param> /// <returns></returns> public ActualStateRecord GetFirstKnownRecord(DateTime date, IWorkRegime flightRegime) { if (flightRegime == null) { flightRegime = FlightRegime.UNK; } date = date.Date; return(Items.OrderBy(r => r.RecordDate.Date) .FirstOrDefault(i => i.RecordDate.Date >= date && i.WorkRegime == flightRegime)); }
/// <summary> /// Возвращает запись по указанной дате и режиму, либо null если запись не была найдена в коллекции /// </summary> /// <param name="date"></param> /// <param name="regime"></param> /// <returns></returns> public ActualStateRecord this[DateTime date, IWorkRegime regime] { get { if (regime == null) { regime = FlightRegime.UNK; } return(Items.FirstOrDefault(t => t.RecordDate.Date == date.Date && t.WorkRegime == regime)); } }
/// <summary> /// Создает воздушное судно без дополнительной информации /// </summary> public ActualStateRecord(ActualStateRecord toCopy) : this() { if (toCopy == null) { return; } ComponentId = toCopy.ComponentId; _onLifelength = new Lifelength(toCopy.OnLifelength); ParentComponent = toCopy.ParentComponent; _recordDate = toCopy.RecordDate.Date; _remarks = toCopy.Remarks; _workRegime = toCopy.WorkRegime; _workRegimeType = toCopy.WorkRegimeType; }
/// <summary> /// Возвращает значение, показывающее является ли значение элемента управления допустимым /// </summary> /// <returns></returns> private bool ValidateData(out string message) { message = ""; if (dateTimePicker1.Value.Date > DateTime.Now.Date) { if (message != "") { message += "\n "; } message += "Performance date must be less than current date."; return(false); } if (dateTimePicker1.Value.Date < _currentComponent.ManufactureDate.Date) { if (message != "") { message += "\n "; } message += "Performance date must be grather than manufacture date."; return(false); } Lifelength perfLifeLength = lifelengthViewer_LastCompliance.Lifelength; if (_currentActualStateRecord.ItemId <= 0) { IWorkRegime workRegime = comboBoxFlightRegime.SelectedItem as IWorkRegime ?? FlightRegime.UNK; ActualStateRecord acr = _currentComponent.ActualStateRecords[dateTimePicker1.Value, workRegime]; if (acr != null) { //Актуальное состояние на заданную дату есть message = $"On a given date {SmartCore.Auxiliary.Convert.GetDateFormat(dateTimePicker1.Value)} have a saved record"; return(false); } acr = _currentComponent.ActualStateRecords.GetLastKnownRecord(dateTimePicker1.Value, workRegime); if (acr != null && perfLifeLength.IsLessByAnyParameter(acr.OnLifelength)) { message = "Performance source must be grather than " + acr.OnLifelength; return(false); } acr = _currentComponent.ActualStateRecords.GetFirstKnownRecord(dateTimePicker1.Value, workRegime); if (acr != null && perfLifeLength.IsGreaterByAnyParameter(acr.OnLifelength)) { message = "Performance source must be less than " + acr.OnLifelength; return(false); } } if (_prevPerfLifelength != null && perfLifeLength.IsLessByAnyParameter(_prevPerfLifelength)) { if (message != "") { message += "\n "; } message += "Performance source must be grather than " + _prevPerfLifelength; return(false); } if (_nextPerfLifelength != null && perfLifeLength.IsGreaterByAnyParameter(_nextPerfLifelength)) { if (message != "") { message += "\n "; } message += "Performance source must be less than " + _nextPerfLifelength; return(false); } return(true); }
private void SetParams() { #region Определение ограничений по ресурсу и дате выполнения if (_currentActualStateRecord.ItemId > 0) { //редактируется старая запись IWorkRegime workRegime = comboBoxFlightRegime.SelectedItem as IWorkRegime ?? FlightRegime.UNK; List <ActualStateRecord> asrs = _currentComponent.ActualStateRecords.Where(r => r.WorkRegime == workRegime) .OrderBy(r => r.RecordDate.Date) .ToList(); int index = asrs.Count > 0 ? asrs.IndexOf(_currentActualStateRecord) : 0; if (index == 0) { //редактируется первая запись о выполнении _prevPerfDate = null; _prevPerfLifelength = null; if (asrs.Count > 1) { //было сделано много записей о выполнении _nextPerfDate = asrs[index + 1].RecordDate.Date; _nextPerfLifelength = asrs[index + 1].OnLifelength; } else { _nextPerfDate = null; _nextPerfLifelength = null; } } else if (index < asrs.Count - 1) { //редактируется запись из середины списка записей о выполнении _prevPerfDate = asrs[index - 1].RecordDate.Date; _prevPerfLifelength = asrs[index - 1].OnLifelength; _nextPerfDate = asrs[index + 1].RecordDate.Date; _nextPerfLifelength = asrs[index + 1].OnLifelength; } else //(index == _currentDirective.PerformanceRecords.Count - 1) { //редактируется последняя запись _prevPerfDate = asrs[index - 1].RecordDate.Date; _prevPerfLifelength = asrs[index - 1].OnLifelength; _nextPerfDate = null; _nextPerfLifelength = null; } } lifelengthViewer_LastCompliance.MinLifelength = _prevPerfLifelength ?? Lifelength.Zero; lifelengthViewer_LastCompliance.MaxLifelength = _nextPerfLifelength ?? GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(_currentComponent); dateTimePicker1.MinDate = _prevPerfDate != null ? (DateTime)_prevPerfDate : DateTimeExtend.GetCASMinDateTime(); dateTimePicker1.MaxDate = _nextPerfDate != null ? (DateTime)_nextPerfDate : DateTime.Today; #endregion }