jace.tang
2022-06-17 9bc010fc2b51ff02d1f7d09accc2847e3d925777
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
 
namespace M423project
{
    public partial class Replay : Form
    {
        public Replay(OPC Opc)
        {
            InitializeComponent();
            this.opc = Opc;
        }
        OPC opc;
        string[] imagePathDataCode, imagePathXY, imagePathZ;
        //int index=-1;
        int imageIndex;
 
        public int ImageIndex
        {
            get { return this.imageIndex; }
        }
        public string[] ImagePathDataCode
        {
            get { return this.imagePathDataCode; }
        }
        public string[] ImagePathXY
        {
            get { return this.imagePathXY; }
        }
        //public string[] ImagePathXYW
        //{
        //    get { return this.imagePathXYW; }
        //}
        public string[] ImagePathZ
        {
            get { return this.imagePathZ; }
        }
        private bool IsEqual()
        {
            if ((imagePathDataCode.Length == imagePathZ.Length) 
                && (imagePathDataCode.Length == imagePathXY.Length) 
                //&& (imagePathDataCode.Length == imagePathXYW.Length)
                &&(imagePathZ.Length==imagePathXY.Length))
                //&&(imagePathZ.Length==imagePathXYW.Length)
                //&&(imagePathXYL.Length==imagePathXYW.Length))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        private void Replay_Load(object sender, EventArgs e)
        {
            btnLast.Enabled = false;
            btnNext.Enabled = false;
            btnStart.Enabled = false;
        }
 
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (IsEqual())
            {
                btnLast.Enabled = true;
                btnNext.Enabled = true;
                btnStart.Enabled = false;
                imageIndex = -1;
                lbTestNumber.Text = (imageIndex + 1).ToString() + "/" + imagePathDataCode.Length.ToString();
            }
            else
            {
                MessageBox.Show("选择图像数量不一致,请重新选择。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 
        private void btnNext_Click(object sender, EventArgs e)
        {
            imageIndex++;
            //imageIndex = index;
            if (imageIndex > imagePathDataCode.Length - 1)
            {
                imageIndex = imagePathDataCode.Length - 1;
                MessageBox.Show("已到达量测下限!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            lbTestNumber.Text = (imageIndex + 1).ToString() + "/" + imagePathDataCode.Length.ToString();
            opc.Write(OPCOutputTag.DetectionStart2, 1);
        }
 
        private void btnLast_Click(object sender, EventArgs e)
        {
            imageIndex--;
            //imageIndex = index;
            if (imageIndex < 0)
            {
                imageIndex = 0;
                MessageBox.Show("已到达量测上限!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            lbTestNumber.Text = (imageIndex + 1).ToString() + "/" + imagePathDataCode.Length.ToString();
            opc.Write(OPCOutputTag.DetectionStart2, 1);
        }
 
        private void btnSelectDataCode_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "D:\\Image\\" + DateTime.Now.ToString("yyyyMMdd") + "\\2DDataCode";
            ofd.Multiselect = true;
            if (ofd.ShowDialog()==DialogResult.OK)
            {
                imagePathDataCode = ofd.FileNames;
                btnStart.Enabled = true;
            }
        }
 
        private void btnSelectZ_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "D:\\Image\\" + DateTime.Now.ToString("yyyyMMdd") + "\\BatteryHeight";
            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                imagePathZ = ofd.FileNames;
                btnStart.Enabled = true;
            }
        }
 
        private void btnSelectXY_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "D:\\Image\\" + DateTime.Now.ToString("yyyyMMdd") + "\\BatteryLW";
            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                imagePathXY = ofd.FileNames;
                btnStart.Enabled = true;
            }
        }
 
        //private void btnSelectY_Click(object sender, EventArgs e)
        //{
        //    OpenFileDialog ofd = new OpenFileDialog();
        //    ofd.InitialDirectory = "D:\\Image\\" + DateTime.Now.ToString("yyyyMMdd") + "\\BatteryWidth";
        //    ofd.Multiselect = true;
        //    if (ofd.ShowDialog() == DialogResult.OK)
        //    {
        //        imagePathXYW = ofd.FileNames;
        //        btnStart.Enabled = true;
        //    }
        //}
    }
}