Exemplo n.º 1
0
        private void work()
        {
            //获取源数据
            String host             = txtSourceIP.Text.Trim();
            String portStr          = txtSourcePort.Text.Trim();
            String userName         = txtSourceUserName.Text.Trim();
            String passWord         = txtSourcePassWord.Text.Trim();
            String dataBase         = cboSourceDataBase.Text;
            String connectionString = MySqlUtil.getConnectionStr(host, portStr, userName, passWord, dataBase);

            connection = MySqlUtil.getConn(connectionString);
            Dictionary <String, DataTable> source        = new Dictionary <string, DataTable>();
            Dictionary <String, DataTable> sourceSetting = btnConnSource.Tag as Dictionary <String, DataTable>;
            Dictionary <String, DataTable> targetSetting = btnConnSource.Tag as Dictionary <String, DataTable>;
            DataTable sourceColumns = sourceSetting["columns"] as DataTable;
            DataTable targetColumns = targetSetting["columns"] as DataTable;

            lbState.Text = "开始获取源数据";
            List <Dictionary <String, Dictionary <String, Object> > > sqlList = new List <Dictionary <String, Dictionary <String, Object> > >();

            foreach (String tableName in clbTableInfo.CheckedItems)
            {
                bool createTable = radCreate.Checked && !radSkip.Checked;

                bool tableIsExist = checkTableExist(tableName, sourceColumns);

                if (createTable && tableIsExist)
                {
                    String insertSql = getCreateSql(sourceColumns, tableName);
                }

                String    sql    = "select * from " + tableName;
                DataTable tempDT = MySqlUtil.getDateTable(connection, sql);

                DataTable tableInfo = sourceSetting[tableName];

                StringBuilder fields = new StringBuilder();

                var rows = sourceColumns.Select("TABLE_NAME = '" + tableName + "' and COLUMN_KEY <> 'PRI'").Distinct(row => row["COLUMN_NAME"]);



                foreach (var row in rows)
                {
                    String colName = row["COLUMN_NAME"].ToString();
                    fields.Append(colName).Append(",");
                }
            }
        }
Exemplo n.º 2
0
        private bool testConnection(String host, String portStr, String userName, String passWord)
        {
            String    sql     = "SELECT 1";
            String    connStr = this.getConnStr(host, portStr, userName, passWord);
            DataTable tempDT  = MySqlUtil.getDateTable(connStr, sql);

            if (tempDT.Rows.Count > 0)
            {
                //this.connStr = connStr;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        private bool testConnection()
        {
            String    sql     = "SELECT 1";
            String    connStr = this.getConnStr();
            DataTable tempDT  = MySqlUtil.getDateTable(connStr, sql);

            if (tempDT.Rows.Count > 0)
            {
                this.connStr = connStr;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                lbConnStr.Text = "";
                lbState.Text   = "";

                String host     = XMLUtil.getValue("Host");
                String port     = XMLUtil.getValue("Port");
                String userName = XMLUtil.getValue("DBUserName");
                String passWord = XMLUtil.getValue("PassWord");
                if (host.Length != 0 && port.Length != 0 && userName.Length != 0 && passWord.Length != 0)
                {
                    String connStr = MySqlUtil.getConnectionStr(host, port, userName, passWord);
                    this.connStr = connStr;
                    DataTable dataBases = MySqlUtil.getSchema(connStr, "Databases");
                    DataRow[] rows      = dataBases.Select("database_name in ('performance_schema','information_schema','mysql')");
                    foreach (DataRow row in rows)
                    {
                        dataBases.Rows.Remove(row);
                    }
                    DataTable tables = MySqlUtil.getSchema(connStr, "Tables");
                    rows = tables.Select("TABLE_SCHEMA in ('performance_schema','information_schema','mysql')");
                    foreach (DataRow row in rows)
                    {
                        tables.Rows.Remove(row);
                    }
                    DataTable columns1 = new DataTable();
                    columns1.Columns.Add("database_name");
                    columns1.Columns.Add("TABLE_SCHEMA");
                    columns1.Columns.Add("column");

                    StringBuilder sqlBuilder = new StringBuilder();
                    foreach (DataRow table in tables.Rows)
                    {
                        String databaseName = table["TABLE_SCHEMA"].ToString();
                        String tableName    = table["TABLE_NAME"].ToString();
                        String sql          = "select * from " + databaseName + "." + tableName + " limit 1;";
                        sqlBuilder.Append(sql);
                    }

                    DataTable c = MySqlUtil.getDateTable(connStr, sqlBuilder.ToString());

                    DataTable columns = MySqlUtil.getSchema(connStr, "Columns");
                    rows = columns.Select("TABLE_SCHEMA in ('performance_schema','information_schema','mysql')");
                    foreach (DataRow row in rows)
                    {
                        columns.Rows.Remove(row);
                    }
                    Session.put("dataBases", dataBases);

                    Session.put("tables", tables);
                    Session.put("columns", columns);
                    isConnected = true;
                }
                if (Session.check("dataBases"))
                {
                    DataTable dataBases = Session.get("dataBases") as DataTable;
                    cboDataBase.ComboBox.DataSource    = dataBases;
                    cboDataBase.ComboBox.DisplayMember = "database_name";
                    cboDataBase.ComboBox.ValueMember   = "database_name";

                    lbConnStr.Text = connStr.Substring(0, connStr.LastIndexOf("password"));


                    DataRow[] rows = dataBases.Select("database_name = '" + selectedDataBase + "'");
                    if (rows.Length > 0)
                    {
                        int index = dataBases.Rows.IndexOf(rows[0]);
                        cboDataBase.SelectedIndex = index;
                    }
                    else if (dataBases.Rows.Count > 0)
                    {
                        cboDataBase.SelectedIndex = 0;
                    }
                    String schemaName = cboDataBase.Text;
                    InitTree(schemaName, "");
                }

                String SelectTable = XMLUtil.getValue("SelectTable");
                lbDbConnState.Text      = isConnected ? "已连接" : "未连接";
                lbDbConnState.ForeColor = isConnected ? Color.Green : Color.Red;

                getExcludedFiledSetting();
                radHibernate.Checked = XMLUtil.getValue("isHibernate").Equals("true");
                radMybatis.Checked   = !XMLUtil.getValue("isHibernate").Equals("true");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }