Пример #1
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);
        }
Пример #2
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;
 }