This is the content of the VisualBookstore.cs file:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace _313_lab_08
{
class VisualBookstore : Control
{
public string Name;
protected override void OnPaint(PaintEventArgs e)
{
Pen p = new Pen(Color.Black);
Font f = new Font("Times New Roman", 10);
Brush b = new SolidBrush(Color.Black);
e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
e.Graphics.DrawString(Name, f, b, 2, 2);
}
public VisualSection AddSection(Genre genre)
{
VisualSection vs = new VisualSection();
vs.genre = genre;
vs.Left = 5;
vs.Width = 300;
vs.Height = 80;
vs.Top = Controls.Count * 90 + 20;
Controls.Add(vs);
return vs;
}
public void AddBook(string title, string author, Genre genre, string id)
{
VisualSection vs = FindSection(genre);
vs.AddBook(title, author, genre, id);
}
private VisualSection FindSection(Genre g)
{
foreach (VisualSection vs in Controls)
{
if (vs.genre == g)
{
// match found, so return it
return vs;
}
}
// no section exists, so create it and return the new section created
return AddSection(g);
}
}
}