Sync checkin
This commit is contained in:
@ -7,5 +7,6 @@ namespace StockHistory.Services
|
||||
Task GenerateStockVision();
|
||||
Task<List<StockEquity>> GetAllAsync();
|
||||
Task<List<StockEquity>> GetAllAsync(DateTime equityDate);
|
||||
Task<List<StockEquity>> GetByCodeAsync(string stockCode);
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ namespace StockHistory.Services
|
||||
Task DeleteAsync(int id);
|
||||
Task<List<TransactionNote>> GetAllAsync();
|
||||
Task<TransactionNote?> GetByIdAsync(int id);
|
||||
Task<List<TransactionNote>> GetByStockCodeAsync(string stockCode);
|
||||
Task UpdateAsync(TransactionNote transactionNote);
|
||||
}
|
||||
}
|
||||
@ -25,6 +25,22 @@ public class StockEquityServices : IStockEquityServices
|
||||
.Where(s => s.Bought <= equityDate && (s.Sold > equityDate || s.SoldQuant == 0))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<StockEquity>> GetByCodeAsync(string stockCode)
|
||||
{
|
||||
var searchedNotes = await _notesServices.GetByStockCodeAsync(stockCode);
|
||||
|
||||
return await _dbContext.Stocks
|
||||
.Where(s => s.StockCode == stockCode)
|
||||
.OrderBy(s => s.Bought)
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// Skapar en ny lista med aktieinnehav baserat på transaktionsnoteringar.
|
||||
/// Den rensar först den befintliga listan och bygger sedan upp den igen genom att
|
||||
/// utgående från alla befintliga notor skapa en lista med aktieinnehav.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task GenerateStockVision()
|
||||
{
|
||||
|
||||
@ -33,12 +49,24 @@ public class StockEquityServices : IStockEquityServices
|
||||
|
||||
var existingNotes = await _notesServices.GetAllAsync();
|
||||
|
||||
foreach (var note in existingNotes.OrderBy(e => e.TransactionDate).ToList())
|
||||
foreach (var note in existingNotes
|
||||
.OrderByDescending(e => e.TransactionType)
|
||||
.OrderBy(e => e.TransactionDate)
|
||||
.ToList())
|
||||
{
|
||||
// Kontrollera om TransactionType är null och StockCode inte är null
|
||||
// (om det är fallet, hoppa över denna iteration)
|
||||
|
||||
if (note.TransactionType == null && note.StockCode != null) { }
|
||||
else
|
||||
|
||||
// Kontrollera om TransactionType är en köpnotering
|
||||
// (ignorera null-värden)
|
||||
|
||||
if (note.TransactionType.ToLower() == "köp")
|
||||
{
|
||||
// Skapa en ny aktieinnehavspost baserat på köpnoteringen
|
||||
|
||||
var equity = new StockEquity
|
||||
{
|
||||
StockCode = note.StockCode,
|
||||
@ -52,9 +80,14 @@ public class StockEquityServices : IStockEquityServices
|
||||
_dbContext.Stocks.Add(equity);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// Kontrollera om TransactionType är en säljnotering
|
||||
|
||||
else if (note.TransactionType.ToLower() == "sälj" || note.TransactionType.ToLower() == "försäljning")
|
||||
{
|
||||
var equityList = await _dbContext.Stocks.Where(s => s.StockCode == note.StockCode && s.SoldQuant == 0).OrderBy(s => s.Quantity).ToListAsync();
|
||||
var equityList = await _dbContext.Stocks
|
||||
.Where(s => s.StockCode == note.StockCode && s.SoldQuant == 0)
|
||||
.OrderBy(s => s.Quantity).ToListAsync();
|
||||
|
||||
if (equityList != null)
|
||||
{
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
using StockHistory.Data;
|
||||
using StockHistory.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using StockHistory.Data;
|
||||
using StockHistory.Models;
|
||||
|
||||
namespace StockHistory.Services;
|
||||
|
||||
@ -33,6 +28,16 @@ public class TransactionNotesServices : ITransactionNotesServices
|
||||
return await _dbContext.TransactionNotes.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<List<TransactionNote>> GetByStockCodeAsync(string stockCode)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stockCode))
|
||||
{
|
||||
return new List<TransactionNote>();
|
||||
}
|
||||
|
||||
return await _dbContext.TransactionNotes.Where(t => t.StockCode == stockCode).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task AddAsync(TransactionNote transactionNote)
|
||||
{
|
||||
using var scope = _provider.CreateScope();
|
||||
|
||||
78
StockHistory/frmStockHistoryAnalyse.Designer.cs
generated
78
StockHistory/frmStockHistoryAnalyse.Designer.cs
generated
@ -37,8 +37,16 @@
|
||||
chBought = new ColumnHeader();
|
||||
chPrize = new ColumnHeader();
|
||||
chNumber = new ColumnHeader();
|
||||
lblTotalValue = new Label();
|
||||
chValue = new ColumnHeader();
|
||||
lblTotalValue = new Label();
|
||||
lwStockHistory = new ListView();
|
||||
histDatum = new ColumnHeader();
|
||||
histKöptSålt = new ColumnHeader();
|
||||
histAntal = new ColumnHeader();
|
||||
histPris = new ColumnHeader();
|
||||
histTotBelopp = new ColumnHeader();
|
||||
columnHeader1 = new ColumnHeader();
|
||||
btnStockHistory = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// lblHistAnalyseHeader
|
||||
@ -67,7 +75,7 @@
|
||||
//
|
||||
// dtpChosenDate
|
||||
//
|
||||
dtpChosenDate.Location = new Point(507, 67);
|
||||
dtpChosenDate.Location = new Point(588, 67);
|
||||
dtpChosenDate.Name = "dtpChosenDate";
|
||||
dtpChosenDate.Size = new Size(200, 23);
|
||||
dtpChosenDate.TabIndex = 2;
|
||||
@ -78,7 +86,7 @@
|
||||
btnClose.BackColor = Color.Chartreuse;
|
||||
btnClose.FlatStyle = FlatStyle.Popup;
|
||||
btnClose.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point, 1, true);
|
||||
btnClose.Location = new Point(680, 411);
|
||||
btnClose.Location = new Point(680, 481);
|
||||
btnClose.Margin = new Padding(3, 2, 3, 2);
|
||||
btnClose.Name = "btnClose";
|
||||
btnClose.Size = new Size(108, 28);
|
||||
@ -90,9 +98,9 @@
|
||||
// lwStocks
|
||||
//
|
||||
lwStocks.Columns.AddRange(new ColumnHeader[] { chStock, chBought, chPrize, chNumber, chValue });
|
||||
lwStocks.Location = new Point(31, 110);
|
||||
lwStocks.Location = new Point(111, 103);
|
||||
lwStocks.Name = "lwStocks";
|
||||
lwStocks.Size = new Size(676, 172);
|
||||
lwStocks.Size = new Size(676, 154);
|
||||
lwStocks.TabIndex = 9;
|
||||
lwStocks.UseCompatibleStateImageBehavior = false;
|
||||
lwStocks.View = View.Details;
|
||||
@ -117,6 +125,10 @@
|
||||
chNumber.Text = "Antal";
|
||||
chNumber.Width = 100;
|
||||
//
|
||||
// chValue
|
||||
//
|
||||
chValue.Text = "Total";
|
||||
//
|
||||
// lblTotalValue
|
||||
//
|
||||
lblTotalValue.AutoSize = true;
|
||||
@ -126,15 +138,57 @@
|
||||
lblTotalValue.TabIndex = 10;
|
||||
lblTotalValue.Text = "...";
|
||||
//
|
||||
// chValue
|
||||
// lwStockHistory
|
||||
//
|
||||
chValue.Text = "Total";
|
||||
lwStockHistory.Columns.AddRange(new ColumnHeader[] { histDatum, histKöptSålt, histAntal, histPris, histTotBelopp, columnHeader1 });
|
||||
lwStockHistory.Location = new Point(113, 311);
|
||||
lwStockHistory.Name = "lwStockHistory";
|
||||
lwStockHistory.Size = new Size(676, 153);
|
||||
lwStockHistory.TabIndex = 11;
|
||||
lwStockHistory.UseCompatibleStateImageBehavior = false;
|
||||
lwStockHistory.View = View.Details;
|
||||
//
|
||||
// histDatum
|
||||
//
|
||||
histDatum.Text = "Datum";
|
||||
//
|
||||
// histKöptSålt
|
||||
//
|
||||
histKöptSålt.Text = "Köpt/Sålt";
|
||||
//
|
||||
// histAntal
|
||||
//
|
||||
histAntal.Text = "Antal";
|
||||
//
|
||||
// histPris
|
||||
//
|
||||
histPris.Text = "Betalt/Erhållit";
|
||||
//
|
||||
// histTotBelopp
|
||||
//
|
||||
histTotBelopp.Text = "Summa";
|
||||
//
|
||||
// btnStockHistory
|
||||
//
|
||||
btnStockHistory.BackColor = Color.Chartreuse;
|
||||
btnStockHistory.FlatStyle = FlatStyle.Flat;
|
||||
btnStockHistory.Font = new Font("Segoe UI", 11F, FontStyle.Bold);
|
||||
btnStockHistory.ImageAlign = ContentAlignment.MiddleLeft;
|
||||
btnStockHistory.Location = new Point(29, 269);
|
||||
btnStockHistory.Name = "btnStockHistory";
|
||||
btnStockHistory.Size = new Size(139, 29);
|
||||
btnStockHistory.TabIndex = 12;
|
||||
btnStockHistory.Text = "Stockhistory";
|
||||
btnStockHistory.UseVisualStyleBackColor = false;
|
||||
btnStockHistory.Click += btnStockHistory_Click;
|
||||
//
|
||||
// frmStockHistoryAnalyse
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(818, 520);
|
||||
Controls.Add(btnStockHistory);
|
||||
Controls.Add(lwStockHistory);
|
||||
Controls.Add(lblTotalValue);
|
||||
Controls.Add(lwStocks);
|
||||
Controls.Add(btnClose);
|
||||
@ -160,5 +214,13 @@
|
||||
private ColumnHeader chNumber;
|
||||
private Label lblTotalValue;
|
||||
private ColumnHeader chValue;
|
||||
private ListView lwStockHistory;
|
||||
private Button btnStockHistory;
|
||||
private ColumnHeader histDatum;
|
||||
private ColumnHeader histKöptSålt;
|
||||
private ColumnHeader histAntal;
|
||||
private ColumnHeader histPris;
|
||||
private ColumnHeader histTotBelopp;
|
||||
private ColumnHeader columnHeader1;
|
||||
}
|
||||
}
|
||||
@ -95,4 +95,9 @@ public partial class frmStockHistoryAnalyse : Form
|
||||
LoadStockListAsync(dtpChosenDate.Value).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnStockHistory_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,8 +327,6 @@ public partial class frmStockHistoryInit : Form
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
txtFound.Text = SortLines(tempStr);
|
||||
txtFound.Refresh();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user