Beispiel #1
0
        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);
        }
Beispiel #2
0
        public static string MarkNames(string idlist, Type objtype, string section, MEDMSql model)
        {
            string result  = "";
            string idlist1 = MarkId(idlist, section);

            if (!string.IsNullOrEmpty(idlist1))
            {
                List <MObj> list = new List <MObj>();
                string      sql  = $"select * from [{MEDMDefModel.MainDef.GetTableNameByType(objtype)}] (nolock) where id!='{default(Guid)}' and id in ({idlist1})";
                model.Select(list, objtype, sql);
                foreach (MObj o in list)
                {
                    result += o.ToString() + "\r\n";
                }
            }
            return(result);
        }
Beispiel #3
0
        protected XmlNode RefreshRow(string name, object id, MEDMSql model, XmlNode xrequest, XmlNode xresponse)
        {
            XmlNode      xrow = null;
            MEDMDefClass dc   = MEDMDefModel.MainDef.Find(name);

            if (dc != null)
            {
                if (dc.BaseClass == "MEDMObj")
                {
                    Type t = dc.GetClassType();
                    if (t != null)
                    {
                        List <MObj> list = new List <MObj>();
                        if (dc.ClassType == "edm")
                        {
                            model.Select(list, t, $"select * from [{dc.Name}] (nolock) where id!=@p1 and id=@p2", "p1", dc.GetIdPropery().GetDefaultValue(), "p2", id);
                        }
                        else if (dc.ClassType == "session")
                        {
                            MObj o = model.CreateObject(t, Session.Id.ToString());
                            list.Add(o);

                            /* Если объекты хранятся в кеше то в сессии их запоминать не к чему
                             * model.SelectFromXML(list, t, Session.GetString(name), id);
                             */
                        }
                        else
                        {
                            throw new Exception($"Для автоматической генерации RefreshRow тип источника данных {dc.ClassType} не определен или задан неправильно.");
                        }
                        PutRefreshResult(list, dc, name, model, xrequest, xresponse);
                    }
                }
                else
                {
                    throw new Exception($"Для автоматической генерации RefreshRow класс источника данных {name} должен быть порожден от MEDMObj");
                }
            }
            return(xrow);
        }