Пример #1
0
        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);
            }
        }
Пример #2
0
        protected XmlNode DefinitionForMarkList(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse, string sectiontype = "", bool addExpand = false)
        {
            bool isdefultsection = false;

            if (sectiontype.ToLower() == "default")
            {
                isdefultsection = true;
                sectiontype     = "";
            }
            XmlNode xrowset  = XFunc.AppendWithFind(xresponse, "rowset", "rowset", name.ToLower(), "datasource", name.ToLower());
            XmlNode xsection = XFunc.Append(xrowset, "section", "row.type", sectiontype);

            XmlNode xrequests = XFunc.Append(xsection, "requests");

            XFunc.Append(xrequests, "request", "name", "refresh");
            XFunc.Append(xrequests, "request", "name", "mark");
            if (addExpand)
            {
                XFunc.Append(xrequests, "request", "name", "expand");
            }
            if (isdefultsection)
            {
                return(xsection);
            }
            XmlNode xfields = XFunc.Append(xsection, "fields");

            {
                XFunc.SetAttr(xfields, "name", "_tostring_");
                XFunc.Append(xfields, "field", "name", "_tostring_", "type", "string", "caption", "", "len", "255");
            }
            return(xsection);
        }
Пример #3
0
        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);
        }
Пример #4
0
 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));
         }
     }
 }
Пример #5
0
        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");
                }
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        public override void InitCfg(string filename)
        {
            MainTrace.Add(TraceType.Cfg, $"file => {Path.GetFileName(filename)} ");
            XmlDocument xdoc = XFunc.Load(filename);

            foreach (XmlNode cfgNode in xdoc.SelectNodes("descendant::cfg"))
            {
                foreach (XmlNode typeNode in cfgNode.SelectNodes("*"))
                {
                    Type t = GetClassTypeByClassName(typeNode.Name);
                    if (t != null)
                    {
                        MainTrace.Add(TraceType.Cfg, $"Class => {t.Name}");
                        foreach (XmlNode itemNode in typeNode.SelectNodes("*"))
                        {
                            LockUpdates++;
                            try
                            {
                                MEDMObj obj = MainDic.GetObj(t, itemNode.Name);
                                obj.SetValues(itemNode);
                                MainTrace.Add(TraceType.Cfg, $"Item => {itemNode.Name} ({obj})");
                            }
                            finally
                            {
                                LockUpdates--;
                            }
                        }
                    }
                    else
                    {
                        MainTrace.Add(TraceType.Error, $"Для узла конфигурации {typeNode.Name} класс не найден");
                    }
                }
            }
        }
Пример #8
0
        protected void Refresh(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse)
        {
            if (name == "empty")
            {
                XmlNode xrow = XFunc.Append(xresponse, "row", "id", "0");
                return;
            }
            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")
                        {
                            RunRefreshSelect(list, dc, name, model, xrequest, xresponse);
                        }
                        else if (dc.ClassType == "session")
                        {
                            MObj o = model.CreateObject(t, Session.Id.ToString());
                            list.Add(o);

                            /* Если объекты хранятся в кеше то в сессии их запоминать не к чему
                             * string id = XFunc.GetText(xrequest.SelectSingleNode("param[@name='id']"), Session.Id);
                             * model.SelectFromXML(list, t, Session.GetString(name), id);
                             * if (list.Count == 0)
                             * {
                             *  MObj o = model.CreateObject(t, Session.Id.ToString());
                             *  list.Add(o);
                             *  model.Save(Session);
                             * }
                             */
                        }
                        else
                        {
                            throw new Exception($"Для автоматической генерации Refresh тип источника данных {dc.ClassType} не определен или задан неправильно.");
                        }
                        PutRefreshResult(list, dc, name, model, xrequest, xresponse);
                    }
                }
                else
                {
                    throw new Exception($"Для автоматической генерации Refresh класс источника данных {name} должен быть порожден от MEDMObj");
                }
            }
            else
            {
                List <MObj> list = new List <MObj>();
                RunRefreshSelect(list, dc, name, model, xrequest, xresponse);
                PutRefreshResult(list, dc, name, model, xrequest, xresponse);
            }
        }
Пример #9
0
        protected void MarkSetCount(string idlist, XmlNode xresponse)
        {
            int count = 0;

            char[] d = { ';' };
            if (!string.IsNullOrEmpty(idlist))
            {
                count = idlist.Split(d, StringSplitOptions.RemoveEmptyEntries).Length;
            }
            XFunc.SetAttr(xresponse, "markcount", count.ToString());
        }
Пример #10
0
 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);
         }
     }
 }
Пример #11
0
 /// <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");
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #12
0
        protected override void RunJoin(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse)
        {
            MEDMDefClass dc = MEDMDefModel.MainDef.Find(name);

            if (dc == null)
            {
                throw new Exception($"Нет описателя класса соответстующго имени {name}");
            }
            MEDMDefProperty dp = dc.GetIdPropery();
            List <Guid>     l  = MarkId <Guid>(Session.GetString(MarkKey(xrequest)), name.ToLower());

            if (l.Count > 0)
            {
                object id = M740.GetParam(dp.GetPropertyType(), xrequest, "id", "");
                if (id != dp.GetDefaultValue())
                {
                    string sql = "";
                    foreach (MEDMDefClass dc1 in MEDMDefModel.MainDef.AllClasses)
                    {
                        foreach (MEDMDefProperty dp1 in dc1.Properties)
                        {
                            if (dp1.RefClass == dc)
                            {
                                sql += $"update [{dc1.Name}] set [{dp1.Name}]=@p0 where CountryPresentingDemandId=@p1\r\n";
                            }
                        }
                    }
                    sql += $"delete [{name}] where Id=@p1\r\n";

                    foreach (object joinid in l)
                    {
                        if (joinid != dp.GetDefaultValue() && joinid != id)
                        {
                            model.Exec(sql, "p0", id, "p1", joinid);
                        }
                    }
                    RunMarkClear(name, model, xrequest, xresponse);
                    XFunc.SetAttr(xresponse, "exec", "refresh");
                }
            }
            else
            {
                throw new Exception($"Нет омеченных элементов");
            }
        }
Пример #13
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);
        }
Пример #14
0
        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");
                }
            }
        }
Пример #15
0
        public virtual bool GenFormByDef(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse)
        {
            MEDMDefClass ds = MEDMDefModel.MainDef.Find(name);

            if (ds != null)
            {
                XmlNode xform    = XFunc.Append(xresponse, "form", "name", ds.Name.ToLower(), "caption", ds.Header);
                XmlNode xrowsets = XFunc.Append(xform, "rowsets");
                XmlNode xrowset  = XFunc.Append(xrowsets, "rowset", "rowset", ds.Name.ToLower(), "datasourse", ds.Name.ToLower());
                XmlNode xpanels  = XFunc.Append(xform, "panels");
                XmlNode xpanel   = XFunc.Append(xpanels, "panel", "type", "grid", "caption", ds.Header, "rowset", ds.Name.ToLower());
                XmlNode xtoolbar = XFunc.Append(xpanel, "toolbar", "default", "1");
                foreach (MEDMDefProperty dp in ds.Properties)
                {
                    if (dp.Name.ToLower() != "id")
                    {
                        XmlNode xfield = XFunc.Append(xpanel, "field", "name", dp.Name.ToLower());
                    }
                }
                return(true);
            }
            return(false);
        }
Пример #16
0
 protected override void PutRefreshResult(List <MObj> list, MEDMDefClass dc, string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse)
 {
     foreach (MObj obj in list)
     {
         XmlNode xrow = XFunc.Append(xresponse, "row");
         if (dc == null)
         {
             dc = MEDMDefModel.MainDef.Find(obj.GetType());
         }
         if (dc != null)
         {
             foreach (MEDMDefProperty dp in dc.Properties)
             {
                 if (dp.IsInterval)
                 {
                     XFunc.SetAttr(xrow, dp.Name.ToLower() + ".min", obj.GetValueAsString(dp.Name + ".Min"));
                     XFunc.SetAttr(xrow, dp.Name.ToLower() + ".max", obj.GetValueAsString(dp.Name + ".Max"));
                 }
                 else
                 {
                     XFunc.SetAttr(xrow, dp.Name.ToLower(), obj.GetValueAsString(dp.Name));
                 }
                 if (!MEDMObj.IsEmptyId(dp.RefClassId))
                 {
                     string n = dp.GetRefName().ToLower();
                     XFunc.SetAttr(xrow, n + "_tostring_", obj.GetValueAsString(n));
                 }
             }
         }
         else if (obj is MEDMObj)
         {
             XFunc.SetAttr(xrow, "id", (obj as MEDMObj).GetId().ToString());
         }
         XFunc.SetAttr(xrow, "_tostring_", obj.ToString());
         PutRowResult(obj, xrow, dc, name, model, xrequest, xresponse);
     }
 }
Пример #17
0
        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");
                }
            }
        }
Пример #18
0
 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}");
 }
Пример #19
0
 public WitchcraftNoParams(MethodInfo methodInfo)
 {
     _func = (XFunc <Sandbox, object>)Delegate.CreateDelegate(
         typeof(XFunc <Sandbox, object>), methodInfo);
 }
Пример #20
0
 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
         {
         }
     }
 }
Пример #21
0
 public WitchcraftNoParams(MethodInfo methodInfo)
 {
     _func = (XFunc<Sandbox, object>)Delegate.CreateDelegate(
         typeof(XFunc<Sandbox, object>), methodInfo);
 }
Пример #22
0
        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;
            }
        }
Пример #23
0
        protected XmlNode Definition(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse, string sectiontype = "", bool addExpand = false, bool addToString = false, bool isReadOnly = false)
        {
            MEDMDefClass dc = MEDMDefModel.MainDef.Find(name);

            if (sectiontype != "")
            {
                dc = MEDMDefModel.MainDef.Find(sectiontype);
            }

            bool isdefultsection = false;

            if (name == "empty")
            {
                XmlNode xrowset   = XFunc.AppendWithFind(xresponse, "rowset", "rowset", "empty", "datasource", "empty");
                XmlNode xsection  = XFunc.Append(xrowset, "section", "row.type", sectiontype);
                XmlNode xrequests = XFunc.Append(xsection, "requests");
                XFunc.Append(xrequests, "request", "name", "refresh");
                return(xsection);
            }
            else if (dc != null)
            {
                isReadOnly = isReadOnly || dc.IsReadOnly;
                if (sectiontype.ToLower() == "default")
                {
                    isdefultsection = true;
                    sectiontype     = "";
                }
                XmlNode xrowset  = XFunc.AppendWithFind(xresponse, "rowset", "rowset", name.ToLower(), "datasource", name.ToLower(), "readonly", isReadOnly ? "1" : "0");
                XmlNode xsection = XFunc.Append(xrowset, "section", "row.type", sectiontype);

                XmlNode xrequests = XFunc.Append(xsection, "requests");
                XFunc.Append(xrequests, "request", "name", "refresh");
                if (addExpand)
                {
                    XFunc.Append(xrequests, "request", "name", "expand");
                }
                if (isdefultsection)
                {
                    return(xsection);
                }
                if (dc != null && dc.BaseClass == "MEDMObj" && !isReadOnly)
                {
                    XFunc.Append(xrequests, "request", "name", "save");
                    XFunc.Append(xrequests, "request", "name", "append");
                    XFunc.Append(xrequests, "request", "name", "delete");
                }
                if (dc.IsMark)
                {
                    XFunc.Append(xrequests, "request", "name", "mark");
                    XFunc.Append(xrequests, "request", "name", "markclear");
                    XmlNode xparams = XFunc.AppendWithFind(xrequests, "params");
                    XFunc.Append(xparams, "param", "name", "markmode", "value", name.ToLower());
                    XFunc.Append(xparams, "param", "name", "markfield", "value", name.ToLower() + "list");
                }
                if (dc.IsJoin && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "join");
                    if (dc.CaptionJoin == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Объединить отмеченные строки...");
                    }
                    else if (dc.CaptionJoin != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionJoin);
                    }
                    if (dc.ConfirmJoin == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут объединены с текущей строкой...");
                    }
                    else if (dc.ConfirmJoin != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmJoin);
                    }
                }
                if (dc.IsCopy && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "copy");
                    if (dc.CaptionCopy == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Копировать отмеченные строки...");
                    }
                    else if (dc.CaptionCopy != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionCopy);
                    }
                    if (dc.ConfirmCopy == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут скопированы...");
                    }
                    else if (dc.ConfirmCopy != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmCopy);
                    }
                }
                if (dc.IsMove && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "move");
                    if (dc.CaptionMove == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Перенести отмеченные строки...");
                    }
                    else if (dc.CaptionMove != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionMove);
                    }
                    if (dc.ConfirmMove == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут перенесены...");
                    }
                    else if (dc.ConfirmMove != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmMove);
                    }
                }
                if (dc.IsLink && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "link");
                    if (dc.CaptionLink == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Присоединить отмеченные строки...");
                    }
                    else if (dc.CaptionLink != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionLink);
                    }
                    if (dc.ConfirmLink == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут присоединены...");
                    }
                    else if (dc.ConfirmLink != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmLink);
                    }
                }
                if (dc.IsClone && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "clone");
                    if (dc.CaptionClone == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Клонировать отмеченные строки...");
                    }
                    else if (dc.CaptionClone != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionClone);
                    }
                    if (dc.ConfirmClone == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут клонированы...");
                    }
                    else if (dc.ConfirmClone != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmClone);
                    }
                }
                XmlNode xfields = XFunc.Append(xsection, "fields");
                foreach (MEDMDefProperty dp in dc.Properties)
                {
                    if (dp.IsVisible)
                    {
                        if (dp.IsInterval)
                        {
                            XFunc.Append(xfields, "field", "name", (dp.Name + ".Min").ToLower(), "type", dp.GetDataTypeFor740(), "caption", dp.Header + " от", "len", GetLen(dp));
                            XFunc.Append(xfields, "field", "name", (dp.Name + ".Max").ToLower(), "type", dp.GetDataTypeFor740(), "caption", "до", "len", GetLen(dp));
                        }
                        else
                        {
                            string t    = dp.GetDataTypeFor740();
                            string list = "";
                            if (!string.IsNullOrEmpty(dp.Items))
                            {
                                foreach (string item in dp.Items.Split(itemd, StringSplitOptions.RemoveEmptyEntries))
                                {
                                    string item1 = item.Replace(";", ",").Trim();
                                    if (!string.IsNullOrEmpty(item1))
                                    {
                                        if (!string.IsNullOrEmpty(list))
                                        {
                                            list += ";";
                                        }
                                        list += item1;
                                    }
                                }
                            }
                            if (list != "")
                            {
                                t = "list";
                            }
                            XmlNode xfield = XFunc.Append(xfields, "field", "name", dp.Name.ToLower(), "type", t, "caption", dp.Header, "len", GetLen(dp), "list", list);
                            if (t == "radio")
                            {
                                if (dp.DataType == "int" || dp.DataType == "long" || dp.DataType == "short" || dp.DataType == "byte")
                                {
                                    XFunc.SetAttr(xfield, "basetype", "num");
                                    XFunc.SetAttr(xfield, "default", MFunc.StringToInt(dp.DefValue, 1).ToString());
                                }
                                else
                                {
                                }
                            }
                            if (!MEDMObj.IsEmptyId(dp.RefClassId))
                            {
                                XFunc.Append(xfield, "ref", "datasource", dp.RefClass.Name.ToLower());
                                XFunc.SetAttr(xfield, "type", "ref");
                                XFunc.SetAttr(xfield, "visible", "0");
                                XmlNode xreffield = XFunc.Append(xfields, "field", "name", (dp.GetRefName() + "_tostring_").ToLower(), "type", "string", "refid", dp.Name.ToLower(), "refname", "_tostring_", "caption", dp.Header, "len", GetLen(dp));
                            }
                        }
                    }
                }
                if (addToString)
                {
                    XFunc.SetAttr(xfields, "name", "_tostring_");
                    XFunc.Append(xfields, "field", "name", "_tostring_", "type", "string", "caption", "", "len", "255");
                }
                return(xsection);
            }
            return(null);
        }
Пример #24
0
        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;
                }
            }
        }