Beispiel #1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            asyncSql bgWorkerObj = (asyncSql)e.Argument;
            Profil   dbProfil    = bgWorkerObj.dbProfil;
            string   sql         = bgWorkerObj.sql;

            MysqlHandler database = new MysqlHandler(dbProfil);

            database.connect();
            if (database.isConnected())
            {
                //database.beginTransaction();
                bgWorkerObj.status = 1;
                //database.query(sql);
                MySql.Data.MySqlClient.MySqlDataReader dbResult;
                if (bgWorkerObj.fireSingleShots)
                {
                    dbResult = null;
                    string[] singleShots = sql.Split(';');
                    for (int i = 0; i < singleShots.Length; i++)
                    {
                        dbResult = database.sql_select(singleShots[i]);
                    }
                }
                else
                {
                    dbResult = database.sql_select(sql);
                }
                bgWorkerObj.result    = dbResult;
                bgWorkerObj.haseRows  = (dbResult != null && dbResult.HasRows == true);
                bgWorkerObj.lastError = database.lastSqlErrorMessage;

/*
 *              if (database.lastSqlErrorMessage != "")
 *              {
 *                  // database.rollBack();
 *              }
 *              else
 *              {
 *                 // database.commit();
 *              }
 */
                bgWorkerObj.status         = 2;
                bgWorkerObj.resultListView = new ListView();
                if (bgWorkerObj.haseRows)
                {
                    database.sql_data2ListView(dbResult, bgWorkerObj.resultListView);
                }

                ThreadList[bgWorkerObj.workerID].ReportProgress(bgWorkerObj.workerID, bgWorkerObj);
            }

            database.disConnect();
        }
Beispiel #2
0
        private void mysql_watcher_DoWork(object sender, DoWorkEventArgs e)
        {
            ListView retObj = (ListView)e.Argument;
            //ListView retObj = new ListView();

            MysqlHandler mysql = new MysqlHandler(watchProfil);

            mysql.connect();

            string sql = "show full processlist";

            MySql.Data.MySqlClient.MySqlDataReader rankings = mysql.sql_select(sql);
            if (retObj != null)
            {
                mysql.sql_data2ListView(rankings, retObj);
            }

            mysql.disConnect();
        }
Beispiel #3
0
        private void fireSql(Profil dbProfil, string sql)
        {
            MysqlHandler database = new MysqlHandler(dbProfil);

            database.connect();

            if (database.isConnected())
            {
                ListViewWorker listTool  = new ListViewWorker();
                GroupBox       instGroup = new GroupBox();
                instGroup.Width     = MainView.Width - 30;
                instGroup.BackColor = SystemColors.Info;
                //instGroup.Height = 350;
                instGroup.Text     = currentProfileName;
                instGroup.AutoSize = true;

                Label infoData = new Label();
                infoData.AutoSize = true;
                infoData.Text     = dbProfil.getProperty("db_username") + "@" + dbProfil.getProperty("db_host") + "/" + dbProfil.getProperty("db_schema");
                infoData.Top      = 15;
                infoData.Left     = 15;

                ListView resultView = new ListView();
                resultView.View = View.Details;

                resultView.Width  = MainView.Width - 60;
                resultView.Height = 300;
                resultView.Left   = 10;
                resultView.Top    = 30;

                resultView.FullRowSelect = true;

                resultView.GridLines = true;

                MySql.Data.MySqlClient.MySqlDataReader dbResult = database.sql_select(sql);

                if (database.lastSqlErrorMessage != "")
                {
                    Label noData = new Label();
                    noData.Top      = 30;
                    noData.Left     = 15;
                    noData.Text     = database.lastSqlErrorMessage;
                    noData.AutoSize = true;
                    noData.Font     = new Font("Courier New", 10, FontStyle.Bold);
                    instGroup.Controls.Add(noData);
                    instGroup.Controls.Add(infoData);
                    instGroup.Height    = 60;
                    instGroup.BackColor = Color.LightPink;
                }
                else
                {
                    if (dbResult != null && dbResult.HasRows)
                    {
                        database.sql_data2ListView(dbResult, resultView);
                        for (int i = 0; i < resultView.Columns.Count; i++)
                        {
                            resultView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
                        }
                        listTool.setRowColors(resultView, Color.LightBlue, Color.LightGreen);

                        resultView.Height = (resultView.Items.Count * 13) + 50;
                        if (resultView.Height > 700)
                        {
                            resultView.Height = 700;
                        }

                        listLabelExports.Add(instGroup.Text);
                        listViewExports.Add(resultView);
                        instGroup.Controls.Add(resultView);
                        instGroup.Controls.Add(infoData);
                    }
                    else
                    {
                        Label noData = new Label();
                        noData.Top      = 30;
                        noData.Left     = 15;
                        noData.Text     = "No Result for this query ";
                        noData.AutoSize = true;
                        instGroup.Controls.Add(noData);
                        instGroup.Height    = 60;
                        instGroup.BackColor = Color.LightYellow;
                        instGroup.Controls.Add(infoData);
                    }
                }



                MainView.Controls.Add(instGroup);
                MainView.Refresh();
            }


            database.disConnect();
        }