Edit stocklist. add stocks,

This commit is contained in:
2022-02-07 23:58:10 +01:00
parent b3d1a46c6c
commit d56e69b448
12 changed files with 87 additions and 43 deletions

BIN
StockInfoCore/Stocks.db-shm Normal file

Binary file not shown.

View File

View File

@ -58,6 +58,7 @@ namespace StockInfoCore
this.label1 = new System.Windows.Forms.Label();
this.txtStockName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.btnSaveNew = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
@ -306,11 +307,23 @@ namespace StockInfoCore
this.label3.TabIndex = 28;
this.label3.Text = "StockId";
//
// btnSaveNew
//
this.btnSaveNew.Location = new System.Drawing.Point(251, 414);
this.btnSaveNew.Name = "btnSaveNew";
this.btnSaveNew.Size = new System.Drawing.Size(80, 23);
this.btnSaveNew.TabIndex = 29;
this.btnSaveNew.Text = "SaveAsNew";
this.btnSaveNew.UseVisualStyleBackColor = true;
this.btnSaveNew.UseWaitCursor = true;
this.btnSaveNew.Click += new System.EventHandler(this.btnSaveNew_Click);
//
// frmEditStock
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(570, 452);
this.Controls.Add(this.btnSaveNew);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtStockName);
this.Controls.Add(this.groupBox1);
@ -377,5 +390,6 @@ namespace StockInfoCore
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtStockName;
private System.Windows.Forms.Label label3;
private Button btnSaveNew;
}
}

View File

@ -54,6 +54,7 @@ namespace StockInfoCore
private void LoadStockData()
{
var stockChosen = _stockRepository.GetStockMember(CurrentStockMember);
txtStockName.Text = stockChosen.StockId;
txtStockExtId.Text = stockChosen.StockExtId;
txtActValue.Text = stockChosen.ActValue.ToString();
//txtActDate.Text = (DateTime.Today + stockChosen.ActDate.Value.TimeOfDay).ToString();
@ -83,14 +84,14 @@ namespace StockInfoCore
txtBuyDate.Text = stockChosen.BuyDate.ToString(); // = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
txtActValue.Text = stockChosen.ActValue.ToString(); // = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
txtActAmount.Text = stockChosen.ActAmount.ToString(); // = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text);
txtSoldDate.Text = stockChosen.SoldDate.ToString(); // = null; //DateTime.MaxValue;
txtSoldDate.Text = stockChosen.SoldDate == DateTime.MinValue ? String.Empty : stockChosen.SoldDate.ToString(); // = null; //DateTime.MaxValue;
txtSoldPrice.Text = stockChosen.SoldValue.ToString(); // = decimal.Parse("0");
txtComment.Text = stockChosen.Comment;
}
private void AddValidateData()
private void AddValidateData(bool New)
{
var currentStock = new StockMember();
currentStock.StockId = txtStockName.Text.Trim();
@ -101,10 +102,15 @@ namespace StockInfoCore
currentStock.BuyDate = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
currentStock.ActAmount = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text);
currentStock.SoldDate = DateTime.Parse(txtSoldDate.Text);
currentStock.SoldDate = txtSoldDate.Text.Trim() == "" ? DateTime.MinValue : DateTime.Parse(txtSoldDate.Text);
currentStock.SoldValue = decimal.Parse(txtSoldPrice.Text);
currentStock.Comment = txtComment.Text;
currentStock.Comment = txtComment.Text.Length<1?String.Empty: txtComment.Text;
//RegisteredStocks.Add(currentStock);
if (!New)
{
currentStock.Id = CurrentStockMember;
}
try
{
_stockRepository.SaveStockMember(currentStock);
@ -119,6 +125,7 @@ namespace StockInfoCore
private void initiateRegWin()
{
txtStockName.Text = "";
txtStockExtId.Text = "";
txtBuyPrice.Text = "";
txtBuyDate.Text = "";
@ -133,7 +140,7 @@ namespace StockInfoCore
private void btnSaveToDB_Click(object sender, EventArgs e)
{
AddValidateData();
AddValidateData(false);
}
private void txtBoughtAmount_TextChanged(object sender, EventArgs e)
@ -149,5 +156,10 @@ namespace StockInfoCore
e.DrawText();
}
}
private void btnSaveNew_Click(object sender, EventArgs e)
{
AddValidateData(true);
}
}
}

View File

@ -34,7 +34,7 @@ namespace StockInfoCore
private readonly frmPerson _personWindow;
private readonly frmPersonShareConnect _personShareConnect;
private readonly frmBackup _backupWindow;
private readonly frmEditStock _editStock;
bool loading = false;
//private frmRegisterStock regWindow;
//private frmMyStocks stockWindow;
@ -58,7 +58,8 @@ namespace StockInfoCore
frmSelling sellWindow,
frmPerson personWindow,
frmPersonShareConnect personShareConnect,
frmBackup backupWindow
frmBackup backupWindow,
frmEditStock editStock
)
{
InitializeComponent();
@ -76,6 +77,7 @@ namespace StockInfoCore
_personWindow = personWindow;
_personShareConnect = personShareConnect;
_backupWindow = backupWindow;
_editStock = editStock;
}
private void Form1_Load(object sender, EventArgs e)
@ -141,9 +143,9 @@ namespace StockInfoCore
private void btnValueView_Click(object sender, EventArgs e)
{
if(!GlobalStopwatch.IsRunning && GlobalStopwatch.EllapsedMillis>0)
GlobalStopwatch.Restart();
else GlobalStopwatch.Start();
//if(!GlobalStopwatch.IsRunning && GlobalStopwatch.EllapsedMillis>0)
// GlobalStopwatch.Restart();
//else GlobalStopwatch.Start();
if (SelectedPersonId == 0)
{
@ -159,8 +161,8 @@ namespace StockInfoCore
_stockWindow.Stocks = _stockMarketRepository.StockMarketList;
Cursor.Current = DefaultCursor;
GlobalStopwatch.Stop();
GlobalStopwatch.PrintSecs("Before Show Stockwindow");
//GlobalStopwatch.Stop();
//GlobalStopwatch.PrintSecs("Before Show Stockwindow");
_stockWindow.ShowDialog();
}
}
@ -272,7 +274,7 @@ namespace StockInfoCore
private void btnBackupAll_Click(object sender, EventArgs e)
{
// backupWindow = new frmBackup(_backupRepository, _backupRoutines);
// backupWindow = new frmBackup(_backupRepository, _backupRoutines);
_backupWindow.ShowDialog();
}
@ -282,7 +284,11 @@ namespace StockInfoCore
{
//MessageBox.Show($"{((DataGridView)sender).SelectedRows.ToString()} eventargs = {e.ToString()}" );
int id = Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells[0].Value);
MessageBox.Show($"Vald rads id = {id}");
if (DialogResult.OK == MessageBox.Show($"Vald rads id = {id}{Environment.NewLine}Ändra ?", "Fråga", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
{
_editStock.CurrentStockMember = id;
_editStock.ShowDialog();
};
}
}
}

View File

@ -73,7 +73,7 @@ namespace StockInfoCore
}
lblOwnerName.Text = $"* {ConnectedPerson.FirstName} {ConnectedPerson.LastName} *";
GlobalStopwatch.PrintSecs("In reload (New window)");
//GlobalStopwatch.PrintSecs("In reload (New window)");
txtBuyTotal.Text = BoughtSum.ToString();
txtBuyTotal.Refresh();

View File

@ -62,6 +62,7 @@ namespace StockInfoCore
PersonStock ps = new PersonStock();
ps.PersonId = ConnectPerson.Id;
ps.StockId = int.Parse(lstShares.SelectedValue.ToString());
ps.Comment = String.Empty;
_stockPersonConnect.SavePersonStockConnection(ps);
RefreshShareList();
RefreshConnectedList();