jace.tang
2022-06-14 bd5297c64f39c360a7bf41435a88ae5e70840fc2
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace M423project
{
    //产品检测数据集合
    public class DetectionCollection : IDisposable, IList<ProductMeasureResult>
    {
        private string saveFileName = string.Empty;
        
        private List<ProductMeasureResult> productList = new List<ProductMeasureResult>();
 
        public int Count
        { get { return productList.Count; } }
        public DetectionCollection(string _saveFileName)
        {
            saveFileName = _saveFileName;
        }
 
        public void AppendProduct(string _productNo)
        {
            //productList.Add(new ProductMeasureResult(_productNo));
        }
 
        public void DeleteProduct()
        {
            if (productList.Count <= 0)
                return;
 
           ProductMeasureResult tr = productList[productList.Count - 1];
           SaveTestResult(tr);
        }
 
        //设定高度数据
        public void SetHeight(string productNo, double height, double cellHeight, MeasureState measureState)
        {
            var p = (from o in productList
                where o.ProductNo == productNo
                select o
            ).FirstOrDefault();
            if (p == null)
                return;
            
            //p.CellHeight = cellHeight;
            p.Height = height;
            p.HeightResult = measureState.ToString();
        }
 
        //结果保存到文件,只有在产品长宽高都设置好时,或未完成设置但对象Dispose时
        public void SaveTestResult(ProductMeasureResult tr)
        {
            using (StreamWriter sw = new StreamWriter(saveFileName))
            {
                sw.WriteLine("{0}:{1:F4},{2:F4},{3};{4:F4}, {5}", tr.ProductNo, tr.Length, tr.Width,
                    tr.ToString(),   tr.Height, tr.ToString());
            }
        }
 
        public void Dispose()
        {
            ProductMeasureResult tr;
            for (int i = productList.Count - 1; i >= 0; i--)
            {
                tr = productList[i];
                SaveTestResult(tr);
            }
         
        }
 
        public int IndexOf(ProductMeasureResult item)
        {
            return productList.IndexOf(item);
        }
 
        public void Insert(int index, ProductMeasureResult item)
        {
            productList.Insert(0, item);
        }
 
        public void RemoveAt(int index)
        {
            productList.RemoveAt(index);
 
        }
 
        public ProductMeasureResult this[int index]
        {
            get
            {
                return productList[index];
            }
            set
            {
                productList[index] = value;
                 
            }
        }
 
        public void Add(ProductMeasureResult item)
        {
            productList.Add(item);
        }
 
        public void Clear()
        {
            productList.Clear();
        }
 
        public bool Contains(ProductMeasureResult item)
        {
            return productList.Contains(item);
        }
 
        public void CopyTo(ProductMeasureResult[] array, int arrayIndex)
        {
            ;
             
        }
 
        public bool IsReadOnly
        {
            get { return false; }
        }
 
        public bool Remove(ProductMeasureResult item)
        {
            return productList.Remove(item);
        }
 
        public IEnumerator<ProductMeasureResult> GetEnumerator()
        {
            return productList.GetEnumerator();
        }
 
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return productList.GetEnumerator();
        }
    }
}