MaterialTemplate.cs
2.0 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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace Model
{
public class MaterialTemplate
{
public List<MaterialCode> Code = new();
public List<MaterialCodeOCR> Ocr = new();
public List<MaterialCodeMatch> Match = new();
public string FilePath { get; set; } = "";
public string ImagePath { get; set; } = "";
public Bitmap Image { get; set; } = null;
public string Name { get; set; } = "";
public int PrimaryCode { get; set; } = -1;
public TemplateState State { get; set; } = TemplateState.Saved;
public MaterialTemplate Clone()
{
MaterialTemplate node = new();
for (int i = 0; i < Code.Count; i++)
node.Code.Add(Code[i].Clone());
for (int i = 0; i < Ocr.Count; i++)
node.Ocr.Add(Ocr[i].Clone());
for (int i = 0; i < Match.Count; i++)
node.Match.Add(Match[i].Clone());
System.Reflection.PropertyInfo[] destination = node.GetType().GetProperties();
System.Reflection.PropertyInfo[] orgin = GetType().GetProperties();
for (int i = 0; i < destination.Length; i++)
destination[i].SetValue(node, orgin[i].GetValue(this));
return node;
}
public int[] GetCodeID()
{
int[] id = new int[Code.Count];
for (int i = 0; i < Code.Count; i++)
id[i] = Code[i].ID;
return id;
}
public int[] GetOcrID()
{
int[] id = new int[Ocr.Count];
for (int i = 0; i < Ocr.Count; i++)
id[i] = Ocr[i].ID;
return id;
}
public int GetMaxID()
{
int max1 = 0;
int max2 = 0;
if (Code.Count > 0) max1 = Code.Max(t => t.ID);
if (Ocr.Count > 0) max2 = Ocr.Max(t => t.ID);
return Math.Max(max1, max2);
}
}
}