-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImagesObserver.cs
More file actions
93 lines (68 loc) · 2.09 KB
/
Copy pathImagesObserver.cs
File metadata and controls
93 lines (68 loc) · 2.09 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static PDFiller.Order;
namespace PDFiller
{
internal class ImagesObserver : IObserver<Shipment>
{
private Panel _panel;
Graphics g;
List<Order> _orders;
Dictionary<string, SoldProduct> _dict = new Dictionary<string, SoldProduct>();
private void Paint()
{
g.Clear(Color.White);
if (_orders == null) return;
int i = 0;
foreach(var data in _dict)
{
g.DrawImage(data.Value.Image, new Rectangle((i % 4) * 150 + 25, (i / 4) * 130 + 10, 100, 100));
g.DrawString($"{data.Value.Name}", new Font("Times New Roman", 14f), new SolidBrush(Color.Black), (i % 4) * 150 + 70 - 4.5f * data.Value.Name.Length, (i / 4) * 130 + 110);
i++;
}
}
public ImagesObserver(Panel panel)
{
this._panel = panel;
this.g = panel.CreateGraphics();
panel.Paint += (sender, e) => this.Paint();
panel.Invalidate();
}
public void OnCompleted()
{
_orders = null;
_dict.Clear();
_panel.Invalidate();
}
public void OnError(Exception error)
{
_orders = null;
_dict.Clear();
_panel.Invalidate();
}
public void OnNext(Shipment shipment)
{
this._orders = shipment.Orders;
_dict.Clear();
foreach (var order in this._orders)
{
foreach (SoldProduct soldProduct in order.products)
{
if (!_dict.ContainsKey(soldProduct.Id))
{
_dict[soldProduct.Id] = soldProduct;
}
}
}
_panel.Invalidate();
}
}
}