add - 添加配方字段代码

master
SoulStar 7 months ago
parent 5958cab962
commit 308b7041b9

@ -74,7 +74,7 @@ namespace HighWayIot.Repository.service
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Error("物料信息添加异常", ex); log.Error("物料类别信息添加异常", ex);
return false; return false;
} }
} }
@ -92,7 +92,7 @@ namespace HighWayIot.Repository.service
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Error("物料信息删除异常", ex); log.Error("物料类别信息删除异常", ex);
return false; return false;
} }
} }

@ -43,6 +43,43 @@ namespace HighWayIot.Repository.service
} }
} }
/// <summary>
/// 查询配方字段信息
/// </summary>
/// <returns></returns>
public List<ZxRecipeParaEntity> GetRecipeParaInfoByRecipeCode()
{
try
{
List<ZxRecipeParaEntity> entity = _repository.GetList(x => x.IsDeleted == false);
return entity;
}
catch (Exception ex)
{
log.Error("用户信息获取异常", ex);
return null;
}
}
/// <summary>
/// 根据配方号查询配方字段信息
/// </summary>
/// <param name="recipeCode">配方编号</param>
/// <returns></returns>
public List<ZxRecipeParaEntity> GetRecipeParaInfoByRecipeCode(string recipeCode)
{
try
{
List<ZxRecipeParaEntity> entity = _repository.GetList(x => x.IsDeleted == false && x.RecipeCode == recipeCode);
return entity;
}
catch (Exception ex)
{
log.Error("用户信息获取异常", ex);
return null;
}
}
/// <summary> /// <summary>
/// 修改配方字段信息 /// 修改配方字段信息
/// </summary> /// </summary>
@ -56,7 +93,7 @@ namespace HighWayIot.Repository.service
} }
catch(Exception ex) catch(Exception ex)
{ {
log.Error("用户信息修改异常", ex); log.Error("配方字段信息修改异常", ex);
return false; return false;
} }
} }
@ -74,7 +111,25 @@ namespace HighWayIot.Repository.service
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Error("用户信息修改异常", ex); log.Error("配方字段信息修改异常", ex);
return false;
}
}
/// <summary>
/// ID删除配方字段信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteRecipeParaInfoById(int id)
{
try
{
return _repository.DeleteById(id);
}
catch (Exception ex)
{
log.Error("配方字段信息删除异常", ex);
return false; return false;
} }
} }

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -19,5 +20,38 @@ namespace HighWayIot.Winform.Business
str[0] = string.Empty; str[0] = string.Empty;
return str; return str;
} }
/// <summary>
/// 转换string为int?
/// </summary>
/// <param name="intValue"></param>
/// <returns></returns>
public static int? StringNullOrToInt(string intValue)
{
if (string.IsNullOrEmpty(intValue.Trim()))
{
return null;
}
if (int.TryParse(intValue, out int result))
{
return result;
}
else
{
return null;
}
}
public static string IntEmptyOrToString(int? value)
{
if (value == null)
{
return string.Empty;
}
else
{
return value.ToString();
}
}
} }
} }

@ -1,5 +1,6 @@
using HighWayIot.Repository.domain; using HighWayIot.Repository.domain;
using HighWayIot.Repository.service; using HighWayIot.Repository.service;
using HighWayIot.Winform.Business;
using HighWayIot.Winform.UserControlPages.RecipeConfigPages; using HighWayIot.Winform.UserControlPages.RecipeConfigPages;
using HighWayIot.Winform.UserControlPages.SysConfigPages; using HighWayIot.Winform.UserControlPages.SysConfigPages;
using Models; using Models;
@ -38,6 +39,16 @@ namespace HighWayIot.Winform.UserControlPages
/// </summary> /// </summary>
ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance; ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance;
/// <summary>
/// 配方字段实例
/// </summary>
ZxRecipeParaEntity zxRecipeParaEntity = new ZxRecipeParaEntity();
/// <summary>
/// 配方字段实例剪切板
/// </summary>
ZxRecipeParaEntity zxRecipeParaEntityCut;
/// <summary> /// <summary>
/// 称重DataGridView数据源 /// 称重DataGridView数据源
/// </summary> /// </summary>
@ -99,7 +110,7 @@ namespace HighWayIot.Winform.UserControlPages
{ {
id = int.Parse(RecipeDataGridView.Rows[a].Cells["RId"].Value.ToString()); id = int.Parse(RecipeDataGridView.Rows[a].Cells["RId"].Value.ToString());
} }
catch(Exception ex) catch (Exception ex)
{ {
MessageBox.Show("ID转换发生错误"); MessageBox.Show("ID转换发生错误");
return; return;
@ -149,7 +160,7 @@ namespace HighWayIot.Winform.UserControlPages
{ {
DataGridViewRow nowRow = RecipeDataGridView.CurrentRow; DataGridViewRow nowRow = RecipeDataGridView.CurrentRow;
if(MessageBox.Show($"确认要更改编号为 [{nowRow.Cells["RecipeCode"].Value.ToString()}] 配方的数据吗", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) if (MessageBox.Show($"确认要更改编号为 [{nowRow.Cells["RecipeCode"].Value.ToString()}] 配方的数据吗", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{ {
return; return;
} }
@ -355,7 +366,52 @@ namespace HighWayIot.Winform.UserControlPages
/// <param name="e"></param> /// <param name="e"></param>
private void SaveParaButton_Click(object sender, EventArgs e) private void SaveParaButton_Click(object sender, EventArgs e)
{ {
string s = RecipeDataGridView.CurrentRow.Cells["RecipeCode"].Value.ToString();
if (MessageBox.Show($"确定要保存配方编号为 [{s}] 的配方的参数?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{
return;
}
ZxRecipeParaEntity entity = GetParaValue();
entity.IsDeleted = false;
entity.RecipeCode = s;
zxRecipeParaEntity = entity;
var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(zxRecipeParaEntity.RecipeCode);
//没有就插入
if (paraData.Count == 0)
{
if (zxRecipeParaService.InsertRecipeParaInfo(zxRecipeParaEntity))
{
MessageBox.Show("保存成功!");
}
else
{
MessageBox.Show("保存失败!");
}
}
//有就更改
else if (paraData.Count == 1)
{
zxRecipeParaEntity.Id = paraData[0].Id;
if (zxRecipeParaService.UpdateRecipeParaInfo(zxRecipeParaEntity))
{
MessageBox.Show("保存成功!");
}
else
{
MessageBox.Show("保存失败!");
}
}
else
{
MessageBox.Show("存在多条未删除的相同配方参数!请检查数据库。");
return;
}
} }
/// <summary> /// <summary>
@ -365,7 +421,8 @@ namespace HighWayIot.Winform.UserControlPages
/// <param name="e"></param> /// <param name="e"></param>
private void CopyParaButton_Click(object sender, EventArgs e) private void CopyParaButton_Click(object sender, EventArgs e)
{ {
zxRecipeParaEntityCut = GetParaValue();
NowCopyLabel.Text = RecipeDataGridView.CurrentRow.Cells["RecipeCode"].Value.ToString();
} }
/// <summary> /// <summary>
@ -375,7 +432,11 @@ namespace HighWayIot.Winform.UserControlPages
/// <param name="e"></param> /// <param name="e"></param>
private void PasteParaButton_Click(object sender, EventArgs e) private void PasteParaButton_Click(object sender, EventArgs e)
{ {
if (zxRecipeParaEntityCut == null)
{
MessageBox.Show("剪切板为空!");
}
SetParaValue(zxRecipeParaEntityCut);
} }
/// <summary> /// <summary>
@ -385,7 +446,8 @@ namespace HighWayIot.Winform.UserControlPages
/// <param name="e"></param> /// <param name="e"></param>
private void ClearCutBoradButton_Click(object sender, EventArgs e) private void ClearCutBoradButton_Click(object sender, EventArgs e)
{ {
zxRecipeParaEntityCut = null;
NowCopyLabel.Text = "N/A";
} }
/// <summary> /// <summary>
@ -404,6 +466,24 @@ namespace HighWayIot.Winform.UserControlPages
WeightDataGridView.DataSource = null; WeightDataGridView.DataSource = null;
WeightDataGridView.DataSource = weightDataSourceEntities; WeightDataGridView.DataSource = weightDataSourceEntities;
var paraData = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(s);
//没有就全0
if (paraData.Count == 0)
{
SetParaValue(new ZxRecipeParaEntity());
}
//有就显示
else if (paraData.Count == 1)
{
SetParaValue(paraData[0]);
}
//有多条设为第一条
else
{
MessageBox.Show("存在多条未删除的相同配方字段信息!将设置为第一条,请检查数据库。");
SetParaValue(paraData[0]);
}
} }
/// <summary> /// <summary>
@ -448,12 +528,71 @@ namespace HighWayIot.Winform.UserControlPages
} }
/// <summary> /// <summary>
/// 所选单条Weight dataSource转为实体类 /// 设置配方字段值
/// </summary> /// </summary>
//private ZxWeightEntity DataSourceToWeight() /// <param name="entity"></param>
//{ private void SetParaValue(ZxRecipeParaEntity entity)
// int a = WeightDataGridView.CurrentRow.Index; {
// foreach zxRecipeParaEntity = entity;
//} E1P1TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P1);
E1P2TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P2);
E1P3TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P3);
E1P4TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E1P4);
E2P1TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P1);
E2P2TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P2);
E2P3TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P3);
E2P4TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E2P4);
E3P1TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P1);
E3P2TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P2);
E3P3TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P3);
E3P4TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P4);
E3P5CheckBox.Checked = zxRecipeParaEntity.E3P5 == 1;
E3P6TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P6);
E3P7TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P7);
E3P8TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P8);
E3P9TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P9);
E3P10TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P10);
E3P11TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P11);
E3P12TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P12);
E3P13TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P13);
E3P14TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P14);
E3P15TextBox.Text = GeneralUtils.IntEmptyOrToString(zxRecipeParaEntity.E3P15);
}
/// <summary>
/// 获取界面上的配方参数
/// </summary>
/// <returns>获取到的配方参数值</returns>
private ZxRecipeParaEntity GetParaValue()
{
ZxRecipeParaEntity entity = new ZxRecipeParaEntity()
{
E1P1 = GeneralUtils.StringNullOrToInt(E1P1TextBox.Text),
E1P2 = GeneralUtils.StringNullOrToInt(E1P2TextBox.Text),
E1P3 = GeneralUtils.StringNullOrToInt(E1P3TextBox.Text),
E1P4 = GeneralUtils.StringNullOrToInt(E1P4TextBox.Text),
E2P1 = GeneralUtils.StringNullOrToInt(E2P1TextBox.Text),
E2P2 = GeneralUtils.StringNullOrToInt(E2P2TextBox.Text),
E2P3 = GeneralUtils.StringNullOrToInt(E2P3TextBox.Text),
E2P4 = GeneralUtils.StringNullOrToInt(E2P4TextBox.Text),
E3P1 = GeneralUtils.StringNullOrToInt(E3P1TextBox.Text),
E3P2 = GeneralUtils.StringNullOrToInt(E3P2TextBox.Text),
E3P3 = GeneralUtils.StringNullOrToInt(E3P3TextBox.Text),
E3P4 = GeneralUtils.StringNullOrToInt(E3P4TextBox.Text),
E3P5 = E3P5CheckBox.Checked ? 1 : 0,
E3P6 = GeneralUtils.StringNullOrToInt(E3P6TextBox.Text),
E3P7 = GeneralUtils.StringNullOrToInt(E3P7TextBox.Text),
E3P8 = GeneralUtils.StringNullOrToInt(E3P8TextBox.Text),
E3P9 = GeneralUtils.StringNullOrToInt(E3P9TextBox.Text),
E3P10 = GeneralUtils.StringNullOrToInt(E3P10TextBox.Text),
E3P11 = GeneralUtils.StringNullOrToInt(E3P11TextBox.Text),
E3P12 = GeneralUtils.StringNullOrToInt(E3P12TextBox.Text),
E3P13 = GeneralUtils.StringNullOrToInt(E3P13TextBox.Text),
E3P14 = GeneralUtils.StringNullOrToInt(E3P14TextBox.Text),
E3P15 = GeneralUtils.StringNullOrToInt(E3P15TextBox.Text),
};
return entity;
}
} }
} }

Loading…
Cancel
Save