Esempio n. 1
0
        private void ButtonAddClick(object sender, EventArgs e)
        {
            if (listViewTasksForSelect.SelectedItems.Count == 0)
            {
                return;
            }

            if (listViewTasksForSelect.SelectedItems.Count > 1)
            {
                MessageBox.Show($"Please select one directive. Because you can only bind one directive.",
                                (string)new GlobalTermsProvider()["SystemName"],
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (listViewBindedTasks.ItemsCount > 0)
            {
                MessageBox.Show($"Directive alredy binded for this MPD. If you want bind MPD please remove current binded directive.",
                                (string)new GlobalTermsProvider()["SystemName"],
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var itemRelations = GlobalObjects.ItemsRelationsDataAccess.CheckRelations(listViewTasksForSelect.SelectedItems.First(), _directive);

            if (itemRelations.Count > 0)
            {
                ItemRelationHelper.ShowDialogIfItemHaveLinkWithAnotherItem($"AD {listViewTasksForSelect.SelectedItems.First().Title}", "MPD", "AD");
                return;
            }

            if (_directive.IsFirst == null)
            {
                _directive.NormalizeItemRelations();
                comboBoxRelationType.SelectedValue = ItemRelationHelper.ConvertBLItemRelationToUIITem(_directive.WorkItemsRelationType, false);
            }
            //Список выбранных задач по компонентам для привязки
            var selectedDirectives = listViewTasksForSelect.SelectedItems.ToList();

            //список уже призязанных задач по компонетам
            var bindedDirectives       = listViewBindedTasks.GetItemsArray().ToList();
            var concatenatedDirectives = selectedDirectives.Concat(bindedDirectives);

            listViewTasksForSelect.RemoveItems(selectedDirectives);
            listViewBindedTasks.SetItemsArray(concatenatedDirectives.ToArray());

            _newBindedItems.AddRange(selectedDirectives);
        }
        private void ButtonAddClick(object sender, EventArgs e)
        {
            if (listViewTasksForSelect.SelectedItems.Count == 0)
            {
                return;
            }

            if (_directive.IsFirst == null)
            {
                _directive.NormalizeItemRelations();
                comboBoxRelationType.SelectedValue = ItemRelationHelper.ConvertBLItemRelationToUIITem(_directive.WorkItemsRelationType, false);
            }
            //Список выбранных задач по компонентам для привязки
            var selectedDirectives = listViewTasksForSelect.SelectedItems.ToList();

            //список уже призязанных задач по компонетам
            var bindedDirectives       = listViewBindedTasks.GetItemsArray().ToList();
            var concatenatedDirectives = selectedDirectives.Concat(bindedDirectives);

            listViewTasksForSelect.RemoveItems(selectedDirectives);
            listViewBindedTasks.SetItemsArray(concatenatedDirectives.ToArray());

            _newBindedItems.AddRange(selectedDirectives);
        }
Esempio n. 3
0
        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);
        }