Beispiel #1
0
        private static void convertToField(int spaceCount, StringBuilder fieldBuilder, StreamReader reader, ClassTemplate meta, int language_type)
        {
            if (fieldBuilder == null || reader == null || meta == null)
                return;
            //文件流回到开始的位置
            reader.DiscardBufferedData();
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            reader.BaseStream.Position = 0;

            string line;
            while ((line = reader.ReadLine()) != null)
            {

                line = findAndReplace(line, "%field_type%", meta.Field_type);
                line = findAndReplace(line, "%field_name%", meta.Field_name);
                line = findAndReplace(line, "%Field_name%", meta.Upper_field_name);
                if (line.IndexOf("%annotation%")!=-1&&string.IsNullOrEmpty(meta.Annotation))
                {
                    continue;
                }
                line = findAndReplace(line, "%annotation%", meta.Annotation);
                fieldBuilder.Append(getDesignatedSpace(spaceCount)).Append(line).Append("\r\n");

            }
        }
Beispiel #2
0
        private static void convertToMethod(int spaceCount, StringBuilder methodBuilder, StreamReader reader, ClassTemplate meta)
        {
            if (methodBuilder == null || reader == null || meta == null)
                return;

            //文件流回到开始的位置
            reader.DiscardBufferedData();
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            reader.BaseStream.Position = 0;

            string line = reader.ReadLine();
            while (line != null)
            {
                line = findAndReplace(line, "%field_type%", meta.Field_type);
                line = findAndReplace(line, "%field_name%", meta.Field_name);
                line = findAndReplace(line, "%Field_name%", meta.Upper_field_name);
                methodBuilder.Append(getDesignatedSpace(spaceCount)).Append(line).Append("\r\n");
                line = reader.ReadLine();
            }
        }
Beispiel #3
0
        private static string getFieldType(ClassTemplate meta, int language_type)
        {
            if (language_type == 1)
            {
                if (meta.Field_name.ToUpper().IndexOf("AMOUNT") != -1)
                {
                    //以amount结尾
                    return "BigDecimal";
                }
                foreach (string str in CommonUtil.javaFieldTypeMap.Keys)
                {
                    if (meta.Field_type.ToUpper().IndexOf(str) != -1)
                    {
                        return CommonUtil.javaFieldTypeMap[str];

                    }
                }
            }
            else if (language_type == 2)
            {
                if (meta.Field_name.ToUpper().LastIndexOf("AMOUNT") != -1)
                {
                    //以amount结尾
                    return "decimal";
                }
                foreach (string str in CommonUtil.cSharpFieldTypeMap.Keys)
                {
                    if (meta.Field_type.ToUpper().IndexOf(str) != -1)
                    {
                        return CommonUtil.cSharpFieldTypeMap[str];
                    }
                }
            }
            return "";
        }
Beispiel #4
0
        private static Dictionary<string, Hashtable> createSqlTemplate(StreamReader sqlReader)
        {
            if (sqlReader == null)
                return null;
            string line;
            Dictionary<string, Hashtable> dic = new Dictionary<string, Hashtable>();
            bool followTable = false;
            string newTableName = "";
            ClassTemplate preFieldClass = null;//前一个字段的对象
            try
            {
                while ((line = sqlReader.ReadLine()) != null)
                {
                    if (line.StartsWith("--"))
                        continue;

                    string[] tempArr = line.Split(' ');
                    if (tempArr.Length == 0)
                        return null;
                    List<string> fieldList = new List<string>();

                    //遍历数组只有有数据的时候才算有效的
                    foreach (string str in tempArr)
                    {
                        if (string.IsNullOrEmpty(str))
                            continue;
                        fieldList.Add(str);
                    }
                    if (fieldList.Count > 1)
                    {
                        if ("create".Equals(fieldList[0], StringComparison.OrdinalIgnoreCase) && "table".Equals(fieldList[1], StringComparison.OrdinalIgnoreCase))
                        {
                            //添加表名
                            newTableName = fieldList[2];
                            dic.Add(newTableName, new Hashtable());
                            followTable = true;
                            continue;
                        }
                        if (followTable)
                        {

                            Hashtable table = dic[newTableName];
                            //字段,类型
                            ClassTemplate temp = new ClassTemplate();
                            temp.Field_name = fieldList[0].ToLower();
                            temp.Field_type = fieldList[1];
                            table.Add(fieldList[0].ToLower(), temp);
                        }
                    }
                    if (line.IndexOf(")") != -1 && line.IndexOf(";") != -1)
                    {
                        //创建表名结束
                        followTable = false;
                        continue;
                    }

                    if (!followTable)
                    {
                        //创建注释
                        if (fieldList.Count > 3)
                        {
                            if ("comment".Equals(fieldList[0], StringComparison.OrdinalIgnoreCase)
                                && "on".Equals(fieldList[1], StringComparison.OrdinalIgnoreCase)
                                && "column".Equals(fieldList[2], StringComparison.OrdinalIgnoreCase))
                            {

                                string[] fieldStr = fieldList[3].Split('.');
                                if (fieldStr.Length == 2)
                                {
                                    Hashtable table = dic[newTableName];
                                    object obj = table[fieldStr[1].ToLower()];
                                    if (obj != null)
                                    {
                                        preFieldClass = obj as ClassTemplate;
                                        continue;
                                    }
                                }
                            }
                        }

                        //注释紧跟在is的后面
                        if (preFieldClass != null)
                        {
                            if (fieldList[0].IndexOf("is") != -1)
                            {

                                preFieldClass.Annotation = fieldList[1].Replace("'", "").Replace(";","");
                                preFieldClass = null;
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("解析失败!" + ex.Message, "系统");
                return null;
            }

            return dic;
        }