Exemplo n.º 1
0
        public bool AddSteps(int taskId)
        {
            //Добавление шагов
            if (!this.IsEmpty())
            {
                var allStepNodes = this.GetAllNodes();

                int firstStepId = 0;
                foreach (var stepNode in allStepNodes)
                {
                    if (stepNode.Tag == null)
                    {
                        return(false);
                    }
                    var           currentStep      = (StepsProperties)stepNode.Tag;
                    ShedulerStep  shedulerStep     = MQueryCommand.SelectShedulerStep(currentStep.Id);
                    TrySQLCommand insertStepResult = null;
                    if (shedulerStep == null)
                    {
                        insertStepResult = MQueryCommand.TryInsertNewStep(taskId,
                                                                          currentStep.OperationId,
                                                                          currentStep.RepeatTimesOnLackOf1cResponse,
                                                                          currentStep.RepeatingIntervalOn1cWaiting * MILLISECONDS_IN_SECOND,
                                                                          currentStep.WaitingForSuccessInterval * MILLISECONDS_IN_SECOND);
                    }
                    else
                    {
                        insertStepResult = MQueryCommand.TryUpdateStep(currentStep.Id,
                                                                       currentStep.OperationId,
                                                                       currentStep.RepeatTimesOnLackOf1cResponse,
                                                                       currentStep.RepeatingIntervalOn1cWaiting * MILLISECONDS_IN_SECOND,
                                                                       currentStep.WaitingForSuccessInterval * MILLISECONDS_IN_SECOND);
                    }

                    if (!insertStepResult.IsComplete)
                    {
                        MessageBox.Show($"Ошибка добавления новой задачи{Environment.NewLine}{insertStepResult.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                    if (stepNode.Parent == null)
                    {
                        firstStepId = insertStepResult.ReturnedId;
                    }

                    currentStep.Id = insertStepResult.ReturnedId;
                }
                ;
                var uspdateResult = MQueryCommand.TryUpdateStepFirstStepId(taskId, firstStepId);
                if (!uspdateResult.IsComplete)
                {
                    return(false);
                }

                // Обновляем Id связей
                foreach (var stepNode in allStepNodes)
                {
                    var stepNodeProperties = (StepsProperties)stepNode.Tag;
                    foreach (TreeNode childNode in stepNode.Nodes)
                    {
                        var childNodeProperties = (StepsProperties)childNode.Tag;
                        if (childNodeProperties.IsPositive)
                        {
                            uspdateResult = MQueryCommand.TryUpdateStepPositiveOperationId(stepNodeProperties.Id, childNodeProperties.Id);
                        }
                        else
                        {
                            uspdateResult = MQueryCommand.TryUpdateStepNegativeOperationId(stepNodeProperties.Id, childNodeProperties.Id);
                        }
                        if (!uspdateResult.IsComplete)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }