You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

771 lines
23 KiB

using ChipGlueDeviceManager.CommonFunctions;
using Module.Common;
using Module.Plc.Profinet.Tool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Module.DB.Model;
using RailSee.LogService;
namespace ChipGlueDeviceManager
{
public partial class FrmT1Glue : Form
{
private delegate void PrintChartParamCallBack(); //委托事件
private PrintChartParamCallBack DgChartParamRealValue;
private bool IsPrintReadValue = true;
#region 基础字段
string yy1 = "";
string dj1 = "";
string hx1 = "";
string xj1 = "";
string yy2 = "";
string dj2 = "";
string hx2 = "";
string xj2 = "";
string yy3 = "";
string dj3 = "";
string hx3 = "";
string xj3 = "";
bool pr1Enable = false;
bool pr1Empty = false;
bool pr1Execute = false;
bool pr2Enable = false;
bool pr2Empty = false;
bool pr2Execute = false;
bool pr3Enable = false;
bool pr3Empty = false;
bool pr3Execute = false;
string yy1Pre = "";
string dj1Pre = "";
string hx1Pre = "";
string xj1Pre = "";
string yy2Pre = "";
string dj2Pre = "";
string hx2Pre = "";
string xj2Pre = "";
string yy3Pre = "";
string dj3Pre = "";
string hx3Pre = "";
string xj3Pre = "";
bool pr1EnablePre = false;
bool pr1EmptyPre = false;
bool pr1ExecutePre = false;
bool pr2EnablePre = false;
bool pr2EmptyPre = false;
bool pr2ExecutePre = false;
bool pr3EnablePre = false;
bool pr3EmptyPre = false;
bool pr3ExecutePre = false;
int glue01Result = 99; //打胶1是否打胶PLC值
int glue02Result = 99; //打胶2是否打胶PLC值
int glue03Result = 99; //打胶3是否打胶PLC值
GlueModel glueModelResult = null; //打胶参数值
bool[] yBits = null; //通道1胶棒阀状态
#endregion 基础字段
public FrmT1Glue()
{
InitializeComponent();
}
private void FrmGlue_Load(object sender, EventArgs e)
{
//开始显示实时值线程
Thread printRealValueThread = new Thread(StartPrintRealValue);
printRealValueThread.IsBackground = true;
printRealValueThread.Start();
DgChartParamRealValue = new PrintChartParamCallBack(PrintRealValueChart); //展示实时值
}
/// <summary>
/// 展示实时值
/// </summary>
private void PrintRealValueChart()
{
try
{
if (glueModelResult != null)
{
yy1 = glueModelResult.pr1Yy;
dj1 = glueModelResult.pr1Dj;
hx1 = glueModelResult.pr1Hx;
xj1 = glueModelResult.pr1Xj;
yy2 = glueModelResult.pr2Yy;
dj2 = glueModelResult.pr2Dj;
hx2 = glueModelResult.pr2Hx;
xj2 = glueModelResult.pr2Xj;
yy3 = glueModelResult.pr3Yy;
dj3 = glueModelResult.pr3Dj;
hx3 = glueModelResult.pr3Hx;
xj3 = glueModelResult.pr3Xj;
pr1Enable = glueModelResult.pr1Enable;
pr1Empty = glueModelResult.pr1Empty;
pr1Execute = glueModelResult.pr1Execute;
pr2Enable = glueModelResult.pr2Enable;
pr2Empty = glueModelResult.pr2Empty;
pr2Execute = glueModelResult.pr2Execute;
pr3Enable = glueModelResult.pr3Enable;
pr3Empty = glueModelResult.pr3Empty;
pr3Execute = glueModelResult.pr3Execute;
TextStatus(tbYy1, yy1Pre, yy1);
TextStatus(tbDj1, dj1Pre, dj1);
TextStatus(tbHx1, hx1Pre, hx1);
TextStatus(tbXj1, xj1Pre, xj1);
TextStatus(tbYy2, yy2Pre, yy2);
TextStatus(tbDj2, dj2Pre, dj2);
TextStatus(tbHx2, hx2Pre, hx2);
TextStatus(tbXj2, xj2Pre, xj2);
TextStatus(tbYy3, yy3Pre, yy3);
TextStatus(tbDj3, dj3Pre, dj3);
TextStatus(tbHx3, hx3Pre, hx3);
TextStatus(tbXj3, xj3Pre, xj3);
TextStatus(checkBoxEnable1, pr1EnablePre, pr1Enable);
TextStatus(checkBoxEmpty1, pr1EmptyPre, pr1Empty);
TextStatus(checkBoxYwpb1, pr1ExecutePre, pr1Execute);
TextStatus(checkBoxEnable2, pr2EnablePre, pr2Enable);
TextStatus(checkBoxEmpty2, pr2EmptyPre, pr2Empty);
TextStatus(checkBoxYwpb2, pr2ExecutePre, pr2Execute);
TextStatus(checkBoxEnable3, pr3EnablePre, pr3Enable);
TextStatus(checkBoxEmpty3, pr3EmptyPre, pr3Empty);
TextStatus(checkBoxYwpb3, pr3ExecutePre, pr3Execute);
pr1EnablePre = pr1Enable;
pr1EmptyPre = pr1Empty;
pr1ExecutePre = pr1Execute;
pr2EnablePre = pr2Enable;
pr2EmptyPre = pr2Empty;
pr2ExecutePre = pr2Execute;
pr3EnablePre = pr3Enable;
pr3EmptyPre = pr3Empty;
pr3ExecutePre = pr3Execute;
yy1Pre = yy1;
dj1Pre = dj1;
hx1Pre = hx1;
xj1Pre = xj1;
yy2Pre = yy2;
dj2Pre = dj2;
hx2Pre = hx2;
xj2Pre = xj2;
yy3Pre = yy3;
dj3Pre = dj3;
hx3Pre = hx3;
xj3Pre = xj3;
}
if (yBits != null)
{
if (yBits.Count() >= 14)
{
LabelStatus1Color(lblY402, yBits[2]);
LabelStatus1Color(lblY403, yBits[3]);
LabelStatus1Color(lblY404, yBits[4]);
LabelStatus1Color(lblY405, yBits[5]);
LabelStatus1Color(lblY406, yBits[6]);
LabelStatus1Color(lblY407, yBits[7]);
LabelStatus1Color(lblY408, yBits[8]);
LabelStatus1Color(lblY409, yBits[9]);
LabelStatus1Color(lblY410, yBits[10]);
LabelStatus1Color(lblY411, yBits[11]);
LabelStatus1Color(lblY412, yBits[12]);
LabelStatus1Color(lblY413, yBits[13]);
}
}
ButtonStatusColor(btnExecute1, glue01Result);
ButtonStatusColor(btnExecute2, glue02Result);
ButtonStatusColor(btnExecute3, glue03Result);
}
catch(Exception ex)
{
Log.LogInstance.WriteLog(ex.ToString(), LogType.Run, "MessageLogUnit");
}
}
private void StartPrintRealValue()
{
while (IsPrintReadValue)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(DgChartParamRealValue, null);
}
glueModelResult = PublicParams.T1GlueModelResult; //打胶参数值
yBits = PublicParams.T1YBits; //通道1胶棒阀状态
glue01Result = PublicParams.T1Glue01Result;
glue02Result = PublicParams.T1Glue02Result;
glue03Result = PublicParams.T1Glue03Result;
Thread.Sleep(100);
}
}
/// <summary>
/// 按钮随着值变化颜色改变
/// </summary>
/// <param name="btnColor"></param>
/// <param name="value"></param>
private void ButtonStatusColor(Button btnColor, int value)
{
if (value == 1)
{
btnColor.BackColor = PublicParams.buttonDownColor;
}
else
{
btnColor.BackColor = SystemColors.Control;
}
}
private void LabelStatus1Color(Label lblColor, bool value)
{
if (value)
{
lblColor.BackColor = PublicParams.buttonDownColor;
}
else
{
lblColor.BackColor = System.Drawing.SystemColors.ControlLight;
}
}
private void TextStatus(TextBox txtValue, string preValue, string value)
{
if (preValue == value)
{
return;
}
txtValue.Text = value;
}
private void TextStatus(CheckBox txtValue, bool preValue, bool value)
{
if (preValue.Equals(value))
{
return;
}
txtValue.Checked = value;
}
private void tbYy1_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbYy1_Update();
}
private void tbYy1_Leave(object sender, EventArgs e)
{
tbYy1_Update();
}
private void tbYy1_Update()
{
if (!checkText(tbYy1.Text))
{
return;
}
tbYy1.Text = Math.Round(Convert.ToDecimal(tbYy1.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbYy1.Text.Trim()) * 10);
T1GlueControlFunc.SetYy(1, value);
}
private void tbDj1_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbDj1_Update();
}
private void tbDj1_Leave(object sender, EventArgs e)
{
tbDj1_Update();
}
private void tbDj1_Update()
{
if (!checkText(tbDj1.Text))
{
return;
}
tbDj1.Text = Math.Round(Convert.ToDecimal(tbDj1.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbDj1.Text.Trim()) * 10);
T1GlueControlFunc.SetDj(1, value);
}
private void tbHx1_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbHx1_Update();
}
private void tbHx1_Leave(object sender, EventArgs e)
{
tbHx1_Update();
}
private void tbHx1_Update()
{
if (!checkText(tbHx1.Text))
{
return;
}
FormValidate.NumberMinMaxValueReset(tbHx1, 0.10, 32.00);
tbHx1.Text = Math.Round(Convert.ToDecimal(tbHx1.Text.Trim()), 2).ToString("#0.00");
short value = Convert.ToInt16(Convert.ToSingle(tbHx1.Text.Trim()) * 1000);
T1GlueControlFunc.SetHx(1, value);
}
private void tbXj1_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbXj1_Update();
}
private void tbXj1_Leave(object sender, EventArgs e)
{
tbXj1_Update();
}
private void tbXj1_Update()
{
try
{
if (!checkText(tbXj1.Text))
{
return;
}
tbXj1.Text = Math.Round(Convert.ToDecimal(tbXj1.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbXj1.Text.Trim()) * 10);
T1GlueControlFunc.SetXj(1, value);
}
catch(Exception ex)
{
ex.ToString();
}
}
private bool checkIsEnterCode(KeyEventArgs e)
{
return Keys.Enter == e.KeyCode;
}
private bool checkText(String text)
{
text = text.Trim();
if (String.IsNullOrEmpty(text))
{
return false;
}
return ValidateUtils.IsNumberOrDecimalSign(text);
}
private void checkBoxEnable1_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(1, 0, checkBoxEnable1.Checked);
}
private void checkBoxEmpty1_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(1, 1, checkBoxEmpty1.Checked);
}
private void checkBoxYwpb1_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(1, 3, checkBoxYwpb1.Checked);
}
private void btnExecute1_Click(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValueOpposite(1, 2);
}
private void checkBoxEnable2_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(2, 0, checkBoxEnable2.Checked);
}
private void checkBoxEmpty2_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(2, 1, checkBoxEmpty2.Checked);
}
private void checkBoxYwpb2_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(2, 3, checkBoxYwpb2.Checked);
}
private void btnExecute2_Click(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValueOpposite(2, 2);
}
private void checkBoxEnable3_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(3, 0, checkBoxEnable3.Checked);
}
private void checkBoxEmpty3_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(3, 1, checkBoxEmpty3.Checked);
}
private void checkBoxYwpb3_CheckedChanged(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValue(3, 3, checkBoxYwpb3.Checked);
}
private void btnExecute3_Click(object sender, EventArgs e)
{
T1GlueControlFunc.setNumberLocationValueOpposite(3, 2);
}
private void tbYy2_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbYy2_Update();
}
private void tbYy2_Leave(object sender, EventArgs e)
{
tbYy2_Update();
}
private void tbYy2_Update()
{
if (!checkText(tbYy2.Text))
{
return;
}
tbYy2.Text = Math.Round(Convert.ToDecimal(tbYy2.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbYy2.Text.Trim()) * 10);
T1GlueControlFunc.SetYy(2, value);
}
private void tbDj2_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbDj2_Update();
}
private void tbDj2_Leave(object sender, EventArgs e)
{
tbDj2_Update();
}
private void tbDj2_Update()
{
if (!checkText(tbDj2.Text))
{
return;
}
tbDj2.Text = Math.Round(Convert.ToDecimal(tbDj2.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbDj2.Text.Trim()) * 10);
T1GlueControlFunc.SetDj(2, value);
}
private void tbHx2_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbHx2_Update();
}
private void tbHx2_Leave(object sender, EventArgs e)
{
tbHx2_Update();
}
private void tbHx2_Update()
{
if (!checkText(tbHx2.Text))
{
return;
}
FormValidate.NumberMinMaxValueReset(tbHx2, 0.10, 32.00);
tbHx2.Text = Math.Round(Convert.ToDecimal(tbHx2.Text.Trim()), 2).ToString("#0.00");
short value = Convert.ToInt16(Convert.ToSingle(tbHx2.Text.Trim()) * 1000);
T1GlueControlFunc.SetHx(2, value);
}
private void tbXj2_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbXj2_Update();
}
private void tbXj2_Leave(object sender, EventArgs e)
{
tbXj2_Update();
}
private void tbXj2_Update()
{
if (!checkText(tbXj2.Text))
{
return;
}
tbXj2.Text = Math.Round(Convert.ToDecimal(tbXj2.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbXj2.Text.Trim()) * 10);
T1GlueControlFunc.SetXj(2, value);
}
private void tbYy3_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbYy3_Update();
}
private void tbYy3_Leave(object sender, EventArgs e)
{
tbYy3_Update();
}
private void tbYy3_Update()
{
if (!checkText(tbYy3.Text))
{
return;
}
tbYy3.Text = Math.Round(Convert.ToDecimal(tbYy3.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbYy3.Text.Trim()) * 10);
T1GlueControlFunc.SetYy(3, value);
}
private void tbDj3_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbDj3_Update();
}
private void tbDj3_Leave(object sender, EventArgs e)
{
tbDj3_Update();
}
private void tbDj3_Update()
{
if (!checkText(tbDj3.Text))
{
return;
}
tbDj3.Text = Math.Round(Convert.ToDecimal(tbDj3.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbDj3.Text.Trim()) * 10);
T1GlueControlFunc.SetDj(3, value);
}
private void tbHx3_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbHx3_Update();
}
private void tbHx3_Leave(object sender, EventArgs e)
{
tbHx3_Update();
}
private void tbHx3_Update()
{
if (!checkText(tbHx3.Text))
{
return;
}
FormValidate.NumberMinMaxValueReset(tbHx3, 0.10, 32.00);
tbHx3.Text = Math.Round(Convert.ToDecimal(tbHx3.Text.Trim()), 2).ToString("#0.00");
short value = Convert.ToInt16(Convert.ToSingle(tbHx3.Text.Trim()) * 1000);
T1GlueControlFunc.SetHx(3, value);
}
private void tbXj3_KeyDown(object sender, KeyEventArgs e)
{
if (!checkIsEnterCode(e))
{
return;
}
tbXj3_Update();
}
private void tbXj3_Leave(object sender, EventArgs e)
{
tbXj3_Update();
}
private void tbXj3_Update()
{
if (!checkText(tbXj3.Text))
{
return;
}
tbXj3.Text = Math.Round(Convert.ToDecimal(tbXj3.Text.Trim()), 1).ToString("#0.0");
short value = Convert.ToInt16(Convert.ToSingle(tbXj3.Text.Trim()) * 10);
T1GlueControlFunc.SetXj(3, value);
}
private void tbYy1_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbDj1_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbHx1_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbXj1_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbYy2_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbDj2_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbHx2_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbXj2_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbYy3_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbDj3_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbHx3_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void tbXj3_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
private void btnExecute1_MouseDown(object sender, MouseEventArgs e)
{
//T1GlueControlFunc.setNumberLocationValueOpposite(1, 2);
}
private void btnExecute1_MouseUp(object sender, MouseEventArgs e)
{
//T1GlueControlFunc.setNumberLocationValueOppositeClose(1, 2);
}
private void btnExecute2_MouseDown(object sender, MouseEventArgs e)
{
//T1GlueControlFunc.setNumberLocationValueOpposite(2, 2);
}
private void btnExecute2_MouseUp(object sender, MouseEventArgs e)
{
//T1GlueControlFunc.setNumberLocationValueOppositeClose(2, 2);
}
private void btnExecute3_MouseDown(object sender, MouseEventArgs e)
{
//T1GlueControlFunc.setNumberLocationValueOpposite(3, 2);
}
private void btnExecute3_MouseUp(object sender, MouseEventArgs e)
{
//T1GlueControlFunc.setNumberLocationValueOppositeClose(3, 2);
}
}
}