protected override void ApplyThreshold(IThreshold threshold) { if (threshold as ComponentDirectiveThreshold == null) { MessageBox.Show( "тип переданного порогового значения не соответстует типу порогового значения данного ЭУ", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ComponentDirectiveThreshold detDirThresh = threshold as ComponentDirectiveThreshold; lifelengthViewer_FirstPerformance.Lifelength = detDirThresh.FirstPerformanceSinceNew; lifelengthViewer_FirstNotify.Lifelength = detDirThresh.FirstNotification; lifelengthViewerRptInterval.Lifelength = detDirThresh.RepeatInterval; lifelengthViewerRptNotify.Lifelength = detDirThresh.RepeatNotification; lifelengthViewerWarranty.Lifelength = detDirThresh.Warranty; lifelengthViewerWarrantyNotify.Lifelength = detDirThresh.WarrantyNotification; if (detDirThresh.FirstPerformanceConditionType == ThresholdConditionType.WhicheverFirst) { radio_WhicheverFirst.Checked = true; } else { radio_WhicheverLater.Checked = true; } }
public void ApplyChanges() { var manHours = ConvertDoubleValue(textBoxManHours.Text); var cost = ConvertDoubleValue(textBoxCost.Text); _currentComponentDirective.DirectiveTypeId = ((ComponentRecordType)comboBoxWorkType.SelectedItem).ItemId; _currentComponentDirective.ManHours = manHours; _currentComponentDirective.Cost = cost; _currentComponentDirective.IsClosed = IsClosed; _currentComponentDirective.IsExpiry = IsExpiry; _currentComponentDirective.KitRequired = textBoxKitRequired.Text; _currentComponentDirective.Remarks = textBoxRemarks.Text; _currentComponentDirective.HiddenRemarks = textBoxHiddenRemarks.Text; _currentComponentDirective.ZoneArea = textBoxZoneArea.Text; _currentComponentDirective.AccessDirective = textBoxAcess.Text; _currentComponentDirective.AAM = textBoxAAM.Text; _currentComponentDirective.CMM = textBoxCMM.Text; _currentComponentDirective.ExpiryDate = dateTimePickerExpiryDate.Value; _currentComponentDirective.MPDTaskType = ((MaintenanceDirectiveTaskType)comboBoxMpdTaskType.SelectedItem); _currentComponentDirective.NDTType = comboBoxNdt.SelectedItem as NDTType; var threshold = new ComponentDirectiveThreshold(); if (_currentComponentDirective.DirectiveTypeId == ComponentRecordType.Preservation.ItemId) { threshold.EffectiveDate = dateTimePickerEffDate.Value; threshold.FirstPerformanceSinceNew.Reset(); threshold.FirstPerformanceSinceEffectiveDate = lifelengthViewer_FirstPerformance.Lifelength; } else { threshold.EffectiveDate = new DateTime(1950, 1, 1); threshold.FirstPerformanceSinceNew = lifelengthViewer_FirstPerformance.Lifelength; threshold.FirstPerformanceSinceEffectiveDate.Reset(); } threshold.FirstNotification = lifelengthViewer_FirstNotify.Lifelength; threshold.RepeatInterval = lifelengthViewerRptInterval.Lifelength; threshold.RepeatNotification = lifelengthViewerRptNotify.Lifelength; threshold.Warranty = lifelengthViewerWarranty.Lifelength; threshold.WarrantyNotification = lifelengthViewerWarrantyNotify.Lifelength; _currentComponentDirective.ExpiryRemainNotify = lifelengthViewerExpiryRemain.Lifelength; threshold.FirstPerformanceConditionType = radio_WhicheverFirst.Checked ? ThresholdConditionType.WhicheverFirst : ThresholdConditionType.WhicheverLater; if (fileControl.GetChangeStatus()) { fileControl.ApplyChanges(); _currentComponentDirective.FaaFormFile = fileControl.AttachedFile; } if (_currentComponentDirective.Threshold.ToString() != threshold.ToString()) { _currentComponentDirective.Threshold = threshold; } }
public void ApplyChanges() { var manHours = ConvertDoubleValue(textBoxManHours.Text); var cost = ConvertDoubleValue(textBoxCost.Text); _currentComponentDirective.DirectiveType = (ComponentRecordType)comboBoxWorkType.SelectedItem; _currentComponentDirective.ManHours = manHours; _currentComponentDirective.Cost = cost; _currentComponentDirective.KitRequired = textBoxKitRequired.Text; _currentComponentDirective.Remarks = textBoxRemarks.Text; _currentComponentDirective.HiddenRemarks = textBoxHiddenRemarks.Text; _currentComponentDirective.MPDTaskType = ((MaintenanceDirectiveTaskType)comboBoxMpdTaskType.SelectedItem); var md = lookupComboboxMaintenanceDirective.SelectedItem as MaintenanceDirective; if (md != null) { _currentComponentDirective.MaintenanceDirective = md; } var threshold = new ComponentDirectiveThreshold(); if (_currentComponentDirective.DirectiveType == ComponentRecordType.Preservation) { threshold.EffectiveDate = dateTimePickerEffDate.Value; threshold.FirstPerformanceSinceNew.Reset(); threshold.FirstPerformanceSinceEffectiveDate = lifelengthViewer_FirstPerformance.Lifelength; } else { threshold.EffectiveDate = DateTimeExtend.GetCASMinDateTime(); threshold.FirstPerformanceSinceNew = lifelengthViewer_FirstPerformance.Lifelength; threshold.FirstPerformanceSinceEffectiveDate.Reset(); } threshold.FirstNotification = lifelengthViewer_FirstNotify.Lifelength; threshold.RepeatInterval = lifelengthViewerRptInterval.Lifelength; threshold.RepeatNotification = lifelengthViewerRptNotify.Lifelength; threshold.Warranty = lifelengthViewerWarranty.Lifelength; threshold.WarrantyNotification = lifelengthViewerWarrantyNotify.Lifelength; threshold.FirstPerformanceConditionType = radio_WhicheverFirst.Checked ? ThresholdConditionType.WhicheverFirst : ThresholdConditionType.WhicheverLater; if (_currentComponentDirective.Threshold == null || _currentComponentDirective.Threshold.ToString() != threshold.ToString()) { _currentComponentDirective.Threshold = threshold; } if (fileControl.GetChangeStatus() || fileControl.AttachedFile != null) { fileControl.ApplyChanges(); _currentComponentDirective.FaaFormFile = fileControl.AttachedFile; } }
/// <summary> /// Создает воздушное судно без дополнительной информации /// </summary> public ComponentDirective(TemplateComponentDirective templateComponentDirective) : this() { ManHours = templateComponentDirective.ManHours; Cost = templateComponentDirective.Cost; DirectiveType = templateComponentDirective.DirectiveType; _threshold = templateComponentDirective.Threshold; Highlight = Highlight.White; NDTType = templateComponentDirective.NDTType; }
/// <summary> /// Создает воздушное судно без дополнительной информации /// </summary> public ComponentDirective(ComponentDirective toCopy) : this() { if (toCopy == null) { return; } Cost = toCopy.Cost; ComponentId = toCopy.ComponentId; DirectiveTypeId = toCopy.DirectiveTypeId; FaaFormFileId = toCopy.FaaFormFileId; HiddenRemarks = toCopy.HiddenRemarks; Highlight = toCopy.Highlight; IsClosed = toCopy.IsClosed; KitRequired = toCopy.KitRequired; ManHours = toCopy.ManHours; MPDTaskType = toCopy.MPDTaskType; ParentComponent = toCopy.ParentComponent; Remarks = toCopy.Remarks; _threshold = toCopy.Threshold; FaaFormFile = toCopy.FaaFormFile; if (_performanceRecords == null) { _performanceRecords = new BaseRecordCollection <DirectiveRecord>(); } _performanceRecords.Clear(); foreach (DirectiveRecord directiveRecord in toCopy.PerformanceRecords) { _performanceRecords.Add(new DirectiveRecord(directiveRecord) { Parent = this, ParentId = ItemId }); } if (Kits == null) { Kits = new CommonCollection <AccessoryRequired>(); } Kits.Clear(); foreach (AccessoryRequired kit in toCopy.Kits) { Kits.Add(new AccessoryRequired(kit) { ParentObject = this, ParentId = ItemId }); } }
/// <summary> /// Считывает все контролы и формирует один Threshold /// </summary> protected override IThreshold GetThreshold() { ComponentDirectiveThreshold threshold = new ComponentDirectiveThreshold(); threshold.FirstPerformanceSinceNew = lifelengthViewer_FirstPerformance.Lifelength; threshold.FirstNotification = lifelengthViewer_FirstNotify.Lifelength; threshold.RepeatInterval = lifelengthViewerRptInterval.Lifelength; threshold.RepeatNotification = lifelengthViewerRptNotify.Lifelength; threshold.Warranty = lifelengthViewerWarranty.Lifelength; threshold.WarrantyNotification = lifelengthViewerWarrantyNotify.Lifelength; threshold.FirstPerformanceConditionType = radio_WhicheverFirst.Checked ? ThresholdConditionType.WhicheverFirst : ThresholdConditionType.WhicheverLater; return(threshold); }
private void ButtonAddClick(object sender, EventArgs e) { if (listViewTasksForSelect.SelectedItems.Count == 0) { return; } if (_maintenanceDirective.IsFirst == null) { _maintenanceDirective.NormalizeItemRelations(); comboBoxRelationType.SelectedValue = ItemRelationHelper.ConvertBLItemRelationToUIITem(_maintenanceDirective.WorkItemsRelationType, false); } //коллекция элементов которые нужно добавить в список, содержащий все связные задачи var itemsToInsert = new CommonCollection <BaseEntityObject>(); //Список выбранных задач по компонентам для привязки var selectedDirectives = listViewTasksForSelect.SelectedItems.OfType <ComponentDirective>().ToList(); //Коллекция выбранных компонентов для привязки var selectedComponents = new ComponentCollection(listViewTasksForSelect.SelectedItems.OfType <Component>()); if (selectedComponents.Count == 0 && selectedDirectives.Count == 0) { return; } //список уже призязанных задач по компонетам var bindedDirectives = listViewBindedTasks.SelectedItems.OfType <ComponentDirective>().ToList(); //Объединенный список выбранных и привязанных компонентов var concatenatedDirectives = selectedDirectives.Concat(bindedDirectives); foreach (ComponentDirective dd in concatenatedDirectives) { if (concatenatedDirectives.Count(d => d.ComponentId == dd.ComponentId) > 1) { //проверка, не выбраны ли 2 или более задач по одному компоненту для привязки //т.к. MPD Item может быть привязан только к одной задаче каждого выбранного компонента string parentComponent; if (dd.ParentComponent != null) { parentComponent = dd.ParentComponent.SerialNumber; } else { parentComponent = "Component ID: " + dd.ComponentId; } MessageBox.Show("the MPD Item can not be bound to two or more tasks of a one component:" + "\n" + parentComponent, (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { var singleItemRelation = dd.ItemRelations.SingleOrDefault(); if (singleItemRelation != null && !CheckThatItemHaveRelationsOnlyWithProvidedItem(dd.IsFirst.HasValue && dd.IsFirst.Value, singleItemRelation, _maintenanceDirective.ItemId, SmartCoreType.MaintenanceDirective.ItemId)) { //Проверка не имеет ли выбранная задача по компоненту привязки к другой задаче string parentComponent; if (dd.ParentComponent != null) { parentComponent = dd.ParentComponent.SerialNumber; } else { parentComponent = "Component ID: " + dd.ComponentId; } MessageBox.Show("You can not select a task: " + "\n" + parentComponent + " " + dd.DirectiveType + "\n" + "because task already has a binding", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } catch (InvalidOperationException) { ItemRelationHelper.ShowDialogIfItemLinksCountMoreThanOne($"Component {dd.PartNumber}", dd.ItemRelations.Count); } catch (Exception ex) { Program.Provider.Logger.Log(ex); } } //Удаление из коллекции выбранных компонентов тех компонентов, //задачи по которым содержатся в коллекции selectedDirectives foreach (ComponentDirective directive in selectedDirectives) { selectedComponents.RemoveById(directive.ComponentId); } //Производится привязка выбранных задач по компонентам к выполнению данного MPD foreach (ComponentDirective dd in selectedDirectives.Where(d => d.ItemRelations.Count == 0)) { try { //TODO:(Evgenii Babak) проверить использования свойств dd.MPDTaskType = _maintenanceDirective.WorkType; dd.FaaFormFile = _maintenanceDirective.TaskCardNumberFile; dd.FaaFormFileId = _maintenanceDirective.TaskCardNumberFile != null ? _maintenanceDirective.TaskCardNumberFile.ItemId : -1; AddComponentAndDirectiveToBindedItemsCollections(dd.ParentComponent, dd, itemsToInsert, _bindedItems, _newBindedItems); //Удаление задачи по компоненту из элемента управления содержащего список всех задач listViewTasksForSelect.RemoveItem(dd); } catch (Exception ex) { Program.Provider.Logger.Log("Error while save bind task record", ex); } } //Производится привязка выбранных компонентов к выполнению данного MPD //В результате предыдущих манипуляций в коллекции выбранных компонентов //должны остаться компоненты у которых либо нет задач, либо не одна не была выбрана foreach (Component selectedComponent in selectedComponents) { if (selectedComponent.ComponentDirectives.Count == 0) { //Выбранный компонент не имеет задач. //Для привязки необходимо создать задачу if (MessageBox.Show("Component:" + "\n" + selectedComponent + "\n" + "has no directives!" + "\n" + "\n" + "Create and save directive for this MPD Item?", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { continue; } } else if (selectedComponent.ComponentDirectives.All(dd => dd.ItemRelations.Any(i => !CheckThatItemHaveRelationsOnlyWithProvidedItem(dd.IsFirst.HasValue && dd.IsFirst.Value, i, _maintenanceDirective.ItemId, SmartCoreType.MaintenanceDirective.ItemId)))) { //Выбранный компонент имеет задачи //Но все они привязаны к другим задачам if (MessageBox.Show("Component:" + "\n" + selectedComponent + "\n" + "has directives, but they are bound to other tasks" + "\n" + "\n" + "Create and save directive for this MPD Item?", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { continue; } } else if (selectedComponent.ComponentDirectives.Count > 0) { //Выбранный компонент имеет задачи //Но ни одна из его задач не была выбрана для привязки //Необходимо задать вопрос: создать ли овую задачу для привязки //или пользователь должен быбрать задачу для привязки сам из имеющихся задач по компоненту if (MessageBox.Show("Component:" + "\n" + selectedComponent + "\n" + "has a tasks, but none of them is selected for binding!" + "\n" + "\n" + "Create and save directive for this MPD Item, or You choose task to bind yourself" + "\n" + "\n" + "Yes - Create and Save directive" + "\n" + "No - You choose task to bind yourself", (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { continue; } } try { var neComponentDirective = new ComponentDirective(); neComponentDirective.DirectiveType = (ComponentRecordType)ComponentRecordType.Items.GetByShortName(_maintenanceDirective.WorkType.ShortName); neComponentDirective.ManHours = _maintenanceDirective.ManHours; neComponentDirective.Cost = _maintenanceDirective.Cost; neComponentDirective.Kits.Clear(); neComponentDirective.Kits.AddRange(_maintenanceDirective.Kits.ToArray()); neComponentDirective.Remarks = _maintenanceDirective.Remarks; neComponentDirective.HiddenRemarks = _maintenanceDirective.HiddenRemarks; neComponentDirective.MPDTaskType = _maintenanceDirective.WorkType; neComponentDirective.FaaFormFile = _maintenanceDirective.TaskCardNumberFile; neComponentDirective.FaaFormFileId = _maintenanceDirective.TaskCardNumberFile != null ? _maintenanceDirective.TaskCardNumberFile.ItemId : -1; neComponentDirective.ComponentId = selectedComponent.ItemId; neComponentDirective.ParentComponent = selectedComponent; MaintenanceDirectiveThreshold mdt = _maintenanceDirective.Threshold; ComponentDirectiveThreshold ddt = neComponentDirective.Threshold; ddt.FirstPerformanceSinceNew = mdt.FirstPerformanceSinceNew; ddt.FirstNotification = mdt.FirstNotification; ddt.RepeatInterval = mdt.RepeatInterval; ddt.RepeatNotification = mdt.RepeatNotification; ddt.FirstPerformanceConditionType = mdt.FirstPerformanceConditionType; AddComponentAndDirectiveToBindedItemsCollections(selectedComponent, neComponentDirective, itemsToInsert, _bindedItems, _newBindedItems); } catch (Exception ex) { Program.Provider.Logger.Log("Error while save bind task record", ex); } } listViewBindedTasks.InsertItems(itemsToInsert); }
/// <summary> /// Возвращает значение, показывающее были ли изменения в данном элементе управления /// </summary> public bool GetChangeStatus() { var manHours = ConvertDoubleValue(textBoxManHours.Text); var cost = ConvertDoubleValue(textBoxCost.Text); ComponentDirectiveThreshold threshold = new ComponentDirectiveThreshold(); if (comboBoxWorkType.SelectedItem as ComponentRecordType == ComponentRecordType.Preservation) { threshold.EffectiveDate = dateTimePickerEffDate.Value; threshold.FirstPerformanceSinceEffectiveDate = lifelengthViewer_FirstPerformance.Lifelength; } else { threshold.EffectiveDate = DateTimeExtend.GetCASMinDateTime(); threshold.FirstPerformanceSinceNew = lifelengthViewer_FirstPerformance.Lifelength; } threshold.FirstNotification = lifelengthViewer_FirstNotify.Lifelength; threshold.RepeatInterval = lifelengthViewerRptInterval.Lifelength; threshold.RepeatNotification = lifelengthViewerRptNotify.Lifelength; threshold.Warranty = lifelengthViewerWarranty.Lifelength; threshold.WarrantyNotification = lifelengthViewerWarrantyNotify.Lifelength; _currentComponentDirective.ExpiryRemainNotify = lifelengthViewerExpiryRemain.Lifelength; threshold.FirstPerformanceConditionType = radio_WhicheverFirst.Checked ? ThresholdConditionType.WhicheverFirst : ThresholdConditionType.WhicheverLater; try { var bindedItemId = -1; var currentRelation = _currentComponentDirective.ItemRelations.SingleOrDefault(); var bindedItemRelationType = ItemRelationHelper.ConvertBLItemRelationToUIITem(_currentComponentDirective.WorkItemsRelationType, _currentComponentDirective.IsFirst.HasValue && _currentComponentDirective.IsFirst.Value); if (currentRelation != null) { bindedItemId = _currentComponentDirective.IsFirst == true ? currentRelation.SecondItemId : currentRelation.FirstItemId; } if (_currentComponentDirective.ManHours != manHours || lookupComboboxMaintenanceDirective.SelectedItemId != bindedItemId || _currentComponentDirective.MPDTaskType != comboBoxMpdTaskType.SelectedItem || (WorkItemsRelationTypeUI)comboBoxRelationType.SelectedValue != bindedItemRelationType || _currentComponentDirective.Cost != cost || _currentComponentDirective.IsClosed != IsClosed || _currentComponentDirective.IsExpiry != IsExpiry || _currentComponentDirective.KitRequired != textBoxKitRequired.Text || _currentComponentDirective.Remarks != textBoxRemarks.Text || textBoxZoneArea.Text != _currentComponentDirective.ZoneArea || textBoxAcess.Text != _currentComponentDirective.AccessDirective || textBoxAAM.Text != _currentComponentDirective.AAM || textBoxCMM.Text != _currentComponentDirective.CMM || dateTimePickerExpiryDate.Value != _currentComponentDirective.ExpiryDate || _currentComponentDirective.NDTType.ItemId != ((NDTType)comboBoxNdt.SelectedItem).ItemId || _currentComponentDirective.Threshold.ToString() != threshold.ToString() || _currentComponentDirective.FaaFormFile != fileControl.AttachedFile || _currentComponentDirective.HiddenRemarks != textBoxHiddenRemarks.Text || _currentComponentDirective.DirectiveType.ItemId != ((ComponentRecordType)comboBoxWorkType.SelectedItem).ItemId || fileControl.GetChangeStatus()) { return(true); } } catch (InvalidOperationException) { ItemRelationHelper.ShowDialogIfItemLinksCountMoreThanOne($"Component {_currentComponentDirective.PartNumber}", _currentComponentDirective.ItemRelations.Count); } catch (Exception ex) { Program.Provider.Logger.Log("Error while saving data", ex); return(true); } return(false); }