diff --git a/RepositoryPattern/frmInitial.cs b/RepositoryPattern/frmInitial.cs index 61f2fc6..ffc3ff5 100644 --- a/RepositoryPattern/frmInitial.cs +++ b/RepositoryPattern/frmInitial.cs @@ -84,6 +84,8 @@ namespace RepositoryPattern regWindow = new frmRegisterStock(); regWindow.Stocks = _stockMarketRepository.StockMarketList; regWindow.ShowDialog(); + + _stockMemberRepository.InsertMany(regWindow.RegisteredStocks); } } } diff --git a/RepositoryPattern/frmRegisterStock.Designer.cs b/RepositoryPattern/frmRegisterStock.Designer.cs index 30430b0..2a55d37 100644 --- a/RepositoryPattern/frmRegisterStock.Designer.cs +++ b/RepositoryPattern/frmRegisterStock.Designer.cs @@ -51,8 +51,13 @@ namespace RepositoryPattern this.lblSoldDate = new System.Windows.Forms.Label(); this.txtComment = new System.Windows.Forms.TextBox(); this.lblComment = new System.Windows.Forms.Label(); - this.listBox1 = new System.Windows.Forms.ListBox(); this.btnSaveStock = new System.Windows.Forms.Button(); + this.lwRegBuffer = new System.Windows.Forms.ListView(); + this.Stock = new System.Windows.Forms.ColumnHeader(); + this.Price = new System.Windows.Forms.ColumnHeader(); + this.Number = new System.Windows.Forms.ColumnHeader(); + this.Comment = new System.Windows.Forms.ColumnHeader(); + this.btnSaveToDB = new System.Windows.Forms.Button(); this.SuspendLayout(); // // cmbStockChoser @@ -128,6 +133,7 @@ namespace RepositoryPattern this.txtBoughtAmount.Name = "txtBoughtAmount"; this.txtBoughtAmount.Size = new System.Drawing.Size(111, 23); this.txtBoughtAmount.TabIndex = 9; + this.txtBoughtAmount.TextChanged += new System.EventHandler(this.txtBoughtAmount_TextChanged); // // lblBoughtAmount // @@ -235,31 +241,74 @@ namespace RepositoryPattern this.lblComment.TabIndex = 20; this.lblComment.Text = "Comment"; // - // listBox1 - // - this.listBox1.FormattingEnabled = true; - this.listBox1.ItemHeight = 15; - this.listBox1.Location = new System.Drawing.Point(39, 467); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(383, 94); - this.listBox1.TabIndex = 22; - // // btnSaveStock // - this.btnSaveStock.Location = new System.Drawing.Point(39, 424); + this.btnSaveStock.Location = new System.Drawing.Point(39, 385); this.btnSaveStock.Name = "btnSaveStock"; this.btnSaveStock.Size = new System.Drawing.Size(75, 23); this.btnSaveStock.TabIndex = 23; this.btnSaveStock.Text = "Register"; this.btnSaveStock.UseVisualStyleBackColor = true; + this.btnSaveStock.Click += new System.EventHandler(this.btnSaveStock_Click); + // + // lwRegBuffer + // + this.lwRegBuffer.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.Stock, + this.Price, + this.Number, + this.Comment}); + this.lwRegBuffer.GridLines = true; + this.lwRegBuffer.HideSelection = false; + this.lwRegBuffer.Location = new System.Drawing.Point(39, 427); + this.lwRegBuffer.Name = "lwRegBuffer"; + this.lwRegBuffer.Size = new System.Drawing.Size(383, 119); + this.lwRegBuffer.TabIndex = 24; + this.lwRegBuffer.UseCompatibleStateImageBehavior = false; + this.lwRegBuffer.View = System.Windows.Forms.View.Details; + // + // Stock + // + this.Stock.Name = "Stock"; + this.Stock.Text = "Stock"; + this.Stock.Width = 120; + // + // Price + // + this.Price.Name = "Price"; + this.Price.Text = "Price"; + this.Price.Width = 80; + // + // Number + // + this.Number.Name = "Number"; + this.Number.Text = "Number"; + this.Number.Width = 80; + // + // Comment + // + this.Comment.Name = "Comment"; + this.Comment.Text = "Comment"; + this.Comment.Width = 120; + // + // btnSaveToDB + // + this.btnSaveToDB.Location = new System.Drawing.Point(266, 567); + this.btnSaveToDB.Name = "btnSaveToDB"; + this.btnSaveToDB.Size = new System.Drawing.Size(75, 23); + this.btnSaveToDB.TabIndex = 25; + this.btnSaveToDB.Text = "Save"; + this.btnSaveToDB.UseVisualStyleBackColor = true; + this.btnSaveToDB.Click += new System.EventHandler(this.btnSaveToDB_Click); // // frmRegisterStock // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(441, 602); + this.Controls.Add(this.btnSaveToDB); + this.Controls.Add(this.lwRegBuffer); this.Controls.Add(this.btnSaveStock); - this.Controls.Add(this.listBox1); this.Controls.Add(this.txtComment); this.Controls.Add(this.lblComment); this.Controls.Add(this.txtSoldDate); @@ -283,6 +332,7 @@ namespace RepositoryPattern this.Controls.Add(this.btnClose); this.Controls.Add(this.cmbStockChoser); this.Name = "frmRegisterStock"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "frmRegisterStock"; this.Shown += new System.EventHandler(this.frmRegisterStock_Shown); this.ResumeLayout(false); @@ -314,7 +364,12 @@ namespace RepositoryPattern private System.Windows.Forms.Label lblSoldDate; private System.Windows.Forms.TextBox txtComment; private System.Windows.Forms.Label lblComment; - private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Button btnSaveStock; + private System.Windows.Forms.ListView lwRegBuffer; + private System.Windows.Forms.ColumnHeader Stock; + private System.Windows.Forms.ColumnHeader Price; + private System.Windows.Forms.ColumnHeader Number; + private System.Windows.Forms.ColumnHeader Comment; + private System.Windows.Forms.Button btnSaveToDB; } } \ No newline at end of file diff --git a/RepositoryPattern/frmRegisterStock.cs b/RepositoryPattern/frmRegisterStock.cs index 896a115..193137b 100644 --- a/RepositoryPattern/frmRegisterStock.cs +++ b/RepositoryPattern/frmRegisterStock.cs @@ -15,6 +15,7 @@ namespace RepositoryPattern { public Dictionary Stocks { get; set; } + public List RegisteredStocks { get; set; } = new List(); public frmRegisterStock() { @@ -25,7 +26,7 @@ namespace RepositoryPattern { if (Stocks.Count() > 0) { - foreach(var key in Stocks.Keys) + foreach (var key in Stocks.Keys) { cmbStockChoser.Items.Add(key); } @@ -50,5 +51,69 @@ namespace RepositoryPattern txtActValue.Text = stockChosen.LatestPrice.ToString(); txtActDate.Text = (DateTime.Today + stockChosen.TimeOfDay).ToString(); } + + private void btnSaveStock_Click(object sender, EventArgs e) + { + AddValidateData(); + RefreshListViewFromRegList(); + } + + private void RefreshListViewFromRegList() + { + lwRegBuffer.Items.Clear(); + foreach (var currStock in RegisteredStocks) + { + AddItemToListView(currStock); + } + } + + private void AddItemToListView(StockMember currStock) + { + var lv = lwRegBuffer.Items.Add(currStock.StockId); + lv.SubItems.Add(currStock.BuyValue.ToString()); + lv.SubItems.Add(currStock.PostAmount.ToString()); + lv.SubItems.Add(currStock.Comment); + } + + private void AddValidateData() + { + var currentStock = new StockMember(); + currentStock.StockId = cmbStockChoser.SelectedItem.ToString(); + currentStock.StockExtId = txtStockExtId.Text; + currentStock.BuyValue = decimal.Parse(string.IsNullOrEmpty(txtBuyPrice.Text) ? "0" : txtBuyPrice.Text); + currentStock.PostAmount = long.Parse(string.IsNullOrEmpty(txtBoughtAmount.Text) ? "0" : txtBoughtAmount.Text); + currentStock.ActDate = DateTime.Parse(txtActDate.Text); + currentStock.BuyDate = DateTime.Today; + currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text); + currentStock.SoldDate = null; //DateTime.MaxValue; + currentStock.SoldValue = decimal.Parse("0"); + currentStock.Comment = txtComment.Text; + RegisteredStocks.Add(currentStock); + initiateRegWin(); + } + + private void initiateRegWin() + { + txtStockExtId.Text = ""; + txtBuyPrice.Text = ""; + txtBuyDate.Text = ""; + txtBoughtAmount.Text = ""; + txtActValue.Text = ""; + txtActDate.Text = ""; + txtActAmount.Text = ""; + txtSoldPrice.Text = ""; + txtSoldDate.Text = ""; + txtComment.Text = ""; + } + + private void btnSaveToDB_Click(object sender, EventArgs e) + { + + } + + private void txtBoughtAmount_TextChanged(object sender, EventArgs e) + { + txtActAmount.Text = txtBoughtAmount.Text; + } } } diff --git a/StockDal.Interface/IStockMemberRepository.cs b/StockDal.Interface/IStockMemberRepository.cs index b0d7c12..b8271c3 100644 --- a/StockDal.Interface/IStockMemberRepository.cs +++ b/StockDal.Interface/IStockMemberRepository.cs @@ -7,8 +7,9 @@ namespace StockDal.Interface public interface IStockMemberRepository { IEnumerable GetStocks(); - bool Insert(StockMember stockMember); + //bool Insert(StockMember stockMember); bool Update(StockMember stockMember); bool Delete(string stockMemberId); + void InsertMany(List stockMembers); } } diff --git a/StockDal.Interface/StockDal.Interface.csproj b/StockDal.Interface/StockDal.Interface.csproj index 0921680..55af59e 100644 --- a/StockDal.Interface/StockDal.Interface.csproj +++ b/StockDal.Interface/StockDal.Interface.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/StockDal/StockDal.csproj b/StockDal/StockDal.csproj index 26d211c..f6a1392 100644 --- a/StockDal/StockDal.csproj +++ b/StockDal/StockDal.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/StockDal/StockMarketRepository.cs b/StockDal/StockMarketRepository.cs index b121b80..31a2c20 100644 --- a/StockDal/StockMarketRepository.cs +++ b/StockDal/StockMarketRepository.cs @@ -185,7 +185,7 @@ namespace StockDal public void Clean() { - driver.Quit(); + driver?.Quit(); } } diff --git a/StockDal/StockMemberRepository.cs b/StockDal/StockMemberRepository.cs index c89bc10..a21bf86 100644 --- a/StockDal/StockMemberRepository.cs +++ b/StockDal/StockMemberRepository.cs @@ -16,9 +16,35 @@ namespace StockDal throw new NotImplementedException(); } - public bool Insert(StockMember stockMember) + public void InsertMany(List stockMembers) { - throw new NotImplementedException(); + using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); + if (db.State == ConnectionState.Closed) + db.Open(); + db.Execute( + @"INSERT INTO [dbo].[StockMember] + (StockId + ,StockExtId + ,BuyValue + ,BuyDate + ,ActValue + ,ActDate + ,SoldValue + ,SoldDate + ,Comment + ,PostAmount) + VALUES + (@StockId + ,@StockExtId + ,@BuyValue + ,@BuyDate + ,@ActValue + ,@ActDate + ,@SoldValue + ,@SoldDate + ,@Comment + ,@PostAmount) + ", stockMembers); } public bool Update(StockMember stockMember) @@ -28,7 +54,7 @@ namespace StockDal IEnumerable IStockMemberRepository.GetStocks() { - using System.Data.IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); + using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString); if (db.State == ConnectionState.Closed) db.Open(); return db.Query(@"SELECT Id diff --git a/StockDomain/StockDomain.csproj b/StockDomain/StockDomain.csproj index cb63190..f208d30 100644 --- a/StockDomain/StockDomain.csproj +++ b/StockDomain/StockDomain.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/StockDomain/StockMember.cs b/StockDomain/StockMember.cs index a98714f..6c45d9d 100644 --- a/StockDomain/StockMember.cs +++ b/StockDomain/StockMember.cs @@ -12,13 +12,14 @@ namespace StockDomain public string StockExtId { get; set; } public decimal BuyValue { get; set; } public DateTime BuyDate { get; set; } - public long BuyAmount { get; set; } public decimal ActValue { get; set; } public DateTime ActDate { get; set; } public long ActAmount { get; set; } public decimal SoldValue { get; set; } - public DateTime SoldDate { get; set; } + public DateTime? SoldDate { get; set; } // public string PostId { get; set; } public string Comment { get; set; } + public long PostAmount { get; set; } + } }