protected string formatMasterItem(IPObject obj) { string template; if (!obj.GetAttr(_conf.MasterItemTemplate, true, out template)) throw new Exception(string.Format("Шаблон наименования оптимизации (атрибут {0}) не найден!", _conf.MasterItemTemplate)); return PTemplates.FormatObject(obj, template, host: this, overloads: null, worker: null, navInfo: null); }
protected string genOptHtml(IPObject obj, out List<string> navLevels, out List<string> navCaptions) { string html = ""; // по-умолчанию пустые списки navLevels = new List<string>(); navCaptions = new List<string>(); if (obj != null) { string template; if (!obj.GetAttr(_conf.DetailTemplate, true, out template)) throw new Exception(string.Format(@"Шаблон просмотра деталей (атрибут {0}) не найден!", _conf.DetailTemplate)); using (FFormat form = new FFormat(this.Width / 2 - 150, this.Height / 2 - 81, obj, template, this, null)) { form.ShowDialog(); if (form.ExceptionMessage != "") throw new Exception(form.ExceptionMessage); html = form.GeneratedHtml; // заменяем navLevels = form.parsedNavLevels; navCaptions = form.parsedNavCaptions; } } if (html != "") html = _addScriptsToBody(html); return html; }
public static string FormatObject(IPObject obj, string template, IMHost host, IMValueGetter overloads, BackgroundWorker worker, PNavigationInfo navInfo) { List<PTemplateAttr> attrs; List<PTemplateCollection> fcollects; _parse(template, out attrs, out fcollects); template = template.Replace("%id%", obj.Id.ToString()); foreach (var attr in attrs) { string val = ""; string moduleName = attr.Module.Trim().ToLower(); string attrName = attr.Name; bool valFound = false; if (moduleName == "") { if (overloads != null) valFound = overloads.QueryValue(attrName, false, out val); if (!valFound) valFound = obj.GetAttr(attr.Name, true, out val); } else if (moduleName == "host") { if (host != null) valFound = host.QueryValue(attr.Name, false, out val); } else { valFound = _queryToModule(moduleName, attrName, out val); } if (!valFound) val = "<" + attr.ToString() + ">"; template = template.Replace(attr.OperatorText, val); } foreach (var fcollect in fcollects) { IPCollection coll = obj.GetCollection(fcollect.collectionName); if (coll != null) { string val = ""; int cnt = coll.Count; for (int i = 0; i < cnt; i++) { IPObject cobj = coll.GetObject(i); string tmp = ""; if (cobj.GetAttr(fcollect.templateName, true, out tmp)) { if (worker != null && worker.CancellationPending) return ""; bool navAdded = false; if (fcollect.navigatorLevelCaption != "") { if (navInfo != null) { navInfo.captions.Add(fcollect.navigatorLevelCaption); navInfo.levels.Add(fcollect.collectionName); navAdded = true; } } val += FormatObject(cobj, tmp, host, overloads, worker, navInfo); // теперь, если уровень навигации добавлялся - нужно сбросить переменную, чтоб в этом цикле не добавить соседние подходящие коллекции if (navAdded) navInfo = null; } else val += "<!" + fcollect.templateName + "!>"; val += (fcollect.endsWithNewLine ? "\n" : ""); } template = template.Replace(fcollect.OperatorText, val); } } // ToDo: может надо else что-нибудь вывести? Коллекция не найдена return template; }