add-添加配方管理界面

master
liuwf 5 months ago
parent 090fc9ea0b
commit 9b1eecf2b2

@ -0,0 +1,36 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;
namespace SlnMesnac.Model.domain
{
/// <summary>
/// 海康配方
/// </summary>
[SugarTable("LOGO_FORMULA"), TenantAttribute("AUCMA_MES")]
public class LogoFormula
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true, OracleSequenceName = "SEQ_LOGO_FORMULA")]
public int Id { get; set; }
/// <summary>
/// 存储1-2-3-4这种发给海康的型号
/// </summary>
[SugarColumn(ColumnName = "KEY")]
public int Key { get; set; }
/// <summary>
/// 存储人工选择的特征-如白色冰柜大LOGO;黑色冰柜小LOGO
/// </summary>
[SugarColumn(ColumnName = "VALUE")]
public string Value { get; set; }
}
}

@ -64,6 +64,7 @@ namespace SlnMesnac.Repository
services.AddSingleton<IBaseMaterialService, BaseMaterialServiceImpl>();
services.AddSingleton<ILogoIdentifyService, LogoIdentifyImpl>();
services.AddSingleton<ILogoConfigService, LogoConfigImpl>();
services.AddSingleton<ILogoFormulaService, LogoFormulaImpl>();
}
}
}

@ -0,0 +1,43 @@
using SlnMesnac.Model.domain;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Repository.service
{
public interface ILogoFormulaService
{
/// <summary>
/// 从本地查询所有型号用来展示
/// </summary>
/// <returns></returns>
Task<List<LogoFormula>> GetListAsync();
//TODO 修改、删除
/// <summary>
/// 新增
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
Task<bool> InsertAsync(LogoFormula record);
/// <summary>
/// 删除
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
Task<bool> DeleteAsync(LogoFormula record);
/// <summary>
/// 修改
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
Task<bool> UpdateAsync(LogoFormula record);
}
}

@ -0,0 +1,64 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Model.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Repository.service.Impl
{
public class LogoFormulaImpl : ILogoFormulaService
{
private readonly ILogger<LogoFormula> _logger;
private readonly Repository<LogoFormula> _rep;
public LogoFormulaImpl(ILogger<LogoFormula> logger, Repository<LogoFormula> rep)
{
_logger = logger;
_rep = rep;
}
public async Task<List<LogoFormula>> GetListAsync()
{
List<LogoFormula> list = null;
list = await _rep.GetListAsync();
return list;
}
/// <summary>
/// 修改
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
public async Task<bool> UpdateAsync(LogoFormula record)
{
bool result = await _rep.UpdateAsync(record);
return result;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
public async Task<bool> DeleteAsync(LogoFormula record)
{
bool result = await _rep.DeleteAsync(record);
return result;
}
/// <summary>
/// 新增
/// </summary>
/// <param name="record"></param>
/// <returns></returns>
public async Task<bool> InsertAsync(LogoFormula record)
{
bool result = await _rep.InsertAsync(record);
return result;
}
}
}

@ -29,6 +29,7 @@ namespace SlnMesnac.WPF.ViewModel
SyncCommand = new RelayCommand(SynchronizeLocal);
QueryCommand = new RelayCommand(Query);
UpdateCommand = new RelayCommand<object>(t=> Update(t));
MangerCommand = new RelayCommand(Manger);
// MainWindowViewModel.RefreDataGridEvent += LoadDataAsync;
LoadDataAsync();
}
@ -73,6 +74,13 @@ namespace SlnMesnac.WPF.ViewModel
}
private void Manger()
{
FormulaWindow window = new FormulaWindow();
window.ShowDialog();
}
/// <summary>
/// 从MES获取数据如果本地没有某个型号加入本地
@ -202,10 +210,14 @@ namespace SlnMesnac.WPF.ViewModel
public RelayCommand QueryCommand { get; set; }
/// <summary>
/// 更新事件
/// 更新检测类型事件
/// </summary>
public RelayCommand<object> UpdateCommand { get; set; }
/// <summary>
/// 管理配方
/// </summary>
public RelayCommand MangerCommand { get; set; }
}
}

@ -0,0 +1,162 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
namespace SlnMesnac.WPF.ViewModel
{
public class FormulaWindowViewModel : ObservableObject
{
private ILogoFormulaService? formulaService;
public FormulaWindowViewModel()
{
formulaService = App.ServiceProvider.GetService<ILogoFormulaService>();
AddCommand = new RelayCommand(AddRecord);
DeleteCommand = new RelayCommand<int>(t => DeleteRecord(t));
LoadDataAsync();
}
#region 加载DataGrid数据
private async void LoadDataAsync()
{
List<LogoFormula> list = await formulaService.GetListAsync();
if (list == null || list.Count == 0) return;
list = list.OrderBy(x => x.Key).ToList();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoFormulaDataGrid.Clear();
foreach (LogoFormula verify in list)
{
LogoFormulaDataGrid.Add(verify);
}
}));
}
#endregion
private async void DeleteRecord(int key)
{
if (key>=0)
{
List<LogoFormula> list = await formulaService.GetListAsync();
if (list == null || list.Count == 0) return;
LogoFormula formula = list.FirstOrDefault(t => t.Key == key);
if (formula != null)
{
bool result = await formulaService.DeleteAsync(formula);
if (result)
{
MessageBox.Show("删除成功");
LoadDataAsync();
}
}
}
}
private async void AddRecord()
{
string key = KeyTxt;
string value = ValueTxt;
if(string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)){
MessageBox.Show("两个值都不能为空");
return;
}
List<LogoFormula> list = await formulaService.GetListAsync();
if (list == null || list.Count == 0) return;
try
{
int result = int.Parse(key);
Console.WriteLine("转换成功,结果是:" + result);
}
catch (FormatException)
{
MessageBox.Show("Key必须为数字");
return;
}
LogoFormula formula = list.FirstOrDefault(t => t.Key == int.Parse(key));
if (formula != null)
{
MessageBox.Show("Key已经存在");
return;
}
else
{
bool result = await formulaService.InsertAsync(new LogoFormula() { Key = int.Parse(key), Value = value });
if (result)
{
MessageBox.Show("添加成功");
LoadDataAsync();
}
}
}
#region 属性
/// <summary>
/// Key
/// </summary>
private string _KeyTxt;
public string KeyTxt
{
get { return _KeyTxt; }
set { _KeyTxt = value; RaisePropertyChanged(); }
}
/// <summary>
/// Value
/// </summary>
private string _ValueTxt;
public string ValueTxt
{
get { return _ValueTxt; }
set { _ValueTxt = value; RaisePropertyChanged(); }
}
#region 初始化datagrid
private ObservableCollection<LogoFormula> _LogoFormulaDataGrid = new ObservableCollection<LogoFormula>();
public ObservableCollection<LogoFormula> LogoFormulaDataGrid
{
get { return _LogoFormulaDataGrid; }
set
{
_LogoFormulaDataGrid = value;
RaisePropertyChanged();//属性通知
}
}
#endregion
#endregion
/// <summary>
/// 查询事件
/// </summary>
public RelayCommand AddCommand { get; set; }
/// <summary>
/// 更新检测类型事件
/// </summary>
public RelayCommand<int> DeleteCommand { get; set; }
}
}

@ -25,6 +25,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using static System.Net.Mime.MediaTypeNames;
namespace SlnMesnac.WPF.ViewModel
{
@ -41,6 +42,7 @@ namespace SlnMesnac.WPF.ViewModel
private IBaseMaterialService? baseMaterialService;
private ILogoIdentifyService? ocrVerfiyService;
private ILogoConfigService? logoConfigService;
private TcpServer? tcpServer;
private PlcPool plcPool = null;
@ -59,6 +61,7 @@ namespace SlnMesnac.WPF.ViewModel
ocrVerfiyService = App.ServiceProvider.GetService<ILogoIdentifyService>();
baseMaterialService = App.ServiceProvider.GetService<IBaseMaterialService>();
logoConfigService = App.ServiceProvider.GetService<ILogoConfigService>();
_logger2 = App.ServiceProvider.GetService<ILogger<LogoBusiness>>();
logoBusiness = LogoBusiness.GetInstance(_logger2, logoConfigService, baseMaterialService, ocrVerfiyService, plcPool, tcpServer);
@ -75,9 +78,11 @@ namespace SlnMesnac.WPF.ViewModel
/// <exception cref="NotImplementedException"></exception>
private void Reset()
{
logoBusiness.Pass();
}
/// <summary>
/// 测试方法
/// </summary>

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:SlnMesnac.WPF.Views" WindowStartupLocation="CenterScreen"
xmlns:converters="clr-namespace:SlnMesnac.WPF.ConvertTo"
mc:Ignorable="d" Background="#1157b9"
Title="配方管理" Height="500" Width="500">
Title="配方管理" Height="1000" Width="1200">
<Window.Resources>
<converters:BooleanToOppositeBooleanConverter x:Key="InverseBooleanConverter" />
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
@ -70,29 +70,50 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="6*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="#1157b9" Margin="1,1,5,5" Orientation="Horizontal" >
<TextBlock Text="型号:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
<TextBox IsReadOnly="True" Text="{Binding MaterialType}" FontSize="20" Width="200" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0"/>
<StackPanel Orientation="horizontal" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
<Label Content="相机模版Key:" FontSize="20" Foreground="White"/>
<TextBox Text="{Binding KeyTxt,Mode=TwoWay}" Width="100" FontSize="20" Foreground="White" Margin="0 0 30 0" />
<Label Content="冰箱型号参数:" Width="130" FontSize="20" Foreground="White"/>
<TextBox Text="{Binding ValueTxt,Mode=TwoWay}" Width="300" FontSize="20" Foreground="White" Margin="0 0 30 0" />
<Button
Content="添 加" Command="{Binding AddCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="LimeGreen" Margin="0 0 100 0"/>
</StackPanel>
<StackPanel Grid.Row="1" Background="#1157b9" Margin="1,1,5,5" Orientation="Horizontal">
<TextBlock Text="是否检测:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
<UniformGrid Grid.Row="1">
<DataGrid x:Name="listDataGrid" Grid.Row="0" ItemsSource="{Binding LogoFormulaDataGrid}" Background="#00000000"
ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}"
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="20"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" LoadingRow="dgvMH_LoadingRow"
ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
Foreground="White" >
<!--修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTemplateColumn Width="55" Header="序号" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}}, Path=Header}" FontSize="18" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Key}" Header="相机模版Key" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Value}" Header="冰箱型号参数" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTemplateColumn Header="操作" Width="1.5*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="删除" Background="Red" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
CommandParameter="{Binding Key}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</UniformGrid>
<RadioButton Foreground="White" Content="是" GroupName="DetectionOptions" IsChecked="{Binding IsDetectionChecked, Mode=TwoWay}" VerticalAlignment="Center" Margin="10 0 0 0"/>
<RadioButton Foreground="White" Content="否" GroupName="DetectionOptions" IsChecked="{Binding IsDetectionChecked, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}" VerticalAlignment="Center" Margin="10 0 0 0"/>
</StackPanel>
<StackPanel Grid.Row="2" Background="#1157b9" Margin="1,1,5,5" Orientation="Horizontal" >
<TextBlock Text="识别类型:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
<TextBox Text="{Binding MaterialType}" FontSize="20" Width="200" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0"/>
</StackPanel>
<Border Grid.Row="3" Background="#1157b9" Margin="1,1,5,5" >
<Button Content="保 存" Command="{Binding SaveCommand}" Width="80"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="Green" HorizontalContentAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</Border>

@ -20,12 +20,17 @@ namespace SlnMesnac.WPF.Views
/// </summary>
public partial class FormulaWindow : Window
{
SetKindWindowViewModel viewModel = null;
public FormulaWindow(string materialType)
FormulaWindowViewModel viewModel = null;
public FormulaWindow()
{
InitializeComponent();
viewModel = new SetKindWindowViewModel(materialType);
viewModel = new FormulaWindowViewModel();
this.DataContext = viewModel;
}
private void dgvMH_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
}
}
}

Loading…
Cancel
Save