using HighWayIot.Log4net;
using HighWayIot.Plc;
using HighWayIot.Plc.PlcHelper;
using HighWayIot.Repository.domain;
using HighWayIot.Repository.service;
using HighWayIot.Winform.Business;
using HighWayIot.Winform.MainForm;
using HighWayIot.Winform.UserControlPages.RecipeConfigPages;
using HighWayIot.Winform.UserControlPages.SysConfigPages;
using Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Schema;
namespace HighWayIot.Winform.UserControlPages
{
public partial class RecipeConfigPage : UserControl
{
///
/// 配方服务类实例
///
private ZxRecipeService zxRecipeService = ZxRecipeService.Instance;
///
/// 称重服务类实例
///
private ZxWeightService zxWeightService = ZxWeightService.Instance;
///
/// 配方服务类实例
///
private ZxMaterialService zxMaterialService = ZxMaterialService.Instance;
///
/// 配方字段服务类实例
///
private ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance;
///
/// 工位配方字段服务类实例
///
private ZxRecipePositionParaService zxRecipePositionParaService = ZxRecipePositionParaService.Instance;
///
/// 配方字段实例
///
private ZxRecipeParaEntity zxRecipeParaEntity = new ZxRecipeParaEntity();
///
/// 工位配方字段实例
///
private List zxRecipePositionParaEntity = new List();
///
/// 称重DataGridView数据源
///
private List weightDataSourceEntities;
///
/// 配方列表
///
private List RecipeLists;
///
/// 称量列表
///
private List WeightLists;
///
/// 现所选配方号
///
private string NowRecipeCode;
///
/// 配方字段剪切板
///
private ZxRecipeParaEntity ParaCopyBoard = new ZxRecipeParaEntity();
///
/// 工位全部配方字段剪切板
///
private List PositionParaCopyBoard = new List();
///
/// 工位单个配方字段剪切板
///
private ZxRecipePositionParaEntity SingalPositionParaCopyBoard;
///
/// PLC实例
///
private RecipeParaHelper recipeParaHelper = new RecipeParaHelper();
public RecipeConfigPage()
{
InitializeComponent();
Init();
}
private void Init()
{
RecipeDataGridView.AutoGenerateColumns = false;
WeightDataGridView.AutoGenerateColumns = false;
RecipeLists = zxRecipeService.GetRecipeInfos();
RecipeDataGridView.DataSource = null;
RecipeDataGridView.DataSource = RecipeLists;
NowRecipeCode = RecipeDataGridView.Rows[0].Cells["RecipeCode"].Value.ToString();
InitPositionEntities();
if(PlcConnect.IsConnect1 == true)
{
//读取SPEC编号
PlcSpecNoLabel.Text = PlcConnect.ReadUInt321("D206").ToString();
//读取SPEC名称
PlcSpecNameLabel.Text = PlcConnect.ReadString1("D290", 10).Trim();
}
}
#region 配方信息
///
/// 添加配方信息
///
///
///
private void AddRecipeButton_Click(object sender, EventArgs e)
{
AddRecipeForm form = new AddRecipeForm();
form.ShowDialog();
RecipeLists = zxRecipeService.GetRecipeInfos();
RecipeDataGridView.DataSource = null;
RecipeDataGridView.DataSource = RecipeLists;
}
///
/// 删除配方信息
///
///
///
private void DeleteRecipeButton_Click(object sender, EventArgs e)
{
int a = RecipeDataGridView.CurrentRow.Index;
//string s = RecipeDataGridView.Rows[a].Cells["RecipeCode"].Value.ToString();
int id;
try
{
id = int.Parse(RecipeDataGridView.Rows[a].Cells["RId"].Value.ToString());
}
catch (Exception ex)
{
MessageBox.Show("ID转换发生错误");
return;
}
if (MessageBox.Show($"确定要删除编号为 [{NowRecipeCode}] 的配方信息?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (zxWeightService.GetWeightInfos(NowRecipeCode).Count > 0)
{
if (MessageBox.Show("是否要删除其关联的所有称量信息?", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
if (zxWeightService.DeleteWeightInfoByRecipeCode(NowRecipeCode))
{
MessageBox.Show("称量信息删除成功");
}
else
{
MessageBox.Show("称量信息删除失败!请检查数据库连接情况");
}
}
}
if (zxRecipeService.DeleteRecipeInfoById(id))
{
MessageBox.Show("配方信息删除成功!");
}
else
{
MessageBox.Show("配方信息删除失败!请检查数据库连接情况");
}
RecipeLists = zxRecipeService.GetRecipeInfos();
RecipeDataGridView.DataSource = null;
RecipeDataGridView.DataSource = RecipeLists;
}
///
/// 修改配方信息
///
///
///
private void UpdateRecipeButton_Click(object sender, EventArgs e)
{
DataGridViewRow nowRow = RecipeDataGridView.CurrentRow;
if (MessageBox.Show($"确认要更改编号为 [{nowRow.Cells["RecipeCode"].Value.ToString()}] 配方的数据吗", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
ZxRecipeEntity entity = new ZxRecipeEntity();
try
{
entity.Id = int.Parse(nowRow.Cells["RId"].Value.ToString().Trim());
entity.RecipeCode = nowRow.Cells["RecipeCode"].Value.ToString().Trim();
entity.RecipeName = nowRow.Cells["RecipeName"].Value.ToString().Trim();
entity.RecipeSpecCode = nowRow.Cells["RecipeSpecCode"].Value.ToString().Trim();
entity.RecipeSpecName = nowRow.Cells["RecipeSpecName"].Value.ToString().Trim();
entity.SizeKind = int.Parse(nowRow.Cells["SizeKind"].Value.ToString().Trim());
entity.FixedWidth = decimal.Parse(nowRow.Cells["FixedWidth"].Value.ToString().Trim());
entity.WeightError = int.Parse(nowRow.Cells["WeightError"].Value.ToString().Trim());
entity.IsUse = bool.Parse(nowRow.Cells["IsUse"].Value.ToString().Trim());
entity.IsDeleted = false;
}
catch (Exception ex)
{
MessageBox.Show("数据格式错误!");
return;
}
if (zxRecipeService.UpdateRecipeInfo(entity))
{
MessageBox.Show("配方更新成功!");
}
else
{
MessageBox.Show("配方更新失败!");
}
RecipeLists = zxRecipeService.GetRecipeInfos();
RecipeDataGridView.DataSource = null;
RecipeDataGridView.DataSource = RecipeLists;
}
///
/// 刷新配方信息
///
///
///
private void RefreshRecipeButton_Click(object sender, EventArgs e)
{
RecipeLists = zxRecipeService.GetRecipeInfos();
RecipeDataGridView.DataSource = null;
RecipeDataGridView.DataSource = RecipeLists;
}
#endregion
#region 称量信息
///
/// 添加称量信息
///
///
///
private void AddWeightButton_Click(object sender, EventArgs e)
{
if (RecipeDataGridView.CurrentRow == null)
{
MessageBox.Show("请先选择一条配方!");
return;
}
AddWeightForm form = new AddWeightForm(NowRecipeCode);
form.ShowDialog();
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
}
///
/// 删除称量信息
///
///
///
private void DeleteWeightButton_Click(object sender, EventArgs e)
{
int a = WeightDataGridView.CurrentRow.Index;
string s2 = WeightDataGridView.Rows[a].Cells["MaterialCode"].Value.ToString();
int id;
try
{
id = int.Parse(WeightDataGridView.Rows[a].Cells["Id"].Value.ToString());
}
catch (Exception ex)
{
MessageBox.Show("ID转换发生错误");
return;
}
if (MessageBox.Show($"确定要删除配方编号为 [{NowRecipeCode}] 物料编码为 [{s2}] 的称重信息?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (zxWeightService.DeleteWeightInfoById(id))
{
MessageBox.Show("配方信息删除成功!");
}
else
{
MessageBox.Show("配方信息删除失败!请检查数据库连接情况");
}
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
}
///
/// 修改称量信息
///
///
///
private void UpdateWeightButton_Click(object sender, EventArgs e)
{
DataGridViewRow nowRow = WeightDataGridView.CurrentRow;
if (MessageBox.Show($"确认要更改配方编号为 [{NowRecipeCode}] 物料编号为 [{nowRow.Cells["MaterialCode"].Value.ToString()}] 的数据吗"
, "确认"
, MessageBoxButtons.OKCancel)
== DialogResult.Cancel)
{
return;
}
ZxWeightEntity entity = new ZxWeightEntity();
try
{
entity.Id = int.Parse(nowRow.Cells["Id"].Value.ToString().Trim());
entity.RecipeCode = NowRecipeCode;
entity.MaterialCode = nowRow.Cells["MaterialCode"].Value.ToString().Trim();
entity.SetThickness = decimal.Parse(nowRow.Cells["SetThickness"].Value.ToString().Trim());
entity.SetWidth = decimal.Parse(nowRow.Cells["SetWidth"].Value.ToString().Trim());
entity.SetLayer = int.Parse(nowRow.Cells["SetLayer"].Value.ToString().Trim());
entity.SetWeight = decimal.Parse(nowRow.Cells["SetWeight"].Value.ToString().Trim());
entity.SetError = decimal.Parse(nowRow.Cells["SetError"].Value.ToString().Trim());
entity.IsUse = bool.Parse(nowRow.Cells["WeightIsUse"].Value.ToString().Trim());
entity.IsDeleted = false;
}
catch (Exception ex)
{
MessageBox.Show("数据格式错误!");
return;
}
if (zxWeightService.UpdateWeightInfo(entity))
{
MessageBox.Show("称量信息更新成功!");
}
else
{
MessageBox.Show("称量信息更新失败!");
}
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
}
///
/// 刷新称量信息
///
///
///
private void RefreshWeightButton_Click(object sender, EventArgs e)
{
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
}
///
/// 称重数据关联物料数据
///
private void WeightToDataSource()
{
weightDataSourceEntities = new List();
foreach (var item in WeightLists)
{
var entitys = zxMaterialService.GetEntityByMaterialCode(item.MaterialCode);
if (entitys == null && entitys.Count == 0)
{
return;
}
if (entitys.Count > 1)
{
MessageBox.Show("请检查是否有多条物料编号相同的可用物料");
return;
}
ZxMaterialEntity material = entitys[0];
weightDataSourceEntities.Add(new WeightDataSourceEntity()
{
Id = item.Id,
RecipeCode = item.RecipeCode,
MaterialCode = item.MaterialCode,
MaterialName = material.MaterialName,
MaterialType = material.MaterialType,
MaterialChildType = material.ChildType,
SetThickness = item.SetThickness,
SetWidth = item.SetWidth,
SetLayer = item.SetLayer,
SetWeight = item.SetWeight,
SetError = item.SetError,
IsUse = item.IsUse,
});
}
}
#endregion
///
/// 所选配方内容更改事件
///
///
///
private void RecipeDataGridView_SelectionChanged(object sender, EventArgs e)
{
int a = RecipeDataGridView.CurrentRow.Index;
NowRecipeCode = RecipeDataGridView.Rows[a].Cells["RecipeCode"].Value.ToString();
SpecNoLabel.Text = RecipeDataGridView.Rows[a].Cells["RecipeSpecCode"].Value.ToString();
SpecNameLabel.Text = RecipeDataGridView.Rows[a].Cells["RecipeSpecName"].Value.ToString();
//初始化工位参数类
InitPositionEntities();
WeightLists = zxWeightService.GetWeightInfos(NowRecipeCode);
WeightToDataSource();
WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities;
//设置参数
var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(NowRecipeCode);
int flag = GetSelectIndex();
var positionParaData = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.RecipeCode == NowRecipeCode);
//没有就全0
if (paraData.Count == 0)
{
SetPublicParaValue(new ZxRecipeParaEntity());
zxRecipeParaEntity = new ZxRecipeParaEntity();
}
//有就显示
else if (paraData.Count == 1)
{
SetPublicParaValue(paraData[0]);
zxRecipeParaEntity = paraData[0];
}
//有多条设为第一条
else
{
MessageBox.Show("存在多条未删除的相同公共配方字段信息!将设置为第一条。点击清除脏数据");
SetPublicParaValue(paraData[0]);
zxRecipeParaEntity = paraData[0];
}
//没有就全0
if (positionParaData.Count == 0)
{
SetPrivateParaValue(new ZxRecipePositionParaEntity());
}
else
{
foreach (var item in positionParaData)
{
ChangePositionEntities(item);
}
SetPrivateParaValue(zxRecipePositionParaEntity.Where(x => x.Position == flag).FirstOrDefault());
}
}
#region 参数设置
///
/// 参数保存
///
///
///
private void SaveParaButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"确定要保存配方编号为 [{NowRecipeCode}] 的配方的参数?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
var index = GetSelectIndex();
//从前端更新值
GetPublicParaValue();
GetPrivateParaValue(index);
//查重
var paraEntity = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(NowRecipeCode);
var positionParaEntity = zxRecipePositionParaService.GetRecipePositionParaInfoByRecipeCode(NowRecipeCode);
zxRecipeParaEntity.RecipeCode = NowRecipeCode;
//保存公共参数
var flag1 = true;
if (paraEntity.Count == 0) //没有就插入
{
flag1 = zxRecipeParaService.InsertRecipeParaInfo(zxRecipeParaEntity);
}
else if (paraEntity.Count == 1) //有就更新
{
zxRecipeParaEntity.Id = paraEntity[0].Id;
flag1 = zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity);
}
else //多条更新第一条
{
zxRecipeParaEntity.Id = paraEntity[0].Id;
flag1 = zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity);
MessageBox.Show("存在多条未删除的相同公共配方字段信息!将设置为第一条。点击清除脏数据");
}
//保存贴合参数
var flag2 = true;
foreach (var item in zxRecipePositionParaEntity)
{
item.RecipeCode = NowRecipeCode;
var count = positionParaEntity.Count(x => x.Position == item.Position);
//如果没有
if (count == 0)
{
flag2 = zxRecipePositionParaService.InsertRecipePositionParaInfo(item);
}
else //有 多条存第一条
{
item.Id = positionParaEntity.FirstOrDefault(x => x.Position == item.Position).Id;
flag2 = zxRecipePositionParaService.UpdateRecipePositionParaInfo(item);
if (count != 1) //多条提示
{
MessageBox.Show("存在多条未删除的相同公共配方字段信息!将设置为第一条。点击清除脏数据");
}
}
if (!flag2) break;
}
if (flag1 && flag2)
{
BaseForm.LogRefreshAction.Invoke("更新成功");
}
else
{
BaseForm.LogRefreshAction.Invoke("更新失败");
}
//保存贴合参数
}
///
/// 初始化工位参数
///
private void InitPositionEntities()
{
zxRecipePositionParaEntity.Clear();
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 1
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 2
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 31
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 32
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 41
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 42
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 51
});
zxRecipePositionParaEntity.Add(new ZxRecipePositionParaEntity()
{
Position = 52
});
}
///
/// 替换工位信息中的元素
///
///
private void ChangePositionEntities(ZxRecipePositionParaEntity entity)
{
int index = zxRecipePositionParaEntity.FindIndex(x => x.Position == entity.Position);
if (index == -1)
{
BaseForm.LogRefreshAction.Invoke("数据保存失败,请重新启动页面");
return;
}
zxRecipePositionParaEntity[index] = entity;
}
///
/// 设置显示的贴合参数字段值
///
///
private void SetPrivateParaValue(ZxRecipePositionParaEntity entity)
{
E1TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E1);
E2TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E2);
E3TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E3);
E4TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E4);
E5TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E5);
E6TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E6);
E7TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E7);
E8TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E8);
E9TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E9);
E10TextBox.Text = GeneralUtils.IntEmptyOrToString(entity.E10);
}
///
/// 设置公共参数
///
///
private void SetPublicParaValue(ZxRecipeParaEntity paraEntity)
{
S0Check.Checked = paraEntity.S0 ?? false;
S1Check.Checked = paraEntity.S1 ?? false;
S2Check.Checked = paraEntity.S2 ?? false;
S3Check.Checked = paraEntity.S3 ?? false;
S4Check.Checked = paraEntity.S4 ?? false;
S5Check.Checked = paraEntity.S5 ?? false;
S6Check.Checked = paraEntity.S6 ?? false;
S7Check.Checked = paraEntity.S7 ?? false;
S8Check.Checked = paraEntity.S8 ?? false;
S9Check.Checked = paraEntity.S9 ?? false;
RimInchTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.RimInch);
LightWidthTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.LightWidth);
SlowDistanceTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.SlowDistance);
StopDistanceTextBox.Text = GeneralUtils.IntEmptyOrToString(paraEntity.StopDistance);
TireWeightTextBox.Text = paraEntity.TireWeight == null ? "0" : paraEntity.TireWeight.ToString();
//SpecNoLabel.Text = GeneralUtils.IntEmptyOrToString(paraEntity.SpecCode);
//SpecNameLabel.Text = paraEntity.SpecName;
}
///
/// 贴合参数获取值 存到实体
///
///
private void GetPrivateParaValue(int flag)
{
var e = zxRecipePositionParaEntity.FirstOrDefault(x => x.Position == flag);
e.E1 = GeneralUtils.StringNullOrToInt(E1TextBox.Text);
e.E2 = GeneralUtils.StringNullOrToInt(E2TextBox.Text);
e.E3 = GeneralUtils.StringNullOrToInt(E3TextBox.Text);
e.E4 = GeneralUtils.StringNullOrToInt(E4TextBox.Text);
e.E5 = GeneralUtils.StringNullOrToInt(E5TextBox.Text);
e.E6 = GeneralUtils.StringNullOrToInt(E6TextBox.Text);
e.E7 = GeneralUtils.StringNullOrToInt(E7TextBox.Text);
e.E8 = GeneralUtils.StringNullOrToInt(E8TextBox.Text);
e.E9 = GeneralUtils.StringNullOrToInt(E9TextBox.Text);
e.E10 = GeneralUtils.StringNullOrToInt(E10TextBox.Text);
e.Position = GetSelectIndex();
e.RecipeCode = NowRecipeCode;
ChangePositionEntities(e);
}
///
/// 公共参数获取值 存到实体
///
///
private void GetPublicParaValue()
{
zxRecipeParaEntity.S0 = S0Check.Checked;
zxRecipeParaEntity.S1 = S1Check.Checked;
zxRecipeParaEntity.S2 = S2Check.Checked;
zxRecipeParaEntity.S3 = S3Check.Checked;
zxRecipeParaEntity.S4 = S4Check.Checked;
zxRecipeParaEntity.S5 = S5Check.Checked;
zxRecipeParaEntity.S6 = S6Check.Checked;
zxRecipeParaEntity.S7 = S7Check.Checked;
zxRecipeParaEntity.S8 = S8Check.Checked;
zxRecipeParaEntity.S9 = S9Check.Checked;
zxRecipeParaEntity.RimInch = GeneralUtils.StringNullOrToInt(RimInchTextBox.Text);
zxRecipeParaEntity.LightWidth = GeneralUtils.StringNullOrToInt(LightWidthTextBox.Text);
zxRecipeParaEntity.SlowDistance = GeneralUtils.StringNullOrToInt(SlowDistanceTextBox.Text);
zxRecipeParaEntity.StopDistance = GeneralUtils.StringNullOrToInt(StopDistanceTextBox.Text);
try
{
zxRecipeParaEntity.TireWeight = float.Parse(TireWeightTextBox.Text == string.Empty ? "0" : TireWeightTextBox.Text);
}
catch
{
MessageBox.Show("胎体重量请输入整数或小数");
}
zxRecipeParaEntity.SpecCode = SpecNoLabel.Text;
zxRecipeParaEntity.SpecName = SpecNameLabel.Text;
}
///
/// 工位改变 保存现在的,显示换的
///
///
///
private void PositionRadioBoxChange(object sender, EventArgs e)
{
RadioButton s = sender as RadioButton;
if (s.Checked)
{
int flag = GetSelectIndex();
SetPrivateParaValue(zxRecipePositionParaEntity.Where(x => x.Position == flag).FirstOrDefault());
if (flag < 10)
{
BodyRadioButton.Enabled = false;
SideRadioButton.Enabled = false;
}
else
{
BodyRadioButton.Enabled = true;
SideRadioButton.Enabled = true;
}
}
}
///
/// 获取选择的工位包边
///
/// 选的不对劲就返回0
private int GetSelectIndex()
{
if (Position1RadioButton.Checked)
{
return 1;
}
if (Position2RadioButton.Checked)
{
return 2;
}
if (Position3RadioButton.Checked)
{
if (BodyRadioButton.Checked)
{
return 31;
}
if (SideRadioButton.Checked)
{
return 32;
}
}
if (Position4RadioButton.Checked)
{
if (BodyRadioButton.Checked)
{
return 41;
}
if (SideRadioButton.Checked)
{
return 42;
}
}
if (Position5RadioButton.Checked)
{
if (BodyRadioButton.Checked)
{
return 51;
}
if (SideRadioButton.Checked)
{
return 52;
}
}
return 0;
}
///
/// 暂存工位参数
///
///
///
private void PositionRadioButton_MouseDown(object sender, MouseEventArgs e)
{
int index = GetSelectIndex();
GetPrivateParaValue(index);
BaseForm.LogRefreshAction.Invoke($"[{index.ToString()}] 工位参数已暂存");
}
///
/// 公共参数复制
///
///
///
private void CopyParaButton_Click(object sender, EventArgs e)
{
ParaCopyBoard = zxRecipeParaEntity;
NowCopyLabel.Text = NowRecipeCode;
}
///
/// 公共参数粘贴
///
///
///
private void PasteParaButton_Click(object sender, EventArgs e)
{
if (ParaCopyBoard == null)
{
MessageBox.Show("剪切板为空!");
return;
}
SetPublicParaValue(ParaCopyBoard);
}
///
/// 贴合参数复制
///
///
///
private void CopyPositionButton_Click(object sender, EventArgs e)
{
var index = GetSelectIndex();
GetPrivateParaValue(index);
SingalPositionParaCopyBoard = zxRecipePositionParaEntity.FirstOrDefault(x => x.Position == index);
PositionCopyBoardLabel.Text = index.ToString() + "|" + NowRecipeCode;
}
///
/// 贴合参数粘贴
///
///
///
private void PastePositionButton_Click(object sender, EventArgs e)
{
if (SingalPositionParaCopyBoard == null)
{
MessageBox.Show("剪切板为空!");
return;
}
SetPrivateParaValue(SingalPositionParaCopyBoard);
}
///
/// 整体复制
///
///
///
private void CopyAllButton_Click(object sender, EventArgs e)
{
int index = GetSelectIndex();
GetPrivateParaValue(index);
ParaCopyBoard = new ZxRecipeParaEntity()
{
S0 = zxRecipeParaEntity.S0 ?? false,
S1 = zxRecipeParaEntity.S1 ?? false,
S2 = zxRecipeParaEntity.S2 ?? false,
S3 = zxRecipeParaEntity.S3 ?? false,
S4 = zxRecipeParaEntity.S4 ?? false,
S5 = zxRecipeParaEntity.S5 ?? false,
S6 = zxRecipeParaEntity.S6 ?? false,
S7 = zxRecipeParaEntity.S7 ?? false,
S8 = zxRecipeParaEntity.S8 ?? false,
S9 = zxRecipeParaEntity.S9 ?? false,
RimInch = zxRecipeParaEntity.RimInch,
LightWidth = zxRecipeParaEntity.LightWidth,
SlowDistance = zxRecipeParaEntity.SlowDistance,
StopDistance = zxRecipeParaEntity.StopDistance,
TireWeight = zxRecipeParaEntity.TireWeight,
};
PositionParaCopyBoard.Clear();
foreach (var entity in zxRecipePositionParaEntity)
{
var clone = new ZxRecipePositionParaEntity()
{
E1 = entity.E1,
E2 = entity.E2,
E3 = entity.E3,
E4 = entity.E4,
E5 = entity.E5,
E6 = entity.E6,
E7 = entity.E7,
E8 = entity.E8,
E9 = entity.E9,
E10 = entity.E10,
Position = entity.Position,
};
PositionParaCopyBoard.Add(clone);
}
//PositionParaCopyBoard = zxRecipePositionParaEntity;
NowCopyLabel.Text = NowRecipeCode + " 全复制";
PositionCopyBoardLabel.Text = "全复制";
}
///
/// 整体粘贴
///
///
///
private void PasteAllButton_Click(object sender, EventArgs e)
{
if (zxRecipeParaEntity != null && (zxRecipePositionParaEntity != null || zxRecipePositionParaEntity.Count != 8))
{
zxRecipePositionParaEntity = PositionParaCopyBoard;
zxRecipeParaEntity = ParaCopyBoard;
}
else
{
MessageBox.Show("粘贴失败,请重新复制数据");
}
SetPublicParaValue(zxRecipeParaEntity);
SetPrivateParaValue(zxRecipePositionParaEntity.First(x => x.Position == GetSelectIndex()));
}
///
/// 清除脏数据
///
///
///
private void ClearDirtyData_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"确定要清除脏数据?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (zxRecipeParaService.DeleteDirtyData() &&
zxRecipePositionParaService.DeleteDirtyData())
{
MessageBox.Show("清除成功");
}
else
{
MessageBox.Show("清除失败");
}
}
///
/// 上载到plc
///
///
///
private void UploadToPlc_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"是否要将此配方下传到PLC?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (!PlcConnect.IsConnect1)
{
MessageBox.Show("PLC未连接");
return;
}
GetPublicParaValue();
GetPrivateParaValue(GetSelectIndex());
if (recipeParaHelper.UploadToPLC(zxRecipeParaEntity, zxRecipePositionParaEntity))
{
MessageBox.Show("下发到PLC成功");
}
else
{
MessageBox.Show("下发到PLC失败");
}
PlcSpecNameLabel.Text = zxRecipeParaEntity.SpecName.Trim();
PlcSpecNoLabel.Text = zxRecipeParaEntity.SpecCode.Trim();
}
///
/// 从plc读取
///
///
///
private void DownloadFromPlc_Click(object sender, EventArgs e)
{
if (MessageBox.Show($"是否要从PLC读取配方?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
if (!PlcConnect.IsConnect1)
{
MessageBox.Show("PLC未连接");
return;
}
zxRecipePositionParaEntity = recipeParaHelper.DownLoadFormPlc(ref zxRecipeParaEntity);
SetPublicParaValue(zxRecipeParaEntity);
SetPrivateParaValue(zxRecipePositionParaEntity.First(x => x.Position == GetSelectIndex()));
PlcSpecNameLabel.Text = zxRecipeParaEntity.SpecName.Trim();
PlcSpecNoLabel.Text = zxRecipeParaEntity.SpecCode.Trim();
}
#endregion
}
}