/// <summary> /// GetTSmatchINFO(Model) - Main SaveReport method. Read TSmatchINFO.xlsx and Raw.xml /// </summary> /// <remarks>When no TSmatchINFO.xlsx or Raw.xml files exists, create (or mark to create) them, and check model integrity</remarks> protected void GetTSmatchINFO(Mod mod, bool initRules = false) { Log.set("SR.GetTSmatchINFO(\"" + mod.name + "\")"); model = mod; dINFO = Docs.getDoc(sINFO, fatal: false); if (dINFO == null) error(); model.elements = Raw(model); if (model.isChanged) { //-- no information available from TSmatchINFO.xlsx or it was changed -- doing re-Pricing model.mh.Pricing(ref model, initRules); } else { //- get ModelINFO and pricing from TSmatchINFO.xlsx model.name = dINFO.Body.Strng(Decl.MODINFO_NAME_R, 2); model.setCity(dINFO.Body.Strng(Decl.MODINFO_ADDRESS_R, 2)); //20/8/2017 model.dir = dINFO.Body.Strng(Decl.MODINFO_DIR_R, 2).Trim(); model.date = Lib.getDateTime(dINFO.Body.Strng(Decl.MODINFO_DATE_R, 2)); model.pricingDate = Lib.getDateTime(dINFO.Body.Strng(Decl.MODINFO_PRCDAT_R, 2)); model.pricingMD5 = dINFO.Body.Strng(Decl.MODINFO_PRCMD5_R, 2); GetSavedReport(); GetSavedRules(model, initRules); } if (!CheckModelIntegrity(model)) error(); Log.exit(); }
/// <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); }
private void initGr(string v) { elmGroups.Clear(); gr.Prf = v; gr.prf = Lib.ToLat(v.ToLower()); elmGroups.Add(gr); }
public W_Supplier() { InitializeComponent(); Title = "TSmatch: выбор поставщика"; List <Spl> items = new List <Spl>(); Docs doc = Docs.getDoc(Decl.SUPPLIERS); for (int i = doc.i0; i <= doc.il; i++) { Supl s = new Supl(i); if (s == null || string.IsNullOrWhiteSpace(s.Name) || string.IsNullOrWhiteSpace(s.City)) { continue; } items.Add(new Spl(s.Name, Lib.ToInt(s.Index), s.City, s.Street, s.Url)); suppliers.Add(s); } Spl oldSupl = items.Find(x => x.SuplName == MainWindow.SuplName); if (oldSupl == null) { Msg.F("W_Supplier: No Selected SuplName"); } int ind = items.IndexOf(oldSupl); items[ind].Flag = true; log.Info("Supplier.Count=" + suppliers.Count + "\tInitial Supplier =\"" + oldSupl.SuplName + "\""); items.Sort(); Suppliers.ItemsSource = items; }
//check if с - part of current Component, and g - part of group //.. is in match in terms of template pattern string with wildcards public bool isOK(string pattern, string c, string g) { var p_c = rulePar(pattern, c); var p_g = rulePar(pattern, g); int cnt = Math.Min(p_c.Count, p_g.Count); for (int i = 0; i < cnt; i++) { if (p_c[i] == p_g[i]) { continue; } if (p_c[i][0] != '@') { return(false); } List <int> pc = Lib.GetPars(p_c[i].Substring(1)); List <int> pg = Lib.GetPars(p_g[i].Substring(1)); int minPars = Math.Min(pc.Count, pg.Count); for (int n = 0; n < minPars; n++) { if (pc[n] < pg[n]) { return(false); } } } return(true); }
} // end update #endif //FOR_FUTURE 6/4/2017 /// <summary> /// modelListUpdate(name, dir, Made, MD5) - update list of models in TSmatch.xlsx/Models /// </summary> /// <param name="name">Model name</param> /// <param name="dir">Model path in File sistem</param> /// <param name="Made">version name of TS.Read - important as AttSet field list identifier</param> /// <param name="MD5">checksum of all Model parts</param> /// <returns>Model, updated in the list of models in TSmatch</returns> /// <history> 6.3.2016 PKh /// 15.3.16 return Model instead of null in case of completely new model; wrToFile handle /// 5.4.16 Current Phase handling /// 6.8.16 non static method /// </history> Model modelListUpdate(string name, string dir = null, string Made = null, string MD5 = null, string Phase = null, string str = null) { Log.set("modelListUpdate"); Models.Clear(); Start(); // renowate Models list from TSmatch.xlsx Model mod = getModel(name); if (mod == null) // mod==null - means this is completely new model { Models.Add(new Model(name, dir, ifcPath, Made, Phase, MD5)); mod = getModel(name); mod.wrToFile = true; } else { if (dir != null) mod.dir = dir; if (Made != null) mod.Made = Made; if (Phase != null) mod.Phase = Phase; if (MD5 != null) mod.MD5 = MD5; if (str != null) { mod.strListRules = str; foreach (int n in Lib.GetPars(str)) mod.Rules.Add(new TSmatch.Rule.Rule(n)); } //!!!!!!!!!!!!!!!!!!!!!!!!!!!! ЗДЕСЬ // 1) проверить, доступен ли каталог dir? Если нет -> запустить FileWindowsDialog, потом рекурсивно вызвать modelListUpdate // 2) проверить, изменился ли MD5 и список Правил str? Если нет -> список моделей не переписываем, оставляем прежднюю дату // 3) читать ModelINFO / MD5 в файле, чтобы понять, нужно ли в него переписать модель (установить флаг wrToFile) } Log.exit(); return mod; }
protected void CheckResx(string rName, string rValue) { ResType type = ResType.Err; foreach (var x in ResTab) { if (!rValue.Contains(x.Value)) continue; type = x.Key; break; } int indx = rValue.IndexOf(':') + 1; string v = rValue.Substring(indx).Trim(); switch (type) { case ResType.Doc: if (!Docs.IsDocExist(rName)) resxError(ResErr.NoDoc, rName); break; case ResType.File: if (!FileOp.isFileExist(rName)) resxError(ResErr.NoFile, rName); break; case ResType.Date: DateTime d = Lib.getDateTime(v); Docs doc = Docs.getDoc(rName, fatal: false); if (doc == null) resxError(ResErr.NoDoc, rName); string sdd = doc.Body.Strng(1, 1); DateTime dd = Lib.getDateTime(sdd); if (dd < d) resxError(ResErr.Obsolete, rName); break; case ResType.Resx: break; default: resxError(ResErr.ErrResource, rName); break; } }
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); }
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); }
protected SType SecType(string text) { if (string.IsNullOrEmpty(text) || !text.Contains(':')) { return(SType.NOT_DEFINED); } string hdr = text.Substring(0, text.IndexOf(':')); hdr = Lib.ToLat(hdr).ToLower().Replace(" ", ""); foreach (SType sec in Enum.GetValues(typeof(SType))) { if (sec == SType.NOT_DEFINED) { continue; } List <string> synonyms = SectionTab[sec.ToString()].ToList(); var secFound = synonyms.Find(x => x.Length > hdr.Length? false: x == hdr.Substring(0, x.Length)); if (secFound != null) { return(sec); } } return(SType.NOT_DEFINED); }
public void getSavedRules() { strListRules = "17, 4, 5, 6, 7"; foreach (int n in Lib.GetPars(strListRules)) Rules.Add(new Rule.Rule(n)); ClosePriceLists(); }
public Parameter(string str) { str = Lib.ToLat(str).ToLower().Replace(" ", ""); if(string.IsNullOrWhiteSpace(str)) { ptype = ParType.ANY; tx = string.Empty; par = str; return; } int indx = str.IndexOf(':') + 1; Regex parametr = new Regex(@"\{.+?\}"); Match m = parametr.Match(str, indx); ptype = getParType(str); if (m.Value.Length > 0) { // string like "{result}" with the Brackets par = Regex.Replace(m.Value, @"\{.*?~|\{|\}", ""); tx = str.Substring(indx, m.Index - indx); } else { // result is part of str, recognised as a parameter value int end = str.IndexOf(';'); if (end < indx) end = str.Length; tx = str.Substring(indx, end - indx); par = tx; } }
public Section(string _text, SType stype = SType.NOT_DEFINED) { if (SectionTab == null) { SectionTab = new Boot.initSection().SectionTab; } string[] sections = Lib.ToLat(_text).ToLower().Replace(" ", "").Split(';'); if (stype == SType.NOT_DEFINED) { type = SecType(sections[0]); body = SecBody(sections[0]); refSection = SecRef(sections[0]); return; } foreach (string str in sections) { if (SecType(str) != stype) { continue; } type = stype; body = SecBody(str); return; } type = SType.NOT_DEFINED; body = string.Empty; }
private void getSavedGroups() { Docs docRaw = Docs.getDoc(Decl.TSMATCHINFO_RAW, create_if_notexist: false); elements.Clear(); int cnt = docRaw.Body.iEOL(); for (int i = docRaw.i0; i <= cnt; i++) { string guid = docRaw.Body.Strng(i, 1); string mat = docRaw.Body.Strng(i, 2); string mat_type = docRaw.Body.Strng(i, 3); string prf = docRaw.Body.Strng(i, 4); double lng = docRaw.Body.Double(i, 5); double weight = docRaw.Body.Double(i, 6); double vol = docRaw.Body.Double(i, 7); Elm elm = new Elm(guid, mat, mat_type, prf, lng, weight, vol); elements.Add(elm); } if (elements.Count != elementsCount) { Msg.F("TSmatchINFO.xlsx inconsystent", name, elementsCount, elements.Count); //11/4 GetSavedReport(doRead: true); } docReport = Docs.getDoc(Decl.TSMATCHINFO_REPORT); getGroups(); int gr_n = docReport.i0; foreach (var gr in elmGroups) { string grPrice = docReport.Body.Strng(gr_n, Decl.REPORT_SUPL_PRICE); gr.totalPrice = Lib.ToDouble(grPrice); gr.SupplierName = docReport.Body.Strng(gr_n, Decl.REPORT_SUPPLIER); gr.CompSetName = docReport.Body.Strng(gr_n, Decl.REPORT_COMPSET); gr_n++; } }
/// <param name="fetch_rqst"></param> /// <example>FetchInit("SFacc/2:3")</example> public void FetchInit(string fetch_rqst) { Log.set("FetchInit(fetch_rqst)"); try { if (string.IsNullOrEmpty(fetch_rqst)) { FetchInit(); return; } string[] ar_rqst = fetch_rqst.Split('/'); if (!Documents.ContainsKey(ar_rqst[0])) Log.FATAL("нет такого Документа"); string strFetch = ar_rqst[0] + "/" + ar_rqst[1]; if (docDic.ContainsKey(strFetch)) return; // уже инициирован -> return Document doc = getDoc(ar_rqst[0]); string[] cols = ar_rqst[1].Split(':'); int key = Lib.ToInt(cols[0]); int val = Lib.ToInt(cols[1]); Dictionary<string, string> keyDic = new Dictionary<string, string>(); docDic.Add(strFetch, keyDic); DateTime t0 = DateTime.Now; for (int i = 1; i <= doc.Body.iEOL(); i++) { string s1 = doc.Body.Strng(i, key); if (s1 != "") try { keyDic.Add(s1, doc.Body.Strng(i, val)); } catch { Log.Warning("Запрос \"" + fetch_rqst + " Строка " + i + " неуникальное значение \"" + s1 + "\" в ключевом поле запроса!"); } } DateTime t1 = DateTime.Now; new Log("-> " + (t1 - t0)); } catch { Log.FATAL("ошибка запроса \"" + fetch_rqst + "\" для Документа \"" + name + "\""); } finally { Log.exit(); } }
private double getPrice(Elm elm, DPar.DPar csDP, string priceStr) { double price = Lib.ToDouble(priceStr); foreach (var sec in csDP.dpar) { if (!sec.Key.ToString().Contains("UNIT_")) { continue; } switch (sec.Key) { case SType.UNIT_Weight: // kg -> tonn return(elm.weight / 1000 * price); case SType.UNIT_Vol: // mm3 -> m3 return(elm.volume / 1000 / 1000 / 1000 * price); case SType.UNIT_Length: return(elm.length * price); case SType.UNIT_Qty: return(price); } } return(0); }
// for internal use, f.e. for comparision public string viewComp_(SType stype) { string str = ""; try { str = compDP.dpar[stype]; } catch { str = "##NOT_AVAILABLE##"; } return(Lib.ToLat(str.ToLower())); }
private static void sub(SType t, params string[] str) { List <string> lst = new List <string>(); foreach (string s in str) { lst.Add(Lib.ToLat(s).ToLower().Replace(" ", "").Replace(".", "").Replace("/", "")); } SectionTab.Add(t.ToString(), lst); }
private void initGr(string v, string mat = "C245") { inp.Clear(); gr.Prf = v; gr.prf = Lib.ToLat(v.ToLower().Replace(" ", "")); gr.Mat = mat; gr.mat = Lib.ToLat(mat.ToLower().Replace(" ", "")); inp.Add(gr); //23/7 mod.elmGroups = inp; }
public ElmAttSet(Ifc ifc_elm) { guid = ifc_elm.guid; mat = ifc_elm.material; mat_type = ifc_elm.type_material; prf = ifc_elm.profile; length = Lib.ToDouble(ifc_elm.length); weight = Lib.ToDouble(ifc_elm.weight); volume = Lib.ToDouble(ifc_elm.volume); price = Lib.ToDouble(ifc_elm.price); }
private void getSupplier(int n) { Docs docSupl = Docs.getDoc(Decl.SUPPLIERS); Date = Lib.getDateTime(docSupl.Body[n, Decl.SUPL_DATE]); Name = (string)docSupl.Body[n, Decl.SUPL_NAME]; Url = (string)docSupl.Body[n, Decl.SUPL_URL]; City = (string)docSupl.Body[n, Decl.SUPL_CITY]; Street = (string)docSupl.Body[n, Decl.SUPL_STREET]; Index = (string)docSupl.Body[n, Decl.SUPL_INDEX]; Telephone = (string)docSupl.Body[n, Decl.SUPL_TEL]; }
public Group(IGrouping <string, Elm> group) { elmsDic = group.ToDictionary(x => x.guid); Mat = elmsDic.First().Value.mat; Prf = elmsDic.First().Value.prf; mat = Lib.ToLat(Mat.ToLower().Replace("*", "x")); prf = Lib.ToLat(Prf.ToLower().Replace("*", "x")); guids = group.Select(x => x.guid).ToList(); totalLength = group.Select(x => x.length).Sum(); totalWeight = group.Select(x => x.weight).Sum(); totalVolume = group.Select(x => x.volume).Sum(); }
// if field of stype not recognized, return -1 //.. f.e. it happaned with constant like "M:C245" public int Col(SType stype) { if (stype.ToString().Contains("UNIT_")) { return(-1); } string str = string.Empty; try { str = dpar[stype]; } catch { } return(Lib.ToInt(str)); }
public void UT_Component_checkComp_L() { //test 1: gr="L75x5" rule="Профиль: Уголок=L *x*;" => TRUE gr.prf = "l75x5"; rule.text = Lib.ToLat("Профиль: Уголок=L *x*;"); rule.ruleDP = new DPar.DPar(rule.text); rule.synonyms = rule.RuleSynParse(rule.text.ToLower()); comp.compDP = new DPar.DPar("Prf:Уголок 75 x 5"); string vs = rule.synonyms[Section.Section.SType.Profile][0]; string vd = comp.viewComp_(Section.Section.SType.Profile); Assert.IsTrue(vd.Contains(vs)); Assert.AreEqual(comp.compDP.dpar.Count, 1); var v = comp.compDP.dpar[Section.Section.SType.Profile]; Assert.AreEqual(v, "угoлoк75x5"); bool b = comp.isMatch(gr, rule); Assert.IsTrue(b); //test 4: gr="I20" rule="Профиль: Балка =I* дл;" comp="Балка 20 дл. 9м Ст3пс5" => TRUE 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(); Assert.AreEqual(syns[0], "бaлкa"); Assert.AreEqual(syns[1], "i"); comp.compDP = new DPar.DPar("Prf:" + comp_txt); Assert.AreEqual(comp.compDP.dpar.Count, 1); Assert.AreEqual(comp.compDP.dpStr[Section.Section.SType.Profile], comp_txt); b = comp.isMatch(gr, rule); Assert.IsTrue(b); //test 4-1: gr="I30Ш2" rule="Профиль: Двутавр=I*Ш*" => TRUE initGr("I30Ш2"); initRule("М: C245=C255 ; Профиль: Двутавр=I*Ш*"); initComp("двутавр 30Ш2"); b = comp.isMatch(gr, rule); Assert.IsTrue(b); //test 5: gr="Гн.100x4" rule="Профиль: Швеллер = U*П_;" => TRUE initGr("Гн.100x4"); initRule("Профиль: Гн.*х*"); initComp("Гн. 100х4"); b = comp.isMatch(gr, rule); Assert.IsTrue(b); //test 6: gr="Гн.100x4" rule="Профиль: Швеллер = U*П_;" Comp=M:C345 => FALSE initGr("Гн.100x46"); initRule("Профиль: Уголок=L *x*x*"); initComp("Гн. 100х4", "C345"); b = comp.isMatch(gr, rule); Assert.IsTrue(!b); }
public double RuleRedundencyPerCent = 0.0; //коэффициент избыточности, требуемый запас по данному материалу/профилю/Правилу public Rule(Docs doc, int i) { name = (string)doc.Body[i, Decl.RULE_NAME]; type = (string)doc.Body[i, Decl.RULE_TYPE]; text = Lib.ToLat((string)doc.Body[i, Decl.RULE_RULE]); synonyms = RuleSynParse(text); ruleDP = new DP(text); // template for identification string csName = (string)doc.Body[i, Decl.RULE_COMPSETNAME]; string suplName = (string)doc.Body[i, Decl.RULE_SUPPLIERNAME]; Supplier = new Suppliers.Supplier(suplName); CompSet = new CmpSet(csName, Supplier); }
private static void testFP_synonym(FingerPrint fp) { Log.set("testFP_synonym(fp)"); int iStart = 0; string str = Lib.ToLat("L=Уголок*").ToLower(); TST.Eq(fp.isSynonym(str, iStart), true); TST.Eq(fp.synParser(str, ref iStart), "l"); TST.Eq(iStart, 2); string tx = str.Substring(iStart); TST.Eq(tx, Lib.ToLat("Уголок*").ToLower()); Log.exit(); }
/// <summary> /// ElementsMD5 -- calculate hash code MD5 for the list of elements of the model /// </summary> /// <returns></returns> /// <remarks>It could take few minutes or more for the large model</remarks> /// <history>21/6/2016 moved here from TS_OpenAPI /// </history> public static string ElementsMD5() { // DateTime t0 = DateTime.Now; string str = ""; foreach (var elm in Elements.Values) { str += elm.mat + elm.prf + elm.length.ToString(); } string ModelMD5 = Lib.ComputeMD5(str); return(ModelMD5); // new Log("MD5 time = " + (DateTime.Now - t0).ToString()); }
/// <summary> /// EOL(int tocRow) - setup this Document int numbers EndEOLinTOC, i0, and il - main table borders /// <para>when TSmatch.xlsx document handled, 'EOL' could be in il TOC column</para> /// </summary> /// <param name="tocRow">line number of this Document in TOC</param> /// <history>19.3.2016 /// 2017.8.2 - bug fix; EOL works for TSmatch Document type only /// </history> void EOL(int tocRow) { i0 = Lib.ToInt(toc.Body.Strng(tocRow, Decl.DOC_I0)); string str = toc.Body.Strng(tocRow, Decl.DOC_IL); if (str == "EOL") { if (type != Decl.TSMATCH) Msg.F("Shouldn't be 'EOL' here in TSmatch/TOC", tocRow); string shN = toc.Body.Strng(tocRow, Decl.DOC_SHEET); Mtr m; if (shN == Decl.DOC_TOC) m = toc.Body; else m = FileOp.getSheetValue(toc.Wb.Worksheets[shN]); il = m.iEOL(); } else il = Lib.ToInt(str); }
/// <summary> /// PrfNormalize operate in <Full>, or in <Mark> mode: /// <para> - Mark: only setup Mark (i.e. Profile type) as pointed in first argument, or</para> /// <para> - Full: setup Mark, and sort digital parameter values the profile template list;</para> /// </summary> private void PrfNormalize(ref List<ElmGr> grp, params string[] prfMark) { foreach (var gr in grp) { foreach (string s in prfMark) { if (!gr.Prf.Contains(s) && !gr.prf.Contains(s)) continue; string initialPrf = gr.Prf; gr.Prf = PrfNormStr(gr.prf, prfMark[0], Lib.GetPars(gr.Prf)); gr.prf = Lib.ToLat(gr.Prf.ToLower()); log.Info("--- " + initialPrf + " -> " + "Prf=" + gr.Prf + "gr.prf=" + gr.prf); break; } } }
public List <Par> secPars(string template) { List <Par> result = new List <Par>(); template = Lib.ToLat(template).ToLower().Replace(" ", ""); template = SecBody(template); string pattern = "^" + template.Replace("*", @"(.*?)") + "$"; Regex r = new Regex(pattern); Match m = r.Match(body); for (int i = 1; i < m.Groups.Count; i++) { result.Add(new Par(m.Groups[i].Value)); } return(result); }