Exemple #1
0
 private void BtnConnect_Click(object sender, EventArgs e)
 {
     dal = new DAL.PGDAL(tbxHost.Text.Trim(), (int)numPort.Value, tbxUser.Text.Trim(), tbxPassword.Text.Trim(), tbxDatabase.Text.Trim());
     Task.Factory.StartNew(() =>
     {
         try
         {
             List <Model.TableModel> tables = dal.GetTableModelList();
             this.Invoke(new Action(() =>
             {
                 lblStatus.Text = "就绪";
                 AddTableNodes(tables);
                 BtnConnect.Enabled = true;
             }));
         }
         catch (Exception ex)
         {
             this.Invoke(new Action(() =>
             {
                 MessageBox.Show(ex.Message);
                 lblStatus.Text     = ex.Message;
                 BtnConnect.Enabled = true;
             }));
         }
     });
     BtnConnect.Enabled = false;
     lblStatus.Text     = "正在加载表...";
 }
Exemple #2
0
        private void tsBtnRun_Click(object sender, EventArgs e)
        {
            string sql = tecSqlQuery.Text;

            if (string.IsNullOrEmpty(sql))
            {
                return;
            }

            dal = new DAL.PGDAL(tbxHost.Text.Trim(), (int)numPort.Value, tbxUser.Text.Trim(), tbxPassword.Text.Trim(), tbxDatabase.Text.Trim());

            if (sql.Trim().ToUpper().StartsWith("SELECT"))
            {
                DateTime dtStart = DateTime.Now;
                Task.Factory.StartNew(() =>
                {
                    DataTable result = dal.QueryDataTable(sql);
                    this.Invoke(new Action(() =>
                    {
                        lblStatus.Text = string.Format("共 {0} 条记录,耗时 {1} 毫秒",
                                                       result.Rows.Count,
                                                       (DateTime.Now - dtStart).TotalMilliseconds);
                        tecSqlQuery.Enabled       = true;
                        tsBtnRun.Enabled          = true;
                        dgvQueryResult.DataSource = result;
                        CodeGenerateByQuery();
                    }));
                });
                lblStatus.Text      = "正在查询...";
                tecSqlQuery.Enabled = false;
                tsBtnRun.Enabled    = false;
            }
            else
            {
                //TODO: INSERT UPDATE DELETE
            }
        }