Exemplo n.º 1
0
        private static EntityFieldModel GetFieldModel(string val, ref List <string> error)
        {
            var result = new EntityFieldModel();

            if (error == null)
            {
                error = new List <string>();
            }
            var items = val.Split(',', ',');

            if (items.Length < 3)
            {
                error.Add($"{val}少于3段");
                return(null);
            }
            result.Name    = items[0].Trim();
            result.Type    = items[1].Trim();
            result.Comment = items[2].Trim();
            if (items.Length > 3)
            {
                var len = items[3];
                if (result.Attributes == null)
                {
                    result.Attributes = new List <string>();
                }
                result.Attributes.Add($"[MaxLength({len})]");
            }
            return(result);
        }
Exemplo n.º 2
0
        private static EntityFieldModel GetFieldModelByPdmCfg(string code, string name, string dataType, string columnLength, string comment, string columnMandatory)
        {
            var nullAblePrefix            = columnMandatory == "1" ? "" : "?";
            Func <string, string> getType = dt =>
            {
                switch (dt)
                {
                case string v when v.Contains("uniqueidentifier"):
                    return("Guid" + nullAblePrefix);

                case string v when v.Contains("datetime"):
                    return("DateTime" + nullAblePrefix);

                case string v when v.Contains("bit"):
                    return("bool" + nullAblePrefix);

                case string v when v.Contains("varchar"):
                    return("string");

                case string v when v.Contains("int"):
                    return("int" + nullAblePrefix);

                default:
                    return("string");
                }
            };
            Func <string, string, List <string> > getAttrs = (dt, len) =>
            {
                if (dt.Contains("varchar") && len.HasValue())
                {
                    return(new List <string> {
                        $"[MaxLength({len})]"
                    });
                }
                return(new List <string>());
            };
            var field = new EntityFieldModel
            {
                Comment    = name + comment,
                Name       = code,
                Type       = getType(dataType),
                Attributes = getAttrs(dataType, columnLength)
            };

            return(field);
        }
Exemplo n.º 3
0
        public static VueFieldModel GenerateVueModelFromEntity(EntityFieldModel entityFieldModel)
        {
            var result = new VueFieldModel
            {
                Name    = ToCamel(entityFieldModel.Name),
                Comment = entityFieldModel.Comment,
            };

            if (CodeGeneraterHelper.IsEnumType(entityFieldModel))
            {
                result.Type      = "select";
                result.KeyValues = entityFieldModel.Type == "bool" ? "this.$enum.ETrueFalse" : $"this.$enum.{entityFieldModel.Type}s";
            }
            else
            {
                //支持:string,int,datetime,date,select,multiSelect,time
                switch (entityFieldModel.Type)
                {
                case "string":
                    result.Type = "string";
                    break;

                case "DateTime":
                    result.Type = "datetime";
                    break;

                case "int":
                    result.Type = "int";
                    break;

                default:
                    result.Type = "string";
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
 private static bool IsEnumType(EntityFieldModel entityFieldModel)
 {
     return(entityFieldModel.Type == "bool" || entityFieldModel.Type.StartsWith("E"));
 }