Beispiel #1
0
        public Component(Dictionary <SType, string> comp
                         , Dictionary <SType, FP> cs_fps)
        {
            bool flag = false;

            foreach (var fpD in cs_fps)
            {
                FP     csFP   = fpD.Value;
                FP     compFP = new FP();
                string str    = comp[fpD.Key];
                Sec    s      = new Sec(str);
                string ld     = csFP.parN();
                if (ld.Contains('*'))       // * template
                {
                    compFP.pars = s.secPars(ld);
//30/3                    s.txs =
                    break;
                }
                if (ld.Contains('{'))       // {2} Col() Parameter
                {
                    compFP.pars.Add(new Parameter.Parameter(ld));
                    break;
                }
                fps.Add(fpD.Key, compFP);
            }
        }
Beispiel #2
0
        public void UT_Section_secPars()
        {
            var sec = new Sec("проф:Уголок 40х4 ст3");
            var ps = sec.secPars("Уголок * х *c*");
            Assert.AreEqual(ps[0].parStr(), "40");
            Assert.AreEqual(ps[1].parStr(), "4");
            Assert.AreEqual(ps[2].parStr(), "т3");

            // случай 1) const , напр. templ=материал С235
            sec = new Sec("");  //то есть в прайс-листе этой колонки нет
            ps = sec.secPars("M:C235");
            Assert.AreEqual(ps.Count, 0);

            // случай 2)  *    , напр. templ="Уголок *х*" comp= "Уголок 40x8"
            sec = new Sec("Уголок 40х4");
            ps = sec.secPars("проф: опис: Уголок * х * ");
            Assert.AreEqual(ps.Count, 2);
            Assert.AreEqual(ps[0].parStr(), "40");
            Assert.AreEqual(ps[1].parStr(), "4");

            // случай 3) {4}   , напр. templ="{4}"        comp= "Уголок 40x8" в кол 4
            sec = new Sec("Уголок 40x8");
            ps = sec.secPars("{4}");
            Assert.AreEqual(ps.Count, 0);
            Assert.AreEqual(sec.body, "угoлoк40x8");

            // случай 4) ссылка, напр. templ="проф:опис: Уголок *х*с*" 
            //                                          comp= "Уголок 40х8" ps 40 и 8
            sec = new Sec("Уголок 40х8");
            ps = sec.secPars("проф: опис: Уголок * х * ");
            Assert.AreEqual(ps.Count, 2);
            Assert.AreEqual(ps[0].parStr(), "40");
            Assert.AreEqual(ps[1].parStr(), "8");
        }
Beispiel #3
0
        public void UT_FP_Component_constr2()
        {
            var Im = new IMIT();
            var rule = Im.IM_Rule("M:*;Проф:Уголок равнопол.=Уголок *x*c*");
            var sec = new Sec("M:");

            var fpMat = new FP("Уголок 75х6 6м Ст3пс/сп5", rule, sec);

            //////////////////var csFPmat = new FP(FPtype.CompSet, "M:{2}");
            // 27/3 //////////var csFPprf = new FP(FPtype.CompSet, "Prf:Уголок {1}");
            //////////////////var csFPs = new List<FP> { csFPmat, csFPprf };
            
            // 23.3.2017 пока решил не позволять использовать несколько параметров в строке
            //xr1 = new FP(FPtype.CompSet, "Цена: {4} НДС {12}{14}%");
            //Assert.AreEqual(xr1.pars.Count, 3);
            //Assert.AreEqual(xr1.txs[3], "%");
            //Assert.AreEqual(xr1.Col(2), 14);
            //Assert.AreEqual(xr1.txs.Count, 4);
            //Assert.AreEqual(xr1.typeFP.ToString(), "CompSet");
            //Assert.AreEqual(xr1.section.type.ToString(), "Price");
            //Assert.AreEqual(xr1.Col(), 4);
            //var sec = new Sec("Prf: L12x5");
            //19/3            FP fp = new FP(sec);
            Assert.Fail();
        }
Beispiel #4
0
 //--- FP constructor 1 for Rule and CompSet
 public FingerPrint(type _type, string str)
 {
     typeFP = _type;    
     section = new Sec(str);
     refSection = section.refSection;
     Par p = new Par(str);
     pars.Add(p);
     txs.Add(p.tx);
 }
Beispiel #5
0
        public void UT_isSectionMatch()
        {
            var sec = new Sec("Prf: L12x5");

            bool b = sec.isSectionMatch("профиль:l*x*");
            Assert.AreEqual(b, true);

            Assert.AreEqual(sec.isSectionMatch("M: C245; профиль:l*x*"), true);

            Assert.AreEqual(sec.isSectionMatch("M: C245"), false);

            Assert.AreEqual(sec.isSectionMatch("профиль:Шв*x*"), false);
        }
Beispiel #6
0
            public initSection()
            {
                sub(SType.Material, "MAT", "m");
                sub(SType.Profile, "PRF", "pro", "пр");
                sub(SType.Price, "CST", "cost", "pric", "цен", "сто");
                sub(SType.Description, "DES", "оп", "знач");
                sub(SType.LengthPerUnit, "LNG", "leng", "длин");
                sub(SType.VolPerUnit, "VOL", "об");
                sub(SType.WeightPerUnit, "WGT", "вес", "w");
                sub(SType.Unit, "UNT", "ед", "un");

                var s = new Sect(SectionTab);
            }
Beispiel #7
0
        /// <summary>
        /// FingerPrint(str, FP csFP, ref flag) -- FP constructor- specially for Component
        /// </summary>
        /// <param name="str">string to be parsed with CompSet FPs</param>
        /// <param name="_section">section of str the FP belongs to</param>
        /// <param name="csFPs">FP  from CompSet</param>
        /// <note>
        /// - parse str with csFP to put price-list parameters in this FP
        /// - quantity of tx in txs is always pars.Count (may be +1)
        /// - 
        /// </note>
            //////////////////public FingerPrint(string str, List<FingerPrint> csFPs, ref bool flag)
            //////////////////{
            //////////////////    typeFP = type.Component;
            //////////////////    flag = false;
            //////////////////    str = Lib.ToLat(str).ToLower();
            //////////////////    section = (Section)RecognyseSection(str);
            //////////////////    FingerPrint csFP = csFPs.Find(x => x.section == section);
            //////////////////    if (csFP == null) Msg.F("No Section \"" + section + " in csFPs");
            //////////////////    int ind = str.IndexOf(':') + 1;
            //////////////////    foreach (var tx in csFP.txs)
            //////////////////    {
            //////////////////        int lng = Math.Min(str.Length, tx.Length);
            /// 28/2/2017 ////        while (string.IsNullOrWhiteSpace(str[ind].ToString())) ind++;
            //////////////////        string s_str = str.Substring(ind, lng);
            //////////////////        string s_tx  = tx.Substring(0, lng);
            //////////////////        if (!isMatchStr(s_str, s_tx)) return;   //по несоответствию tx надо разбираться с синонимами - потом
            //////////////////        flag = true;
            //////////////////        txs.Add(s_tx);
            //////////////////        ind += tx.Length;
            //////////////////        bool isBrackets;
            //////////////////        string par = getPar(str, ref ind, out isBrackets);
            //////////////////        pars.Add(par);
            //////////////////        // 27/02 //                if (isBrackets) pars.Add(par); else txs.Add(par);
            //////////////////    }
            //////////////////}

        public FingerPrint(string str, FingerPrint csFP, out bool flag)
        { 
            flag = false;
            typeFP = type.Component;
            if (string.IsNullOrEmpty(str) || csFP == null) return;
            flag = true;
            section = csFP.section;
            if(str.Contains("*"))
            {
                pars = section.secPars(str);
            }
            Par par = new Par(str);
            pars.Add(par);
        }
Beispiel #8
0
 public DPar(string str)
 {
     string[] sections = str.Split(';');
     foreach (string sec in sections)
     {
         Sec txSec = new Sec(sec);
         if (txSec.type == SType.NOT_DEFINED)
         {
             continue;
         }
         dpar.Add(txSec.type, txSec.body);           // with ToLat.Tolower
         int indx = sec.IndexOf(':') + 1;
         dpStr.Add(txSec.type, sec.Substring(indx)); // initial body
     }
 }
Beispiel #9
0
        //--- FP constructor 2 for Component
#if DEBUG   //--- 29-Mar-2017 Вариант конструктора для UT
        public FingerPrint(SType stype, dynamic obj)
        {
            typeFP = type.Component;
            if (stype == SType.Description)
            {
                Par p = new Par(obj);
                p.par = p.tx = obj;
                pars.Add(p);
                return;
            }
            section = new Sec(stype.ToString() + ":");
            string str = "";
            if (obj.GetType() == typeof(string)) str = (string)obj;
            if (obj.GetType() == typeof(double)) str = ((double)obj).ToString();
            pars.Add(new Par(str));
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public void UT_Section()
        {
            Sect s = new Sect("hh");

            Assert.AreEqual(SType.NOT_DEFINED, s.type);

            s = new Sect(string.Empty);
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            s = new Sect("M: qq");
            Assert.AreEqual(s.type, SType.Material);
            Assert.AreEqual(s.body, "qq");

            s = new Sect("Prf: x; price: y;");
            Assert.AreEqual(s.type, SType.Profile);
            Assert.AreEqual(s.body, "x");

            s = new Sect("Описание: xx");
            Assert.AreEqual(s.type, SType.Description);
            Assert.AreEqual(s.body, "xx");

            s = new Sect("длина: 5");
            Assert.AreEqual(s.type, SType.LengthPerUnit);
            Assert.AreEqual(s.body, "5");

            s = new Sect("Объем: 7");
            Assert.AreEqual(s.type, SType.VolPerUnit);
            Assert.AreEqual(s.body, "7");

            s = new Sect("вес: 77");
            Assert.AreEqual(s.type, SType.WeightPerUnit);
            Assert.AreEqual(s.body, "77");

            // test err 24/11/17: err:
            s = new Sect("Ед: руб/т");
            Assert.AreEqual(SType.UNIT_Weight, s.type);
            Assert.AreEqual("", s.body);

            s = new Sect("Ед: за м ");
            Assert.AreEqual(SType.UNIT_Length, s.type);
            Assert.AreEqual("", s.body);

            s = new Sect("Ед: руб/м3 ");
            Assert.AreEqual(SType.UNIT_Vol, s.type);
            Assert.AreEqual("", s.body);

            s = new Sect("единица: ");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            //----- error input text handling -----
            s = new Sect("Цена 2540");   // no ':'
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "цeнa2540");
            // то есть s.body заполняется, хотя заголовок секции не распознан

            s = new Sect("Цена 2540;");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "цeнa2540");

            s = new Sect("; профиль: L");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            //--- construtor Section("..;..;", SType) test
            //           -> SType.Unit не находим, возвращаем SType.NOT_DEFINED
            s = new Sect(";проф: Sec; Mat: n", SType.Unit);
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            // из строки с секциями Материал и Профиль -> выбор второй секции
            s = new Sect("m: c255=c245; пpoфиль: yгoлoк=l *x*;", SType.Profile);
            Assert.AreEqual("yгoлoк=l*x*", s.body);
            Assert.AreEqual(SType.Profile, s.type);

            // performatce test 10 000 циклов за < 1 сек, т.е. на Sect 100 микросекунд
            int      cnt = 100000;
            DateTime t0  = DateTime.Now;

            for (int i = 0; i < cnt; i++)
            {
                string hdr  = "Prof" + i % 10;
                string body = " A" + i % 15;
                string x    = hdr + ":" + body + ";";
                s = new Sect(x);
            }
            DateTime t1 = DateTime.Now;
            TimeSpan d  = t1 - t0;
        }
Beispiel #12
0
 public void UT_Section_SecRef()
 {
     var s = new Sec("Profile: Descr: Уголок *х*");
     Assert.AreEqual(s.refSection, SType.Description);
     Assert.AreEqual(s.type, SType.Profile);
 }
Beispiel #13
0
        public void UT_Section_Test()
        {
            var SectionTab = new Bootstrap.Bootstrap.initSection().SectionTab;
            Assert.AreEqual(SectionTab != null, true);

            var s = new Sec("hh");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "hh");

            s = new Sec(string.Empty);
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            s = new Sec("M: qq");
            Assert.AreEqual(s.type, SType.Material);
            Assert.AreEqual(s.body, "qq");

            s = new Sec("мат: В20");
            Assert.AreEqual(s.type, SType.Material);

            s = new Sec("Prf: x; price: y;");
            Assert.AreEqual(s.type, SType.Profile);
            Assert.AreEqual(s.body, "x");

            s = new Sec("Описание: xx");
            Assert.AreEqual(s.type, SType.Description);
            Assert.AreEqual(s.body, "xx");

            s = new Sec("Des:{1}");
            Assert.AreEqual(s.type, SType.Description);
            Assert.AreEqual(s.body, "{1}");

            s = new Sec("длина: 5");
            Assert.AreEqual(s.type, SType.LengthPerUnit);
            Assert.AreEqual(s.body, "5");

            s = new Sec("Объем: 7");    //Внимание!! Слово Объем содержит букву 'м'
                                        //.. его нельзя употреблять в заголовках Секций
            Assert.AreEqual(s.type, SType.Material);
            Assert.AreEqual(s.body, "7");

            s = new Sec("кубометров: ");
            Assert.AreEqual(s.type, SType.Material);    //.. тоже нельзя

            s = new Sec("v: заливка в кубометрах");
            Assert.AreEqual(s.type, SType.VolPerUnit);  //..но можно использовать 'м' в теле

            s = new Sec("вес: 77");
            Assert.AreEqual(s.type, SType.WeightPerUnit);
            Assert.AreEqual(s.body, "77");

            s = new Sec("единица: ");
            Assert.AreEqual(s.type, SType.Unit);
            Assert.AreEqual(s.body, "");

            //-- multi-header string
            s = new Sec("M: hh: dd: ff : gh");
            Assert.AreEqual(s.type, SType.Material);
            Assert.AreEqual(s.body, "gh");

            s = new Sec("Prf: Def: Уголок40х4");
            Assert.AreEqual(s.type, SType.Profile);
            Assert.AreEqual(s.body, "угoлoк40x4");

            //----- error input text handling -----
            s = new Sec("Цена 2540");   // no ':'
            Assert.AreEqual(s.type, SType.Price);
            Assert.AreEqual(s.body, "цeнa2540");

            s = new Sec("Цена 2540;");
            Assert.AreEqual(s.type, SType.Price);
            Assert.AreEqual(s.body, "цeнa2540");

            s = new Sec("; профиль: L");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            //--- construtor Section("..;..;", SType) test
            s = new Sec(";проф: Sec; Mat: n", SType.Profile);
            Assert.AreEqual(s.type, SType.Profile);
            Assert.AreEqual(s.body, "sec");

            s = new Sec(";проф: Sec; Mat: n", SType.Unit);
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");
        }
Beispiel #14
0
        public void UT_Section_Test()
        {
            new Bootstrap.Bootstrap.initSection();

            var s = new UT_Sec("hh");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);

            s = new UT_Sec(string.Empty);
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            s = new UT_Sec("M: qq");
            Assert.AreEqual(s.type, SType.Material);
            Assert.AreEqual(s.body, "qq");

            s = new UT_Sec("Prf: x; price: y;");
            Assert.AreEqual(s.type, SType.Profile);
            Assert.AreEqual(s.body, "x");

            s = new UT_Sec("Описание: xx");
            Assert.AreEqual(s.type, SType.Description);
            Assert.AreEqual(s.body, "xx");

            s = new UT_Sec("длина: 5");
            Assert.AreEqual(s.type, SType.LengthPerUnit);
            Assert.AreEqual(s.body, "5");

            s = new UT_Sec("Объем: 7");
            Assert.AreEqual(s.type, SType.VolPerUnit);
            Assert.AreEqual(s.body, "7");

            s = new UT_Sec("вес: 77");
            Assert.AreEqual(s.type, SType.WeightPerUnit);
            Assert.AreEqual(s.body, "77");

            s = new UT_Sec("единица: ");
            Assert.AreEqual(s.type, SType.Unit);
            Assert.AreEqual(s.body, "");

            //----- error input text handling -----
            s = new UT_Sec("Цена 2540");   // no ':'
            Assert.AreEqual(s.type, SType.Price);
            Assert.AreEqual(s.body, "");

            s = new UT_Sec("Цена 2540;");
            Assert.AreEqual(s.type, SType.Price);
            Assert.AreEqual(s.body, "");

            s = new UT_Sec("; профиль: L");
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");

            //--- construtor Section("..;..;", SType) test
            s = new UT_Sec(";проф: Sec; Mat: n", SType.Profile);
            Assert.AreEqual(s.type, SType.Profile);
            Assert.AreEqual(s.body, "sec");

            s = new UT_Sec(";проф: Sec; Mat: n", SType.Unit);
            Assert.AreEqual(s.type, SType.NOT_DEFINED);
            Assert.AreEqual(s.body, "");
        }