Ejemplo n.º 1
0
        /// <summary>
        /// 获取实体的文件名
        /// </summary>
        /// <param name="table">实体表信息</param>
        /// <param name="doc">文档信息</param>
        /// <returns></returns>
        public static string GetRealFileName(DBTableInfo table, ClassDesignerInfo designerInfo)
        {
            string   className = EntityFieldBase.ToPascalName(table.Name);
            FileInfo docfile   = new FileInfo(designerInfo.SelectDocView.DocData.FileName);

            return(docfile.DirectoryName + "\\" + className + ".cs");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 去掉基类已有字段
        /// </summary>
        private void FilterBaseTypeParam()
        {
            Dictionary <string, EntityParamField>   dicParam    = new Dictionary <string, EntityParamField>(StringComparer.CurrentCultureIgnoreCase);
            Dictionary <string, EntityRelationItem> dicRelation = new Dictionary <string, EntityRelationItem>(StringComparer.CurrentCultureIgnoreCase);

            FillBaseTypeParam(_baseType, _designerInfo, dicParam, dicRelation);
            int count = _belongTable.Params.Count;

            for (int i = count - 1; i >= 0; i--)
            {
                string key = _belongTable.Params[i].ParamName;
                if (dicParam.ContainsKey(key))
                {
                    _belongTable.Params.RemoveAt(i);
                }
            }

            count = _belongTable.RelationItems.Count;
            for (int i = count - 1; i >= 0; i--)
            {
                TableRelationAttribute er = _belongTable.RelationItems[i];
                string key = EntityFieldBase.ToPascalName(er.SourceName) + "_" + EntityFieldBase.ToPascalName(er.TargetName);
                if (dicRelation.ContainsKey(key))
                {
                    _belongTable.RelationItems.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取实体的文件名
        /// </summary>
        /// <param name="table">实体表信息</param>
        /// <param name="doc">文档信息</param>
        /// <returns></returns>
        public static string GetEntityRealFileName(DBTableInfo table, DBConfigInfo db, ClassDesignerInfo designerInfo)
        {
            string   className = EntityFieldBase.ToPascalName(table.Name);
            FileInfo docfile   = new FileInfo(designerInfo.SelectDocView.DocData.FileName);

            if (db.EntityToDirectory)
            {
                return(docfile.DirectoryName + "\\Entity\\" + className + ".cs");
            }
            return(docfile.DirectoryName + "\\" + className + ".cs");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 填充关系代码
        /// </summary>
        /// <param name="er"></param>
        /// <param name="sb"></param>
        internal static void FillRelationsInfo(TableRelationAttribute er, StringBuilder sb)
        {
            if (er.IsParent)
            {
                er.FieldTypeName = EntityFieldBase.ToPascalName(er.TargetTable);
                //string name = EntityFieldBase.ToPascalName(er.TargetTable) + "_" + EntityFieldBase.ToPascalName(er.SourceName) + "_" + EntityFieldBase.ToPascalName(er.TargetName);
                string name = EntityFieldBase.ToPascalName(er.SourceName) + "2" + EntityFieldBase.ToPascalName(er.TargetTable);
                er.FieldName    = "_belong" + name;
                er.PropertyName = name;
                er.IsToDB       = true;
                sb.AppendLine("        /// <summary>");
                sb.AppendLine(FormatSummary(er.Description));
                sb.AppendLine("        /// </summary>");
                sb.AppendLine("        protected " + er.FieldTypeName + " " + er.FieldName + ";");
                sb.AppendLine("");

                sb.AppendLine("        /// <summary>");
                sb.AppendLine("        /// " + er.Description);
                sb.AppendLine("        /// </summary>");
                sb.AppendLine("        public virtual " + er.FieldTypeName + " " + er.PropertyName);
                sb.AppendLine("        {");
                sb.AppendLine("            get{ return " + er.FieldName + "; }");
                sb.AppendLine("            set{ " + er.FieldName + " = value; }");
                sb.AppendLine("        }");
            }
            else
            {
                er.FieldTypeName = "List<" + EntityFieldBase.ToPascalName(er.TargetTable) + ">";
                string name = EntityFieldBase.ToPascalName(er.TargetTable) + "2" + EntityFieldBase.ToPascalName(er.TargetName);
                er.FieldName = "_lst" + name;
                //er.PropertyName = "Lst" + name;

                er.PropertyName = name;
                er.IsToDB       = false;
                sb.AppendLine("        /// <summary>");
                sb.AppendLine(FormatSummary(er.Description));
                sb.AppendLine("        /// </summary>");
                sb.AppendLine("        protected " + er.FieldTypeName + " " + er.FieldName + ";");
                sb.AppendLine("");

                sb.AppendLine("        /// <summary>");
                sb.AppendLine("        /// " + er.Description);
                sb.AppendLine("        /// </summary>");
                sb.AppendLine("        public virtual " + er.FieldTypeName + " " + er.PropertyName);
                sb.AppendLine("        {");
                sb.AppendLine("            get{ return " + er.FieldName + "; }");
                sb.AppendLine("            set{ " + er.FieldName + " = value; }");
                sb.AppendLine("        }");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加字段代码
        /// </summary>
        /// <param name="prm"></param>
        /// <param name="sb"></param>
        internal static void AppendFieldInfo(EntityParam prm, StringBuilder sb)
        {
            prm.FieldName = "_" + EntityFieldBase.ToCamelName(prm.ParamName);
            string typeName = ToCSharpType(prm.SqlType, prm.AllowNull);

            sb.AppendLine("        ///<summary>");
            sb.AppendLine(FormatSummary(prm.Description));
            sb.AppendLine("        ///</summary>");
            sb.AppendLine("        protected " + typeName + " " + prm.FieldName + ";");
            sb.AppendLine("");


            prm.PropertyName = EntityFieldBase.ToPascalName(prm.ParamName);

            sb.AppendLine("        /// <summary>");
            sb.AppendLine(FormatSummary(prm.Description));
            sb.AppendLine("        ///</summary>");
            sb.AppendLine("        public virtual " + typeName + " " + prm.PropertyName + "");
            sb.AppendLine("        {");
            sb.AppendLine("            get{ return " + prm.FieldName + ";}");
            sb.AppendLine("            set{ " + prm.FieldName + "=value;}");
            sb.AppendLine("        }");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 初始化类信息
        /// </summary>
        private void InitInfo()
        {
            _className = EntityFieldBase.ToPascalName(_belongTable.Name);

            _fileName = GetRealFileName(_belongTable, DesignerInfo);
        }