Ejemplo n.º 1
0
        private void AddFile(string ext)
        {
            InputForm frm = new InputForm();

            frm.Title = string.Format("请输入文件名称 (.{0})", ext);
            frm.Value = "test";
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (string.IsNullOrEmpty(frm.Value))
                {
                    MessageBoxMessage.Alert("文件名称不能为空。");
                    frm.ShowDialog();
                    return;
                }

                DirectoryInfo rootFolder = tvTemplates.SelectedNode.Tag as DirectoryInfo;
                string        path       = string.Format("{0}\\{1}.{2}", rootFolder.FullName, frm.Value, ext);
                if (File.Exists(path))
                {
                    MessageBoxMessage.Alert("文件已存在。");
                    frm.ShowDialog();
                    return;
                }

                Helper.WriteFile(path, "");
                LoadFiles(tvTemplates.SelectedNode);
            }
        }
Ejemplo n.º 2
0
        private void mnuAddTemplate_Click(object sender, EventArgs e)
        {
            InputForm frm = new InputForm();

            frm.Title = "请输入模板名称";
            frm.Value = "新模板";
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (string.IsNullOrEmpty(frm.Value))
                {
                    MessageBoxMessage.Alert("模板名称不能为空。");
                    frm.ShowDialog();
                    return;
                }

                DirectoryInfo rootFolder = rootNode.Tag as DirectoryInfo;
                string        path       = rootFolder.FullName + "\\" + frm.Value;
                if (Directory.Exists(path))
                {
                    MessageBoxMessage.Alert("模板已存在。");
                    frm.ShowDialog();
                    return;
                }

                Helper.CopyFolder(Application.StartupPath + "\\Config\\NewTemplate", path);
                LoadTempates();
                if (TemplateChanged != null)
                {
                    TemplateChanged();
                }
            }
        }
Ejemplo n.º 3
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);
            }
        }