Running against Northwind and StockDB

This commit is contained in:
2021-01-10 18:07:51 +01:00
parent dd530c02a9
commit c7254389e4
8 changed files with 159 additions and 4 deletions

View File

@ -2,5 +2,6 @@
<configuration>
<connectionStrings>
<add name="cn" connectionString="Data Source=oemansv7win;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="StockDB" connectionString="Data Source=oemansv7win;Initial Catalog=StockDB;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -22,7 +22,7 @@ namespace RepositoryPattern
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Container = Configure();
Application.Run(new Form1(Container.Resolve<IProductRepository>()));
Application.Run(new Form1(Container.Resolve<IProductRepository>(),Container.Resolve<IStockMemberRepository>()));
}
/// <summary>
/// Setting dependency injection
@ -32,6 +32,7 @@ namespace RepositoryPattern
{
var builder = new ContainerBuilder();
builder.RegisterType<ProductRepository>().As<IProductRepository>();
builder.RegisterType<StockMemberRepository>().As<IStockMemberRepository>();
builder.RegisterType<Form1>();
return builder.Build();
}