private void BtnImportConfig_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title            = "Browse Text Files";

            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;

            openFileDialog1.DefaultExt       = "txt";
            openFileDialog1.Filter           = "Db Config File (*.json)|*.json";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            openFileDialog1.ReadOnlyChecked = true;
            openFileDialog1.ShowReadOnly    = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string file = openFileDialog1.FileName;
                string tmp  = File.ReadAllText(file);
                conModel = JsonConvert.DeserializeObject <ConnectionModelGG>(tmp);
            }
        }
        public bool IsConnect(ConnectionModelGG modelGG)
        {
            if (String.IsNullOrEmpty(databaseName))
            {
                return(false);
            }
            string connstring = string.Format("Server={0}; Port={1}; database={2}; UID={3}; password={4}", modelGG.server, modelGG.port, modelGG.databaseName, modelGG.username, modelGG.password);

            connection = new MySqlConnection(connstring);
            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error no: 1 -" + ex.Message);
                return(false);
            }

            return(true);
        }
        private void BtnTestConnection_Click(object sender, System.EventArgs e)
        {
            if (conModel == null && txtDbName.Text.Trim() == "")
            {
                MessageBox.Show("Error no: 2 - Please enter connection info OR Import database config!");
            }
            else
            {
                if (conModel == null)
                {
                    conModel                = new ConnectionModelGG();
                    conModel.port           = txtPort.Text.Trim();
                    conModel.server         = txtServer.Text.Trim();
                    conModel.username       = txtUsername.Text.Trim();
                    conModel.password       = txtPassword.Text.Trim();
                    conModel.databaseName   = txtDbName.Text.Trim();
                    conModel.ggProductTable = txtTableGGProduct.Text.Trim();
                    conModel.productTable   = txtTableProduct.Text.Trim();
                }

                var con = DBConnection.Instance();
                con.DatabaseName = conModel.databaseName;
                if (con.IsConnect(conModel))
                {
                    txtPort.Text           = conModel.port;
                    txtServer.Text         = conModel.server;
                    txtUsername.Text       = conModel.username;
                    txtDbName.Text         = conModel.databaseName;
                    txtTableProduct.Text   = conModel.productTable;
                    txtTableGGProduct.Text = conModel.ggProductTable;

                    MessageBox.Show("Test is successful.");
                }

                con.Close();
            }
        }