forked from wenjy/HighWayIot
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.
269 lines
9.7 KiB
C#
269 lines
9.7 KiB
C#
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.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace HighWayIot.Winform.UserControlPages.RecipeConfigPages
|
|
{
|
|
public partial class AddWeightForm : Form
|
|
{
|
|
/// <summary>
|
|
/// 物料子类型服务类实例
|
|
/// </summary>
|
|
ZxMaterialChildTypeService zxMaterialChildTypeService = ZxMaterialChildTypeService.Instance;
|
|
|
|
/// <summary>
|
|
/// 物料类型服务类实例
|
|
/// </summary>
|
|
ZxMaterialTypeService zxMaterialTypeService = ZxMaterialTypeService.Instance;
|
|
|
|
/// <summary>
|
|
/// 物料服务类实例
|
|
/// </summary>
|
|
ZxMaterialService zxMaterialService = ZxMaterialService.Instance;
|
|
|
|
/// <summary>
|
|
/// 称量服务类实例
|
|
/// </summary>
|
|
ZxWeightService zxWeightService = ZxWeightService.Instance;
|
|
|
|
/// <summary>
|
|
/// 物料编号数组
|
|
/// </summary>
|
|
string[] MaterialCodeArray;
|
|
|
|
/// <summary>
|
|
/// 物料名称数组
|
|
/// </summary>
|
|
string[] MaterialNameArray;
|
|
|
|
/// <summary>
|
|
/// 物料子类型数组
|
|
/// </summary>
|
|
string[] MaterialChildTypeArray;
|
|
|
|
/// <summary>
|
|
/// 物料类型数组
|
|
/// </summary>
|
|
string[] MaterialTypeArray;
|
|
|
|
/// <summary>
|
|
/// 配方编号
|
|
/// </summary>
|
|
string RecipeCode;
|
|
|
|
public AddWeightForm(string recipeCode)
|
|
{
|
|
InitializeComponent();
|
|
RecipeCode = recipeCode;
|
|
Init();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
RecipeCodeTextBox.Text = RecipeCode;
|
|
|
|
//获取数据
|
|
MaterialTypeArray = zxMaterialTypeService.GetMaterialTypeInfos().Select(x => x.MaterialTypeName).ToArray();
|
|
List<ZxMaterialEntity> list = zxMaterialService.GetMaterialInfos();
|
|
MaterialCodeArray = list.Select(x => x.MaterialCode).ToArray();
|
|
MaterialNameArray = list.Select(x => x.MaterialName).ToArray();
|
|
|
|
//添加空白行
|
|
MaterialTypeArray = GeneralUtils.HeadAddEmptyString(MaterialTypeArray);
|
|
MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray);
|
|
MaterialNameArray = GeneralUtils.HeadAddEmptyString(MaterialNameArray);
|
|
|
|
//绑定combobox数据源
|
|
MaterialTypeComboBox.DataSource = MaterialTypeArray;
|
|
MaterialCodeComboBox.DataSource = MaterialCodeArray;
|
|
MaterialNameComboBox.DataSource = MaterialNameArray;
|
|
}
|
|
|
|
private void AddButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(MaterialCodeComboBox.Text))
|
|
{
|
|
MessageBox.Show("物料编号不可为空!");
|
|
return;
|
|
}
|
|
|
|
ZxWeightEntity zxWeightEntity = new ZxWeightEntity()
|
|
{
|
|
RecipeCode = this.RecipeCode,
|
|
MaterialCode = MaterialCodeComboBox.Text.Trim(),
|
|
IsUse = IsUseCheckBox.Checked,
|
|
IsDeleted = false,
|
|
};
|
|
|
|
if (!decimal.TryParse(SetThicknessTextBox.Text.Trim(), out decimal thickness))
|
|
{
|
|
MessageBox.Show("厚度请填入可带小数的阿拉伯数字");
|
|
return;
|
|
}
|
|
zxWeightEntity.SetThickness = thickness;
|
|
|
|
if (!decimal.TryParse(SetWidthTextBox.Text.Trim(), out decimal width))
|
|
{
|
|
MessageBox.Show("宽度请填入可带小数的阿拉伯数字");
|
|
return;
|
|
}
|
|
zxWeightEntity.SetWidth = width;
|
|
|
|
if (!int.TryParse(SetLayerTextBox.Text.Trim(), out int layer))
|
|
{
|
|
MessageBox.Show("层数请填入整数阿拉伯数字");
|
|
return;
|
|
}
|
|
zxWeightEntity.SetLayer = layer;
|
|
|
|
if (!decimal.TryParse(SetWeightTextBox.Text.Trim(), out decimal weight))
|
|
{
|
|
MessageBox.Show("重量请填入可带小数的阿拉伯数字");
|
|
return;
|
|
}
|
|
zxWeightEntity.SetWeight = weight;
|
|
|
|
if (!decimal.TryParse(SetErrorTextBox.Text.Trim(), out decimal error))
|
|
{
|
|
MessageBox.Show("重量公差请填入可带小数的阿拉伯数字");
|
|
return;
|
|
}
|
|
zxWeightEntity.SetError = error;
|
|
|
|
if (zxWeightService.InsertWeightInfo(zxWeightEntity))
|
|
{
|
|
MessageBox.Show("称量信息添加成功!");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("称量信息添加失败!请尝试重新添加");
|
|
return;
|
|
}
|
|
|
|
this.Close();
|
|
this.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 物料类型选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MaterialTypeComboBox_SelectionChangeCommitted(object sender, EventArgs e)
|
|
{
|
|
List<ZxMaterialEntity> list = zxMaterialService.GetMaterialInfos(null, MaterialTypeComboBox.Text.Trim());
|
|
MaterialCodeArray = list.Select(x => x.MaterialCode).ToArray();
|
|
MaterialNameArray = list.Select(x => x.MaterialName).ToArray();
|
|
|
|
//添加空白行
|
|
MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray);
|
|
MaterialNameArray = GeneralUtils.HeadAddEmptyString(MaterialNameArray);
|
|
|
|
//绑定combobox数据源
|
|
MaterialCodeComboBox.DataSource = MaterialCodeArray;
|
|
MaterialNameComboBox.DataSource = MaterialNameArray;
|
|
|
|
MaterialChildTypeArray = zxMaterialChildTypeService.GetMaterialChildTypeInfos(x => x.MaterialTypeName == MaterialTypeComboBox.Text).Select(x => x.MaterialChlidTypeName).ToArray();
|
|
MaterialChildTypeArray = GeneralUtils.HeadAddEmptyString(MaterialChildTypeArray);
|
|
|
|
ChildTypeComboBox.DataSource = MaterialChildTypeArray;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 物料子类型选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ChildTypeComboBox_SelectionChangeCommitted(object sender, EventArgs e)
|
|
{
|
|
List<ZxMaterialEntity> list = zxMaterialService.GetMaterialInfos(null, MaterialTypeComboBox.Text.Trim(), ChildTypeComboBox.Text.Trim());
|
|
MaterialCodeArray = list.Select(x => x.MaterialCode).ToArray();
|
|
MaterialNameArray = list.Select(x => x.MaterialName).ToArray();
|
|
|
|
//添加空白行
|
|
MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray);
|
|
MaterialNameArray = GeneralUtils.HeadAddEmptyString(MaterialNameArray);
|
|
|
|
//绑定combobox数据源
|
|
MaterialCodeComboBox.DataSource = MaterialCodeArray;
|
|
MaterialNameComboBox.DataSource = MaterialNameArray;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 物料编号选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MaterialCodeComboBox_SelectionChangeCommitted(object sender, EventArgs e)
|
|
{
|
|
ZxMaterialEntity entity = zxMaterialService.GetSingleEntityByCode(MaterialCodeComboBox.Text.Trim());
|
|
|
|
if (entity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
MaterialNameComboBox.Text = entity.MaterialName;
|
|
MaterialTypeComboBox.Text = entity.MaterialType;
|
|
ChildTypeComboBox.Text = entity.ChildType;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 物料名称选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MaterialNameComboBox_SelectionChangeCommitted(object sender, EventArgs e)
|
|
{
|
|
List<ZxMaterialEntity> entitys = zxMaterialService.GetMaterialInfos(MaterialNameComboBox.Text.Trim());
|
|
|
|
if (entitys.Count == 1)
|
|
{
|
|
ZxMaterialEntity entity = entitys[0];
|
|
MaterialCodeComboBox.Text = entity.MaterialCode;
|
|
MaterialTypeComboBox.Text = entity.MaterialType;
|
|
ChildTypeComboBox.Text = entity.ChildType;
|
|
}
|
|
else if (entitys == null)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
MaterialCodeArray = entitys.Select(x => x.MaterialCode).ToArray();
|
|
|
|
//添加空白行
|
|
MaterialCodeArray = GeneralUtils.HeadAddEmptyString(MaterialCodeArray);
|
|
|
|
//绑定combobox数据源
|
|
MaterialCodeComboBox.DataSource = MaterialCodeArray;
|
|
|
|
MaterialTypeComboBox.Text = string.Empty;
|
|
ChildTypeComboBox.Text = string.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 物料类型更改事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void MaterialTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
MaterialChildTypeArray = zxMaterialChildTypeService.GetMaterialChildTypeInfos(x => x.MaterialTypeName == MaterialTypeComboBox.Text).Select(x => x.MaterialChlidTypeName).ToArray();
|
|
MaterialChildTypeArray = GeneralUtils.HeadAddEmptyString(MaterialChildTypeArray);
|
|
ChildTypeComboBox.DataSource = MaterialChildTypeArray;
|
|
}
|
|
}
|
|
}
|