Example #1
0
        void test_Mtch_3()
        {
            Log.set(" test_Mtch_3: Rule 5 и Group < C235, Pl30 >");
            rule = new Rule.Rule(5);
            ElmAttSet.ElmAttSet elm = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D74-3134-353338303236",
                "C235", "Steel", "Pl30", 0, 0, 0, 1001);
            Dictionary<string, ElmAttSet.ElmAttSet> els
                = new Dictionary<string, ElmAttSet.ElmAttSet>();
            els.Add(elm.guid, elm);
            List<string> guids = new List<string>(); guids.Add(elm.guid);
            var model = new Model.Model();
            model.setElements(els);
            model.getGroups();
            var gr = model.elmGroups[0];
            //6/4/17           TST.Eq(gr.guids.Count, 1);
            //6/4/17           TST.Eq(gr.mat, "c235");
            //6/4/17TST.Eq(gr.prf, "pl30");
            var doc = Docs.getDoc("Полоса СтальхолдингM");
            var csDP = new Dictionary<SType, string>();
            //31/3            csFPs = rule.Parser(FP.type.CompSet, doc.LoadDescription);
            // 2/4            Comp comp1 = new Comp(doc, 2, csDP);
            // 2/4            Comp comp2 = new Comp(doc, 12, csDP);
            // 2/4            List<Comp> comps = new List<Comp> { comp1, comp2 };
            // 2/4            CS cs = new CS("test_CS", null, rule, doc.LoadDescription, comps);
            // 2/4            TST.Eq(cs.csDP.Count, 4);

            //////////////////////////TST.Eq(comp1.isMatch(gr, rule), false);
            //////////////////////////TST.Eq(comp2.isMatch(gr, rule), true);
            Log.exit();
        }
Example #2
0
        /// <summary>
        /// getNEWcs(Supplier, Group) - return CompSet could be supplied by supl, or null if not available
        /// </summary>
        /// <param name="selSupl"></param>
        /// <param name="grOLD"></param>
        /// <returns></returns>
        internal CmpSet getNEWcs(Supplier supl, Gr group)
        {
            string grCSname = group.CompSetName;
            CmpSet cs;
            try { cs = new CmpSet(grCSname, this); }
            catch { return null; }

            //////////if (CompSets.Count == 0)
            //////////{

            //////////}
            //////////var cs = CompSets.Find(x => x.name == grCSname);
            //////////if (cs != null) return cs; // нашел CS с тем же именем!
            // в дальнейшем тут вставить подбор CompSet по-компонентно с учетом Rule.synonyms
            // это означает, что, хотя у CS другое название, его разрешено использовать Правилами.
            var mod = MainWindow.model;
            if (mod.Rules.Count == 0) return null; // тут надо загрузить Правила из TSmatchINFO.xlsx/Rules
            Rule.Rule rule = null;
            if (group.match != null) rule = group.match.rule;
            cs = CompSets.Find(x => x.name == rule.CompSet.name);
            if (cs != null) return cs;    // true - found CompSet.name from this Suppler
            //.. по крайней мере, имя отличается -- проверим по-компонентно все прайс-листы с Match
            //.. еще не написано
            return cs;
        }
Example #3
0
        bool isMatchGrRule(SType stype, ElmAttSet.Group gr, Rule.Rule rule)
        {
            if (rule == null || !fps.ContainsKey(stype))
            {
                return(true);
            }
            var    ruleSyns  = rule.synonyms;
            string comMatPrf = fps[stype].pars[0].par.ToString();
            string grMatPrf  = stype == SType.Material ? gr.mat : gr.prf;

            if (grMatPrf == comMatPrf)
            {
                return(true);
            }
            if (ruleSyns != null && ruleSyns.ContainsKey(stype))
            {
                List <string> Syns = ruleSyns[stype].ToList();
                if (!Lib.IContains(Syns, comMatPrf) || !Lib.IContains(Syns, grMatPrf))
                {
                    return(false);
                }

                string c = strExclude(comMatPrf, Syns);
                string g = strExclude(grMatPrf, Syns);
//27/3                if(c == g) return true;
                return(c.Contains(g));

                ////////////////var p1 = Params(Syns, comMatPrf, );
                //// 27/3 //////var p2 = Params(Syns, grMatPrf);
                ////////////////bool b = p1 != p2  && stype == SType.Material;

                return(Params(Syns, comMatPrf) == Params(Syns, grMatPrf));
            }
            return(false);
        }
Example #4
0
        bool isMatchGrRule(SType stype, ElmAttSet.Group gr, Rule.Rule rule)
        {
            if (rule == null || !compDP.dpar.ContainsKey(stype))
            {
                return(true);
            }
            var    ruleSyns  = rule.synonyms;
            string comMatPrf = viewComp_(stype);
            string grMatPrf  = stype == SType.Material ? gr.mat : gr.prf;

            if (grMatPrf.Contains("ш2") && comMatPrf.Contains("ш2"))
            {
                log.Info("--");                                                       //5/4
            }
            if (ruleSyns != null && ruleSyns.ContainsKey(stype))
            {
                List <string> Syns = ruleSyns[stype].ToList();
                if (!Lib.IContains(Syns, comMatPrf) || !Lib.IContains(Syns, grMatPrf))
                {
                    return(false);
                }
                string c = strExclude(comMatPrf, Syns);
                string g = strExclude(grMatPrf, Syns);
                if (c == g)
                {
                    return(true);
                }
                return(c.Contains(g));
                ////////////////var p1 = Params(Syns, comMatPrf, );
                //// 27/3 //////var p2 = Params(Syns, grMatPrf);
                ////////////////bool b = p1 != p2  && stype == SType.Material;
                //31/3//////////return Params(Syns, comMatPrf) == Params(Syns, grMatPrf);
            }
            return(comMatPrf == grMatPrf);
        }
Example #5
0
 public CompSet(string _name, Rule.Rule rule, string LoadDescriptor, List <Comp> comps = null)
 {
     name  = _name;
     csFPs = rule.Parser(FP.type.CompSet, LoadDescriptor);
     if (comps != null)
     {
         Components = comps;
     }
 }
Example #6
0
        public void UT_Mtch()
        {
            boot.Init();
            var model = mod.sr.SetModel(boot, initSupl: false);

            Assert.IsTrue(model.elmGroups.Count > 0);
            Assert.IsTrue(model.Rules.Count > 0);
            var Rules = model.Rules.ToList();
            var grps  = model.elmGroups.ToList();

            // test 1 Уголок L50x5 -> цена 7 209 руб
            Rule.Rule   rule = Rules.Find(x => x.sCS.Contains("Уголок"));
            Group.Group gr   = grps.Find(x => x.Prf.Contains("L"));
            if (rule != null && gr != null)
            {
                rule.Init();
                var m = new Mtch(gr, rule);
                Assert.IsTrue(gr.totalPrice > 7000);
                double rubPerKg = gr.totalPrice / gr.totalWeight;
                Assert.IsTrue(rubPerKg > 20);
            }

            // test 2 Полоса -30 из Листа ЛСС
            rule = Rules.Find(x => x.sCS.Contains("Лист"));
            gr   = grps.Find(x => x.Prf.Contains("—"));
            if (rule != null && gr != null)
            {
                rule.Init();
                var m = new Mtch(gr, rule);
                Assert.IsTrue(gr.totalPrice > 7000);
                double rubPerKg = gr.totalPrice / gr.totalWeight;
                Assert.IsTrue(rubPerKg > 20);
            }

            // test 3 Бетон
            rule = Rules.Find(x => x.sCS.Contains("бетон"));
            gr   = grps.Find(x => x.mat.Contains("b"));
            if (rule != null && gr != null)
            {
                rule.Init();
                var m = new Mtch(gr, rule);
                Assert.IsTrue(gr.totalPrice > 7000);
                double rubPerM3 = gr.totalPrice / gr.totalVolume; //.totalWeight;
                Assert.IsTrue(rubPerM3 > 2000);
            }
            //foreach (var gr in model.elmGroups)
            //{
            //    Assert.IsTrue(model.Rules.Count > 0);
            //    foreach (var rule in model.Rules)
            //    {
            //        Assert.IsNotNull(rule.CompSet.Supplier);
            //        Assert.IsTrue(rule.CompSet.Components.Count > 0);
            //        Mtch _match = new Mtch(gr, rule);
            //    }
            //}
            FileOp.AppQuit();
        }
Example #7
0
        public static IRuleConfig GetPageRule(Stream stream)
        {
            IRuleConfig pageRule = null;

            using (JsonReader jsonReader = new JsonTextReader(new StreamReader(stream)))
            {
                JObject jObject = JObject.Load(jsonReader);

                var jTokens = jObject["Pages"]?.AsJEnumerable();

                if (jTokens != null)
                {
                    var _pageRule = new RuleConfig();

                    foreach (var jToken in jTokens)
                    {
                        PageType pageType;

                        if (!Enum.TryParse(jToken?.Value <string>("PageType"), out pageType))
                        {
                            continue;
                        }

                        Page page = new Page();

                        if (Boolean.TryParse(jToken?.Value <string>("UseProxy"), out bool useProxy))
                        {
                            page.UseProxy = useProxy;
                        }

                        var jRules = jToken["Rules"].AsJEnumerable();

                        foreach (var jRule in jRules)
                        {
                            Rule.Rule rule = new Rule.Rule()
                            {
                                Name  = jRule?.Value <string>("Name"),
                                XPath = jRule?.Value <string>("XPath"),
                                Fun   = (Rule.Rule.RuleFun)Enum.Parse(typeof(Rule.Rule.RuleFun), jRule?.Value <string>("Fun")),
                                Param = jRule?.Value <string>("Param"),
                            };
                            page.Add(rule);
                        }

                        _pageRule.AddRule(pageType, page);
                    }

                    pageRule = _pageRule;
                }
            }

            return(pageRule);
        }
Example #8
0
        ///////////////////// <summary>
        ///////////////////// setComp(doc) - fill price list of Components from doc
        ///////////////////// setComp(doc_name) - overload
        ///////////////////// </summary>
        ///////////////////// <param name="doc">price-list</param>
        ///////////////////// <returns>List of Components</returns>
        ///////////////////// <history>26.3.2016
        /////////////////////  3.4.2016 - setComp(doc_name) overload
        /////////////////////  8.4.2016 - remove unnecteesary fields - bug fix
        ///////////////////// 14.4.2016 - field mat = Material fill
        /////////////////////  </history>
        //////////////////public static List<Component> setComp(string doc_name)
        //////////////////{ return setComp(Docs.getDoc(doc_name)); }
        //////////////////public static List<Component> setComp(Docs doc)
        //////////////////{
        //////////////////    Log.set("setComp(" + doc.name + ")");
        //////////////////    List<int> docCompPars = Lib.GetPars(doc.LoadDescription);
        //////////////////    //-- заполнение массива комплектующих Comps из прайс-листа металлопроката
        //////////////////    List<Component> Comps = new List<Component>();
        //////////////////    for (int i = doc.i0; i <= doc.il; i++)
        //////////////////    {
        //////////////////        try
        //////////////////        {
        //////////////////            string descr = doc.Body.Strng(i, docCompPars[0]);
        //////////////////            double lng = 0;
        //////////////////            //-- разбор параметров LoadDescription

        //////////////////            List<int> strPars = Lib.GetPars(descr);
        //////////////////            string docDescr = doc.LoadDescription;
        //////////////////            int parShft = 0;
        //////////////////            while (docDescr.Contains('/'))
        //////////////////            {
        //////////////////                string[] s = doc.LoadDescription.Split('/');
        //////////////////                List<int> c = Lib.GetPars(s[0]);
        //////////////////                int pCol = c[c.Count() - 1];    // колонка - последний параметр до '/'
        //////////////////                List<int> p = Lib.GetPars(s[1]);
        //////////////////                lng = strPars[p[0] - 1];    // длина заготовки = параметр в str; индекс - первое число после '/'
        // 29/3/2017 /////                docDescr = docDescr.Replace("/", "");
        //  устарело /////                parShft++;
        //////////////////            }
        //////////////////            if (lng == 0)
        //////////////////                lng = doc.Body.Int(i, docCompPars[1]) / 1000;    // для lng указана колонка в LoadDescription
        //////////////////            double price = doc.Body.Double(i, docCompPars[2] + parShft);
        //////////////////            double wgt = 0.0;   //!!! времянка -- пока вес будем брать только из Tekla
        //////////////////            string mat = "";    //!!! времянка -- материал нужно извлекать из description или описания - еще не написано!
        //////////////////            Comps.Add(new Component(descr, mat, lng, wgt, price));
        //////////////////        }
        //////////////////        catch { Msg.F("Err in setComp", doc.name); }
        //////////////////    }
        //////////////////    Log.exit();
        //////////////////    return Comps;
        //////////////////}

        public bool isMatch(ElmAttSet.Group gr, Rule.Rule rule = null) //25/3 Dictionary<SecTYPE,List<string>> ruleFPs = null)
        {
            if (!isMatchGrRule(SType.Material, gr, rule))
            {
                return(false);
            }
            if (!isMatchGrRule(SType.Profile, gr, rule))
            {
                return(false);
            }
            return(true);
        }
Example #9
0
        ///////////////////// <summary>
        ///////////////////// setComp(doc) - fill price list of Components from doc
        ///////////////////// setComp(doc_name) - overload
        ///////////////////// </summary>
        ///////////////////// <param name="doc">price-list</param>
        ///////////////////// <returns>List of Components</returns>
        ///////////////////// <history>26.3.2016
        /////////////////////  3.4.2016 - setComp(doc_name) overload
        /////////////////////  8.4.2016 - remove unnecteesary fields - bug fix
        ///////////////////// 14.4.2016 - field mat = Material fill
        /////////////////////  </history>
        //////////////////public static List<Component> setComp(string doc_name)
        //////////////////{ return setComp(Docs.getDoc(doc_name)); }
        //////////////////public static List<Component> setComp(Docs doc)
        //////////////////{
        //////////////////    Log.set("setComp(" + doc.name + ")");
        //////////////////    List<int> docCompPars = Lib.GetPars(doc.LoadDescription);
        //////////////////    //-- заполнение массива комплектующих Comps из прайс-листа металлопроката
        //////////////////    List<Component> Comps = new List<Component>();
        //////////////////    for (int i = doc.i0; i <= doc.il; i++)
        //////////////////    {
        //////////////////        try
        //////////////////        {
        //////////////////            string descr = doc.Body.Strng(i, docCompPars[0]);
        //////////////////            double lng = 0;
        //////////////////            //-- разбор параметров LoadDescription

        //////////////////            List<int> strPars = Lib.GetPars(descr);
        //////////////////            string docDescr = doc.LoadDescription;
        //////////////////            int parShft = 0;
        //////////////////            while (docDescr.Contains('/'))
        //////////////////            {
        //////////////////                string[] s = doc.LoadDescription.Split('/');
        //////////////////                List<int> c = Lib.GetPars(s[0]);
        //////////////////                int pCol = c[c.Count() - 1];    // колонка - последний параметр до '/'
        //////////////////                List<int> p = Lib.GetPars(s[1]);
        //////////////////                lng = strPars[p[0] - 1];    // длина заготовки = параметр в str; индекс - первое число после '/'
        // 29/3/2017 /////                docDescr = docDescr.Replace("/", "");
        //  устарело /////                parShft++;
        //////////////////            }
        //////////////////            if (lng == 0)
        //////////////////                lng = doc.Body.Int(i, docCompPars[1]) / 1000;    // для lng указана колонка в LoadDescription
        //////////////////            double price = doc.Body.Double(i, docCompPars[2] + parShft);
        //////////////////            double wgt = 0.0;   //!!! времянка -- пока вес будем брать только из Tekla
        //////////////////            string mat = "";    //!!! времянка -- материал нужно извлекать из description или описания - еще не написано!
        //////////////////            Comps.Add(new Component(descr, mat, lng, wgt, price));
        //////////////////        }
        //////////////////        catch { Msg.F("Err in setComp", doc.name); }
        //////////////////    }
        //////////////////    Log.exit();
        //////////////////    return Comps;
        //////////////////}
#endif
        public bool isMatch(Group.Group gr, Rule.Rule rule = null)
        {
            if (!isMatchGrRule(SType.Material, gr, rule))
            {
                return(false);
            }
            if (!isMatchGrRule(SType.Profile, gr, rule))
            {
                return(false);
            }
            return(true);
        }
Example #10
0
 ////////////////public CompSet(string _name, List<Component.Component> _comps, Supl _supl, Docs _doc, List<FP> _csFPs)
 ////////////////{
 ////////////////    this.name       = _name;
 ////////////////    this.Components = _comps;
 ////////////////    this.Supplier   = _supl;
 ////////////////    this.doc        = _doc;
 ////////////////    this.csFPs      = _csFPs;
 ////////////////}
 public CompSet(string _name, Supl _supl, Rule.Rule _rule)
 {
     name     = _name;
     Supplier = _supl;
     doc      = getCSdoc(Supplier, _name);
     csFPs    = _rule.Parser(FP.type.CompSet, doc.LoadDescription);
     for (int i = doc.i0; i < doc.il; i++)
     {
         Comp comp = new Comp(doc, i, csFPs);
         Components.Add(comp);
     }
 }
Example #11
0
        public void UT_PriceGr_Msg()
        {
            // Assign
            boot.Init();
            Rule.Rule rule = new Rule.Rule();
            rule.sSupl = "СтальХолдинг";
            rule.sCS   = "Полоса";
            rule.text  = "М: C245=C255 ; Профиль: Полоса горячекатаная = PL = — *x*;";
            ElmGr gr = new ElmGr();

            gr.SupplierName = rule.sSupl;
            gr.guids        = new List <string>()
            {
                "guid1", "guid2"
            };

            // test 1: Msg.F("Rules not initialyzed") English
            string s = sub_PriceGr(mod, gr, "en");

            Assert.AreEqual("Rules in Model were not initialyzed", s);

            // test 2: Msg.F("Rules not initialyzed") Russian
            s = sub_PriceGr(mod, gr, "ru");
            Assert.AreEqual("Не инциированы правила модели", s);

            // test 3: Rules initialyzed, works with CompSet and Components, Rule, MsgF Wrong LoadDescriptor
            gr.Prf    = "I20"; gr.prf = "i20";
            rule.text = "Профиль: Балка =I*";
            string comp_txt = "Балка 20";

            rule.ruleDP   = new DPar.DPar(rule.text);
            rule.synonyms = rule.RuleSynParse(rule.text);
            //           var syns = rule.synonyms[Section.Section.SType.Profile].ToList();
            List <Comp> comps = new List <Comp>()
            {
                new Comp(new DP("Prf:I10; Price:23456")),
                new Comp(new DP("Prf:I20; Price:34567"))
            };
            Supl   supl           = new Supl("СтальХолдинг", init: false);
            string LoadDescriptor = "M:1; опис:3; профиль:2; цена: 4; Ед: руб/т";
            CS     cs             = new CS("Балка", supl, LoadDescriptor, comps);
            Comp   comp           = new Comp();

            comp.compDP = new DP("Prf: " + comp_txt);
            mod.Rules.Add(rule);
            rule.CompSet = cs;
            s            = sub_PriceGr(mod, gr, "en", _prefix: "Msg.W: ");
            Assert.AreEqual("CompSet_wrong_LoadDescriptor", s);

            FileOp.AppQuit();
        }
Example #12
0
        //////////////        private void test_getSectionText()
        //////////////        {
        //////////////            Log.set("test_getSectionTest(Section.Material, text");
        //28/5/////////////// 7/3/2017 /////////////////            TST.Eq(getSectionText(FP.Section.Material, "Профиль: L 20 x 5; M: C245; Price: 2690"), "c245");
        //////////////            Log.exit();
        //////////////        }

        //////////////private void test_isSectionMatch()
        //////////////{
        //////////////    Log.set("isSectionMatch(Section.Material, C245, rule.text)");

        //////////////    /////// 7/3/2017 ////            bool ok = isSectionMatch(FP.Section.Material, "C245", "Профиль: L * x * ст*; длина: * = * м; M: ст *;");

        //////////////    Log.exit();
        //////////////}

        private void test_Mtch_1()
        {
            Log.set(" test_Mtch_1: Rule 4 и Group<C255, L20x4>");
            Rule.Rule rule = new Rule.Rule(4);
            ElmAttSet.ElmAttSet el = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D70-3134-353338303236",
                "C245", "Steel", "Уголок20X4", 0, 0, 0, 1000);
            Dictionary<string, ElmAttSet.ElmAttSet> els = new Dictionary<string, ElmAttSet.ElmAttSet>();
            els.Add(el.guid, el);
            List<string> guids = new List<string>(); guids.Add(el.guid);
            Group.Group gr = new Group.Group(els, "C245", "Уголок20X4", guids);
            Mtch match = new Mtch(gr, rule);
            //6/4/17            TST.Eq(match.ok == OK.Match, true);
            Log.exit();
        }
Example #13
0
        static RuleConfig()
        {
            using (JsonReader jsonReader = new JsonTextReader(new StreamReader("rule.json")))
            {
                JObject jObject = JObject.Load(jsonReader);

                var jTokens = jObject["Rule"]?.AsJEnumerable();

                if (jTokens != null)
                {
                    var _pageRule = new PageRule();

                    foreach (var jToken in jTokens)
                    {
                        PageType pageType;

                        if (!Enum.TryParse(jToken?.Value <string>("PageType"), out pageType))
                        {
                            continue;
                        }

                        Page page = new Page();

                        var jRules = jToken["Rules"].AsJEnumerable();

                        foreach (var jRule in jRules)
                        {
                            Rule.Rule rule = new Rule.Rule()
                            {
                                Name  = jRule?.Value <string>("Name"),
                                XPath = jRule?.Value <string>("XPath"),
                                Fun   = Enum.Parse <Rule.Rule.RuleFun>(jRule?.Value <string>("Fun")),
                                Param = jRule?.Value <string>("Param"),
                            };
                            page.Add(rule);
                        }

                        _pageRule.AddRule(pageType, page);
                    }

                    pageRule = _pageRule;
                }
            }
        }
Example #14
0
 void test_Mtch_2()
 {
     Log.set(" test_Mtch_2: Rule 15 и Group < B12,5 , 1900x1600 > ");
     rule = new Rule.Rule(15);
     ElmAttSet.ElmAttSet elB = new ElmAttSet.ElmAttSet(
         "ID56A7442F-0000-0D7B-3134-353338303236",
         "B12,5", "Concrete", "1900x1600", 0, 0, 0, 1000);
     Dictionary<string, ElmAttSet.ElmAttSet> els = new Dictionary<string, ElmAttSet.ElmAttSet>();
     els.Add(elB.guid, elB);
     List<string> guids = new List<string>(); guids.Add(elB.guid);
     var model = new Model.Model();
     model.setElements(els);
     model.getGroups();
     var gr = model.elmGroups[0];
     //6/4/17            TST.Eq(gr.guids.Count, 1);
     var match = new Mtch(gr, rule);
     //6/4/17           TST.Eq(match.ok == OK.Match, true);
     var cmp = match.component;
     //31/3            TST.Eq(cmp.fps[SType.Material].pars[0].par.ToString(), "b12,5");
     Log.exit();
 }
Example #15
0
        bool isMatchGrRule(SType stype, Group.Group gr, Rule.Rule rule)
        {
            if (rule == null || !compDP.dpar.ContainsKey(stype))
            {
                return(true);
            }
            string sb = new Sec(rule.text, stype).body;

            if (sb == "")
            {
                return(true);
            }
            var    ruleSyns  = rule.synonyms;
            string comMatPrf = viewComp_(stype);
            string grMatPrf  = stype == SType.Material ? gr.mat : gr.prf;

            if (ruleSyns != null && ruleSyns.ContainsKey(stype))
            {
                List <string> Syns = ruleSyns[stype].ToList();
                if (!Lib.IContains(Syns, comMatPrf) || !Lib.IContains(Syns, grMatPrf))
                {
                    return(false);
                }
                string c = strExclude(comMatPrf, Syns);
                string g = strExclude(grMatPrf, Syns);
                if (c == g)
                {
                    return(true);
                }
                string pattern = new Sec(rule.text, stype).body.Replace("=", "");
                foreach (var s in Syns)
                {
                    pattern = strExclude(pattern, Syns);
                }
                return(isOK(pattern, c, g));
            }
            return(comMatPrf == grMatPrf);
        }
Example #16
0
        /// <summary>
        /// Mtch(gr, _rule) - check if Group gr is in match with rule
        ///    if Mtch.ok.Match - return Mtch.Component chousen from CompSet.Component
        ///    else ok.NoMatch
        /// </summary>
        /// <param name="gr"></param>
        /// <param name="_rule"></param>
        public Mtch(Group.Group gr, Rule.Rule _rule)
        {
            if (gr == null || gr.guids == null || gr.guids.Count < 1)
                Msg.F("Matcher__Mtch Bad arguments");
            ok = OK.NoMatch;
            group = gr;
            foreach (var comp in _rule.CompSet.Components)
            {
                bool found = false;
                try { found = comp.isMatch(gr, _rule); }
                catch { }
                if (!found) continue;
                //-- Component is found - fill Price for all Guids elemets
                ok = OK.Match;
                string priceStr;
                try { priceStr = comp.Str(SType.Price); }
                catch { Msg.F("Match: Bad Price descriptor", _rule.sSupl, _rule.sCS); }
                component = comp;
//29/8                gr.match = this;    //27/3!!
                rule = _rule;
                gr.totalPrice = getPrice(gr, rule.CompSet.csDP, comp.Str(SType.Price));
                break;
            }
        }
Example #17
0
        public void UT_CompSet_init_Naive()
        {
            boot.Init();
            Mod mod = new Mod();

            // test 0: бетон -> должен быть DP[UNIT_Vol]
            Supl    spl = new Supl("ГК Монолит СПб");
            CompSet csb = new CompSet("Товарный бетон", spl);

            Assert.IsNotNull(csb);
            Assert.IsNotNull(csb.csDP);
            Assert.AreEqual(4, csb.csDP.dpStr.Count);
            Assert.IsTrue(csb.csDP.dpar.ContainsKey(SType.UNIT_Vol));

            // test 1: after bug "Ед: руб/т" не попадал в compDP -> compDP содержит SType.UNIT_Weight
            Supl    supl = new Supl("ЛенСпецСталь");
            CompSet cs   = new CompSet("Полоса", supl);

            Assert.IsTrue(cs.csDP.dpar.ContainsKey(SType.UNIT_Weight));


            // test 2: Check if all Rules have CompSet with Section Unit_
            mod = mod.sr.SetModel(boot, initSupl: true);
            Assert.IsTrue(mod.Rules.Count > 0);
            Rule.Rule r = mod.Rules.ToList()[3];

            foreach (var rule in mod.Rules)
            {
                var  csDP = rule.CompSet.csDP;
                bool bw   = csDP.dpStr.ContainsKey(SType.UNIT_Weight);
                bool bv   = csDP.dpStr.ContainsKey(SType.UNIT_Vol);
                Assert.IsTrue(bw || bv);
            }

            FileOp.AppQuit();
        }
Example #18
0
        ////////////////public FingerPrint(Sec.SType stype, string str, ParType parType = ParType.String)
        ////////////////{
        // 21/3 ////////    Param par = new Param(str, parType);
        ////////////////    pars.Add(par);
        ////////////////}

        public FingerPrint(string str, Rule.Rule rule, Sec sec)
        {
            FingerPrint ruleFP = rule.ruleFPs[sec.type];
            //        FingerPrint csFP = rule.CompSet.csFPs.Find(x => x.section.type == sec.type);
            SType stype = sec.type;
            var vv = rule.CompSet.csFPs;

//20/3 ЗАГЛУШКА!!            FingerPrint csFP = rule.CompSet.csFPs[stype];
            section = sec;
            string ruleText = sec.body;
            List<string> sPars = ReverseFomat(str, ruleText);
            int i = 0;
            foreach(var p in sPars)
            {
                //20/3 ЗАГЛУШКА!!                 Parameter.Parameter csPar = (Parameter.Parameter)csFP.pars[i++];
                //20/3 ЗАГЛУШКА!!                 Parameter.Parameter par = new Parameter.Parameter(str, csPar.ptype);
                //20/3 ЗАГЛУШКА!! pars.Add(par);
            }

            // str = Section.body в строке прайс-листа
            // template - Section.body в Rule.text
            // заполняет pars в FP для Component
            //12/3            foreach (var par in ReverseFormat(str, ruleText)) pars.Add(par);
        }
Example #19
0
        public void UT_comp_PL_Native()
        {
            boot.Init();
            // test 1 Native: берем группу, правила и компонент - пластину PL8 из модели
            model = model.sr.SetModel(boot);
            if (model.name != "Chasovnya+lepestok") goto exit;
            gr = model.elmGroups[23];
            Assert.AreEqual("—8", gr.prf);
            rule = new Rule.Rule(6);
            Assert.AreEqual(58, rule.text.Length);
            rule.Init();
            Assert.AreEqual(93, rule.CompSet.Components.Count);
            comp = rule.CompSet.Components[60];
            Assert.AreEqual("С245", comp.Str(SType.Material));
            Assert.AreEqual("PL8x100", comp.Str(SType.Profile));

            bool b = comp.isMatch(gr, rule);
            Assert.IsTrue(b);

            //test 2 Native: обрабатываем все группы, но проверяем только нужную - PL8
            Mtch _mtch = null;
            foreach (var g in model.elmGroups)
            {
                _mtch = new Mtch(g, rule);
                if (g.prf != "—8") continue;
                Assert.AreEqual(Mtch.OK.Match, _mtch.ok);
            }

            //test 3 Native: загружаем несколько Правил
            model.Rules.Clear();
            rule = new Rule.Rule(5);
            rule.Init();
            model.Rules.Add(rule);
            rule = new Rule.Rule(6);
            rule.Init();
            model.Rules.Add(rule);
            _mtch = null;
            Mtch found_mtch = null;
            foreach (var g in model.elmGroups)
            {
                foreach (var r in model.Rules)
                {
                    _mtch = new Mtch(g, r);
                    if (g.prf != "—8" || !r.text.Contains("—")) continue;
                    Assert.AreEqual(Mtch.OK.Match, _mtch.ok);
                    found_mtch = _mtch;
                    break;
                }
            }
            Assert.AreEqual("Полоса", found_mtch.rule.sCS);

            //test 4 Native with Handle, init all rules
            model.Rules.Clear(); model.matches.Clear();
            Docs rRule = Docs.getDoc("Rules", fatal: false, create_if_notexist: false);
            for (int i = 4; i < rRule.il; i++)
            {
                rule = new Rule.Rule(i);
                rule.Init();
                model.Rules.Add(rule);
            }
            model.mh.Hndl(ref model);
            foreach (var m in model.matches)
            {
                if (m.group.prf != "—8") continue;
                Assert.AreEqual(Mtch.OK.Match, m.ok);
                Assert.AreEqual("Полоса", m.rule.sCS);
                Assert.AreEqual("СтальХолдинг", m.rule.sSupl);
            }

            //test 5 Native with Pricing
            model.Rules.Clear(); model.matches.Clear();
            model.mh.Pricing(ref model);
            if (model.name != "Chasovnya+lepestok") goto exit;
            bool c235found = false;
            //проверим, что это в самом деле правила из TSmatchINFO/Rules - есть С235
            foreach (var r in model.Rules)
            {
                if (!r.text.Contains("235")) continue;
                c235found = true;
                break;
            }
            Assert.IsTrue(c235found);
            //полоса PL8 находится в matches[23]
            Mtch found_match = model.matches[23];
            Assert.AreEqual(Mtch.OK.Match, found_match.ok);
            Assert.AreEqual("Полоса", found_match.rule.sCS);
            Assert.AreEqual("СтальХолдинг", found_match.rule.sSupl);

            exit: FileOp.AppQuit();
        }