Skip to content

Commit ea856e1

Browse files
authored
Merge pull request #1 from RehmatFalcon/master
feat: add loading status bar
2 parents 3b14ff3 + bc0e7fd commit ea856e1

File tree

3 files changed

+131
-41
lines changed

3 files changed

+131
-41
lines changed

MainWindow.Designer.cs

Lines changed: 88 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainWindow.cs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Windows.Forms;
45
using postgres_database_restore_tool.Helper;
56
using postgres_database_restore_tool.Validator;
@@ -15,6 +16,20 @@ public PgAdmin()
1516
AddEventHandlers();
1617
}
1718

19+
private void StartLoading(string msg)
20+
{
21+
loadingLbl.Text = msg;
22+
loadingLbl.Visible = true;
23+
loadingBar.Visible = true;
24+
}
25+
26+
private void EndLoading()
27+
{
28+
loadingLbl.Text = "";
29+
loadingLbl.Visible = false;
30+
loadingBar.Visible = false;
31+
}
32+
1833
const string pwdKey = "PGPASSWORD";
1934

2035
private void AddEventHandlers()
@@ -54,8 +69,8 @@ private void OnRestore(object sender, EventArgs e)
5469
{
5570
try
5671
{
72+
StartLoading("Restoring Database");
5773

58-
5974
var connection = UserConnectionValidator.ValidateConnection(new UserConnectionVo()
6075
{
6176
UserName = UserNameElm.Text,
@@ -67,20 +82,36 @@ private void OnRestore(object sender, EventArgs e)
6782
});
6883

6984
WorkingStatus.Text = "Restoring...";
70-
CommandExecutor.ExecuteRestore(connection);
71-
WorkingStatus.Text = "Completed";
72-
MessageBox.Show($"Database #{DatabaseElem.Text} restored successfully");
73-
SelectedFilelbl.Text = "";
74-
WorkingStatus.Text = "";
85+
var bgw = new BackgroundWorker();
86+
bgw.DoWork += (object _, DoWorkEventArgs args) =>
87+
{
88+
CommandExecutor.ExecuteRestore(connection);
89+
};
90+
bgw.RunWorkerCompleted += (object _, RunWorkerCompletedEventArgs args) =>
91+
{
92+
if(args.Error == null)
93+
{
94+
WorkingStatus.Text = "Completed";
95+
MessageBox.Show($"Database #{DatabaseElem.Text} restored successfully");
96+
}
97+
else
98+
{
99+
var msg = (args.Error as Exception)?.Message ?? "Error during operation";
100+
MessageBox.Show(msg);
101+
}
102+
SelectedFilelbl.Text = "";
103+
WorkingStatus.Text = "";
104+
EndLoading();
105+
106+
};
107+
bgw.RunWorkerAsync();
75108
}
76109
catch (Exception ex)
77110
{
111+
EndLoading();
78112
SelectedFilelbl.Text = "";
79113
WorkingStatus.Text = "";
80114
MessageBox.Show(ex.Message);
81-
}
82-
finally
83-
{
84115
Environment.SetEnvironmentVariable(pwdKey, "");
85116
}
86117
}

MainWindow.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,7 @@
120120
<metadata name="TargetLocation.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121121
<value>25, 11</value>
122122
</metadata>
123+
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124+
<value>183, 11</value>
125+
</metadata>
123126
</root>

0 commit comments

Comments
 (0)