diff --git a/Helpers/Helpers.csproj b/Helpers/Helpers.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/Helpers/Helpers.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/Helpers/StringExtensions.cs b/Helpers/StringExtensions.cs new file mode 100644 index 0000000..b8978fc --- /dev/null +++ b/Helpers/StringExtensions.cs @@ -0,0 +1,13 @@ +using System; +using System.Globalization; + +namespace Helpers +{ + public static class StringExtensions + { + public static bool IsNumeric(this string s) + { + return float.TryParse(s, NumberStyles.Float | NumberStyles.Integer, CultureInfo.CurrentUICulture, out _); + } + } +} diff --git a/StockDBEFApp.sln b/StockDBEFApp.sln index 47568ef..01c6cad 100644 --- a/StockDBEFApp.sln +++ b/StockDBEFApp.sln @@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatamodelLibrary", "Datamod EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataDomain", "DataDomain\DataDomain.csproj", "{D8057A61-F1CE-4467-9F9E-5E1DA180B3C4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDAL", "StockDAL\StockDAL.csproj", "{E84394CB-98B8-48C0-A65F-008BC97E34A3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDAL", "StockDAL\StockDAL.csproj", "{E84394CB-98B8-48C0-A65F-008BC97E34A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDAL.Interface", "StockDal.Interface\StockDAL.Interface.csproj", "{7B0D0A18-D071-40ED-8788-120D432D16D8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDAL.Interface", "StockDal.Interface\StockDAL.Interface.csproj", "{7B0D0A18-D071-40ED-8788-120D432D16D8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockInfo", "StockInfo\StockInfo.csproj", "{EC122B56-FCE0-4BBD-956D-7BF46D617CF8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockInfo", "StockInfo\StockInfo.csproj", "{EC122B56-FCE0-4BBD-956D-7BF46D617CF8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Helpers", "Helpers\Helpers.csproj", "{5FEE920E-07B8-4185-A41F-1587643ECC26}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Debug|Any CPU.Build.0 = Debug|Any CPU {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Release|Any CPU.ActiveCfg = Release|Any CPU {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Release|Any CPU.Build.0 = Release|Any CPU + {5FEE920E-07B8-4185-A41F-1587643ECC26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5FEE920E-07B8-4185-A41F-1587643ECC26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5FEE920E-07B8-4185-A41F-1587643ECC26}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5FEE920E-07B8-4185-A41F-1587643ECC26}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/StockInfo/StockInfo.csproj b/StockInfo/StockInfo.csproj index 3e2f4ca..35bf22d 100644 --- a/StockInfo/StockInfo.csproj +++ b/StockInfo/StockInfo.csproj @@ -1,4 +1,4 @@ - + WinExe @@ -25,6 +25,7 @@ + diff --git a/StockInfo/Stocks.db-shm b/StockInfo/Stocks.db-shm new file mode 100644 index 0000000..0fff49c Binary files /dev/null and b/StockInfo/Stocks.db-shm differ diff --git a/StockInfo/Stocks.db-wal b/StockInfo/Stocks.db-wal new file mode 100644 index 0000000..1bfc2f4 Binary files /dev/null and b/StockInfo/Stocks.db-wal differ diff --git a/StockInfo/frmInitial.Designer.cs b/StockInfo/frmInitial.Designer.cs index 0a67429..d6cc060 100644 --- a/StockInfo/frmInitial.Designer.cs +++ b/StockInfo/frmInitial.Designer.cs @@ -40,6 +40,7 @@ namespace StockInfo this.gbStockMgmnt = new System.Windows.Forms.GroupBox(); this.btnValueView = new System.Windows.Forms.Button(); this.btnStockReg = new System.Windows.Forms.Button(); + this.btnStockSale = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.gB1.SuspendLayout(); this.gbStockMgmnt.SuspendLayout(); @@ -126,6 +127,7 @@ namespace StockInfo // // gbStockMgmnt // + this.gbStockMgmnt.Controls.Add(this.btnStockSale); this.gbStockMgmnt.Controls.Add(this.btnValueView); this.gbStockMgmnt.Controls.Add(this.btnStockReg); this.gbStockMgmnt.Location = new System.Drawing.Point(411, 411); @@ -154,6 +156,16 @@ namespace StockInfo this.btnStockReg.UseVisualStyleBackColor = true; this.btnStockReg.Click += new System.EventHandler(this.btnStockReg_Click); // + // btnStockSale + // + this.btnStockSale.Location = new System.Drawing.Point(108, 9); + this.btnStockSale.Name = "btnStockSale"; + this.btnStockSale.Size = new System.Drawing.Size(96, 23); + this.btnStockSale.TabIndex = 2; + this.btnStockSale.Text = "Stock Sell"; + this.btnStockSale.UseVisualStyleBackColor = true; + this.btnStockSale.Click += new System.EventHandler(this.btnStockSale_Click); + // // frmInitial // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -194,6 +206,7 @@ namespace StockInfo private System.Windows.Forms.GroupBox gbStockMgmnt; private System.Windows.Forms.Button btnStockReg; private System.Windows.Forms.Button btnValueView; + private System.Windows.Forms.Button btnStockSale; } } diff --git a/StockInfo/frmInitial.cs b/StockInfo/frmInitial.cs index dca3911..8870ded 100644 --- a/StockInfo/frmInitial.cs +++ b/StockInfo/frmInitial.cs @@ -20,6 +20,7 @@ namespace StockInfo private frmRegisterStock regWindow; private frmMyStocks stockWindow; + private frmSelling sellWindow; public frmInitial(IStockRepository stockMemberRepository, IStockMarketRepository stockMarketRepository) { @@ -102,6 +103,8 @@ namespace StockInfo regWindow.ShowDialog(); _stockRepository.InsertMany(regWindow.RegisteredStocks); + + ReloadData(); } private void btnValueView_Click(object sender, EventArgs e) @@ -113,5 +116,15 @@ namespace StockInfo Cursor.Current = DefaultCursor; stockWindow.ShowDialog(); } + + private void btnStockSale_Click(object sender, EventArgs e) + { + Cursor.Current = Cursors.WaitCursor; + sellWindow = new frmSelling(_stockRepository); + Cursor.Current = DefaultCursor; + sellWindow.ShowDialog(); + + ReloadData(); + } } } diff --git a/StockInfo/frmRegisterStock.cs b/StockInfo/frmRegisterStock.cs index 804c4a2..6fdef69 100644 --- a/StockInfo/frmRegisterStock.cs +++ b/StockInfo/frmRegisterStock.cs @@ -86,6 +86,7 @@ namespace StockInfo currentStock.ActDate = DateTime.Parse(txtActDate.Text); 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 = null; //DateTime.MaxValue; currentStock.SoldValue = decimal.Parse("0"); currentStock.Comment = txtComment.Text; diff --git a/StockInfo/frmSelling.Designer.cs b/StockInfo/frmSelling.Designer.cs new file mode 100644 index 0000000..333d05d --- /dev/null +++ b/StockInfo/frmSelling.Designer.cs @@ -0,0 +1,415 @@ + +namespace StockInfo +{ + partial class frmSelling + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lvSellCandidates = new System.Windows.Forms.ListView(); + this.StockName = new System.Windows.Forms.ColumnHeader(); + this.Buydate = new System.Windows.Forms.ColumnHeader(); + this.BuyPrice = new System.Windows.Forms.ColumnHeader(); + this.LeftNumber = new System.Windows.Forms.ColumnHeader(); + this.ActPrice = new System.Windows.Forms.ColumnHeader(); + this.TotalValue = new System.Windows.Forms.ColumnHeader(); + this.gbInfo = new System.Windows.Forms.GroupBox(); + this.txtBuyValue = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.txtBuyPrice = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.txtBuyNumber = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtBuyDate = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtStockId = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtId = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.gbSell = new System.Windows.Forms.GroupBox(); + this.btnConfirm = new System.Windows.Forms.Button(); + this.txtRemainingNo = new System.Windows.Forms.TextBox(); + this.label11 = new System.Windows.Forms.Label(); + this.txtSellValue = new System.Windows.Forms.TextBox(); + this.label10 = new System.Windows.Forms.Label(); + this.txtSoldAmount = new System.Windows.Forms.TextBox(); + this.label9 = new System.Windows.Forms.Label(); + this.txtSoldPrice = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.txtSoldDate = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.gbInfo.SuspendLayout(); + this.gbSell.SuspendLayout(); + this.SuspendLayout(); + // + // lvSellCandidates + // + this.lvSellCandidates.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.StockName, + this.Buydate, + this.BuyPrice, + this.LeftNumber, + this.ActPrice, + this.TotalValue}); + this.lvSellCandidates.FullRowSelect = true; + this.lvSellCandidates.HideSelection = false; + this.lvSellCandidates.Location = new System.Drawing.Point(13, 13); + this.lvSellCandidates.MultiSelect = false; + this.lvSellCandidates.Name = "lvSellCandidates"; + this.lvSellCandidates.Size = new System.Drawing.Size(519, 128); + this.lvSellCandidates.TabIndex = 0; + this.lvSellCandidates.UseCompatibleStateImageBehavior = false; + this.lvSellCandidates.View = System.Windows.Forms.View.Details; + this.lvSellCandidates.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSellCandidates_MouseUp); + // + // StockName + // + this.StockName.Name = "StockName"; + this.StockName.Text = "StockId"; + this.StockName.Width = 80; + // + // Buydate + // + this.Buydate.Name = "Buydate"; + this.Buydate.Text = "Date of Buy"; + this.Buydate.Width = 80; + // + // BuyPrice + // + this.BuyPrice.Name = "BuyPrice"; + this.BuyPrice.Text = "Price per stock"; + this.BuyPrice.Width = 80; + // + // LeftNumber + // + this.LeftNumber.Name = "LeftNumber"; + this.LeftNumber.Text = "Remaining Nr"; + this.LeftNumber.Width = 80; + // + // ActPrice + // + this.ActPrice.Name = "ActPrice"; + this.ActPrice.Text = "Price today"; + this.ActPrice.Width = 80; + // + // TotalValue + // + this.TotalValue.Name = "TotalValue"; + this.TotalValue.Text = "Value Today"; + this.TotalValue.Width = 80; + // + // gbInfo + // + this.gbInfo.Controls.Add(this.txtBuyValue); + this.gbInfo.Controls.Add(this.label6); + this.gbInfo.Controls.Add(this.txtBuyPrice); + this.gbInfo.Controls.Add(this.label5); + this.gbInfo.Controls.Add(this.txtBuyNumber); + this.gbInfo.Controls.Add(this.label4); + this.gbInfo.Controls.Add(this.txtBuyDate); + this.gbInfo.Controls.Add(this.label3); + this.gbInfo.Controls.Add(this.txtStockId); + this.gbInfo.Controls.Add(this.label2); + this.gbInfo.Controls.Add(this.txtId); + this.gbInfo.Controls.Add(this.label1); + this.gbInfo.Location = new System.Drawing.Point(13, 170); + this.gbInfo.Name = "gbInfo"; + this.gbInfo.Size = new System.Drawing.Size(276, 216); + this.gbInfo.TabIndex = 1; + this.gbInfo.TabStop = false; + this.gbInfo.Text = "Actual Stock"; + // + // txtBuyValue + // + this.txtBuyValue.Location = new System.Drawing.Point(116, 165); + this.txtBuyValue.Name = "txtBuyValue"; + this.txtBuyValue.ReadOnly = true; + this.txtBuyValue.Size = new System.Drawing.Size(73, 23); + this.txtBuyValue.TabIndex = 11; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(7, 168); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(58, 15); + this.label6.TabIndex = 10; + this.label6.Text = "Buy value"; + // + // txtBuyPrice + // + this.txtBuyPrice.Location = new System.Drawing.Point(116, 136); + this.txtBuyPrice.Name = "txtBuyPrice"; + this.txtBuyPrice.ReadOnly = true; + this.txtBuyPrice.Size = new System.Drawing.Size(73, 23); + this.txtBuyPrice.TabIndex = 9; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(7, 139); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(56, 15); + this.label5.TabIndex = 8; + this.label5.Text = "Buy price"; + // + // txtBuyNumber + // + this.txtBuyNumber.Location = new System.Drawing.Point(116, 107); + this.txtBuyNumber.Name = "txtBuyNumber"; + this.txtBuyNumber.ReadOnly = true; + this.txtBuyNumber.Size = new System.Drawing.Size(73, 23); + this.txtBuyNumber.TabIndex = 7; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(7, 110); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(93, 15); + this.label4.TabIndex = 6; + this.label4.Text = "Bought Number"; + // + // txtBuyDate + // + this.txtBuyDate.Location = new System.Drawing.Point(116, 78); + this.txtBuyDate.Name = "txtBuyDate"; + this.txtBuyDate.ReadOnly = true; + this.txtBuyDate.Size = new System.Drawing.Size(73, 23); + this.txtBuyDate.TabIndex = 5; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(7, 81); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(72, 15); + this.label3.TabIndex = 4; + this.label3.Text = "Bought date"; + // + // txtStockId + // + this.txtStockId.Location = new System.Drawing.Point(116, 49); + this.txtStockId.Name = "txtStockId"; + this.txtStockId.ReadOnly = true; + this.txtStockId.Size = new System.Drawing.Size(154, 23); + this.txtStockId.TabIndex = 3; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(7, 52); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(49, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Stock Id"; + // + // txtId + // + this.txtId.Location = new System.Drawing.Point(116, 20); + this.txtId.Name = "txtId"; + this.txtId.ReadOnly = true; + this.txtId.Size = new System.Drawing.Size(73, 23); + this.txtId.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(7, 23); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(48, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Local Id"; + // + // gbSell + // + this.gbSell.Controls.Add(this.btnConfirm); + this.gbSell.Controls.Add(this.txtRemainingNo); + this.gbSell.Controls.Add(this.label11); + this.gbSell.Controls.Add(this.txtSellValue); + this.gbSell.Controls.Add(this.label10); + this.gbSell.Controls.Add(this.txtSoldAmount); + this.gbSell.Controls.Add(this.label9); + this.gbSell.Controls.Add(this.txtSoldPrice); + this.gbSell.Controls.Add(this.label8); + this.gbSell.Controls.Add(this.txtSoldDate); + this.gbSell.Controls.Add(this.label7); + this.gbSell.Location = new System.Drawing.Point(296, 170); + this.gbSell.Name = "gbSell"; + this.gbSell.Size = new System.Drawing.Size(236, 216); + this.gbSell.TabIndex = 2; + this.gbSell.TabStop = false; + this.gbSell.Text = "Sell decision"; + // + // btnConfirm + // + this.btnConfirm.Location = new System.Drawing.Point(121, 165); + this.btnConfirm.Name = "btnConfirm"; + this.btnConfirm.Size = new System.Drawing.Size(75, 23); + this.btnConfirm.TabIndex = 12; + this.btnConfirm.Text = "Confirm"; + this.btnConfirm.UseVisualStyleBackColor = true; + // + // txtRemainingNo + // + this.txtRemainingNo.Location = new System.Drawing.Point(121, 136); + this.txtRemainingNo.Name = "txtRemainingNo"; + this.txtRemainingNo.ReadOnly = true; + this.txtRemainingNo.Size = new System.Drawing.Size(73, 23); + this.txtRemainingNo.TabIndex = 11; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(12, 139); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(80, 15); + this.label11.TabIndex = 10; + this.label11.Text = "Remaining Nr"; + // + // txtSellValue + // + this.txtSellValue.Location = new System.Drawing.Point(121, 107); + this.txtSellValue.Name = "txtSellValue"; + this.txtSellValue.ReadOnly = true; + this.txtSellValue.Size = new System.Drawing.Size(73, 23); + this.txtSellValue.TabIndex = 9; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(12, 110); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(56, 15); + this.label10.TabIndex = 8; + this.label10.Text = "Sell Value"; + // + // txtSoldAmount + // + this.txtSoldAmount.Location = new System.Drawing.Point(121, 78); + this.txtSoldAmount.Name = "txtSoldAmount"; + this.txtSoldAmount.Size = new System.Drawing.Size(73, 23); + this.txtSoldAmount.TabIndex = 7; + this.txtSoldAmount.TextChanged += new System.EventHandler(this.txtSoldAmount_TextChanged); + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(12, 81); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(77, 15); + this.label9.TabIndex = 6; + this.label9.Text = "Sold Number"; + // + // txtSoldPrice + // + this.txtSoldPrice.Location = new System.Drawing.Point(121, 49); + this.txtSoldPrice.Name = "txtSoldPrice"; + this.txtSoldPrice.Size = new System.Drawing.Size(73, 23); + this.txtSoldPrice.TabIndex = 5; + this.txtSoldPrice.TextChanged += new System.EventHandler(this.txtSoldPrice_TextChanged); + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(12, 52); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(71, 15); + this.label8.TabIndex = 4; + this.label8.Text = "Selling Price"; + // + // txtSoldDate + // + this.txtSoldDate.Location = new System.Drawing.Point(121, 20); + this.txtSoldDate.Name = "txtSoldDate"; + this.txtSoldDate.Size = new System.Drawing.Size(73, 23); + this.txtSoldDate.TabIndex = 3; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(12, 23); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(57, 15); + this.label7.TabIndex = 2; + this.label7.Text = "Sold Date"; + // + // frmSelling + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(544, 450); + this.Controls.Add(this.gbSell); + this.Controls.Add(this.gbInfo); + this.Controls.Add(this.lvSellCandidates); + this.Name = "frmSelling"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmSelling"; + this.Load += new System.EventHandler(this.frmSelling_Load); + this.gbInfo.ResumeLayout(false); + this.gbInfo.PerformLayout(); + this.gbSell.ResumeLayout(false); + this.gbSell.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView lvSellCandidates; + private System.Windows.Forms.ColumnHeader StockName; + private System.Windows.Forms.ColumnHeader Buydate; + private System.Windows.Forms.ColumnHeader BuyPrice; + private System.Windows.Forms.ColumnHeader LeftNumber; + private System.Windows.Forms.ColumnHeader ActPrice; + private System.Windows.Forms.ColumnHeader TotalValue; + private System.Windows.Forms.GroupBox gbInfo; + private System.Windows.Forms.TextBox txtStockId; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtId; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtBuyDate; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtBuyValue; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txtBuyPrice; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtBuyNumber; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.GroupBox gbSell; + private System.Windows.Forms.Button btnConfirm; + private System.Windows.Forms.TextBox txtRemainingNo; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.TextBox txtSellValue; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.TextBox txtSoldAmount; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txtSoldPrice; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TextBox txtSoldDate; + private System.Windows.Forms.Label label7; + } +} \ No newline at end of file diff --git a/StockInfo/frmSelling.cs b/StockInfo/frmSelling.cs new file mode 100644 index 0000000..b0a85a8 --- /dev/null +++ b/StockInfo/frmSelling.cs @@ -0,0 +1,99 @@ +using DataDomain; +using Helpers; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StockInfo +{ + public partial class frmSelling : Form + { + private readonly IStockRepository _stockRepository; + private List remainingStocks = new (); + public StockMember stkMemSelected { get; set; } = null; + + public frmSelling(IStockRepository stockRepository ) + { + InitializeComponent(); + _stockRepository = stockRepository; + } + + private void frmSelling_Load(object sender, EventArgs e) + { + remainingStocks = _stockRepository.GetAllRemainingStocks().ToList(); + foreach(var stock in remainingStocks) + { + var lvRow = lvSellCandidates.Items.Add(stock.StockId); + lvRow.Tag = stock.Id; + lvRow.SubItems.Add(stock.BuyDate.ToShortDateString()); + lvRow.SubItems.Add(stock.BuyValue.ToString()); + lvRow.SubItems.Add(stock.ActAmount.ToString()); + lvRow.SubItems.Add(stock.ActValue.ToString()); + lvRow.SubItems.Add((stock.ActValue * stock.ActAmount).ToString()); + } + } + + private void SelectStock(object tag) + { + //Debug.WriteLine($"selected item {(int)tag}"); + foreach(var remStk in remainingStocks) + { + if(remStk.Id == (int)tag) + { + stkMemSelected = remStk; + break; + } + } + + EditStockForSelling(stkMemSelected); + } + + private void EditStockForSelling(StockMember stkMemSelected) + { + txtId.Text = stkMemSelected.Id.ToString(); + txtStockId.Text = stkMemSelected.StockId; + txtBuyDate.Text = stkMemSelected.BuyDate.ToShortDateString(); + txtBuyNumber.Text = stkMemSelected.PostAmount.ToString(); + txtBuyPrice.Text = stkMemSelected.BuyValue.ToString(); + txtBuyValue.Text = (stkMemSelected.BuyValue * stkMemSelected.PostAmount).ToString(); + + txtSoldDate.Text = DateTime.Today.ToShortDateString(); + txtSoldPrice.Text = stkMemSelected.ActValue.ToString(); + txtSoldAmount.Text = stkMemSelected.ActAmount.ToString(); + } + + + private void lvSellCandidates_MouseUp(object sender, MouseEventArgs e) + { + var selRows = lvSellCandidates.SelectedItems; + SelectStock(selRows[0].Tag); + } + + private void txtSoldPrice_TextChanged(object sender, EventArgs e) + { + CalcNumberAndValue(); + } + + private void CalcNumberAndValue() + { + if (txtSoldPrice.Text.IsNumeric() && txtSoldAmount.Text.IsNumeric()) + { + txtSellValue.Text = (decimal.Parse(txtSoldPrice.Text) * long.Parse(txtSoldAmount.Text)).ToString(); + txtRemainingNo.Text = (stkMemSelected.PostAmount - long.Parse(txtSoldAmount.Text)).ToString(); + } + } + + private void txtSoldAmount_TextChanged(object sender, EventArgs e) + { + CalcNumberAndValue(); + } + } +} diff --git a/StockInfo/frmSelling.resx b/StockInfo/frmSelling.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfo/frmSelling.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file