Ejemplo n.º 1
0
        /// <summary>
        /// 绑定UI信息
        /// </summary>
        /// <param name="dicControl"></param>
        /// <param name="item"></param>
        private void BindUIModleInfo(Dictionary <string, EditorBase> dicControl, UIModelItem item)
        {
            Dictionary <string, object> dic = item.CheckItem;

            List <EditorBase> lstEditor = new List <EditorBase>(dicControl.Count);

            foreach (KeyValuePair <string, EditorBase> kvp in dicControl)
            {
                lstEditor.Add(kvp.Value);
            }
            object value = null;

            foreach (EditorBase editor in lstEditor)
            {
                string key = editor.BindPropertyName;
                if (item.CheckItem.TryGetValue(key, out value))
                {
                    editor.Value = value;
                }
                else
                {
                    editor.Reset();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载属性项信息
        /// </summary>
        private void LoadItemCache()
        {
            string directory = ModelPath + "gencache\\";
            string fileName  = directory + _curEntityInfo.FullName + ".cache.xml";

            if (!File.Exists(fileName))
            {
                return;
            }
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(fileName);
            }
            catch { return; }
            XmlNodeList nodes = doc.GetElementsByTagName("modelitem");


            List <UIModelItem> lstCurPropertys = _curEntityInfo.Propertys;
            List <UIModelItem> lstNewPropertys = new List <UIModelItem>(lstCurPropertys.Count);

            for (int j = 0; j < nodes.Count; j++)
            {
                XmlNode      node = nodes[j];
                XmlAttribute att  = node.Attributes["name"];
                if (att == null)
                {
                    continue;
                }
                string name = att.InnerText;
                if (name == null)
                {
                    continue;
                }
                for (int i = lstCurPropertys.Count - 1; i >= 0; i--)
                {
                    UIModelItem item = lstCurPropertys[i];
                    if (item.PropertyName == name)
                    {
                        att = node.Attributes["isgen"];
                        if (att != null)
                        {
                            item.IsGenerate = att.InnerText == "1";
                        }

                        item.ReadItem(node, _configItemInfo);
                        lstNewPropertys.Add(item);
                        lstCurPropertys.RemoveAt(i);
                        break;
                    }
                }
            }
            _curEntityInfo.Propertys = lstNewPropertys;
        }
Ejemplo n.º 3
0
 private void gvMember_CurrentCellChanged(object sender, EventArgs e)
 {
     if (gvMember.CurrentCell == null)
     {
         return;
     }
     _currentItem = gvMember.Rows[gvMember.CurrentCell.RowIndex].DataBoundItem as UIModelItem;
     if (_propertyUIConfig != null && _currentItem != null)
     {
         BindUIModleInfo(_propertyUIConfig, _currentItem);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 初始化默认值
 /// </summary>
 /// <param name="collection">配置项</param>
 /// <param name="entityInfo">实体信息</param>
 /// <param name="selectedProject">选择项</param>
 /// <param name="itemInfo">所属的属性信息</param>
 public void InitDefaultValue(IEnumerable <ConfigItem> collection,
                              EntityInfo entityInfo, Project selectedProject, UIModelItem itemInfo)
 {
     foreach (ConfigItem citem in collection)
     {
         string dvalue = citem.DefaultValue;
         if (!string.IsNullOrEmpty(dvalue))
         {
             dvalue = ConfigItem.FormatDefaultValue(citem, entityInfo, selectedProject, itemInfo);
             object value = ConvertValue(dvalue, citem);
             _dicCheckItem[citem.Name] = value;
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 输出成GeneratorEntity
        /// </summary>
        /// <param name="classModelInfo"></param>
        /// <returns></returns>
        public Buffalo.GeneratorInfo.EntityInfo ToGeneratorEntity(UIModelItem classModelInfo)
        {
            List <Property> lst = new List <Property>(_lstProperty.Count);

            foreach (UIModelItem item in _lstProperty)
            {
                lst.Add(item.ToGeneratItem());
            }

            string dbName = DBConfigInfo.GetDbName(DesignerInfo);

            Buffalo.GeneratorInfo.EntityInfo entity = new Buffalo.GeneratorInfo.EntityInfo(dbName, _fileName,
                                                                                           _namespace, _className, _summary, _baseTypeName, lst,
                                                                                           _dicGenericInfo, classModelInfo.ToGeneratItem());
            return(entity);
        }
Ejemplo n.º 6
0
        ///// <summary>
        ///// 清空项目的编译缓存
        ///// </summary>
        //public void ClearCache(EntityInfo entityInfo, List<UIProjectItem> lstItem)
        //{
        //    foreach (UIProjectItem pitem in lstItem)
        //    {
        //        string mPath = UIConfigItem.FormatParameter(pitem.ModelPath, entityInfo);
        //        CodeGenCache.DeleteGenerationer(mPath);
        //        if (pitem.ChildItems != null && pitem.ChildItems.Count > 0)
        //        {
        //            ClearCache(entityInfo, pitem.ChildItems);
        //        }
        //    }
        //}

        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="entityInfo">实体信息</param>
        /// <param name="classConfig">UI配置信息</param>
        /// <param name="selectPropertys">选中需要生成的属性信息</param>
        /// <param name="lstItem">UI项目项</param>
        /// <param name="parentItem">父项</param>
        /// <returns></returns>
        private void GenerateCode(EntityInfo entityInfo, UIConfigItem classConfig, Project selectedProject,
                                  List <UIModelItem> selectPropertys, UIModelItem classInfo, List <UIProjectItem> lstItem, ProjectItem parentItem)
        {
            Encoding fileEncoding = null;

            foreach (UIProjectItem pitem in lstItem)
            {
                string      mPath   = UIConfigItem.FormatParameter(pitem.ModelPath, entityInfo, selectedProject);
                string      tPath   = UIConfigItem.FormatParameter(pitem.TargetPath, entityInfo, selectedProject);
                CodeGenInfo info    = CodeGenCache.GetGenerationer(mPath, entityInfo);
                string      content = info.Invoke(entityInfo, classConfig, selectPropertys, classInfo);
                fileEncoding = pitem.Encoding;
                ProjectItem item = SaveItem(tPath, selectedProject, content, pitem.GenType, parentItem, fileEncoding);
                if (pitem.ChildItems != null && pitem.ChildItems.Count > 0)
                {
                    GenerateCode(entityInfo, classConfig, selectedProject, selectPropertys, classInfo, pitem.ChildItems, item);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 初始化属性
        /// </summary>
        private void InitPropertys()
        {
            _lstProperty = new List <UIModelItem>();


            List <ClrProperty>   lstClrProperty = EntityConfig.GetAllMember <ClrProperty>(_classType, true);
            EntityConfig         entity         = new EntityConfig(_classType, DesignerInfo);
            Stack <EntityConfig> stkEntity      = EntityConfig.GetEntity(entity, DesignerInfo);

            foreach (ClrProperty property in lstClrProperty)
            {
                UIModelItem item = new UIModelItem(property);


                EntityParamField finfo = EntityConfig.FindParamInfoByName(stkEntity, item.PropertyName);
                if (finfo != null)
                {
                    bool      isPK  = EnumUnit.ContainerValue((int)finfo.EntityPropertyType, (int)EntityPropertyType.PrimaryKey);
                    TableInfo tinfo = new TableInfo(isPK, finfo.ParamName, finfo.Length, finfo.ReadOnly, (DbType)EnumUnit.GetEnumInfoByName(typeof(DbType), finfo.DbType).Value);
                    item.TabInfo = tinfo;
                }
                else
                {
                    EntityRelationItem rel = EntityConfig.FindRelInfoByName(stkEntity, item.PropertyName);
                    if (rel != null)
                    {
                        RelationInfo rinfo = new RelationInfo(rel.TargetProperty, rel.SourceProperty, rel.IsParent, rel.TypeName, rel.TypeFullName);
                        item.RelInfo = rinfo;
                    }
                }



                _lstProperty.Add(item);
            }
        }
Ejemplo n.º 8
0
        private void btnUp_Click(object sender, EventArgs e)
        {
            if (gvMember.SelectedRows.Count == 0)
            {
                return;
            }
            int index = gvMember.SelectedRows[0].Index;

            if (index <= 0)
            {
                return;
            }
            BindingList <UIModelItem> lst = gvMember.DataSource as BindingList <UIModelItem>;

            if (lst == null)
            {
                return;
            }
            UIModelItem tmp = lst[index];

            lst[index]     = lst[index - 1];
            lst[index - 1] = tmp;
            gvMember.Rows[index - 1].Selected = true;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 格式化默认项的值
        /// </summary>
        /// <param name="item">项信息</param>
        /// <param name="entityInfo">实体信息</param>
        /// <param name="selectedProject">选中的项目</param>
        /// <param name="itemInfo">项的属性信息</param>
        /// <returns></returns>
        public static string FormatDefaultValue(ConfigItem item,
                                                EntityInfo entityInfo, Project selectedProject, UIModelItem itemInfo)
        {
            string value = item.DefaultValue;

            value = UIConfigItem.FormatParameter(value, entityInfo, selectedProject);
            value = value.Replace("{ItemSummary}", item.Summary);
            value = value.Replace("{ItemName}", item.Name);
            if (itemInfo != null)
            {
                value = value.Replace("{PropertyName}", itemInfo.PropertyName);
                value = value.Replace("{PropertySummary}", itemInfo.Summary);
                value = value.Replace("{PropertyTypeName}", itemInfo.TypeName);
                value = value.Replace("{PropertyTypeFullName}", itemInfo.TypeFullName);
            }
            return(value);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 生成代码
 /// </summary>
 /// <param name="entityInfo">实体信息</param>
 /// <param name="classConfig">UI配置信息</param>
 /// <param name="selectPropertys">选中需要生成的属性信息</param>
 /// <returns></returns>
 public void GenerateCode(EntityInfo entityInfo, UIConfigItem classConfig, Project selectedProject, List <UIModelItem> selectPropertys, UIModelItem classInfo)
 {
     GenerateCode(entityInfo, classConfig, selectedProject, selectPropertys, classInfo, _lstItems, null);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 加载属性项信息
        /// </summary>
        private void LoadClassItemCache()
        {
            _classInfo = new UIModelItem();
            _classInfo.InitDefaultValue(_config.ClassItems, CurEntityInfo, CurEntityInfo.DesignerInfo.CurrentProject, null);
            string fileName = ModelPath + "\\classinfo.cache.xml";

            if (!File.Exists(fileName))
            {
                return;
            }
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(fileName);
            }
            catch { return; }
            XmlNodeList nodes = doc.GetElementsByTagName("root");

            if (nodes.Count <= 0)
            {
                return;
            }
            XmlNode nodeRoot = nodes[0];

            XmlAttribute attRoot = nodeRoot.Attributes["model"];

            if (attRoot != null)
            {
                string mname = attRoot.InnerText;
                if (!string.IsNullOrEmpty(mname))
                {
                    foreach (UIProject upro in _config.Projects)
                    {
                        if (upro.Name == mname)
                        {
                            cmbModels.Value = upro;
                            break;
                        }
                    }
                }
            }

            attRoot = nodeRoot.Attributes["project"];
            if (attRoot != null)
            {
                string pname = attRoot.InnerText;
                if (!string.IsNullOrEmpty(pname))
                {
                    foreach (Project ipro in _lstProjects)
                    {
                        if (ipro.Name == pname)
                        {
                            cmbProjects.Value = ipro;
                            break;
                        }
                    }
                }
            }

            _classInfo.ReadItem(nodeRoot, _configClassInfo);
        }