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.

166 lines
5.9 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 HighWayIot.Log4net;
using HighWayIot.Repository.service;
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()
{
zxSchedulingEntity = zxSchedulingService.GetSchedulingInfo();
SchedulingDataGridView.AutoGenerateColumns = false;
bindingSource.DataSource = zxSchedulingEntity;
SchedulingDataGridView.DataSource = null;
SchedulingDataGridView.DataSource = bindingSource;
ComboBoxBind();
}
private void ComboBoxBind()
{
zxRecipeEntities = zxRecipeService.GetRecipeInfos();
RecipeName1.DataSource = null;
RecipeName2.DataSource = null;
List<string> r1 = zxRecipeEntities.Select(x => x.RecipeName).ToList();
r1.Insert(0, "");
RecipeName1.DataSource = r1;
List<string> r2 = zxRecipeEntities.Select(x => x.RecipeName).ToList();
r2.Insert(0, "");
RecipeName2.DataSource = r2;
}
private void UpdateConfigButton_Click(object sender, EventArgs e)
{
if (zxSchedulingService.UpdateSchedulingInfo(zxSchedulingEntity))
{
MessageBox.Show("更新成功");
}
else
{
MessageBox.Show("更新失败");
}
}
private void SelectConfigButton_Click(object sender, EventArgs e)
{
zxSchedulingEntity = zxSchedulingService.GetSchedulingInfo();
bindingSource.DataSource = null;
bindingSource.DataSource = zxSchedulingEntity;
}
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.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;
if(column == 2)
{
ZxRecipeEntity recipe = zxRecipeService.GetSingleInfoByRecipeName(combox.Text);
if (recipe == null)
{
zxSchedulingEntity[row].SpecName1 = string.Empty;
zxSchedulingEntity[row].RecipeNo1 = string.Empty;
}
else
{
zxSchedulingEntity[row].SpecName1 = recipe.RecipeSpecName;
zxSchedulingEntity[row].RecipeNo1 = recipe.RecipeCode;
}
}
if(column == 4)
{
ZxRecipeEntity recipe = zxRecipeService.GetSingleInfoByRecipeName(combox.Text);
if (recipe == null)
{
zxSchedulingEntity[row].SpecName2 = string.Empty;
zxSchedulingEntity[row].RecipeNo2 = string.Empty;
}
else
{
zxSchedulingEntity[row].SpecName2 = recipe.RecipeSpecName;
zxSchedulingEntity[row].RecipeNo2 = 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);
}
}
}