Exemplo n.º 1
0
        public string DoFormat1(string arg)
        {
            string[] lines = Fields.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            StringBuilder code = new StringBuilder();

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                string[] words = line.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                StringBuilder sb = new StringBuilder();
                for (int i = 1; i < words.Length; i++)
                {
                    sb.Append(words[i].Trim(CoderBase.NoneLanguageChar).ToUWord());
                }
                var name = sb.ToString().Trim(CoderBase.NoneLanguageChar);
                if (name[0] >= '0' && name[0] <= '9')
                {
                    name = "m" + name;
                }
                StringBuilder sb2 = new StringBuilder();
                for (int i = 1; i < words.Length; i++)
                {
                    sb2.Append(words[i].ToUWord());
                    sb2.Append(' ');
                }
                code.Append($"{name},{words[0]},{sb2},{BaiduFanYi.FanYi(sb2.ToString())}\r\n");
            }
            return(code.ToString());
        }
Exemplo n.º 2
0
        private void CheckColumns(SqlCommand cmd, EntityConfig schema)
        {
            parameter.Value = schema.ReadTableName;
            foreach (PropertyConfig col in schema.PublishProperty)
            {
                col.DbIndex = 0;
            }
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    string         field = reader.GetString(0);
                    PropertyConfig col   = schema.DbFields.FirstOrDefault(p => string.Equals(p.ColumnName, field, StringComparison.OrdinalIgnoreCase));
                    if (col == null)
                    {
                        schema.Properties.Add(col = new PropertyConfig
                        {
                            Name        = field,
                            Caption     = BaiduFanYi.FanYi(field),
                            Description = BaiduFanYi.FanYi(field),
                            ColumnName  = field,
                            DbType      = reader.GetString(1),
                            Parent      = Entity
                        });

                        col.Datalen = Convert.ToInt32(reader.GetValue(2));
                        col.Scale   = Convert.ToInt32(reader.GetValue(3));
                        if (col.Datalen <= 0)
                        {
                            col.Datalen = Convert.ToInt32(reader.GetValue(4));
                        }
                        col.CsType = ToCstringType(col.DbType);
                    }
                    else
                    {
                        col.DbType = reader.GetString(1);
                        if (col.CsType.Equals("string", StringComparison.OrdinalIgnoreCase))
                        {
                            col.Datalen = Convert.ToInt32(reader.GetValue(4));
                        }
                        else
                        {
                            col.Datalen = Convert.ToInt32(reader.GetValue(2));
                            col.Scale   = Convert.ToInt32(reader.GetValue(3));
                        }
                    }
                    col.DbNullable = reader.GetBoolean(5);
                    col.DbIndex    = Convert.ToInt32(reader.GetValue(6));
                    if (!reader.IsDBNull(7))
                    {
                        col.Caption = col.Description = reader.GetString(7);
                    }
                    col.IsPrimaryKey = !reader.IsDBNull(8);
                    col.IsIdentity   = reader.GetBoolean(9);
                    col.IsCompute    = reader.GetBoolean(10);
                }
            }
        }
Exemplo n.º 3
0
 private static string ReplceWord(string caption, bool isEn)
 {
     if (caption == null)
     {
         return(null);
     }
     caption = caption.Trim(NoneLanguageChar);
     if (isEn)
     {
         caption = BaiduFanYi.FanYi(caption);
     }
     return(caption);
 }
Exemplo n.º 4
0
        private static void ToChiness2(ConfigBase config)
        {
            config.Caption = BaiduFanYi.FanYi(config.Name);
            var parent = config as ParentConfigBase;

            if (parent == null)
            {
                return;
            }
            foreach (var child in parent.MyChilds)
            {
                ToChiness2(child);
            }
        }
Exemplo n.º 5
0
 private static string ReplceWord(string caption, bool isEn)
 {
     if (caption == null)
     {
         return(null);
     }
     caption = caption.Trim(NoneLanguageChar);
     if (isEn)
     {
         caption = BaiduFanYi.FanYi(caption);
     }
     caption = caption.Replace("blackcard", "黑卡");
     caption = caption.Replace("vleader", "V领队");
     return(caption);
 }
 /// <summary>
 ///     中译英
 /// </summary>
 public void ToEnglish()
 {
     if (Entity.IsFreeze)
     {
         return;
     }
     foreach (var col in Entity.Properties)
     {
         if (string.IsNullOrEmpty(col.Caption) || (!string.IsNullOrWhiteSpace(col.Name) && col.Name[0] < 256))
         {
             continue;
         }
         col.Name = BaiduFanYi.FanYiWord(col.Caption);
     }
     Entity.IsModify = true;
 }
Exemplo n.º 7
0
 public void CheckColumns(SqlConnection connection, string table, string description)
 {
     using (var cmd = new SqlCommand(sql, connection))
     {
         cmd.Parameters.Add(parameter = new SqlParameter("@entity", SqlDbType.NVarChar, 256));
         var           ch = table.Split('_');
         string        pro;
         ProjectConfig project;
         if (ch.Length > 1)
         {
             pro     = ch[1];
             project = SolutionConfig.Current.Projects.FirstOrDefault(p => string.Equals(p.Name, pro,
                                                                                         StringComparison.OrdinalIgnoreCase));
             if (project == null)
             {
                 SolutionConfig.Current.Projects.Add(project = new ProjectConfig
                 {
                     Name        = pro,
                     Caption     = BaiduFanYi.FanYi(pro),
                     Description = BaiduFanYi.FanYi(pro),
                     DbHost      = Project.DbHost,
                     DbPassWord  = Project.DbPassWord,
                     DbUser      = Project.DbUser,
                     DbSoruce    = Project.DbSoruce,
                 });
             }
         }
         else
         {
             project = Project;
         }
         var name   = ch.Length > 2 ? ch[2] : table;
         var cap    = BaiduFanYi.FanYi(name);
         var entity = new EntityConfig
         {
             Name          = name,
             Caption       = description,
             Description   = description,
             ReadTableName = table,
             SaveTableName = table,
             Parent        = project
         };
         CheckColumns(cmd, entity);
         project.Entities.Add(entity);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        ///     自动修复
        /// </summary>
        public void EnumToEnglish()
        {
            var en = Context.SelectConfig as EnumConfig;

            if (en == null)
            {
                return;
            }
            foreach (var item in en.Items)
            {
                if (string.IsNullOrWhiteSpace(item.Name) || item.Name[0] < 256)
                {
                    continue;
                }
                item.Name = BaiduFanYi.FanYiWord(item.Name);
            }
            en.IsModify = true;
        }
Exemplo n.º 9
0
        private void DoImport()
        {
            _trace.Message1 = "连接数据库";
            _trace.Track    = _connectionString;
            using (MySqlConnection connection = new MySqlConnection(_connectionString))
            {
                _trace.Track = "正在连接...";
                connection.Open();
                _trace.Track = "连接成功";
                var tables = new List <string>();

                _trace.Message1 = "分析数据表";
                using (var cmd = connection.CreateCommand())
                {
                    _trace.Message2 = "读取表名";
                    _trace.Track    = "正在读取表名...";
                    cmd.CommandText =
                        $@"select Table_Name from information_schema.tables where table_schema='{_database}' and table_type='base table';";
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (!reader.HasRows)
                        {
                            _trace.Message1 = "没有任何表";
                            return;
                        }
                        while (reader.Read())
                        {
                            tables.Add(reader.GetString(0));
                        }
                    }
                    _trace.Track = $@"读取成功({tables.Count})";
                }
                _trace.Message1 = "分析表结构";
                foreach (var t in tables)
                {
                    string table = t;
                    bool   isnew = false;
                    _trace.Message2 = table;
                    var entity = _solution.Entities.FirstOrDefault(p => string.Equals(p.SaveTable, table, StringComparison.OrdinalIgnoreCase));
                    if (entity == null)
                    {
                        isnew  = true;
                        entity = new EntityConfig
                        {
                            ReadTableName = table,
                            Name          = CoderBase.ToWordName(table),
                            Project       = _database
                        };
                        _trace.Track   = @"新增的表";
                        entity.Caption = BaiduFanYi.FanYi(entity.Name);
                        _dispatcher.Invoke(() =>
                        {
                            _project.Entities.Add(entity);
                            _solution.Entities.Add(entity);
                        });
                    }
                    _trace.Message3 = "列分析";
                    using (var cmd = connection.CreateCommand())
                    {
                        LoadColumn(_database, cmd, table, entity, isnew);
                    }
                }
            }
            _trace.Message1 = "完成";
        }
Exemplo n.º 10
0
        public static void CheckEnum(PropertyConfig column)
        {
            var line = column.Description?.Trim(CoderBase.NoneLanguageChar) ?? "";

            StringBuilder sb          = new StringBuilder();
            StringBuilder caption     = new StringBuilder();
            bool          preIsNumber = false;
            bool          startEnum   = false;
            EnumConfig    ec          = new EnumConfig
            {
                Name        = column.Parent.Name.ToUWord() + column.Name.ToUWord(),
                Description = column.Description,
                Caption     = column.Caption,
                Items       = new ConfigCollection <EnumItem>()
            };
            EnumItem ei = new EnumItem();

            foreach (var c in line)
            {
                if (c >= '0' && c <= '9')
                {
                    if (!preIsNumber)
                    {
                        if (!startEnum)
                        {
                            caption.Append(sb);
                        }
                        else if (sb.Length > 0)
                        {
                            new List <string>().Add(sb.ToString());
                            ei.Caption = sb.ToString();
                        }
                        sb        = new StringBuilder();
                        startEnum = true;
                    }
                    preIsNumber = true;
                }
                else
                {
                    if (preIsNumber)
                    {
                        if (sb.Length > 0)
                        {
                            ei = new EnumItem
                            {
                                Value = sb.ToString()
                            };
                            ec.Items.Add(ei);
                            sb = new StringBuilder();
                        }
                    }
                    preIsNumber = false;
                }
                sb.Append(c);
            }

            if (!startEnum)
            {
                return;
            }
            if (sb.Length > 0)
            {
                if (preIsNumber)
                {
                    ec.Items.Add(new EnumItem
                    {
                        Value = sb.ToString()
                    });
                }
                else
                {
                    ei.Caption = sb.ToString();
                }
            }

            if (ec.Items.Count > 0)
            {
                ec.LinkField       = column.Key;
                column.EnumConfig  = ec;
                column.CustomType  = ec.Name;
                column.Description = line;
                foreach (var item in ec.Items)
                {
                    if (string.IsNullOrEmpty(item.Caption))
                    {
                        column.EnumConfig = null;
                        column.CustomType = null;
                        return;
                    }
                    var arr = item.Caption.Trim(CoderBase.NoneNameChar).Split(CoderBase.NoneNameChar, StringSplitOptions.RemoveEmptyEntries);
                    if (arr.Length == 0)
                    {
                        column.EnumConfig = null;
                        column.CustomType = null;
                        return;
                    }
                    item.Caption = arr[0];
                    item.Name    = BaiduFanYi.FanYiWord(item.Caption.MulitReplace2("", "表示"));
                }
                if (caption.Length > 0)
                {
                    column.Caption = caption.ToString();
                }
            }
            else
            {
                column.EnumConfig = null;
                column.CustomType = null;
            }
        }
Exemplo n.º 11
0
        /*
         * `TABLE_CATALOG` AS `TABLE_CATALOG`,
         * `TABLE_SCHEMA` AS `TABLE_SCHEMA`,
         * `TABLE_NAME` AS `TABLE_NAME`,
         * `COLUMN_NAME` AS `COLUMN_NAME`,
         * `ORDINAL_POSITION` AS `ORDINAL_POSITION`,
         * `COLUMN_DEFAULT` AS `COLUMN_DEFAULT`,
         * `IS_NULLABLE` AS `IS_NULLABLE`,
         * `DATA_TYPE` AS `DATA_TYPE`,
         * `CHARACTER_MAXIMUM_LENGTH` AS `CHARACTER_MAXIMUM_LENGTH`,
         * `CHARACTER_OCTET_LENGTH` AS `CHARACTER_OCTET_LENGTH`,
         * `NUMERIC_PRECISION` AS `NUMERIC_PRECISION`,
         * `NUMERIC_SCALE` AS `NUMERIC_SCALE`,
         * `DATETIME_PRECISION` AS `DATETIME_PRECISION`,
         * `CHARACTER_SET_NAME` AS `CHARACTER_SET_NAME`,
         * `COLLATION_NAME` AS `COLLATION_NAME`,
         * `COLUMN_TYPE` AS `COLUMN_TYPE`,
         * `COLUMN_KEY` AS `COLUMN_KEY`,
         * `EXTRA` AS `EXTRA`,
         * `PRIVILEGES` AS `PRIVILEGES`,
         * `COLUMN_COMMENT` AS `COLUMN_COMMENT`,
         * `GENERATION_EXPRESSION` AS `GENERATION_EXPRESSION`
         */
        private void LoadColumn(string db, MySqlCommand cmd, string table, EntityConfig entity, bool isNewEntity)
        {
            cmd.CommandText =
                $@"select COLUMN_NAME,IS_Nullable,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,COLUMN_KEY,COLUMN_COMMENT,EXTRA
from information_schema.columns where table_schema='{
                    db}' and table_name='{table}'";
            using (var reader = cmd.ExecuteReader())
            {
                if (!reader.HasRows)
                {
                    return;
                }
                while (reader.Read())
                {
                    var field = reader.GetString(0);
                    _trace.Message4 = field;
                    if (field == null)
                    {
                        continue;
                    }
                    var  dbType = reader.GetString(2);
                    var  column = entity.Properties.FirstOrDefault(p => string.Equals(p.ColumnName, field, StringComparison.OrdinalIgnoreCase));
                    bool isNew  = isNewEntity;
                    if (column == null)
                    {
                        _trace.Track = @"新字段";
                        isNew        = true;
                        column       = new PropertyConfig
                        {
                            ColumnName = field,
                            DbType     = dbType,
                            CsType     = ToCstringType(dbType),
                            Parent     = entity
                        };

                        InvokeInUiThread(() => entity.Properties.Add(column));
                        if (!reader.IsDBNull(5))
                        {
                            column.Caption = reader.GetString(5);
                        }
                        column.Description = column.Caption;
                    }
                    else if (column.DbType != dbType)
                    {
                        _trace.Track  = $@"字段类型变更:{column.DbType }->{dbType}";
                        column.DbType = dbType;
                        column.CsType = ToCstringType(column.DbType);
                    }
                    column.DbNullable   = reader.GetString(1) == "YES";
                    column.IsPrimaryKey = reader.GetString(4) == "PRI";

                    if (!reader.IsDBNull(3))
                    {
                        column.Datalen = (int)reader.GetInt64(3);
                    }

                    if (!reader.IsDBNull(6))
                    {
                        var ext = reader.GetString(6);
                        column.IsIdentity = ext.Contains("auto_increment");
                        if (column.IsIdentity)
                        {
                            _trace.Track = @"自增列";
                        }
                    }
                    if (!isNew)
                    {
                        continue;
                    }
                    _trace.Track = @"分析属性名称";
                    switch (column.DbType.ToLower())
                    {
                    case "varchar":
                    case "longtext":
                        column.Name = FirstBy(column.ColumnName, "m_str", "M_str", "m_", "M_");
                        break;

                    case "int":
                    case "tinyint":
                        column.Name = FirstBy(column.ColumnName, "m_b", "m_n", "m_", "M_");
                        break;

                    case "double":
                        column.Name = FirstBy(column.ColumnName, "m_d", "m_", "M_");
                        break;

                    default:
                        column.Name = FirstBy(column.ColumnName, "m_", "M_");
                        break;
                    }
                    column.Name  = CoderBase.ToWordName(column.Name ?? column.ColumnName);
                    _trace.Track = $@"属性名称:{column.Name}";
                    if (string.IsNullOrWhiteSpace(column.Caption))
                    {
                        column.Caption = BaiduFanYi.FanYi(column.Name);
                        _trace.Track   = $@"通过百度翻译得到中文名称:{column.Caption}";
                    }
                    else
                    {
                        CheckEnum(column);
                        if (column.EnumConfig != null)
                        {
                            column.EnumConfig.Name    = column.Name + "Type";
                            column.EnumConfig.Caption = column.Caption + "自定义类型";
                            column.CustomType         = column.EnumConfig.Name;
                            _trace.Track = $@"解析得到枚举类型:{column.EnumConfig.Name},参考内容{column.EnumConfig.Description}";
                        }
                    }
                    if (string.IsNullOrWhiteSpace(column.Description))
                    {
                        column.Description = column.Caption;
                    }
                    column.Caption = column.Caption.Split(CoderBase.NoneLanguageChar, 2)[0];
                }
            }
        }
Exemplo n.º 12
0
 private static void Name2CaptionChiness(ConfigBase config)
 {
     config.Caption = BaiduFanYi.ToChiness(config.Name);
 }
Exemplo n.º 13
0
 private static void ToChiness(ConfigBase config)
 {
     config.Caption     = BaiduFanYi.ToChiness(config.Caption ?? config.Name);
     config.Description = BaiduFanYi.ToChiness(config.Description);
 }
Exemplo n.º 14
0
 /// <summary>
 ///     自动修复
 /// </summary>
 public void CaptionToEnglish(ConfigBase item)
 {
     item.Caption = BaiduFanYi.ToWord(item.Caption);
 }
Exemplo n.º 15
0
 /// <summary>
 ///     英译中
 /// </summary>
 public void NameToEnglish(ConfigBase item)
 {
     item.Name = BaiduFanYi.ToWord(item.Name);
 }