///<summary> /// Конструктор принимающий в качестве параметров уже готовую запись ///</summary> ///<param name="currentComponentеталь, которой принадлежит запись</param> ///<param name="currentRecord">Сама запись</param> public ComponentChangeLLPCategoryRecordForm(Component currentComponent, ComponentLLPCategoryChangeRecord currentRecord) : this() { _currentComponent = currentComponent; _currentRecord = currentRecord; UpdateInformation(); }
public ComponentLLPCategoryChangeRecordView(ComponentLLPCategoryChangeRecord source) { if (source == null) { return; } Id = source.Id; ParentId = source.ParentId; RecordDate = source.RecordDate.Value; OnLifeLength = Lifelength.ConvertFromByteArray(source.OnLifeLengthByte); }
public void SmartCoreFileTest_DetailLLPCategoryChangeRecord() { var enviroment = GetEnviroment(); var detailLLPCategoryChangeRecord = new ComponentLLPCategoryChangeRecord { AttachedFile = new AttachedFile { FileName = "AttachedFile.test" }, }; enviroment.NewKeeper.Save(detailLLPCategoryChangeRecord); Assert.IsTrue(detailLLPCategoryChangeRecord.ItemId > 0, "ItemId должен быть больше 0"); var forCheck = enviroment.NewLoader.GetObject <ComponentLLPCategoryChangeRecordDTO, ComponentLLPCategoryChangeRecord>(new Filter("ItemId", detailLLPCategoryChangeRecord.ItemId), true); enviroment.NewKeeper.Delete(detailLLPCategoryChangeRecord); Assert.IsTrue(forCheck != null, "значение не должно быть null"); Assert.AreEqual(forCheck.Files.Count, 1, "Кол-во файлов должно быть 1"); Assert.IsTrue(forCheck.AttachedFile != null); Assert.AreEqual(forCheck.AttachedFile.FileName, "AttachedFile.test"); }
protected override void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { backgroundWorker.ReportProgress(50); try { Invoke(new Action(() => listViewCompliance.Items.Clear())); } catch (Exception) { } if (_currentComponent == null) { e.Cancel = true; return; } var parentAircraft = GlobalObjects.AircraftsCore.GetParentAircraft(_currentComponent); var lastRecords = new List <AbstractRecord>(); var nextPerformances = new List <NextPerformance>(); var allWorkPackagesIncludedTask = new CommonCollection <WorkPackage>(); var openPubWorkPackagesIncludedTask = new CommonCollection <WorkPackage>(); var closedWorkPackages = new CommonCollection <WorkPackage>(); var taskThatIncludeInWorkPackage = new List <IDirective>(); lastRecords.AddRange(_currentComponent.TransferRecords.ToArray()); lastRecords.AddRange(_currentComponent.ChangeLLPCategoryRecords.ToArray()); lastRecords.AddRange(_currentComponent.ActualStateRecords.ToArray()); //Объекты для в котороые будет извлекаться информация //из записеи о перемещении var lastDestination = ""; //прогнозируемый ресурс //если известна родительская деталь данной директивы, //то ее текущая наработка и средняя утилизация //используются в качестве ресурсов прогноза //для расчета всех просроченных выполнений var forecastData = new ForecastData(DateTime.Now, GlobalObjects.AverageUtilizationCore.GetAverageUtillization(_currentComponent), GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(_currentComponent)); foreach (var directive in _currentComponent.ComponentDirectives) { if (directive.IsAffect().GetValueOrDefault(true)) { //расчет след. выполнений директивы. //если известен ресурс прогноза, то будут расчитаны все просрочнные выполнения //если неизвестне, то только первое //GlobalObjects.PerformanceCalculator.GetNextPerformance(directive, forecastData); nextPerformances.AddRange(directive.NextPerformances); lastRecords.AddRange(directive.PerformanceRecords.ToArray()); if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } taskThatIncludeInWorkPackage.Add(directive); } else { var bindedItems = GlobalObjects.BindedItemsCore.GetBindedItemsFor(parentAircraft.ItemId, directive); foreach (var bindedItem in bindedItems) { if (bindedItem is MaintenanceDirective) { var mpd = (MaintenanceDirective)bindedItem; //прогнозируемый ресурс //если известна родительская деталь данной директивы, //то ее текущая наработка и средняя утилизация //используются в качестве ресурсов прогноза //для расчета всех просроченных выполнений //расчет след. выполнений директивы. //если известен ресурс прогноза, то будут расчитаны все просрочнные выполнения //если неизвестне, то только первое GlobalObjects.PerformanceCalculator.GetNextPerformance(mpd, forecastData); nextPerformances.AddRange(mpd.NextPerformances); lastRecords.AddRange(mpd.PerformanceRecords.ToArray()); taskThatIncludeInWorkPackage.Add(mpd); } } } } //загрузка рабочих пакетов для определения //перекрытых ими выполнений задач if (_openPubWorkPackages == null) { _openPubWorkPackages = new CommonCollection <WorkPackage>(); } _openPubWorkPackages.Clear(); //загрузка рабочих пакетов для определения _openPubWorkPackages.AddRange(GlobalObjects.WorkPackageCore.GetWorkPackagesLite(parentAircraft, WorkPackageStatus.Opened)); _openPubWorkPackages.AddRange(GlobalObjects.WorkPackageCore.GetWorkPackagesLite(parentAircraft, WorkPackageStatus.Published)); allWorkPackagesIncludedTask.AddRange(GlobalObjects.WorkPackageCore.GetWorkPackagesLite(parentAircraft, WorkPackageStatus.All, taskThatIncludeInWorkPackage)); #region Добавление в список просроченных выполнений //и сравнение их с открытыми и опубликованными рабочими пакетами openPubWorkPackagesIncludedTask.AddRange( allWorkPackagesIncludedTask.Where(wp => wp.Status == WorkPackageStatus.Opened || wp.Status == WorkPackageStatus.Published)); //сбор всех записей рабочих пакетов для удобства фильтрации var openPubWpRecords = openPubWorkPackagesIncludedTask.SelectMany(wp => wp.WorkPakageRecords).ToList(); //LINQ запрос для сортировки записей по дате var sortNextRecords = (from record in nextPerformances orderby GetDate(record) descending select record).ToList(); for (int i = 0; i < sortNextRecords.Count; i++) { if (backgroundWorker.CancellationPending) { allWorkPackagesIncludedTask.Clear(); openPubWorkPackagesIncludedTask.Clear(); closedWorkPackages.Clear(); e.Cancel = true; return; } //поиск записи в рабочих пакетах по данному чеку //чей номер группы выполнения (по записи) совпадает с расчитанным var parentDirective = sortNextRecords[i].Parent; //номер выполнения int parentCountPerf; if (parentDirective.LastPerformance != null) { parentCountPerf = parentDirective.LastPerformance.PerformanceNum <= 0 ? 1 : parentDirective.LastPerformance.PerformanceNum; } else { parentCountPerf = 0; } parentCountPerf += parentDirective.NextPerformances.IndexOf(sortNextRecords[i]); parentCountPerf += 1; var wpr = openPubWpRecords.FirstOrDefault(r => r.PerformanceNumFromStart == parentCountPerf && r.WorkPackageItemType == parentDirective.SmartCoreObjectType.ItemId && r.DirectiveId == parentDirective.ItemId); if (wpr != null) { var wp = openPubWorkPackagesIncludedTask.GetItemById(wpr.WorkPakageId); //запись о выполнении блокируется найденым пакетом sortNextRecords[i].BlockedByPackage = wp; //последующие записи о выполнении так же должны быть заблокированы for (int j = i - 1; j >= 0; j--) { //блокировать нужно все рабочие записи, или до первой записи, //заблокированной другим рабочим пакетом if (sortNextRecords[j].BlockedByPackage != null || sortNextRecords[j].Condition != ConditionState.Overdue) { break; } if (sortNextRecords[j].Parent == parentDirective) { sortNextRecords[j].BlockedByPackage = wp; Invoke(new Action <int, Color>(SetItemColor), j, Color.FromArgb(Highlight.GrayLight.Color)); } } } Invoke(new Action <NextPerformance>(AddListViewItem), sortNextRecords[i]); } #endregion #region Добавление в список записей о произведенных выполнениях //и сравнение их с закрытыми рабочими пакетами closedWorkPackages.AddRange(allWorkPackagesIncludedTask.Where(wp => wp.Status == WorkPackageStatus.Closed)); //LINQ запрос для сортировки записей по дате var sortLastRecords = (from record in lastRecords orderby record.RecordDate ascending select record).ToList(); var items = new List <KeyValuePair <AbstractRecord, string[]> >(); for (int i = 0; i < sortLastRecords.Count; i++) { if (backgroundWorker.CancellationPending) { allWorkPackagesIncludedTask.Clear(); openPubWorkPackagesIncludedTask.Clear(); closedWorkPackages.Clear(); e.Cancel = true; return; } string[] subs; if (sortLastRecords[i] is DirectiveRecord) { var directiveRecord = (DirectiveRecord)sortLastRecords[i]; subs = new[] { directiveRecord.WorkType, UsefulMethods.NormalizeDate(directiveRecord.RecordDate), directiveRecord.OnLifelength != null ? directiveRecord.OnLifelength.ToString() : "", "", "", directiveRecord.Remarks }; } else if (sortLastRecords[i] is TransferRecord) { TransferRecord transferRecord = (TransferRecord)sortLastRecords[i]; string currentDestination, destinationObject; DestinationHelper.GetDestination(transferRecord, out currentDestination, out destinationObject); subs = new[] { lastDestination != "" ? "Transfered " + destinationObject + " from " + lastDestination + " to " + currentDestination : "Transfered " + destinationObject + " to " + currentDestination, UsefulMethods.NormalizeDate(transferRecord.TransferDate), transferRecord.OnLifelength.ToString(), "", "", transferRecord.Remarks, }; lastDestination = currentDestination; } else if (sortLastRecords[i] is ComponentLLPCategoryChangeRecord) { ComponentLLPCategoryChangeRecord llpRecord = (ComponentLLPCategoryChangeRecord)sortLastRecords[i]; LLPLifeLimitCategory toCategory = llpRecord.ToCategory; subs = new[] { "Changed to " + toCategory, UsefulMethods.NormalizeDate(llpRecord.RecordDate), llpRecord.OnLifelength.ToString(), "", "", llpRecord.Remarks, }; } else if (sortLastRecords[i] is ActualStateRecord) { ActualStateRecord actualStateRecord = (ActualStateRecord)sortLastRecords[i]; subs = new[] { "Actual state:", UsefulMethods.NormalizeDate(actualStateRecord.RecordDate.Date), actualStateRecord.OnLifelength != null ? actualStateRecord.OnLifelength.ToString() : "", "", "", actualStateRecord.Remarks, }; } else { subs = new[] { "Unknown record ", UsefulMethods.NormalizeDate(sortLastRecords[i].RecordDate), sortLastRecords[i].OnLifelength.ToString(), "", "", sortLastRecords[i].Remarks, }; } items.Add(new KeyValuePair <AbstractRecord, string[]>(sortLastRecords[i], subs)); } #endregion for (int i = items.Count - 1; i >= 0; i--) { WorkPackage workPackage = null; if (items[i].Key is AbstractPerformanceRecord) { var apr = items[i].Key as AbstractPerformanceRecord; workPackage = closedWorkPackages.FirstOrDefault(wp => wp.ItemId == apr.DirectivePackageId); } Invoke(new Action <AbstractRecord, string[], WorkPackage>(AddListViewItem), items[i].Key, items[i].Value, workPackage); } allWorkPackagesIncludedTask.Clear(); openPubWorkPackagesIncludedTask.Clear(); closedWorkPackages.Clear(); backgroundWorker.ReportProgress(100); }
private void ButtonDeleteClick(object sender, EventArgs e) { if (listViewCompliance.SelectedItems.Count == 0) { return; } if (listViewCompliance.SelectedItems[0].Tag is DirectiveRecord) { DirectiveRecord record = (DirectiveRecord)listViewCompliance.SelectedItems[0].Tag; if (record.DirectivePackage != null) { MessageBox.Show("Perform of the task:" + listViewCompliance.SelectedItems[0].Text + "\nadded by Work Package:" + "\n" + record.DirectivePackage.Title + "\nTo remove a performance of task, you need to exclude task from this work package," + "\nor delete the work package ", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } switch (MessageBox.Show(@"Delete this compliance " + record.RecordType + " ?", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)) { case DialogResult.Yes: GlobalObjects.PerformanceCore.Delete(record); InvokeComplianceAdded(null); break; case DialogResult.No: break; } } else if (listViewCompliance.SelectedItems[0].Tag is ActualStateRecord) { ActualStateRecord record = (ActualStateRecord)listViewCompliance.SelectedItems[0].Tag; switch (MessageBox.Show(@"Delete this actual state record ?", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)) { case DialogResult.Yes: GlobalObjects.ComponentCore.DeleteActualStateRecord(record); InvokeComplianceAdded(null); break; case DialogResult.No: break; } } else if (listViewCompliance.SelectedItems[0].Tag is ComponentLLPCategoryChangeRecord) { ComponentLLPCategoryChangeRecord record = (ComponentLLPCategoryChangeRecord)listViewCompliance.SelectedItems[0].Tag; if (record.ParentComponent == null) { record.ParentComponent = _currentComponent; } switch (MessageBox.Show(@"Delete this LLP category change record ?", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)) { case DialogResult.Yes: GlobalObjects.ComponentCore.DeleteLLPCategoryChangeRecord(record); InvokeComplianceAdded(null); break; case DialogResult.No: break; } } }