protected override void RunRefreshSelect(List <MObj> list, MEDMDefClass dc, string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse) { FilterParamList l = new FilterParamList(dc, xrequest); object[] parms = new object[l.Count * 2 + 2]; string t = l.Top > 0 ? "top " + l.Top.ToString():""; string sql = $"select {t} * from [{dc.Name}] (nolock) where id!=@p0"; parms[0] = "p0"; parms[1] = dc.GetIdPropery().GetDefaultValue(); for (int i = 0; i < l.Count; i++) { switch (l[i].Mode) { case "": case "eq": sql += $" and ( [{l[i].Name}]=@p{i + 1})"; break; case "ne": sql += $" and ( [{l[i].Name}]!=@p{i + 1})"; break; case "eqornone": sql += $" and ( [{l[i].Name}]=@p{i + 1} or [{l[i].Name}]=@p0)"; break; } parms[(i + 1) * 2] = $"p{i + 1}"; parms[(i + 1) * 2 + 1] = l[i].Value; } { MEDMDefProperty dp = dc.Properties.Find(p => p.Name.ToLower() == "name"); if (dp == null) { dp = dc.Properties.Find(p => p.Name.ToLower().EndsWith("name")); } if (dp == null) { dp = dc.Properties.Find(p => p.Name.ToLower().Contains("name")); } if (dp != null) { sql += $" order by [{dp.Name}]"; } } model.Select(list, dc.GetClassType(), sql, parms); }
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"); } } }