Esempio n. 1
0
        private void getPriceForComponent(ModelDoc2 model, bool ParentCalcStruct, Action<decimal> nextPrice, Action<Exception, string> nextError)
        {
            string currentConfig = model.IGetActiveConfiguration().Name;

            if (currentConfig.ToLower().Contains("по умолчани") || currentConfig.ToLower().Contains("default"))
                currentConfig = string.Empty;

            string isProduct = model.GetCustomInfoValue(currentConfig, "IsProduct");
            if (string.IsNullOrEmpty(isProduct))
            {
                isProduct = model.GetCustomInfoValue(string.Empty, "IsProduct");
                if (string.IsNullOrEmpty(isProduct))
                    isProduct = "No";
            }

            if (isProduct == "Yes")
            {
                //изделие

                //Проверка существования артикула для компонента в случает отсутствия, расчет цены на сам компонент не производится
                string articul = model.GetCustomInfoValue(string.Empty, "Articul");
                if (string.IsNullOrEmpty(articul))
                    articul = model.GetCustomInfoValue(currentConfig, "Articul");

                if (!string.IsNullOrEmpty(articul))
                {
                    try
                    {
                        nextPrice(сalculatePriceForModel(model));
                    }
                    catch (Exception e)
                    {
                        if (checkError(e))
                            nextError(e, Path.GetFileName(model.GetPathName()));
                    }
                }

                string s = model.GetPathName();
                AssemblyDoc model_assembly = model as AssemblyDoc;
                if (model_assembly != null)
                {
                    bool calcStruct = true;
                    if (!string.IsNullOrEmpty(articul))
                    {
                        string calcStructStr = model.get_CustomInfo2(string.Empty, "CalcStruct");
                        if (calcStructStr.ToLower() == "no")
                            calcStruct = false;
                    }

                    var components = (object[])((AssemblyDoc)model).GetComponents(true);
                    foreach (var component in components)
                    {
                        var comp = (Component2)component;
                        ModelDoc2 _model = comp.IGetModelDoc();
                        if (_model != null)
                        {
                            getPriceForComponent(_model, calcStruct, nextPrice, nextError);
                        }
                    }
                }
            }
            else
            {
                //не изделие

                string articul = model.GetCustomInfoValue(string.Empty, "Articul");
                if (string.IsNullOrEmpty(articul))
                    articul = model.GetCustomInfoValue(currentConfig, "Articul");

                string isIndependentStr = model.get_CustomInfo2(string.Empty, "IsIndependent");
                bool isIndependent = true;
                if (string.IsNullOrEmpty(isIndependentStr) || isIndependentStr.ToLower() == "no")
                    isIndependent = false;

                if (isIndependent)
                {
                    bool calcStruct = true;
                    if (!string.IsNullOrEmpty(articul))
                    {
                        //независимый и с артикулом
                        try
                        {
                            nextPrice(сalculatePriceForModel(model));
                        }
                        catch (Exception e)
                        {
                            if (checkError(e))
                                nextError(e, Path.GetFileName(model.GetPathName()));
                        }
                        string calcStructStr = model.get_CustomInfo2(string.Empty, "CalcStruct");

                        if (calcStructStr.ToLower() == "no")
                            calcStruct = false;
                    }

                    if (calcStruct)
                    {
                        AssemblyDoc model_assembly = model as AssemblyDoc;
                        if (model_assembly != null)
                        {
                            var components = (object[])((AssemblyDoc)model).GetComponents(true);
                            foreach (var component in components)
                            {
                                var comp = (Component2)component;
                                ModelDoc2 _model = comp.IGetModelDoc();
                                if (_model != null)
                                {
                                    getPriceForComponent(_model, calcStruct, nextPrice, nextError);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //компонент входит в состав изделия
                    if (ParentCalcStruct)
                    {
                        //нужно получить цену
                        bool calcStruct = true;
                        if (!string.IsNullOrEmpty(articul))
                        {
                            try
                            {
                                nextPrice(сalculatePriceForModel(model));
                            }
                            catch (Exception e)
                            {
                                if (checkError(e))
                                    nextError(e, Path.GetFileName(model.GetPathName()));
                            }
                            string calcStructStr = model.get_CustomInfo2(string.Empty, "CalcStruct");
                            if (calcStructStr.ToLower() == "no")
                                calcStruct = false;
                        }

                        AssemblyDoc model_assembly = model as AssemblyDoc;
                        if (model_assembly != null)
                        {
                            var components = (object[])((AssemblyDoc)model).GetComponents(true);
                            foreach (var component in components)
                            {
                                var comp = (Component2)component;
                                ModelDoc2 _model = comp.IGetModelDoc();
                                if (_model != null)
                                {
                                    getPriceForComponent(_model, calcStruct, nextPrice, nextError);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (model as AssemblyDoc != null)
                        {
                            var components = (object[])((AssemblyDoc)model).GetComponents(true);
                            foreach (var component in components)
                            {
                                var comp = (Component2)component;
                                ModelDoc2 _model = comp.IGetModelDoc();
                                if (_model != null)
                                {
                                    getPriceForComponent(_model, false, nextPrice, nextError);
                                }
                            }
                        }
                    }
                }
            }
        }