schangxiang@126.com
2025-05-07 c2fa981fb19aa0fee113dd684f5f14956d58bd93
Weben_CMSרÓôúÂëÉú³ÉÆ÷/Code/MainForm.cs
@@ -9,6 +9,7 @@
using GenerateCode_WeiBen_WMS.Const;
using GenerateCode_WeiBen_WMS.Model;
using GenerateCode_WeiBen_WMS.Utility;
using System.Xml;
namespace GenerateCode_GEBrilliantFactory
{
@@ -685,5 +686,128 @@
            dataBaseEnum = (DataBaseEnum)Enum.Parse(typeof(DataBaseEnum), name);
        }
        private void btn_SelectFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*txt*)|*.txt*"; //设置要选择的文件的类型
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;//返回文件的完整路径
                this.tb_FilePath.Text = file;
            }
        }
        private void tb_FilePath_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string filePath = this.tb_FilePath.Text;
                string[] lines = File.ReadAllLines(filePath);
                // åˆ›å»ºå®žä½“类对象
                GenerateCodeConfigParam entity = new GenerateCodeConfigParam();
                // è§£æžæ¯ä¸€è¡Œå†…容并赋值给实体类属性
                foreach (string line in lines)
                {
                    if (line.Contains(":"))
                    {
                        string[] parts = line.Split(':');
                        string propertyName = parts[0].Trim('[', ']');
                        string propertyValue = parts[1].Trim();
                        // æ ¹æ®å±žæ€§åèµ‹å€¼
                        switch (propertyName)
                        {
                            case "表名":
                                entity.表名 = propertyValue;
                                break;
                            case "实体类名":
                                entity.实体类名 = propertyValue;
                                break;
                            case "实体类对象名":
                                entity.实体类对象名 = propertyValue;
                                break;
                            case "页面菜单名":
                                entity.页面菜单名 = propertyValue;
                                break;
                            case "页面菜单对象缩写":
                                entity.页面菜单对象缩写 = propertyValue;
                                break;
                            case "表的中文注解":
                                entity.表的中文注解 = propertyValue;
                                break;
                            case "重复性校验字段":
                                entity.重复性校验字段 = propertyValue;
                                break;
                            case "删除提示字段":
                                entity.删除提示字段 = propertyValue;
                                break;
                            case "模糊查询字段":
                                entity.模糊查询字段 = propertyValue;
                                break;
                            case "模糊查询字段名":
                                entity.模糊查询字段名 = propertyValue;
                                break;
                            case "项目命名空间":
                                entity.项目命名空间 = propertyValue;
                                break;
                            case "枚举类型字段集合":
                                entity.枚举类型字段集合 = propertyValue;
                                break;
                        }
                    }
                }
                //给界面赋值
                this.tb_TableName.Text = "";//表名
                this.tb_WCF_NameSpacePath.Text = "";//表名
                this.tb_ChinaComment.Text = "";//表名
                this.tb_MenuName.Text = "";//表名
                this.tb_PageMenuInstanceName.Text = "";//表名
                this.tb_EntityName.Text = "";//表名
                this.tb_LikeQueryAttrs.Text = "";//表名
                this.tb_LikeQueryAttrsName.Text = "";//表名
                this.tb_EntityProName.Text = "";//表名
                this.tb_EnumList.Text = "";//表名
                this.tb_ValidateRepeatName.Text = "";//表名
                this.tb_DeleteAlertAttr.Text = "";//表名
                this.tb_TableName.Text = entity.表名;//表名
                this.tb_WCF_NameSpacePath.Text = entity.项目命名空间;//WCF项目命名空间
                this.tb_ChinaComment.Text = entity.表的中文注解;//中文注释
                this.tb_MenuName.Text = entity.页面菜单名;
                this.tb_PageMenuInstanceName.Text = entity.页面菜单对象缩写;
                this.tb_EntityName.Text = entity.实体类名;//实体类名
                this.tb_LikeQueryAttrs.Text = entity.模糊查询字段;
                this.tb_LikeQueryAttrsName.Text = entity.模糊查询字段名;
                this.tb_EntityProName.Text = entity.实体类对象名;//实体类对象名
                this.tb_EnumList.Text = entity.枚举类型字段集合;
                this.tb_ValidateRepeatName.Text = entity.重复性校验字段;
                this.tb_DeleteAlertAttr.Text = entity.删除提示字段;
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("错误: æ–‡ä»¶æœªæ‰¾åˆ°!");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"错误: å‘生了一个未知错误: {ex.Message}");
            }
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            this.tb_FilePath.Text = "";
        }
    }
}