/// <summary>
        /// inialize button (or test) button click event
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void btn_initlize_Click(object sender, EventArgs e)
        {
            bool checkResult = CheckInput(false);

            if (!checkResult)
            {
                return;
            }

            string databaseSel = cbx_databaseList.Text;
            string ipAddr      = txt_ip.Text;
            string port        = txt_port.Text;
            string userName    = txt_userName.Text;
            string password    = txt_password.Text;
            string scheme      = cbx_scheme.Text;
            string url         = txt_url.Text;

            // check current is an oracle. if an oracle,response the test event, othwise initlize scheme
            // Query all current connect's database(scheme) information, default DatabaseType is MySQL
            DatabaseConnectorProvider connectorProvider = DatabaseConnectorProvider.GetInstance(ipAddr, port, userName, password, DataBaseType.MySql);
            bool result;

            // Init the scheme info (sqlserver or mysql) can be test the connect before
            switch (databaseSel)
            {
            case Database.MySQL:
                connectorProvider.ChangeDatabaseType(DataBaseType.MySql);
                result = connectorProvider.connect();
                break;

            case Database.SqlServer:
                connectorProvider.ChangeDatabaseType(DataBaseType.SqlServer);
                result = connectorProvider.connect();
                break;

            case Database.Oracle:
                // Modity the test tag
                IsTest = true;
                connectorProvider.ChangeDatabaseType(DataBaseType.Oracle);
                result = connectorProvider.connect();
                break;

            default:
                result = false;
                break;
            }
            if (result)
            {
                label_connectStatus.Text      = "Connected successfully !";
                label_connectStatus.ForeColor = Color.Green;
                label_connectStatus.Show();
                tb_next.Enabled = true;
            }
            else
            {
                label_connectStatus.Text      = "Connected failed !";
                label_connectStatus.ForeColor = Color.Red;
                label_connectStatus.Show();
                // disable the tb_next button
                tb_next.Enabled = false;
            }

            if (!IsOracle)
            {
                // init the database all scheme
                List <string> schemes = connectorProvider.initScheme();
                cbx_scheme.Items.Clear();
                for (int i = 0; i < schemes.Count; i++)
                {
                    cbx_scheme.Items.Add(schemes[i].ToString());
                }
                if (cbx_scheme.Items.Count > 0)
                {
                    cbx_scheme.SelectedIndex = 0;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Next button click event
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void tb_next_Click(object sender, EventArgs e)
        {
            var result = CheckInput(true);

            if (!result)
            {
                return;
            }

            string ip       = txt_ip.Text;
            string port     = txt_port.Text;
            string userName = txt_userName.Text;
            string password = txt_password.Text;
            string scheme   = cbx_scheme.Text;

            string modelPackage     = txt_modelPackage.Text;
            string daoPackage       = txt_daoPackage.Text;
            string mapperXmlPackage = txt_mapperPackage.Text;

            bool removeComment        = cb_removeComment.Checked;
            bool forceBigDecimals     = cb_forceBbigDecimals.Checked;
            bool enableSubPackag      = cb_enableSubPackages.Checked;
            bool trimStrings          = cb_trimStrings.Checked;
            bool useActualColumnNames = cb_useActualColumnNames.Checked;


            if (currentButtonStatus == 1)
            {
                // hidden the init panage and show the generate panel
                // panel_initResource.Hide();
                panel_generate.Show();

                label_connectStatus.Hide();
                tb_next.Text        = "Serialize";
                currentButtonStatus = 2;

                // 查询选中数据库下的所有表信息
                DatabaseConnectorProvider connectorProvider = DatabaseConnectorProvider.GetInstance(ip, port, userName, password, DataBaseType.MySql);
                connectorProvider.ChangeDatabaseType(DataBaseType.MySql);
                bool connectResult = connectorProvider.connect();
                if (connectResult)
                {
                    cbx_tables.Items.Clear();
                    List <string> tableList = connectorProvider.initAllTable(scheme);
                    // add default scheme(all table)
                    cbx_tables.Items.Add("%");
                    for (int i = 0; i < tableList.Count; i++)
                    {
                        cbx_tables.Items.Add(tableList[i].ToString());
                    }
                }
            }
            else if (currentButtonStatus == 2)
            {
                // serialize
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                folderBrowserDialog.Description         = "请选择具体保存的文件夹";
                folderBrowserDialog.ShowNewFolderButton = true;
                folderBrowserDialog.ShowDialog();

                string selectPath = folderBrowserDialog.SelectedPath;

                string connectUrl = String.Format("jdbc:mysql://{0}:{1}/{2}?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;autoReconnect=true",
                                                  ip, port, scheme);
                ApplicationRunnerUtils.SerializeRun(txt_targetRuntime.Text, connectUrl, userName, password, modelPackage, daoPackage, mapperXmlPackage, forceBigDecimals, enableSubPackag, trimStrings, cbx_tables.SelectedItem.ToString(), selectPath);
            }
        }