public FilterParamList(MEDMDefClass dc, XmlNode xrequest) { foreach (XmlNode xparam in xrequest.SelectNodes("descendant::param")) { string[] nn = XFunc.GetAttr(xparam, "name", "").Split('.'); string n = nn[0]; string m = ""; if (nn.Length > 1) { if (nn[0].ToLower() == "filter") { n = nn[nn.Length - 1]; if (nn.Length == 3) { m = nn[1].ToLower(); } } if (nn[0].ToLower() == "paginator") { n = nn[nn.Length - 1]; if (n.ToLower() == "top") { Top = MFunc.StringToInt(XFunc.GetText(xparam, ""), 0); continue; } } } MEDMDefProperty dp = dc.Properties[n]; if (dp != null) { object v = dp.ConvertToPropertyType(XFunc.GetText(xparam, "")); Add(new FilterParam(n, m, v)); } } }
protected override void RunDelete(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { MEDMDefClass dc = MEDMDefModel.MainDef.Find(name); if (dc != null) { if (dc.BaseClass == "MEDMObj") { Type t = dc.GetClassType(); if (t != null) { string id = XFunc.GetAttr(xrequest, "id", ""); if (id == "") { throw new Exception("В параметрах запроса отсутствует id"); } MEDMObj obj = model.MainDic.GetObj(t, id); if (obj == null) { throw new Exception($"Не удалось создать объект типа {t}. Удаление невозможно."); } model.DeleteObject(obj); model.Save(Session); } } else { throw new Exception($"Для автоматической генерации Delete класс источника данных {name} должен быть порожден от MEDMObj"); } } }
protected virtual void RunMark(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { string rowtype = XFunc.GetAttr(xrequest, "row.type", ""); string marktypes = M740.GetParam(xrequest, "marktypes"); if (marktypes == "" || marktypes.Contains(rowtype)) { string id = XFunc.GetAttr(xrequest, "id", ""); string key = MarkKey(xrequest); string s = Session.GetString(key); if (s == null) { s = ""; } if (rowtype != "") { id = rowtype + "." + id; } if (s.Contains(id)) { s = s.Replace(id + ";", ""); XFunc.Append(xresponse, "row", "row.mark", "0"); } else { s += id + ";"; XFunc.Append(xresponse, "row", "row.mark", "1"); } Session.SetString(key, s); MarkSetCount(s, xresponse); } }
public T Load <T>(XmlNode xnode, string pref = "") where T : MEDMObj { T p = null; string n = XFunc.GetAttr(xnode, "name", ""); if (n != "") { __ = $"{typeof(T).Name}: {n}"; if (pref != "") { n = $"{pref}.{n}"; } p = MainDic.GetObj <T>(n); try { p.SetValues(xnode); } catch (Exception e) { __ = $"error: {e}"; } } else { __ = $"error: Имя {typeof(T).Name} не задано."; } return(p); }
protected virtual void RunRefreshMark(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { string key = MarkKey(xrequest); string s = Session.GetString(key); if (s == null) { s = ""; } if (s != "") { foreach (XmlNode xrow in xresponse.SelectNodes("descendant::row")) { string id = XFunc.GetAttr(xrow, "id", ""); string rowtype = XFunc.GetAttr(xrow, "row.type", ""); if (rowtype != "") { id = rowtype + "." + id; } XFunc.SetAttr(xrow, "row.mark", s.Contains(id) ? "1" : "0"); } } else { foreach (XmlNode xrow in xresponse.SelectNodes("descendant::row")) { XFunc.SetAttr(xrow, "row.mark", "0"); } } MarkSetCount(s, xresponse); }
public static void ParmsToObj(XmlNode xparms, MObj obj) { foreach (XmlNode xparm in xparms.SelectNodes("descendant::param")) { string name = XFunc.GetAttr(xparm, "name", ""); string value = XFunc.GetText(xparm, ""); if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value)) { obj.SetValue(name, value); } } }
/// <summary> /// Генерит описания источников данных, по описанию модели. /// Описание для источника генерится только в том случае если своего описание rowset не имеет /// </summary> /// <param name="formName"></param> /// <param name="model"></param> /// <param name="xrequest"></param> /// <param name="xresponse"></param> public virtual void GenRowSetsAndPanels(string formName, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { foreach (XmlNode xpanel in xresponse.SelectNodes("descendant::panel")) { if (XFunc.GetAttr(xpanel, "autogen", false)) { string name = XFunc.GetAttr(xpanel, "rowset", ""); if (name != "") { MEDMDefClass ds = MEDMDefModel.MainDef.Find(name); if (ds != null) { if (ds.Properties.Count > 0) { if (xpanel.SelectSingleNode("toolbar") == null) { XFunc.Append(xpanel, "toolbar", "default", "1"); } if (xpanel.SelectSingleNode("fields") == null) { XmlNode xfields = XFunc.Append(xpanel, "fields"); foreach (MEDMDefProperty dp in ds.Properties) { if (dp.IsVisible) { if (!MEDMObj.IsEmptyId(dp.RefClassId)) { XmlNode xreffield = XFunc.Append(xfields, "field", "name", (dp.GetRefName() + "_tostring_").ToLower(), "stretch", "1"); } else { if (dp.IsInterval) { XFunc.Append(xfields, "field", "name", (dp.Name + ".Min").ToLower()); XFunc.Append(xfields, "field", "name", (dp.Name + ".Max").ToLower()); } else { XFunc.Append(xfields, "field", "name", dp.Name.ToLower(), "stretch", dp.DataType == "string"?"1":"0"); } } } } } } } } } } }
public static string GetParam(XmlNode xnode, string paramname, string defvalue = "") { string r = defvalue; XmlNode xparam = xnode.SelectSingleNode($"descendant::param[@name='{paramname}']"); if (xparam == null) { xparam = xnode.SelectSingleNode($"descendant::param[contains(@name,'.{paramname}')]"); } if (xparam != null) { r = XFunc.GetText(xparam, defvalue); } else { r = XFunc.GetAttr(xnode, paramname, defvalue); } return(r); }
protected override void RunSave(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { MEDMDefClass dc = MEDMDefModel.MainDef.Find(name); if (dc != null) { if (dc.BaseClass == "MEDMObj") { Type t = dc.GetClassType(); if (t != null) { string id = XFunc.GetAttr(xrequest, "id", ""); if (id == "") { throw new Exception("В параметрах запроса отсутствует id"); } MEDMObj obj = model.MainDic.GetObj(t, id); if (obj == null) { throw new Exception($"Не удалось создать объект типа {t}. Сохранить изменения невозможно."); } foreach (XmlNode xparam in xrequest.ChildNodes) { if (xparam.Name == "param") { obj.SetStringValue(XFunc.GetAttr(xparam, "name", ""), xparam.InnerText); } } model.Save(Session); RefreshRow(name, id, model, xrequest, xresponse); } } else { throw new Exception($"Для автоматической генерации Save класс источника данных {name} должен быть порожден от MEDMObj"); } } }
protected override void RunAppend(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { MEDMDefClass dc = MEDMDefModel.MainDef.Find(name); if (dc != null) { if (dc.BaseClass == "MEDMObj") { Type t = dc.GetClassType(); if (t != null) { FilterParamList l = new FilterParamList(dc, xrequest); MEDMObj obj = model.CreateObject(t, null); model.Save(Session); foreach (FilterParam fp in l) { obj.SetValue(fp.Name, fp.Value); } model.Save(Session); if (obj != null) { XmlNode xrow = RefreshRow(name, obj.GetId(), model, xrequest, xresponse); if (xrow != null) { XFunc.SetAttr(xrow, "row.destmode", "after"); XFunc.SetAttr(xrow, "row.destid", XFunc.GetAttr(xrequest, "id", "")); } } } } else { throw new Exception($"Для автоматической генерации Append класс источника данных {name} должен быть порожден от MEDMObj"); } } }
public static string MarkKey(XmlNode xrequest, string datasource = "", string mode = "") { if (mode == "") { mode = M740.GetParam(xrequest, "markmode"); } if (datasource == "") { datasource = M740.GetParam(xrequest, "markfield"); } if (datasource == "") { datasource = M740.GetParam(xrequest, "rowset"); } if (datasource == "") { M740.GetParam(xrequest, "datasource"); } if (datasource == "") { datasource = XFunc.GetAttr(xrequest, "datasource", ""); } return($"mark.{datasource}.{mode}"); }
public void SelectFromXML(IList list, Type t, XmlNode xroot, object id) { if (xroot != null) { try { bool f = MainDic.ContainsKey(t); { foreach (XmlNode xrow in xroot.ChildNodes) { if (xrow.Name == "row") { if (id == null || id.ToString() == "" || id.ToString().ToLower() == XFunc.GetAttr(xrow, "id", "")) { MObj obj = null; if (f) { obj = MainDic.CreateObj(t); } else { obj = Activator.CreateInstance(t) as MObj; if (obj == null) { throw new Exception($@"Тип ""{t}"" не наследует от MObj"); } obj.Model = this; } SetObjValues(obj, xrow); if (list != null) { list.Add(obj); } if (obj is MEDMObj) { MainDic.AddObj(obj as MEDMObj); } } } } } } finally { } } }
public virtual void SetValues(XmlNode xnode) { foreach (PropertyInfo pi in GetType().GetRuntimeProperties()) { EDMPropertyAttribute pa = pi.GetCustomAttribute <EDMPropertyAttribute>(); string pt = ""; if (pa != null) { pt = pa.PropType.ToUpper(); } switch (pt) { case "LIST": object l = pi.GetValue(this); if (l is IList) { string n = pi.Name; string[] v = XFunc.GetAttr(xnode, n, "").Split(';'); Type t = pa.ItemType; foreach (string id in v) { if (!string.IsNullOrEmpty(id)) { (l as IList).Add(Model.MainDic.GetObj(t, id)); } } } break; default: { if (pi.CanRead && pi.CanWrite) { string n = pi.Name; string v = XFunc.GetAttr(xnode, n, ""); // Значение задано в текущем узле if (v != "") { SetStringValue(pi, v, false); } // Попробуем поискать значение в родительском узле else { XmlNode xnode1 = xnode.ParentNode; while (xnode1 != null) { v = XFunc.GetAttr(xnode1, $"default.{n}", ""); if (v != "") { SetStringValue(pi, v, false); break; } xnode1 = xnode1.ParentNode; } } } } break; } } }
public virtual void Run(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { string requestname = XFunc.GetAttr(xrequest, "name", "").ToLower(); switch (requestname) { case "definition": RunDefinition(name, model, xrequest, xresponse); break; case "expand": case "refresh": RunRefresh(name, model, xrequest, xresponse); RunRefreshMark(name, model, xrequest, xresponse); break; case "save": RunSave(name, model, xrequest, xresponse); break; case "append": RunAppend(name, model, xrequest, xresponse); break; case "delete": RunDelete(name, model, xrequest, xresponse); break; case "change": RunChange(name, model, xrequest, xresponse); break; case "mark": RunMark(name, model, xrequest, xresponse); break; case "markclear": RunMarkClear(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); RunRefreshMark(name, model, xrequest, xresponse); break; case "markset": RunMarkSet(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); break; case "join": RunJoin(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); break; case "copy": RunCopy(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); break; case "move": RunMove(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); break; case "link": RunLink(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); break; case "clone": RunClone(name, model, xrequest, xresponse); RunRefresh(name, model, xrequest, xresponse); break; default: RunRequest(name, requestname, model, xrequest, xresponse); break; } }