Files

419 lines
15 KiB
C#

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;
namespace AGVSystem
{
public partial class frm_card : Form
{
private Label[] l1 = new Label[32];
private Label[] l2 = new Label[32];
private Label[] l3 = new Label[32];
private PictureBox[] pbox1 = new PictureBox[32];
private PictureBox[] pbox2 = new PictureBox[32];
private PictureBox[] pbox3 = new PictureBox[32];
public frm_card()
{
InitializeComponent();
l1[0] = lab1;
l1[1] = lab2;
l1[2] = lab3;
l1[3] = lab4;
l1[4] = lab5;
l1[5] = lab6;
l1[6] = lab7;
l1[7] = lab8;
l1[8] = lab9;
l1[9] = lab10;
l1[10] = lab11;
l1[11] = lab12;
l1[12] = lab13;
l1[13] = lab14;
l1[14] = lab15;
l1[15] = lab16;
l1[16] = lab17;
l1[17] = lab18;
l1[18] = lab19;
l1[19] = lab20;
l1[20] = lab21;
l1[21] = lab22;
l1[22] = lab23;
l1[23] = lab24;
l1[24] = lab25;
l1[25] = lab26;
l1[26] = lab27;
l1[27] = lab28;
l1[28] = lab29;
l1[29] = lab30;
l1[30] = lab31;
l1[31] = lab32;
pbox1[0] = pictureBox1_1;
pbox1[1] = pictureBox1_2;
pbox1[2] = pictureBox1_3;
pbox1[3] = pictureBox1_4;
pbox1[4] = pictureBox1_5;
pbox1[5] = pictureBox1_6;
pbox1[6] = pictureBox1_7;
pbox1[7] = pictureBox1_8;
pbox1[8] = pictureBox1_9;
pbox1[9] = pictureBox1_10;
pbox1[10] = pictureBox1_11;
pbox1[11] = pictureBox1_12;
pbox1[12] = pictureBox1_13;
pbox1[13] = pictureBox1_14;
pbox1[14] = pictureBox1_15;
pbox1[15] = pictureBox1_16;
pbox1[16] = pictureBox1_17;
pbox1[17] = pictureBox1_18;
pbox1[18] = pictureBox1_19;
pbox1[19] = pictureBox1_20;
pbox1[20] = pictureBox1_21;
pbox1[21] = pictureBox1_22;
pbox1[22] = pictureBox1_23;
pbox1[23] = pictureBox1_24;
pbox1[24] = pictureBox1_25;
pbox1[25] = pictureBox1_26;
pbox1[26] = pictureBox1_27;
pbox1[27] = pictureBox1_28;
pbox1[28] = pictureBox1_29;
pbox1[29] = pictureBox1_30;
pbox1[30] = pictureBox1_31;
pbox1[31] = pictureBox1_32;
pbox1[16].Enabled = false;
pbox1[17].Enabled = false;
pbox1[18].Enabled = false;
pbox1[19].Enabled = false;
pbox1[20].Enabled = false;
pbox1[21].Enabled = false;
pbox1[22].Enabled = false;
pbox1[23].Enabled = false;
pbox1[24].Enabled = false;
pbox1[25].Enabled = false;
pbox1[26].Enabled = false;
pbox1[27].Enabled = false;
pbox1[28].Enabled = false;
pbox1[29].Enabled = false;
pbox1[30].Enabled = false;
pbox1[31].Enabled = false;
ClsDBConn_sql db = new ClsDBConn_sql();
DataSet ds = new DataSet();
if (Cls.Param.Card1_Interval > 0)
{
checkBox1.Checked = true;
ds = db.connDt("SELECT [ID] ,[CLASS],[BIT] ,[REMARK] FROM [IO_CARD] where ID='CARD0' ORDER BY[CLASS], [BIT]");
int i = 0;
int ss = ds.Tables[0].Rows.Count;
foreach (DataRow DR in ds.Tables[0].Rows)
{
if (i < 32)
{
l1[i].Text = DR[3].ToString();
i++;
}
}
timer1.Interval = Cls.Param.Card1_Interval+10;
timer1.Enabled = true;
Cls.Param.card1.Output1 = 0;
string temp = Convert.ToString(Cls.Param.card1.Output1, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp.Substring(7 - m, 1) == "0")
pbox1[16 + m].BackgroundImage = Properties.Resources.ledLow;
else
pbox1[16 + m].BackgroundImage = Properties.Resources.ledHigh;
}
temp = Convert.ToString(Cls.Param.card1.Output2, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp.Substring(7 - m, 1) == "0")
pbox1[24 + m].BackgroundImage = Properties.Resources.ledLow;
else
pbox1[24 + m].BackgroundImage = Properties.Resources.ledHigh;
}
for (int m = 0; m < 16; m++)
{
pbox1[16 + m].Click += new EventHandler(picBox1_Click);
}
}
l2[0] = label75;
l2[1] = label74;
l2[2] = label73;
l2[3] = label72;
l2[4] = label71;
l2[5] = label70;
l2[6] = label69;
l2[7] = label68;
l2[8] = label67;
l2[9] = label66;
l2[10] = label65;
l2[11] = label64;
l2[12] = label63;
l2[13] = label62;
l2[14] = label61;
l2[15] = label60;
l2[16] = label33;
l2[17] = label32;
l2[18] = label31;
l2[19] = label30;
l2[20] = label29;
l2[21] = label28;
l2[22] = label27;
l2[23] = label26;
l2[24] = label25;
l2[25] = label24;
l2[26] = label23;
l2[27] = label22;
l2[28] = label21;
l2[29] = label20;
l2[30] = label19;
l2[31] = label18;
pbox2[0] = pictureBox32;
pbox2[1] = pictureBox31;
pbox2[2] = pictureBox30;
pbox2[3] = pictureBox29;
pbox2[4] = pictureBox28;
pbox2[5] = pictureBox27;
pbox2[6] = pictureBox26;
pbox2[7] = pictureBox25;
pbox2[8] = pictureBox24;
pbox2[9] = pictureBox23;
pbox2[10] = pictureBox22;
pbox2[11] = pictureBox21;
pbox2[12] = pictureBox20;
pbox2[13] = pictureBox19;
pbox2[14] = pictureBox18;
pbox2[15] = pictureBox17;
pbox2[16] = pictureBox16;
pbox2[17] = pictureBox15;
pbox2[18] = pictureBox14;
pbox2[19] = pictureBox13;
pbox2[20] = pictureBox12;
pbox2[21] = pictureBox11;
pbox2[22] = pictureBox10;
pbox2[23] = pictureBox9;
pbox2[24] = pictureBox8;
pbox2[25] = pictureBox7;
pbox2[26] = pictureBox6;
pbox2[27] = pictureBox5;
pbox2[28] = pictureBox4;
pbox2[29] = pictureBox3;
pbox2[30] = pictureBox2;
pbox2[31] = pictureBox1;
if (ds.Tables.Count > 0)
ds.Tables.Clear();
if (Cls.Param.Card2_Interval > 0)
{
checkBox2.Checked = true;
ds = db.connDt("SELECT [ID] ,[CLASS],[BIT] ,[REMARK] FROM [IO_CARD] where ID='CARD1' ORDER BY[CLASS], [BIT]");
int i = 0;
foreach (DataRow DR in ds.Tables[0].Rows)
{
l2[i].Text = DR[3].ToString();
i++;
}
timer2.Interval = Cls.Param.Card2_Interval + 10;
timer2.Enabled = true;
string temp = Convert.ToString(Cls.Param.card2.Output1, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp.Substring(7 - m, 1) == "0")
pbox2[16 + m].BackgroundImage = Properties.Resources.ledLow;
else
pbox2[16 + m].BackgroundImage = Properties.Resources.ledHigh;
}
temp = Convert.ToString(Cls.Param.card2.Output2, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp.Substring(7 - m, 1) == "0")
pbox2[24 + m].BackgroundImage = Properties.Resources.ledLow;
else
pbox2[24 + m].BackgroundImage = Properties.Resources.ledHigh;
}
for (int m = 0; m < 16; m++)
{
pbox2[16 + m].Click += new EventHandler(picBox2_Click);
}
}
}
private void picBox1_Click(object sender, EventArgs e)
{
string str;
PictureBox pb = (PictureBox)sender;
if (Convert.ToInt16(pb.Tag) < 9)
{
str = Convert.ToString(Cls.Param.card1.Output1, 2).PadLeft(8, '0');
str = str.Substring(7 - (Convert.ToInt16(pb.Tag) - 1), 1);
if (str == "0")
{
Cls.Param.card1.WriteBit(0, (Convert.ToInt16(pb.Tag) - 1), (byte)1);
pb.BackgroundImage = Properties.Resources.ledHigh;
}
else
{
Cls.Param.card1.WriteBit(0, (Convert.ToInt16(pb.Tag) - 1), (byte)0);
pb.BackgroundImage = Properties.Resources.ledLow;
}
}
else
{
str = Convert.ToString(Cls.Param.card1.Output2, 2).PadLeft(8, '0');
str = str.Substring(7 - (Convert.ToInt16(pb.Tag) - 9), 1);
if (str == "0")
{
Cls.Param.card1.WriteBit(1, (Convert.ToInt16(pb.Tag) - 9), (byte)1);
pb.BackgroundImage = Properties.Resources.ledHigh;
}
else
{
Cls.Param.card1.WriteBit(1, (Convert.ToInt16(pb.Tag) - 9), (byte)0);
pb.BackgroundImage = Properties.Resources.ledLow;
}
}
}
private void picBox2_Click(object sender, EventArgs e)
{
string str;
PictureBox pb = (PictureBox)sender;
if (Convert.ToInt16(pb.Tag) < 9)
{
str = Convert.ToString(Cls.Param.card2.Output1, 2).PadLeft(8, '0');
str = str.Substring(7 - (Convert.ToInt16(pb.Tag) - 1), 1);
if (str == "0")
{
Cls.Param.card2.WriteBit(0, 7 - (Convert.ToInt16(pb.Tag) - 1), (byte)1);
pb.BackgroundImage = Properties.Resources.ledHigh;
}
else
{
Cls.Param.card2.WriteBit(0, 7 - (Convert.ToInt16(pb.Tag) - 1), (byte)0);
pb.BackgroundImage = Properties.Resources.ledLow;
}
}
else
{
str = Convert.ToString(Cls.Param.card2.Output2, 2).PadLeft(8, '0');
str = str.Substring(7 - (Convert.ToInt16(pb.Tag) - 9), 1);
if (str == "0")
{
Cls.Param.card2.WriteBit(0, 7 - (Convert.ToInt16(pb.Tag) - 9), (byte)1);
pb.BackgroundImage = Properties.Resources.ledHigh;
}
else
{
Cls.Param.card2.WriteBit(0, 7 - (Convert.ToInt16(pb.Tag) - 9), (byte)0);
pb.BackgroundImage = Properties.Resources.ledLow;
}
}
}
string temp;
private void timer1_Tick(object sender, EventArgs e)
{
temp = Convert.ToString(Cls.Param.card1.Input1, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp.Substring(7 - m, 1) == "0")
pbox1[ m].BackgroundImage = Properties.Resources.ledLow;
else
pbox1[ m].BackgroundImage = Properties.Resources.ledHigh;
}
temp = Convert.ToString(Cls.Param.card1.Input2, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp.Substring(7 - m, 1) == "0")
pbox1[8 + m].BackgroundImage = Properties.Resources.ledLow;
else
pbox1[8 + m].BackgroundImage = Properties.Resources.ledHigh;
}
}
string temp2;
private void timer2_Tick(object sender, EventArgs e)
{
temp2 = Convert.ToString(Cls.Param.card2.Input1, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp2.Substring(7 - m, 1) == "0")
pbox2[m].BackgroundImage = Properties.Resources.ledLow;
else
pbox2[m].BackgroundImage = Properties.Resources.ledHigh;
}
temp2 = Convert.ToString(Cls.Param.card2.Input2, 2).PadLeft(8, '0');
for (int m = 0; m < 8; m++)
{
if (temp2.Substring(7 - m, 1) == "0")
pbox2[8 + m].BackgroundImage = Properties.Resources.ledLow;
else
pbox2[8 + m].BackgroundImage = Properties.Resources.ledHigh;
}
}
private void frm_card_FormClosed(object sender, FormClosedEventArgs e)
{
mainfrm.frm_card1 = null;
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (checkBox4.Checked)
{
pbox1[16].Enabled = true;
pbox1[17].Enabled = true;
pbox1[18].Enabled = true;
pbox1[19].Enabled = true;
pbox1[20].Enabled = true;
pbox1[21].Enabled = true;
pbox1[22].Enabled = true;
pbox1[23].Enabled = true;
pbox1[24].Enabled = true;
pbox1[25].Enabled = true;
pbox1[26].Enabled = true;
pbox1[27].Enabled = true;
pbox1[28].Enabled = true;
pbox1[29].Enabled = true;
pbox1[30].Enabled = true;
pbox1[31].Enabled = true;
}
else
{
pbox1[16].Enabled = false;
pbox1[17].Enabled = false;
pbox1[18].Enabled = false;
pbox1[19].Enabled = false;
pbox1[20].Enabled = false;
pbox1[21].Enabled = false;
pbox1[22].Enabled = false;
pbox1[23].Enabled = false;
pbox1[24].Enabled = false;
pbox1[25].Enabled = false;
pbox1[26].Enabled = false;
pbox1[27].Enabled = false;
pbox1[28].Enabled = false;
pbox1[29].Enabled = false;
pbox1[30].Enabled = false;
pbox1[31].Enabled = false;
}
}
}
}