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.

1029 lines
31 KiB
C#

1 year ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Mesnac.Controls.Feeding
{
/// <summary>
/// 胶料称量监控
/// </summary>
[ToolboxBitmap(typeof(System.Windows.Forms.DataGridView))]
public partial class RecipPlyMonitor : System.Windows.Forms.DataGridView
{
public RecipPlyMonitor()
{
InitializeComponent();
InitMethod();
this.Resize += new EventHandler(RecipPlyMonitor_Resize);
}
public RecipPlyMonitor(IContainer container)
{
container.Add(this);
InitializeComponent();
this.InitMethod();
this.Resize += new EventHandler(RecipPlyMonitor_Resize);
}
protected void RecipPlyMonitor_Resize(object sender, EventArgs e)
{
this.SetColumnStyle();
}
/// <summary>
/// 初始化方法
/// </summary>
private void InitMethod()
{
this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //整行选择模式
this.MultiSelect = false; //禁用多行选项
this.ReadOnly = true; //禁止编辑
this.RowTemplate.Height = 38;
this.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 28F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.ColumnHeadersHeight = 42;
this.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.RowHeadersVisible = false;
}
#region 自定义属性
private bool _bHaveAction;
private string _dataName;
private DataTable _data;
private DataTable _cloneData;
private string _currentRecipPlyName1;
private int _currentRecipPly1;
private string _currentRecipPlyName2;
private int _currentRecipPly2;
private string _currentRecipPlyName3;
private int _currentRecipPly3;
private string _currentRecipPlyName4;
private int _currentRecipPly4;
private string _currentRecipPlyName5;
private int _currentRecipPly5;
private string _currentRecipPlyName6;
private int _currentRecipPly6;
private string _currentRecipPlyName7;
private int _currentRecipPly7;
private string _currentRecipPlyName8;
private int _currentRecipPly8;
private string _currentRecipPlyName9;
private int _currentRecipPly9;
private string _currentRecipPlyName10;
private int _currentRecipPly10;
private string _currentRecipPlyName11;
private int _currentRecipPly11;
private string _currentRecipPlyName12;
private int _currentRecipPly12;
private string _currentRecipPlyName13;
private int _currentRecipPly13;
private string _currentRecipPlyName14;
private int _currentRecipPly14;
private string _currentRecipPlyName15;
private int _currentRecipPly15;
private string _plyCurrentValueName1;
private double _plyCurrentValue1; //胶料实际值
private string _plyCurrentValueName2;
private double _plyCurrentValue2;
private string _plyCurrentValueName3;
private double _plyCurrentValue3;
private string _plyCurrentValueName4;
private double _plyCurrentValue4;
private string _plyCurrentValueName5;
private double _plyCurrentValue5;
private string _plyCurrentValueName6;
private double _plyCurrentValue6;
private string _plyCurrentValueName7;
private double _plyCurrentValue7;
private string _plyCurrentValueName8;
private double _plyCurrentValue8;
private string _plyCurrentValueName9;
private double _plyCurrentValue9;
private string _plyCurrentValueName10;
private double _plyCurrentValue10;
private string _plyCurrentValueName11;
private double _plyCurrentValue11;
private string _plyCurrentValueName12;
private double _plyCurrentValue12;
private string _plyCurrentValueName13;
private double _plyCurrentValue13;
private string _plyCurrentValueName14;
private double _plyCurrentValue14;
private string _plyCurrentValueName15;
private double _plyCurrentValue15;
private int _endAndWaitPloy = 0;
private string _endAndWaitPloyName;
#region 动画属性
/// <summary>
/// 是否有动画
/// </summary>
public bool HaveAction
{
get
{
return _bHaveAction;
}
set
{
_bHaveAction = value;
}
}
/// <summary>
/// 数据源动画属性
/// </summary>
public string DataName
{
get { return _dataName; }
set { _dataName = value; }
}
#region 当前称量胶料动画属性
/// <summary>
/// 称量的第一种胶料动画属性
/// </summary>
public string CurrentRecipPlyName1
{
get { return _currentRecipPlyName1; }
set { _currentRecipPlyName1 = value; }
}
/// <summary>
/// 称量的第二种胶料动画属性
/// </summary>
public string CurrentRecipPlyName2
{
get { return _currentRecipPlyName2; }
set { _currentRecipPlyName2 = value; }
}
/// <summary>
/// 称量的第三种胶料动画属性
/// </summary>
public string CurrentRecipPlyName3
{
get { return _currentRecipPlyName3; }
set { _currentRecipPlyName3 = value; }
}
/// <summary>
/// 称量的第四种胶料动画属性
/// </summary>
public string CurrentRecipPlyName4
{
get { return _currentRecipPlyName4; }
set { _currentRecipPlyName4 = value; }
}
/// <summary>
/// 称量的第五种胶料动画属性
/// </summary>
public string CurrentRecipPlyName5
{
get { return _currentRecipPlyName5; }
set { _currentRecipPlyName5 = value; }
}
/// <summary>
/// 称量的第六种胶料动画属性
/// </summary>
public string CurrentRecipPlyName6
{
get { return _currentRecipPlyName6; }
set { _currentRecipPlyName6 = value; }
}
/// <summary>
/// 称量的第七种胶料动画属性
/// </summary>
public string CurrentRecipPlyName7
{
get { return _currentRecipPlyName7; }
set { _currentRecipPlyName7 = value; }
}
/// <summary>
/// 称量的第八种胶料动画属性
/// </summary>
public string CurrentRecipPlyName8
{
get { return this._currentRecipPlyName8; }
set { this._currentRecipPlyName8 = value; }
}
/// <summary>
/// 称量的第九种胶料动画属性
/// </summary>
public string CurrentRecipPlyName9
{
get { return this._currentRecipPlyName9; }
set { this._currentRecipPlyName9 = value; }
}
/// <summary>
/// 称量的第十种胶料的动画属性
/// </summary>
public string CurrentRecipPlyName10
{
get { return this._currentRecipPlyName10; }
set { this._currentRecipPlyName10 = value; }
}
/// <summary>
/// 称量的第十一种胶料的动画属性
/// </summary>
public string CurrentRecipPlyName11
{
get { return this._currentRecipPlyName11; }
set { this._currentRecipPlyName11 = value; }
}
/// <summary>
/// 称量的第十二种胶料的动画属性
/// </summary>
public string CurrentRecipPlyName12
{
get { return this._currentRecipPlyName12; }
set { this._currentRecipPlyName12 = value; }
}
/// <summary>
/// 称量的第十三种胶料的动画属性
/// </summary>
public string CurrentRecipPlyName13
{
get { return this._currentRecipPlyName13; }
set { this._currentRecipPlyName13 = value; }
}
/// <summary>
/// 称量的第十四种胶料的动画属性
/// </summary>
public string CurrentRecipPlyName14
{
get { return this._currentRecipPlyName14; }
set { this._currentRecipPlyName14 = value; }
}
/// <summary>
/// 称量的第十五种胶料的动画属性
/// </summary>
public string CurrentRecipPlyName15
{
get { return this._currentRecipPlyName15; }
set { this._currentRecipPlyName15 = value; }
}
#endregion
#region 胶料实际值动画属性
/// <summary>
/// 称量的第一种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName1
{
get { return this._plyCurrentValueName1; }
set { this._plyCurrentValueName1 = value; }
}
/// <summary>
/// 称量的第二种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName2
{
get { return _plyCurrentValueName2; }
set { this._plyCurrentValueName2 = value; }
}
/// <summary>
/// 称量的第三种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName3
{
get { return this._plyCurrentValueName3; }
set { this._plyCurrentValueName3 = value; }
}
/// <summary>
/// 称量的第四种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName4
{
get { return this._plyCurrentValueName4; }
set { this._plyCurrentValueName4 = value; }
}
/// <summary>
/// 称量的第五种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName5
{
get { return this._plyCurrentValueName5; }
set { this._plyCurrentValueName5 = value; }
}
/// <summary>
/// 称量的第六种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName6
{
get { return this._plyCurrentValueName6; }
set { this._plyCurrentValueName6 = value; }
}
/// <summary>
/// 称量的第七种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName7
{
get { return this._plyCurrentValueName7; }
set { this._plyCurrentValueName7 = value; }
}
/// <summary>
/// 称量的第八种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName8
{
get { return this._plyCurrentValueName8; }
set { this._plyCurrentValueName8 = value; }
}
/// <summary>
/// 称量的第九种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName9
{
get { return this._plyCurrentValueName9; }
set { this._plyCurrentValueName9 = value; }
}
/// <summary>
/// 称量的第十种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName10
{
get { return this._plyCurrentValueName10; }
set { this._plyCurrentValueName10 = value; }
}
/// <summary>
/// 称量的第十一种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName11
{
get { return this._plyCurrentValueName11; }
set { this._plyCurrentValueName11 = value; }
}
/// <summary>
/// 称量的第十二种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName12
{
get { return this._plyCurrentValueName12; }
set { this._plyCurrentValueName12 = value; }
}
/// <summary>
/// 称量的第十三种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName13
{
get { return this._plyCurrentValueName13; }
set { this._plyCurrentValueName13 = value; }
}
/// <summary>
/// 称量的第十四种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName14
{
get { return this._plyCurrentValueName14; }
set { this._plyCurrentValueName14 = value; }
}
/// <summary>
/// 称量的第十五种胶料实际值动画属性
/// </summary>
public string PlyCurrentValueName15
{
get { return this._plyCurrentValueName15; }
set { this._plyCurrentValueName15 = value; }
}
#endregion
#endregion
#region 数据属性
/// <summary>
/// 数据源
/// </summary>
public DataTable Data
{
get { return _data; }
set
{
_data = value;
if (this._cloneData == null || this._cloneData.Rows.Count == 0 || this._cloneData.TableName != this._data.TableName)
{
InitData();
}
}
}
/// <summary>
/// 初始化数据
/// </summary>
public void InitData()
{
try
{
if (this._cloneData != null)
{
this.DataSource = null;
this._cloneData.Dispose();
this._cloneData = null;
}
if (this._data != null)
{
this._cloneData = this._data.Copy();
this.DataSource = this._cloneData;
//禁止排序
for (int i = 0; i < this.ColumnCount; i++)
{
this.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
this.SetColumnStyle();
//清除选中行
this.ClearSelection();
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("胶料称监控画面胶料列表控件初始化数据错误InitData" + ex.Message, ex);
}
}
/// <summary>
/// 设置列宽
/// </summary>
private void SetColumnStyle()
{
lock (String.Empty)
{
try
{
//设定初始列宽
if (this.Columns.Contains("名称"))
{
this.Columns["名称"].Width = 150;
}
if (this.Columns.Contains("序号"))
{
this.Columns["序号"].Width = 15;
}
if (this.Columns.Contains("设定"))
{
this.Columns["设定"].Width = 100;
}
if (this.Columns.Contains("实际"))
{
this.Columns["实际"].Width = 100;
}
if (this.Columns.Contains("误差"))
{
this.Columns["误差"].Width = 140;
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("胶料称监控画面胶料列表控件设置列宽错误SetColumnStyle" + ex.Message, ex);
}
}
}
#region 判断当前称量的胶料
/// <summary>
/// 称量的第一种胶料
/// </summary>
public int CurrentRecipPly1
{
get { return _currentRecipPly1; }
set
{
_currentRecipPly1 = value;
this.RefreshCurrentRow();
}
}
/// <summary>
/// 称量的第二种胶料
/// </summary>
public int CurrentRecipPly2
{
get { return _currentRecipPly2; }
set
{
_currentRecipPly2 = value;
this.RefreshCurrentRow();
}
}
/// <summary>
/// 称量的第三种胶料
/// </summary>
public int CurrentRecipPly3
{
get { return _currentRecipPly3; }
set
{
_currentRecipPly3 = value;
this.RefreshCurrentRow(); ;
}
}
/// <summary>
/// 称量的第四种胶料
/// </summary>
public int CurrentRecipPly4
{
get { return _currentRecipPly4; }
set
{
_currentRecipPly4 = value;
this.RefreshCurrentRow();
}
}
/// <summary>
/// 称量的第五种胶料
/// </summary>
public int CurrentRecipPly5
{
get { return _currentRecipPly5; }
set
{
_currentRecipPly5 = value;
this.RefreshCurrentRow();
}
}
/// <summary>
/// 称量的第六种胶料
/// </summary>
public int CurrentRecipPly6
{
get { return _currentRecipPly6; }
set
{
_currentRecipPly6 = value;
this.RefreshCurrentRow();
}
}
/// <summary>
/// 称量的第七种胶料
/// </summary>
public int CurrentRecipPly7
{
get { return _currentRecipPly7; }
set
{
_currentRecipPly7 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly8
{
get { return _currentRecipPly8; }
set
{
_currentRecipPly8 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly9
{
get { return _currentRecipPly9; }
set
{
_currentRecipPly9 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly10
{
get { return _currentRecipPly10; }
set
{
_currentRecipPly10 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly11
{
get { return _currentRecipPly11; }
set
{
_currentRecipPly11 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly12
{
get { return _currentRecipPly12; }
set
{
_currentRecipPly12 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly13
{
get { return _currentRecipPly13; }
set
{
_currentRecipPly13 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly14
{
get { return _currentRecipPly14; }
set
{
_currentRecipPly14 = value;
this.RefreshCurrentRow();
}
}
public int CurrentRecipPly15
{
get { return _currentRecipPly15; }
set
{
_currentRecipPly15 = value;
this.RefreshCurrentRow();
}
}
/// <summary>
/// 称量结束等待送物料
/// </summary>
[Description("称量结束等待送物料"), Category("PLC")]
public int EndAndWaitPloy
{
get { return _endAndWaitPloy; }
set { _endAndWaitPloy = value; if (value == 1)this.RefereshText(); }
}
/// <summary>
/// 称量结束等待送物料动画属性
/// </summary>
public string EndAndWaitPloyName
{
get { return _endAndWaitPloyName; }
set { _endAndWaitPloyName = value; }
}
#endregion
public void RefereshText()
{
for (int i = 0; i < this._cloneData.Rows.Count; i++)
{
this.Rows[i].DefaultCellStyle.BackColor = Color.Green;
}
}
/// <summary>
/// 刷新选中行
/// </summary>
private void RefreshCurrentRow()
{
if (this._currentRecipPly15 == 1)
{
this.CurrentSelectRow(15);
}
else if (this._currentRecipPly14 == 1)
{
this.CurrentSelectRow(14);
}
else if (this._currentRecipPly13 == 1)
{
this.CurrentSelectRow(13);
}
else if (this._currentRecipPly12 == 1)
{
this.CurrentSelectRow(12);
}
else if (this._currentRecipPly11 == 1)
{
this.CurrentSelectRow(11);
}
else if (this._currentRecipPly10 == 1)
{
this.CurrentSelectRow(10);
}
else if (this._currentRecipPly9 == 1)
{
this.CurrentSelectRow(9);
}
else if (this._currentRecipPly8 == 1)
{
this.CurrentSelectRow(8);
}
else if (this._currentRecipPly7 == 1)
{
this.CurrentSelectRow(7);
}
else if (this._currentRecipPly6 == 1)
{
this.CurrentSelectRow(6);
}
else if (this._currentRecipPly5 == 1)
{
this.CurrentSelectRow(5);
}
else if (this._currentRecipPly4 == 1)
{
this.CurrentSelectRow(4);
}
else if (this._currentRecipPly3 == 1)
{
this.CurrentSelectRow(3);
}
else if (this._currentRecipPly2 == 1)
{
this.CurrentSelectRow(2);
}
else if (this._currentRecipPly1 == 1)
{
this.CurrentSelectRow(1);
}
//else
//{
// this.ClearSelection();
// if (this._cloneData != null && this._cloneData.Rows.Count > 0)
// {
// for (int i = 0; i < this._cloneData.Rows.Count; i++)
// {
// this.Rows[i].DefaultCellStyle.BackColor = Color.White;
// }
// }
//}
}
//选中某一行
private void CurrentSelectRow(int rowIndex)
{
this.ClearSelection();
if (this._cloneData != null && this._cloneData.Columns.Contains("序号") && this._cloneData.Rows.Count > 0)
{
if (rowIndex <= this._cloneData.Rows.Count)
{
DataRow row = this._cloneData.Rows[rowIndex - 1];
object val = row["序号"];
if (val != DBNull.Value)
{
for (int i = 0; i < rowIndex - 1; i++)
{
this.Rows[i].DefaultCellStyle.BackColor = Color.Green;
}
this.Rows[rowIndex - 1].DefaultCellStyle.BackColor = Color.GreenYellow;
for (int i = rowIndex; i < this._cloneData.Rows.Count; i++)
{
this.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
//this.Rows[rowIndex - 1].Selected = true;
this.CurrentCell = this.Rows[rowIndex - 1].Cells[0];
}
}
else
{
if (rowIndex > 0)
{
for (int i = 0; i < this._cloneData.Rows.Count; i++)
{
this.Rows[i].DefaultCellStyle.BackColor = Color.Green;
}
}
}
}
}
#endregion
/// <summary>
/// 第一种胶料实际值
/// </summary>
public double PlyCurrentValue1
{
get { return _plyCurrentValue1; }
set
{
_plyCurrentValue1 = value;
this.RefreshCurrentValue(1, value);
}
}
/// <summary>
/// 第二种胶料实际值
/// </summary>
public double PlyCurrentValue2
{
get { return this._plyCurrentValue2; }
set
{
this._plyCurrentValue2 = value;
this.RefreshCurrentValue(2, value);
}
}
/// <summary>
/// 第三种胶料实际值
/// </summary>
public double PlyCurrentValue3
{
get { return this._plyCurrentValue3; }
set
{
this._plyCurrentValue3 = value;
this.RefreshCurrentValue(3, value);
}
}
/// <summary>
/// 第四种胶料实际值
/// </summary>
public double PlyCurrentValue4
{
get { return this._plyCurrentValue4; }
set
{
this._plyCurrentValue4 = value;
this.RefreshCurrentValue(4, value);
}
}
/// <summary>
/// 第五种胶料实际值
/// </summary>
public double PlyCurrentValue5
{
get { return this._plyCurrentValue5; }
set
{
this._plyCurrentValue5 = value;
this.RefreshCurrentValue(5, value);
}
}
/// <summary>
/// 第六种胶料实际值
/// </summary>
public double PlyCurrentValue6
{
get { return this._plyCurrentValue6; }
set
{
this._plyCurrentValue6 = value;
this.RefreshCurrentValue(6, value);
}
}
/// <summary>
/// 第七种胶料实际值
/// </summary>
public double PlyCurrentValue7
{
get { return this._plyCurrentValue7; }
set
{
this._plyCurrentValue7 = value;
this.RefreshCurrentValue(7, value);
}
}
/// <summary>
/// 第八种胶料实际值
/// </summary>
public double PlyCurrentValue8
{
get { return this._plyCurrentValue8; }
set
{
this._plyCurrentValue8 = value;
this.RefreshCurrentValue(8, value);
}
}
/// <summary>
/// 第九种胶料实际值
/// </summary>
public double PlyCurrentValue9
{
get { return this._plyCurrentValue9; }
set
{
this._plyCurrentValue9 = value;
this.RefreshCurrentValue(9, value);
}
}
/// <summary>
/// 第十种胶料实际值
/// </summary>
public double PlyCurrentValue10
{
get { return this._plyCurrentValue10; }
set
{
this._plyCurrentValue10 = value;
this.RefreshCurrentValue(10, value);
}
}
/// <summary>
/// 第十一种胶料实际值
/// </summary>
public double PlyCurrentValue11
{
get { return this._plyCurrentValue11; }
set
{
this._plyCurrentValue11 = value;
this.RefreshCurrentValue(11, value);
}
}
/// <summary>
/// 第十二种胶料实际值
/// </summary>
public double PlyCurrentValue12
{
get { return this._plyCurrentValue12; }
set
{
this._plyCurrentValue12 = value;
this.RefreshCurrentValue(12, value);
}
}
/// <summary>
/// 第十三种胶料实际值
/// </summary>
public double PlyCurrentValue13
{
get { return this._plyCurrentValue13; }
set
{
this._plyCurrentValue13 = value;
this.RefreshCurrentValue(13, value);
}
}
/// <summary>
/// 第十四种胶料实际值
/// </summary>
public double PlyCurrentValue14
{
get { return this._plyCurrentValue14; }
set
{
this._plyCurrentValue14 = value;
this.RefreshCurrentValue(14, value);
}
}
/// <summary>
/// 第十五种胶料实际值
/// </summary>
public double PlyCurrentValue15
{
get { return this._plyCurrentValue15; }
set
{
this._plyCurrentValue15 = value;
this.RefreshCurrentValue(15, value);
}
}
#region 数据列
/// <summary>
/// 刷新当前值
/// </summary>
/// <param name="value"></param>
private void RefreshCurrentValue(int index, double value)
{
this.UpdateCurrentValue(index, value);
}
private void UpdateCurrentValue(int rowIndex, double value)
{
try
{
if (rowIndex < 1)
{
this.ClearSelection();
}
else
{
if (this._cloneData != null)
{
if (this._cloneData.Columns.Contains("实际"))
{
if (rowIndex <= this._cloneData.Rows.Count)
{
DataRow row = this._cloneData.Rows[rowIndex - 1];
if (row != null)
{
row["实际"] = value;
}
}
}
}
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("胶料称监控画面胶料列表控件刷新当前值错误:" + ex.Message, ex);
}
}
#endregion
#endregion
}
}