Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)

        {
            SettingMode mode = collectSettingMode();

            saveCacheData(SETTING_MODE, mode);
            FileUtils.saveObject(mode, setting_file);
            MessageBox.Show("保存成功!");
        }
Beispiel #2
0
        private string handleGetSetAndNoted(string content, TypeMode typeMode, SettingMode mode)
        {
            string result = content;

            //添加引用空间
            if (!result.Contains(typeMode.UsingSpace))
            {
                result = typeMode.UsingSpace + "\r\n" + result;
            }
            //类型替换
            result = Regex.Replace(result, @" " + typeMode.JavaName + " ", " " + typeMode.CSharpName + " ");

            //get set  注释处理
            string partten = @"(\s*)private " + typeMode.CSharpName + " ([a-zA-Z0-9]+)";

            if (typeMode.CSharpName.EndsWith("?") && typeMode.CSharpName.Length > 1)
            {
                int index = typeMode.CSharpName.LastIndexOf("?");
                partten = @"(\s*)private " + typeMode.CSharpName.Substring(0, index) + "\\" + typeMode.CSharpName.Substring(index) + " ([a-zA-Z0-9]+)";
            }
            Regex           r1 = new Regex(partten);
            MatchCollection matchCollection = r1.Matches(result);

            foreach (Match m in matchCollection)
            {
                var matchValue = m.Value;//private Int32 gnameId
                if (matchValue.Contains("?") && matchValue.Length > 1)
                {
                    int index = matchValue.LastIndexOf("?");
                    matchValue = matchValue.Substring(0, index) + "\\" + matchValue.Substring(index);
                }
                var spaceKey        = m.Result("$1");
                var javaFieldName   = m.Result("$2");
                var cSharpFieldName = javaFieldName.Substring(0, 1);
                if (mode.isFirstUpper)
                {
                    cSharpFieldName = cSharpFieldName.ToUpper();
                }
                if (javaFieldName.Length > 1)
                {
                    cSharpFieldName = cSharpFieldName + javaFieldName.Substring(1);
                }
                var replaceValue = spaceKey + "public " + typeMode.CSharpName + " " + cSharpFieldName + " { get; set; }";
                if (!string.IsNullOrEmpty(mode.StrPropNote))
                {
                    replaceValue = "\r\n\t    " + Regex.Replace(mode.StrPropNote, "\"fieldName\"", "\"" + javaFieldName + "\"") + replaceValue;
                }
                result = Regex.Replace(result, @"" + matchValue, replaceValue);
            }


            return(result);
        }
Beispiel #3
0
 private void FMain_Load(object sender, EventArgs e)
 {
     if (FileUtils.Exists(setting_file))
     {
         loadSettingConifg();
     }
     else
     {
         SettingMode mode = collectSettingMode();
         saveCacheData(SETTING_MODE, mode);
     }
 }
Beispiel #4
0
        private void loadSettingConifg()
        {
            try
            {
                SettingMode mode = FileUtils.readObject <SettingMode>(setting_file);
                saveCacheData(SETTING_MODE, mode);

                txtDesPath.Text         = mode.StrOutPutDir;
                txtSpace.Text           = mode.StrSpaceName;
                txtPropertyNote.Text    = mode.StrPropNote;
                chxFirstUpper.Checked   = mode.isFirstUpper;
                chxAutoTransfor.Checked = mode.isAutoTransfor;
                chxDelClass.Checked     = mode.isDelClassNote;
                chxDelProp.Checked      = mode.isDelPropNote;
                #region
                foreach (var item in mode.TypeModes)
                {
                    setUiByTypeMode(item);
                }
                #endregion
            }
            catch {
            }
        }
Beispiel #5
0
        private string transforContent(string content)
        {
            //去掉头 ,package ... importz
            //package com.wdhis.mmis.model.basic;  import java.io.Serializable;
            string result = Regex.Replace(content, "((package|import) [a-z0-9A-Z]+(\\.[a-z0-9A-Z]+)+;\\r\\n)", "");

            //类的转化  更改继承表示,implements Serializable去掉加上特定注释 extend改成: public class转成public partial class
            result = Regex.Replace(result, " implements Serializable", "");
            result = Regex.Replace(result, " extends ", " : ");
            result = Regex.Replace(result, "public class ", "public partial class ");

            Regex r = new Regex(@"\{");

            result = r.Replace(result, "\r\n{", 1);

            //去掉原来JAVA的get set方法

            /**
             * This method was generated by MyBatis Generator.
             * This method returns the value of the database column MMIS_DIC_MED_STO_ATTR_VAULE.VALUE_DATETIME
             *
             * @return the value of MMIS_DIC_MED_STO_ATTR_VAULE.VALUE_DATETIME
             *
             * @mbg.generated Mon Aug 14 17:35:21 CST 2017
             */
            //public Date getValueDatetime() {
            //    return valueDatetime;
            //}
            //result = Regex.Replace(result, @"(/\*[\s\S]*?\*/[\r\n|\n])", "");//去多行注释
            result = Regex.Replace(result, @"/\*[^/]*?\*/[\s\r\n]+public [a-zA-Z<>]+ (set|get).+\(.*\).*\{[^\}]*\}", ""); //去掉有多行注释的get set方法
            result = Regex.Replace(result, @"//[\s\r\n]+public [a-zA-Z<>]+ (set|get).+\(.*\).*\{[^\}]*\}", "");;          //去掉有单行注释的get set方法
            result = Regex.Replace(result, @"public [a-zA-Z<>]+ (set|get).+\(.*\).*\{[^\}]*\}", "");;                     //去掉仅有get set方法
            result = Regex.Replace(result, @"(\r\n\r\n    \r\n\r\n)*", "");                                               //去掉多余的回车符
            result = Regex.Replace(result, @"\r\n", "\r\n\t");                                                            //去掉多余的回车符
            result = Regex.Replace(result, ";", "");                                                                      //去掉分号 C#中模型不用
            //字段处理  类型,注释,get set转换
            SettingMode mode = (SettingMode)data[SETTING_MODE];

            //加入命名空间
            result = (mode.StrSpaceName.StartsWith("namespace") ? mode.StrSpaceName : "namespace " + mode.StrSpaceName) + "\r\n{\r\n" + result;
            foreach (var item in mode.TypeModes)
            {
                result = handleGetSetAndNoted(result, item, mode);
            }
            //去掉类注释 单行或多行
            if (mode.isDelClassNote)
            {
                result = Regex.Replace(result, @"/\*[^/]*?\*/[\s\r\n]+public partial class", "public partial class"); //多行注释处理
                result = Regex.Replace(result, @"//[^p]+public partial class", "public partial class");               //多行注释处理
            }
            //去掉属性注释 单行或多行
            if (mode.isDelPropNote)
            {
                string pattern     = ""; //多行注释
                string patternSimp = ""; //单行注释
                string rvalue      = "";
                if (string.IsNullOrEmpty(mode.StrPropNote))
                {
                    pattern     = @"/\*[^/]*?\*/[\s\r\n]+public";
                    patternSimp = @"//[^p]+public";
                    rvalue      = "public";
                }
                else
                {
                    rvalue      = mode.StrPropNote.Substring(0, 1);
                    pattern     = @"/\*[^/]*?\*/[\s\r\n]+\" + rvalue;
                    patternSimp = @"//[^p]+\" + rvalue;
                }
                result = Regex.Replace(result, pattern, rvalue);
                result = Regex.Replace(result, patternSimp, rvalue);
            }
            return(result + "\r\n}");
        }
Beispiel #6
0
        private SettingMode collectSettingMode()
        {
            SettingMode mode = new SettingMode();

            mode.StrOutPutDir   = txtDesPath.Text;
            mode.StrSpaceName   = txtSpace.Text;
            mode.StrPropNote    = txtPropertyNote.Text;
            mode.isFirstUpper   = chxFirstUpper.Checked;
            mode.isAutoTransfor = chxAutoTransfor.Checked;
            mode.isDelClassNote = chxDelClass.Checked;
            mode.isDelPropNote  = chxDelProp.Checked;

            mode.TypeModes = new List <TypeMode>();

            TypeMode intMode = new TypeMode();

            intMode.JavaName   = "Integer";
            intMode.CSharpName = txtInt.Text;
            intMode.UsingSpace = "using System;";
            mode.TypeModes.Add(intMode);


            TypeMode decimalMode = new TypeMode();

            decimalMode.JavaName   = "BigDecimal";
            decimalMode.CSharpName = txtBIgDecimal.Text;
            decimalMode.UsingSpace = "using System;";
            mode.TypeModes.Add(decimalMode);


            TypeMode shortMode = new TypeMode();

            shortMode.JavaName   = "Short";
            shortMode.CSharpName = txtShort.Text;
            shortMode.UsingSpace = "using System;";
            mode.TypeModes.Add(shortMode);


            TypeMode stringMode = new TypeMode();

            stringMode.JavaName   = "String";
            stringMode.CSharpName = txtString.Text;
            stringMode.UsingSpace = "using System;";
            mode.TypeModes.Add(stringMode);

            TypeMode longMode = new TypeMode();

            longMode.JavaName   = "Long";
            longMode.CSharpName = txtLong.Text;
            longMode.UsingSpace = "using System;";
            mode.TypeModes.Add(longMode);

            TypeMode dateMode = new TypeMode();

            dateMode.JavaName   = "Date";
            dateMode.CSharpName = txtDate.Text;
            dateMode.UsingSpace = "using System;";
            mode.TypeModes.Add(dateMode);

            TypeMode listMode = new TypeMode();

            listMode.JavaName   = "List";
            listMode.CSharpName = txtList.Text;
            listMode.UsingSpace = "using System.Collections.Generic;";
            mode.TypeModes.Add(listMode);

            TypeMode mapMode = new TypeMode();

            mapMode.JavaName   = "Map";
            mapMode.CSharpName = txtMap.Text;
            mapMode.UsingSpace = "using System;";
            mode.TypeModes.Add(mapMode);

            TypeMode floatMode = new TypeMode();

            floatMode.JavaName   = "Float";
            floatMode.CSharpName = txtFloat.Text;
            floatMode.UsingSpace = "using System;";
            mode.TypeModes.Add(floatMode);


            TypeMode doubleMode = new TypeMode();

            doubleMode.JavaName   = "Double";
            doubleMode.CSharpName = txtDouble.Text;
            doubleMode.UsingSpace = "using System;";
            mode.TypeModes.Add(doubleMode);


            TypeMode charMode = new TypeMode();

            charMode.JavaName   = "Character";
            charMode.CSharpName = txtCharacter.Text;
            charMode.UsingSpace = "using System;";
            mode.TypeModes.Add(charMode);


            TypeMode byteMode = new TypeMode();

            byteMode.JavaName   = "Byte";
            byteMode.CSharpName = txtCharacter.Text;
            byteMode.UsingSpace = "using System;";
            mode.TypeModes.Add(byteMode);
            return(mode);
        }