/// <summary> /// Hndl(model) - find matching Components for model and total_price /// </summary> /// <param name="mod">model to be handled</param> public void Hndl(ref Mod mod) { Log.set("MH.Hndl"); mod.elmGroups = getGrps(mod.elements); if (mod.elmGroups.Count < 1 || mod.Rules.Count < 1) Msg.F("No Rules or element Groups"); if(testMode) { Log.exit(); return; } foreach (var rules in mod.Rules) if (rules.CompSet == null) rules.Init(); // find matching Components with Rules by module Mtch foreach (var gr in mod.elmGroups) { bool b = false; foreach (var rule in mod.Rules) { Mtch _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); b = true; break; } } if (!b) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf); } // calculate prices for matches mod.total_price = mod.elmGroups.Sum(x => x.totalPrice); mod.pricingDate = DateTime.Now; mod.pricingMD5 = mod.get_pricingMD5(mod.elmGroups); Log.Trace("price date=\t" + mod.pricingDate + "\tMD5=" + mod.pricingMD5); log.Info("Model.Hndl set " + mod.matches.Count + " groups. Total price=" + mod.total_price + " rub"); Log.exit(); }
public void Pricing(ref Mod m, bool unit_test_mode = false) { Log.set("mh.Pricing"); #if DEBUG testMode = unit_test_mode; var x = new Mtch(m); #endif if (m.Rules == null || m.Rules.Count == 0) { m = sr._GetSavedRules(m); } log.Info(">m.MD5=" + m.MD5 + " =?= " + m.getMD5(m.elements)); Hndl(ref m); log.Info(">m.MD5=" + m.MD5 + " =?= " + m.getMD5(m.elements)); Log.Trace(" date=\t" + m.date + "\tMD5=" + m.MD5 + "\telements.Count=" + m.elements.Count); Log.Trace("price date=\t" + m.pricingDate + "\tMD5=" + m.pricingMD5 + "\ttotal price" + m.total_price); Log.exit(); }
public void Handler(Mod mod) { Log.set("MH.Handler(\"" + mod.name + "\")"); getGroups(mod.elements); log.Info("- total elements = " + mod.elements.Count + " in " + mod.elmGroups.Count + "groups"); foreach (var gr in mod.elmGroups) { bool b = false; foreach (var rule in mod.Rules) { Mtch _match = new Mtch(gr, rule); if (_match.ok == Mtch.OK.Match) { mod.matches.Add(_match); b = true; break; } } if (!b) log.Info("No Match Group. mat= " + gr.mat + "\tprf=" + gr.prf); } int cnt = 0; var elms = new Dictionary<string, Elm>(); elms = mod.elements.ToDictionary(elm => elm.guid); foreach (var match in mod.matches) { match.group.SupplierName = match.rule.Supplier.name; double price_per_t = match.group.totalPrice / match.group.totalVolume; foreach (var guid in match.group.guids) { elms[guid].price = price_per_t * elms[guid].volume; cnt++; } } log.Info("- found " + mod.matches.Count + " price matches for " + cnt + " elements"); elements = elms.Values.ToList(); Log.Trace("<MH>Rules.Count=", mod.Rules.Count); Log.Trace("<MH>Price match for ", mod.matches.Count, " / ", mod.elmGroups.Count); Log.exit(); }