diff --git a/BrowserHelper/Extensions/HtmlTableExtension.cs b/BrowserHelper/Extensions/HtmlTableExtension.cs
index ed1bf6c..8cad648 100644
--- a/BrowserHelper/Extensions/HtmlTableExtension.cs
+++ b/BrowserHelper/Extensions/HtmlTableExtension.cs
@@ -1,12 +1,6 @@
using DataDomain;
-using Helpers;
using OpenQA.Selenium;
-using System;
using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace BrowserHelper.Extensions
{
@@ -86,14 +80,14 @@ namespace BrowserHelper.Extensions
IWebElement tblBody = table.FindElement(By.XPath(".//tbody"));
var rows = tblBody.FindElements(By.TagName("tr"));
Dictionary columnPos = new Dictionary();
- GlobalStopwatch.PrintSecs("After allocations");
+ //GlobalStopwatch.PrintSecs("After allocations");
for (int i = 0; i < columns.Count; i++)
{
if (shareHeaders.Contains(columns[i].Text)) columnPos.Add(columns[i].Text, i);
}
var antal = shares.Length;
int rowIndex = 0;
- GlobalStopwatch.PrintSecs("Before scraplooping");
+ //GlobalStopwatch.PrintSecs("Before scraplooping");
foreach (var row in rows)
{
var element = row.FindElement(By.XPath(".//td"));
@@ -116,7 +110,7 @@ namespace BrowserHelper.Extensions
}
if (antal < 1) break;
}
- GlobalStopwatch.PrintSecs("After scraplooping");
+ //GlobalStopwatch.PrintSecs("After scraplooping");
return shareCollection;
}
diff --git a/BrowserHelper/Extensions/WebDriverInitializerExtension.cs b/BrowserHelper/Extensions/WebDriverInitializerExtension.cs
index cb1c7d5..cc45e30 100644
--- a/BrowserHelper/Extensions/WebDriverInitializerExtension.cs
+++ b/BrowserHelper/Extensions/WebDriverInitializerExtension.cs
@@ -1,6 +1,4 @@
-using BrowserHelper.Driver;
-using Microsoft.Extensions.DependencyInjection;
-using System.IO;
+using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
diff --git a/DatamodelLibrary/StockContext.cs b/DatamodelLibrary/StockContext.cs
index 098df71..fad847f 100644
--- a/DatamodelLibrary/StockContext.cs
+++ b/DatamodelLibrary/StockContext.cs
@@ -18,6 +18,6 @@ namespace DatamodelLibrary
public DbSet StockGroups { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
- => options.UseSqlite("Data Source=Stocks.db");
+ => options.UseSqlite(@"Data Source=.\Stocks.db");
}
}
diff --git a/StockDAL/StockMarketRepository.cs b/StockDAL/StockMarketRepository.cs
index 6c3c21c..c5848e3 100644
--- a/StockDAL/StockMarketRepository.cs
+++ b/StockDAL/StockMarketRepository.cs
@@ -246,10 +246,9 @@ namespace StockDal
{
StockMarketList = new Dictionary();
DumpObjects = new List();
- GlobalStopwatch.PrintSecs("After dictionaries setup ");
- //var connStocks = _stockPersonConnect.GetAllConnectionsByPersId(persId);
+ //GlobalStopwatch.PrintSecs("After dictionaries setup ");
var groupedStocks = _stockRepository.GetStocksGroupedPerPerson(persId);
- GlobalStopwatch.PrintSecs("After groupedStocks fetched ");
+ //GlobalStopwatch.PrintSecs("After groupedStocks fetched ");
var lastGroup = string.Empty;
var stockList = new List();
@@ -261,9 +260,9 @@ namespace StockDal
{
_testSettings.StockWishes = stockList.ToArray();
stockList.Clear();
- GlobalStopwatch.PrintSecs("Before GetStockStatus");
+ //GlobalStopwatch.PrintSecs("Before GetStockStatus");
saveStockData( _scrapePage.GetMyStockStatus(lastGroup));
- GlobalStopwatch.PrintSecs("After GetStockStatus");
+ //GlobalStopwatch.PrintSecs("After GetStockStatus");
lastGroup = groupedStock.StockGroup;
}
else
@@ -286,14 +285,6 @@ namespace StockDal
saveStockData(_scrapePage.GetMyStockStatus(lastGroup));
}
- //OpenBrowser(null);
- //Find_Data();
- //OpenBrowser();
- //Find_Data();
- //OpenBrowser(true);
- //Find_Data();
-
-
if (DumpObjects.Any())
{
SaveLogging();
diff --git a/StockDAL/StockRepository.cs b/StockDAL/StockRepository.cs
index 3710298..29abfff 100644
--- a/StockDAL/StockRepository.cs
+++ b/StockDAL/StockRepository.cs
@@ -15,7 +15,35 @@ namespace StockDAL
{
using (var context = new StockContext())
{
- var sm = context.Stocks.Add(stockMember);
+ if (stockMember.Id > 0)
+ {
+ var entity = (from stk in context.Stocks
+ where stk.Id == stockMember.Id
+ select stk).FirstOrDefault();
+ if (entity != null)
+ {
+ entity.StockId = stockMember.StockId;
+ entity.StockExtId = stockMember.StockExtId;
+ entity.ActValue = stockMember.ActValue;
+ entity.ActAmount= stockMember.ActAmount;
+ entity.SoldDate = stockMember.SoldDate;
+ entity.ActDate = stockMember.ActDate;
+ entity.SoldStockPrice = stockMember.SoldStockPrice;
+ entity.SoldValue = stockMember.SoldValue;
+ entity.PostAmount = stockMember.PostAmount;
+ entity.Comment = stockMember.Comment;
+ entity.BuyDate = stockMember.BuyDate;
+ entity.BuyValue = stockMember.BuyValue;
+ }
+ else
+ {
+ var sm = context.Stocks.Add(stockMember);
+ }
+ }
+ else
+ {
+ var sm = context.Stocks.Add(stockMember);
+ }
context.SaveChanges();
}
}
@@ -111,7 +139,7 @@ namespace StockDAL
join stk in context.Stocks on prs.StockId equals stk.Id
join grp in context.StockGroups on stk.StockId equals grp.StockName
where prs.PersonId == persId
- orderby grp.GroupName, grp.StockName
+ orderby grp.GroupName, grp.StockName
select new StockGrpPers
{
PersId = persId,
diff --git a/StockInfoCore/Stocks.db-shm b/StockInfoCore/Stocks.db-shm
new file mode 100644
index 0000000..fe9ac28
Binary files /dev/null and b/StockInfoCore/Stocks.db-shm differ
diff --git a/StockInfoCore/Stocks.db-wal b/StockInfoCore/Stocks.db-wal
new file mode 100644
index 0000000..e69de29
diff --git a/StockInfoCore/frmEditStock.Designer.cs b/StockInfoCore/frmEditStock.Designer.cs
index dad1b6c..4804265 100644
--- a/StockInfoCore/frmEditStock.Designer.cs
+++ b/StockInfoCore/frmEditStock.Designer.cs
@@ -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;
}
}
\ No newline at end of file
diff --git a/StockInfoCore/frmEditStock.cs b/StockInfoCore/frmEditStock.cs
index 1a46ffd..cca1680 100644
--- a/StockInfoCore/frmEditStock.cs
+++ b/StockInfoCore/frmEditStock.cs
@@ -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);
+ }
}
}
diff --git a/StockInfoCore/frmInitial.cs b/StockInfoCore/frmInitial.cs
index d84145b..34c0c6d 100644
--- a/StockInfoCore/frmInitial.cs
+++ b/StockInfoCore/frmInitial.cs
@@ -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();
+ };
}
}
}
diff --git a/StockInfoCore/frmMyStocks.cs b/StockInfoCore/frmMyStocks.cs
index 39522fe..5f18db7 100644
--- a/StockInfoCore/frmMyStocks.cs
+++ b/StockInfoCore/frmMyStocks.cs
@@ -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();
diff --git a/StockInfoCore/frmPersonShareConnect.cs b/StockInfoCore/frmPersonShareConnect.cs
index 58bd735..9153c9e 100644
--- a/StockInfoCore/frmPersonShareConnect.cs
+++ b/StockInfoCore/frmPersonShareConnect.cs
@@ -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();