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.
605 lines
20 KiB
C#
605 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
|
|
namespace Mesnac.Controls.Feeding
|
|
{
|
|
/// <summary>
|
|
/// 配方步骤
|
|
/// </summary>
|
|
[ToolboxBitmap(typeof(System.Windows.Forms.DataGridView))]
|
|
public partial class RecipeMixing : System.Windows.Forms.DataGridView
|
|
{
|
|
public RecipeMixing()
|
|
{
|
|
InitializeComponent();
|
|
this.InitMethod();
|
|
}
|
|
|
|
public RecipeMixing(IContainer container)
|
|
{
|
|
container.Add(this);
|
|
InitializeComponent();
|
|
this.InitMethod();
|
|
}
|
|
/// <summary>
|
|
/// 初始化方法
|
|
/// </summary>
|
|
private void InitMethod()
|
|
{
|
|
this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //设置整行选择模式
|
|
this.MultiSelect = false; //禁用多行选项
|
|
this.ReadOnly = true; //禁止编辑
|
|
this.MouseDown += new MouseEventHandler(RecipeMixing_MouseDown);
|
|
this.MouseLeave += new EventHandler(RecipeMixing_MouseLeave);
|
|
this.MouseMove += new MouseEventHandler(RecipeMixing_MouseMove);
|
|
}
|
|
|
|
#region 自定义属性
|
|
|
|
private string _dataName;
|
|
private DataTable _data;
|
|
private DataTable _cloneData; //克隆数据源
|
|
private string _finishStatusName;
|
|
private OnOffStatuses _finishStatus;
|
|
private string _lengthMixerName;
|
|
private int _lengthMixer;
|
|
protected bool _bHaveAction;
|
|
|
|
/// <summary>
|
|
/// 是否有动画
|
|
/// </summary>
|
|
public bool bHaveAction
|
|
{
|
|
get
|
|
{
|
|
return _bHaveAction;
|
|
}
|
|
set
|
|
{
|
|
_bHaveAction = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 数据源动画属性
|
|
/// </summary>
|
|
public string DataName
|
|
{
|
|
get { return _dataName; }
|
|
set { _dataName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 一车结束标志动画属性
|
|
/// </summary>
|
|
public string FinishStatusName
|
|
{
|
|
get { return _finishStatusName; }
|
|
set { _finishStatusName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 当前步骤动画属性
|
|
/// </summary>
|
|
public string LengthMixerName
|
|
{
|
|
get { return _lengthMixerName; }
|
|
set { _lengthMixerName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 初始化数据
|
|
/// </summary>
|
|
private void InitData()
|
|
{
|
|
try
|
|
{
|
|
if (this._cloneData != null)
|
|
{
|
|
this.DataSource = null;
|
|
this._cloneData.Dispose();
|
|
this._cloneData = null;
|
|
}
|
|
if (this._data != null && this._data.Rows.Count > 0)
|
|
{
|
|
this._cloneData = this._data.Copy();
|
|
//this._cloneData.Columns[0].AllowDBNull = true;
|
|
//for (int i = 0; i < this._cloneData.Rows.Count; i++)
|
|
//{
|
|
|
|
// this._cloneData.Rows[i]["步骤"] = DBNull.Value;
|
|
//}
|
|
////this._cloneData.Columns["步骤"].DataType = typeof(string);
|
|
//int j=1;
|
|
//for (int i = 0; i < this._cloneData.Rows.Count; i++)
|
|
//{
|
|
// if (i + 1 == this._cloneData.Rows.Count)
|
|
// {
|
|
// this._cloneData.Rows[i]["步骤"] = j;
|
|
// continue;
|
|
// }
|
|
// if (this._cloneData.Rows[i + 1]["条件"].ToString().Trim() == "同时执行")
|
|
// {
|
|
// continue;
|
|
// }
|
|
// this._cloneData.Rows[i]["步骤"] = j;
|
|
// j++;
|
|
//}
|
|
DataRow row = this._cloneData.NewRow();
|
|
if (this._cloneData.Columns.Contains("步骤"))
|
|
{
|
|
row["步骤"] = 0;
|
|
}
|
|
if (this._cloneData.Columns.Contains("条件"))
|
|
{
|
|
row["条件"] = "准备中...";
|
|
}
|
|
this._cloneData.Rows.InsertAt(row, 0);
|
|
|
|
this.DataSource = this._cloneData; //绑定克隆数据源
|
|
//禁用排序
|
|
for (int i = 0; i < this.ColumnCount; i++)
|
|
{
|
|
this.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
}
|
|
//设定动作列宽
|
|
if (this.Columns.Contains("动作"))
|
|
{
|
|
this.Columns["动作"].Width = 80;
|
|
}
|
|
//清除选中行
|
|
this.ClearSelection();
|
|
//设定初始选中行
|
|
this.Rows[0].Selected = true;
|
|
this.CurrentCell = this.Rows[0].Cells[0];
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据源
|
|
/// </summary>
|
|
public DataTable Data
|
|
{
|
|
get { return _data; }
|
|
set
|
|
{
|
|
_data = value;
|
|
if (this._cloneData == null || this._cloneData.TableName != this._data.TableName)
|
|
{
|
|
this.InitData();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 一车结束标志
|
|
/// </summary>
|
|
public OnOffStatuses FinishStatus
|
|
{
|
|
get { return _finishStatus; }
|
|
set
|
|
{
|
|
if ((int)value > 1)
|
|
{
|
|
this._finishStatus = OnOffStatuses.On;
|
|
}
|
|
else if ((int)value < 0)
|
|
{
|
|
this._finishStatus = OnOffStatuses.Off;
|
|
}
|
|
else
|
|
{
|
|
this._finishStatus = value;
|
|
}
|
|
//如果一车标志结束,则重新绑定数据源
|
|
if (this._finishStatus == OnOffStatuses.On)
|
|
{
|
|
this.InitData();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 当前步骤
|
|
/// </summary>
|
|
public int LengthMixer
|
|
{
|
|
get { return _lengthMixer; }
|
|
set
|
|
{
|
|
_lengthMixer = value;
|
|
if (this._cloneData != null)
|
|
{
|
|
if (this._cloneData.Columns.Contains("步骤"))
|
|
{
|
|
if (this._cloneData.Rows.Count > 0)
|
|
{
|
|
this._lengthMixer = FactSetp(_lengthMixer);
|
|
for (int i = 0; i < this._cloneData.Rows.Count; i++)
|
|
{
|
|
DataRow row = this._cloneData.Rows[i];
|
|
object val = row["步骤"];
|
|
if (val != DBNull.Value)
|
|
{
|
|
if (Convert.ToInt32(val) == this._lengthMixer)
|
|
{
|
|
this.ClearSelection();
|
|
if (i < this.Rows.Count)
|
|
{
|
|
this.Rows[i].Selected = true;
|
|
this.CurrentCell = this.Rows[i].Cells[0];
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (this.Rows.Count > 0)
|
|
{
|
|
this.Rows[0].Selected = true;
|
|
this.CurrentCell = this.Rows[0].Cells[0];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int FactSetp(int LengthMixer)
|
|
{
|
|
int factsetp = 0;
|
|
int returnsetp = 0;
|
|
for (int i = 1; i < this._cloneData.Rows.Count; i++)
|
|
{
|
|
if (this._cloneData.Rows.Count>(i+1) && this._cloneData.Rows[i + 1]["条件"].ToString().Trim() == "同时执行")
|
|
{
|
|
continue;
|
|
}
|
|
factsetp++;
|
|
if (LengthMixer == factsetp)
|
|
returnsetp = Convert.ToInt32(this._cloneData.Rows[i]["步骤"]);
|
|
}
|
|
return returnsetp;
|
|
}
|
|
#endregion
|
|
|
|
#region 数据列
|
|
|
|
private string _mixingTimeName;
|
|
private double _mixingTime;
|
|
private string _mixingTempName;
|
|
private double _mixingTemp;
|
|
private string _mixingEnergyName;
|
|
private double _mixingEnergy;
|
|
private string _mixingPowerName;
|
|
private double _mixingPower;
|
|
private string _mixingPressName;
|
|
private double _mixingPress;
|
|
private string _mixingSpeedName;
|
|
private double _mixingSpeed;
|
|
|
|
|
|
/// <summary>
|
|
/// 时间动画属性
|
|
/// </summary>
|
|
public string MixingTimeName
|
|
{
|
|
get { return _mixingTimeName; }
|
|
set { _mixingTimeName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 温度动画属性
|
|
/// </summary>
|
|
public string MixingTempName
|
|
{
|
|
get { return _mixingTempName; }
|
|
set { _mixingTempName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 能量动画属性
|
|
/// </summary>
|
|
public string MixingEnergyName
|
|
{
|
|
get { return _mixingEnergyName; }
|
|
set { _mixingEnergyName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 功率动画属性
|
|
/// </summary>
|
|
public string MixingPowerName
|
|
{
|
|
get { return _mixingPowerName; }
|
|
set { _mixingPowerName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 压力动画属性
|
|
/// </summary>
|
|
public string MixingPressName
|
|
{
|
|
get { return _mixingPressName; }
|
|
set { _mixingPressName = value; }
|
|
}
|
|
/// <summary>
|
|
/// 转速动画属性
|
|
/// </summary>
|
|
public string MixingSpeedName
|
|
{
|
|
get { return _mixingSpeedName; }
|
|
set { _mixingSpeedName = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新数据
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
private void UpdateData(string columnName, double value)
|
|
{
|
|
if (this._cloneData != null)
|
|
{
|
|
if (this._cloneData.Columns.Contains(columnName))
|
|
{
|
|
if (this._cloneData.Columns[columnName].ReadOnly)
|
|
{
|
|
this._cloneData.Columns[columnName].ReadOnly = false;
|
|
}
|
|
if (this.CurrentRow != null)
|
|
{
|
|
if (this._cloneData.Rows.Count > 1 && this.CurrentRow.Index > 0 && this.CurrentRow.Index < this._cloneData.Rows.Count)
|
|
{
|
|
DataRow row = this._cloneData.Rows[this.CurrentRow.Index];
|
|
if (this._cloneData.Rows[this.CurrentRow.Index]["条件"].ToString().Trim() == "同时执行")
|
|
{
|
|
DataRow rowPre = this._cloneData.Rows[this.CurrentRow.Index - 1];
|
|
if (rowPre != null) rowPre[columnName] = value;
|
|
}
|
|
if (row != null) row[columnName] = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 时间
|
|
/// </summary>
|
|
public double MixingTime
|
|
{
|
|
get { return _mixingTime; }
|
|
set
|
|
{
|
|
_mixingTime = value;
|
|
this.UpdateData("时间", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 温度
|
|
/// </summary>
|
|
public double MixingTemp
|
|
{
|
|
get { return _mixingTemp; }
|
|
set
|
|
{
|
|
_mixingTemp = value;
|
|
this.UpdateData("温度", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 能量
|
|
/// </summary>
|
|
public double MixingEnergy
|
|
{
|
|
get { return _mixingEnergy; }
|
|
set
|
|
{
|
|
_mixingEnergy = value;
|
|
this.UpdateData("能量", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 功率
|
|
/// </summary>
|
|
public double MixingPower
|
|
{
|
|
get { return _mixingPower; }
|
|
set
|
|
{
|
|
_mixingPower = value;
|
|
this.UpdateData("功率", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 压力
|
|
/// </summary>
|
|
public double MixingPress
|
|
{
|
|
get { return _mixingPress; }
|
|
set
|
|
{
|
|
_mixingPress = value;
|
|
this.UpdateData("压力", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 转速
|
|
/// </summary>
|
|
public double MixingSpeed
|
|
{
|
|
get { return _mixingSpeed; }
|
|
set
|
|
{
|
|
_mixingSpeed = value;
|
|
this.UpdateData("转速", value);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 拖动
|
|
const int Band = 5;
|
|
const int MinWidth = 50;
|
|
const int MinHeight = 60;
|
|
/// <summary>
|
|
/// 鼠标在事件源的位置
|
|
/// </summary>
|
|
private Point p = new Point();
|
|
private Point p1 = new Point();
|
|
private enum EnumMousePointPosition
|
|
{
|
|
MouseSizeNone = 0, //'无
|
|
MouseSizeRight = 1, //'拉伸右边框
|
|
MouseSizeLeft = 2, //'拉伸左边框
|
|
MouseSizeBottom = 3, //'拉伸下边框
|
|
MouseSizeTop = 4, //'拉伸上边框
|
|
MouseSizeTopLeft = 5, //'拉伸左上角
|
|
MouseSizeTopRight = 6, //'拉伸右上角
|
|
MouseSizeBottomLeft = 7, //'拉伸左下角
|
|
MouseSizeBottomRight = 8, //'拉伸右下角
|
|
MouseDrag = 9 // '鼠标拖动
|
|
}
|
|
private EnumMousePointPosition m_MousePointPosition;
|
|
|
|
void RecipeMixing_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
p.X = e.X;
|
|
p.Y = e.Y;
|
|
p1.X = e.X;
|
|
p1.Y = e.Y;
|
|
}
|
|
|
|
void RecipeMixing_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
m_MousePointPosition = EnumMousePointPosition.MouseSizeNone;
|
|
this.Cursor = Cursors.Arrow;
|
|
}
|
|
void RecipeMixing_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
Control lCtrl = (sender as Control);
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
switch (m_MousePointPosition)
|
|
{
|
|
case EnumMousePointPosition.MouseDrag:
|
|
if (this.Left > 930)
|
|
{
|
|
this.Left = 929;
|
|
return;
|
|
}
|
|
if (this.Top > 374)
|
|
{
|
|
this.Top = 373;
|
|
return;
|
|
}
|
|
lCtrl.Left = lCtrl.Left + e.X - p.X;
|
|
lCtrl.Top = lCtrl.Top + e.Y - p.Y;
|
|
|
|
break;
|
|
//case EnumMousePointPosition.MouseSizeRight:
|
|
// lCtrl.Width = lCtrl.Width + e.X - p1.X;
|
|
// p1.X = e.X;
|
|
// p1.Y = e.Y; //记录光标拖动的当前点
|
|
// break;
|
|
case EnumMousePointPosition.MouseSizeLeft:
|
|
lCtrl.Left = lCtrl.Left + e.X - p.X;
|
|
lCtrl.Width = lCtrl.Width - (e.X - p.X);
|
|
break;
|
|
case EnumMousePointPosition.MouseSizeBottom:
|
|
lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
|
|
p1.X = e.X;
|
|
p1.Y = e.Y; //'记录光标拖动的当前点
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (lCtrl.Width < MinWidth) lCtrl.Width = MinWidth;
|
|
if (lCtrl.Height < MinHeight) lCtrl.Height = MinHeight;
|
|
|
|
}
|
|
else
|
|
{
|
|
m_MousePointPosition = MousePointPosition(lCtrl.Size, e); //'判断光标的位置状态
|
|
switch (m_MousePointPosition) //'改变光标
|
|
{
|
|
case EnumMousePointPosition.MouseSizeNone:
|
|
this.Cursor = Cursors.Arrow; //'箭头
|
|
break;
|
|
case EnumMousePointPosition.MouseDrag:
|
|
this.Cursor = Cursors.SizeAll; //'四方向
|
|
break;
|
|
case EnumMousePointPosition.MouseSizeRight:
|
|
this.Cursor = Cursors.SizeWE; //东西
|
|
break;
|
|
case EnumMousePointPosition.MouseSizeLeft:
|
|
this.Cursor = Cursors.SizeWE; //东西
|
|
break;
|
|
case EnumMousePointPosition.MouseSizeBottom:
|
|
this.Cursor = Cursors.SizeNS; //'南北
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private EnumMousePointPosition MousePointPosition(Size size, System.Windows.Forms.MouseEventArgs e)
|
|
{
|
|
|
|
if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height))
|
|
{
|
|
if (e.X < Band)
|
|
{
|
|
if (e.Y < Band) { return EnumMousePointPosition.MouseSizeNone; }
|
|
else
|
|
{
|
|
if (e.Y > -1 * Band + size.Height)
|
|
{ return EnumMousePointPosition.MouseSizeNone; }
|
|
else
|
|
{ return EnumMousePointPosition.MouseSizeLeft; }
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (e.X > -1 * Band + size.Width)
|
|
{
|
|
if (e.Y < Band)
|
|
{ return EnumMousePointPosition.MouseSizeNone; }
|
|
else
|
|
{
|
|
if (e.Y > -1 * Band + size.Height)
|
|
{ return EnumMousePointPosition.MouseSizeNone; }
|
|
else
|
|
{ return EnumMousePointPosition.MouseSizeRight; }
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (e.Y < Band)
|
|
{ return EnumMousePointPosition.MouseSizeNone; }
|
|
else
|
|
{
|
|
if (e.Y > -1 * Band + size.Height)
|
|
{ return EnumMousePointPosition.MouseSizeBottom; }
|
|
else
|
|
{ return EnumMousePointPosition.MouseDrag; }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{ return EnumMousePointPosition.MouseSizeNone; }
|
|
}
|
|
#endregion
|
|
}
|
|
}
|