private void SaveSql() { if (!String.IsNullOrEmpty(this.sqlGenerated)) { string commandName = this.mchkUseReplaceInto.Checked ? "replace" : "insert"; this.saveFileDialog1.FileName = String.Format( "{0}-{1}-{2}.sql", this.DbConnection.Database, this.TableName, commandName ); if (this.saveFileDialog1.ShowDialog() == DialogResult.OK) { try { using (StreamWriter sw = new StreamWriter(this.saveFileDialog1.FileName)) { sw.Write(this.sqlGenerated); MetroMsgBoxUtil.Success(this, "已保存", "成功"); } } catch (Exception ex) { MetroMsgBoxUtil.Fail(this, ex.Message, "失败"); } } } }
private void dgvMapping_CellEndEdit(object sender, DataGridViewCellEventArgs e) { var colName = Convert.ToString(dgvMapping.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); if (!String.IsNullOrEmpty(colName) && !excelColumnHeaderNameList.Contains(colName.Trim())) { MetroMsgBoxUtil.Fail(this, String.Format("不存在名为\"{0}\"的列头。", colName), "列头错误"); this.dgvMapping.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = cellValueBeforeEdit; } }
private IDbConnection GetConnection() { var connStr = String.Format("server={0};uid={1};pwd={2};", this.mtxtHostname.Text.Trim(), this.mtxtUsername.Text.Trim(), this.mtxtPassword.Text); if (!String.IsNullOrEmpty(this.mtxtPort.Text.Trim())) { connStr += String.Format("port={0};", this.mtxtPort.Text.Trim()); } try { using (var conn = new MySqlConnection(connStr)) { conn.Open(); return(conn); } } catch (Exception ex) { MetroMsgBoxUtil.Fail(this, ex.Message, "连接失败"); return(null); } }