Regret closing initial window and progressbar for timeconsuming events

This commit is contained in:
2022-02-22 21:59:29 +01:00
parent 95a9537af9
commit e6121da2ca
4 changed files with 76 additions and 21 deletions

View File

@ -29,6 +29,7 @@ namespace StockInfoCore
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.lblTotalRecords = new System.Windows.Forms.Label(); this.lblTotalRecords = new System.Windows.Forms.Label();
this.gB1 = new System.Windows.Forms.GroupBox(); this.gB1 = new System.Windows.Forms.GroupBox();
@ -48,6 +49,8 @@ namespace StockInfoCore
this.btnConnShares = new System.Windows.Forms.Button(); this.btnConnShares = new System.Windows.Forms.Button();
this.btnEditPerson = new System.Windows.Forms.Button(); this.btnEditPerson = new System.Windows.Forms.Button();
this.cmbOwners = new System.Windows.Forms.ComboBox(); this.cmbOwners = new System.Windows.Forms.ComboBox();
this.pbInitial = new System.Windows.Forms.ProgressBar();
this.tmrProgBar = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.gB1.SuspendLayout(); this.gB1.SuspendLayout();
this.gbStockMgmnt.SuspendLayout(); this.gbStockMgmnt.SuspendLayout();
@ -60,11 +63,11 @@ namespace StockInfoCore
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 16); this.dataGridView.Location = new System.Drawing.Point(12, 21);
this.dataGridView.MultiSelect = false; this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25; this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(871, 360); this.dataGridView.Size = new System.Drawing.Size(871, 355);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
this.dataGridView.SelectionChanged += new System.EventHandler(this.dataGridView_SelectionChanged); this.dataGridView.SelectionChanged += new System.EventHandler(this.dataGridView_SelectionChanged);
// //
@ -243,15 +246,30 @@ namespace StockInfoCore
this.cmbOwners.FormattingEnabled = true; this.cmbOwners.FormattingEnabled = true;
this.cmbOwners.Location = new System.Drawing.Point(6, 33); this.cmbOwners.Location = new System.Drawing.Point(6, 33);
this.cmbOwners.Name = "cmbOwners"; this.cmbOwners.Name = "cmbOwners";
this.cmbOwners.Size = new System.Drawing.Size(152, 23); this.cmbOwners.Size = new System.Drawing.Size(222, 23);
this.cmbOwners.TabIndex = 0; this.cmbOwners.TabIndex = 0;
this.cmbOwners.SelectedIndexChanged += new System.EventHandler(this.cmbOwners_SelectedIndexChanged); this.cmbOwners.SelectedIndexChanged += new System.EventHandler(this.cmbOwners_SelectedIndexChanged);
// //
// pbInitial
//
this.pbInitial.ForeColor = System.Drawing.Color.Tomato;
this.pbInitial.Location = new System.Drawing.Point(131, 5);
this.pbInitial.Name = "pbInitial";
this.pbInitial.Size = new System.Drawing.Size(646, 10);
this.pbInitial.TabIndex = 11;
this.pbInitial.Visible = false;
//
// tmrProgBar
//
this.tmrProgBar.Interval = 250;
this.tmrProgBar.Tick += new System.EventHandler(this.tmrProgBar_Tick);
//
// frmInitial // frmInitial
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(895, 538); this.ClientSize = new System.Drawing.Size(895, 538);
this.Controls.Add(this.pbInitial);
this.Controls.Add(this.gpOwners); this.Controls.Add(this.gpOwners);
this.Controls.Add(this.lblStockRows); this.Controls.Add(this.lblStockRows);
this.Controls.Add(this.gbStockMgmnt); this.Controls.Add(this.gbStockMgmnt);
@ -296,6 +314,8 @@ namespace StockInfoCore
private System.Windows.Forms.Button btnEditPerson; private System.Windows.Forms.Button btnEditPerson;
private System.Windows.Forms.ComboBox cmbOwners; private System.Windows.Forms.ComboBox cmbOwners;
private System.Windows.Forms.Button btnBackupAll; private System.Windows.Forms.Button btnBackupAll;
private ProgressBar pbInitial;
private System.Windows.Forms.Timer tmrProgBar;
} }
} }

View File

@ -36,6 +36,7 @@ namespace StockInfoCore
private readonly frmBackup _backupWindow; private readonly frmBackup _backupWindow;
private readonly frmEditStock _editStock; private readonly frmEditStock _editStock;
bool loading = false; bool loading = false;
int progressValue = 0;
public int SelectedPersonId { get; set; } = 0; public int SelectedPersonId { get; set; } = 0;
@ -83,13 +84,13 @@ namespace StockInfoCore
btnBackupAll.Enabled = false; btnBackupAll.Enabled = false;
} }
private void ReloadData(bool upd = false) private async Task ReloadData(bool upd = false)
{ {
loading = true; loading = true;
var allStocks = _stockRepository.GetAllStocks(); var allStocks = _stockRepository.GetAllStocks();
if (upd) if (upd)
{ {
_stockMarketRepository.LoadStockMarketList(SelectedPersonId); await _stockMarketRepository.LoadStockMarketListAsync(SelectedPersonId);
allStocks.ToList().ForEach(SM => SM.ActValue = UpdateOnlyNonZeroAmount(SM).ActValue); allStocks.ToList().ForEach(SM => SM.ActValue = UpdateOnlyNonZeroAmount(SM).ActValue);
} }
dataGridView.DataSource = allStocks; dataGridView.DataSource = allStocks;
@ -103,32 +104,36 @@ namespace StockInfoCore
var output = new StockMember(); var output = new StockMember();
if (sMember.ActAmount > 0) if (sMember.ActAmount > 0)
{ {
if (_stockMarketRepository.StockMarketList.ContainsKey(sMember.StockId)){ if (_stockMarketRepository.StockMarketList.ContainsKey(sMember.StockId))
{
sMember.ActValue = _stockMarketRepository.StockMarketList[sMember.StockId].LatestPrice; sMember.ActValue = _stockMarketRepository.StockMarketList[sMember.StockId].LatestPrice;
_stockRepository.UpdateActualPrice(sMember.Id, sMember.ActValue); _stockRepository.UpdateActualPrice(sMember.Id, sMember.ActValue);
} }
} }
output=sMember; output = sMember;
return output; return output;
} }
private void btnReload_Click(object sender, EventArgs e) private async void btnReload_Click(object sender, EventArgs e)
{ {
Cursor = Cursors.WaitCursor; StartProgressTicking(350);
ReloadData(true); await ReloadData(true);
Cursor=Cursors.Default; StopProgressTicking();
} }
private void frmInitial_FormClosing(object sender, FormClosingEventArgs e) private void frmInitial_FormClosing(object sender, FormClosingEventArgs e)
{ {
MessageBox.Show("B y e B y e !!"); if (DialogResult.OK != MessageBox.Show("B y e B y e !!", "Should we close ?", MessageBoxButtons.OKCancel))
{
e.Cancel = true;
}
} }
private void btnStockReg_Click(object sender, EventArgs e) private void btnStockReg_Click(object sender, EventArgs e)
{ {
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
_stockMarketRepository.LoadStockMarketList(SelectedPersonId==0?10000: SelectedPersonId); _stockMarketRepository.LoadStockMarketList(SelectedPersonId == 0 ? 10000 : SelectedPersonId);
_regWindow.Stocks = _stockMarketRepository.StockMarketList; _regWindow.Stocks = _stockMarketRepository.StockMarketList;
Cursor.Current = DefaultCursor; Cursor.Current = DefaultCursor;
_regWindow.ShowDialog(); _regWindow.ShowDialog();
@ -152,16 +157,15 @@ namespace StockInfoCore
} }
else else
{ {
StartProgressTicking();
var person = _personRepository.GetPersonById(SelectedPersonId); var person = _personRepository.GetPersonById(SelectedPersonId);
Cursor.Current = Cursors.WaitCursor;
await _stockMarketRepository.LoadStockMarketListAsync(SelectedPersonId); await _stockMarketRepository.LoadStockMarketListAsync(SelectedPersonId);
StopProgressTicking();
_stockWindow.ConnectedPerson = person; _stockWindow.ConnectedPerson = person;
_stockWindow.Stocks = _stockMarketRepository.StockMarketList; _stockWindow.Stocks = _stockMarketRepository.StockMarketList;
Cursor.Current = DefaultCursor; //GlobalStopwatch.Stop();
//GlobalStopwatch.Stop();
//GlobalStopwatch.PrintSecs("Before Show Stockwindow"); //GlobalStopwatch.PrintSecs("Before Show Stockwindow");
_stockWindow.ShowDialog(); _stockWindow.ShowDialog();
} }
@ -295,5 +299,32 @@ namespace StockInfoCore
}; };
} }
} }
private void tmrProgBar_Tick(object sender, EventArgs e)
{
pbInitial.Value = progressValue;
if (progressValue < 100)
progressValue += 1;
}
public void StartProgressTicking(int intervall = 250)
{
pbInitial.Enabled = true;
pbInitial.Minimum = 0;
pbInitial.Maximum = 100;
pbInitial.Value = 0;
pbInitial.Visible = true;
tmrProgBar.Interval = intervall;
tmrProgBar.Enabled = true;
tmrProgBar.Start();
}
public void StopProgressTicking()
{
tmrProgBar.Stop();
tmrProgBar.Enabled = false;
pbInitial.Visible = false;
progressValue = 0;
}
} }
} }

View File

@ -63,7 +63,10 @@
<metadata name="ofdOpener.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="ofdOpener.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>114, 17</value> <value>114, 17</value>
</metadata> </metadata>
<metadata name="tmrProgBar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>225, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>27</value> <value>75</value>
</metadata> </metadata>
</root> </root>

View File

@ -33,6 +33,7 @@ namespace StockInfoCore
private void ReloadRemainingStocks() private void ReloadRemainingStocks()
{ {
if (selectedPersonId == 0) return; if (selectedPersonId == 0) return;
lvSellCandidates.Items.Clear();
remainingStocks = _stockRepository.GetAllRemainingStocks(selectedPersonId).ToList(); remainingStocks = _stockRepository.GetAllRemainingStocks(selectedPersonId).ToList();
foreach (var stock in remainingStocks) foreach (var stock in remainingStocks)
{ {