Skip to content

Commit 025f1b2

Browse files
committed
fix infinite loading bug due to delayed change textbox.
beautify the create table sql script a bit fix broken User Guide link after migrating to .net 6
1 parent 56c88fb commit 025f1b2

File tree

5 files changed

+74
-50
lines changed

5 files changed

+74
-50
lines changed

src/ParquetFileViewer/Controls/DelayedOnChangedTextBox.cs

+31-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace ParquetFileViewer.Controls
55
{
66
public class DelayedOnChangedTextBox : TextBox
77
{
8-
private Timer m_delayedTextChangedTimer;
8+
private bool _skipNextTextChange = false;
9+
private Timer _delayedTextChangedTimer;
910

1011
public event EventHandler DelayedTextChanged;
1112

@@ -23,11 +24,11 @@ public DelayedOnChangedTextBox(int secondsDelay)
2324

2425
protected override void Dispose(bool disposing)
2526
{
26-
if (m_delayedTextChangedTimer != null)
27+
if (_delayedTextChangedTimer != null)
2728
{
28-
m_delayedTextChangedTimer.Stop();
29+
_delayedTextChangedTimer.Stop();
2930
if (disposing)
30-
m_delayedTextChangedTimer.Dispose();
31+
_delayedTextChangedTimer.Dispose();
3132
}
3233

3334
base.Dispose(disposing);
@@ -42,23 +43,41 @@ protected virtual void OnDelayedTextChanged(EventArgs e)
4243

4344
protected override void OnTextChanged(EventArgs e)
4445
{
45-
this.InitializeDelayedTextChangedEvent();
46+
if (this._skipNextTextChange)
47+
{
48+
_skipNextTextChange = false;
49+
}
50+
else
51+
{
52+
this.InitializeDelayedTextChangedEvent();
53+
}
54+
4655
base.OnTextChanged(e);
4756
}
4857

58+
/// <summary>
59+
/// Sets the Text value of the textbox without triggering the text changed event
60+
/// </summary>
61+
/// <param name="text">New value to set as the textbox's text</param>
62+
public void SetTextQuiet(string text)
63+
{
64+
this._skipNextTextChange = true;
65+
this.Text = text;
66+
}
67+
4968
private void InitializeDelayedTextChangedEvent()
5069
{
51-
if (m_delayedTextChangedTimer != null)
52-
m_delayedTextChangedTimer.Stop();
70+
if (_delayedTextChangedTimer != null)
71+
_delayedTextChangedTimer.Stop();
5372

54-
if (m_delayedTextChangedTimer == null || m_delayedTextChangedTimer.Interval != this.DelayedTextChangedTimeout)
73+
if (_delayedTextChangedTimer == null || _delayedTextChangedTimer.Interval != this.DelayedTextChangedTimeout)
5574
{
56-
m_delayedTextChangedTimer = new Timer();
57-
m_delayedTextChangedTimer.Tick += new EventHandler(HandleDelayedTextChangedTimerTick);
58-
m_delayedTextChangedTimer.Interval = this.DelayedTextChangedTimeout;
75+
_delayedTextChangedTimer = new Timer();
76+
_delayedTextChangedTimer.Tick += new EventHandler(HandleDelayedTextChangedTimerTick);
77+
_delayedTextChangedTimer.Interval = this.DelayedTextChangedTimeout;
5978
}
6079

61-
m_delayedTextChangedTimer.Start();
80+
_delayedTextChangedTimer.Start();
6281
}
6382

6483
private void HandleDelayedTextChangedTimerTick(object sender, EventArgs e)

src/ParquetFileViewer/Helpers/CustomScriptBasedSchemaAdapter.cs

+23-21
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ public class CustomScriptBasedSchemaAdapter
1414

1515
static CustomScriptBasedSchemaAdapter()
1616
{
17-
Hashtable hashtable = new Hashtable();
18-
hashtable.Add(typeof(ulong), "bigint {1}NULL");
19-
hashtable.Add(typeof(long), "bigint {1}NULL");
20-
hashtable.Add(typeof(bool), "bit {1}NULL");
21-
hashtable.Add(typeof(char), "char {1}NULL");
22-
hashtable.Add(typeof(DateTime), "datetime {1}NULL");
23-
hashtable.Add(typeof(double), "float {1}NULL");
24-
hashtable.Add(typeof(uint), "int {1}NULL");
25-
hashtable.Add(typeof(int), "int {1}NULL");
26-
hashtable.Add(typeof(Guid), "uniqueidentifier {1}NULL");
27-
hashtable.Add(typeof(ushort), "smallint {1}NULL");
28-
hashtable.Add(typeof(short), "smallint {1}NULL");
29-
hashtable.Add(typeof(decimal), "real {1}NULL");
30-
hashtable.Add(typeof(byte), "tinyint {1}NULL");
31-
hashtable.Add(typeof(sbyte), "tinyint {1}NULL");
32-
hashtable.Add(typeof(string), "nvarchar({0}) {1}NULL");
33-
hashtable.Add(typeof(TimeSpan), "int {1}NULL");
34-
hashtable.Add(typeof(byte[]), "varbinary {1}NULL");
17+
Hashtable hashtable = new Hashtable
18+
{
19+
{ typeof(ulong), "BIGINT {1}NULL" },
20+
{ typeof(long), "BIGINT {1}NULL" },
21+
{ typeof(bool), "BIT {1}NULL" },
22+
{ typeof(char), "CHAR {1}NULL" },
23+
{ typeof(DateTime), "DATETIME {1}NULL" },
24+
{ typeof(double), "FLOAT {1}NULL" },
25+
{ typeof(uint), "INT {1}NULL" },
26+
{ typeof(int), "INT {1}NULL" },
27+
{ typeof(Guid), "UNIQUEIDENTIFIER {1}NULL" },
28+
{ typeof(ushort), "SMALLINT {1}NULL" },
29+
{ typeof(short), "SMALLINT {1}NULL" },
30+
{ typeof(decimal), "REAL {1}NULL" },
31+
{ typeof(byte), "TINYINT {1}NULL" },
32+
{ typeof(sbyte), "TINYINT {1}NULL" },
33+
{ typeof(string), "NVARCHAR({0}) {1}NULL" },
34+
{ typeof(TimeSpan), "INT {1}NULL" },
35+
{ typeof(byte[]), "VARBINARY {1}NULL" }
36+
};
3537
TypeMap = hashtable;
3638
}
3739

@@ -132,7 +134,7 @@ private string MakeList(DataColumnCollection columns)
132134
{
133135
if (!flag)
134136
{
135-
stringBuilder.Append(" , ");
137+
stringBuilder.Append(", ");
136138
}
137139
string str = this.MakeSafe(column.ColumnName);
138140
string typeFor = this.GetTypeFor(column);
@@ -163,7 +165,7 @@ private string MakeRelation(DataRelation relation)
163165
protected string MakeSafe(string inputValue)
164166
{
165167
string str = inputValue.Trim();
166-
string str1 = string.Format("[{0}]", str.Substring(0, Math.Min(128, str.Length)));
168+
string str1 = string.Format("[{0}]", str[..Math.Min(128, str.Length)]);
167169
return str1;
168170
}
169171

@@ -172,7 +174,7 @@ private string MakeTable(DataTable table, bool markTablesAsLocalTemp)
172174
StringBuilder stringBuilder = new StringBuilder();
173175
string str = this.MakeSafe(string.Concat(markTablesAsLocalTemp ? "#" : string.Empty, this.TablePrefix, table.TableName));
174176
string str1 = this.MakeList(table.Columns);
175-
stringBuilder.AppendFormat("CREATE TABLE {0} ({1});\n", str, str1);
177+
stringBuilder.AppendFormat("CREATE TABLE {0} ({1}\n);", str, str1);
176178
return stringBuilder.ToString();
177179
}
178180
}

src/ParquetFileViewer/MainForm.Designer.cs

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

src/ParquetFileViewer/MainForm.cs

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4-
using System.ComponentModel;
54
using System.Data;
5+
using System.Diagnostics;
66
using System.Drawing;
77
using System.IO;
88
using System.Linq;
@@ -144,8 +144,8 @@ public MainForm()
144144
{
145145
InitializeComponent();
146146
this.DefaultFormTitle = this.Text;
147-
this.offsetTextBox.Text = DefaultOffset.ToString();
148-
this.recordCountTextBox.Text = DefaultRowCount.ToString();
147+
this.offsetTextBox.SetTextQuiet(DefaultOffset.ToString());
148+
this.recordCountTextBox.SetTextQuiet(DefaultRowCount.ToString());
149149
this.MainDataSource = new DataTable();
150150
this.OpenFilePath = null;
151151

@@ -396,7 +396,7 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
396396

397397
private void userGuideToolStripMenuItem_Click(object sender, EventArgs e)
398398
{
399-
System.Diagnostics.Process.Start(WikiURL);
399+
Process.Start(new ProcessStartInfo(WikiURL) { UseShellExecute = true });
400400
}
401401

402402
private void MainGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
@@ -668,8 +668,18 @@ private void mainGridView_DataBindingComplete(object sender, DataGridViewBinding
668668
private void OpenNewFile(string filePath)
669669
{
670670
this.OpenFilePath = filePath;
671-
this.offsetTextBox.Text = string.IsNullOrWhiteSpace(this.offsetTextBox.Text) ? DefaultOffset.ToString() : this.offsetTextBox.Text;
672-
this.recordCountTextBox.Text = string.IsNullOrWhiteSpace(this.recordCountTextBox.Text) ? DefaultRowCount.ToString() : this.recordCountTextBox.Text;
671+
672+
if (!DefaultOffset.ToString().Equals(this.offsetTextBox.Text)) //Without this 'if' SetTextQuiet doesn't work correctly!
673+
{
674+
this.offsetTextBox.SetTextQuiet(DefaultOffset.ToString());
675+
this.currentMaxRowCount = DefaultRowCount;
676+
}
677+
678+
if (!DefaultRowCount.ToString().Equals(this.recordCountTextBox.Text)) //Without this 'if' SetTextQuiet doesn't work correctly!
679+
{
680+
this.recordCountTextBox.SetTextQuiet(DefaultRowCount.ToString());
681+
this.currentOffset = DefaultOffset;
682+
}
673683

674684
this.OpenFieldSelectionDialog(false);
675685
}
@@ -852,15 +862,9 @@ public ParquetReadResult(DataTable result, long totalNumberOfRecordsInFile)
852862

853863
private void GetSQLCreateTableScriptToolStripMenuItem_Click(object sender, EventArgs e)
854864
{
855-
string tableName = DefaultTableName;
856-
try
857-
{
858-
tableName = Path.GetFileNameWithoutExtension(this.OpenFilePath);
859-
}
860-
catch { /* just in case */ }
861-
862865
try
863866
{
867+
string tableName = Path.GetFileNameWithoutExtension(this.OpenFilePath) ?? DefaultTableName;
864868
if (this.mainDataSource?.Columns.Count > 0)
865869
{
866870
var dataset = new DataSet();

src/ParquetFileViewer/Properties/AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.4.1.0")]
34+
[assembly: AssemblyVersion("2.4.1.1")]

0 commit comments

Comments
 (0)