-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewObserver.cs
More file actions
49 lines (46 loc) · 1.46 KB
/
Copy pathPreviewObserver.cs
File metadata and controls
49 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PDFiller
{
/// <summary>
/// A concrete observer for the preview functionality.
/// Will manage the tab ExcelPreview tab in the main window.
/// And the coresponding data grid view
/// </summary>
internal class PreviewObserver:IObserver<Shipment>
{
private DataGridView _dataGridView;
public PreviewObserver(DataGridView dataGridView)
{
_dataGridView = dataGridView;
_dataGridView.Rows.Clear();
}
public virtual void OnCompleted()
{
_dataGridView.Rows.Clear();
}
public virtual void OnNext(Shipment shipment)
{
List<Order> orders = shipment.Orders;
var rows = _dataGridView.Rows;
rows.Clear();
foreach (Order o in orders)
{
rows.Add(o.country, o.customerName, o.products[0].Name, o.products[0].Quantity);
foreach (SoldProduct product in o.products.GetRange(1, o.products.Count - 1))
{
rows.Add(null,null, product.Name, product.Quantity);
}
}
}
public virtual void OnError(Exception error)
{
_dataGridView.Rows.Clear();
_dataGridView.Rows.Add(null ,null,error.Message,null);
}
}
}