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

1051 lines
46 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Estsh.Client.Base;
namespace Estsh.Client.StepLibrary
{
public partial class TorqueCollect : StepBase
{
TorqueCollectApp _app = null;
private List<dynamic> _dtKeydataItems = null; //当前工位采集数据需求
private List<dynamic> _dtKeydataItemsLast = null; //上一工位采集数据需求
private string _StepSn = string.Empty; //RFID中过程条码
private string terminalId = string.Empty; //工位ID
private string terminalIdLast = string.Empty; //上一工位ID
private bool isFirstFinished = false; //首次执行轮循是否完成
private bool _OK = true;
private bool _NG = true;
#region 程序控件定义
private Timer CollectKeydata;
private Panel plHead;
private Label lblOption;
private Label lblReceiveTitle;
private Label lblHeadPic;
private Label lblHead;
private Panel plDone;
private Panel plLast;
private Panel plFinish;
private Label lblQtySum;
private Label lblOf;
private Label lblQtyFact;
private Label lblFinish;
private Panel plData;
private DataGridView dgvTorqueCollect;
private DataGridViewTextBoxColumn keydata_seq;
private DataGridViewTextBoxColumn keydata_status;
private DataGridViewTextBoxColumn keydata_name;
private DataGridViewTextBoxColumn value;
private DataGridViewTextBoxColumn keydata_value;
private DataGridViewTextBoxColumn keydata_angle;
private DataGridViewTextBoxColumn keydata_id;
private DataGridViewTextBoxColumn item_count;
private DataGridViewTextBoxColumn keydata_desc;
private DataGridViewTextBoxColumn min_value;
private DataGridViewTextBoxColumn max_value;
private DataGridViewTextBoxColumn keydata_result;
private DataGridViewTextBoxColumn keydata_ymd;
private DataGridViewTextBoxColumn keydata_hms;
private System.ComponentModel.IContainer components;
#endregion
public TorqueCollect()
{
InitializeComponent();
}
public override bool Do()
{
try
{
//清空混合表
mergeDT = null;
this.Visible = true;
this.BringToFront();
ShowMessage(this, "green|正在采集扭矩信息...");
isFirstFinished = false;
_app = new TorqueCollectApp(App);
//_StepSn = Context["serial_number"].ToString();
terminalId = Context["terminal_id"].ToString();
terminalIdLast = terminalId;
this.SetLastTerminalData();
this.WriteKeydataItems();
this.WriteKeydataItmesLast();
CollectKeydata.Enabled = true;
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
return base.Do();
}
#region 界面控件定义
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TorqueCollect));
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
this.CollectKeydata = new System.Windows.Forms.Timer(this.components);
this.plHead = new System.Windows.Forms.Panel();
this.lblHeadPic = new System.Windows.Forms.Label();
this.lblHead = new System.Windows.Forms.Label();
this.lblOption = new System.Windows.Forms.Label();
this.lblReceiveTitle = new System.Windows.Forms.Label();
this.plDone = new System.Windows.Forms.Panel();
this.plLast = new System.Windows.Forms.Panel();
this.plFinish = new System.Windows.Forms.Panel();
this.lblQtySum = new System.Windows.Forms.Label();
this.lblOf = new System.Windows.Forms.Label();
this.lblQtyFact = new System.Windows.Forms.Label();
this.lblFinish = new System.Windows.Forms.Label();
this.plData = new System.Windows.Forms.Panel();
this.dgvTorqueCollect = new System.Windows.Forms.DataGridView();
this.keydata_seq = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_status = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_angle = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.item_count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_desc = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.min_value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.max_value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_result = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_ymd = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keydata_hms = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.plHead.SuspendLayout();
this.plDone.SuspendLayout();
this.plFinish.SuspendLayout();
this.plData.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvTorqueCollect)).BeginInit();
this.SuspendLayout();
//
// CollectKeydata
//
this.CollectKeydata.Interval = 797;
this.CollectKeydata.Tick += new System.EventHandler(this.CollectKeydata_Tick);
//
// plHead
//
this.plHead.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.plHead.Controls.Add(this.lblHeadPic);
this.plHead.Controls.Add(this.lblHead);
this.plHead.Location = new System.Drawing.Point(-1, 0);
this.plHead.Name = "plHead";
this.plHead.Size = new System.Drawing.Size(929, 75);
this.plHead.TabIndex = 6;
//
// lblHeadPic
//
this.lblHeadPic.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lblHeadPic.BackColor = System.Drawing.Color.LightGray;
this.lblHeadPic.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblHeadPic.Font = new System.Drawing.Font("宋体", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblHeadPic.Image = ((System.Drawing.Image)(resources.GetObject("lblHeadPic.Image")));
this.lblHeadPic.Location = new System.Drawing.Point(2, 0);
this.lblHeadPic.Name = "lblHeadPic";
this.lblHeadPic.Size = new System.Drawing.Size(85, 75);
this.lblHeadPic.TabIndex = 7;
this.lblHeadPic.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblHead
//
this.lblHead.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblHead.BackColor = System.Drawing.Color.LightGray;
this.lblHead.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblHead.Font = new System.Drawing.Font("微软雅黑", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblHead.Location = new System.Drawing.Point(87, 0);
this.lblHead.Name = "lblHead";
this.lblHead.Size = new System.Drawing.Size(841, 75);
this.lblHead.TabIndex = 6;
this.lblHead.Text = "关键数据信息采集";
this.lblHead.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblOption
//
this.lblOption.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblOption.BackColor = System.Drawing.Color.Violet;
this.lblOption.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblOption.Font = new System.Drawing.Font("微软雅黑", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblOption.Location = new System.Drawing.Point(1, 75);
this.lblOption.Name = "lblOption";
this.lblOption.Size = new System.Drawing.Size(927, 35);
this.lblOption.TabIndex = 0;
this.lblOption.Text = " 操作提示";
this.lblOption.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblReceiveTitle
//
this.lblReceiveTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblReceiveTitle.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.lblReceiveTitle.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblReceiveTitle.Font = new System.Drawing.Font("微软雅黑", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblReceiveTitle.Location = new System.Drawing.Point(1, 183);
this.lblReceiveTitle.Name = "lblReceiveTitle";
this.lblReceiveTitle.Size = new System.Drawing.Size(927, 35);
this.lblReceiveTitle.TabIndex = 10;
this.lblReceiveTitle.Text = " 关键数据信息";
this.lblReceiveTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// plDone
//
this.plDone.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.plDone.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.plDone.Controls.Add(this.plLast);
this.plDone.Controls.Add(this.plFinish);
this.plDone.Location = new System.Drawing.Point(1, 110);
this.plDone.Name = "plDone";
this.plDone.Size = new System.Drawing.Size(927, 73);
this.plDone.TabIndex = 11;
//
// plLast
//
this.plLast.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.plLast.BackColor = System.Drawing.Color.Green;
this.plLast.Location = new System.Drawing.Point(347, 0);
this.plLast.Name = "plLast";
this.plLast.Size = new System.Drawing.Size(579, 71);
this.plLast.TabIndex = 10;
//
// plFinish
//
this.plFinish.BackColor = System.Drawing.Color.Green;
this.plFinish.Controls.Add(this.lblQtySum);
this.plFinish.Controls.Add(this.lblOf);
this.plFinish.Controls.Add(this.lblQtyFact);
this.plFinish.Controls.Add(this.lblFinish);
this.plFinish.Location = new System.Drawing.Point(0, 0);
this.plFinish.Name = "plFinish";
this.plFinish.Size = new System.Drawing.Size(350, 71);
this.plFinish.TabIndex = 9;
//
// lblQtySum
//
this.lblQtySum.Font = new System.Drawing.Font("微软雅黑", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblQtySum.Location = new System.Drawing.Point(275, 13);
this.lblQtySum.Name = "lblQtySum";
this.lblQtySum.Size = new System.Drawing.Size(67, 48);
this.lblQtySum.TabIndex = 3;
this.lblQtySum.Text = "0";
this.lblQtySum.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblOf
//
this.lblOf.Font = new System.Drawing.Font("微软雅黑", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblOf.Location = new System.Drawing.Point(198, 13);
this.lblOf.Name = "lblOf";
this.lblOf.Size = new System.Drawing.Size(67, 48);
this.lblOf.TabIndex = 2;
this.lblOf.Text = "of";
this.lblOf.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblQtyFact
//
this.lblQtyFact.Font = new System.Drawing.Font("微软雅黑", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblQtyFact.Location = new System.Drawing.Point(121, 13);
this.lblQtyFact.Name = "lblQtyFact";
this.lblQtyFact.Size = new System.Drawing.Size(67, 48);
this.lblQtyFact.TabIndex = 1;
this.lblQtyFact.Text = "0";
this.lblQtyFact.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblFinish
//
this.lblFinish.Font = new System.Drawing.Font("微软雅黑", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblFinish.Location = new System.Drawing.Point(5, 10);
this.lblFinish.Name = "lblFinish";
this.lblFinish.Size = new System.Drawing.Size(125, 48);
this.lblFinish.TabIndex = 0;
this.lblFinish.Text = "完成:";
this.lblFinish.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// plData
//
this.plData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.plData.Controls.Add(this.dgvTorqueCollect);
this.plData.Location = new System.Drawing.Point(1, 218);
this.plData.Name = "plData";
this.plData.Size = new System.Drawing.Size(926, 606);
this.plData.TabIndex = 15;
//
// dgvTorqueCollect
//
this.dgvTorqueCollect.AllowUserToAddRows = false;
this.dgvTorqueCollect.AllowUserToDeleteRows = false;
this.dgvTorqueCollect.BackgroundColor = System.Drawing.Color.White;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 21F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dgvTorqueCollect.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.dgvTorqueCollect.ColumnHeadersHeight = 51;
this.dgvTorqueCollect.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.keydata_seq,
this.keydata_status,
this.keydata_name,
this.value,
this.keydata_value,
this.keydata_angle,
this.keydata_id,
this.item_count,
this.keydata_desc,
this.min_value,
this.max_value,
this.keydata_result,
this.keydata_ymd,
this.keydata_hms});
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dgvTorqueCollect.DefaultCellStyle = dataGridViewCellStyle2;
this.dgvTorqueCollect.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgvTorqueCollect.Location = new System.Drawing.Point(0, 0);
this.dgvTorqueCollect.Name = "dgvTorqueCollect";
this.dgvTorqueCollect.ReadOnly = true;
this.dgvTorqueCollect.RowHeadersVisible = false;
this.dgvTorqueCollect.RowTemplate.Height = 50;
this.dgvTorqueCollect.Size = new System.Drawing.Size(926, 606);
this.dgvTorqueCollect.TabIndex = 11;
this.dgvTorqueCollect.SelectionChanged += new System.EventHandler(this.dgvTorqueCollect_SelectionChanged_1);
//
// keydata_seq
//
this.keydata_seq.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
this.keydata_seq.DataPropertyName = "seq";
this.keydata_seq.HeaderText = "";
this.keydata_seq.MinimumWidth = 80;
this.keydata_seq.Name = "keydata_seq";
this.keydata_seq.ReadOnly = true;
this.keydata_seq.Width = 80;
//
// keydata_status
//
this.keydata_status.DataPropertyName = "keydata_status";
this.keydata_status.HeaderText = "状态";
this.keydata_status.MinimumWidth = 160;
this.keydata_status.Name = "keydata_status";
this.keydata_status.ReadOnly = true;
this.keydata_status.Visible = false;
this.keydata_status.Width = 160;
//
// keydata_name
//
this.keydata_name.DataPropertyName = "keydata_name";
this.keydata_name.HeaderText = "项目名称";
this.keydata_name.MinimumWidth = 250;
this.keydata_name.Name = "keydata_name";
this.keydata_name.ReadOnly = true;
this.keydata_name.Width = 250;
//
// value
//
this.value.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.value.DataPropertyName = "value";
this.value.HeaderText = "标准值";
this.value.Name = "value";
this.value.ReadOnly = true;
//
// keydata_value
//
this.keydata_value.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.keydata_value.DataPropertyName = "keydata_value";
this.keydata_value.HeaderText = "结果值";
this.keydata_value.MinimumWidth = 100;
this.keydata_value.Name = "keydata_value";
this.keydata_value.ReadOnly = true;
//
// keydata_angle
//
this.keydata_angle.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.keydata_angle.DataPropertyName = "keydata_angle";
this.keydata_angle.HeaderText = "角度值";
this.keydata_angle.MinimumWidth = 100;
this.keydata_angle.Name = "keydata_angle";
this.keydata_angle.ReadOnly = true;
//
// keydata_id
//
this.keydata_id.DataPropertyName = "keydata_id";
this.keydata_id.HeaderText = "keydata_id";
this.keydata_id.Name = "keydata_id";
this.keydata_id.ReadOnly = true;
this.keydata_id.Visible = false;
//
// item_count
//
this.item_count.DataPropertyName = "item_count";
this.item_count.HeaderText = "item_count";
this.item_count.Name = "item_count";
this.item_count.ReadOnly = true;
this.item_count.Visible = false;
//
// keydata_desc
//
this.keydata_desc.DataPropertyName = "keydata_desc";
this.keydata_desc.HeaderText = "项目描述";
this.keydata_desc.Name = "keydata_desc";
this.keydata_desc.ReadOnly = true;
this.keydata_desc.Visible = false;
//
// min_value
//
this.min_value.DataPropertyName = "min_value";
this.min_value.HeaderText = "最小值";
this.min_value.Name = "min_value";
this.min_value.ReadOnly = true;
this.min_value.Visible = false;
//
// max_value
//
this.max_value.DataPropertyName = "max_value";
this.max_value.HeaderText = "最大值";
this.max_value.Name = "max_value";
this.max_value.ReadOnly = true;
this.max_value.Visible = false;
//
// keydata_result
//
this.keydata_result.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.keydata_result.DataPropertyName = "keydata_result";
this.keydata_result.HeaderText = "结果";
this.keydata_result.Name = "keydata_result";
this.keydata_result.ReadOnly = true;
this.keydata_result.Visible = false;
//
// keydata_ymd
//
this.keydata_ymd.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.keydata_ymd.DataPropertyName = "keydata_ymd";
this.keydata_ymd.HeaderText = "日期";
this.keydata_ymd.Name = "keydata_ymd";
this.keydata_ymd.ReadOnly = true;
this.keydata_ymd.Visible = false;
//
// keydata_hms
//
this.keydata_hms.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.keydata_hms.DataPropertyName = "keydata_hms";
this.keydata_hms.HeaderText = "时间";
this.keydata_hms.Name = "keydata_hms";
this.keydata_hms.ReadOnly = true;
this.keydata_hms.Visible = false;
//
// TorqueCollect
//
this.Controls.Add(this.plData);
this.Controls.Add(this.plDone);
this.Controls.Add(this.lblReceiveTitle);
this.Controls.Add(this.lblOption);
this.Controls.Add(this.plHead);
this.Name = "TorqueCollect";
this.Size = new System.Drawing.Size(931, 824);
this.plHead.ResumeLayout(false);
this.plDone.ResumeLayout(false);
this.plFinish.ResumeLayout(false);
this.plData.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgvTorqueCollect)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 获取上一工位信息,如果存在则赋值给对应变量
/// </summary>
private void SetLastTerminalData()
{
try
{
//获取服务器配置信息(格式:当前工位ID|上一工位ID当前工位ID2|上一工位ID2
string terminalGroup = _app.GetTerminalGroupValue();
if (string.IsNullOrEmpty(terminalGroup))
{
return;
}
if (terminalGroup.IndexOf(terminalId + "|") < 0)
{
return;
}
string split = ",";
string singleValue = string.Empty;
if (terminalGroup.IndexOf(split) < 0)
{
singleValue = terminalGroup;
}
else
{
string[] array = null;
array = terminalGroup.Split(split.ToCharArray());
if (array.Length < 0)
{
return;
}
for (int i = 0; i < array.Length; i++)
{
if (array[i].IndexOf(terminalId + "|") >= 0)
{
singleValue = array[i];
break;
}
}
}
if (string.IsNullOrEmpty(singleValue))
{
return;
}
string temp = singleValue.Replace(terminalId + "|", "");
if (string.IsNullOrEmpty(temp))
{
return;
}
//上一工位ID赋值
terminalIdLast = temp;
if (terminalIdLast != terminalId)
{
}
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
private void CollectKeydata_Tick(object sender, EventArgs e)
{
try
{
if (!isFirstFinished && terminalId != terminalIdLast)
{
this.WriteKeydataFactValueLast();
isFirstFinished = true;
}
this.WriteKeydataFactValue();
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
/// <summary>
/// 关键零件需求数量写入DGV中
/// </summary>
/// <param name="sn">条码</param>
/// <param name="terminalId">工位ID</param>
public void WriteKeydataItems()
{
try
{
_dtKeydataItems = _app.GetKeyData(Context["serial_number"].ToString(), terminalId, 0);
if (_dtKeydataItems == null || _dtKeydataItems.Count < 1)
{
return;
}
dgvTorqueCollect.DataSource = _dtKeydataItems;
dgvTorqueCollect.Update();
for (int i = 0; i < _dtKeydataItems.Count; i++)
{
dgvTorqueCollect[i].DefaultCellStyle.BackColor = Color.Yellow;
}
lblQtySum.Text = _dtKeydataItems.Count.ToString();
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
/// <summary>
/// 有上一工位验证功能,则写入上一工位已采集数据
/// </summary>
/// <param name="sn">条码信息</param>
public void WriteKeydataItmesLast()
{
try
{
//如果为有上一工位验证功能,则写入上一工位已采集数据
if (terminalId != terminalIdLast)
{
_dtKeydataItemsLast = _app.GetKeyData(Context["serial_number"].ToString(), terminalIdLast, 0);
if (_dtKeydataItemsLast == null || _dtKeydataItemsLast.Count < 1)
{
return;
}
}
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
/// <summary>
/// 将已获取的关键数据更新至程序数据网格中
/// </summary>
/// <param name="sn">条码</param>
/// <param name="terminalId">工位ID</param>
public void WriteKeydataFactValue()
{
try
{
int keydataItemsCount = _dtKeydataItems.Count;
if (keydataItemsCount == 0)
{
CollectKeydata.Enabled = false;
isFirstFinished = false;
// 记录日志
using (StreamWriter sw = new StreamWriter("Step_Log_" + DateTime.Now.ToString("yyyy-MM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", " 条码:" + Context["serial_number"].ToString() + " 当前工位ID:[" + terminalId + "] 不需要采集扭矩或没有配置零件关键数据。准备调取工步完成方法!"));
sw.Flush();
sw.Close();
}
// 工步完成
Complate(this, null);
}
//获取当前工位操作的扭矩信息
List<dynamic> dt = _app.GetKeyDataValue(Context["serial_number"].ToString(), terminalId);
//把前一工位的坐靠结合扭矩信息转移过来
if (mergeDT != null)
{
//忽略补打工位的坐靠结合扭矩信息;
//操作人员没有注意不需要补打坐靠结合,进行了补打操作时会造成显示背景不变的问题
for (int i = 0; i < dt.Count; i++)
{
string keyDataDesc = dt[i]["keydata_desc"].ToString();
//DFPV座靠结合扭矩补打01为补打工位的坐靠结合扭矩枪
if (keyDataDesc == "DFPV座靠结合扭矩补打01")
{
dt.Remove(dt[i]);
}
}
//合并前一工位和当前工位的扭矩信息
List<dynamic> tempDT = null;
tempDT = mergeDT.Copy();
tempDT.Merge(dt);
dt = tempDT;
}
if (dt == null || dt.Count < 1)
{
return;
}
int qtyFact = dt.Count;
if (qtyFact > keydataItemsCount)
{
qtyFact = keydataItemsCount;
}
#region 预防扭矩值不合格但是会返回合格信号
bool updateKeyDataResult = false;
for (int i = 0; i < qtyFact; i++)
{
if (string.IsNullOrEmpty(_dtKeydataItems[i]["keydata_value"].ToString()))
{
Double maxValue = Convert.ToDouble(_dtKeydataItems[i]["max_value"].ToString());
Double minValue = Convert.ToDouble(_dtKeydataItems[i]["min_value"].ToString());
Double keyDataValue = Convert.ToDouble(dt[i]["keydata_value"].ToString());
string guid = Convert.ToString(dt[i]["guid"].ToString());
if (keyDataValue > maxValue || keyDataValue < minValue)
{
//MessageBox.Show("i:" + i + "max:" + maxValue + "min:" + minValue + "keydatav:" + keyDataValue);
updateKeyDataResult = _app.updateKeyDataResult(Context["serial_number"].ToString(), keyDataValue.ToString(), guid);
}
}
}
if (updateKeyDataResult)
{
dt = _app.GetKeyDataValue(Context["serial_number"].ToString(), terminalId);
//把前一工位的坐靠结合扭矩信息转移过来
if (mergeDT != null)
{
//忽略补打工位的坐靠结合扭矩信息;
//操作人员没有注意不需要补打坐靠结合,进行了补打操作时会造成显示背景不变的问题
for (int i = 0; i < dt.Count; i++)
{
string keyDataDesc = dt[i]["keydata_desc"].ToString();
//DFPV座靠结合扭矩补打01为补打工位的坐靠结合扭矩枪
if (keyDataDesc == "DFPV座靠结合扭矩补打01")
{
dt.Remove(dt[i]);
}
}
//合并前一工位和当前工位的扭矩信息
List<dynamic> tempDT = null;
tempDT = mergeDT.Copy();
tempDT.Merge(dt);
dt = tempDT;
}
if (dt == null || dt.Count < 1)
{
return;
}
qtyFact = dt.Count;
}
#endregion
//判断实际已采集数据是否大于需求数量,如果是,则多出数据抛弃
if (qtyFact > keydataItemsCount)
{
qtyFact = keydataItemsCount;
}
lblQtyFact.Text = qtyFact.ToString();
for (int i = 0; i < qtyFact; i++)
{
if (string.IsNullOrEmpty(_dtKeydataItems[i]["keydata_value"].ToString()))
{
Double maxValue = Convert.ToDouble(_dtKeydataItems[i]["max_value"].ToString());
Double minValue = Convert.ToDouble(_dtKeydataItems[i]["min_value"].ToString());
Double keyDataValue = Convert.ToDouble(dt[i]["keydata_value"].ToString());
_dtKeydataItems[i]["keydata_value"] = dt[i]["keydata_value"].ToString();
_dtKeydataItems[i]["keydata_angle"] = dt[i]["keydata_angle"].ToString();
string status = dt[i]["keydata_status"].ToString();
if (status.Trim().ToUpper() == "GOOD")
{
_dtKeydataItems[i]["keydata_status"] = "OK";
}
else
{
_dtKeydataItems[i]["keydata_status"] = dt[i]["keydata_status"].ToString();
}
_dtKeydataItems[i]["keydata_result"] = dt[i]["keydata_result"].ToString();
_dtKeydataItems[i]["keydata_ymd"] = dt[i]["keydata_ymd"].ToString();
_dtKeydataItems[i]["keydata_hms"] = dt[i]["keydata_hms"].ToString();
dgvTorqueCollect.DataSource = _dtKeydataItems;
dgvTorqueCollect.Update();
if (dgvTorqueCollect.Count>0)
{
dgvTorqueCollect[i].DefaultCellStyle.BackColor = Color.Green;
}
}
}
//System.Windows.Forms.Application.DoEvents();
string qty = lblQtyFact.Text.ToString();
string sum = lblQtySum.Text.ToString();
if (qty == sum)
{
////取消报警信号发送
//if (_OK)
//{
// _OK = false;
// _app.UpdateOPCPointValue(terminalId, "OPC_NG");
//}
CollectKeydata.Enabled = false;
isFirstFinished = false;
// 记录日志
using (StreamWriter sw = new StreamWriter("PLC_Log-" + DateTime.Now.ToString("yyyy-MM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", " 条码:" + Context["serial_number"].ToString() + " 当前工位ID:[" + terminalId + "] 采集扭矩数量[" + qty + "]个,共[" + qty + "]个。本工位扭矩采集完成,准备调取工步完成方法!"));
sw.Flush();
sw.Close();
}
bool blState = _app.atlasDataTransfer(Context["serial_number"].ToString(), terminalId);
if (blState == false)
{
ShowMessage(this, "保存扭矩信息失败!");
return;
}
// 工步完成
Complate(this, null);
}
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
private List<dynamic> mergeDT = null;
public void WriteKeydataFactValueLast()
{
try
{
int keydataItemsCount = _dtKeydataItemsLast.Count;
if (keydataItemsCount < 1)
{
return;
}
List<dynamic> dt = _app.GetKeyDataValue(Context["serial_number"].ToString(), terminalIdLast);
if (dt == null || dt.Count < 1)
{
//扭矩未完成报警信号发送
if (_NG)
{
_NG = false;
_app.UpdateOPCPointValue(terminalId, "OPC_NG");
}
return;
}
//int qtyFact = dt .Count;
int qtyFact = keydataItemsCount;
//判断实际已采集数据是否大于需求数量,如果是,则多出数据抛弃
if (qtyFact > keydataItemsCount)
{
qtyFact = keydataItemsCount;
}
lblQtyFact.Text = qtyFact.ToString();
//获取前一工位采集的扭矩并附给混合表
if (qtyFact >= 5 && qtyFact != keydataItemsCount)
{
mergeDT = dt.Copy();
for (int i = 0; i < mergeDT.Count; i++)
{
string keyDataDesc = mergeDT[i]["keydata_desc"].ToString();
//DFPV座靠结合扭矩01为气囊扭矩枪
if (keyDataDesc == "DFPV座靠结合扭矩01")
{
mergeDT.Remove(mergeDT[i]);
}
}
}
for (int i = 0; i < qtyFact; i++)
{
if (string.IsNullOrEmpty(_dtKeydataItemsLast[i]["keydata_value"].ToString()))
{
_dtKeydataItemsLast[i]["keydata_value"] = dt[i]["keydata_value"].ToString();
_dtKeydataItemsLast[i]["keydata_angle"] = dt[i]["keydata_angle"].ToString();
string status = dt[i]["keydata_status"].ToString();
if (status.Trim().ToUpper() == "GOOD")
{
_dtKeydataItemsLast[i]["keydata_status"] = "OK";
}
else
{
_dtKeydataItemsLast[i]["keydata_status"] = dt[i]["keydata_status"].ToString();
}
_dtKeydataItemsLast[i]["keydata_result"] = dt[i]["keydata_result"].ToString();
_dtKeydataItemsLast[i]["keydata_ymd"] = dt[i]["keydata_ymd"].ToString();
_dtKeydataItemsLast[i]["keydata_hms"] = dt[i]["keydata_hms"].ToString();
}
}
//System.Windows.Forms.Application.DoEvents();
string qty = qtyFact.ToString();
string sum = lblQtySum.Text.ToString();
if (qty == sum && sum != "0")
{
CollectKeydata.Enabled = false;
//System.Threading.Thread.Sleep(100);
isFirstFinished = false;
// 记录日志
using (StreamWriter sw = new StreamWriter("PLC_Log-" + DateTime.Now.ToString("yyyy-MM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", " 条码:" + Context["serial_number"].ToString() + " 机器人扭矩工位ID:[" + terminalIdLast + "] 采集扭矩数量[" + qty + "]个,共[" + qty + "]个。机器人扭矩工位完成扭矩采集,当前工位不需要操作。准备调取工步完成方法!"));
sw.Flush();
sw.Close();
}
// 工步完成
Complate(this, null);
}
else
{
//扭矩未完成报警信号发送
if (_NG)
{
_NG = false;
_app.UpdateOPCPointValue(terminalId, "OPC_NG");
}
}
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
private void dgvTorqueCollect_SelectionChanged(object sender, EventArgs e)
{
try
{
dgvTorqueCollect.ClearSelection();
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
private void dgvLastData_SelectionChanged(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
// 记录日志
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
{
sw.WriteLine(string.Format("{0} {1}", "["
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+ "]", ex.ToString()));
sw.Flush();
sw.Close();
}
}
}
private void dgvTorqueCollect_SelectionChanged_1(object sender, EventArgs e)
{
dgvTorqueCollect.ClearSelection();
}
/// <summary>
/// 释放定时器
/// </summary>
public override bool TickDispose()
{
try
{
this.CollectKeydata.Dispose();
}
catch { }
return base.TickDispose();
}
}
}