⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newproject.cs

📁 通过数据库结构自动 生成三层结构代码,相当不错的一款软件
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Codematic
{
    using LTP.Utility;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Threading;
    using System.Windows.Forms;

    public class NewProject : Form
    {
        private Button btn_browser;
        private Button btn_ok;
        private Button button2;
        private INIFile cfgfile;
        private string cmcfgfile = (Application.StartupPath + @"\cmcfg.ini");
        private IContainer components;
        private string folder1 = "";
        private string folder2 = "";
        private GroupBox groupBox1;
        private ImageList imageList1;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private TextBox lblTooltip;
        private ListView listView1;
        private Thread mythread;
        private Panel panel1;
        private string ProName = "";
        private TreeView treeView1;
        private TextBox txtProName;
        private TextBox txtProPath;

        public NewProject()
        {
            this.InitializeComponent();
            this.InitTreeView();
            this.InitListView();
            this.btn_ok.Enabled = false;
        }

        private void btn_browser_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                this.txtProPath.Text = dialog.SelectedPath;
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count >= 1)
            {
                string text = this.listView1.SelectedItems[0].Text;
                string appFrame = "S3";
                string str4 = text;
                if (str4 != null)
                {
                    if (!(str4 == "单类结构"))
                    {
                        if (str4 == "简单三层")
                        {
                            this.folder1 = Application.StartupPath + @"\Template\CodematicDemoS3";
                            appFrame = "S3";
                        }
                        else if (str4 == "工厂模式结构")
                        {
                            this.folder1 = Application.StartupPath + @"\Template\CodematicDemoF3";
                            appFrame = "F3";
                        }
                    }
                    else
                    {
                        appFrame = "One";
                        MessageBox.Show("该功能尚未完成,可以选择其他功能继续使用。");
                    }
                }
                this.folder2 = this.txtProPath.Text.Trim();
                this.ProName = this.txtProName.Text.Trim();
                this.cfgfile.IniWriteValue("Project", "lastpath", this.folder2);
                if (this.ProName != "")
                {
                    this.folder2 = this.folder2 + @"\" + this.ProName;
                }
                if (this.txtProPath.Text.Trim() == "")
                {
                    MessageBox.Show("请选择输出目录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    try
                    {
                        DirectoryInfo info = new DirectoryInfo(this.folder1);
                        DirectoryInfo info2 = new DirectoryInfo(this.folder2);
                        if (!info.Exists)
                        {
                            MessageBox.Show("源目录已经不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        if (!info2.Exists)
                        {
                            try
                            {
                                info2.Create();
                            }
                            catch
                            {
                                MessageBox.Show("目标目录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                return;
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("目录信息有误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }
                    string dbViewSelServer = FormCommon.GetDbViewSelServer();
                    if (!(dbViewSelServer == ""))
                    {
                        this.mythread = new Thread(new ThreadStart(this.ThreadWork));
                        this.mythread.Start();
                        new NewProjectDB(dbViewSelServer, this, this.folder2, appFrame).Show();
                        base.Close();
                    }
                    else
                    {
                        MessageBox.Show("你尚未选择要生成代码的数据库信息!\r\n请先建立数据库连接。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        public void CopyDirectory(string SourceDirectory, string TargetDirectory)
        {
            DirectoryInfo info = new DirectoryInfo(SourceDirectory);
            DirectoryInfo info2 = new DirectoryInfo(TargetDirectory);
            if (info.Exists)
            {
                if (!info2.Exists)
                {
                    info2.Create();
                }
                FileInfo[] files = info.GetFiles();
                int length = files.Length;
                for (int i = 0; i < length; i++)
                {
                    if ((files[i].Extension == ".sln") || (files[i].Extension == ".suo"))
                    {
                        File.Copy(files[i].FullName, info2.FullName + @"\" + this.ProName + files[i].Extension, true);
                    }
                    else
                    {
                        File.Copy(files[i].FullName, info2.FullName + @"\" + files[i].Name, true);
                    }
                }
                DirectoryInfo[] directories = info.GetDirectories();
                for (int j = 0; j < directories.Length; j++)
                {
                    this.CopyDirectory(directories[j].FullName, info2.FullName + @"\" + directories[j].Name);
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(NewProject));
            this.treeView1 = new TreeView();
            this.panel1 = new Panel();
            this.listView1 = new ListView();
            this.label1 = new Label();
            this.label3 = new Label();
            this.lblTooltip = new TextBox();
            this.groupBox1 = new GroupBox();
            this.label2 = new Label();
            this.label4 = new Label();
            this.txtProName = new TextBox();
            this.txtProPath = new TextBox();
            this.btn_browser = new Button();
            this.button2 = new Button();
            this.btn_ok = new Button();
            this.imageList1 = new ImageList(this.components);
            this.panel1.SuspendLayout();
            base.SuspendLayout();
            this.treeView1.Location = new Point(12, 30);
            this.treeView1.Name = "treeView1";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -