Пример #1
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);
        }
Пример #2
0
        public void UT_ModHandler_PrfUpdate()
        {
            var mod = new ModHandler();

            ElmAttSet.Group gr = new ElmAttSet.Group();

            // test 1: "—100*6" => "—6x100"
            gr.Prf = gr.prf = "—100*6";
            mod.elmGroups.Add(gr);
            mod.PrfUpdate();
            var v = mod.elmGroups[0].prf;

            Assert.AreEqual(v, "—6x100");

            // test 2: "—100*6" => "—6x100"
            gr.Prf = gr.prf = "—100*6";
            mod.elmGroups.Add(gr);
            mod.PrfUpdate();
            v = mod.elmGroups[1].prf;
            Assert.AreEqual(v, "—6x100");

            // test 3: "L75X5_8509_93" => L75x5"
            gr.Prf = gr.prf = "L75X5_8509_93";
            mod.elmGroups.Add(gr);
            mod.PrfUpdate();
            v = mod.elmGroups[2].prf;
            Assert.AreEqual(v, "L75x5");
        }
Пример #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);
        }
Пример #4
0
        /// <summary>
        /// Имитация группировки из ElmAttSet.Group
        /// </summary>
        /// <param name="i">номер группы</param>
        internal ElmAttSet.Group IM_Group(string mat = "", string prf = "")
        {
            var model    = IM_Model();
            var elements = IM_Elements();

            mat = Lib.ToLat(mat).ToLower().Replace(" ", "");
            prf = Lib.ToLat(prf).ToLower().Replace(" ", "");
            ElmAttSet.Group result = null;
            model.setElements(elements.Values.ToList());
            model.getGroups();
            foreach (var gr in model.elmGroups)
            {
                if (mat != "" && gr.mat != mat)
                {
                    continue;
                }
                if (prf != "" && gr.prf != prf)
                {
                    continue;
                }
                result = gr;
            }
            if (result == null)
            {
                Assert.Fail();
            }
            return(result);
        }
Пример #5
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);
        }
Пример #6
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);

            ElmAttSet.Group gr    = new ElmAttSet.Group(els, "C245", "Уголок20X4", guids);
            Mtch            match = new Mtch(gr, rule);

//6/4/17            TST.Eq(match.ok == OK.Match, true);
            Log.exit();
        }
Пример #7
0
        public Rule.Rule rule;                  //the rule, which manage the matching

        /// <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(ElmAttSet.Group gr, Rule.Rule _rule)
        {
            if (gr.prf.Contains("ш2") /* && _rule.text.Contains("д") */)
            {
                rule = _rule;
            }


            if (gr == null || gr.guids.Count < 1)
            {
                return;
            }
            ok    = OK.NoMatch;
            group = gr;
            foreach (var comp in _rule.CompSet.Components)
            {
                if (!comp.isMatch(gr, _rule))
                {
                    continue;
                }
                //-- Component is found - fill Price for all Guids elemets
                ok            = OK.Match;
                component     = comp;
                gr.match      = this; //27/3!!
                rule          = _rule;
                gr.totalPrice = 0;
                foreach (var id in gr.guids)
                {
                    Elm    elm      = gr.Elements[id];
                    string priceStr = comp.Str(SType.Price);
                    double price    = getPrice(elm, rule.CompSet.csDP, priceStr);
                    gr.Elements[id].price = price;
                    gr.totalPrice        += price;
                }
                break;
            }
        }
Пример #8
0
        public void UT_Model_getGroup()
        {
            var Im    = new IMIT();
            Mod model = Im.IM_Model();
            Dictionary <string, Elm> elements = Im.IM_Elements();
            string        id1 = "MyId1", id2 = "MyId2";
            string        mat = elements[id1].mat;
            string        prf = elements[id1].prf;
            List <string> guids = new List <string> {
                id1, id2
            };

            ElmAttSet.Group gr = new ElmAttSet.Group(elements, mat, prf, guids);

            Assert.AreEqual(gr.totalPrice, elements[id1].price + elements[id2].price);

            model.setElements(elements.Values.ToList());
            model.getGroups();
            Assert.AreEqual(model.elmGroups.Count, 3);
            Assert.AreEqual(model.elmGroups[0].mat, mat);
            Assert.AreEqual(model.elmGroups[0].prf, prf);
            Assert.AreEqual(model.elmGroups[0].totalPrice, 0);
            Assert.AreEqual(model.elmGroups[0].guids.Count, 2);
            Assert.AreEqual(model.elmGroups[1].guids.Count, 1);
            var gds0 = model.elmGroups[0].guids;

            Assert.AreEqual(gds0[0], id1);
            Assert.AreEqual(gds0[1], id2);
            Assert.AreEqual(model.elmGroups[1].totalPrice, 0);

            var grB = Im.IM_Group("B20");

            Assert.AreEqual(grB.mat, "b20");
            Assert.AreEqual(grB.prf, "1900x1600");
            Assert.AreEqual(grB.guids.Count, 2);
        }