diff --git a/StockInfoCore/frmInitial.Designer.cs b/StockInfoCore/frmInitial.Designer.cs index 183ddf5..11ea324 100644 --- a/StockInfoCore/frmInitial.Designer.cs +++ b/StockInfoCore/frmInitial.Designer.cs @@ -29,6 +29,7 @@ namespace StockInfoCore /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.lblTotalRecords = new System.Windows.Forms.Label(); this.gB1 = new System.Windows.Forms.GroupBox(); @@ -48,6 +49,8 @@ namespace StockInfoCore this.btnConnShares = new System.Windows.Forms.Button(); this.btnEditPerson = new System.Windows.Forms.Button(); 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(); this.gB1.SuspendLayout(); this.gbStockMgmnt.SuspendLayout(); @@ -60,11 +63,11 @@ namespace StockInfoCore | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); 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.Name = "dataGridView"; 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.SelectionChanged += new System.EventHandler(this.dataGridView_SelectionChanged); // @@ -243,15 +246,30 @@ namespace StockInfoCore this.cmbOwners.FormattingEnabled = true; this.cmbOwners.Location = new System.Drawing.Point(6, 33); 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.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 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(895, 538); + this.Controls.Add(this.pbInitial); this.Controls.Add(this.gpOwners); this.Controls.Add(this.lblStockRows); this.Controls.Add(this.gbStockMgmnt); @@ -296,6 +314,8 @@ namespace StockInfoCore private System.Windows.Forms.Button btnEditPerson; private System.Windows.Forms.ComboBox cmbOwners; private System.Windows.Forms.Button btnBackupAll; + private ProgressBar pbInitial; + private System.Windows.Forms.Timer tmrProgBar; } } diff --git a/StockInfoCore/frmInitial.cs b/StockInfoCore/frmInitial.cs index c86cf91..d7d861a 100644 --- a/StockInfoCore/frmInitial.cs +++ b/StockInfoCore/frmInitial.cs @@ -36,7 +36,8 @@ namespace StockInfoCore private readonly frmBackup _backupWindow; private readonly frmEditStock _editStock; bool loading = false; - + int progressValue = 0; + public int SelectedPersonId { get; set; } = 0; public frmInitial( @@ -83,13 +84,13 @@ namespace StockInfoCore btnBackupAll.Enabled = false; } - private void ReloadData(bool upd = false) + private async Task ReloadData(bool upd = false) { loading = true; var allStocks = _stockRepository.GetAllStocks(); if (upd) { - _stockMarketRepository.LoadStockMarketList(SelectedPersonId); + await _stockMarketRepository.LoadStockMarketListAsync(SelectedPersonId); allStocks.ToList().ForEach(SM => SM.ActValue = UpdateOnlyNonZeroAmount(SM).ActValue); } dataGridView.DataSource = allStocks; @@ -103,32 +104,36 @@ namespace StockInfoCore var output = new StockMember(); if (sMember.ActAmount > 0) { - if (_stockMarketRepository.StockMarketList.ContainsKey(sMember.StockId)){ + if (_stockMarketRepository.StockMarketList.ContainsKey(sMember.StockId)) + { sMember.ActValue = _stockMarketRepository.StockMarketList[sMember.StockId].LatestPrice; _stockRepository.UpdateActualPrice(sMember.Id, sMember.ActValue); } } - output=sMember; + output = sMember; return output; } - private void btnReload_Click(object sender, EventArgs e) + private async void btnReload_Click(object sender, EventArgs e) { - Cursor = Cursors.WaitCursor; - ReloadData(true); - Cursor=Cursors.Default; + StartProgressTicking(350); + await ReloadData(true); + 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) { Cursor.Current = Cursors.WaitCursor; - _stockMarketRepository.LoadStockMarketList(SelectedPersonId==0?10000: SelectedPersonId); + _stockMarketRepository.LoadStockMarketList(SelectedPersonId == 0 ? 10000 : SelectedPersonId); _regWindow.Stocks = _stockMarketRepository.StockMarketList; Cursor.Current = DefaultCursor; _regWindow.ShowDialog(); @@ -152,16 +157,15 @@ namespace StockInfoCore } else { + StartProgressTicking(); var person = _personRepository.GetPersonById(SelectedPersonId); - Cursor.Current = Cursors.WaitCursor; - + await _stockMarketRepository.LoadStockMarketListAsync(SelectedPersonId); - + StopProgressTicking(); _stockWindow.ConnectedPerson = person; _stockWindow.Stocks = _stockMarketRepository.StockMarketList; - Cursor.Current = DefaultCursor; - //GlobalStopwatch.Stop(); + //GlobalStopwatch.Stop(); //GlobalStopwatch.PrintSecs("Before Show Stockwindow"); _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; + } } } diff --git a/StockInfoCore/frmInitial.resx b/StockInfoCore/frmInitial.resx index 5e4a4cc..c9b74ac 100644 --- a/StockInfoCore/frmInitial.resx +++ b/StockInfoCore/frmInitial.resx @@ -63,7 +63,10 @@ 114, 17 + + 225, 17 + - 27 + 75 \ No newline at end of file diff --git a/StockInfoCore/frmSelling.cs b/StockInfoCore/frmSelling.cs index 8efbf33..3f4be1c 100644 --- a/StockInfoCore/frmSelling.cs +++ b/StockInfoCore/frmSelling.cs @@ -33,6 +33,7 @@ namespace StockInfoCore private void ReloadRemainingStocks() { if (selectedPersonId == 0) return; + lvSellCandidates.Items.Clear(); remainingStocks = _stockRepository.GetAllRemainingStocks(selectedPersonId).ToList(); foreach (var stock in remainingStocks) {