Example #1
0
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            object obj = tvTemplates.SelectedNode.Tag;

            switch (tvTemplates.SelectedNode.Level)
            {
            case 1:
                if (MessageBoxMessage.Confirm("确定要删除此模板吗?") == false)
                {
                    return;
                }
                DirectoryInfo dir = obj as DirectoryInfo;
                Directory.Delete(dir.FullName, true);
                LoadTempates();
                if (TemplateChanged != null)
                {
                    TemplateChanged();
                }
                break;

            case 2:
                if (MessageBoxMessage.Confirm("确定要删除此文件吗?") == false)
                {
                    return;
                }
                TreeNode parent = tvTemplates.SelectedNode.Parent;
                FileInfo fi     = obj as FileInfo;
                File.Delete(fi.FullName);
                LoadFiles(parent);
                break;

            default:
                break;
            }
        }
Example #2
0
        private void btnOutputCode_Click(object sender, EventArgs e)
        {
            foreach (Table table in selectTableUserControl1.SelectedTables)
            {
                if (table.Fields.Count == 0)
                {
                    MessageBoxMessage.Alert(string.Format("表{0}不存在任何字段,无法生成!", table.Name));
                    return;
                }
            }

            if (false == MessageBoxMessage.Confirm("确定要输出代码吗?"))
            {
                return;
            }

            if (Directory.Exists(CreateFilePath))
            {
                if (MessageBoxMessage.Confirm("该目录已存在,是否删除?"))
                {
                    try
                    {
                        Directory.Delete(CreateFilePath, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBoxMessage.Error(ex.ToString());
                    }
                }
            }

            //selectTemplateUserControl1.SaveSetting();
            db.Selects = selectTableUserControl1.SelectedTables;

            //在Settings中额外地增加一项设定,值为当前选中的所有表
            List <Setting> settings = selectTemplateUserControl1.Settings;

            //目录有可能不存在,如果没有生成任何代码则打开目录会出错,故先创建目录
            if (false == Directory.Exists(CreateFilePath))
            {
                Directory.CreateDirectory(CreateFilePath);
            }

            try
            {
                Template template = new Template();
                template.TemplateFolder    = selectTemplateUserControl1.TemplateFolderPath;
                template.Database          = db;
                template.Settings          = settings;
                template.GenerateFolder    = CreateFilePath;
                template.OnProcessChanged += new ProcessChanged(template_OnProcessChanged);
                template.Generate();
                if (ShowDebug != null)
                {
                    ShowDebug(template.DatabaseJson, template.SettingJson, false);
                }
            }
            catch (Exception ex)
            {
                MessageBoxMessage.Error(ex.Message);
            }

            progressBar1.Value = 0;
            if (MessageBoxMessage.Confirm("成功生成,是否打开目录?"))
            {
                Process.Start(CreateFilePath);
            }
        }