private static long GeneratePartsForEachLevel(ProductStructureInput inputParameters,
                                                      ProductStructure productStructure, List <HashSet <long> > availableNodes, MasterTableArticleType articleTypes,
                                                      MasterTableUnit units, M_Unit[] unitCol, XRandom rng, int i, bool sampleWorkPlanLength,
                                                      TruncatedDiscreteNormal truncatedDiscreteNormalDistribution)
        {
            //Problem mit Algorithmus aus SYMTEP: bei ungünstigen Eingabeparametern gibt es auf manchen Fertigungsstufen keine Teile (0 Knoten)
            //-> Es fehlt wohl Nebenbedingung, dass Anzahl an Teilen auf jeden Fertigungsstufe mindestens 1 sein darf
            //-> Entsprechend wurde das hier angepasst
            var nodeCount = Math.Max(1, Convert.ToInt64(Math.Round(
                                                            Math.Pow(inputParameters.ComplexityRatio / inputParameters.ReutilisationRatio, i - 1) *
                                                            inputParameters.EndProductCount)));
            var nodesCurrentLevel = new Dictionary <long, Node>();

            productStructure.NodesPerLevel.Add(nodesCurrentLevel);
            var availableNodesOnThisLevel = new HashSet <long>();

            availableNodes.Add(availableNodesOnThisLevel);

            bool          toPurchase, toBuild;
            M_Unit        unit = null;
            M_ArticleType articleType;

            if (i == 1)
            {
                toPurchase  = false;
                toBuild     = true;
                unit        = units.PIECES;
                articleType = articleTypes.PRODUCT;
            }
            else if (i == inputParameters.DepthOfAssembly)
            {
                toPurchase  = true;
                toBuild     = false;
                articleType = articleTypes.MATERIAL;
            }
            else
            {
                toPurchase  = false;
                toBuild     = true;
                unit        = units.PIECES;
                articleType = articleTypes.ASSEMBLY;
            }

            for (long j = 0; j < nodeCount; j++)
            {
                unit = GeneratePartsForCurrentLevel(inputParameters, unitCol, rng, i, sampleWorkPlanLength,
                                                    truncatedDiscreteNormalDistribution, availableNodesOnThisLevel, j, unit, articleType, toPurchase,
                                                    toBuild, nodesCurrentLevel);
            }

            return(nodeCount);
        }
        private void GenerateFirstSetOfEdgesForDivergingMaterialFlow(ProductStructureInput inputParameters,
                                                                     ProductStructure productStructure, XRandom rng, List <HashSet <long> > availableNodes)
        {
            for (var i = inputParameters.DepthOfAssembly; i >= 2; i--)
            {
                for (long j = 1; j <= productStructure.NodesPerLevel[i - 1].LongCount() /*&& availableNodes[i - 2].LongCount() > 0*/; j++)
                {
                    var endNodePos = rng.NextLong(availableNodes[i - 2].LongCount());
                    var endNode    = availableNodes[i - 2].ToArray()[endNodePos];
                    var edge       = new Edge
                    {
                        Start = productStructure.NodesPerLevel[i - 1][j - 1],
                        End   = productStructure.NodesPerLevel[i - 2][endNode]
                    };
                    edge.End.IncomingEdges.Add(edge);
                    productStructure.Edges.Add(edge);
                    availableNodes[i - 2].Remove(endNode);
                }
            }

            for (var i = 1; i < inputParameters.DepthOfAssembly; i++)
            {
                var pk = GetCumulatedProbabilitiesPk2(i, inputParameters.DepthOfAssembly);
                foreach (var j in availableNodes[i - 1])
                {
                    var u   = rng.NextDouble();
                    var sum = 0.0;
                    var k   = 0;
                    while (k < pk.Count - 1)
                    {
                        sum += pk[k].Value;
                        if (u < sum)
                        {
                            break;
                        }

                        k++;
                    }

                    var assemblyLevelOfStartNode = pk[k].Key;
                    var posOfNode = rng.NextLong(productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1].LongCount());
                    var edge      = new Edge
                    {
                        Start = productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1][posOfNode],
                        End   = productStructure.NodesPerLevel[i - 1][j]
                    };
                    edge.End.IncomingEdges.Add(edge);
                    productStructure.Edges.Add(edge);
                }
            }
        }
        private void GenerateFirstSetOfEdgesForConvergingMaterialFlow(ProductStructureInput inputParameters, XRandom rng,
                                                                      Dictionary <int, List <KeyValuePair <int, double> > > pkPerI, List <HashSet <long> > availableNodes,
                                                                      ProductStructure productStructure)
        {
            for (var i = 1; i <= inputParameters.DepthOfAssembly - 1; i++)
            {
                for (long j = 1; j <= productStructure.NodesPerLevel[i - 1].LongCount() /*&& availableNodes[i].LongCount() > 0*/; j++)
                {
                    var startNodePos = rng.NextLong(availableNodes[i].LongCount());
                    var startNode    = availableNodes[i].ToArray()[startNodePos];
                    var edge         = new Edge
                    {
                        Start = productStructure.NodesPerLevel[i][startNode],
                        End   = productStructure.NodesPerLevel[i - 1][j - 1]
                    };
                    edge.End.IncomingEdges.Add(edge);
                    productStructure.Edges.Add(edge);
                    availableNodes[i].Remove(startNode);
                }
            }

            for (var i = inputParameters.DepthOfAssembly; i >= 2; i--)
            {
                foreach (var j in availableNodes[i - 1])
                {
                    var u   = rng.NextDouble();
                    var sum = 0.0;
                    var k   = 0;
                    while (k < pkPerI[i].Count - 1)
                    {
                        sum += pkPerI[i][k].Value;
                        if (u < sum)
                        {
                            break;
                        }

                        k++;
                    }

                    var assemblyLevelOfEndNode = pkPerI[i][k].Key;
                    var posOfNode = rng.NextLong(productStructure.NodesPerLevel[assemblyLevelOfEndNode - 1].LongCount());
                    var edge      = new Edge
                    {
                        Start = productStructure.NodesPerLevel[i - 1][j],
                        End   = productStructure.NodesPerLevel[assemblyLevelOfEndNode - 1][posOfNode]
                    };
                    edge.End.IncomingEdges.Add(edge);
                    productStructure.Edges.Add(edge);
                }
            }
        }
        // Wie könnte man Testen, ob der Algorithmus dem aus SYMTEP enspricht (keine Fehler enthält)
        public ProductStructure GenerateProductStructure(ProductStructureInput inputParameters,
                                                         MasterTableArticleType articleTypes, MasterTableUnit units, M_Unit[] unitCol, XRandom rng)
        {
            var productStructure = new ProductStructure();
            var availableNodes   = new List <HashSet <long> >();

            GenerateParts(inputParameters, productStructure, availableNodes, articleTypes, units, unitCol, rng);

            GenerateEdges(inputParameters, productStructure, rng, availableNodes);

            DeterminationOfEdgeWeights(inputParameters, productStructure, rng);

            return(productStructure);
        }
Exemplo n.º 5
0
        private void IsValidStructure(ProductStructure structure)
        {
            Document currentDoc = structure.Document;

            // существование родителя
            if (structure.GetAllRowElements().Where(x => x.ParentRowElement == null).Count() != 1)
            {
                throw new DocStructureParentException(currentDoc.FileName);
            }

            // проверка обозначения родителя на валидность
            RowElement parentItem = structure.GetAllRowElements().Where(
                x => x.ParentRowElement == null).FirstOrDefault();

            SchemeDataConfig schemeConfig = new SchemeDataConfig(structure);
            SchemeData       scheme       = schemeConfig.GetScheme();

            ElementDataConfig dataConfig = new ElementDataConfig(parentItem, scheme);

            ElementData itemData = dataConfig.ConfigData();

            if (itemData.Sign == string.Empty ||
                itemData.MainSection != "Документация" && itemData.Sign.Contains("СБ"))
            {
                throw new DocStructureParentSignNotValidException(currentDoc.FileName);
            }

            // проверка типа документа у родителя
            if ((itemData.MainSection == "Документация" ||
                 itemData.MainSection == "Сборочные единицы" ||
                 itemData.MainSection == "Комплекты") &&
                itemData.DocCode == string.Empty)
            {
                throw new DocStructureDocTypeNotValidException(currentDoc.FileName);
            }

            // проверка обозначения у родителя
            if (itemData.Sign == String.Empty || itemData.Section == String.Empty)
            {
                throw new DocStructurePerentPropsException();
            }
        }
        private void GenerateParts(ProductStructureInput inputParameters, ProductStructure productStructure,
                                   List <HashSet <long> > availableNodes, MasterTableArticleType articleTypes, MasterTableUnit units,
                                   M_Unit[] unitCol, XRandom rng)
        {
            bool sampleWorkPlanLength = inputParameters.MeanWorkPlanLength != null &&
                                        inputParameters.VarianceWorkPlanLength != null;
            TruncatedDiscreteNormal truncatedDiscreteNormalDistribution = null;

            if (sampleWorkPlanLength)
            {
                truncatedDiscreteNormalDistribution = new TruncatedDiscreteNormal(1, null,
                                                                                  Normal.WithMeanVariance((double)inputParameters.MeanWorkPlanLength,
                                                                                                          (double)inputParameters.VarianceWorkPlanLength, rng.GetRng()));
            }
            for (var i = 1; i <= inputParameters.DepthOfAssembly; i++)
            {
                productStructure.NodesCounter += GeneratePartsForEachLevel(inputParameters, productStructure, availableNodes,
                                                                           articleTypes, units, unitCol, rng, i, sampleWorkPlanLength, truncatedDiscreteNormalDistribution);
            }
        }
Exemplo n.º 7
0
 public void SaveNewProductStructure()
 {
     using (var db = new DataSmartDBContext())
     {
         if (db.ProductStructure.Any(o => o.Category_1 == Product.ProductCategory_1 & o.Category_2 == Product.ProductCategory_2))
         {
             return;
         }
         else
         {
             ProductStructure Structure = new ProductStructure()
             {
                 Category_1 = Product.ProductCategory_1,
                 Category_2 = Product.ProductCategory_2
             };
             db.ProductStructure.Add(Structure);
             db.SaveChanges();
         }
     }
 }
        private void GenerateEdges(ProductStructureInput inputParameters, ProductStructure productStructure, XRandom rng,
                                   List <HashSet <long> > availableNodes)
        {
            var nodesOfLastAssemblyLevelCounter =
                productStructure.NodesPerLevel[inputParameters.DepthOfAssembly - 1].LongCount();
            var edgeCount = Convert.ToInt64(Math.Round(Math.Max(
                                                           inputParameters.ReutilisationRatio * (productStructure.NodesCounter - inputParameters.EndProductCount),
                                                           inputParameters.ComplexityRatio * (productStructure.NodesCounter - nodesOfLastAssemblyLevelCounter))));
            var pkPerI = GetSetOfCumulatedProbabilitiesPk1(inputParameters.DepthOfAssembly);

            if (inputParameters.ReutilisationRatio < inputParameters.ComplexityRatio)
            {
                GenerateFirstSetOfEdgesForConvergingMaterialFlow(inputParameters, rng, pkPerI, availableNodes, productStructure);
            }
            else
            {
                GenerateFirstSetOfEdgesForDivergingMaterialFlow(inputParameters, productStructure, rng, availableNodes);
            }

            //scheinbar können hierbei Multikanten entstehen. ist das in Erzeugnisstruktur erlaubt? -> stellt kein Problem dar
            GenerateSecondSetOfEdges(inputParameters, productStructure, rng, edgeCount, pkPerI);
        }
Exemplo n.º 9
0
 public SchemeDataConfig(ProductStructure structure)
 {
     Structure = structure;
 }
        private static void DeterminationOfEdgeWeights(ProductStructureInput inputParameters, ProductStructure productStructure, XRandom rng)
        {
            var logNormalDistribution = LogNormal.WithMeanVariance(inputParameters.MeanIncomingMaterialAmount,
                                                                   Math.Pow(inputParameters.StdDevIncomingMaterialAmount, 2), rng.GetRng());

            foreach (var edge in productStructure.Edges)
            {
                edge.Weight = logNormalDistribution.Sample();
            }
        }
        private static void GenerateSecondSetOfEdges(ProductStructureInput inputParameters, ProductStructure productStructure,
                                                     XRandom rng, long edgeCount, Dictionary <int, List <KeyValuePair <int, double> > > pkPerI)
        {
            var possibleStartNodes = productStructure.NodesCounter - inputParameters.EndProductCount;

            for (var j = productStructure.Edges.LongCount() + 1; j <= edgeCount; j++)
            {
                var startNodePos             = rng.NextLong(possibleStartNodes) + 1;
                var assemblyLevelOfStartNode = 2;
                while (assemblyLevelOfStartNode < inputParameters.DepthOfAssembly)
                {
                    if (startNodePos <= productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1].LongCount())
                    {
                        break;
                    }

                    startNodePos -= productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1].LongCount();
                    assemblyLevelOfStartNode++;
                }

                var u   = rng.NextDouble();
                var sum = 0.0;
                var k   = 0;
                while (k < pkPerI[assemblyLevelOfStartNode].Count - 1)
                {
                    sum += pkPerI[assemblyLevelOfStartNode][k].Value;
                    if (u < sum)
                    {
                        break;
                    }

                    k++;
                }

                var assemblyLevelOfEndNode = pkPerI[assemblyLevelOfStartNode][k].Key;
                var endNodePos             = rng.NextLong(productStructure.NodesPerLevel[assemblyLevelOfEndNode - 1].LongCount());
                var edge = new Edge
                {
                    Start = productStructure.NodesPerLevel[assemblyLevelOfStartNode - 1][startNodePos - 1],
                    End   = productStructure.NodesPerLevel[assemblyLevelOfEndNode - 1][endNodePos]
                };
                edge.End.IncomingEdges.Add(edge);
                productStructure.Edges.Add(edge);
            }
        }
Exemplo n.º 12
0
        public void VerifyComplexityAndReutilizationRation(ProductStructureInput input, ProductStructure productStructure)
        {
            var nodesOfLastAssemblyLevelCounter =
                productStructure.NodesPerLevel[input.DepthOfAssembly - 1].LongCount();
            var actualComplexityRatio = productStructure.Edges.Count /
                                        (double)(productStructure.NodesCounter - nodesOfLastAssemblyLevelCounter);
            var actualReutilizationRation = productStructure.Edges.Count /
                                            (double)(productStructure.NodesCounter - input.EndProductCount);

            System.Diagnostics.Debug.WriteLine("################################# Generated product structure has a complexity ratio of " + actualComplexityRatio + " (input was " + input.ComplexityRatio + ")");
            System.Diagnostics.Debug.WriteLine("################################# Generated product structure has a reutilization ratio of " + actualReutilizationRation + " (input was " + input.ReutilisationRatio + ")");
        }
 public ProductStructureViewModel(SalesUnit salesUnit)
 {
     ProductStructures = ProductStructure.GenerateProductStructures(salesUnit).ToList();
 }
Exemplo n.º 14
0
        private void ExportStructure(ProductStructure structure, bool isConfig = false)
        {
            // верификация структуры
            IsValidStructure(structure);

            // текущий документ
            Document currentDoc = structure.Document;

            // схема структуры
            SchemeDataConfig schemeConfig = new SchemeDataConfig(structure);
            SchemeData       scheme       = schemeConfig.GetScheme();

            // родительский элемент
            RowElement parentItem = structure.GetAllRowElements().Where(
                x => x.ParentRowElement == null).FirstOrDefault();

            ElementDataConfig dataConfig = new ElementDataConfig(parentItem, scheme);
            ElementData       itemData   = dataConfig.ConfigData();

            // если структура является исполнением, то обозначением головного элемента
            // является наименование структуры
            if (isConfig)
            {
                itemData.Sign = structure.Name;
            }

            // логирование
            log.Span     = sw.Elapsed;
            log.User     = settings.UserName;
            log.Document = this.doc.FileName;
            log.Section  = itemData.Section;
            log.Position = itemData.Position;
            log.Sign     = itemData.Sign;
            log.Name     = itemData.Name;
            log.Qty      = itemData.Qty;
            log.Doccode  = itemData.DocCode;
            log.FilePath = itemData.FilePath;
            log.Error    = null;

            log.Write();

            // команды
            TFlexObjSynchRepository synchRep = new TFlexObjSynchRepository();

            // родительский элемент
            decimal?parent = null;

            // код БД
            decimal code    = 0;
            decimal doccode = 0;

            // синхронизация с КИС "Омега"
            V_SEPO_TFLEX_OBJ_SYNCH synchObj = synchRep.GetSynchObj(
                itemData.MainSection,
                itemData.DocCode,
                itemData.Sign,
                itemData.ObjectType);

            // если головной элемент не синхронизирован - выход
            if (synchObj == null)
            {
                return;
            }

            #region экспорт родителя

            switch (synchObj.KOTYPE)
            {
            case (decimal)ObjTypes.SpecFixture:

                #region Спецификация оснастки

                CreateSpecFix.Exec(
                    itemData.Sign,
                    itemData.Name,
                    ownerCode,
                    synchObj.BOSTATECODE,
                    ompUserCode,
                    fixTypeCode,
                    ref code);

                // очищение спецификации
                ClearSpecification.Exec(code);

                // родительский элемент
                parent = code;

                // поиск файла спецификации по шаблону
                string signPattern = Regex.Replace(itemData.Sign, @"\D", "");

                string[] files = Directory.GetFiles(currentDoc.FilePath);

                foreach (var file in files)
                {
                    if (file.Contains(itemData.Sign) && file.Contains("СП"))
                    {
                        AddFile.Exec(code, file, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);
                    }
                }

                #endregion Спецификация оснастки

                break;

            case (decimal)ObjTypes.SpecDraw:

                #region Сборочный чертеж

                CreateSpecDraw.Exec(
                    itemData.Sign,
                    itemData.Name,
                    ownerCode,
                    synchObj.BOSTATECODE,
                    ompUserCode,
                    ref code);

                // присоединенный файл
                AddFile.Exec(code, currentDoc.FileName, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);

                #endregion Сборочный чертеж

                break;

            case (decimal)ObjTypes.Document:
            case (decimal)ObjTypes.UserDocument:

                #region Документация

                CreateDocument.Exec(
                    synchObj.BOTYPE,
                    itemData.Sign,
                    itemData.Name,
                    ownerCode,
                    synchObj.BOSTATECODE,
                    ompUserCode,
                    ref code);

                // присоединенный файл
                AddFile.Exec(code, currentDoc.FileName, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);

                #endregion Документация

                break;

            case (decimal)ObjTypes.Detail:

                #region Деталь

                CreateDetail.Exec(
                    itemData.Sign,
                    itemData.Name,
                    ownerCode,
                    synchObj.BOSTATECODE,
                    ompUserCode,
                    ref code);

                // присоединенный файл
                AddFile.Exec(code, currentDoc.FileName, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);

                // модели для детали
                var models = structure.GetAllRowElements().Where(x => x.ParentRowElement == parentItem);

                foreach (var model in models)
                {
                    ElementDataConfig modelDataConfig = new ElementDataConfig(model, scheme);
                    ElementData       modelData       = modelDataConfig.ConfigData();

                    if (modelData.FilePath != null)
                    {
                        log.Span     = sw.Elapsed;
                        log.User     = settings.UserName;
                        log.Document = this.doc.FileName;
                        log.Section  = modelData.Section;
                        log.Position = modelData.Position;
                        log.Sign     = modelData.Sign;
                        log.Name     = modelData.Name;
                        log.Qty      = modelData.Qty;
                        log.Doccode  = modelData.DocCode;
                        log.FilePath = modelData.FilePath;
                        log.Error    = null;

                        decimal linkdoccode = 0;

                        AddFile.TryExec(log, code, modelData.FilePath, ompUserCode,
                                        synchObj.FILEGROUP, doccode, fileAdditional, ref linkdoccode);
                    }
                }

                // моделями также являются невидимые фрагменты у деталей
                foreach (var fragment in currentDoc.GetFragments().Where(x => !x.Visible))
                {
                    if (fragment.FullFilePath != null)
                    {
                        log.Span     = sw.Elapsed;
                        log.User     = settings.UserName;
                        log.Document = this.doc.FileName;
                        log.Section  = null;
                        log.Position = null;
                        log.Sign     = null;
                        log.Name     = null;
                        log.Qty      = null;
                        log.Doccode  = null;
                        log.FilePath = fragment.FilePath;
                        log.Error    = null;

                        decimal linkdoccode = 0;

                        AddFile.TryExec(log, code, fragment.FullFilePath, ompUserCode,
                                        synchObj.FILEGROUP, doccode, fileAdditional, ref linkdoccode);
                    }
                }

                #endregion Деталь

                break;

            case (decimal)ObjTypes.Fixture:

                #region Оснастка

                CreateFixture.Exec(
                    itemData.Sign,
                    itemData.Name,
                    ownerCode,
                    synchObj.BOSTATECODE,
                    ompUserCode,
                    fixTypeCode,
                    ref code);

                // присоединенный файл
                AddFile.Exec(code, currentDoc.FileName, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);

                // модели для детали
                var fix_models = structure.GetAllRowElements().Where(x => x.ParentRowElement == parentItem);

                foreach (var model in fix_models)
                {
                    ElementDataConfig modelDataConfig = new ElementDataConfig(model, scheme);
                    ElementData       modelData       = modelDataConfig.ConfigData();

                    if (modelData.FilePath != null)
                    {
                        log.Span     = sw.Elapsed;
                        log.User     = settings.UserName;
                        log.Document = this.doc.FileName;
                        log.Section  = modelData.Section;
                        log.Position = modelData.Position;
                        log.Sign     = modelData.Sign;
                        log.Name     = modelData.Name;
                        log.Qty      = modelData.Qty;
                        log.Doccode  = modelData.DocCode;
                        log.FilePath = modelData.FilePath;
                        log.Error    = null;

                        decimal linkdoccode = 0;

                        AddFile.TryExec(log, code, modelData.FilePath, ompUserCode,
                                        synchObj.FILEGROUP, doccode, fileAdditional, ref linkdoccode);
                    }
                }

                // моделями также являются невидимые фрагменты у деталей
                foreach (var fragment in currentDoc.GetFragments().Where(x => !x.Visible))
                {
                    if (fragment.FullFilePath != null)
                    {
                        log.Span     = sw.Elapsed;
                        log.User     = settings.UserName;
                        log.Document = this.doc.FileName;
                        log.Section  = null;
                        log.Position = null;
                        log.Sign     = null;
                        log.Name     = null;
                        log.Qty      = null;
                        log.Doccode  = null;
                        log.FilePath = fragment.FilePath;
                        log.Error    = null;

                        decimal linkdoccode = 0;

                        AddFile.TryExec(log, code, fragment.FullFilePath, ompUserCode,
                                        synchObj.FILEGROUP, doccode, fileAdditional, ref linkdoccode);
                    }
                }

                #endregion Оснастка

                break;

            default:
                break;
            }

            #endregion экспорт родителя

            #region элементы спецификации

            if (itemData.MainSection == "Сборочные единицы")
            {
                foreach (var elem in
                         structure
                         .GetAllRowElements()
                         .Where(x => x.ParentRowElement == parentItem)
                         )
                {
                    // получение данных о документе
                    dataConfig = new ElementDataConfig(elem, scheme);

                    itemData = dataConfig.ConfigData();

                    // логирование
                    log.Span     = sw.Elapsed;
                    log.User     = settings.UserName;
                    log.Document = this.doc.FileName;
                    log.Section  = itemData.Section;
                    log.Position = itemData.Position;
                    log.Sign     = itemData.Sign;
                    log.Name     = itemData.Name;
                    log.Qty      = itemData.Qty;
                    log.Doccode  = itemData.DocCode;
                    log.FilePath = itemData.FilePath;
                    log.Error    = null;

                    log.Write();

                    // если обозначение или секция пустые, то переход на следующий элемент
                    if (itemData.Sign == String.Empty || itemData.Section == String.Empty)
                    {
                        continue;
                    }

                    //System.Windows.Forms.MessageBox.Show(itemData.SignFull + " |" + itemData.Section + " | "
                    //    + itemData.MainSection + " | " + itemData.ObjectType);

                    // синхронизация с КИС "Омега"
                    synchObj = synchRep.GetSynchObj(
                        itemData.MainSection,
                        itemData.DocCode,
                        itemData.Sign,
                        itemData.ObjectType);

                    // переход на следующий элемент, если позиция не синхронизирована
                    if (synchObj == null)
                    {
                        continue;
                    }

                    switch (synchObj.KOTYPE)
                    {
                    case (decimal)ObjTypes.SpecFixture:

                        #region Спецификация оснастки

                        CreateSpecFix.Exec(
                            itemData.SignFull,
                            itemData.Name,
                            ownerCode,
                            synchObj.BOSTATECODE,
                            ompUserCode,
                            fixTypeCode,
                            ref code);

                        // очищение спецификации
                        ClearSpecification.Exec(code);

                        // если у сборки есть фрагмент...
                        if (itemData.FilePath != null)
                        {
                            try
                            {
                                if (!File.Exists(itemData.FilePath))
                                {
                                    throw new FileNotFoundException();
                                }

                                // открыть документ входящей сборки в режиме чтения
                                Document linkDoc = TFlex.Application.OpenDocument(itemData.FilePath, false, true);

                                // добавить документ в стек
                                stackDocs.Add(linkDoc);

                                // экспорт документа
                                ExportDoc(linkDoc, itemData.SignFull);

                                // закрытие документа
                                linkDoc.Close();

                                // удалить из стека документ
                                stackDocs.Remove(linkDoc);
                            }
                            catch (FileNotFoundException e)
                            {
                                log.Span     = sw.Elapsed;
                                log.User     = settings.UserName;
                                log.Document = this.doc.FileName;
                                log.Section  = itemData.Section;
                                log.Position = itemData.Position;
                                log.Sign     = itemData.Sign;
                                log.Name     = itemData.Name;
                                log.Qty      = itemData.Qty;
                                log.Doccode  = itemData.DocCode;
                                log.FilePath = itemData.FilePath;
                                log.Error    = null;

                                log.Write(e);
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        #endregion Спецификация оснастки

                        break;

                    case (decimal)ObjTypes.SpecDraw:

                        #region Сборочный чертеж

                        CreateSpecDraw.Exec(
                            itemData.Sign,
                            itemData.Name,
                            ownerCode,
                            synchObj.BOSTATECODE,
                            ompUserCode,
                            ref code);

                        // присоединенный файл
                        AddFile.Exec(code, currentDoc.FileName, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);

                        #endregion Сборочный чертеж

                        break;

                    case (decimal)ObjTypes.Document:
                    case (decimal)ObjTypes.UserDocument:

                        #region Документация

                        CreateDocument.Exec(
                            synchObj.BOTYPE,
                            itemData.Sign,
                            itemData.Name,
                            ownerCode,
                            synchObj.BOSTATECODE,
                            ompUserCode,
                            ref code);

                        // файл
                        if (itemData.FilePath != null)
                        {
                            AddFile.Exec(code, itemData.FilePath, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);
                        }

                        #endregion Документация

                        break;

                    case (decimal)ObjTypes.Detail:

                        #region Деталь

                        CreateDetail.Exec(
                            itemData.SignFull,
                            itemData.Name,
                            ownerCode,
                            synchObj.BOSTATECODE,
                            ompUserCode,
                            ref code);

                        // файл
                        if (itemData.FilePath != null)
                        {
                            AddFile.Exec(code, itemData.FilePath, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);
                        }

                        // модели для детали
                        var models = structure.GetAllRowElements().Where(x => x.ParentRowElement == elem);

                        foreach (var model in models)
                        {
                            ElementDataConfig modelDataConfig = new ElementDataConfig(model, scheme);
                            ElementData       modelData       = modelDataConfig.ConfigData();

                            if (modelData.FilePath != null)
                            {
                                log.Span     = sw.Elapsed;
                                log.User     = settings.UserName;
                                log.Document = this.doc.FileName;
                                log.Section  = modelData.Section;
                                log.Position = modelData.Position;
                                log.Sign     = modelData.Sign;
                                log.Name     = modelData.Name;
                                log.Qty      = modelData.Qty;
                                log.Doccode  = modelData.DocCode;
                                log.FilePath = modelData.FilePath;
                                log.Error    = null;

                                decimal linkdoccode = 0;

                                AddFile.TryExec(log, code, modelData.FilePath, ompUserCode,
                                                synchObj.FILEGROUP, (doccode == 0) ? null : (decimal?)doccode, fileAdditional, ref linkdoccode);
                            }
                        }

                        // открывается документ на деталь, если есть
                        if (itemData.FilePath != null)
                        {
                            try
                            {
                                if (!File.Exists(itemData.FilePath))
                                {
                                    throw new FileNotFoundException();
                                }

                                // открыть документ входящей сборки в режиме чтения
                                Document linkDoc = TFlex.Application.OpenDocument(itemData.FilePath, false, true);

                                // добавить документ в стек
                                stackDocs.Add(linkDoc);

                                // экспорт документа
                                ExportDoc(linkDoc, itemData.SignFull);

                                // закрытие документа
                                linkDoc.Close();

                                // удалить из стека документ
                                stackDocs.Remove(linkDoc);
                            }
                            catch (FileNotFoundException e)
                            {
                                log.Span     = sw.Elapsed;
                                log.User     = settings.UserName;
                                log.Document = this.doc.FileName;
                                log.Section  = itemData.Section;
                                log.Position = itemData.Position;
                                log.Sign     = itemData.Sign;
                                log.Name     = itemData.Name;
                                log.Qty      = itemData.Qty;
                                log.Doccode  = itemData.DocCode;
                                log.FilePath = itemData.FilePath;
                                log.Error    = null;

                                log.Write(e);
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        #endregion Деталь

                        break;

                    case (decimal)ObjTypes.Fixture:

                        #region Оснастка

                        CreateFixture.Exec(
                            itemData.SignFull,
                            itemData.Name,
                            ownerCode,
                            synchObj.BOSTATECODE,
                            ompUserCode,
                            fixTypeCode,
                            ref code);

                        // файл
                        if (itemData.FilePath != null)
                        {
                            AddFile.Exec(code, itemData.FilePath, ompUserCode, synchObj.FILEGROUP, null, fileMain, ref doccode);
                        }

                        // модели для детали
                        var fix_models = structure.GetAllRowElements().Where(x => x.ParentRowElement == elem);

                        foreach (var model in fix_models)
                        {
                            ElementDataConfig modelDataConfig = new ElementDataConfig(model, scheme);
                            ElementData       modelData       = modelDataConfig.ConfigData();

                            if (modelData.FilePath != null)
                            {
                                log.Span     = sw.Elapsed;
                                log.User     = settings.UserName;
                                log.Document = this.doc.FileName;
                                log.Section  = modelData.Section;
                                log.Position = modelData.Position;
                                log.Sign     = modelData.Sign;
                                log.Name     = modelData.Name;
                                log.Qty      = modelData.Qty;
                                log.Doccode  = modelData.DocCode;
                                log.FilePath = modelData.FilePath;
                                log.Error    = null;

                                decimal linkdoccode = 0;

                                AddFile.Exec(code, modelData.FilePath, ompUserCode, synchObj.FILEGROUP,
                                             (doccode == 0) ? null : (decimal?)doccode, fileAdditional, ref linkdoccode);
                            }
                        }

                        // открывается документ на деталь, если есть
                        if (itemData.FilePath != null)
                        {
                            try
                            {
                                if (!File.Exists(itemData.FilePath))
                                {
                                    throw new FileNotFoundException();
                                }

                                // открыть документ входящей сборки в режиме чтения
                                Document linkDoc = TFlex.Application.OpenDocument(itemData.FilePath, false, true);

                                // добавить документ в стек
                                stackDocs.Add(linkDoc);

                                // экспорт документа
                                ExportDoc(linkDoc, itemData.SignFull);

                                // закрытие документа
                                linkDoc.Close();

                                // удалить из стека документ
                                stackDocs.Remove(linkDoc);
                            }
                            catch (FileNotFoundException e)
                            {
                                log.Span     = sw.Elapsed;
                                log.User     = settings.UserName;
                                log.Document = this.doc.FileName;
                                log.Section  = itemData.Section;
                                log.Position = itemData.Position;
                                log.Sign     = itemData.Sign;
                                log.Name     = itemData.Name;
                                log.Qty      = itemData.Qty;
                                log.Doccode  = itemData.DocCode;
                                log.FilePath = itemData.FilePath;
                                log.Error    = null;

                                log.Write(e);
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        #endregion Оснастка

                        break;

                    default:
                        code = 0;
                        break;
                    }

                    // добавить очередной элемент в спецификацию
                    if (code != 0)
                    {
                        AddElement.Exec(
                            parent.Value,
                            code,
                            synchObj.KOTYPE,
                            synchObj.OMPSECTION,
                            itemData.Qty.Value,
                            itemData.Position,
                            ompUserCode);
                    }
                }
            }

            #endregion элементы спецификации
        }