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; // } //} } }