示例#1
0
        /// <summary>
        /// 添加一个数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton_add_Click(object sender, EventArgs e)
        {
            string databaseName = textBox_name.Text;
            string ip           = textBox_ip.Text;
            string port         = textBox_port.Text;
            string username     = textBox_username.Text;
            string password     = textBox_password.Text;
            string encoding     = textBox_encoding.Text;

            if (databaseName.Trim() == "")
            {
                MessageBox.Show("数据库名称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            lib.pMysql mysql = new lib.pMysql(ip, port, username, password, "");
            if (!mysql.isConnOpen())
            {
                MessageBox.Show("MySQL无法打开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            pDataManageClass p = new pDataManageClass();

            if (!p.addMysqlDataBase(databaseName, ip, port, username, password, encoding))
            {
                MessageBox.Show("添加出错!" + p.error, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Close();
        }
示例#2
0
        /// <summary>
        /// 右键功能选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinContextMenuStrip_table_create_tools_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == null)
            {
                return;
            }

            if (e.ClickedItem.ToString() == "Yii生成模型")
            {
                CreateYiiModel model = new CreateYiiModel(treeviewSelectHash);
                model.Show();
            }

            if (e.ClickedItem.ToString() == "Yii迁移数据")
            {
                CreateYiiMigrate model = new CreateYiiMigrate(treeviewSelectHash);
                model.Show();
            }
            if (e.ClickedItem.ToString() == "TP迁移数据")
            {
                CreateTpMigrate model = new CreateTpMigrate(treeviewSelectHash);
                model.Show();
            }

            if (e.ClickedItem.ToString() == "转POST参数")
            {
                Data.pDataManageClass    p  = new Data.pDataManageClass();
                FormAll.pStringUrlDataTo to = new FormAll.pStringUrlDataTo();
                to.Show();
                to.showContent(p.dToJson(tableListData));
            }
        }
示例#3
0
 /// <summary>
 /// 添加MySQL数据库
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void mysqlToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Data.addMysql p = new Data.addMysql();
     p.ShowDialog();
     Data.pDataManageClass data = new Data.pDataManageClass();
     data.refreshTreeView(treeView_database);//刷新
 }
示例#4
0
        /// <summary>
        /// 输出包含表的树
        /// </summary>
        /// <param name="tv"></param>
        /// <param name="hash"></param>
        /// <param name="database"></param>
        public void showSqliteTreeViewTableList(TreeView tv, string hash, Dictionary <string, string> database)
        {
            Data.pDataManageClass    p    = new Data.pDataManageClass();
            Dictionary <int, object> list = p.getSqliteTable(database["path"]);

            if (list.Count <= 0)
            {
                return;
            }
            TreeNode tn = tv.SelectedNode;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, string> d = new Dictionary <string, string> {
                };
                d = (Dictionary <string, string>)list[i];
                string   pidHash = hash + "|table|" + Data.DataBaseType.Sqlite.ToString() + "|" + d["TABLE_NAME"];
                TreeNode pidTn   = pForm1TreeView.FindNodeByName(tn.Nodes, pidHash);
                if (pidTn != null)
                {
                    return;
                }
                TreeNode show = tn.Nodes.Add(pidHash, d["TABLE_NAME"]);
                show.ImageIndex         = 1;
                show.SelectedImageIndex = 1;
            }
        }
示例#5
0
        /// <summary>
        /// 加载mysql表结构
        /// </summary>
        /// <param name="hash"></param>
        /// <param name="database"></param>
        /// <param name="table"></param>
        public void mysqlLoad(string hash, string database, string table)
        {
            Data.pDataManageClass       pData = new Data.pDataManageClass();
            Dictionary <string, string> d     = pData.getDataBaseHash(hash);

            lib.pMysql mysql = new lib.pMysql(d["ip"], d["port"], d["username"], d["password"], database);
            showDataGridViewDictionary(mysql.getTableInfo(table), Data.DataBaseType.Mysql);
        }
示例#6
0
        /// <summary>
        /// 加载sqlite表结构
        /// </summary>
        /// <param name="hash"></param>
        public void sqliteLoad(string hash, string table)
        {
            Data.pDataManageClass       pData = new Data.pDataManageClass();
            Dictionary <string, string> d     = pData.getDataBaseHash(hash);

            if (d.Count <= 0)
            {
                return;
            }
            lib.pSqlite sqlite = new lib.pSqlite(d["path"]);
            showDataGridViewDictionary(sqlite.getTableInfo(table), Data.DataBaseType.Sqlite);
        }
示例#7
0
        public void showTreeView()
        {
            Data.pDataManageClass p       = new Data.pDataManageClass();
            TreeView tv                   = treeView_database;
            Dictionary <int, object> list = p.getDataBaseAll();

            tv.Invoke(new Action(() =>
            {
                for (int i = 0; i < list.Count; i++)
                {
                    Dictionary <string, string> item = (Dictionary <string, string>)list[i];
                    tv.Nodes.Add(item["hash"], item["type"] + " : " + item["name"]);
                }
            }));
        }
示例#8
0
        /// <summary>
        /// 添加数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton_add_Click(object sender, EventArgs e)
        {
            string name = skinTextBox_name.Text;
            string path = skinTextBox_path.Text;

            if (name == "")
            {
                MessageBox.Show("数据名称不能为空!");
                return;
            }
            if (path == "")
            {
                MessageBox.Show("数据库地址不能为空!");
                return;
            }
            if (!File.Exists(path))
            {
                MessageBox.Show("数据库地址不正确!");
                return;
            }
            else
            {
                lib.pSqlite sql = new lib.pSqlite(path);
                if (sql.conn == null)
                {
                    MessageBox.Show("无法打开数据库", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            Data.pDataManageClass data = new pDataManageClass();
            if (data.addSqliteDataBase(name, path))
            {
                tv.Nodes.Add(data.hash, DataBaseType.Sqlite + " : " + name);
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
示例#9
0
        /// <summary>
        /// 创建数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton_create_Click(object sender, EventArgs e)
        {
            TreeView tv       = pDataManage.f.getTreeView();
            string   name     = textBox_name.Text;
            string   encoding = textBox_encoding.Text;

            if (name == "")
            {
                MessageBox.Show("数据库名称不能为空!", "提示");
                return;
            }
            Data.pDataManageClass       p        = new pDataManageClass();
            Dictionary <string, string> database = p.getDataBaseHash(this.hash);

            if (database.Count <= 0)
            {
                MessageBox.Show("找不到相关配置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            lib.pMysql mysql = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], "", encoding);
            //CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
            string sql = string.Format("CREATE DATABASE IF NOT EXISTS {0} DEFAULT CHARSET {1} COLLATE {2}", name, encoding, encoding + "_general_ci");

            if (mysql.executeNonQuery(sql) > 0)
            {
                tv.BeginInvoke(new Action(() =>
                {
                    TreeNode tn            = pForm1TreeView.FindNodeByName(tv.Nodes, this.hash);
                    TreeNode pid           = tn.Nodes.Add(name);
                    pid.ImageIndex         = 2;
                    pid.SelectedImageIndex = 2;
                }));
                this.Close();
            }
            else
            {
                MessageBox.Show("创建失败!\r\n" + mysql.error, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#10
0
 /// <summary>
 /// 重命名
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void skinButton_ren_Click(object sender, EventArgs e)
 {
     name = skinTextBox_name.Text;
     if (name.Trim() == "")
     {
         MessageBox.Show("名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
     }
     string[] array = this.hash.Split('|');
     if (array.Length == 1)//数据库重命名
     {
         Data.pDataManageClass p = new pDataManageClass();
         if (p.updateDataBaseName(this.hash, name) > 0)
         {
             this.result = true;
         }
         else
         {
             this.error  = p.error;//error
             this.result = false;
         }
     }
     this.Close();
 }
示例#11
0
 /// <summary>
 /// 自定义sql运行 button按钮
 /// </summary>
 /// <param name="obj1"></param>
 /// <param name="obj2"></param>
 public void getRunSql(object obj1, object obj2)
 {
     try
     {
         if (obj1 == null)
         {
             return;
         }
         SkinButton        sb   = (SkinButton)obj1;
         string            name = sb.Name;
         string            rand = name.Replace("sqlrun", "");
         Models.RunSqlForm rsf  = RunSqlList[rand];
         string            text = rsf.fctb.Text;
         if (text == "")
         {
             return;
         }
         if (rsf.selectHash == null)
         {
             return;
         }
         string   hash  = rsf.selectHash;
         string[] array = hash.Split('|');
         if (array.Length <= 1)                               //主要数据库
         {
             string databaseHash                  = array[0]; //数据库hash
             Data.pDataManageClass       p        = new Data.pDataManageClass();
             Dictionary <string, string> database = p.getDataBaseHash(databaseHash);
             if (database["type"] == Data.DataBaseType.Mysql.ToString())
             {
                 lib.pMysql mysql = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], "");
                 Dictionary <int, object> List = mysql.getRows(text);
                 if (mysql.error.Length <= 0)
                 {
                     tabPageDataGridViewShow(rsf.stp, List, rand);//结果显示
                 }
                 else
                 {
                     tabPageErrorShow(rsf.stp, mysql.error, rand);//错误显示
                 }
             }
         }
         if (array.Length >= 4)              //表
         {
             string type         = array[2]; //获取类型
             string databaseHash = array[0]; //数据库hash
             string table        = array[3]; //数据库table
             if (type == Data.DataBaseType.Mysql.ToString())
             {
                 Data.pDataManageClass       p        = new Data.pDataManageClass();
                 Dictionary <string, string> database = p.getDataBaseHash(databaseHash);
                 lib.pMysql mysql = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], table);
                 Dictionary <int, object> List = mysql.getRows(text);
                 if (mysql.error.Length <= 0)
                 {
                     tabPageDataGridViewShow(rsf.stp, List, rand);//结果显示
                 }
                 else
                 {
                     tabPageErrorShow(rsf.stp, mysql.error, rand);//错误显示
                 }
             }
         }
     }
     catch (Exception ex) { pLogs.logs(ex.ToString()); }
     //string name = obj1;
 }
示例#12
0
        /// <summary>
        /// 动态sql生成查询
        /// </summary>
        /// <param name="hash"></param>
        public void createSqlRunTab(string hash)
        {
            try
            {
                string[] array = hash.Split('|');
                string   text  = "";
                Dictionary <string, string> database = new Dictionary <string, string>();
                if (array.Length <= 0)
                {
                    return;
                }
                if (array.Length == 1)//查询主数据库
                {
                    Data.pDataManageClass p = new Data.pDataManageClass();
                    string dataHash         = array[0];
                    database = p.getDataBaseHash(array[0]);
                    array    = new string[4];
                    array[0] = dataHash;
                    array[1] = "database";
                    array[2] = database["type"];
                }
                if (array[2] == Data.DataBaseType.Mysql.ToString())//mysql
                {
                    if (array.Length > 2)
                    {
                        text = array[3];
                        if (array[1] == "database")
                        {
                            text = database["name"];
                        }
                    }
                }

                ContextMenuStrip cms = new ContextMenuStrip(); //关闭右键菜单
                Random           rd  = new Random();
                cms.Items.Add("关闭" + text);                    //添加右键文本
                string      rand = rd.Next(10000, 99999).ToString();
                string      name = text + rand;
                SkinTabPage page = new SkinTabPage();
                page.ToolTipText      = Text + " 查询"; //提示显示完整
                page.Text             = text + " 查询"; //tab显示文本
                page.Name             = name;         //tab name 唯一
                page.ContextMenuStrip = cms;
                cms.Name         = "cms" + rand;
                cms.ItemClicked += closeTabPage;//关联事件
                this.skinTabControl1.Controls.Add(page);

                Label lab = new Label();
                lab.Text     = text + " 查询";
                lab.Location = new Point(10, 5);
                page.Controls.Add(lab);

                SkinButton skbutton = new SkinButton();
                skbutton.Text     = "查询";
                skbutton.Name     = "sqlrun" + rand;
                skbutton.Click   += getRunSql;//点击事件
                skbutton.Location = new Point(10, 30);
                page.Controls.Add(skbutton);

                FastColoredTextBox fctb = new FastColoredTextBox();//输入框
                fctb.Name        = "fctb" + rand;
                fctb.Location    = new Point(10, 80);
                fctb.Language    = Language.SQL;            //sql
                fctb.Width       = page.Width - 30;         //控件宽度
                fctb.Height      = page.Height / 3;         //控件高度
                fctb.ImeMode     = ImeMode.On;              //开启
                fctb.KeyDown    += RunSqlKeysDown;          //键盘事件
                fctb.BorderStyle = BorderStyle.FixedSingle; //边框
                page.Controls.Add(fctb);                    //添加输入框

                skinTabControl1.SelectedTab = page;         //指定tabpage显示

                if (array.Length == 5)                      //打开表查询
                {
                    fctb.BeginInvoke(new Action(() =>
                    {
                        string table = array[4];
                        fctb.Text    = string.Format("select *from {0}", table);
                    }));
                }

                Models.RunSqlForm rsf = new Models.RunSqlForm
                {
                    button     = skbutton,
                    fctb       = fctb,
                    stp        = page,
                    selectHash = hash,
                };
                if (!RunSqlList.ContainsKey(rand))
                {
                    RunSqlList.Add(rand, rsf);//添加列队
                }
                else
                {
                    RunSqlList[rand] = rsf;
                }
            }
            catch (Exception ex) { pLogs.logs(ex.ToString()); }
        }
示例#13
0
 /// <summary>
 /// treeview 右键菜单
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void skinContextMenuStrip_treeview_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     skinContextMenuStrip_treeview.Close();//关闭
     if (e.ClickedItem == null)
     {
         return;
     }
     if (e.ClickedItem.ToString() == "删除数据库")
     {
         string   hash  = treeView_database.SelectedNode.Name;
         string[] array = hash.Split('|');
         if (array.Length <= 1)
         {
             return;
         }
         string database = treeView_database.SelectedNode.Text;
         if (MessageBox.Show("删除" + database + "?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
         {
             return;
         }
         Data.pDataManageClass       p = new Data.pDataManageClass();
         Dictionary <string, string> d = p.getDataBaseHash(hash);
         if (d.Count <= 0)
         {
             return;
         }
         if (p.deleteDataBaseHash(hash) > 0)
         {
             treeView_database.SelectedNode.Remove();//删除节点
         }
         else
         {
             MessageBox.Show(p.error, "提示");
             return;
         }
     }
     else if (e.ClickedItem.ToString() == "重命名")
     {
         string   hash  = treeView_database.SelectedNode.Name;
         string   name  = treeView_database.SelectedNode.Text;
         string[] array = hash.Split('|');
         if (array.Length == 1)
         {
             string[]  nameArray = name.Split(':');
             Data.pRen ren       = new Data.pRen(hash, nameArray[1].Trim());
             ren.ShowDialog();//重命名
             if (ren.result)
             {
                 treeView_database.SelectedNode.Text = nameArray[0] + ": " + ren.name;
             }
             else
             {
                 MessageBox.Show(ren.error, "提示");
             }
         }
     }
     else if (e.ClickedItem.ToString() == "关闭")
     {
         TreeNode tn = treeView_database.SelectedNode;
         tn.Nodes.Clear();//关闭
     }
     else if (e.ClickedItem.ToString() == "重命名")
     {
     }
     else if (e.ClickedItem.ToString() == "查询")
     {
         string hash = treeView_database.SelectedNode.Name;
         string name = treeView_database.SelectedNode.Text;
         createSqlRunTab(hash);//动态创建tab
     }
     else if (e.ClickedItem.ToString() == "连接详情")
     {
         string hash = treeView_database.SelectedNode.Name;
         Thread th   = new System.Threading.Thread((System.Threading.ThreadStart) delegate
         {
             Application.Run(new Data.DataBaseInfo(hash));
         });
         th.SetApartmentState(ApartmentState.STA);
         th.IsBackground = true;
         th.Start();
     }
     else if (e.ClickedItem.ToString() == "新建数据库")//新建数据库
     {
         string hash = treeView_database.SelectedNode.Name;
         Thread th   = new System.Threading.Thread((System.Threading.ThreadStart) delegate
         {
             Application.Run(new Data.createDatabase(hash));
         });
         th.SetApartmentState(ApartmentState.STA);
         th.IsBackground = true;
         th.Start();
     }
     else if (e.ClickedItem.ToString() == "新建表")//新建表
     {
         string   hash  = treeView_database.SelectedNode.Name;
         string[] array = hash.Split('|');
         Dictionary <string, string> database = new Dictionary <string, string>();
         if (array.Length == 1)
         {
             Data.pDataManageClass p = new Data.pDataManageClass();
             database = p.getDataBaseHash(hash);
             if (database["type"] == Data.DataBaseType.Mysql.ToString())
             {
                 return;
             }
         }
         Thread th = new System.Threading.Thread((System.Threading.ThreadStart) delegate
         {
             Application.Run(new Data.createTable(hash));
         });
         th.SetApartmentState(ApartmentState.STA);
         th.IsBackground = true;
         th.Start();
     }
 }
示例#14
0
 public void treeView_database_DoubleClickFun()
 {
     this.Cursor = Cursors.WaitCursor;
     try
     {
         Data.pDataManageClass p = new Data.pDataManageClass();
         TreeView tv             = treeView_database;
         this.treeviewSelectHash = "";
         if (tv.SelectedNode == null)
         {
             this.Cursor = Cursors.Default; return;
         }
         string hash = tv.SelectedNode.Name;
         this.treeviewSelectHash = hash;
         Dictionary <string, string> database = p.getDataBaseHash(hash);
         if (database.Count > 0)                                          //是数据库
         {
             if (database["type"] == Data.DataBaseType.Sqlite.ToString()) //sqlite
             {
                 if (!File.Exists(database["path"]))
                 {
                     MessageBox.Show("数据库不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     this.Cursor = Cursors.Default;
                     return;
                 }
                 showSqliteTreeViewTableList(tv, hash, database);
                 return;
             }
             if (database["type"] == Data.DataBaseType.Mysql.ToString())//mysql
             {
                 lib.pMysql mysql = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], "");
                 if (!mysql.isConnOpen())
                 {
                     MessageBox.Show("无法打开数据库!" + mysql.error, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     this.Cursor = Cursors.Default; return;
                 }
                 showMysqlTreeViewTableList(tv, hash, database, mysql);
                 this.Cursor = Cursors.Default;
                 return;
             }
         }
         string[] array = hash.Split('|');
         if (array.Length < 2)
         {
             this.Cursor = Cursors.Default; return;
         }
         if (array[1] == "table")//打开表
         {
             Dictionary <string, string> list = p.getDataBaseHash(array[0]);
             if (list.Count <= 0)
             {
                 this.Cursor = Cursors.Default; return;
             }
             if (list["type"] == Data.DataBaseType.Sqlite.ToString())//sqlite
             {
                 lib.pSqlite sqlite = new lib.pSqlite(list["path"]);
                 Dictionary <int, object> tableList = sqlite.getTableListData(array[3]);
                 showDataViewTableListData(tableList);
             }
         }
         if (array[1] == "mysql_database")//打开mysql数据库显示表
         {
             database = p.getDataBaseHash(array[0]);
             string     databaseName = array[3];//数据库
             lib.pMysql mysql        = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], databaseName);
             showMysqlTableTreeViewTableList(treeView_database, array[0], database, mysql, databaseName);
             mysql.close();
         }
         if (array[1] == "mysql_table")//打开mysql表
         {
             database = p.getDataBaseHash(array[0]);
             string     databaseName = array[3]; //数据库
             string     table        = array[4]; //数据库
             lib.pMysql mysql        = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], databaseName);
             if (!mysql.isConnOpen())
             {
                 MessageBox.Show("操作不正常");
                 this.Cursor = Cursors.Default; return;
             }
             Dictionary <int, object> tableList = mysql.getTableListData(table);
             if (tableList.Count <= 0)//为空情况下默认输出一行
             {
                 lib.pMysql mysqlInfo = new lib.pMysql(database["ip"], database["port"], database["username"], database["password"], databaseName);
                 Dictionary <int, object>    tableListInfo = mysqlInfo.getTableInfo(table);
                 Dictionary <string, string> add           = new Dictionary <string, string> {
                 };
                 for (int i = 0; i < tableListInfo.Count; i++)
                 {
                     Dictionary <string, string> temp = (Dictionary <string, string>)tableListInfo[i];
                     add.Add(temp["Field"], "");
                 }
                 tableList.Add(0, add);
             }
             showDataViewTableListData(tableList);
             skinTabControl1.SelectedTab = skinTabPage1;
         }
     }
     catch (Exception ex)
     {
         pLogs.logs(ex.ToString());
         this.Cursor = Cursors.Default;
     }
     this.Cursor = Cursors.Default;
 }