private void ComboBoxWorkTypeSelectedIndexChanged(object sender, EventArgs e) { ComponentRecordType drt = comboBoxWorkType.SelectedItem as ComponentRecordType; if (drt == null || drt != ComponentRecordType.Preservation) { labelEffectivityDate.Visible = false; dateTimePickerEffDate.Visible = false; lifelengthViewer_FirstPerformance.LeftHeader = "Perform at:"; } else { labelEffectivityDate.Visible = true; dateTimePickerEffDate.Visible = true; lifelengthViewer_FirstPerformance.LeftHeader = "Since Cons. Date:"; } }
public async Task <List <WorkPackageRecordView> > GetWorkPackageRecordsTask(int wpId) { var wp = await _db.WorkPackages .AsNoTracking() .FirstOrDefaultAsync(i => i.Id == wpId); var wpr = await _db.WorkPackageRecords .AsNoTracking() .Where(i => i.WorkPakageId == wpId) .ToListAsync(); var res = wpr.ToBlView(); var wpView = wp.ToBlView(); var adWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.Directive.ItemId).ToList(); if (adWprs.Count > 0) { var directivesIds = adWprs.Select(i => i.DirectivesId); var directives = await _db.Directives .AsNoTracking() .Include(i => i.ATAChapter) .Where(i => directivesIds.Contains(i.Id)) .ToListAsync(); var directiveView = directives.ToBlView(); foreach (var adWpr in adWprs) { adWpr.WorkPakage = wpView; var directive = directiveView.FirstOrDefault(i => i.Id == adWpr.DirectivesId); var firstPerf = ""; if (directive.Threshold.FirstPerformanceSinceNew != null && !directive.Threshold.FirstPerformanceSinceNew.IsNullOrZero()) { firstPerf = "s/n: " + directive.Threshold.FirstPerformanceSinceNew; } if (directive.Threshold.FirstPerformanceSinceEffectiveDate != null && !directive.Threshold.FirstPerformanceSinceEffectiveDate.IsNullOrZero()) { if (firstPerf != "") { firstPerf += " or "; } else { firstPerf = ""; } firstPerf += "s/e.d: " + directive.Threshold.FirstPerformanceSinceEffectiveDate; } if (directive != null) { adWpr.Task = new WprTask() { Parent = directive, AtaChapterView = directive.AtaString, Title = $"{directive.EngineeringOrders} {directive.Title}", Description = directive.Description, FirstPerformance = firstPerf, RepeatInterval = directive.Threshold.RepeatInterval.ToString(), WorkType = directive.WorkType.FullName, NDT = directive.NDTType.ShortName, PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = directive.ManHours, KMH = directive.ManHours * wp.KMH, Cost = directive.Cost, }; } } } var detWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.Component.ItemId).ToList(); if (detWprs.Count > 0) { var componentIds = detWprs.Select(i => i.DirectivesId); var components = await _db.Components .AsNoTracking() .Include(i => i.ATAChapter) .Where(i => componentIds.Contains(i.Id) && !i.IsBaseComponent) .ToListAsync(); var componentViews = components.ToBlView(); foreach (var adWpr in detWprs) { adWpr.WorkPakage = wpView; var component = componentViews.FirstOrDefault(i => i.Id == adWpr.DirectivesId); if (component != null) { adWpr.Task = new WprTask() { Parent = component, AtaChapterView = component.ATAChapterString, Title = component.PartNumber, Description = component.Description, FirstPerformance = component.LifeLimit != null?component.LifeLimit.ToString() : "", RepeatInterval = "", WorkType = "Remove", NDT = "", PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = component.ManHours, KMH = component.ManHours * wp.KMH, Cost = component.Cost, }; } } } var baseDetWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.BaseComponent.ItemId).ToList(); if (baseDetWprs.Count > 0) { var componentIds = baseDetWprs.Select(i => i.DirectivesId); var components = await _db.Components .AsNoTracking() .Include(i => i.ATAChapter) .Where(i => componentIds.Contains(i.Id) && i.IsBaseComponent) .ToListAsync(); var componentViews = components.ToBlView(); foreach (var adWpr in baseDetWprs) { adWpr.WorkPakage = wpView; var component = componentViews.FirstOrDefault(i => i.Id == adWpr.DirectivesId); if (component != null) { adWpr.Task = new WprTask() { Parent = component, AtaChapterView = component.ATAChapterString, Title = component.PartNumber, Description = component.Description, FirstPerformance = component.LifeLimit != null?component.LifeLimit.ToString() : "", RepeatInterval = "", WorkType = "Remove", NDT = "", PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = component.ManHours, KMH = component.ManHours * wp.KMH, Cost = component.Cost, }; } } } var detDirWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.ComponentDirective.ItemId).ToList(); if (detDirWprs.Count > 0) { var componentDirectiveIds = detDirWprs.Select(i => i.DirectivesId); var componentDirectives = await _db.ComponentDirectives .AsNoTracking() .Include(i => i.Component) .Include(i => i.Component.ATAChapter) .Where(i => componentDirectiveIds.Contains(i.Id)) .ToListAsync(); var componentDirectiveViews = componentDirectives.ToBlView(); foreach (var adWpr in detDirWprs) { adWpr.WorkPakage = wpView; var directive = componentDirectiveViews.FirstOrDefault(i => i.Id == adWpr.DirectivesId); var first = ""; if (directive.Threshold.FirstPerformanceSinceNew != null && !directive.Threshold.FirstPerformanceSinceNew.IsNullOrZero()) { first = "s/n: " + directive.Threshold.FirstPerformanceSinceNew; } if (directive != null) { adWpr.Task = new WprTask() { Parent = directive, AtaChapterView = directive.Component.ATAChapterString, Title = "", Description = directive.Remarks, FirstPerformance = first, RepeatInterval = directive.Threshold.RepeatInterval?.ToString(), WorkType = ComponentRecordType.GetItemById(directive.DirectiveType).ToString(), NDT = directive.NDTTypeString, PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = directive.ManHours, KMH = directive.ManHours * wp.KMH, Cost = directive.Cost, }; } } } var maintCheckWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.MaintenanceCheck.ItemId).ToList(); if (maintCheckWprs.Count > 0) { var mcIds = maintCheckWprs.Select(i => i.DirectivesId); var mcs = await _db.MaintenanceChecks .AsNoTracking() .Where(i => mcIds.Contains(i.Id)) .ToListAsync(); var componentDirectiveViews = mcs.ToBlView(); foreach (var adWpr in maintCheckWprs) { adWpr.WorkPakage = wpView; var mc = componentDirectiveViews.FirstOrDefault(i => i.Id == adWpr.DirectivesId); if (mc != null) { adWpr.Task = new WprTask() { Parent = mc, AtaChapterView = "", Title = "", Description = mc.Name + (mc.Schedule ? " Shedule" : " Unshedule"), FirstPerformance = mc.Interval.ToString(), RepeatInterval = "", WorkType = "", NDT = "", PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = mc.ManHours, KMH = mc.ManHours * wp.KMH, Cost = mc.Cost, }; } } } var mpdWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.MaintenanceDirective.ItemId).ToList(); if (mpdWprs.Count > 0) { var mpdIds = mpdWprs.Select(i => i.DirectivesId); var mpds = await _db.MaintenanceDirectives .AsNoTracking() .Include(i => i.ATAChapter) .Where(i => mpdIds.Contains(i.Id)) .ToListAsync(); var componentDirectiveViews = mpds.ToBlView(); foreach (var adWpr in mpdWprs) { adWpr.WorkPakage = wpView; var mpd = componentDirectiveViews.FirstOrDefault(i => i.Id == adWpr.DirectivesId); var first = ""; if (mpd.Threshold.FirstPerformanceSinceNew != null && !mpd.Threshold.FirstPerformanceSinceNew.IsNullOrZero()) { first = "s/n: " + mpd.Threshold.FirstPerformanceSinceNew; } if (mpd.Threshold.FirstPerformanceSinceEffectiveDate != null && !mpd.Threshold.FirstPerformanceSinceEffectiveDate.IsNullOrZero()) { if (first != "") { first += " or "; } else { first = ""; } first += "s/e.d: " + mpd.Threshold.FirstPerformanceSinceEffectiveDate; } if (mpd != null) { adWpr.Task = new WprTask() { Parent = mpd, AtaChapterView = mpd.AtaString, Title = $"{mpd.TaskCardNumber} {mpd.TaskNumberCheck} {mpd.Description}", Description = mpd.Description, FirstPerformance = first, RepeatInterval = mpd.Threshold.RepeatInterval?.ToString(), WorkType = mpd.WorkType.FullName, NDT = mpd.NDTType.ShortName, PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = mpd.ManHours, KMH = mpd.ManHours * wp.KMH, Cost = mpd.Cost, }; } } } var nrjWprs = res.Where(w => w.WorkPackageItemType == SmartCoreType.NonRoutineJob.ItemId).ToList(); if (nrjWprs.Count > 0) { var nrjIds = nrjWprs.Select(i => i.DirectivesId); var nrjs = await _db.NonRoutineJobs .AsNoTracking() .Include(i => i.ATAChapter) .Where(i => nrjIds.Contains(i.Id)) .ToListAsync(); var nrjViews = nrjs.ToBlView(); foreach (var adWpr in nrjWprs) { adWpr.WorkPakage = wpView; var nrj = nrjViews.FirstOrDefault(i => i.Id == adWpr.DirectivesId); if (nrj != null) { adWpr.Task = new WprTask() { Parent = nrj, AtaChapterView = nrj.AtaString, Title = nrj.Title, Description = nrj.Description, FirstPerformance = "", RepeatInterval = "", WorkType = "", NDT = "", PerfDate = wpView.PerfAfter.PerformDate.ToUniversalString(), MH = nrj.ManHours, KMH = nrj.ManHours * wp.KMH, Cost = nrj.Cost, }; } } } return(res.OrderBy(i => i.Task?.Type).ToList()); }
/// <summary> /// Добавляется элемент в таблицу данных /// </summary> /// <param name="reportedComponentобавлямая директива</param> /// <param name="destinationDataSet">Таблица, в которую добавляется элемент</param> private void AddDirectiveToDataset(Component reportedComponent, LandingGearStatusDataSet destinationDataSet) { Lifelength total = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(reportedComponent); string domTtsnTcsn = SmartCore.Auxiliary.Convert.GetDateFormat(reportedComponent.ManufactureDate, "/"); if (domTtsnTcsn != "") { domTtsnTcsn += "\n"; } domTtsnTcsn += total.ToHoursMinutesAndCyclesStrings("FH", "FC"); string position = reportedComponent.Position; string pos = ""; string dwgItem = ""; string pattern = @"\d+"; Regex r = new Regex(pattern); Match m = r.Match(position); if (m.Success) { pos = position.Substring(0, m.Index); dwgItem = position.Substring(m.Index); } ComponentRecordType workType = ComponentRecordType.Unknown; ComponentDirective overhaul = reportedComponent.ComponentDirectives.FirstOrDefault(dd => dd.DirectiveType == ComponentRecordType.Overhaul); Lifelength interval = Lifelength.Null; Lifelength used = Lifelength.Null; Lifelength remain = Lifelength.Null; string lastPerformanceDateString = ""; string lastPerformanceHours = ""; string lastPerformanceCycles = ""; if (overhaul != null) { if (overhaul.LastPerformance != null) { DirectiveRecord lastPerformance = overhaul.LastPerformance; interval = overhaul.Threshold.RepeatInterval; lastPerformanceDateString = SmartCore.Auxiliary.Convert.GetDateFormat(lastPerformance.RecordDate, "/"); lastPerformanceHours = lastPerformance.OnLifelength.ToHoursMinutesFormat("FH"); lastPerformanceCycles = lastPerformance.OnLifelength.Cycles != null && lastPerformance.OnLifelength.Cycles != 0 ? lastPerformance.OnLifelength.Cycles.ToString() : ""; used = total - lastPerformance.OnLifelength; used.Resemble(interval); } else { interval = overhaul.Threshold.FirstPerformanceSinceNew; used = new Lifelength(total); used.Resemble(interval); } workType = overhaul.DirectiveType; remain = new Lifelength(overhaul.Remains); } destinationDataSet.ItemsTable.AddItemsTableRow( dwgItem, reportedComponent.ATAChapter.ToString(), reportedComponent.PartNumber, reportedComponent.SerialNumber, pos, reportedComponent.Description, reportedComponent.MaintenanceControlProcess.ToString(), SmartCore.Auxiliary.Convert.GetDateFormat(reportedComponent.TransferRecords.GetLast().TransferDate, "/"), reportedComponent.LifeLimit.ToHoursMinutesAndCyclesStrings("FH", "FC"), total.ToHoursMinutesAndCyclesStrings("FH", "FC"), reportedComponent.Remains.ToHoursMinutesAndCyclesStrings("FH", "FC"), workType.ToString(), interval.ToHoursMinutesAndCyclesStrings("FH", "FC"), lastPerformanceDateString, lastPerformanceHours, lastPerformanceCycles, used.Days != null ? used.Days.ToString() : "", used.Hours != null ? used.Hours.ToString() : "", used.Cycles != null ? used.Cycles.ToString(): "", used.ToHoursMinutesAndCyclesStrings("FH", "FC"), "", "", "", remain.ToHoursMinutesAndCyclesStrings("FH", "FC"), reportedComponent.Condition.ToString(), reportedComponent.ManHours, reportedComponent.Cost, reportedComponent.Kits.ToString(), "", reportedComponent.Remarks, reportedComponent.Status.ToString(), domTtsnTcsn); }
//#endregion #region public static void Fill(Type type, object value) public static object GetValue(Type type, object value) { //Проверка, является ли переданный тип наследником BaseSmartCoreObject if (type.IsSubclassOf(typeof(AbstractDictionary))) { try { var typeDict = _casEnvironment.GetDictionary(type); return(typeDict == null ? null : typeDict.GetItemById(ToInt32(value))); } catch (Exception ex) { throw ex; } } if (type.IsSubclassOf(typeof(StaticDictionary))) { try { //поиск в типе своиства Items PropertyInfo itemsProp = type.GetProperty("Items"); //поиск у типа конструктора беза параметров ConstructorInfo ci = type.GetConstructor(new Type[0]); //создание экземпляра статического словаря //(при этом будут созданы все его статические элементы, //которые будут доступны через статическое своиство Items) StaticDictionary instance = (StaticDictionary)ci.Invoke(null); //Получение элементов статического своиства Items IEnumerable staticList = (IEnumerable)itemsProp.GetValue(instance, null); int id = ToInt32(value); StaticDictionary res = staticList.Cast <StaticDictionary>().FirstOrDefault(o => o.ItemId == id) ?? staticList.Cast <StaticDictionary>().FirstOrDefault(o => o.ItemId == -1); return(res); } catch (Exception) { return(null); } } if (type.IsEnum) { try { object o = Enum.Parse(type, value.ToString()); return(o); } catch (Exception) { return(null); } } if (type.Name == typeof(Aircraft).Name) { try { var aircraft = _aircraftsCore.GetAircraftById(ToInt32(value)); return(aircraft); } catch (Exception) { return(null); } } if (type.Name == typeof(BaseComponent).Name) { try { BaseComponent bd = _casEnvironment.BaseComponents.GetItemById(ToInt32(value));//TODO(Evgenii Babak): использовать ComponentCore return(bd); } catch (Exception) { return(null); } } if (type.Name == typeof(Hangar).Name) { try { Hangar hangar = _casEnvironment.Hangars.GetItemById(ToInt32(value)); return(hangar); } catch (Exception) { return(null); } } if (type.Name == typeof(Operator).Name) { try { Operator op = _casEnvironment.Operators.GetItemById(ToInt32(value)); return(op); } catch (Exception) { return(null); } } if (type.Name == typeof(Store).Name) { try { Store store = _casEnvironment.Stores.GetItemById(ToInt32(value)); return(store); } catch (Exception) { return(null); } } if (type.Name == typeof(WorkShop).Name) { try { WorkShop workShop = _casEnvironment.WorkShops.GetItemById(ToInt32(value)); return(workShop); } catch (Exception) { return(null); } } Type nullable = Nullable.GetUnderlyingType(type); if (nullable != null) { //TODO:(Evgenii Babak) использовать Nameof() вместо названия типа string typeName = nullable.Name.ToLower(); switch (typeName) { case "int32": return(ToInt32Nullable(value)); case "int16": return(ToInt16Nullable(value)); case "datetime": return(ToDateTimeNullable(value)); case "bool": return(ToBoolNullable(value)); case "boolean": return(ToBoolNullable(value)); case "double": return(ToDoubleNullable(value)); default: return(null); } } else { string typeName = type.Name.ToLower(); switch (typeName) { case "string": return(ToString(value)); case "int32": return(ToInt32(value)); case "int16": return(ToInt16(value)); case "datetime": return(ToDateTime(value)); case "bool": return(ToBool(value)); case "boolean": return(ToBool(value)); case "byte[]": return(ToBytes(value)); case "double": return(ToDouble(value)); case "adtype": return((ADType)ToInt16(value)); case "averageutilization": return(ToAverageUtilization(value)); case "avionicsinventorymarktype": //case "atachapter": // return _casEnvironment.Dictionaries[typeof(AtaChapter)].GetItemById(ToInt32(value)); case "componentdirectivethreshold": return(ToComponentDirectiveThreshold(value)); case "trainingthreshold": return(ToTrainingThreshold(value)); case "componenttype": return(BaseComponentType.GetComponentTypeById(ToInt32(value))); case "componentrecordtype": return(ComponentRecordType.GetItemById(ToInt32(value))); case "detectionphase": return((DetectionPhase)ToInt16(value)); case "directivethreshold": return(ToDirectiveThreshold(value)); case "directivetype": return(DirectiveWorkType.GetItemById(ToInt32(value))); case "highlight": return(Highlight.GetHighlightById(ToInt32(value))); case "componentstatus": return((ComponentStatus)ToInt16(value)); case "lifelength": return(ToLifelength(value)); case "landinggearmarktype": return((LandingGearMarkType)ToInt32(value)); case "maintenancedirectivethreshold": return(ToMaintenanceDirectiveThreshold(value)); case "maintenancecontrolprocess": return(MaintenanceControlProcess.GetItemById(ToInt32(value))); case "powerloss": return((PowerLoss)ToInt16(value)); case "runupcondition": return((RunUpCondition)ToInt16(value)); case "runuptype": return((RunUpType)ToInt16(value)); case "shutdowntype": return((ShutDownType)ToInt16(value)); case "thrustlever": return((ThrustLever)ToInt16(value)); case "timespan": return(ToTime(value)); case "weathercondition": return((WeatherCondition)ToInt16(value)); case "workpackagestatus": return((WorkPackageStatus)ToInt32(value)); default: return(null); } } }