示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            ConnectionSettingCollection csc = new ConnectionSettingCollection();

            csc.Remove(csc[cb_dbConnectionName.SelectedItem.ToString()]);
            txtConnectionString.Text = string.Empty;
            RefreshCombox();
        }
示例#2
0
        private void RefreshCombox()
        {
            cb_dbConnectionName.Items.Clear();
            ConnectionSettingCollection csc = new ConnectionSettingCollection();

            foreach (ConnectionSetting item in csc)
            {
                cb_dbConnectionName.Items.Add(item.Name);
            }
            if (csc.Count > 0)
            {
                cb_dbConnectionName.SelectedIndex = 0;
            }
        }
示例#3
0
        //private string TemplatePath { get; set; }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            this.DbConnectionName = cb_dbConnectionName.SelectedItem.ToString();
            ConnectionSetting setting = new ConnectionSettingCollection()[this.DbConnectionName];

            setting.ConnectionString = txtConnectionString.Text.Trim();
            var checkedNodes = new List <TreeNode>();

            FindCheckedNodes(tableTrees.Nodes, checkedNodes);
            if (!checkedNodes.Any())
            {
                MessageBox.Show("请选择模板");
                return;
            }
            var paths = new List <string>();

            //GetPathFromTree(tableTrees.SelectedNode, paths);
            GetPathFromTree(checkedNodes.First(), paths);
            paths.Reverse();
            string templatePath = string.Join("\\", paths);

            if (lb_selectedTables.Items.Count <= 0)
            {
                MessageBox.Show("请选择您要生成的数据表");
                return;
            }
            //if (tableTrees.SelectedNode == null || (tableTrees.SelectedNode.Nodes != null && tableTrees.SelectedNode.Nodes.Count > 0))
            //{
            //    MessageBox.Show("选择的模版不是标准的velocity引擎语言");
            //    return;
            //}
            string saveDirectory = txtSavePath.Text.Trim();

            Task.Factory.StartNew(() =>
            {
                string errorMsg;
                GenerateAll(saveDirectory, setting, lb_selectedTables.Items, templatePath, this.txtNamespace.Text, out errorMsg);
                this.Invoke((MethodInvoker) delegate
                {
                    lb_selectedTables.Items.Clear();
                    generateProcess.Value = 0;
                    string messageshow    = "所有的代码生成任务都已完成!";
                    if (!string.IsNullOrEmpty(errorMsg))
                    {
                        messageshow += errorMsg + "生成失败";
                    }
                    MessageBox.Show(messageshow);
                });
            });
        }
示例#4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ConnectionSettingCollection csc = new ConnectionSettingCollection();

            foreach (ConnectionSetting item in csc)
            {
                cb_dbConnectionName.Items.Add(item.Name);
            }
            if (csc.Count > 0)
            {
                cb_dbConnectionName.SelectedIndex = 0;
            }
            string path = AppDomain.CurrentDomain.BaseDirectory + "Template/";

            //tableTrees.DrawMode = TreeViewDrawMode.OwnerDrawAll; //是否自绘树形UI
            tableTrees.Nodes.Add(ListDir(path, null));
            tableTrees.ExpandAll();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            string name                     = txtConnectionName.Text.Trim();
            string type                     = cb_dbtype.SelectedItem.ToString();
            string connectionstring         = txtConnectionString.Text.Trim();
            ConnectionSettingCollection csc = new ConnectionSettingCollection();

            if (csc[name] != null)
            {
                MessageBox.Show("此名称已存在,请更换名称");
                return;
            }
            ConnectionSetting setting = new ConnectionSetting();

            setting.ConnectionString = connectionstring;
            setting.Name             = name;
            setting.Provider         = (DatabaseType)Enum.Parse(typeof(DatabaseType), type);
            csc.Add(setting);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
示例#6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            NewConnection form = new NewConnection();

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                cb_dbConnectionName.Items.Clear();
                ConnectionSettingCollection csc = new ConnectionSettingCollection();
                foreach (ConnectionSetting item in csc)
                {
                    cb_dbConnectionName.Items.Add(item.Name);
                }
                cb_dbConnectionName.SelectedIndex = csc.Count - 1;
            }

            #region Microsoft Connection Dialog
            //DataConnectionDialog dialog = new DataConnectionDialog();
            //dialog.DataSources.Add(DataSource.SqlDataSource);
            //dialog.DataSources.Add(DataSource.OracleDataSource);
            //dialog.DataSources.Add(DataSource.AccessDataSource);
            //dialog.DataSources.Add(DataSource.OdbcDataSource);
            //dialog.DataSources.Add(DataSource.SqlFileDataSource);
            //dialog.SelectedDataSource = DataSource.OracleDataSource;
            //dialog.SelectedDataProvider = DataProvider.OracleDataProvider;
            //if (DataConnectionDialog.Show(dialog, this) == DialogResult.OK)
            //{
            //    ConnectionSettingCollection csc = new ConnectionSettingCollection();
            //    if (csc[dialog.SelectedDataSource.Name] != null)
            //    {
            //        MessageBox.Show("此名称已存在,请更换名称");
            //        return;
            //    }
            //    ConnectionSetting setting = new ConnectionSetting();
            //    setting.ConnectionString = dialog.ConnectionString;
            //    setting.Name = dialog.SelectedDataSource.Name;
            //    setting.Provider = (DatabaseType)Enum.Parse(typeof(DatabaseType), type);
            //    csc.Add(setting);
            //}
            #endregion
        }
示例#7
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            lb_tables.Items.Clear();
            ConnectionSettingCollection csc = new ConnectionSettingCollection();
            string            connName      = cb_dbConnectionName.SelectedItem.ToString();
            ConnectionSetting setting       = csc[connName];

            setting.ConnectionString = txtConnectionString.Text.Trim().TrimEnd(';');
            DataFactory    factory = DatabaseResolver.GetDataFactory(setting);
            DatabaseSchema db      = factory.GetDatabaseSchema();
            List <string>  tables  = new List <string>();

            foreach (var table in db.Tables)
            {
                tables.Add(table.Name);
                lb_tables.Items.Add(table.Name);
            }
            AutoCompleteStringCollection autoColl = new AutoCompleteStringCollection();

            autoColl.AddRange(tables.ToArray());
            txtSearchbox.AutoCompleteCustomSource = autoColl;
        }
示例#8
0
        private void cb_dbConnectionName_SelectedIndexChanged(object sender, EventArgs e)
        {
            ConnectionSettingCollection csc = new ConnectionSettingCollection();

            this.txtConnectionString.Text = csc[cb_dbConnectionName.SelectedItem.ToString()].ConnectionString;
        }
示例#9
0
        static void Main(string[] args)
        {
            string startMode = args.Length > 0 ? args[0] : null;

            if (startMode == "/quiet" || startMode == "/vs")//控制台静默启动,或者作为外部工具在visual studio使用
            {
                string saveDirectory = null, db = null, table = null, templatePath = null, @namespace = null;
                try
                {
                    if (startMode == "/quiet")
                    {
                        saveDirectory = args[1]; db = args[2]; table = args[3]; templatePath = args[4]; @namespace = args[5];
                    }
                    else
                    {
                        var projFilePath = args[1];
                        var itemFile     = args[2];
                        saveDirectory = Path.GetDirectoryName(itemFile);
                        db            = args[3];
                        table         = Path.GetFileName(itemFile).Replace(".generate", "").Replace(".cs", "");
                        @namespace    = Form1.ReadNamespaceFromProjectXml(projFilePath);
                        templatePath  = args[3];
                    }
                    //build as windows application, run from command line
                    //AttachConsole(-1);
                    //AllocConsole();
                    string errorMsg;
                    if (!Regex.IsMatch(saveDirectory, @"^[a-zA-Z]:\\"))
                    {
                        Console.WriteLine("文件保存路径无效");
                        return;
                    }
                    ConnectionSetting setting = new ConnectionSettingCollection()[db];
                    if (setting == null)
                    {
                        Console.WriteLine("数据库连接字符串无效");
                        return;
                    }
                    IList selectedItems = new List <string>();
                    selectedItems.Add(table);
                    if (!Form1.GenerateAll(saveDirectory, setting, selectedItems, templatePath, @namespace, out errorMsg))
                    {
                        Console.WriteLine("代码生成失败");
                        Console.WriteLine(errorMsg);
                    }
                    else
                    {
                        Console.WriteLine($"代码生成成功,Table={table},savingPath={saveDirectory}");
                    }
                }
                finally
                {
                    //FreeConsole();
                }
            }
            else
            {
                Console.WriteLine("start gui application");
                //string[] newArgs = null;
                //启动参数不满足静默模式,启动GUI程序
                if (args != null && args.Length != 3)
                {
                    args = new string[0];
                }
                //else
                //{
                //    newArgs = args;
                //}
                //build as Console Application, run GUI application
                //use FreeConsole to hide command line window, but still have a cmd window flash out
                FreeConsole();
                try
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1(args));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("start gui application failed");
                    Console.WriteLine(ex.Message);
                }
            }
        }