示例#1
0
        public static void ReadXml(string xml)
        {
            using (TextReader reader = new StringReader(xml))
            {
                var doc      = XDocument.Load(reader);
                var dbinfo   = doc.Element("root").Element("dbinfo");
                var server   = dbinfo.Element("server").Value;
                var uid      = dbinfo.Element("uid").Value;
                var pwd      = dbinfo.Element("pwd").Value;
                var database = dbinfo.Element("database").Value;
                var port     = dbinfo.Element("port").Value;
                var table    = dbinfo.Element("table").Value;

                PageCache.server       = server;
                PageCache.name         = uid;
                PageCache.pwd          = pwd;
                PageCache.DatabaseName = database;
                int portNum = 0;
                int.TryParse(port, out portNum);
                PageCache.port      = portNum;
                PageCache.TableName = table;

                var    keyinfo = doc.Element("root").Element("keyinfo");
                var    keyid   = keyinfo.Element("keyid").Value;
                string keytype = keyinfo.Element("keytype").Value;

                PageCache.KeyId        = keyid;
                PageCache.KeyId_DbType = keytype;

                PageCache.sqlColumnList = new List <SqlColumnInfo>();
                var cols = doc.Element("root").Element("cols");
                if (cols.HasElements)
                {
                    var colList = cols.Elements("col");
                    foreach (XElement colEle in colList)
                    {
                        var name     = colEle.Element("name").Value;
                        var colname  = colEle.Element("colname").Value;
                        var dbtype   = colEle.Element("dbtype").Value;
                        var attrtype = colEle.Element("attrtype").Value;
                        var title    = colEle.Element("title").Value;

                        PageCache.sqlColumnList.Add(new SqlColumnInfo()
                        {
                            Name      = colname,
                            DbType    = dbtype,
                            Comment   = title,
                            IsMainKey = colname == keyid,
                        });
                    }
                }

                PageCache.ExtendList = new List <ExtendAttributeInfo>();
                var extends    = doc.Element("root").Element("extends");
                var extendList = extends.Elements("extend");
                foreach (var extendEle in extendList)
                {
                    var name       = extendEle.Element("name").Value;
                    var colname    = extendEle.Element("colname").Value;
                    var dbtype     = extendEle.Element("dbtype").Value;
                    var attrtype   = extendEle.Element("attrtype").Value;
                    var title      = extendEle.Element("title").Value;
                    var formattype = extendEle.Element("formattype").Value;
                    int formatNum  = 0;
                    var formatstr  = extendEle.Element("formatstr").Value;
                    int.TryParse(formattype, out formatNum);

                    PageCache.ExtendList.Add(new ExtendAttributeInfo()
                    {
                        NewAttName       = name,
                        DependColumn     = colname,
                        Comment          = title,
                        DependColumnType = dbtype,
                        AttributeType    = attrtype,
                        FormatStr        = formatstr,
                        FormatType       = formatNum
                    });
                }

                PageCache.CmdList = new List <CmdInfo>();
                var toolinfo = doc.Element("root").Element("toolinfo");
                var tools    = toolinfo.Elements("tool");
                foreach (var toolEle in tools)
                {
                    CmdInfo cmdInfo = new CmdInfo();
                    var     name    = toolEle.Element("name").Value;
                    var     guid    = toolEle.Element("guid").Value;
                    cmdInfo.CmdName  = name;
                    cmdInfo.Guid     = guid;
                    cmdInfo.AttrList = new List <ClassAttributeInfo>();

                    var attrs    = toolEle.Element("attrs");
                    var attrList = attrs.Elements("attr");
                    foreach (var attrEle in attrList)
                    {
                        var    attrname       = attrEle.Element("name").Value;
                        var    title          = attrEle.Element("title").Value;
                        var    styleinfo      = attrEle.Element("styleinfo");
                        string style_name     = styleinfo.Element("name").Value;
                        int    style_type_Num = 0;
                        string style_type     = styleinfo.Element("type").Value;
                        int.TryParse(style_type, out style_type_Num);
                        string style_str = styleinfo.Element("str").Value;

                        var colInfo = PageCache.GetColumnList().Find(p => p.Name == attrname);
                        if (colInfo != null)
                        {
                            cmdInfo.AttrList.Add(new ClassAttributeInfo()
                            {
                                AttrName  = attrname,
                                ColName   = colInfo.Name,
                                DbType    = colInfo.DbType,
                                AttrType  = colInfo.DbType,
                                TitleName = colInfo.Comment,
                                Style     = new FieldStyleInfo()
                                {
                                    FieldName  = style_name,
                                    FormatType = style_type_Num,
                                    FormatStr  = style_str
                                }
                            });
                        }
                        else
                        {
                            var extendInfo = PageCache.ExtendList.Find(p => p.NewAttName == attrname);
                            cmdInfo.AttrList.Add(new ClassAttributeInfo()
                            {
                                AttrName  = attrname,
                                ColName   = extendInfo.DependColumn,
                                DbType    = extendInfo.DependColumnType,
                                AttrType  = extendInfo.AttributeType,
                                TitleName = extendInfo.Comment,
                                Style     = new FieldStyleInfo()
                                {
                                    FieldName  = style_name,
                                    FormatType = style_type_Num,
                                    FormatStr  = style_str
                                }
                            });
                        }
                    }

                    PageCache.CmdList.Add(cmdInfo);
                }

                var othersetting = doc.Element("root").Element("othersetting");
                PageCache.DbType           = int.Parse(othersetting.Element("dbtype").Value);
                PageCache.UIType           = int.Parse(othersetting.Element("uitype").Value);
                PageCache.WebType          = int.Parse(othersetting.Element("webtype").Value);
                PageCache.FrameworkVersion = int.Parse(othersetting.Element("version").Value);
                PageCache.ModelStyle       = int.Parse(othersetting.Element("modeltype").Value);
                PageCache.NameSpaceStr     = othersetting.Element("namespace").Value;
                PageCache.ModelSuffix      = othersetting.Element("modelsuffix").Value;
                PageCache.DALSuffix        = othersetting.Element("dalsuffix").Value;
                PageCache.UISuffix         = othersetting.Element("uisuffix").Value;
            }
        }
示例#2
0
 public static void AddCmd(CmdInfo info)
 {
     CmdList.Add(info);
 }