/// <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; }
private void elmGroups_SelectionChanged(object sender, SelectionChangedEventArgs e) { gr g = (gr)elm_groups.SelectedValue; if (g == null) return; currentGroup = model.elmGroups.Find(x => x.Mat == g.mat && x.Prf == g.prf); SuplName = currentGroup.SupplierName; Supl supl = new Supl(currentGroup.SupplierName); Supl_CS_Mat_Prf.Text = SuplName + "\t" + currentGroup.CompSetName; string str = "Адрес: "; if (!string.IsNullOrEmpty(supl.Index)) str += supl.Index + ", "; str += supl.City + ", "; if (str.Length > 20) str += "\n"; str += supl.Street + "\nтел." + supl.Telephone; Supl_CS.Text = str; //--2017.07.26 не вполне работает Hyperlink- нет вызова сайта при клике. Пока оставил так.. Supl_URL.Inlines.Clear(); Run myURL = new Run(supl.Url); Hyperlink hyperl = new Hyperlink(myURL); Supl_URL.Inlines.Add(hyperl); //-- double p = 0, w = 0, v = 0; foreach (var gr in model.elmGroups) { if (gr.SupplierName != currentGroup.SupplierName) continue; w += gr.totalWeight; v += gr.totalVolume; p += gr.totalPrice; } TotalSupl_weight_volume.Text = String.Format("Общий вес= {0:N1} кг, объем = {1:N1} м3", w, v); string sP = string.Format("{0:N2}", p); TotalSupl_price.Text = "Цена по этому поставщику " + sP + " руб"; MWmsg("MainWindow msg Group selection"); elm_groups.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal , new NextPrimeDelegate(HighLighting)); }
/// <summary> /// CheckCS(group) return true, when this Supplier /// containes same material and profule, or rule allow replacement /// </summary> /// <param name="group"></param> /// <param name="rule"></param> /// <returns></returns> internal bool CheckCS(Gr group) { string grCSname = group.CompSetName; var cs = CompSets.Find(x => x.name == grCSname); if (cs != null) return true; // нашел CS с тем же именем! return false; }
/// <summary> /// getGroups() - groupping of elements of Model by Material and Profile /// </summary> /// <history> /// 2016.09.29 created /// 2017.05.8 перенес в модуль ModHandling, добавил аргумент elements /// 2017.06.27 переписано /// 2017.07.20 field bool errDialog add /// </history> public List<ElmGr> getGrps(List<Elm> elements) { Log.set("getGrps(" + elements.Count + ")"); if (elements == null || elements.Count == 0) Msg.F("getGrps: no elements"); var gr = new ElmGr(); List<ElmGr> groups = new List<ElmGr>(); var grps = elements.GroupBy(x => x.prf); foreach (var grp in grps) groups.Add(new ElmGr(grp)); if (elements.Count != groups.Sum(x => x.guids.Count)) Msg.F("getGrps internal error"); var v = new ProfileUpdate.ProfileUpdate(ref groups); Log.exit(); return groups; }
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(); }
private string sub_PriceGr(Mod mod, ElmGr gr, string sLang = "en", string sev = "F", string _prefix = "") { U.SetLanguage(sLang); string result = "", prefix = _prefix; if (string.IsNullOrEmpty(prefix)) { prefix = "Msg." + sev + ": [Handler.PriceGr]: "; } try { mod.mh.PriceGr(mod, gr); } catch (Exception e) { if (e.Message.IndexOf(prefix) == 0) { result = e.Message.Substring(prefix.Length); } } return(result); }
public Mtch PriceGr(Mod mod, ElmGr gr) { Log.set("Handler.PriceGr"); Mtch match = null; bool found=false; if (mod.Rules == null || mod.Rules.Count == 0) Msg.F("Handler__PriceGr Rules not Initialized"); foreach(var rule in mod.Rules) { if (gr.SupplierName != string.Empty && gr.SupplierName != rule.sSupl) continue; match = new Mtch(gr, rule); if (match.ok == Mtch.OK.Match) { mod.matches.Add(match); gr.CompSetName = match.rule.sCS; gr.SupplierName = match.rule.sSupl; gr.compDescription = match.component.Str(Section.Section.SType.Description); found = true; break; } } if (!found) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf); Log.exit(); return match; }
public Serialized_Group(ElmGr elmGr) { guids = elmGr.guids; mat = elmGr.mat; Mat = elmGr.Mat; prf = elmGr.prf; Prf = elmGr.Prf; wgt = elmGr.totalWeight; lng = elmGr.totalLength; vol = elmGr.totalVolume; pr = elmGr.totalPrice; Supplier_name = elmGr.SupplierName; CompSet_name = elmGr.CompSetName; try { Rule_Text = elmGr.match.rule.text; LoadDescriptor = elmGr.match.rule.CompSet.doc.LoadDescription; } catch { Rule_Text = LoadDescriptor = string.Empty; Rule_date = DateTime.MinValue; } }
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(); }