Traced.cs 3.2 KB
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Xml;

namespace BLL
{
    /// <summary>
    /// 追溯类
    /// </summary>
    public class Traced
    {
        private XmlDocument _doc;
        private List<CodeSplice.TraceTemp> _trac;
        
        /// <summary>
        /// 追溯类
        /// </summary>
        /// <param name="path"></param>
        public Traced(string path)
        {
            try
            {
                string[] arr;
                List<string> itemFile = new List<string>();
                string[] file = System.IO.Directory.GetFiles(path);
                foreach (string s in file)
                    if (s.ToUpper().EndsWith(".XML")) itemFile.Add(s);

                _doc = new XmlDocument();
                _trac = new List<CodeSplice.TraceTemp>();
                for (int i = 0; i < itemFile.Count; i++)  //文件循环
                {
                    _doc.Load(itemFile[i]);
                    XmlElement root = (XmlElement)_doc.LastChild;
                    CodeSplice.TraceTemp temp = new CodeSplice.TraceTemp();

                    temp.Name = (i + 1).ToString();
                    temp.MateTemp = root.GetAttribute("MaterialTemp");
                    temp.MateImageName = root.GetAttribute("MaterialImage");
                    temp.MateImage = new Bitmap(path + temp.MateImageName);
                    temp.LabelTemp = root.GetAttribute("LabelTemp");
                    temp.LabelImageName = root.GetAttribute("LabelImage");
                    temp.LabelImage = new Bitmap(path + temp.LabelImageName);

                    int n = root.ChildNodes.Count;
                    for (int j = 0; j < n; j++)  //标签区域循环
                    {
                        CodeSplice.BarCode code = new CodeSplice.BarCode();
                        XmlElement ele = (XmlElement)root.ChildNodes[j];
                        arr = ele.GetAttribute("Center").Split(',');
                        code.Center = new PointF(Convert.ToSingle(arr[0]), Convert.ToSingle(arr[1]));
                        code.Text = ele.GetAttribute("Text");
                        temp.Code.Add(code);
                    }
                    _trac.Add(temp);
                }
            }
            catch (Exception ex)
            {
                CodeSplice.Common.Log.OutError(ex.Message);
            }
        }

        /// <summary>
        /// 物料模板名称
        /// </summary>
        public string[] Name
        {
            get
            {
                string[] s = new string[_trac.Count];
                for (int i = 0; i < s.Length; i++)
                    s[i] = _trac[i].Name;
                return s;
            }
        }

        /// <summary>
        /// 物料模板总数
        /// </summary>
        public int Count
        {
            get
            {
                if (_trac == null)
                    return -1;
                else
                    return _trac.Count;
            }
        }

        public int Index { set; get; } = -1;

        public CodeSplice.TraceTemp GetTrace(int index)
        {
            return _trac[index];
        }

        public void Add(CodeSplice.TraceTemp temp)
        {
            _trac.Add(temp);
        }








    }
}