diff --git a/RepositoryPattern/App.config b/RepositoryPattern/App.config
index fd3821e..d9792bd 100644
--- a/RepositoryPattern/App.config
+++ b/RepositoryPattern/App.config
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/RepositoryPattern/Form1.Designer.cs b/RepositoryPattern/Form1.Designer.cs
index 562b342..2212b9a 100644
--- a/RepositoryPattern/Form1.Designer.cs
+++ b/RepositoryPattern/Form1.Designer.cs
@@ -31,7 +31,12 @@ namespace RepositoryPattern
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.lblTotalRecords = new System.Windows.Forms.Label();
+ this.gB1 = new System.Windows.Forms.GroupBox();
+ this.rdbStock = new System.Windows.Forms.RadioButton();
+ this.rdbNorth = new System.Windows.Forms.RadioButton();
+ this.btnReload = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.gB1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
@@ -52,11 +57,55 @@ namespace RepositoryPattern
this.lblTotalRecords.TabIndex = 2;
this.lblTotalRecords.Text = "Total Records: ???";
//
+ // gB1
+ //
+ this.gB1.Controls.Add(this.btnReload);
+ this.gB1.Controls.Add(this.rdbStock);
+ this.gB1.Controls.Add(this.rdbNorth);
+ this.gB1.Location = new System.Drawing.Point(220, 410);
+ this.gB1.Name = "gB1";
+ this.gB1.Size = new System.Drawing.Size(248, 35);
+ this.gB1.TabIndex = 3;
+ this.gB1.TabStop = false;
+ //
+ // rdbStock
+ //
+ this.rdbStock.AutoSize = true;
+ this.rdbStock.Location = new System.Drawing.Point(98, 9);
+ this.rdbStock.Name = "rdbStock";
+ this.rdbStock.Size = new System.Drawing.Size(54, 19);
+ this.rdbStock.TabIndex = 1;
+ this.rdbStock.Text = "Stock";
+ this.rdbStock.UseVisualStyleBackColor = true;
+ //
+ // rdbNorth
+ //
+ this.rdbNorth.AutoSize = true;
+ this.rdbNorth.Checked = true;
+ this.rdbNorth.Location = new System.Drawing.Point(7, 9);
+ this.rdbNorth.Name = "rdbNorth";
+ this.rdbNorth.Size = new System.Drawing.Size(84, 19);
+ this.rdbNorth.TabIndex = 0;
+ this.rdbNorth.TabStop = true;
+ this.rdbNorth.Text = "NorthWind";
+ this.rdbNorth.UseVisualStyleBackColor = true;
+ //
+ // btnReload
+ //
+ this.btnReload.Location = new System.Drawing.Point(158, 9);
+ this.btnReload.Name = "btnReload";
+ this.btnReload.Size = new System.Drawing.Size(75, 23);
+ this.btnReload.TabIndex = 2;
+ this.btnReload.Text = "Reload";
+ this.btnReload.UseVisualStyleBackColor = true;
+ this.btnReload.Click += new System.EventHandler(this.btnReload_Click);
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.gB1);
this.Controls.Add(this.lblTotalRecords);
this.Controls.Add(this.dataGridView);
this.MinimizeBox = false;
@@ -65,6 +114,8 @@ namespace RepositoryPattern
this.Text = "Repository Pattern";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.gB1.ResumeLayout(false);
+ this.gB1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -74,6 +125,10 @@ namespace RepositoryPattern
private System.Windows.Forms.DataGridView dataGridView;
private System.Windows.Forms.Label lblTotalRecords;
+ private System.Windows.Forms.GroupBox gB1;
+ private System.Windows.Forms.RadioButton rdbStock;
+ private System.Windows.Forms.RadioButton rdbNorth;
+ private System.Windows.Forms.Button btnReload;
}
}
diff --git a/RepositoryPattern/Form1.cs b/RepositoryPattern/Form1.cs
index d96b286..4bad109 100644
--- a/RepositoryPattern/Form1.cs
+++ b/RepositoryPattern/Form1.cs
@@ -14,16 +14,35 @@ namespace RepositoryPattern
public partial class Form1 : Form
{
IProductRepository _productRepository;
- public Form1(IProductRepository productRepository)
+ private readonly IStockMemberRepository _stockMemberRepository;
+
+ public Form1(IProductRepository productRepository,IStockMemberRepository stockMemberRepository)
{
InitializeComponent();
_productRepository = productRepository;
+ _stockMemberRepository = stockMemberRepository;
}
private void Form1_Load(object sender, EventArgs e)
{
- dataGridView.DataSource = _productRepository.GetProducts();
+ ReloadData();
+ }
+
+ private void ReloadData()
+ {
+ if (rdbNorth.Checked)
+ {
+ dataGridView.DataSource = _productRepository.GetProducts(); }
+ else if(rdbStock.Checked)
+ {
+ dataGridView.DataSource = _stockMemberRepository.GetStocks();
+ }
lblTotalRecords.Text = $"Total records: {dataGridView.RowCount}";
}
+
+ private void btnReload_Click(object sender, EventArgs e)
+ {
+ ReloadData();
+ }
}
}
diff --git a/RepositoryPattern/Program.cs b/RepositoryPattern/Program.cs
index 89f86a1..4ec3a83 100644
--- a/RepositoryPattern/Program.cs
+++ b/RepositoryPattern/Program.cs
@@ -22,7 +22,7 @@ namespace RepositoryPattern
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Container = Configure();
- Application.Run(new Form1(Container.Resolve()));
+ Application.Run(new Form1(Container.Resolve(),Container.Resolve()));
}
///
/// Setting dependency injection
@@ -32,6 +32,7 @@ namespace RepositoryPattern
{
var builder = new ContainerBuilder();
builder.RegisterType().As();
+ builder.RegisterType().As();
builder.RegisterType();
return builder.Build();
}
diff --git a/StockDal.Interface/IStockMemberRepository.cs b/StockDal.Interface/IStockMemberRepository.cs
new file mode 100644
index 0000000..b0d7c12
--- /dev/null
+++ b/StockDal.Interface/IStockMemberRepository.cs
@@ -0,0 +1,14 @@
+using StockDomain;
+using System;
+using System.Collections.Generic;
+
+namespace StockDal.Interface
+{
+ public interface IStockMemberRepository
+ {
+ IEnumerable GetStocks();
+ bool Insert(StockMember stockMember);
+ bool Update(StockMember stockMember);
+ bool Delete(string stockMemberId);
+ }
+}
diff --git a/StockDal/AppConnection.cs b/StockDal/AppConnection.cs
index 8bd408c..853d7dc 100644
--- a/StockDal/AppConnection.cs
+++ b/StockDal/AppConnection.cs
@@ -11,4 +11,8 @@ namespace RepositoryPattern
{
public static string ConnectionString => ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
}
+ public class StockDBConnection
+ {
+ public static string ConnectionString => ConfigurationManager.ConnectionStrings["StockDB"].ConnectionString;
+ }
}
diff --git a/StockDal/StockMemberRepository.cs b/StockDal/StockMemberRepository.cs
new file mode 100644
index 0000000..c89bc10
--- /dev/null
+++ b/StockDal/StockMemberRepository.cs
@@ -0,0 +1,48 @@
+using Dapper;
+using RepositoryPattern;
+using StockDal.Interface;
+using StockDomain;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.SqlClient;
+
+namespace StockDal
+{
+ public class StockMemberRepository : IStockMemberRepository
+ {
+ public bool Delete(string stockMemberId)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool Insert(StockMember stockMember)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool Update(StockMember stockMember)
+ {
+ throw new NotImplementedException();
+ }
+
+ IEnumerable IStockMemberRepository.GetStocks()
+ {
+ using System.Data.IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString);
+ if (db.State == ConnectionState.Closed)
+ db.Open();
+ return db.Query(@"SELECT Id
+ ,StockId
+ ,StockExtId
+ ,BuyValue
+ ,BuyDate
+ ,ActValue
+ ,ActDate
+ ,SoldValue
+ ,SoldDate
+ ,Comment
+ ,PostAmount
+ FROM dbo.StockMember", commandType: CommandType.Text);
+ }
+ }
+}
diff --git a/StockDomain/StockMember.cs b/StockDomain/StockMember.cs
index 2b79cfa..4d93320 100644
--- a/StockDomain/StockMember.cs
+++ b/StockDomain/StockMember.cs
@@ -5,7 +5,20 @@ using System.Text;
namespace StockDomain
{
- class StockMember
+ public class StockMember
{
+ public int Id { get; set; }
+ public string StockId { get; set; }
+ public string StockExtId { get; set; }
+ public decimal BuyValue { get; set; }
+ public DateTime BuyDate { get; set; }
+ public long BuytAmount { 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 string PostId { get; set; }
+ public string Comment { get; set; }
}
}