Skip to content

Commit f66b9ab

Browse files
committed
chore: modify create sql script menu button logic for better user experience
1 parent c013005 commit f66b9ab

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

src/ParquetFileViewer/MainForm.Designer.cs

+29-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ParquetFileViewer/MainForm.cs

+16-9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private string OpenFilePath
4343
this.SelectedFields = null;
4444
this.openFilePath = value;
4545
this.changeFieldsMenuStripButton.Enabled = false;
46+
this.getSQLCreateTableScriptToolStripMenuItem.Enabled = false;
4647
this.recordCountStatusBarLabel.Text = "0";
4748
this.totalRowCountStatusBarLabel.Text = "0";
4849
this.MainDataSource.Clear();
@@ -56,6 +57,7 @@ private string OpenFilePath
5657
{
5758
this.Text = string.Concat("Open File: ", value);
5859
this.changeFieldsMenuStripButton.Enabled = true;
60+
this.getSQLCreateTableScriptToolStripMenuItem.Enabled = true;
5961
}
6062
}
6163
}
@@ -671,8 +673,8 @@ private void mainGridView_DataBindingComplete(object sender, DataGridViewBinding
671673
private void OpenNewFile(string filePath)
672674
{
673675
this.OpenFilePath = filePath;
674-
this.offsetTextBox.Text = DefaultOffset.ToString();
675-
this.recordCountTextBox.Text = DefaultRowCount.ToString();
676+
this.offsetTextBox.Text = string.IsNullOrWhiteSpace(this.offsetTextBox.Text) ? DefaultOffset.ToString() : this.offsetTextBox.Text;
677+
this.recordCountTextBox.Text = string.IsNullOrWhiteSpace(this.recordCountTextBox.Text) ? DefaultRowCount.ToString() : this.recordCountTextBox.Text;
676678

677679
this.OpenFieldSelectionDialog();
678680
}
@@ -833,16 +835,21 @@ private void GetSQLCreateTableScriptToolStripMenuItem_Click(object sender, Event
833835

834836
try
835837
{
836-
var dataset = new DataSet();
838+
if (this.mainDataSource?.Columns.Count > 0)
839+
{
840+
var dataset = new DataSet();
837841

838-
this.mainDataSource.TableName = tableName;
839-
dataset.Tables.Add(this.mainDataSource);
842+
this.mainDataSource.TableName = tableName;
843+
dataset.Tables.Add(this.mainDataSource);
840844

841-
var scriptAdapter = new CustomScriptBasedSchemaAdapter();
842-
string sql = scriptAdapter.GetSchemaScript(dataset, false);
845+
var scriptAdapter = new CustomScriptBasedSchemaAdapter();
846+
string sql = scriptAdapter.GetSchemaScript(dataset, false);
843847

844-
Clipboard.SetText(sql);
845-
MessageBox.Show(this, "Create table script copied to clipboard!", "Parquet Viewer", MessageBoxButtons.OK, MessageBoxIcon.Information);
848+
Clipboard.SetText(sql);
849+
MessageBox.Show(this, "Create table script copied to clipboard!", "Parquet Viewer", MessageBoxButtons.OK, MessageBoxIcon.Information);
850+
}
851+
else
852+
MessageBox.Show(this, "Please select some fields first to get the SQL script", "Parquet Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error);
846853
}
847854
catch (Exception ex)
848855
{

0 commit comments

Comments
 (0)