Exemple #1
0
        private void dbConnectCreateTableBtn_Click(object sender, EventArgs e)
        {
            //test create table "menu"
            DBConnection dbConnect;
            string       queryString = "";

            if (radioButtonDatabaseMySql.Checked)
            {
                dbConnect   = new DBConnection_MySQL();
                queryString = String.Format("create table menu (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), type VARCHAR(20), price VARCHAR(10), modifiedDate datetime);");
            }
            else
            {
                dbConnect   = new DBConnection_Azure_MsSQL();
                queryString = String.Format("create table menu (id INT IDENTITY(1,1) PRIMARY KEY, name VARCHAR(30), type VARCHAR(20), price VARCHAR(10), modifiedDate datetime);");
            }


            //queryString = $"create table if not exists menu (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), type VARCHAR(20), price VARCHAR(10), modifiedDate datetime);";

            dbConnect.executeQuery(queryString);
            if (dbConnect.IsSuccess())
            {
                MessageBox.Show("Table Created");
            }
            else
            {
                MessageBox.Show(dbConnect.getErrorString());
            }
        }
Exemple #2
0
        private void dbConnectDropTableBtn_Click(object sender, EventArgs e)
        {
            //test drop table "menu"
            DBConnection dbConnect;

            if (radioButtonDatabaseMySql.Checked)
            {
                dbConnect = new DBConnection_MySQL();
            }
            else
            {
                dbConnect = new DBConnection_Azure_MsSQL();
            }


            string queryString = "";

            //queryString = $"drop table if exists menu;";
            queryString = "drop table menu;";
            dbConnect.executeQuery(queryString);
            if (dbConnect.IsSuccess())
            {
                MessageBox.Show("Table Droped");
            }
            else
            {
                MessageBox.Show(dbConnect.getErrorString());
            }
        }
Exemple #3
0
        private void dbConnectBtn_Click(object sender, EventArgs e)
        {
            DBConnection dbConnect;

            if (radioButtonDatabaseMySql.Checked)
            {
                dbConnect = new DBConnection_MySQL();
            }
            else
            {
                dbConnect = new DBConnection_Azure_MsSQL();
            }

            //test connection
            if (dbConnect.Connect())
            {
                //disconnect
                if (dbConnect.Disconnect())
                {
                    MessageBox.Show("Connect Test Success.");
                }
                else
                {
                    MessageBox.Show(dbConnect.getErrorString());
                }
            }
            else
            {
                MessageBox.Show(dbConnect.getErrorString());
            }
        }
Exemple #4
0
        private void dbConnectInsertBtn_Click(object sender, EventArgs e)
        {
            //test insert data into table "menu"
            DBConnection dbConnect;
            string       queryString1 = "";
            string       queryString2 = "";

            if (radioButtonDatabaseMySql.Checked)
            {
                dbConnect    = new DBConnection_MySQL();
                queryString1 = "INSERT INTO menu (name, type, price, modifiedDate) VALUES('Beef Noodle', 'Noodle', '8.99', NOW());";
                queryString2 = "INSERT INTO menu(name, type, price, modifiedDate) VALUES('Fired Chicken Rice', 'Rice', '7.99', NOW());";
            }
            else
            {
                dbConnect    = new DBConnection_Azure_MsSQL();
                queryString1 = "INSERT INTO menu (name, type, price, modifiedDate) VALUES('Beef Noodle', 'Noodle', '8.99', GETDATE());";
                queryString2 = "INSERT INTO menu(name, type, price, modifiedDate) VALUES('Fired Chicken Rice', 'Rice', '7.99', GETDATE());";
            }


            dbConnect.executeQuery(queryString1);
            if (dbConnect.IsSuccess())
            {
                MessageBox.Show("Inserted first record");
            }
            else
            {
                MessageBox.Show(dbConnect.getErrorString());
                return;
            }

            dbConnect.executeQuery(queryString2);
            if (dbConnect.IsSuccess())
            {
                MessageBox.Show("Inserted second record");
            }
            else
            {
                MessageBox.Show(dbConnect.getErrorString());
                return;
            }
        }
Exemple #5
0
        private void dbConnectSelectBtn_Click(object sender, EventArgs e)
        {
            DBConnection dbConnect;

            if (radioButtonDatabaseMySql.Checked)
            {
                dbConnect = new DBConnection_MySQL();
            }
            else
            {
                dbConnect = new DBConnection_Azure_MsSQL();
            }


            List <string> resultList = dbConnect.SelectTest();

            string finalResult = "";

            foreach (string result in resultList)
            {
                finalResult += result + '\n';
            }
            MessageBox.Show(finalResult);
        }