Exemple #1
0
        private void btn_run_Click(object sender, EventArgs e)
        {
            if (cmb_connections.Text == "" || cmb_connections.Text.Length == 0)
            {
                MessageBox.Show("No connection Selected. Please Refresh Connection list.");
            }


            else
            {
                dg.DataSource = null;
                if (txt.SelectedText.Length == 0)
                {
                    tbl = sql.Execute_DataTable(txt.Text, Convert.ToInt32(cmb_connections.SelectedValue));
                }
                else
                {
                    tbl = sql.Execute_DataTable(txt.SelectedText, Convert.ToInt32(cmb_connections.SelectedValue));
                }



                dg.DataSource = tbl;

                DataRow dr = tbl_res.NewRow();

                dr[0] = DateTime.Now;
                if (txt.SelectedText.Length == 0)
                {
                    dr[1] = txt.Text;
                }
                else
                {
                    dr[1] = txt.SelectedText;
                }


                dr[2] = sql.WorkerResult.Message;


                tbl_res.Rows.Add(dr);

                if (sql.WorkerResult.Result)
                {
                    txt_Status.Text           = "SUCCESS";
                    txt_Status.ForeColor      = Color.ForestGreen;
                    tabControl1.SelectedIndex = 0;
                }
                else
                {
                    txt_Status.Text           = "ERROR";
                    txt_Status.ForeColor      = Color.IndianRed;
                    tabControl1.SelectedIndex = 1;
                }
            }
        }
Exemple #2
0
        private void tv_connections_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.Node.Name == "PATH")
                {
                    e.Node.ContextMenuStrip = menu_connect;
                    curr_node = e.Node;
                    //menu_connect.Show();
                }
                else if (e.Node.Name == "CONN")
                {
                    e.Node.ContextMenuStrip = menu_connection;
                    curr_node = e.Node;
                }

                else if (e.Node.Name == "TABLE")
                {
                    e.Node.ContextMenuStrip = menu_table;
                    curr_node = e.Node;
                }
            }

            txt_status.Text = e.Node.Name;

            if (e.Node.Name == "TABLE" || e.Node.Name == "VIEW")
            {
                var connId = Convert.ToInt32(e.Node.Tag);

                txt_query.Text     = "";
                dg_data.DataSource = null;

                tbl = obj_sql.Execute_DataTable("SELECT sql FROM sqlite_master WHERE  tbl_name='"
                                                + e.Node.Text + "'", connId);
                if (tbl.Rows.Count != 0)
                {
                    txt_query.Text = tbl.Rows[0][0].ToString();
                }
                else
                {
                    txt_status.Text = obj_sql.WorkerResult.Message;
                    return;
                }
                // MessageBox.Show(e.Node.Tag.ToString());

                tbl = obj_sql.Execute_DataTable("SELECT * from " + e.Node.Text + " limit 100"
                                                , connId);

                if (tbl.Rows.Count != 0)
                {
                    dg_data.DataSource = tbl;
                }
                else
                {
                    txt_status.Text = obj_sql.WorkerResult.Message;
                }


                using (SQLiteDataReader dr = obj_sql.Execute_DataReader($"SELECT * FROM {e.Node.Text} WHERE 1=2",
                                                                        connId))
                {
                    dg_struct.DataSource = dr.GetSchemaTable().AsEnumerable()
                                           .Select(x => new
                    {
                        ColumnOrdinal   = x.Field <int>("ColumnOrdinal"),
                        ColumnName      = x.Field <string>("ColumnName"),
                        DataTypeName    = x.Field <string>("DataTypeName"),
                        AllowDBNull     = x.Field <bool>("AllowDBNull"),
                        IsKey           = x.Field <bool>("IsKey"),
                        IsAutoIncrement = x.Field <bool>("IsAutoIncrement")
                    }).ToList();
                }
            }
        }