MaterialTemplate.cs 2.0 KB
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);
        }
    }


}