jace.tang
2023-02-11 ed8d469ccdc0e627d8f180bb92a9d78dbdb008b1
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace M423project
{
    //检测状态,初始为未检测
    public enum MeasureState { OK, NG, UNKNOWN, NA }
 
    /// <summary>
    /// 检测长宽结果类型
    /// </summary>
    public struct MeasureSize
    {
        public double Length, Width, CellWidth; //分别为长、宽、格子宽度
 
        public MeasureState Result;
        public MeasureState LengthResult;
        public MeasureState WidthResult;
        public override string ToString()
        {
            return string.Format("L:{0:F4} W:{1:F4} CW:{2:F4} R:{3:F4}",
                Length, Width, CellWidth, Result);
        }
    }
    /// <summary>
    /// 检测高度结果类型
    /// </summary>
    public struct MeasureHeight
    {
        public double Height, CellHeight; //分别为高度、格子高度
        public MeasureState HeightResult;
        public MeasureState CellHeightResult;
 
        public override string ToString()
        {
            return string.Format("H:{0:F4} CH:{1:F4} R:{2}",
                Height, CellHeight, HeightResult);
        }
    }
 
    /// <summary>
    /// 测量结果,包含产品代码、尺寸(长、宽)、高度
    /// </summary>
    public class ProductMeasureResult
    {
        public MeasureSize measureSize;
        public MeasureHeight measureHeight;
        public MeasureState productNoResult;
 
        private string productNo;
 
        public int DetectID { get; set; }
        public string ProductNo
        {
            get
            {
                return productNo;
            }
            set
            {
                productNo = value;
            }
        }
 
        public DateTime DetectTime { get; set; }
        public int PlateID { get; set; }
 
        public string ProductNoResult
        {
            get { return productNoResult.ToString(); }
            set { productNoResult = (MeasureState)Enum.Parse(typeof(MeasureState), value); }
        }
 
        public double Height { get { return measureHeight.Height; } set { measureHeight.Height = value; } }
        public double CellHeight { get { return measureHeight.CellHeight; } set { measureHeight.CellHeight = value; } }
        public string HeightResult
        {
            get { return measureHeight.HeightResult.ToString(); }
            set { measureHeight.HeightResult = (MeasureState)Enum.Parse(typeof(MeasureState), value); }
        }
 
        public string CellHeightResult
        {
            get { return measureHeight.CellHeightResult.ToString(); }
            set { measureHeight.CellHeightResult = (MeasureState)Enum.Parse(typeof(MeasureState), value); }
 
        }
 
        public double Length { get { return measureSize.Length; } set { measureSize.Length = value; } }
        public string LengthResult
        {
            get { return measureSize.LengthResult.ToString(); }
            set { measureSize.LengthResult = (MeasureState)Enum.Parse(typeof(MeasureState), value); }
        }
        public double Width { get { return measureSize.Width; } set { measureSize.Width = value; } }
        public string WidthResult
        {
            get { return measureSize.WidthResult.ToString(); }
            set { measureSize.WidthResult = (MeasureState)Enum.Parse(typeof(MeasureState), value); }
        }
        //public double CellWidth { get { return measureSize.CellWidth; } set { measureSize.CellWidth = value; } }
        //public string SizeResult 
        //{ 
        //    get { return measureSize.Result.ToString(); }
        //    set { measureSize.Result = (MeasureState)Enum.Parse(typeof(MeasureState), value); } 
        // }
 
        /// <summary>
        /// 是否是抽檢數據
        /// </summary>
        public bool IsSpotCheck { get; set; }
 
        public string ProductResult
        {
            get; set;
        }
        public ProductMeasureResult(string _productNo, int _detectID)
        {
            productNo = _productNo;
            DetectID = _detectID;
            measureSize.Result = MeasureState.UNKNOWN;
            measureSize.LengthResult = MeasureState.UNKNOWN;
            measureSize.WidthResult = MeasureState.UNKNOWN;
            measureSize.CellWidth = 0;
            measureSize.Length = 0;
            measureSize.Width = 0;
            measureHeight.HeightResult = MeasureState.UNKNOWN;
            measureHeight.CellHeight = 0;
            measureHeight.Height = 0;
            measureHeight.CellHeight = 0;
            measureHeight.CellHeightResult = MeasureState.UNKNOWN;
            productNoResult = MeasureState.UNKNOWN;
            DetectTime = DateTime.Now;
            ProductResult = MeasureState.UNKNOWN.ToString();
            PlateID = 0;
        }
 
        public override string ToString()
        {
 
            return string.Format("{0} L:{1:F4},W:{2:F4}, CW:{3:F4}, R:{4}  H:{5:F4},CH:{6:F4}, R:{7}",
                productNo, measureSize.Length, measureSize.Width, measureSize.CellWidth, measureSize.Result,
                measureHeight.Height, measureHeight.CellHeight, measureHeight.HeightResult);
        }
    }
 
    [Serializable]
    public class MeasureResultTTL
    {
        public int ProductQuntity { get; set; }
        public int PassQuntity { get; set; }
        public int FailQuntity { get; set; }
 
        public int EmptyQuantity { get; set; }
        public string PassRate
        {
            get
            {
                double v = 0.0;
                if (ProductQuntity != 0)
                    v = (double)PassQuntity / (double)(ProductQuntity - EmptyQuantity);
                return string.Format("{0:P2}", v);
            }
        }
        public int HeightPassQuntity { get; set; }
        public int HeightFailQuntity { get; set; }
        public int SizePassQuantity { get; set; }
        public int SizeFailQuantity { get; set; }
        public int ProductNoFailQuantity { get; set; }
 
        public void Clear()
        {
            ProductQuntity = 0;
            PassQuntity = 0;
            FailQuntity = 0;
            HeightPassQuntity = 0;
            HeightFailQuntity = 0;
            SizePassQuantity = 0;
            SizeFailQuantity = 0;
            ProductNoFailQuantity = 0;
            EmptyQuantity = 0;
        }
 
        public MeasureResultTTL()
        {
            Clear();
        }
 
        public override string ToString()
        {
            return string.Format("检测产品总数:{0}, 合格数:{1}, 不合格数:{2}, 合格率:{3};其中高度合格数为{4},不合格数为{5}, 尺寸合格数为{6}, 不合格数为{7})",
                ProductQuntity, PassQuntity, FailQuntity, PassRate, HeightPassQuntity, HeightFailQuntity, SizePassQuantity, SizeFailQuantity);
        }
    }
 
}