|
|
using HighWayIot.Log4net;
|
|
|
using HighWayIot.Repository.service;
|
|
|
using HighWayIot.Winform.Business;
|
|
|
using Models;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace HighWayIot.Winform.UserControlPages.ParamConfigPages
|
|
|
{
|
|
|
public partial class ProductionScheduling : UserControl
|
|
|
{
|
|
|
ZxSchedulingService zxSchedulingService = ZxSchedulingService.Instance;
|
|
|
|
|
|
ZxRecipeService zxRecipeService = ZxRecipeService.Instance;
|
|
|
|
|
|
List<ZxRecipeEntity> zxRecipeEntities = new List<ZxRecipeEntity>();
|
|
|
|
|
|
List<ZxSchedulingEntity> zxSchedulingEntity = new List<ZxSchedulingEntity>();
|
|
|
|
|
|
BindingSource bindingSource = new BindingSource();
|
|
|
|
|
|
public ProductionScheduling()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
private void init()
|
|
|
{
|
|
|
this.SchedulingDataGridView.DataError += new DataGridViewDataErrorEventHandler(SchedulingDataGridView_DataError);
|
|
|
zxSchedulingEntity = zxSchedulingService.GetSchedulingInfo();
|
|
|
SchedulingDataGridView.AutoGenerateColumns = false;
|
|
|
bindingSource.DataSource = zxSchedulingEntity;
|
|
|
SchedulingDataGridView.DataSource = null;
|
|
|
SchedulingDataGridView.DataSource = bindingSource;
|
|
|
ComboBoxBind();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 处理异常数据
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
private void SchedulingDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 绑定下拉框数据源
|
|
|
/// </summary>
|
|
|
private void ComboBoxBind()
|
|
|
{
|
|
|
zxRecipeEntities = zxRecipeService.GetRecipeInfos();
|
|
|
RecipeName1.DataSource = null;
|
|
|
RecipeName2.DataSource = null;
|
|
|
|
|
|
List<string> r1 = zxRecipeEntities.Select(x => x.RecipeName).ToList();
|
|
|
r1.Sort();
|
|
|
r1.Insert(0, "");
|
|
|
RecipeName1.DataSource = r1;
|
|
|
List<string> r2 = zxRecipeEntities.Select(x => x.RecipeName).ToList();
|
|
|
r2.Sort();
|
|
|
r2.Insert(0, "");
|
|
|
RecipeName2.DataSource = r2;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新设置
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void UpdateConfigButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (zxSchedulingService.UpdateSchedulingInfo(zxSchedulingEntity))
|
|
|
{
|
|
|
MessageBox.Show("更新成功");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("更新失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新页面
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void SelectConfigButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
zxSchedulingEntity = zxSchedulingService.GetSchedulingInfo();
|
|
|
bindingSource.DataSource = null;
|
|
|
bindingSource.DataSource = zxSchedulingEntity;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 实现单击一次显示下拉列表框
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void SchedulingDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
|
|
|
{
|
|
|
if (SchedulingDataGridView.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && e.RowIndex != -1)
|
|
|
{
|
|
|
SendKeys.Send("{F4}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
**第一步:
|
|
|
**/
|
|
|
ComboBox cbo = new ComboBox();
|
|
|
private void SchedulingDataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
|
|
|
{
|
|
|
if (SchedulingDataGridView.CurrentCell.OwningColumn.Name.Contains("RecipeName") && SchedulingDataGridView.CurrentCell.RowIndex != -1)
|
|
|
{
|
|
|
//保存当前的事件源。为了触发事件后。在取消
|
|
|
cbo = e.Control as ComboBox;
|
|
|
//cbo.AutoCompleteSource = AutoCompleteSource.CustomSource;
|
|
|
//cbo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
|
|
|
cbo.SelectedIndexChanged += new EventHandler(cbo_SelectedIndexChanged);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
**第二步:
|
|
|
**/
|
|
|
void cbo_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
ComboBox combox = sender as ComboBox;
|
|
|
//添加离开combox的事件(重要;)
|
|
|
combox.Leave += new EventHandler(combox_Leave);
|
|
|
try
|
|
|
{
|
|
|
//在这里就可以做值是否改变判断
|
|
|
if (combox.SelectedItem != null)
|
|
|
{
|
|
|
int row = SchedulingDataGridView.CurrentCell.RowIndex;
|
|
|
int column = SchedulingDataGridView.CurrentCell.ColumnIndex;
|
|
|
string DeviceNo = SchedulingDataGridView.Rows[row].Cells[1].Value.ToString();
|
|
|
|
|
|
if(column == 5)
|
|
|
{
|
|
|
ZxRecipeEntity recipe = zxRecipeService.GetSingleInfoByRecipeName(combox.Text);
|
|
|
if (recipe == null)
|
|
|
{
|
|
|
MessageBox.Show("存在多个相同的标称尺度或不存在,请检查并维护配方,重启排程界面");
|
|
|
zxSchedulingEntity[row].RecipeCode1 = string.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
zxSchedulingEntity[row].RecipeCode1 = recipe.RecipeCode;
|
|
|
SqlLogHelper.AddLog($"排程信息操作 机台[{DeviceNo}下模] 配方更改为[{recipe.RecipeCode}]");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (column == 3)
|
|
|
{
|
|
|
ZxRecipeEntity recipe = zxRecipeService.GetSingleInfoByRecipeName(combox.Text);
|
|
|
if (recipe == null)
|
|
|
{
|
|
|
MessageBox.Show("存在多个相同的标称尺度或不存在,请检查并维护配方,重启排程界面");
|
|
|
zxSchedulingEntity[row].RecipeCode2 = string.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
zxSchedulingEntity[row].RecipeCode2 = recipe.RecipeCode;
|
|
|
SqlLogHelper.AddLog($"排程信息操作 机台[{DeviceNo}上模] 配方更改为[{recipe.RecipeCode}]");
|
|
|
}
|
|
|
}
|
|
|
SchedulingDataGridView.Refresh();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.Instance.Error("硫化排程发生错误", ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
**第三步:离开combox时,把事件删除
|
|
|
**/
|
|
|
public void combox_Leave(object sender, EventArgs e)
|
|
|
{
|
|
|
ComboBox combox = sender as ComboBox;
|
|
|
//做完处理,须撤销动态事件
|
|
|
combox.SelectedIndexChanged -= new EventHandler(cbo_SelectedIndexChanged);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|