private void btnGetCode_Click(object sender, EventArgs e) { if (this.txtInputArea.Text.Trim() == "") { return; } if (!this.txtInputArea.Text.Trim().ToLower().StartsWith("select ")) { this.txtLog.Text = "search failed!is not start with \"select\""; return; } this.btnGetCode.Enabled = false; try { DataTable dt = DataMarket.ExecuteDataTable(this.txtInputArea.Text); if (dt == null) { return; } this.dgList.DataSource = dt; this.txtLog.Text = string.Format("search success!get {0} rows from table", dt.Rows.Count); } catch (Exception ex) { this.txtLog.Text = string.Format("search failed, reason:{0}", ex.ToString()); } finally { this.btnGetCode.Enabled = true; } }
private void btnCSV_Click(object sender, EventArgs e) { if (this.txtInputArea.Text.Trim() == "") { return; } if (!this.txtInputArea.Text.Trim().ToLower().StartsWith("select ")) { this.txtLog.Text = "export failed!is not start with \"select\""; return; } this.btnGetCode.Enabled = false; try { DataTable dt = DataMarket.ExecuteDataTable(this.txtInputArea.Text); if (dt == null) { return; } //this.directoryEntry1..sho.show this.sfCSV.Filter = "CSV文件|*.CSV"; this.sfCSV.InitialDirectory = folder; this.sfCSV.FileName = tableName + DateTime.Now.ToString("_yyyyMMddHHmmSS"); if (this.sfCSV.ShowDialog() == DialogResult.Cancel) { return; } else { folder = this.sfCSV.InitialDirectory; string fileName = this.sfCSV.FileName; SaveCSV(dt, fileName); } this.txtLog.Text = string.Format("save success!get {0} rows from table", dt.Rows.Count); } catch (Exception ex) { this.txtLog.Text = string.Format("save failed, reason:{0}", ex.ToString()); } finally { this.btnGetCode.Enabled = true; } }